• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *    Keith Whitwell <keithw@vmware.com>
26  */
27 
28 #if !HAVE_SPEC
29 #define VERT_SET_SPEC( v, c )
30 #define VERT_COPY_SPEC( v0, v1 )
31 #define VERT_SAVE_SPEC( idx )
32 #define VERT_RESTORE_SPEC( idx )
33 #endif
34 
TAG(unfilled_tri)35 static void TAG(unfilled_tri)( struct gl_context *ctx,
36 			       GLenum mode,
37 			       GLuint e0, GLuint e1, GLuint e2 )
38 {
39    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
40    GLubyte *ef = VB->EdgeFlag;
41    VERTEX *v[3];
42    LOCAL_VARS(3);
43 
44    v[0] = (VERTEX *)GET_VERTEX(e0);
45    v[1] = (VERTEX *)GET_VERTEX(e1);
46    v[2] = (VERTEX *)GET_VERTEX(e2);
47 
48    if (ctx->Light.ShadeModel == GL_FLAT && HAVE_HW_FLATSHADE) {
49       VERT_SAVE_RGBA(0);
50       VERT_SAVE_RGBA(1);
51       VERT_COPY_RGBA(v[0], v[2]);
52       VERT_COPY_RGBA(v[1], v[2]);
53 
54       if (HAVE_SPEC) {
55 	 VERT_SAVE_SPEC(0);
56 	 VERT_SAVE_SPEC(1);
57 	 VERT_COPY_SPEC(v[0], v[2]);
58 	 VERT_COPY_SPEC(v[1], v[2]);
59       }
60    }
61 
62 /*     fprintf(stderr, "%s %s %d %d %d\n", __func__, */
63 /*  	   _mesa_enum_to_string( mode ), */
64 /*  	   ef[e0], ef[e1], ef[e2]); */
65 
66    if (mode == GL_POINT) {
67       RASTERIZE(GL_POINTS);
68       if (ef[e0]) POINT( v[0] );
69       if (ef[e1]) POINT( v[1] );
70       if (ef[e2]) POINT( v[2] );
71    }
72    else {
73       RASTERIZE(GL_LINES);
74       if (RENDER_PRIMITIVE == GL_POLYGON) {
75 	 if (ef[e2]) LINE( v[2], v[0] );
76 	 if (ef[e0]) LINE( v[0], v[1] );
77 	 if (ef[e1]) LINE( v[1], v[2] );
78       }
79       else {
80 	 if (ef[e0]) LINE( v[0], v[1] );
81 	 if (ef[e1]) LINE( v[1], v[2] );
82 	 if (ef[e2]) LINE( v[2], v[0] );
83       }
84    }
85 
86    if (ctx->Light.ShadeModel == GL_FLAT && HAVE_HW_FLATSHADE) {
87       VERT_RESTORE_RGBA(0);
88       VERT_RESTORE_RGBA(1);
89 
90       if (HAVE_SPEC) {
91 	 VERT_RESTORE_SPEC(0);
92 	 VERT_RESTORE_SPEC(1);
93       }
94    }
95 }
96 
97 
TAG(unfilled_quad)98 static void TAG(unfilled_quad)( struct gl_context *ctx,
99 				GLenum mode,
100 				GLuint e0, GLuint e1,
101 				GLuint e2, GLuint e3 )
102 {
103    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
104    GLubyte *ef = VB->EdgeFlag;
105    VERTEX *v[4];
106    LOCAL_VARS(4);
107 
108    v[0] = (VERTEX *)GET_VERTEX(e0);
109    v[1] = (VERTEX *)GET_VERTEX(e1);
110    v[2] = (VERTEX *)GET_VERTEX(e2);
111    v[3] = (VERTEX *)GET_VERTEX(e3);
112 
113    /* Hardware flatshading breaks down here.  If the hardware doesn't
114     * support flatshading, this will already have been done:
115     */
116    if (ctx->Light.ShadeModel == GL_FLAT && HAVE_HW_FLATSHADE) {
117       VERT_SAVE_RGBA(0);
118       VERT_SAVE_RGBA(1);
119       VERT_SAVE_RGBA(2);
120       VERT_COPY_RGBA(v[0], v[3]);
121       VERT_COPY_RGBA(v[1], v[3]);
122       VERT_COPY_RGBA(v[2], v[3]);
123 
124       if (HAVE_SPEC) {
125 	 VERT_SAVE_SPEC(0);
126 	 VERT_SAVE_SPEC(1);
127 	 VERT_SAVE_SPEC(2);
128 	 VERT_COPY_SPEC(v[0], v[3]);
129 	 VERT_COPY_SPEC(v[1], v[3]);
130 	 VERT_COPY_SPEC(v[2], v[3]);
131       }
132    }
133 
134    if (mode == GL_POINT) {
135       RASTERIZE(GL_POINTS);
136       if (ef[e0]) POINT( v[0] );
137       if (ef[e1]) POINT( v[1] );
138       if (ef[e2]) POINT( v[2] );
139       if (ef[e3]) POINT( v[3] );
140    }
141    else {
142       RASTERIZE(GL_LINES);
143       if (ef[e0]) LINE( v[0], v[1] );
144       if (ef[e1]) LINE( v[1], v[2] );
145       if (ef[e2]) LINE( v[2], v[3] );
146       if (ef[e3]) LINE( v[3], v[0] );
147    }
148 
149    if (ctx->Light.ShadeModel == GL_FLAT && HAVE_HW_FLATSHADE) {
150       VERT_RESTORE_RGBA(0);
151       VERT_RESTORE_RGBA(1);
152       VERT_RESTORE_RGBA(2);
153 
154       if (HAVE_SPEC) {
155 	 VERT_RESTORE_SPEC(0);
156 	 VERT_RESTORE_SPEC(1);
157 	 VERT_RESTORE_SPEC(2);
158       }
159    }
160 }
161 
162 
163 #if !HAVE_SPEC
164 #undef VERT_SET_SPEC
165 #undef VERT_COPY_SPEC
166 #undef VERT_SAVE_SPEC
167 #undef VERT_RESTORE_SPEC
168 #endif
169 
170 #undef TAG
171