diff options
author | Keith Whitwell <keith@tungstengraphics.com> | 2001-01-29 20:47:39 +0000 |
---|---|---|
committer | Keith Whitwell <keith@tungstengraphics.com> | 2001-01-29 20:47:39 +0000 |
commit | 5c1e7fa6ee72f4403d9ec9d12830dd689b966e71 (patch) | |
tree | 8cb11c26af178632b05de9c5b2f53c32331475c5 /src/mesa/tnl | |
parent | 4b90e68ac6d0fe4ffca5e2cd51794bb4350cac28 (diff) |
Removed knowledge of swrast Clear/Bitmap/Accum/Draw/Read/CopyPixels
functions from core mesa -- if drivers need these fallbacks they
must now call them themselves.
Introduced hooks for clip-vertex-interpolation and the rendering
of clipped lines and polygons. Allows drivers to interpolate
their hardware-format vertices directly. Used in dri drivers to
replace fastpath code.
Slight optimizations to pipeline build/run routines.
Diffstat (limited to 'src/mesa/tnl')
-rw-r--r-- | src/mesa/tnl/t_context.h | 10 | ||||
-rw-r--r-- | src/mesa/tnl/t_imm_dlist.c | 7 | ||||
-rw-r--r-- | src/mesa/tnl/t_pipeline.c | 56 | ||||
-rw-r--r-- | src/mesa/tnl/t_vb_cliptmp.h | 146 | ||||
-rw-r--r-- | src/mesa/tnl/t_vb_render.c | 467 | ||||
-rw-r--r-- | src/mesa/tnl/t_vb_texgen.c | 43 | ||||
-rw-r--r-- | src/mesa/tnl/t_vb_vertex.c | 31 |
7 files changed, 224 insertions, 536 deletions
diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h index d3414be29b..c15dd13087 100644 --- a/src/mesa/tnl/t_context.h +++ b/src/mesa/tnl/t_context.h @@ -1,4 +1,4 @@ -/* $Id: t_context.h,v 1.12 2001/01/24 00:04:59 brianp Exp $ */ +/* $Id: t_context.h,v 1.13 2001/01/29 20:47:39 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -234,12 +234,6 @@ struct vertex_arrays typedef struct gl_material GLmaterial; -typedef void (*interp_func)( GLcontext *ctx, - GLfloat t, GLuint dst, GLuint in, GLuint out, - GLboolean force_boundary ); - -typedef void (*copy_pv_func)( GLcontext *ctx, GLuint dst, GLuint src ); - /* Contains the current state of a running pipeline. */ typedef struct vertex_buffer @@ -299,8 +293,6 @@ typedef struct vertex_buffer */ GLuint LastClipped; - interp_func interpfunc; - copy_pv_func copypvfunc; /* Private data from _tnl_render_stage that has no business being * in this struct. */ diff --git a/src/mesa/tnl/t_imm_dlist.c b/src/mesa/tnl/t_imm_dlist.c index b77344a7ac..3e1a9e266f 100644 --- a/src/mesa/tnl/t_imm_dlist.c +++ b/src/mesa/tnl/t_imm_dlist.c @@ -1,4 +1,4 @@ -/* $Id: t_imm_dlist.c,v 1.5 2001/01/08 21:56:00 keithw Exp $ */ +/* $Id: t_imm_dlist.c,v 1.6 2001/01/29 20:47:39 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -156,6 +156,9 @@ _tnl_compile_cassette( GLcontext *ctx, struct immediate *IM ) +#if 0 +/* Drivers to turn this on? + */ static void calc_normal_lengths( GLfloat *dest, CONST GLfloat (*data)[3], GLuint *flags, @@ -177,7 +180,7 @@ static void calc_normal_lengths( GLfloat *dest, flags[0] = tmpflag; } - +#endif static void diff --git a/src/mesa/tnl/t_pipeline.c b/src/mesa/tnl/t_pipeline.c index b2d4f15547..942b8ba21e 100644 --- a/src/mesa/tnl/t_pipeline.c +++ b/src/mesa/tnl/t_pipeline.c @@ -1,4 +1,4 @@ -/* $Id: t_pipeline.c,v 1.10 2001/01/17 02:49:39 keithw Exp $ */ +/* $Id: t_pipeline.c,v 1.11 2001/01/29 20:47:39 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -77,40 +77,50 @@ void _tnl_destroy_pipeline( GLcontext *ctx ) tnl->pipeline.nr_stages = 0; } - - +/* TODO: merge validate with run. + */ void _tnl_validate_pipeline( GLcontext *ctx ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct gl_pipeline *pipe = &tnl->pipeline; - struct gl_pipeline_stage *stage = pipe->stages; + struct gl_pipeline_stage *s = pipe->stages; GLuint newstate = pipe->build_state_changes; GLuint generated = 0; GLuint i; + GLuint changed_inputs = 0; pipe->inputs = 0; pipe->build_state_changes = 0; - for (i = 0 ; i < pipe->nr_stages ; i++) { - if (stage[i].check_state & newstate) { - stage[i].check(ctx, &stage[i]); + for (i = pipe->nr_stages+1 ; --i ; s++) { + + s->changed_inputs |= s->inputs & changed_inputs; + + if (s->check_state & newstate) { + if (s->active) { + GLuint old_outputs = s->outputs; + s->check(ctx, s); + if (!s->active) + changed_inputs |= old_outputs; + } + else + s->check(ctx, s); } - if (stage[i].active) { - pipe->inputs |= stage[i].inputs & ~generated; - generated |= stage[i].outputs; + if (s->active) { + pipe->inputs |= s->inputs & ~generated; + generated |= s->outputs; } } } - void _tnl_run_pipeline( GLcontext *ctx ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct gl_pipeline *pipe = &tnl->pipeline; - struct gl_pipeline_stage *stage = pipe->stages; + struct gl_pipeline_stage *s = pipe->stages; GLuint changed_state = pipe->run_state_changes; GLuint changed_inputs = pipe->run_input_changes; GLboolean running = GL_TRUE; @@ -129,21 +139,21 @@ void _tnl_run_pipeline( GLcontext *ctx ) * Even inactive stages have their state and inputs examined to try * to keep cached data alive over state-changes. */ - for (i = 0 ; i < pipe->nr_stages ; i++) { - - stage[i].changed_inputs |= stage[i].inputs & changed_inputs; + for (i = pipe->nr_stages+1 ; --i ; s++) { + s->changed_inputs |= s->inputs & changed_inputs; - if (stage[i].run_state & changed_state) { - stage[i].changed_inputs = stage[i].inputs; + if (s->run_state & changed_state) { +/* changed_inputs |= s->check(ctx, s); */ + s->changed_inputs = s->inputs; } - if (stage[i].active) { - if (stage[i].changed_inputs) - changed_inputs |= stage[i].outputs; - + if (s->active) { if (running) { - running = stage[i].run( ctx, &stage[i] ); - stage[i].changed_inputs = 0; + if (s->changed_inputs) + changed_inputs |= s->outputs; + +/* fprintf(stderr, "run %s\n", s->name); */ + running = s->run( ctx, s ); } } } diff --git a/src/mesa/tnl/t_vb_cliptmp.h b/src/mesa/tnl/t_vb_cliptmp.h index 35fe391b84..59dc0b2fec 100644 --- a/src/mesa/tnl/t_vb_cliptmp.h +++ b/src/mesa/tnl/t_vb_cliptmp.h @@ -1,4 +1,4 @@ -/* $Id: t_vb_cliptmp.h,v 1.7 2001/01/17 02:49:39 keithw Exp $ */ +/* $Id: t_vb_cliptmp.h,v 1.8 2001/01/29 20:47:39 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -37,7 +37,7 @@ do { \ GLfloat dpPrev = CLIP_DOTPROD(idxPrev, A, B, C, D ); \ GLuint outcount = 0; \ GLuint i; \ - \ + \ inlist[n] = inlist[0]; /* prevent rotation of vertices */ \ for (i = 1; i <= n; i++) { \ GLuint idx = inlist[i]; \ @@ -58,13 +58,13 @@ do { \ * know dp != dpPrev from DIFFERENT_SIGNS, above. \ */ \ GLfloat t = dp / (dp - dpPrev); \ - LINTERP_SZ( t, coord, newvert, idx, idxPrev, SIZE ); \ + LINTERP_4F( t, coord, newvert, idx, idxPrev, SIZE ); \ interp( ctx, t, newvert, idx, idxPrev, GL_TRUE ); \ - } else { \ + } else { \ /* Coming back in. \ */ \ GLfloat t = dpPrev / (dpPrev - dp); \ - LINTERP_SZ( t, coord, newvert, idxPrev, idx, SIZE ); \ + LINTERP_4F( t, coord, newvert, idxPrev, idx, SIZE ); \ interp( ctx, t, newvert, idxPrev, idx, GL_FALSE ); \ } \ } \ @@ -98,13 +98,13 @@ do { \ if (NEGATIVE(dpJ)) { \ GLfloat t = dpI / (dpI - dpJ); \ VB->ClipMask[jj] |= PLANE; \ - LINTERP_SZ( t, coord, newvert, ii, jj, SIZE ); \ + LINTERP_4F( t, coord, newvert, ii, jj, SIZE ); \ interp( ctx, t, newvert, ii, jj, GL_FALSE ); \ jj = newvert; \ } else { \ GLfloat t = dpJ / (dpJ - dpI); \ VB->ClipMask[ii] |= PLANE; \ - LINTERP_SZ( t, coord, newvert, jj, ii, SIZE ); \ + LINTERP_4F( t, coord, newvert, jj, ii, SIZE ); \ interp( ctx, t, newvert, jj, ii, GL_FALSE ); \ ii = newvert; \ } \ @@ -115,50 +115,15 @@ do { \ } while (0) -static void TAG(build_proj_verts)( GLcontext *ctx ) -{ - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - - /* Project if necessary. - */ - if (VB->ProjectedClipPtr) { - GLfloat (*coord)[4] = VB->ClipPtr->data; - GLfloat (*proj)[4] = VB->ProjectedClipPtr->data; - GLuint last = VB->LastClipped; - GLuint i; - - for (i = VB->FirstClipped; i < last; i++) { - if (VB->ClipMask[i] == 0) { - if (SIZE == 4 && W(i) != 0.0F) { - GLfloat wInv = 1.0F / W(i); - proj[i][0] = X(i) * wInv; - proj[i][1] = Y(i) * wInv; - proj[i][2] = Z(i) * wInv; - proj[i][3] = wInv; - } else { - proj[i][0] = X(i); - proj[i][1] = Y(i); - proj[i][2] = Z(i); - proj[i][3] = W(i); - } - } - } - } - - ctx->Driver.BuildProjectedVertices(ctx, - VB->FirstClipped, - VB->LastClipped, - ~0); -} /* Clip a line against the viewport and user clip planes. */ -static void TAG(clip_line)( GLcontext *ctx, - GLuint i, GLuint j, - GLubyte mask ) +static __inline void TAG(clip_line)( GLcontext *ctx, + GLuint i, GLuint j, + GLubyte mask ) { struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - interp_func interp = (interp_func) VB->interpfunc; + interp_func interp = ctx->Driver.RenderInterp; GLfloat (*coord)[4] = VB->ClipPtr->data; GLuint ii = i, jj = j, p; @@ -186,31 +151,29 @@ static void TAG(clip_line)( GLcontext *ctx, } if ((ctx->_TriangleCaps & DD_FLATSHADE) && j != jj) - VB->copypvfunc( ctx, jj, j ); - - TAG(build_proj_verts)( ctx ); - - /* Render the new line. - */ - ctx->Driver.LineFunc( ctx, ii, jj ); + ctx->Driver.RenderCopyPV( ctx, jj, j ); + ctx->Driver.RenderClippedLine( ctx, ii, jj ); } -/* Clip a triangle or quad against the viewport and user clip planes. +/* Clip a triangle against the viewport and user clip planes. */ -static void TAG(clip_polygon)( GLcontext *ctx, - GLuint n, GLuint vlist[], - GLubyte mask ) +static __inline void TAG(clip_tri)( GLcontext *ctx, + GLuint v0, GLuint v1, GLuint v2, + GLubyte mask ) { struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - interp_func interp = (interp_func) VB->interpfunc; + interp_func interp = ctx->Driver.RenderInterp; GLfloat (*coord)[4] = VB->ClipPtr->data; - GLuint pv = vlist[0]; - GLuint vlist2[MAX_CLIPPED_VERTICES]; - GLuint *inlist = vlist, *outlist = vlist2; + GLuint pv = v0; + GLuint vlist[2][MAX_CLIPPED_VERTICES]; + GLuint *inlist = vlist[0], *outlist = vlist[1]; GLuint p; GLubyte *clipmask = VB->ClipMask; + GLuint n = 3; + + ASSIGN_3V(inlist, v0, v1, v2 ); VB->LastClipped = VB->FirstClipped; @@ -238,25 +201,64 @@ static void TAG(clip_polygon)( GLcontext *ctx, if (ctx->_TriangleCaps & DD_FLATSHADE) { if (pv != inlist[0]) { ASSERT( inlist[0] >= VB->FirstClipped ); - VB->copypvfunc( ctx, inlist[0], pv ); + ctx->Driver.RenderCopyPV( ctx, inlist[0], pv ); } } - TAG(build_proj_verts)( ctx ); - - /* Render the new vertices as an unclipped polygon. - */ - { - GLuint *tmp = VB->Elts; - VB->Elts = inlist; - ctx->Driver.RenderTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END ); - VB->Elts = tmp; - } + ctx->Driver.RenderClippedPolygon( ctx, inlist, n ); } +/* Clip a quad against the viewport and user clip planes. + */ +static __inline void TAG(clip_quad)( GLcontext *ctx, + GLuint v0, GLuint v1, GLuint v2, GLuint v3, + GLubyte mask ) +{ + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + interp_func interp = ctx->Driver.RenderInterp; + GLfloat (*coord)[4] = VB->ClipPtr->data; + GLuint pv = v0; + GLuint vlist[2][MAX_CLIPPED_VERTICES]; + GLuint *inlist = vlist[0], *outlist = vlist[1]; + GLuint p; + GLubyte *clipmask = VB->ClipMask; + GLuint n = 4; + + ASSIGN_4V(inlist, v0, v1, v2, v3 ); + VB->LastClipped = VB->FirstClipped; + if (mask & 0x3f) { + POLY_CLIP( CLIP_RIGHT_BIT, -1, 0, 0, 1 ); + POLY_CLIP( CLIP_LEFT_BIT, 1, 0, 0, 1 ); + POLY_CLIP( CLIP_TOP_BIT, 0, -1, 0, 1 ); + POLY_CLIP( CLIP_BOTTOM_BIT, 0, 1, 0, 1 ); + POLY_CLIP( CLIP_FAR_BIT, 0, 0, -1, 1 ); + POLY_CLIP( CLIP_NEAR_BIT, 0, 0, 1, 1 ); + } + + if (mask & CLIP_USER_BIT) { + for (p=0;p<MAX_CLIP_PLANES;p++) { + if (ctx->Transform.ClipEnabled[p]) { + GLfloat a = ctx->Transform._ClipUserPlane[p][0]; + GLfloat b = ctx->Transform._ClipUserPlane[p][1]; + GLfloat c = ctx->Transform._ClipUserPlane[p][2]; + GLfloat d = ctx->Transform._ClipUserPlane[p][3]; + POLY_CLIP( CLIP_USER_BIT, a, b, c, d ); + } + } + } + + if (ctx->_TriangleCaps & DD_FLATSHADE) { + if (pv != inlist[0]) { + ASSERT( inlist[0] >= VB->FirstClipped ); + ctx->Driver.RenderCopyPV( ctx, inlist[0], pv ); + } + } + + ctx->Driver.RenderClippedPolygon( ctx, inlist, n ); +} #undef W #undef Z diff --git a/src/mesa/tnl/t_vb_render.c b/src/mesa/tnl/t_vb_render.c index 68bb3aa643..d364b4f460 100644 --- a/src/mesa/tnl/t_vb_render.c +++ b/src/mesa/tnl/t_vb_render.c @@ -1,4 +1,4 @@ -/* $Id: t_vb_render.c,v 1.11 2001/01/23 23:39:37 brianp Exp $ */ +/* $Id: t_vb_render.c,v 1.12 2001/01/29 20:47:39 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -51,7 +51,6 @@ #include "glheader.h" #include "context.h" -#include "colormac.h" #include "macros.h" #include "mem.h" #include "mtypes.h" @@ -75,296 +74,6 @@ typedef void (*clip_poly_func)( GLcontext *ctx, -struct render_stage_data { - - /* Clipping functions for current state. - */ - interp_func interp; /* Clip interpolation function */ - copy_pv_func copypv; /* Flatshade fixup function */ - GLuint _ClipInputs; /* Inputs referenced by interpfunc */ -}; - -#define RENDER_STAGE_DATA(stage) ((struct render_stage_data *)stage->private) - - -/**********************************************************************/ -/* Interpolate between pairs of vertices */ -/**********************************************************************/ - - -#define LINTERP_SZ( t, vec, to, a, b, sz ) \ -do { \ - switch (sz) { \ - case 4: vec[to][3] = LINTERP( t, vec[a][3], vec[b][3] ); \ - case 3: vec[to][2] = LINTERP( t, vec[a][2], vec[b][2] ); \ - case 2: vec[to][1] = LINTERP( t, vec[a][1], vec[b][1] ); \ - case 1: vec[to][0] = LINTERP( t, vec[a][0], vec[b][0] ); \ - } \ -} while(0) - - -#if 1 - -#define LINTERP_RGBA(nr, t, out, a, b) { \ - int i; \ - for (i = 0; i < nr; i++) { \ - GLfloat fa = CHAN_TO_FLOAT(a[i]); \ - GLfloat fb = CHAN_TO_FLOAT(b[i]); \ - GLfloat fo = LINTERP(t, fa, fb); \ - CLAMPED_FLOAT_TO_CHAN(out[i], fo); \ - } \ -} - -#else - -#define LINTERP_RGBA(nr, t, out, a, b) { \ - int n; \ - const GLuint ti = FloatToInt(t*256.0F); \ - const GLubyte *Ib = (const GLubyte *)&a[0]; \ - const GLubyte *Jb = (const GLubyte *)&b[0]; \ - GLubyte *Ob = (GLubyte *)&out[0]; \ - \ - for (n = 0 ; n < nr ; n++) \ - Ob[n] = (GLubyte) (Ib[n] + ((ti * (Jb[n] - Ib[n]))/256)); \ -} - -#endif - - - - -#define INTERP_RGBA 0x1 -#define INTERP_TEX 0x2 -#define INTERP_INDEX 0x4 -#define INTERP_SPEC 0x8 -#define INTERP_FOG 0x10 -#define INTERP_EDGE 0x20 -#define MAX_INTERP 0x40 - -static interp_func interp_tab[MAX_INTERP]; -static copy_pv_func copy_tab[MAX_INTERP]; - - -#define IND (0) -#define NAME interp_none -#include "t_vb_interptmp.h" - -#define IND (INTERP_FOG) -#define NAME interp_FOG -#include "t_vb_interptmp.h" - -#define IND (INTERP_TEX) -#define NAME interp_TEX -#include "t_vb_interptmp.h" - -#define IND (INTERP_FOG|INTERP_TEX) -#define NAME interp_FOG_TEX -#include "t_vb_interptmp.h" - -#define IND (INTERP_EDGE) -#define NAME interp_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_FOG|INTERP_EDGE) -#define NAME interp_FOG_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_TEX|INTERP_EDGE) -#define NAME interp_TEX_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_FOG|INTERP_TEX|INTERP_EDGE) -#define NAME interp_FOG_TEX_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA) -#define NAME interp_RGBA -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_SPEC) -#define NAME interp_RGBA_SPEC -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_FOG) -#define NAME interp_RGBA_FOG -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_SPEC|INTERP_FOG) -#define NAME interp_RGBA_SPEC_FOG -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_TEX) -#define NAME interp_RGBA_TEX -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_SPEC|INTERP_TEX) -#define NAME interp_RGBA_SPEC_TEX -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_FOG|INTERP_TEX) -#define NAME interp_RGBA_FOG_TEX -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_TEX) -#define NAME interp_RGBA_SPEC_FOG_TEX -#include "t_vb_interptmp.h" - -#define IND (INTERP_INDEX) -#define NAME interp_INDEX -#include "t_vb_interptmp.h" - -#define IND (INTERP_FOG|INTERP_INDEX) -#define NAME interp_FOG_INDEX -#include "t_vb_interptmp.h" - -#define IND (INTERP_TEX|INTERP_INDEX) -#define NAME interp_TEX_INDEX -#include "t_vb_interptmp.h" - -#define IND (INTERP_FOG|INTERP_TEX|INTERP_INDEX) -#define NAME interp_FOG_TEX_INDEX -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_EDGE) -#define NAME interp_RGBA_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_SPEC|INTERP_EDGE) -#define NAME interp_RGBA_SPEC_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_FOG|INTERP_EDGE) -#define NAME interp_RGBA_FOG_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_EDGE) -#define NAME interp_RGBA_SPEC_FOG_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_TEX|INTERP_EDGE) -#define NAME interp_RGBA_TEX_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_SPEC|INTERP_TEX|INTERP_EDGE) -#define NAME interp_RGBA_SPEC_TEX_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_FOG|INTERP_TEX|INTERP_EDGE) -#define NAME interp_RGBA_FOG_TEX_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_TEX|INTERP_EDGE) -#define NAME interp_RGBA_SPEC_FOG_TEX_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_INDEX|INTERP_EDGE) -#define NAME interp_INDEX_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_FOG|INTERP_INDEX|INTERP_EDGE) -#define NAME interp_FOG_INDEX_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_TEX|INTERP_INDEX|INTERP_EDGE) -#define NAME interp_TEX_INDEX_EDGE -#include "t_vb_interptmp.h" - -#define IND (INTERP_FOG|INTERP_TEX|INTERP_INDEX|INTERP_EDGE) -#define NAME interp_FOG_TEX_INDEX_EDGE -#include "t_vb_interptmp.h" - - -#define IND (INTERP_RGBA) -#define NAME copy_RGBA -#include "t_vb_flattmp.h" - -#define IND (INTERP_RGBA|INTERP_SPEC) -#define NAME copy_RGBA_SPEC -#include "t_vb_flattmp.h" - -#define IND (INTERP_INDEX) -#define NAME copy_INDEX -#include "t_vb_flattmp.h" - - - - -static void interp_invalid( GLcontext *ctx, - GLfloat t, - GLuint dst, GLuint in, GLuint out, - GLboolean boundary ) -{ - (void)(ctx && t && in && out && boundary); - fprintf(stderr, "Invalid interpolation function in t_vbrender.c\n"); -} - -static void copy_invalid( GLcontext *ctx, GLuint dst, GLuint src ) -{ - (void)(ctx && dst && src); - fprintf(stderr, "Invalid copy function in t_vbrender.c\n"); -} - - -static void interp_init( void ) -{ - GLuint i; - - /* Use the maximal function as the default. I don't believe any of - * the non-implemented combinations are reachable, but this gives - * some safety from crashes. - */ - for (i = 0 ; i < Elements(interp_tab) ; i++) { - interp_tab[i] = interp_invalid; - copy_tab[i] = copy_invalid; - } - - interp_tab[0] = interp_none; - interp_tab[INTERP_FOG] = interp_FOG; - interp_tab[INTERP_TEX] = interp_TEX; - interp_tab[INTERP_FOG|INTERP_TEX] = interp_FOG_TEX; - interp_tab[INTERP_EDGE] = interp_EDGE; - interp_tab[INTERP_FOG|INTERP_EDGE] = interp_FOG_EDGE; - interp_tab[INTERP_TEX|INTERP_EDGE] = interp_TEX_EDGE; - interp_tab[INTERP_FOG|INTERP_TEX|INTERP_EDGE] = interp_FOG_TEX_EDGE; - - interp_tab[INTERP_RGBA] = interp_RGBA; - interp_tab[INTERP_RGBA|INTERP_SPEC] = interp_RGBA_SPEC; - interp_tab[INTERP_RGBA|INTERP_FOG] = interp_RGBA_FOG; - interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_FOG] = interp_RGBA_SPEC_FOG; - interp_tab[INTERP_RGBA|INTERP_TEX] = interp_RGBA_TEX; - interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_TEX] = interp_RGBA_SPEC_TEX; - interp_tab[INTERP_RGBA|INTERP_FOG|INTERP_TEX] = interp_RGBA_FOG_TEX; - interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_TEX] = - interp_RGBA_SPEC_FOG_TEX; - interp_tab[INTERP_INDEX] = interp_INDEX; - interp_tab[INTERP_FOG|INTERP_INDEX] = interp_FOG_INDEX; - interp_tab[INTERP_TEX|INTERP_INDEX] = interp_TEX_INDEX; - interp_tab[INTERP_FOG|INTERP_TEX|INTERP_INDEX] = interp_FOG_TEX_INDEX; - interp_tab[INTERP_RGBA|INTERP_EDGE] = interp_RGBA_EDGE; - interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_EDGE] = interp_RGBA_SPEC_EDGE; - interp_tab[INTERP_RGBA|INTERP_FOG|INTERP_EDGE] = interp_RGBA_FOG_EDGE; - interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_EDGE] = - interp_RGBA_SPEC_FOG_EDGE; - interp_tab[INTERP_RGBA|INTERP_TEX|INTERP_EDGE] = interp_RGBA_TEX_EDGE; - interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_TEX|INTERP_EDGE] = - interp_RGBA_SPEC_TEX_EDGE; - interp_tab[INTERP_RGBA|INTERP_FOG|INTERP_TEX|INTERP_EDGE] = - interp_RGBA_FOG_TEX_EDGE; - interp_tab[INTERP_RGBA|INTERP_SPEC|INTERP_FOG|INTERP_TEX|INTERP_EDGE] = - interp_RGBA_SPEC_FOG_TEX_EDGE; - interp_tab[INTERP_INDEX|INTERP_EDGE] = interp_INDEX_EDGE; - interp_tab[INTERP_FOG|INTERP_INDEX|INTERP_EDGE] = interp_FOG_INDEX_EDGE; - interp_tab[INTERP_TEX|INTERP_INDEX|INTERP_EDGE] = interp_TEX_INDEX_EDGE; - interp_tab[INTERP_FOG|INTERP_TEX|INTERP_INDEX|INTERP_EDGE] = - interp_FOG_TEX_INDEX_EDGE; - - - copy_tab[INTERP_RGBA] = copy_RGBA; - copy_tab[INTERP_RGBA|INTERP_SPEC] = copy_RGBA_SPEC; - copy_tab[INTERP_INDEX] = copy_INDEX; - -} - /**********************************************************************/ /* Clip single primitives */ @@ -382,6 +91,28 @@ static void interp_init( void ) */ #endif +#define LINTERP_SZ( t, vec, to, a, b, sz ) \ +do { \ + switch (sz) { \ + case 2: vec[to][2] = 0.0; \ + case 3: vec[to][3] = 1.0; \ + } \ + switch (sz) { \ + case 4: vec[to][3] = LINTERP( t, vec[a][3], vec[b][3] ); \ + case 3: vec[to][2] = LINTERP( t, vec[a][2], vec[b][2] ); \ + case 2: vec[to][1] = LINTERP( t, vec[a][1], vec[b][1] ); \ + vec[to][0] = LINTERP( t, vec[a][0], vec[b][0] ); \ + } \ +} while(0) + +#define LINTERP_4F( t, vec, to, a, b, sz ) \ +do { \ + vec[to][3] = LINTERP( t, vec[a][3], vec[b][3] ); \ + vec[to][2] = LINTERP( t, vec[a][2], vec[b][2] ); \ + vec[to][1] = LINTERP( t, vec[a][1], vec[b][1] ); \ + vec[to][0] = LINTERP( t, vec[a][0], vec[b][0] ); \ +} while (0) + #define W(i) coord[i][3] #define Z(i) coord[i][2] #define Y(i) coord[i][1] @@ -390,37 +121,6 @@ static void interp_init( void ) #define TAG(x) x##_4 #include "t_vb_cliptmp.h" -#define W(i) 1.0 -#define Z(i) coord[i][2] -#define Y(i) coord[i][1] -#define X(i) coord[i][0] -#define SIZE 3 -#define TAG(x) x##_3 -#include "t_vb_cliptmp.h" - -#define W(i) 1.0 -#define Z(i) 0.0 -#define Y(i) coord[i][1] -#define X(i) coord[i][0] -#define SIZE 2 -#define TAG(x) x##_2 -#include "t_vb_cliptmp.h" - -static clip_poly_func clip_poly_tab[5] = { - 0, - 0, - clip_polygon_2, - clip_polygon_3, - clip_polygon_4 -}; - -static clip_line_func clip_line_tab[5] = { - 0, - 0, - clip_line_2, - clip_line_3, - clip_line_4 -}; /**********************************************************************/ @@ -444,7 +144,7 @@ do { \ if (!ormask) \ LineFunc( ctx, v1, v2 ); \ else if (!(c1 & c2 & 0x3f)) \ - clip_line_tab[sz]( ctx, v1, v2, ormask ); \ + clip_line_4( ctx, v1, v2, ormask ); \ } while (0) #define RENDER_TRI( v1, v2, v3 ) \ @@ -453,11 +153,8 @@ do { \ GLubyte ormask = c1|c2|c3; \ if (!ormask) \ TriangleFunc( ctx, v1, v2, v3 ); \ - else if (!(c1 & c2 & c3 & 0x3f)) { \ - GLuint vlist[MAX_CLIPPED_VERTICES]; \ - ASSIGN_3V(vlist, v3, v1, v2 ); \ - clip_poly_tab[sz]( ctx, 3, vlist, ormask ); \ - } \ + else if (!(c1 & c2 & c3 & 0x3f)) \ + clip_tri_4( ctx, v1, v2, v3, ormask ); \ } while (0) #define RENDER_QUAD( v1, v2, v3, v4 ) \ @@ -467,11 +164,8 @@ do { \ GLubyte ormask = c1|c2|c3|c4; \ if (!ormask) \ QuadFunc( ctx, v1, v2, v3, v4 ); \ - else if (!(c1 & c2 & c3 & c4 & 0x3f)) { \ - GLuint vlist[MAX_CLIPPED_VERTICES]; \ - ASSIGN_4V(vlist, v4, v1, v2, v3 ); \ - clip_poly_tab[sz]( ctx, 4, vlist, ormask ); \ - } \ + else if (!(c1 & c2 & c3 & c4 & 0x3f)) \ + clip_quad_4( ctx, v1, v2, v3, v4, ormask ); \ } while (0) @@ -483,12 +177,13 @@ do { \ const line_func LineFunc = ctx->Driver.LineFunc; \ const triangle_func TriangleFunc = ctx->Driver.TriangleFunc; \ const quad_func QuadFunc = ctx->Driver.QuadFunc; \ + const GLboolean stipple = ctx->Line.StippleFlag; \ (void) (LineFunc && TriangleFunc && QuadFunc); \ - (void) elt; (void) mask; (void) sz; + (void) elt; (void) mask; (void) sz; (void) stipple; #define TAG(x) clip_##x##_verts #define INIT(x) ctx->Driver.RenderPrimitive( ctx, x ) -#define RESET_STIPPLE ctx->Driver.ResetLineStipple( ctx ) +#define RESET_STIPPLE if (stipple) ctx->Driver.ResetLineStipple( ctx ) #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE; #define PRESERVE_VB_DEFS #include "t_vb_rendertmp.h" @@ -503,6 +198,40 @@ do { \ #define TAG(x) clip_##x##_elts #include "t_vb_rendertmp.h" +/* TODO: do this for all primitives, verts and elts: + */ +static void clip_elt_triangles( GLcontext *ctx, + GLuint start, + GLuint count, + GLuint flags ) +{ + GLuint j; + GLuint last = count-2; + render_func render_tris = ctx->Driver.RenderTabElts[GL_TRIANGLES]; + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + const GLuint * const elt = VB->Elts; + GLubyte *mask = VB->ClipMask; + (void) flags; + + ctx->Driver.RenderPrimitive( ctx, GL_TRIANGLES ); + + for (j=start; j < last; j+=3 ) { + GLubyte c1 = mask[elt[j]]; + GLubyte c2 = mask[elt[j+1]]; + GLubyte c3 = mask[elt[j+2]]; + GLubyte ormask = c1|c2|c3; + if (ormask) { + if (start < j) + render_tris( ctx, start, j, 0 ); + if (!(c1&c2&c3&0x3f)) + clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask ); + start = j+3; + } + } + + if (start < j) + render_tris( ctx, start, j, 0 ); +} /**********************************************************************/ /* Render whole begin/end objects */ @@ -570,29 +299,21 @@ static GLboolean run_render( GLcontext *ctx, render_func *tab; GLint pass = 0; - VB->interpfunc = RENDER_STAGE_DATA(stage)->interp; - VB->copypvfunc = RENDER_STAGE_DATA(stage)->copypv; - /* Allow the drivers to lock before projected verts are built so * that window coordinates are guarenteed not to change before * rendering. */ ctx->Driver.RenderStart( ctx ); - + ctx->Driver.BuildProjectedVertices( ctx, 0, VB->Count, new_inputs ); + if (VB->ClipOrMask) { tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts; - - if (new_inputs & VB->importable_data) - VB->import_data( ctx, - new_inputs & VB->importable_data, - VEC_NOT_WRITEABLE|VEC_BAD_STRIDE); + clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles; } else { tab = VB->Elts ? ctx->Driver.RenderTabElts : ctx->Driver.RenderTabVerts; } - ctx->Driver.BuildProjectedVertices( ctx, 0, VB->Count, new_inputs ); - do { GLuint i, length, flags = 0; @@ -623,30 +344,21 @@ static GLboolean run_render( GLcontext *ctx, /* Quite a bit of work involved in finding out the inputs for the - * render stage. This function also identifies which vertex - * interpolation function to use, as these are essentially the same - * question. + * render stage. */ static void check_render( GLcontext *ctx, struct gl_pipeline_stage *stage ) { - struct render_stage_data *store = RENDER_STAGE_DATA(stage); - GLuint interp = 0; - GLuint copy = 0; GLuint inputs = VERT_CLIP; GLuint i; if (ctx->Visual.rgbMode) { - interp |= INTERP_RGBA; inputs |= VERT_RGBA; if (ctx->_TriangleCaps & DD_SEPERATE_SPECULAR) { - interp |= INTERP_SPEC; inputs |= VERT_SPEC_RGB; } if (ctx->Texture._ReallyEnabled) { - interp |= INTERP_TEX; - for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) { if (ctx->Texture.Unit[i]._ReallyEnabled) inputs |= VERT_TEX(i); @@ -655,7 +367,6 @@ static void check_render( GLcontext *ctx, struct gl_pipeline_stage *stage ) } else { - interp |= INTERP_INDEX; inputs |= VERT_INDEX; } @@ -665,63 +376,25 @@ static void check_render( GLcontext *ctx, struct gl_pipeline_stage *stage ) /* How do drivers turn this off? */ if (ctx->Fog.Enabled) { - interp |= INTERP_FOG; inputs |= VERT_FOG_COORD; } if (ctx->_TriangleCaps & DD_TRI_UNFILLED) { inputs |= VERT_EDGE; - interp |= INTERP_EDGE; } if (ctx->RenderMode==GL_FEEDBACK) { - interp |= INTERP_TEX; inputs |= VERT_TEX_ANY; } - if (ctx->_TriangleCaps & DD_FLATSHADE) { - copy = interp & (INTERP_RGBA|INTERP_SPEC|INTERP_INDEX); - interp &= ~copy; - } - - store->copypv = copy_tab[copy]; - store->interp = interp_tab[interp]; stage->inputs = inputs; } -/* Called the first time stage->check() is invoked. - */ -static void alloc_render_data( GLcontext *ctx, - struct gl_pipeline_stage *stage ) -{ - struct render_stage_data *store; - static GLboolean first_time = 1; - - if (first_time) { - interp_init(); - first_time = 0; - } - - stage->private = MALLOC(sizeof(*store)); - if (!stage->private) - return; - - /* Now do the check. - */ - stage->check = check_render; - stage->check( ctx, stage ); -} - static void dtr( struct gl_pipeline_stage *stage ) { - struct render_stage_data *store = RENDER_STAGE_DATA(stage); - if (store) { - FREE( store ); - stage->private = 0; - } } @@ -742,6 +415,6 @@ const struct gl_pipeline_stage _tnl_render_stage = 0, 0, /* inputs (set in check_render), outputs */ 0, 0, /* changed_inputs, private */ dtr, /* destructor */ - alloc_render_data, /* check - initially set to alloc data */ + check_render, /* check */ run_render /* run */ }; diff --git a/src/mesa/tnl/t_vb_texgen.c b/src/mesa/tnl/t_vb_texgen.c index e975665e8a..70c53de7de 100644 --- a/src/mesa/tnl/t_vb_texgen.c +++ b/src/mesa/tnl/t_vb_texgen.c @@ -1,4 +1,4 @@ -/* $Id: t_vb_texgen.c,v 1.1 2000/12/26 05:09:33 keithw Exp $ */ +/* $Id: t_vb_texgen.c,v 1.2 2001/01/29 20:47:39 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -372,6 +372,7 @@ static void texgen( GLcontext *ctx, GLuint count = VB->Count; GLfloat (*f)[3] = store->tmp_f; GLfloat *m = store->tmp_m; + GLuint holes = 0; if (texUnit->_GenFlags & TEXGEN_NEED_M) { @@ -380,25 +381,33 @@ static void texgen( GLcontext *ctx, build_f_tab[in->size]( (GLfloat *)store->tmp_f, 3, normal, eye ); } - if (in != out) { + if (!in) { + ASSERT(0); + in = out; + in->count = VB->Count; + + out->size = store->TexgenSize[unit]; + out->flags |= texUnit->TexGenEnabled; + out->count = VB->Count; + holes = store->TexgenHoles[unit]; + } + else { GLuint copy = (all_bits[in->size] & ~texUnit->TexGenEnabled); if (copy) gl_copy_tab[0][copy](out, in, 0); - } - if (store->TexgenHoles[unit]) - { - GLuint holes = (~all_bits[in->size] & store->TexgenHoles[unit]); - if (holes) { - if (holes & VEC_DIRTY_2) gl_vector4f_clean_elem(out, count, 2); - if (holes & VEC_DIRTY_1) gl_vector4f_clean_elem(out, count, 1); - if (holes & VEC_DIRTY_0) gl_vector4f_clean_elem(out, count, 0); - } + out->size = MAX2(in->size, store->TexgenSize[unit]); + out->flags |= (in->flags & VEC_SIZE_FLAGS) | texUnit->TexGenEnabled; + out->count = in->count; + + holes = ~all_bits[in->size] & store->TexgenHoles[unit]; } - out->size = MAX2(in->size, store->TexgenSize[unit]); - out->flags |= (in->flags & VEC_SIZE_FLAGS) | texUnit->TexGenEnabled; - out->count = in->count; + if (holes) { + if (holes & VEC_DIRTY_2) gl_vector4f_clean_elem(out, count, 2); + if (holes & VEC_DIRTY_1) gl_vector4f_clean_elem(out, count, 1); + if (holes & VEC_DIRTY_0) gl_vector4f_clean_elem(out, count, 0); + } if (texUnit->TexGenEnabled & S_BIT) { GLuint i; @@ -414,7 +423,7 @@ static void texgen( GLcontext *ctx, texUnit->EyePlaneS, 0); break; case GL_SPHERE_MAP: - for (indata=in->start,i=0 ; i<count ; i++, STRIDE_F(indata,in->stride)) + for (indata=in->start,i=0 ; i<count ;i++, STRIDE_F(indata,in->stride)) texcoord[i][0] = indata[0] * m[i] + 0.5F; break; case GL_REFLECTION_MAP_NV: @@ -604,8 +613,8 @@ static void check_texgen( GLcontext *ctx, struct gl_pipeline_stage *stage ) /* Need the original input in case it contains a Q coord: * (sigh) */ - if ((ctx->Texture.Unit[i]._ReallyEnabled|Q_BIT) & - ~ctx->Texture.Unit[i].TexGenEnabled) +/* if ((ctx->Texture.Unit[i]._ReallyEnabled|Q_BIT) & */ +/* ~ctx->Texture.Unit[i].TexGenEnabled) */ inputs |= VERT_TEX(i); /* Something for Feedback? */ diff --git a/src/mesa/tnl/t_vb_vertex.c b/src/mesa/tnl/t_vb_vertex.c index 0c163ee4f3..fc35103395 100644 --- a/src/mesa/tnl/t_vb_vertex.c +++ b/src/mesa/tnl/t_vb_vertex.c @@ -1,4 +1,4 @@ -/* $Id: t_vb_vertex.c,v 1.2 2001/01/13 05:48:26 keithw Exp $ */ +/* $Id: t_vb_vertex.c,v 1.3 2001/01/29 20:47:39 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -160,13 +160,26 @@ static GLboolean run_vertex_stage( GLcontext *ctx, { /* Combined modelviewproject transform: */ - if (ctx->_ModelProjectMatrix.type == MATRIX_IDENTITY) + if (ctx->_ModelProjectMatrix.type == MATRIX_IDENTITY) VB->ClipPtr = VB->ObjPtr; else VB->ClipPtr = TransformRaw( &store->clip, &ctx->_ModelProjectMatrix, VB->ObjPtr ); } + /* Drivers expect this to be clean to element 4... + */ + if (VB->ClipPtr->size < 4) { + if (VB->ClipPtr->flags & VEC_NOT_WRITEABLE) { + ASSERT(VB->ClipPtr == VB->ObjPtr); + VB->import_data( ctx, VERT_OBJ, VEC_NOT_WRITEABLE ); + VB->ClipPtr = VB->ObjPtr; + } + if (VB->ClipPtr->size == 2) + gl_vector4f_clean_elem( VB->ClipPtr, VB->Count, 2 ); + gl_vector4f_clean_elem( VB->ClipPtr, VB->Count, 3 ); + } + /* Cliptest and perspective divide. Clip functions must clear * the clipmask. */ @@ -181,20 +194,6 @@ static GLboolean run_vertex_stage( GLcontext *ctx, &store->ormask, &store->andmask ); - /* Drivers expect this to be size 4... - */ - if (VB->ProjectedClipPtr->size < 4) { - ASSERT(VB->ProjectedClipPtr == VB->ClipPtr); - if (VB->ProjectedClipPtr->flags & VEC_NOT_WRITEABLE) { - ASSERT(VB->ProjectedClipPtr == VB->ObjPtr); - VB->import_data( ctx, VERT_OBJ, VEC_NOT_WRITEABLE ); - VB->ProjectedClipPtr = VB->ClipPtr = VB->ObjPtr; - } - if (VB->ClipPtr->size == 2) - gl_vector4f_clean_elem( VB->ClipPtr, VB->Count, 2 ); - gl_vector4f_clean_elem( VB->ClipPtr, VB->Count, 3 ); - VB->ClipPtr->size = 4; - } } else { VB->ProjectedClipPtr = 0; gl_clip_np_tab[VB->ClipPtr->size]( VB->ClipPtr, |