Add render stage for unclipped vb's to fx driver.
[mesa.git] / src / mesa / tnl / t_vb_render.c
1 /* $Id: t_vb_render.c,v 1.4 2000/12/28 22:11:06 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28 /*
29 * Render whole vertex buffers, including projection of vertices from
30 * clip space and clipping of primitives.
31 *
32 * This file makes calls to project vertices and to the point, line
33 * and triangle rasterizers via the function pointers:
34 *
35 * context->Driver.BuildProjectedVertices()
36 * context->Driver.PointsFunc()
37 * context->Driver.LineFunc()
38 * context->Driver.TriangleFunc()
39 * context->Driver.QuadFunc()
40 *
41 */
42
43
44 #include "glheader.h"
45 #include "context.h"
46 #include "colormac.h"
47 #include "macros.h"
48 #include "mem.h"
49 #include "mtypes.h"
50 #include "mmath.h"
51
52 #include "math/m_matrix.h"
53 #include "math/m_xform.h"
54
55 #include "t_pipeline.h"
56
57
58 typedef GLuint (*interp_func)( GLcontext *ctx,
59 GLfloat t, GLuint in, GLuint out,
60 GLboolean force_boundary );
61
62 typedef void (*clip_line_func)( GLcontext *ctx,
63 GLuint i, GLuint j,
64 GLubyte mask);
65
66 typedef void (*clip_poly_func)( GLcontext *ctx,
67 GLuint n, GLuint vlist[],
68 GLuint pv, GLubyte mask );
69
70
71 typedef void (*render_func)( GLcontext *ctx,
72 GLuint start,
73 GLuint count,
74 GLuint flags );
75
76
77
78 struct render_stage_data {
79
80 /* Clipping functions for current state.
81 */
82 interp_func interp; /* Clip interpolation function */
83 GLuint _ClipInputs; /* Inputs referenced by interpfunc */
84
85 };
86
87 #define RENDER_STAGE_DATA(stage) ((struct render_stage_data *)stage->private)
88
89 static void render_poly_pv_raw_elts( GLcontext *ctx,
90 GLuint start,
91 GLuint count,
92 GLuint flags,
93 GLuint pv );
94
95 /**********************************************************************/
96 /* Interpolate between pairs of vertices */
97 /**********************************************************************/
98
99
100 #define INTERP_RGBA 0x1
101 #define INTERP_TEX 0x2
102 #define INTERP_INDEX 0x4
103 #define INTERP_SPEC 0x8
104 #define INTERP_FOG 0x10
105 #define INTERP_EDGE 0x20
106 #define MAX_INTERP 0x40
107
108
109 #define LINTERP_SZ( t, vec, to, a, b, sz ) \
110 do { \
111 switch (sz) { \
112 case 4: vec[to][3] = LINTERP( t, vec[a][3], vec[b][3] ); \
113 case 3: vec[to][2] = LINTERP( t, vec[a][2], vec[b][2] ); \
114 case 2: vec[to][1] = LINTERP( t, vec[a][1], vec[b][1] ); \
115 case 1: vec[to][0] = LINTERP( t, vec[a][0], vec[b][0] ); \
116 } \
117 } while(0)
118
119
120 #if 1
121
122 #define LINTERP_RGBA(nr, t, out, a, b) { \
123 int i; \
124 for (i = 0; i < nr; i++) { \
125 GLfloat fa = CHAN_TO_FLOAT(a[i]); \
126 GLfloat fb = CHAN_TO_FLOAT(b[i]); \
127 GLfloat fo = LINTERP(t, fa, fb); \
128 FLOAT_COLOR_TO_CHAN(out[i], fo); \
129 } \
130 }
131
132 #else
133
134 #define LINTERP_RGBA(nr, t, out, a, b) { \
135 int n; \
136 const GLuint ti = FloatToInt(t*256.0F); \
137 const GLubyte *Ib = (const GLubyte *)&a[0]; \
138 const GLubyte *Jb = (const GLubyte *)&b[0]; \
139 GLubyte *Ob = (GLubyte *)&out[0]; \
140 \
141 for (n = 0 ; n < nr ; n++) \
142 Ob[n] = (GLubyte) (Ib[n] + ((ti * (Jb[n] - Ib[n]))/256)); \
143 }
144
145 #endif
146
147
148
149 static interp_func interp_tab[0x80];
150
151
152 #define IND (INTERP_RGBA)
153 #define NAME interp_RGBA
154 #include "t_vb_interptmp.h"
155
156 #define IND (INTERP_RGBA|INTERP_SPEC)
157 #define NAME interp_RGBA_SPEC
158 #include "t_vb_interptmp.h"
159
160 #define IND (INTERP_RGBA|INTERP_FOG)
161 #define NAME interp_RGBA_FOG
162 #include "t_vb_interptmp.h"
163
164 #define IND (INTERP_RGBA|INTERP_SPEC|INTERP_FOG)
165 #define NAME interp_RGBA_SPEC_FOG
166 #include "t_vb_interptmp.h"
167
168 #define IND (INTERP_RGBA|INTERP_TEX)
169 #define NAME interp_RGBA_TEX
170 #include "t_vb_interptmp.h"
171
172 #define IND (INTERP_RGBA|INTERP_SPEC|INTERP_TEX)
173 #define NAME interp_RGBA_SPEC_TEX
174 #include "t_vb_interptmp.h"
175
176 #define IND (INTERP_RGBA|INTERP_FOG|INTERP_TEX)
177 #define NAME interp_RGBA_FOG_TEX
178 #include "t_vb_interptmp.h"
179
180 #define IND (INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_TEX)
181 #define NAME interp_RGBA_SPEC_FOG_TEX
182 #include "t_vb_interptmp.h"
183
184 #define IND (INTERP_INDEX)
185 #define NAME interp_INDEX
186 #include "t_vb_interptmp.h"
187
188 #define IND (INTERP_FOG|INTERP_INDEX)
189 #define NAME interp_FOG_INDEX
190 #include "t_vb_interptmp.h"
191
192 #define IND (INTERP_TEX|INTERP_INDEX)
193 #define NAME interp_TEX_INDEX
194 #include "t_vb_interptmp.h"
195
196 #define IND (INTERP_FOG|INTERP_TEX|INTERP_INDEX)
197 #define NAME interp_FOG_TEX_INDEX
198 #include "t_vb_interptmp.h"
199
200 #define IND (INTERP_RGBA|INTERP_EDGE)
201 #define NAME interp_RGBA_EDGE
202 #include "t_vb_interptmp.h"
203
204 #define IND (INTERP_RGBA|INTERP_SPEC|INTERP_EDGE)
205 #define NAME interp_RGBA_SPEC_EDGE
206 #include "t_vb_interptmp.h"
207
208 #define IND (INTERP_RGBA|INTERP_FOG|INTERP_EDGE)
209 #define NAME interp_RGBA_FOG_EDGE
210 #include "t_vb_interptmp.h"
211
212 #define IND (INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_EDGE)
213 #define NAME interp_RGBA_SPEC_FOG_EDGE
214 #include "t_vb_interptmp.h"
215
216 #define IND (INTERP_RGBA|INTERP_TEX|INTERP_EDGE)
217 #define NAME interp_RGBA_TEX_EDGE
218 #include "t_vb_interptmp.h"
219
220 #define IND (INTERP_RGBA|INTERP_SPEC|INTERP_TEX|INTERP_EDGE)
221 #define NAME interp_RGBA_SPEC_TEX_EDGE
222 #include "t_vb_interptmp.h"
223
224 #define IND (INTERP_RGBA|INTERP_FOG|INTERP_TEX|INTERP_EDGE)
225 #define NAME interp_RGBA_FOG_TEX_EDGE
226 #include "t_vb_interptmp.h"
227
228 #define IND (INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_TEX|INTERP_EDGE)
229 #define NAME interp_RGBA_SPEC_FOG_TEX_EDGE
230 #include "t_vb_interptmp.h"
231
232 #define IND (INTERP_INDEX|INTERP_EDGE)
233 #define NAME interp_INDEX_EDGE
234 #include "t_vb_interptmp.h"
235
236 #define IND (INTERP_FOG|INTERP_INDEX|INTERP_EDGE)
237 #define NAME interp_FOG_INDEX_EDGE
238 #include "t_vb_interptmp.h"
239
240 #define IND (INTERP_TEX|INTERP_INDEX|INTERP_EDGE)
241 #define NAME interp_TEX_INDEX_EDGE
242 #include "t_vb_interptmp.h"
243
244 #define IND (INTERP_FOG|INTERP_TEX|INTERP_INDEX|INTERP_EDGE)
245 #define NAME interp_FOG_TEX_INDEX_EDGE
246 #include "t_vb_interptmp.h"
247
248
249
250 static GLuint interp_invalid( GLcontext *ctx,
251 GLfloat t,
252 GLuint in, GLuint out,
253 GLboolean boundary )
254 {
255 (void)(ctx && t && in && out && boundary);
256 fprintf(stderr, "Invalid interpolation function in t_vbrender.c\n");
257 return in;
258 }
259
260
261 static void interp_init( void )
262 {
263 GLuint i;
264
265 /* Use the maximal function as the default. I don't believe any of
266 * the non-implemented combinations are reachable, but this gives
267 * some safety from crashes.
268 */
269 for (i = 0 ; i < Elements(interp_tab) ; i++)
270 interp_tab[i] = interp_invalid;
271
272 interp_tab[INTERP_RGBA] = interp_RGBA;
273 interp_tab[INTERP_RGBA|INTERP_SPEC] = interp_RGBA_SPEC;
274 interp_tab[INTERP_RGBA|INTERP_FOG] = interp_RGBA_FOG;
275 interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_FOG] = interp_RGBA_SPEC_FOG;
276 interp_tab[INTERP_RGBA|INTERP_TEX] = interp_RGBA_TEX;
277 interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_TEX] = interp_RGBA_SPEC_TEX;
278 interp_tab[INTERP_RGBA|INTERP_FOG|INTERP_TEX] = interp_RGBA_FOG_TEX;
279 interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_TEX] = interp_RGBA_SPEC_FOG_TEX;
280 interp_tab[INTERP_INDEX] = interp_INDEX;
281 interp_tab[INTERP_FOG|INTERP_INDEX] = interp_FOG_INDEX;
282 interp_tab[INTERP_TEX|INTERP_INDEX] = interp_TEX_INDEX;
283 interp_tab[INTERP_FOG|INTERP_TEX|INTERP_INDEX] = interp_FOG_TEX_INDEX;
284 interp_tab[INTERP_RGBA|INTERP_EDGE] = interp_RGBA_EDGE;
285 interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_EDGE] = interp_RGBA_SPEC_EDGE;
286 interp_tab[INTERP_RGBA|INTERP_FOG|INTERP_EDGE] = interp_RGBA_FOG_EDGE;
287 interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_EDGE] = interp_RGBA_SPEC_FOG_EDGE;
288 interp_tab[INTERP_RGBA|INTERP_TEX|INTERP_EDGE] = interp_RGBA_TEX_EDGE;
289 interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_TEX|INTERP_EDGE] = interp_RGBA_SPEC_TEX_EDGE;
290 interp_tab[INTERP_RGBA|INTERP_FOG|INTERP_TEX|INTERP_EDGE] = interp_RGBA_FOG_TEX_EDGE;
291 interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_TEX|INTERP_EDGE] = interp_RGBA_SPEC_FOG_TEX_EDGE;
292 interp_tab[INTERP_INDEX|INTERP_EDGE] = interp_INDEX_EDGE;
293 interp_tab[INTERP_FOG|INTERP_INDEX|INTERP_EDGE] = interp_FOG_INDEX_EDGE;
294 interp_tab[INTERP_TEX|INTERP_INDEX|INTERP_EDGE] = interp_TEX_INDEX_EDGE;
295 interp_tab[INTERP_FOG|INTERP_TEX|INTERP_INDEX|INTERP_EDGE] = interp_FOG_TEX_INDEX_EDGE;
296 }
297
298
299 /**********************************************************************/
300 /* Clip single primitives */
301 /**********************************************************************/
302
303
304 #if 0
305 #define NEGATIVE(x) ((*(int *)&x)<0)
306 #define DIFFERENT_SIGNS(a,b) ((a*b) < 0)
307 #else
308 #define NEGATIVE(x) (x < 0)
309 #define DIFFERENT_SIGNS(a,b) ((a*b) < 0)
310 #endif
311
312 #define W(i) coord[i][3]
313 #define Z(i) coord[i][2]
314 #define Y(i) coord[i][1]
315 #define X(i) coord[i][0]
316 #define SIZE 4
317 #define TAG(x) x##_4
318 #include "t_vb_cliptmp.h"
319
320 #define W(i) 1.0
321 #define Z(i) coord[i][2]
322 #define Y(i) coord[i][1]
323 #define X(i) coord[i][0]
324 #define SIZE 3
325 #define TAG(x) x##_3
326 #include "t_vb_cliptmp.h"
327
328 #define W(i) 1.0
329 #define Z(i) 0.0
330 #define Y(i) coord[i][1]
331 #define X(i) coord[i][0]
332 #define SIZE 2
333 #define TAG(x) x##_2
334 #include "t_vb_cliptmp.h"
335
336 static clip_poly_func clip_poly_tab[5] = {
337 0,
338 0,
339 viewclip_polygon_2,
340 viewclip_polygon_3,
341 viewclip_polygon_4
342 };
343
344 static clip_line_func clip_line_tab[5] = {
345 0,
346 0,
347 viewclip_line_2,
348 viewclip_line_3,
349 viewclip_line_4
350 };
351
352
353
354 /**********************************************************************/
355 /* Clip and render single primitives */
356 /**********************************************************************/
357
358
359
360 static INLINE void draw_line(GLcontext *ctx, GLuint v1, GLuint v2 )
361 {
362 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
363 GLubyte c1 = VB->ClipMask[v1], c2 = VB->ClipMask[v2];
364 GLubyte ormask = c1|c2;
365 if (!ormask)
366 ctx->Driver.LineFunc( ctx, v1, v2, v2 );
367 else if (!(c1 & c2 & 0x3f))
368 clip_line_tab[VB->ClipPtr->size]( ctx, v1, v2, ormask );
369 }
370
371 static INLINE void draw_triangle(GLcontext *ctx,
372 GLuint v1, GLuint v2, GLuint v3,
373 GLuint pv )
374 {
375 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
376 GLubyte c1 = VB->ClipMask[v1], c2 = VB->ClipMask[v2], c3 = VB->ClipMask[v3];
377 GLubyte ormask = c1|c2|c3;
378 if (!ormask)
379 ctx->Driver.TriangleFunc( ctx, v1, v2, v3, pv );
380 else if (!(c1 & c2 & c3 & 0x3f)) {
381 GLuint vlist[MAX_CLIPPED_VERTICES];
382 ASSIGN_3V(vlist, v1, v2, v3 );
383 clip_poly_tab[VB->ClipPtr->size]( ctx, 3, vlist, pv, ormask );
384 }
385 }
386
387
388 static INLINE void draw_quad( GLcontext *ctx,
389 GLuint v1, GLuint v2, GLuint v3,
390 GLuint v4, GLuint pv )
391 {
392 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
393 GLubyte c1 = VB->ClipMask[v1], c2 = VB->ClipMask[v2];
394 GLubyte c3 = VB->ClipMask[v3], c4 = VB->ClipMask[v4];
395 GLubyte ormask = c1|c2|c3|c4;
396 if (!ormask)
397 ctx->Driver.QuadFunc( ctx, v1, v2, v3, v4, pv );
398 else if (!(c1 & c2 & c3 & c4 & 0x3f)) {
399 GLuint vlist[MAX_CLIPPED_VERTICES];
400 ASSIGN_4V(vlist, v1, v2, v3, v4 );
401 clip_poly_tab[VB->ClipPtr->size]( ctx, 4, vlist, pv, ormask );
402 }
403 }
404
405
406 /**********************************************************************/
407 /* Clip and render whole begin/end objects */
408 /**********************************************************************/
409
410 #define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED)
411 #define EDGEFLAG_GET(idx) VB->EdgeFlagPtr->data[idx]
412 #define EDGEFLAG_SET(idx, val) VB->EdgeFlagPtr->data[idx] = val
413
414
415 /* Vertices, no clipping.
416 */
417 #define RENDER_POINTS( start, count ) \
418 ctx->Driver.PointsFunc( ctx, start, count-1 )
419
420 #define RENDER_LINE( i1, i ) \
421 ctx->Driver.LineFunc( ctx, i1, i, i )
422
423 #define RENDER_TRI( i2, i1, i, pv, parity ) \
424 do { \
425 if (parity) \
426 ctx->Driver.TriangleFunc( ctx, i1, i2, i, pv ); \
427 else \
428 ctx->Driver.TriangleFunc( ctx, i2, i1, i, pv ); \
429 } while (0)
430
431 #define RENDER_QUAD( i3, i2, i1, i, pv ) \
432 ctx->Driver.QuadFunc( ctx, i3, i2, i1, i, pv );
433
434 #define TAG(x) x##_raw
435
436 #define LOCAL_VARS \
437 struct vertex_buffer *VB = &(TNL_CONTEXT(ctx)->vb); \
438 (void) VB;
439
440 #define RESET_STIPPLE ctx->Driver.ResetLineStipple( ctx )
441 #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE;
442 #define PRESERVE_VB_DEFS
443 #include "t_vb_rendertmp.h"
444
445
446 /* Elts, no clipping.
447 */
448 #undef ELT
449 #undef TAG
450 #undef LOCAL_VARS
451 #define TAG(x) x##_raw_elts
452 #define ELT(x) elt[x]
453 #define LOCAL_VARS \
454 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; \
455 const GLuint * const elt = VB->Elts; \
456 (void) elt;
457 #include "t_vb_rendertmp.h"
458
459
460
461
462 /* Vertices, with the possibility of clipping.
463 */
464 #define RENDER_POINTS( start, count ) \
465 ctx->Driver.PointsFunc( ctx, start, count-1 )
466
467 #define RENDER_LINE( i1, i ) \
468 draw_line( ctx, i1, i )
469
470 #define RENDER_TRI( i2, i1, i, pv, parity) \
471 do { \
472 GLuint e2=i2, e1=i1; \
473 if (parity) { GLuint t=e2; e2=e1; e1=t; } \
474 draw_triangle(ctx,e2,e1,i,pv); \
475 } while (0)
476
477 #define RENDER_QUAD( i3, i2, i1, i, pv) \
478 draw_quad(ctx,i3,i2,i1,i,pv)
479
480
481 #define LOCAL_VARS \
482 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; \
483 (void)VB;
484
485 #define TAG(x) x##_clipped
486 #define RESET_STIPPLE ctx->Driver.ResetLineStipple( ctx )
487 #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE;
488 #define PRESERVE_VB_DEFS
489 #include "t_vb_rendertmp.h"
490
491
492
493 /* Elts, with the possibility of clipping.
494 */
495 #undef ELT
496 #undef TAG
497 #undef LOCAL_VARS
498 #define ELT(x) elt[x]
499 #define LOCAL_VARS \
500 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; \
501 const GLuint * const elt = VB->Elts; \
502 (void) elt;
503 #define TAG(x) x##_clipped_elts
504
505 #include "t_vb_rendertmp.h"
506
507
508
509 /**********************************************************************/
510 /* Clip and render whole vertex buffers */
511 /**********************************************************************/
512
513
514 static GLboolean run_render( GLcontext *ctx,
515 struct gl_pipeline_stage *stage )
516 {
517 TNLcontext *tnl = TNL_CONTEXT(ctx);
518 struct vertex_buffer *VB = &tnl->vb;
519 GLuint new_inputs = stage->changed_inputs;
520 render_func *tab;
521 GLint pass = 0;
522
523 /* return GL_FALSE; */
524
525 VB->interpfunc = (void *)RENDER_STAGE_DATA(stage)->interp;
526
527 if (new_inputs) {
528 GLuint importable = new_inputs & VB->importable_data;
529 GLuint interested = 0;
530
531 if (VB->ClipOrMask)
532 interested = ~0;
533
534 if (ctx->_TriangleCaps & DD_TRI_UNFILLED)
535 interested |= VERT_EDGE;
536
537 importable &= interested;
538
539 if (importable)
540 VB->import_data( ctx, importable, VEC_NOT_WRITEABLE|VEC_BAD_STRIDE);
541
542 if (ctx->Driver.BuildProjectedVertices)
543 ctx->Driver.BuildProjectedVertices( ctx, 0, VB->Count, new_inputs);
544 }
545
546 /* Rendering is considered a side-effect, and must be repeated each
547 * time the stage is run, even if no inputs have changed.
548 */
549 if (VB->Elts) {
550 tab = VB->ClipOrMask ? render_tab_clipped_elts : render_tab_raw_elts;
551 } else {
552 tab = VB->ClipOrMask ? render_tab_clipped : render_tab_raw;
553 }
554
555 if (ctx->Driver.RenderStart)
556 ctx->Driver.RenderStart( ctx );
557
558 do
559 {
560 GLuint i, length, flags = 0;
561 for (i = 0 ; !(flags & PRIM_LAST) ; i += length)
562 {
563 flags = VB->Primitive[i];
564 length= VB->PrimitiveLength[i];
565 ASSERT(length || (flags & PRIM_LAST));
566 ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1);
567 /* fprintf(stderr, "render %s %d..%d\n", */
568 /* _mesa_prim_name[flags & PRIM_MODE_MASK], */
569 /* i, i+length); */
570 if (length)
571 tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags );
572 }
573 } while (ctx->Driver.MultipassFunc &&
574 ctx->Driver.MultipassFunc( ctx, ++pass ));
575
576 if (ctx->Driver.RenderFinish)
577 ctx->Driver.RenderFinish( ctx );
578
579 return GL_FALSE; /* finished the pipe */
580 }
581
582
583 /**********************************************************************/
584 /* Render pipeline stage */
585 /**********************************************************************/
586
587
588
589 /* Quite a bit of work involved in finding out the inputs for the
590 * render stage. This function also identifies which vertex
591 * interpolation function to use, as these are essentially the same
592 * question.
593 */
594 static void check_render( GLcontext *ctx, struct gl_pipeline_stage *stage )
595 {
596 struct render_stage_data *store = RENDER_STAGE_DATA(stage);
597 GLuint interp = 0;
598 GLuint inputs = VERT_CLIP;
599 GLuint i;
600
601 if (ctx->Visual.RGBAflag)
602 {
603 interp |= INTERP_RGBA;
604 inputs |= VERT_RGBA;
605
606 if (ctx->_TriangleCaps & DD_SEPERATE_SPECULAR) {
607 interp |= INTERP_SPEC;
608 inputs |= VERT_SPEC_RGB;
609 }
610
611 if (ctx->Texture._ReallyEnabled) {
612 interp |= INTERP_TEX;
613
614 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) {
615 if (ctx->Texture.Unit[i]._ReallyEnabled)
616 inputs |= VERT_TEX(i);
617 }
618 }
619 }
620 else
621 {
622 interp |= INTERP_INDEX;
623 inputs |= VERT_INDEX;
624 }
625
626 if (ctx->Point._Attenuated)
627 inputs |= VERT_POINT_SIZE;
628
629 /* How do drivers turn this off?
630 */
631 if (ctx->Fog.Enabled) {
632 interp |= INTERP_FOG;
633 inputs |= VERT_FOG_COORD;
634 }
635
636 if (ctx->_TriangleCaps & DD_TRI_UNFILLED) {
637 inputs |= VERT_EDGE;
638 interp |= INTERP_EDGE;
639 }
640
641 if (ctx->RenderMode==GL_FEEDBACK) {
642 interp |= INTERP_TEX;
643 inputs |= VERT_TEX_ANY;
644 }
645
646 store->interp = interp_tab[interp];
647 stage->inputs = inputs;
648 }
649
650
651 /* Called the first time stage->check() is invoked.
652 */
653 static void alloc_render_data( GLcontext *ctx,
654 struct gl_pipeline_stage *stage )
655 {
656 struct render_stage_data *store;
657 static GLboolean first_time = 1;
658
659 if (first_time) {
660 interp_init();
661 first_time = 0;
662 }
663
664 stage->private = MALLOC(sizeof(*store));
665 if (!stage->private)
666 return;
667
668 /* Now do the check.
669 */
670 stage->check = check_render;
671 stage->check( ctx, stage );
672 }
673
674
675
676 static void dtr( struct gl_pipeline_stage *stage )
677 {
678 struct render_stage_data *store = RENDER_STAGE_DATA(stage);
679 if (store) {
680 FREE( store );
681 stage->private = 0;
682 }
683 }
684
685
686 const struct gl_pipeline_stage _tnl_render_stage =
687 {
688 "render",
689 (_NEW_BUFFERS |
690 _DD_NEW_SEPERATE_SPECULAR |
691 _NEW_TEXTURE|
692 _NEW_LIGHT|
693 _NEW_POINT|
694 _NEW_FOG|
695 _DD_NEW_TRI_UNFILLED |
696 _NEW_RENDERMODE), /* re-check (new inputs, interp function) */
697 0, /* re-run (always runs) */
698 GL_TRUE, /* active */
699 0, 0, /* inputs (set in check_render), outputs */
700 0, 0, /* changed_inputs, private */
701 dtr, /* destructor */
702 alloc_render_data, /* check - initially set to alloc data */
703 run_render /* run */
704 };