1 /* $Id: t_vb_rendertmp.h,v 1.1 2000/12/26 05:09:33 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Keith Whitwell <keithw@valinux.com>
39 #ifndef NEED_EDGEFLAG_SETUP
40 #define NEED_EDGEFLAG_SETUP 0
41 #define EDGEFLAG_GET(a) 0
42 #define EDGEFLAG_SET(a,b)
49 #ifndef RESET_OCCLUSION
50 #define RESET_OCCLUSION
54 #define TEST_PRIM_END(flags) (flags & PRIM_END)
55 #define TEST_PRIM_BEGIN(flags) (flags & PRIM_BEGIN)
56 #define TEST_PRIM_PARITY(flags) (flags & PRIM_PARITY)
63 static void TAG(render_points
)( GLcontext
*ctx
,
73 RENDER_POINTS( start
, count
);
77 static void TAG(render_lines
)( GLcontext
*ctx
,
88 for (j
=start
+1; j
<count
; j
+=2 ) {
89 RENDER_LINE( ELT(j
-1), ELT(j
) );
96 static void TAG(render_line_strip
)( GLcontext
*ctx
,
108 for (j
=start
+1; j
<count
; j
++ ) {
109 RENDER_LINE( ELT(j
-1), ELT(j
) );
112 if (TEST_PRIM_END(flags
))
119 static void TAG(render_line_loop
)( GLcontext
*ctx
,
132 if (start
+1 < count
) {
133 if (TEST_PRIM_BEGIN(flags
)) {
134 RENDER_LINE( ELT(start
), ELT(start
+1) );
137 for ( i
= start
+2 ; i
< count
; i
++) {
138 RENDER_LINE( ELT(i
-1), ELT(i
) );
141 if ( TEST_PRIM_END(flags
)) {
142 RENDER_LINE( ELT(count
-1), ELT(start
) );
151 static void TAG(render_triangles
)( GLcontext
*ctx
,
161 if (NEED_EDGEFLAG_SETUP
) {
162 for (j
=start
+2; j
<count
; j
+=3) {
163 /* Leave the edgeflags as supplied by the user.
165 RENDER_TRI( ELT(j
-2), ELT(j
-1), ELT(j
), ELT(j
), 0 );
169 for (j
=start
+2; j
<count
; j
+=3) {
170 RENDER_TRI( ELT(j
-2), ELT(j
-1), ELT(j
), ELT(j
), 0 );
178 static void TAG(render_tri_strip
)( GLcontext
*ctx
,
187 if (TEST_PRIM_PARITY(flags
))
191 if (NEED_EDGEFLAG_SETUP
) {
192 for (j
=start
+2;j
<count
;j
++,parity
^=1) {
193 /* All edges are boundary. Set edgeflags to 1, draw the
194 * triangle, and restore them to the original values.
196 GLuint ej2
= ELT(j
-2);
197 GLuint ej1
= ELT(j
-1);
199 GLboolean ef2
= EDGEFLAG_GET( ej2
);
200 GLboolean ef1
= EDGEFLAG_GET( ej1
);
201 GLboolean ef
= EDGEFLAG_GET( ej
);
202 EDGEFLAG_SET( ej2
, GL_TRUE
);
203 EDGEFLAG_SET( ej1
, GL_TRUE
);
204 EDGEFLAG_SET( ej
, GL_TRUE
);
205 RENDER_TRI( ej2
, ej1
, ej
, ej
, parity
);
206 EDGEFLAG_SET( ej2
, ef2
);
207 EDGEFLAG_SET( ej1
, ef1
);
208 EDGEFLAG_SET( ej
, ef
);
212 for (j
=start
+2;j
<count
;j
++,parity
^=1) {
213 RENDER_TRI( ELT(j
-2), ELT(j
-1), ELT(j
), ELT(j
), parity
);
220 static void TAG(render_tri_fan
)( GLcontext
*ctx
,
230 if (NEED_EDGEFLAG_SETUP
) {
231 for (j
=start
+2;j
<count
;j
++) {
232 /* For trifans, all edges are boundary.
234 GLuint ejs
= ELT(start
);
235 GLuint ej1
= ELT(j
-1);
237 GLboolean efs
= EDGEFLAG_GET( ejs
);
238 GLboolean ef1
= EDGEFLAG_GET( ej1
);
239 GLboolean ef
= EDGEFLAG_GET( ej
);
240 EDGEFLAG_SET( ejs
, GL_TRUE
);
241 EDGEFLAG_SET( ej1
, GL_TRUE
);
242 EDGEFLAG_SET( ej
, GL_TRUE
);
243 RENDER_TRI( ejs
, ej1
, ej
, ej
, 0);
244 EDGEFLAG_SET( ejs
, efs
);
245 EDGEFLAG_SET( ej1
, ef1
);
246 EDGEFLAG_SET( ej
, ef
);
250 for (j
=start
+2;j
<count
;j
++) {
251 RENDER_TRI( ELT(start
), ELT(j
-1), ELT(j
), ELT(j
), 0 );
259 /* This is a bit of a hack. Clipping produces polygons and really
260 * wants to use this function to render them (in particular to get the
261 * edgeflags right). However, the rule that pv==start for polys
262 * doens't hold there, hence the extra arg and the wrapper below.
264 static void TAG(render_poly_pv
)( GLcontext
*ctx
,
275 if (NEED_EDGEFLAG_SETUP
) {
276 if (start
+3 < count
) {
277 GLboolean efstart
= EDGEFLAG_GET( ELT(start
) );
278 GLboolean efcount
= EDGEFLAG_GET( ELT(count
-1) );
281 /* If the primitive does not begin here, the first edge
284 if (!TEST_PRIM_BEGIN(flags
))
285 EDGEFLAG_SET( ELT(start
), GL_FALSE
);
287 /* If the primitive does not end here, the final edge is
290 if (!TEST_PRIM_END(flags
))
291 EDGEFLAG_SET( ELT(count
-1), GL_FALSE
);
293 /* Draw the first triangle (possibly also the last).
296 GLboolean ef
= EDGEFLAG_GET( ELT(j
) );
297 EDGEFLAG_SET( ELT(j
), GL_FALSE
);
298 RENDER_TRI( ELT(start
), ELT(j
-1), ELT(j
), ELT(pv
), 0 );
299 EDGEFLAG_SET( ELT(j
), ef
);
303 /* For internal tris, the first and last edges are non-boundary.
305 EDGEFLAG_SET( ELT(start
), GL_FALSE
);
306 for (;j
<count
-1;j
++) {
307 GLboolean ef
= EDGEFLAG_GET( ELT(j
) );
308 EDGEFLAG_SET( ELT(j
), GL_FALSE
);
309 RENDER_TRI( ELT(start
), ELT(j
-1), ELT(j
), ELT(pv
), 0 );
310 EDGEFLAG_SET( ELT(j
), ef
);
313 /* Draw the last triangle
316 RENDER_TRI( ELT(start
), ELT(j
-1), ELT(j
), ELT(pv
), 0 );
320 /* Restore the first, last edgeflags:
322 EDGEFLAG_SET( ELT(count
-1), efcount
);
323 EDGEFLAG_SET( ELT(start
), efstart
);
326 if (TEST_PRIM_END(flags
)) {
331 for (j
=start
+2;j
<count
;j
++) {
332 RENDER_TRI( ELT(start
), ELT(j
-1), ELT(j
), ELT(start
), 0 );
338 static void TAG(render_poly
)( GLcontext
*ctx
,
343 TAG(render_poly_pv
)( ctx
, start
, count
, flags
, start
);
346 static void TAG(render_quads
)( GLcontext
*ctx
,
356 if (NEED_EDGEFLAG_SETUP
) {
357 for (j
=start
+3; j
<count
; j
+=4) {
358 /* Use user-specified edgeflags for quads.
360 RENDER_QUAD( ELT(j
-3), ELT(j
-2), ELT(j
-1), ELT(j
), ELT(j
) );
364 for (j
=start
+3; j
<count
; j
+=4) {
365 RENDER_QUAD( ELT(j
-3), ELT(j
-2), ELT(j
-1), ELT(j
), ELT(j
) );
371 static void TAG(render_quad_strip
)( GLcontext
*ctx
,
381 if (NEED_EDGEFLAG_SETUP
) {
382 for (j
=start
+3;j
<count
;j
+=2) {
383 /* All edges are boundary. Set edgeflags to 1, draw the
384 * quad, and restore them to the original values.
386 GLboolean ef3
= EDGEFLAG_GET( ELT(j
-3) );
387 GLboolean ef2
= EDGEFLAG_GET( ELT(j
-2) );
388 GLboolean ef1
= EDGEFLAG_GET( ELT(j
-1) );
389 GLboolean ef
= EDGEFLAG_GET( ELT(j
) );
390 EDGEFLAG_SET( ELT(j
-3), GL_TRUE
);
391 EDGEFLAG_SET( ELT(j
-2), GL_TRUE
);
392 EDGEFLAG_SET( ELT(j
-1), GL_TRUE
);
393 EDGEFLAG_SET( ELT(j
), GL_TRUE
);
394 RENDER_QUAD( ELT(j
-3), ELT(j
-2), ELT(j
), ELT(j
-1), ELT(j
) );
395 EDGEFLAG_SET( ELT(j
-3), ef3
);
396 EDGEFLAG_SET( ELT(j
-2), ef2
);
397 EDGEFLAG_SET( ELT(j
-1), ef1
);
398 EDGEFLAG_SET( ELT(j
), ef
);
402 for (j
=start
+3;j
<count
;j
+=2) {
403 RENDER_QUAD( ELT(j
-3), ELT(j
-2), ELT(j
), ELT(j
-1), ELT(j
) );
409 static void TAG(render_noop
)( GLcontext
*ctx
,
414 (void)(ctx
&& start
&& count
&& flags
);
417 static render_func
TAG(render_tab
)[GL_POLYGON
+2] = {
420 TAG(render_line_loop
),
421 TAG(render_line_strip
),
422 TAG(render_triangles
),
423 TAG(render_tri_strip
),
426 TAG(render_quad_strip
),
433 #ifndef PRESERVE_VB_DEFS
450 #undef PRESERVE_VB_DEFS