3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2003 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>
31 * Render whole vertex buffers, including projection of vertices from
32 * clip space and clipping of primitives.
34 * This file makes calls to project vertices and to the point, line
35 * and triangle rasterizers via the function pointers:
37 * context->Driver.Render.*
48 #include "nvfragprog.h"
49 #include "math/m_matrix.h"
50 #include "math/m_xform.h"
52 #include "t_pipeline.h"
56 /**********************************************************************/
57 /* Clip single primitives */
58 /**********************************************************************/
61 #define W(i) coord[i][3]
62 #define Z(i) coord[i][2]
63 #define Y(i) coord[i][1]
64 #define X(i) coord[i][0]
67 #include "t_vb_cliptmp.h"
71 /**********************************************************************/
72 /* Clip and render whole begin/end objects */
73 /**********************************************************************/
75 #define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL)
76 #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx]
77 #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
80 #define CLIPMASK (CLIP_ALL_BITS|CLIP_CULL_BIT)
83 /* Vertices, with the possibility of clipping.
85 #define RENDER_POINTS( start, count ) \
86 tnl->Driver.Render.Points( ctx, start, count )
88 #define RENDER_LINE( v1, v2 ) \
90 GLubyte c1 = mask[v1], c2 = mask[v2]; \
91 GLubyte ormask = c1|c2; \
93 LineFunc( ctx, v1, v2 ); \
94 else if (!(c1 & c2 & CLIPMASK)) \
95 clip_line_4( ctx, v1, v2, ormask ); \
98 #define RENDER_TRI( v1, v2, v3 ) \
100 GLubyte c1 = mask[v1], c2 = mask[v2], c3 = mask[v3]; \
101 GLubyte ormask = c1|c2|c3; \
103 TriangleFunc( ctx, v1, v2, v3 ); \
104 else if (!(c1 & c2 & c3 & CLIPMASK)) \
105 clip_tri_4( ctx, v1, v2, v3, ormask ); \
108 #define RENDER_QUAD( v1, v2, v3, v4 ) \
110 GLubyte c1 = mask[v1], c2 = mask[v2]; \
111 GLubyte c3 = mask[v3], c4 = mask[v4]; \
112 GLubyte ormask = c1|c2|c3|c4; \
114 QuadFunc( ctx, v1, v2, v3, v4 ); \
115 else if (!(c1 & c2 & c3 & c4 & CLIPMASK)) \
116 clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \
121 TNLcontext *tnl = TNL_CONTEXT(ctx); \
122 struct vertex_buffer *VB = &tnl->vb; \
123 const GLuint * const elt = VB->Elts; \
124 const GLubyte *mask = VB->ClipMask; \
125 const GLuint sz = VB->ClipPtr->size; \
126 const tnl_line_func LineFunc = tnl->Driver.Render.Line; \
127 const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \
128 const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \
129 const GLboolean stipple = ctx->Line.StippleFlag; \
130 (void) (LineFunc && TriangleFunc && QuadFunc); \
131 (void) elt; (void) mask; (void) sz; (void) stipple;
133 #define TAG(x) clip_##x##_verts
134 #define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x )
135 #define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx )
136 #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE
137 #define PRESERVE_VB_DEFS
138 #include "t_vb_rendertmp.h"
142 /* Elts, with the possibility of clipping.
146 #define ELT(x) elt[x]
147 #define TAG(x) clip_##x##_elts
148 #include "t_vb_rendertmp.h"
150 /* TODO: do this for all primitives, verts and elts:
152 static void clip_elt_triangles( GLcontext
*ctx
,
157 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
158 tnl_render_func render_tris
= tnl
->Driver
.Render
.PrimTabElts
[GL_TRIANGLES
];
159 struct vertex_buffer
*VB
= &tnl
->vb
;
160 const GLuint
* const elt
= VB
->Elts
;
161 GLubyte
*mask
= VB
->ClipMask
;
162 GLuint last
= count
-2;
166 tnl
->Driver
.Render
.PrimitiveNotify( ctx
, GL_TRIANGLES
);
168 for (j
=start
; j
< last
; j
+=3 ) {
169 GLubyte c1
= mask
[elt
[j
]];
170 GLubyte c2
= mask
[elt
[j
+1]];
171 GLubyte c3
= mask
[elt
[j
+2]];
172 GLubyte ormask
= c1
|c2
|c3
;
175 render_tris( ctx
, start
, j
, 0 );
176 if (!(c1
&c2
&c3
&CLIPMASK
))
177 clip_tri_4( ctx
, elt
[j
], elt
[j
+1], elt
[j
+2], ormask
);
183 render_tris( ctx
, start
, j
, 0 );
186 /**********************************************************************/
187 /* Render whole begin/end objects */
188 /**********************************************************************/
190 #define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL)
191 #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx]
192 #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
195 /* Vertices, no clipping.
197 #define RENDER_POINTS( start, count ) \
198 tnl->Driver.Render.Points( ctx, start, count )
200 #define RENDER_LINE( v1, v2 ) \
201 LineFunc( ctx, v1, v2 )
203 #define RENDER_TRI( v1, v2, v3 ) \
204 TriangleFunc( ctx, v1, v2, v3 )
206 #define RENDER_QUAD( v1, v2, v3, v4 ) \
207 QuadFunc( ctx, v1, v2, v3, v4 )
209 #define TAG(x) _tnl_##x##_verts
212 TNLcontext *tnl = TNL_CONTEXT(ctx); \
213 struct vertex_buffer *VB = &tnl->vb; \
214 const GLuint * const elt = VB->Elts; \
215 const tnl_line_func LineFunc = tnl->Driver.Render.Line; \
216 const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \
217 const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad; \
218 const GLboolean stipple = ctx->Line.StippleFlag; \
219 (void) (LineFunc && TriangleFunc && QuadFunc); \
220 (void) elt; (void) stipple
222 #define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx )
223 #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE
224 #define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x )
225 #define RENDER_TAB_QUALIFIER
226 #define PRESERVE_VB_DEFS
227 #include "t_vb_rendertmp.h"
230 /* Elts, no clipping.
233 #define TAG(x) _tnl_##x##_elts
234 #define ELT(x) elt[x]
235 #include "t_vb_rendertmp.h"
238 /**********************************************************************/
239 /* Helper functions for drivers */
240 /**********************************************************************/
242 void _tnl_RenderClippedPolygon( GLcontext
*ctx
, const GLuint
*elts
, GLuint n
)
244 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
245 struct vertex_buffer
*VB
= &tnl
->vb
;
246 GLuint
*tmp
= VB
->Elts
;
248 VB
->Elts
= (GLuint
*)elts
;
249 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
]( ctx
, 0, n
, PRIM_BEGIN
|PRIM_END
);
253 void _tnl_RenderClippedLine( GLcontext
*ctx
, GLuint ii
, GLuint jj
)
255 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
256 tnl
->Driver
.Render
.Line( ctx
, ii
, jj
);
261 /**********************************************************************/
262 /* Clip and render whole vertex buffers */
263 /**********************************************************************/
266 static GLboolean
run_render( GLcontext
*ctx
,
267 struct tnl_pipeline_stage
*stage
)
269 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
270 struct vertex_buffer
*VB
= &tnl
->vb
;
271 tnl_render_func
*tab
;
274 /* Allow the drivers to lock before projected verts are built so
275 * that window coordinates are guarenteed not to change before
278 ASSERT(tnl
->Driver
.Render
.Start
);
280 tnl
->Driver
.Render
.Start( ctx
);
282 ASSERT(tnl
->Driver
.Render
.BuildVertices
);
283 ASSERT(tnl
->Driver
.Render
.PrimitiveNotify
);
284 ASSERT(tnl
->Driver
.Render
.Points
);
285 ASSERT(tnl
->Driver
.Render
.Line
);
286 ASSERT(tnl
->Driver
.Render
.Triangle
);
287 ASSERT(tnl
->Driver
.Render
.Quad
);
288 ASSERT(tnl
->Driver
.Render
.ResetLineStipple
);
289 ASSERT(tnl
->Driver
.Render
.Interp
);
290 ASSERT(tnl
->Driver
.Render
.CopyPV
);
291 ASSERT(tnl
->Driver
.Render
.ClippedLine
);
292 ASSERT(tnl
->Driver
.Render
.ClippedPolygon
);
293 ASSERT(tnl
->Driver
.Render
.Finish
);
295 tnl
->Driver
.Render
.BuildVertices( ctx
, 0, VB
->Count
, ~0 );
297 if (VB
->ClipOrMask
) {
298 tab
= VB
->Elts
? clip_render_tab_elts
: clip_render_tab_verts
;
299 clip_render_tab_elts
[GL_TRIANGLES
] = clip_elt_triangles
;
303 tnl
->Driver
.Render
.PrimTabElts
:
304 tnl
->Driver
.Render
.PrimTabVerts
);
311 for (i
= 0 ; i
< VB
->PrimitiveCount
; i
++)
313 GLuint prim
= VB
->Primitive
[i
].mode
;
314 GLuint start
= VB
->Primitive
[i
].start
;
315 GLuint length
= VB
->Primitive
[i
].count
;
317 assert((prim
& PRIM_MODE_MASK
) < GL_POLYGON
+1);
319 if (MESA_VERBOSE
& VERBOSE_PRIMS
)
320 _mesa_debug(NULL
, "MESA prim %s %d..%d\n",
321 _mesa_lookup_enum_by_nr(prim
& PRIM_MODE_MASK
),
322 start
, start
+length
);
325 tab
[prim
& PRIM_MODE_MASK
]( ctx
, start
, start
+ length
, prim
);
327 } while (tnl
->Driver
.Render
.Multipass
&&
328 tnl
->Driver
.Render
.Multipass( ctx
, ++pass
));
330 tnl
->Driver
.Render
.Finish( ctx
);
332 return GL_FALSE
; /* finished the pipe */
336 /**********************************************************************/
337 /* Render pipeline stage */
338 /**********************************************************************/
344 const struct tnl_pipeline_stage _tnl_render_stage
=
347 NULL
, /* private data */
349 NULL
, /* destructor */