3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
38 #ifndef NEED_EDGEFLAG_SETUP
39 #define NEED_EDGEFLAG_SETUP 0
40 #define EDGEFLAG_GET(a) 0
41 #define EDGEFLAG_SET(a,b) (void)b
48 #ifndef RESET_OCCLUSION
49 #define RESET_OCCLUSION
53 #define TEST_PRIM_END(flags) (flags & PRIM_END)
54 #define TEST_PRIM_BEGIN(flags) (flags & PRIM_BEGIN)
55 #define TEST_PRIM_PARITY(flags) (flags & PRIM_PARITY)
62 #ifndef RENDER_TAB_QUALIFIER
63 #define RENDER_TAB_QUALIFIER static
66 static void TAG(render_points
)( GLcontext
*ctx
,
76 RENDER_POINTS( start
, count
);
80 static void TAG(render_lines
)( GLcontext
*ctx
,
91 for (j
=start
+1; j
<count
; j
+=2 ) {
92 RENDER_LINE( ELT(j
-1), ELT(j
) );
99 static void TAG(render_line_strip
)( GLcontext
*ctx
,
111 for (j
=start
+1; j
<count
; j
++ )
112 RENDER_LINE( ELT(j
-1), ELT(j
) );
114 if (TEST_PRIM_END(flags
))
121 static void TAG(render_line_loop
)( GLcontext
*ctx
,
134 if (start
+1 < count
) {
135 if (TEST_PRIM_BEGIN(flags
)) {
136 RENDER_LINE( ELT(start
), ELT(start
+1) );
139 for ( i
= start
+2 ; i
< count
; i
++) {
140 RENDER_LINE( ELT(i
-1), ELT(i
) );
143 if ( TEST_PRIM_END(flags
)) {
144 RENDER_LINE( ELT(count
-1), ELT(start
) );
153 static void TAG(render_triangles
)( GLcontext
*ctx
,
163 if (NEED_EDGEFLAG_SETUP
) {
164 for (j
=start
+2; j
<count
; j
+=3) {
165 /* Leave the edgeflags as supplied by the user.
167 RENDER_TRI( ELT(j
-2), ELT(j
-1), ELT(j
) );
171 for (j
=start
+2; j
<count
; j
+=3) {
172 RENDER_TRI( ELT(j
-2), ELT(j
-1), ELT(j
) );
180 static void TAG(render_tri_strip
)( GLcontext
*ctx
,
189 INIT(GL_TRIANGLE_STRIP
);
190 if (NEED_EDGEFLAG_SETUP
) {
191 for (j
=start
+2;j
<count
;j
++,parity
^=1) {
192 GLuint ej2
= ELT(j
-2+parity
);
193 GLuint ej1
= ELT(j
-1-parity
);
195 GLboolean ef2
= EDGEFLAG_GET( ej2
);
196 GLboolean ef1
= EDGEFLAG_GET( ej1
);
197 GLboolean ef
= EDGEFLAG_GET( ej
);
198 EDGEFLAG_SET( ej2
, GL_TRUE
);
199 EDGEFLAG_SET( ej1
, GL_TRUE
);
200 EDGEFLAG_SET( ej
, GL_TRUE
);
201 RENDER_TRI( ej2
, ej1
, ej
);
202 EDGEFLAG_SET( ej2
, ef2
);
203 EDGEFLAG_SET( ej1
, ef1
);
204 EDGEFLAG_SET( ej
, ef
);
208 for (j
=start
+2; j
<count
; j
++, parity
^=1) {
209 RENDER_TRI( ELT(j
-2+parity
), ELT(j
-1-parity
), ELT(j
) );
216 static void TAG(render_tri_fan
)( GLcontext
*ctx
,
225 INIT(GL_TRIANGLE_FAN
);
226 if (NEED_EDGEFLAG_SETUP
) {
227 for (j
=start
+2;j
<count
;j
++) {
228 /* For trifans, all edges are boundary.
230 GLuint ejs
= ELT(start
);
231 GLuint ej1
= ELT(j
-1);
233 GLboolean efs
= EDGEFLAG_GET( ejs
);
234 GLboolean ef1
= EDGEFLAG_GET( ej1
);
235 GLboolean ef
= EDGEFLAG_GET( ej
);
236 EDGEFLAG_SET( ejs
, GL_TRUE
);
237 EDGEFLAG_SET( ej1
, GL_TRUE
);
238 EDGEFLAG_SET( ej
, GL_TRUE
);
239 RENDER_TRI( ejs
, ej1
, ej
);
240 EDGEFLAG_SET( ejs
, efs
);
241 EDGEFLAG_SET( ej1
, ef1
);
242 EDGEFLAG_SET( ej
, ef
);
246 for (j
=start
+2;j
<count
;j
++) {
247 RENDER_TRI( ELT(start
), ELT(j
-1), ELT(j
) );
255 static void TAG(render_poly
)( GLcontext
*ctx
,
265 if (NEED_EDGEFLAG_SETUP
) {
266 GLboolean efstart
= EDGEFLAG_GET( ELT(start
) );
267 GLboolean efcount
= EDGEFLAG_GET( ELT(count
-1) );
269 /* If the primitive does not begin here, the first edge
272 if (!TEST_PRIM_BEGIN(flags
))
273 EDGEFLAG_SET( ELT(start
), GL_FALSE
);
275 /* If the primitive does not end here, the final edge is
278 if (!TEST_PRIM_END(flags
))
279 EDGEFLAG_SET( ELT(count
-1), GL_FALSE
);
281 /* Draw the first triangles (possibly zero)
284 GLboolean ef
= EDGEFLAG_GET( ELT(j
) );
285 EDGEFLAG_SET( ELT(j
), GL_FALSE
);
286 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
287 EDGEFLAG_SET( ELT(j
), ef
);
290 /* Don't render the first edge again:
292 EDGEFLAG_SET( ELT(start
), GL_FALSE
);
294 for (;j
<count
-1;j
++) {
295 GLboolean efj
= EDGEFLAG_GET( ELT(j
) );
296 EDGEFLAG_SET( ELT(j
), GL_FALSE
);
297 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
298 EDGEFLAG_SET( ELT(j
), efj
);
302 /* Draw the last or only triangle
305 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
307 /* Restore the first and last edgeflags:
309 EDGEFLAG_SET( ELT(count
-1), efcount
);
310 EDGEFLAG_SET( ELT(start
), efstart
);
312 if (TEST_PRIM_END(flags
)) {
317 for (j
=start
+2;j
<count
;j
++) {
318 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
324 static void TAG(render_quads
)( GLcontext
*ctx
,
334 if (NEED_EDGEFLAG_SETUP
) {
335 for (j
=start
+3; j
<count
; j
+=4) {
336 /* Use user-specified edgeflags for quads.
338 RENDER_QUAD( ELT(j
-3), ELT(j
-2), ELT(j
-1), ELT(j
) );
342 for (j
=start
+3; j
<count
; j
+=4) {
343 RENDER_QUAD( ELT(j
-3), ELT(j
-2), ELT(j
-1), ELT(j
) );
349 static void TAG(render_quad_strip
)( GLcontext
*ctx
,
359 if (NEED_EDGEFLAG_SETUP
) {
360 for (j
=start
+3;j
<count
;j
+=2) {
361 /* All edges are boundary. Set edgeflags to 1, draw the
362 * quad, and restore them to the original values.
364 GLboolean ef3
= EDGEFLAG_GET( ELT(j
-3) );
365 GLboolean ef2
= EDGEFLAG_GET( ELT(j
-2) );
366 GLboolean ef1
= EDGEFLAG_GET( ELT(j
-1) );
367 GLboolean ef
= EDGEFLAG_GET( ELT(j
) );
368 EDGEFLAG_SET( ELT(j
-3), GL_TRUE
);
369 EDGEFLAG_SET( ELT(j
-2), GL_TRUE
);
370 EDGEFLAG_SET( ELT(j
-1), GL_TRUE
);
371 EDGEFLAG_SET( ELT(j
), GL_TRUE
);
372 RENDER_QUAD( ELT(j
-1), ELT(j
-3), ELT(j
-2), ELT(j
) );
373 EDGEFLAG_SET( ELT(j
-3), ef3
);
374 EDGEFLAG_SET( ELT(j
-2), ef2
);
375 EDGEFLAG_SET( ELT(j
-1), ef1
);
376 EDGEFLAG_SET( ELT(j
), ef
);
380 for (j
=start
+3;j
<count
;j
+=2) {
381 RENDER_QUAD( ELT(j
-1), ELT(j
-3), ELT(j
-2), ELT(j
) );
387 static void TAG(render_noop
)( GLcontext
*ctx
,
392 (void)(ctx
&& start
&& count
&& flags
);
395 RENDER_TAB_QUALIFIER
void (*TAG(render_tab
)[GL_POLYGON
+2])(GLcontext
*,
402 TAG(render_line_loop
),
403 TAG(render_line_strip
),
404 TAG(render_triangles
),
405 TAG(render_tri_strip
),
408 TAG(render_quad_strip
),
415 #ifndef PRESERVE_VB_DEFS
426 #undef RENDER_TAB_QUALIFIER
433 #undef PRESERVE_VB_DEFS