2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keith@tungstengraphics.com>
37 #ifndef NEED_EDGEFLAG_SETUP
38 #define NEED_EDGEFLAG_SETUP 0
39 #define EDGEFLAG_GET(a) 0
40 #define EDGEFLAG_SET(a,b) (void)b
48 #define TEST_PRIM_END(prim) (flags & PRIM_END)
49 #define TEST_PRIM_BEGIN(prim) (flags & PRIM_BEGIN)
56 #ifndef RENDER_TAB_QUALIFIER
57 #define RENDER_TAB_QUALIFIER static
60 static void TAG(render_points
)( GLcontext
*ctx
,
69 RENDER_POINTS( start
, count
);
73 static void TAG(render_lines
)( GLcontext
*ctx
,
83 for (j
=start
+1; j
<count
; j
+=2 ) {
85 RENDER_LINE( ELT(j
-1), ELT(j
) );
91 static void TAG(render_line_strip
)( GLcontext
*ctx
,
102 if (TEST_PRIM_BEGIN(flags
)) {
106 for (j
=start
+1; j
<count
; j
++ )
107 RENDER_LINE( ELT(j
-1), ELT(j
) );
113 static void TAG(render_line_loop
)( GLcontext
*ctx
,
125 if (start
+1 < count
) {
126 if (TEST_PRIM_BEGIN(flags
)) {
128 RENDER_LINE( ELT(start
), ELT(start
+1) );
131 for ( i
= start
+2 ; i
< count
; i
++) {
132 RENDER_LINE( ELT(i
-1), ELT(i
) );
135 if ( TEST_PRIM_END(flags
)) {
136 RENDER_LINE( ELT(count
-1), ELT(start
) );
144 static void TAG(render_triangles
)( GLcontext
*ctx
,
154 if (NEED_EDGEFLAG_SETUP
) {
155 for (j
=start
+2; j
<count
; j
+=3) {
156 /* Leave the edgeflags as supplied by the user.
159 RENDER_TRI( ELT(j
-2), ELT(j
-1), ELT(j
) );
162 for (j
=start
+2; j
<count
; j
+=3) {
163 RENDER_TRI( ELT(j
-2), ELT(j
-1), ELT(j
) );
171 static void TAG(render_tri_strip
)( GLcontext
*ctx
,
180 INIT(GL_TRIANGLE_STRIP
);
181 if (NEED_EDGEFLAG_SETUP
) {
182 for (j
=start
+2;j
<count
;j
++,parity
^=1) {
183 GLuint ej2
= ELT(j
-2+parity
);
184 GLuint ej1
= ELT(j
-1-parity
);
186 GLboolean ef2
= EDGEFLAG_GET( ej2
);
187 GLboolean ef1
= EDGEFLAG_GET( ej1
);
188 GLboolean ef
= EDGEFLAG_GET( ej
);
189 if (TEST_PRIM_BEGIN(flags
)) {
192 EDGEFLAG_SET( ej2
, GL_TRUE
);
193 EDGEFLAG_SET( ej1
, GL_TRUE
);
194 EDGEFLAG_SET( ej
, GL_TRUE
);
195 RENDER_TRI( ej2
, ej1
, ej
);
196 EDGEFLAG_SET( ej2
, ef2
);
197 EDGEFLAG_SET( ej1
, ef1
);
198 EDGEFLAG_SET( ej
, ef
);
201 for (j
=start
+2; j
<count
; j
++, parity
^=1) {
202 RENDER_TRI( ELT(j
-2+parity
), ELT(j
-1-parity
), ELT(j
) );
209 static void TAG(render_tri_fan
)( GLcontext
*ctx
,
218 INIT(GL_TRIANGLE_FAN
);
219 if (NEED_EDGEFLAG_SETUP
) {
220 for (j
=start
+2;j
<count
;j
++) {
221 /* For trifans, all edges are boundary.
223 GLuint ejs
= ELT(start
);
224 GLuint ej1
= ELT(j
-1);
226 GLboolean efs
= EDGEFLAG_GET( ejs
);
227 GLboolean ef1
= EDGEFLAG_GET( ej1
);
228 GLboolean ef
= EDGEFLAG_GET( ej
);
229 if (TEST_PRIM_BEGIN(flags
)) {
232 EDGEFLAG_SET( ejs
, GL_TRUE
);
233 EDGEFLAG_SET( ej1
, GL_TRUE
);
234 EDGEFLAG_SET( ej
, GL_TRUE
);
235 RENDER_TRI( ejs
, ej1
, ej
);
236 EDGEFLAG_SET( ejs
, efs
);
237 EDGEFLAG_SET( ej1
, ef1
);
238 EDGEFLAG_SET( ej
, ef
);
241 for (j
=start
+2;j
<count
;j
++) {
242 RENDER_TRI( ELT(start
), ELT(j
-1), ELT(j
) );
250 static void TAG(render_poly
)( GLcontext
*ctx
,
260 if (NEED_EDGEFLAG_SETUP
) {
261 GLboolean efstart
= EDGEFLAG_GET( ELT(start
) );
262 GLboolean efcount
= EDGEFLAG_GET( ELT(count
-1) );
264 /* If the primitive does not begin here, the first edge
267 if (!TEST_PRIM_BEGIN(flags
))
268 EDGEFLAG_SET( ELT(start
), GL_FALSE
);
273 /* If the primitive does not end here, the final edge is
276 if (!TEST_PRIM_END(flags
))
277 EDGEFLAG_SET( ELT(count
-1), GL_FALSE
);
279 /* Draw the first triangles (possibly zero)
282 GLboolean ef
= EDGEFLAG_GET( ELT(j
) );
283 EDGEFLAG_SET( ELT(j
), GL_FALSE
);
284 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
285 EDGEFLAG_SET( ELT(j
), ef
);
288 /* Don't render the first edge again:
290 EDGEFLAG_SET( ELT(start
), GL_FALSE
);
292 for (;j
+1<count
;j
++) {
293 GLboolean efj
= EDGEFLAG_GET( ELT(j
) );
294 EDGEFLAG_SET( ELT(j
), GL_FALSE
);
295 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
296 EDGEFLAG_SET( ELT(j
), efj
);
300 /* Draw the last or only triangle
303 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
305 /* Restore the first and last edgeflags:
307 EDGEFLAG_SET( ELT(count
-1), efcount
);
308 EDGEFLAG_SET( ELT(start
), efstart
);
312 for (j
=start
+2;j
<count
;j
++) {
313 RENDER_TRI( ELT(j
-1), ELT(j
), ELT(start
) );
319 static void TAG(render_quads
)( GLcontext
*ctx
,
329 if (NEED_EDGEFLAG_SETUP
) {
330 for (j
=start
+3; j
<count
; j
+=4) {
331 /* Use user-specified edgeflags for quads.
334 RENDER_QUAD( ELT(j
-3), ELT(j
-2), ELT(j
-1), ELT(j
) );
337 for (j
=start
+3; j
<count
; j
+=4) {
338 RENDER_QUAD( ELT(j
-3), ELT(j
-2), ELT(j
-1), ELT(j
) );
344 static void TAG(render_quad_strip
)( GLcontext
*ctx
,
354 if (NEED_EDGEFLAG_SETUP
) {
355 for (j
=start
+3;j
<count
;j
+=2) {
356 /* All edges are boundary. Set edgeflags to 1, draw the
357 * quad, and restore them to the original values.
359 GLboolean ef3
= EDGEFLAG_GET( ELT(j
-3) );
360 GLboolean ef2
= EDGEFLAG_GET( ELT(j
-2) );
361 GLboolean ef1
= EDGEFLAG_GET( ELT(j
-1) );
362 GLboolean ef
= EDGEFLAG_GET( ELT(j
) );
363 if (TEST_PRIM_BEGIN(flags
)) {
366 EDGEFLAG_SET( ELT(j
-3), GL_TRUE
);
367 EDGEFLAG_SET( ELT(j
-2), GL_TRUE
);
368 EDGEFLAG_SET( ELT(j
-1), GL_TRUE
);
369 EDGEFLAG_SET( ELT(j
), GL_TRUE
);
370 RENDER_QUAD( ELT(j
-1), ELT(j
-3), ELT(j
-2), ELT(j
) );
371 EDGEFLAG_SET( ELT(j
-3), ef3
);
372 EDGEFLAG_SET( ELT(j
-2), ef2
);
373 EDGEFLAG_SET( ELT(j
-1), ef1
);
374 EDGEFLAG_SET( ELT(j
), ef
);
377 for (j
=start
+3;j
<count
;j
+=2) {
378 RENDER_QUAD( ELT(j
-1), ELT(j
-3), ELT(j
-2), ELT(j
) );
384 static void TAG(render_noop
)( GLcontext
*ctx
,
389 (void)(ctx
&& start
&& count
&& flags
);
392 RENDER_TAB_QUALIFIER
void (*TAG(render_tab
)[GL_POLYGON
+2])(GLcontext
*,
399 TAG(render_line_loop
),
400 TAG(render_line_strip
),
401 TAG(render_triangles
),
402 TAG(render_tri_strip
),
405 TAG(render_quad_strip
),
412 #ifndef PRESERVE_VB_DEFS
423 #undef RENDER_TAB_QUALIFIER
430 #undef PRESERVE_VB_DEFS