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)
61 #ifndef RENDER_TAB_QUALIFIER
62 #define RENDER_TAB_QUALIFIER static
65 static void TAG(render_points
)( GLcontext
*ctx
,
75 RENDER_POINTS( start
, count
);
79 static void TAG(render_lines
)( GLcontext
*ctx
,
90 for (j
=start
+1; j
<count
; j
+=2 ) {
92 RENDER_LINE( ELT(j
-1), ELT(j
) );
98 static void TAG(render_line_strip
)( GLcontext
*ctx
,
110 if (TEST_PRIM_BEGIN(flags
)) {
114 for (j
=start
+1; j
<count
; j
++ )
115 RENDER_LINE( ELT(j
-1), ELT(j
) );
121 static void TAG(render_line_loop
)( GLcontext
*ctx
,
134 if (start
+1 < count
) {
135 if (TEST_PRIM_BEGIN(flags
)) {
137 RENDER_LINE( ELT(start
), ELT(start
+1) );
140 for ( i
= start
+2 ; i
< count
; i
++) {
141 RENDER_LINE( ELT(i
-1), ELT(i
) );
144 if ( TEST_PRIM_END(flags
)) {
145 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.
168 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 if (TEST_PRIM_BEGIN(flags
)) {
201 EDGEFLAG_SET( ej2
, GL_TRUE
);
202 EDGEFLAG_SET( ej1
, GL_TRUE
);
203 EDGEFLAG_SET( ej
, GL_TRUE
);
204 RENDER_TRI( ej2
, ej1
, ej
);
205 EDGEFLAG_SET( ej2
, ef2
);
206 EDGEFLAG_SET( ej1
, ef1
);
207 EDGEFLAG_SET( ej
, ef
);
210 for (j
=start
+2; j
<count
; j
++, parity
^=1) {
211 RENDER_TRI( ELT(j
-2+parity
), ELT(j
-1-parity
), ELT(j
) );
218 static void TAG(render_tri_fan
)( GLcontext
*ctx
,
227 INIT(GL_TRIANGLE_FAN
);
228 if (NEED_EDGEFLAG_SETUP
) {
229 for (j
=start
+2;j
<count
;j
++) {
230 /* For trifans, all edges are boundary.
232 GLuint ejs
= ELT(start
);
233 GLuint ej1
= ELT(j
-1);
235 GLboolean efs
= EDGEFLAG_GET( ejs
);
236 GLboolean ef1
= EDGEFLAG_GET( ej1
);
237 GLboolean ef
= EDGEFLAG_GET( ej
);
238 if (TEST_PRIM_BEGIN(flags
)) {
241 EDGEFLAG_SET( ejs
, GL_TRUE
);
242 EDGEFLAG_SET( ej1
, GL_TRUE
);
243 EDGEFLAG_SET( ej
, GL_TRUE
);
244 RENDER_TRI( ejs
, ej1
, ej
);
245 EDGEFLAG_SET( ejs
, efs
);
246 EDGEFLAG_SET( ej1
, ef1
);
247 EDGEFLAG_SET( ej
, ef
);
250 for (j
=start
+2;j
<count
;j
++) {
251 RENDER_TRI( ELT(start
), ELT(j
-1), ELT(j
) );
259 static void TAG(render_poly
)( GLcontext
*ctx
,
269 if (NEED_EDGEFLAG_SETUP
) {
270 GLboolean efstart
= EDGEFLAG_GET( ELT(start
) );
271 GLboolean efcount
= EDGEFLAG_GET( ELT(count
-1) );
273 /* If the primitive does not begin here, the first edge
276 if (!TEST_PRIM_BEGIN(flags
))
277 EDGEFLAG_SET( ELT(start
), GL_FALSE
);
282 /* If the primitive does not end here, the final edge is
285 if (!TEST_PRIM_END(flags
))
286 EDGEFLAG_SET( ELT(count
-1), GL_FALSE
);
288 /* Draw the first triangles (possibly zero)
291 GLboolean ef
= EDGEFLAG_GET( ELT(j
) );
292 EDGEFLAG_SET( ELT(j
), GL_FALSE
);
293 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
294 EDGEFLAG_SET( ELT(j
), ef
);
297 /* Don't render the first edge again:
299 EDGEFLAG_SET( ELT(start
), GL_FALSE
);
301 for (;j
+1<count
;j
++) {
302 GLboolean efj
= EDGEFLAG_GET( ELT(j
) );
303 EDGEFLAG_SET( ELT(j
), GL_FALSE
);
304 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
305 EDGEFLAG_SET( ELT(j
), efj
);
309 /* Draw the last or only triangle
312 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
314 /* Restore the first and last edgeflags:
316 EDGEFLAG_SET( ELT(count
-1), efcount
);
317 EDGEFLAG_SET( ELT(start
), efstart
);
321 for (j
=start
+2;j
<count
;j
++) {
322 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
328 static void TAG(render_quads
)( GLcontext
*ctx
,
338 if (NEED_EDGEFLAG_SETUP
) {
339 for (j
=start
+3; j
<count
; j
+=4) {
340 /* Use user-specified edgeflags for quads.
343 RENDER_QUAD( ELT(j
-3), ELT(j
-2), ELT(j
-1), ELT(j
) );
346 for (j
=start
+3; j
<count
; j
+=4) {
347 RENDER_QUAD( ELT(j
-3), ELT(j
-2), ELT(j
-1), ELT(j
) );
353 static void TAG(render_quad_strip
)( GLcontext
*ctx
,
363 if (NEED_EDGEFLAG_SETUP
) {
364 for (j
=start
+3;j
<count
;j
+=2) {
365 /* All edges are boundary. Set edgeflags to 1, draw the
366 * quad, and restore them to the original values.
368 GLboolean ef3
= EDGEFLAG_GET( ELT(j
-3) );
369 GLboolean ef2
= EDGEFLAG_GET( ELT(j
-2) );
370 GLboolean ef1
= EDGEFLAG_GET( ELT(j
-1) );
371 GLboolean ef
= EDGEFLAG_GET( ELT(j
) );
372 if (TEST_PRIM_BEGIN(flags
)) {
375 EDGEFLAG_SET( ELT(j
-3), GL_TRUE
);
376 EDGEFLAG_SET( ELT(j
-2), GL_TRUE
);
377 EDGEFLAG_SET( ELT(j
-1), GL_TRUE
);
378 EDGEFLAG_SET( ELT(j
), GL_TRUE
);
379 RENDER_QUAD( ELT(j
-1), ELT(j
-3), ELT(j
-2), ELT(j
) );
380 EDGEFLAG_SET( ELT(j
-3), ef3
);
381 EDGEFLAG_SET( ELT(j
-2), ef2
);
382 EDGEFLAG_SET( ELT(j
-1), ef1
);
383 EDGEFLAG_SET( ELT(j
), ef
);
386 for (j
=start
+3;j
<count
;j
+=2) {
387 RENDER_QUAD( ELT(j
-1), ELT(j
-3), ELT(j
-2), ELT(j
) );
393 static void TAG(render_noop
)( GLcontext
*ctx
,
398 (void)(ctx
&& start
&& count
&& flags
);
401 RENDER_TAB_QUALIFIER
void (*TAG(render_tab
)[GL_POLYGON
+2])(GLcontext
*,
408 TAG(render_line_loop
),
409 TAG(render_line_strip
),
410 TAG(render_triangles
),
411 TAG(render_tri_strip
),
414 TAG(render_quad_strip
),
421 #ifndef PRESERVE_VB_DEFS
432 #undef RENDER_TAB_QUALIFIER
439 #undef PRESERVE_VB_DEFS