From cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 26 Dec 2000 05:09:27 +0000 Subject: Major rework of tnl module New array_cache module Support 8 texture units in core mesa (now support 8 everywhere) Rework core mesa statechange operations to avoid flushing on many noop statechanges. --- src/mesa/swrast_setup/ss_context.c | 70 +++++------ src/mesa/swrast_setup/ss_context.h | 12 +- src/mesa/swrast_setup/ss_triangle.c | 130 +++++++++++--------- src/mesa/swrast_setup/ss_tritmp.h | 160 +++++++++++++------------ src/mesa/swrast_setup/ss_vb.c | 226 +++++++++++++++++++++++++---------- src/mesa/swrast_setup/ss_vbtmp.h | 99 ++++++++------- src/mesa/swrast_setup/swrast_setup.h | 15 ++- 7 files changed, 411 insertions(+), 301 deletions(-) (limited to 'src/mesa/swrast_setup') diff --git a/src/mesa/swrast_setup/ss_context.c b/src/mesa/swrast_setup/ss_context.c index e58abdc6c5..84c313db8e 100644 --- a/src/mesa/swrast_setup/ss_context.c +++ b/src/mesa/swrast_setup/ss_context.c @@ -1,4 +1,4 @@ -/* $Id: ss_context.c,v 1.4 2000/11/16 21:05:42 keithw Exp $ */ +/* $Id: ss_context.c,v 1.5 2000/12/26 05:09:32 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -77,20 +77,19 @@ _swsetup_validate_points( GLcontext *ctx, GLuint first, GLuint last ) static void -_swsetup_validate_rastersetup( struct vertex_buffer *VB, - GLuint start, GLuint end ) +_swsetup_validate_buildprojverts( GLcontext *ctx, + GLuint start, GLuint end, GLuint new_inputs ) { - GLcontext *ctx = VB->ctx; _swsetup_choose_rastersetup_func( ctx ); - SWSETUP_CONTEXT(ctx)->RasterSetup( VB, start, end ); + SWSETUP_CONTEXT(ctx)->BuildProjVerts( ctx, start, end, new_inputs ); } -#define _SWSETUP_NEW_RASTERSETUP (_NEW_RENDERMODE| \ - _NEW_TEXTURE| \ - _NEW_COLOR| \ - _NEW_FOG| \ - _NEW_POINT) +#define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \ + _NEW_TEXTURE| \ + _NEW_COLOR| \ + _NEW_FOG| \ + _NEW_POINT) #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT) @@ -118,8 +117,8 @@ _swsetup_invalidate_state( GLcontext *ctx, GLuint new_state ) swsetup->Quad = _swsetup_validate_quad; } - if (new_state & _SWSETUP_NEW_RASTERSETUP) { - swsetup->RasterSetup = _swsetup_validate_rastersetup; + if (new_state & _SWSETUP_NEW_VERTS) { + swsetup->BuildProjVerts = _swsetup_validate_buildprojverts; } } @@ -156,9 +155,10 @@ _swsetup_Points( GLcontext *ctx, GLuint first, GLuint last ) } void -_swsetup_RasterSetup( struct vertex_buffer *VB, GLuint start, GLuint end ) +_swsetup_BuildProjectedVertices( GLcontext *ctx, GLuint start, GLuint end, + GLuint new_inputs ) { - SWSETUP_CONTEXT(VB->ctx)->RasterSetup( VB, start, end ); + SWSETUP_CONTEXT(ctx)->BuildProjVerts( ctx, start, end, new_inputs ); } void @@ -171,11 +171,18 @@ _swsetup_InvalidateState( GLcontext *ctx, GLuint new_state ) GLboolean _swsetup_CreateContext( GLcontext *ctx ) { + TNLcontext *tnl = TNL_CONTEXT(ctx); SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext)); - + if (!swsetup) return GL_FALSE; + swsetup->verts = ALIGN_MALLOC( sizeof(SWvertex) * tnl->vb.Size, 32); + if (!swsetup->verts) { + FREE(swsetup); + return GL_FALSE; + } + ctx->swsetup_context = swsetup; swsetup->NewState = ~0; @@ -184,11 +191,11 @@ _swsetup_CreateContext( GLcontext *ctx ) swsetup->Triangle = _swsetup_validate_triangle; swsetup->Line = _swsetup_validate_line; swsetup->Points = _swsetup_validate_points; - swsetup->RasterSetup = _swsetup_validate_rastersetup; + swsetup->BuildProjVerts = _swsetup_validate_buildprojverts; _swsetup_vb_init( ctx ); _swsetup_trifuncs_init( ctx ); - + return GL_TRUE; } @@ -196,35 +203,12 @@ void _swsetup_DestroyContext( GLcontext *ctx ) { if (SWSETUP_CONTEXT(ctx)) { + if (SWSETUP_CONTEXT(ctx)->verts) + ALIGN_FREE(SWSETUP_CONTEXT(ctx)->verts); + FREE(SWSETUP_CONTEXT(ctx)); ctx->swsetup_context = 0; } } -void -_swsetup_RegisterVB( struct vertex_buffer *VB ) -{ - SSvertexbuffer *ssvb = (SSvertexbuffer *)CALLOC(sizeof(SSvertexbuffer) ); - ssvb->verts = ALIGN_MALLOC( sizeof(SWvertex) * VB->Size, 32); - if (!ssvb->verts) { - FREE(ssvb); - /*return GL_FALSE;*/ - } - - VB->swsetup_vb = ssvb; - /*return GL_TRUE;*/ -} - - -void -_swsetup_UnregisterVB( struct vertex_buffer *VB ) -{ - SSvertexbuffer *ssvb = SWSETUP_VB(VB); - - if (ssvb) { - if (ssvb->verts) ALIGN_FREE(ssvb->verts); - FREE(ssvb); - VB->swsetup_vb = 0; - } -} diff --git a/src/mesa/swrast_setup/ss_context.h b/src/mesa/swrast_setup/ss_context.h index b991813763..f4dcb4e7d1 100644 --- a/src/mesa/swrast_setup/ss_context.h +++ b/src/mesa/swrast_setup/ss_context.h @@ -40,7 +40,8 @@ typedef struct { */ void (*InvalidateState)( GLcontext *ctx, GLuint new_state ); - void (*RasterSetup)( struct vertex_buffer *VB, GLuint start, GLuint end ); + void (*BuildProjVerts)( GLcontext *ctx, + GLuint start, GLuint end, GLuint new_inputs ); void (*Quad)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, GLuint pv ); @@ -52,17 +53,10 @@ typedef struct { void (*Points)( GLcontext *ctx, GLuint first, GLuint last ); -} SScontext; - -typedef struct { - SWvertex *verts; -} SSvertexbuffer; - +} SScontext; #define SWSETUP_CONTEXT(ctx) ((SScontext *)ctx->swsetup_context) -#define SWSETUP_VB(VB) ((SSvertexbuffer *)VB->swsetup_vb) - #endif diff --git a/src/mesa/swrast_setup/ss_triangle.c b/src/mesa/swrast_setup/ss_triangle.c index 962f811875..a3f8cd6cec 100644 --- a/src/mesa/swrast_setup/ss_triangle.c +++ b/src/mesa/swrast_setup/ss_triangle.c @@ -34,16 +34,15 @@ #include "ss_triangle.h" #include "ss_context.h" -#define SS_FLAT_BIT 0x1 +#define SS_FLAT_BIT 0x1 #define SS_OFFSET_BIT 0x2 #define SS_TWOSIDE_BIT 0x4 #define SS_UNFILLED_BIT 0x10 -#define SS_COPY_EXTRAS 0x20 /* optimization */ -#define SS_MAX_TRIFUNC 0x40 +#define SS_RGBA_BIT 0x20 +#define SS_MAX_TRIFUNC 0x80 static triangle_func tri_tab[SS_MAX_TRIFUNC]; static line_func line_tab[SS_MAX_TRIFUNC]; -static points_func points_tab[SS_MAX_TRIFUNC]; static quad_func quad_tab[SS_MAX_TRIFUNC]; @@ -115,68 +114,68 @@ static quad_func quad_tab[SS_MAX_TRIFUNC]; #define TAG(x) x##_flat_offset_twoside_unfilled #include "ss_tritmp.h" -#define IND (0|SS_COPY_EXTRAS) -#define TAG(x) x##_spec +#define IND (0|SS_RGBA_BIT) +#define TAG(x) x##_rgba #include "ss_tritmp.h" -#define IND (SS_FLAT_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_flat_spec +#define IND (SS_FLAT_BIT|SS_RGBA_BIT) +#define TAG(x) x##_flat_rgba #include "ss_tritmp.h" -#define IND (SS_OFFSET_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_offset_spec +#define IND (SS_OFFSET_BIT|SS_RGBA_BIT) +#define TAG(x) x##_offset_rgba #include "ss_tritmp.h" -#define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_flat_offset_spec +#define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_RGBA_BIT) +#define TAG(x) x##_flat_offset_rgba #include "ss_tritmp.h" -#define IND (SS_TWOSIDE_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_twoside_spec +#define IND (SS_TWOSIDE_BIT|SS_RGBA_BIT) +#define TAG(x) x##_twoside_rgba #include "ss_tritmp.h" -#define IND (SS_FLAT_BIT|SS_TWOSIDE_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_flat_twoside_spec +#define IND (SS_FLAT_BIT|SS_TWOSIDE_BIT|SS_RGBA_BIT) +#define TAG(x) x##_flat_twoside_rgba #include "ss_tritmp.h" -#define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_offset_twoside_spec +#define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_RGBA_BIT) +#define TAG(x) x##_offset_twoside_rgba #include "ss_tritmp.h" -#define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_flat_offset_twoside_spec +#define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_RGBA_BIT) +#define TAG(x) x##_flat_offset_twoside_rgba #include "ss_tritmp.h" -#define IND (SS_UNFILLED_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_unfilled_spec +#define IND (SS_UNFILLED_BIT|SS_RGBA_BIT) +#define TAG(x) x##_unfilled_rgba #include "ss_tritmp.h" -#define IND (SS_FLAT_BIT|SS_UNFILLED_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_flat_unfilled_spec +#define IND (SS_FLAT_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT) +#define TAG(x) x##_flat_unfilled_rgba #include "ss_tritmp.h" -#define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_offset_unfilled_spec +#define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT) +#define TAG(x) x##_offset_unfilled_rgba #include "ss_tritmp.h" -#define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_UNFILLED_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_flat_offset_unfilled_spec +#define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT) +#define TAG(x) x##_flat_offset_unfilled_rgba #include "ss_tritmp.h" -#define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_twoside_unfilled_spec +#define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT) +#define TAG(x) x##_twoside_unfilled_rgba #include "ss_tritmp.h" -#define IND (SS_FLAT_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_flat_twoside_unfilled_spec +#define IND (SS_FLAT_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT) +#define TAG(x) x##_flat_twoside_unfilled_rgba #include "ss_tritmp.h" -#define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_offset_twoside_unfilled_spec +#define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT) +#define TAG(x) x##_offset_twoside_unfilled_rgba #include "ss_tritmp.h" -#define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_COPY_EXTRAS) -#define TAG(x) x##_flat_offset_twoside_unfilled_spec +#define IND (SS_FLAT_BIT|SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT) +#define TAG(x) x##_flat_offset_twoside_unfilled_rgba #include "ss_tritmp.h" @@ -201,25 +200,42 @@ void _swsetup_trifuncs_init( GLcontext *ctx ) init_offset_twoside_unfilled(); init_flat_offset_twoside_unfilled(); - init_spec(); - init_flat_spec(); - init_offset_spec(); - init_flat_offset_spec(); - init_twoside_spec(); - init_flat_twoside_spec(); - init_offset_twoside_spec(); - init_flat_offset_twoside_spec(); - init_unfilled_spec(); - init_flat_unfilled_spec(); - init_offset_unfilled_spec(); - init_flat_offset_unfilled_spec(); - init_twoside_unfilled_spec(); - init_flat_twoside_unfilled_spec(); - init_offset_twoside_unfilled_spec(); - init_flat_offset_twoside_unfilled_spec(); + init_rgba(); + init_flat_rgba(); + init_offset_rgba(); + init_flat_offset_rgba(); + init_twoside_rgba(); + init_flat_twoside_rgba(); + init_offset_twoside_rgba(); + init_flat_offset_twoside_rgba(); + init_unfilled_rgba(); + init_flat_unfilled_rgba(); + init_offset_unfilled_rgba(); + init_flat_offset_unfilled_rgba(); + init_twoside_unfilled_rgba(); + init_flat_twoside_unfilled_rgba(); + init_offset_twoside_unfilled_rgba(); + init_flat_offset_twoside_unfilled_rgba(); } +static void swsetup_points( GLcontext *ctx, GLuint first, GLuint last ) +{ + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; + int i; + + if (VB->Elts) { + for(i=first;i<=last;i++) + if(VB->ClipMask[VB->Elts[i]]==0) + _swrast_Point( ctx, &verts[VB->Elts[i]] ); + } else { + for(i=first;i<=last;i++) + if(VB->ClipMask[i]==0) + _swrast_Point( ctx, &verts[i] ); + } +} + void _swsetup_choose_trifuncs( GLcontext *ctx ) { SScontext *swsetup = SWSETUP_CONTEXT(ctx); @@ -234,17 +250,15 @@ void _swsetup_choose_trifuncs( GLcontext *ctx ) if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) ind |= SS_TWOSIDE_BIT; - if (ctx->Polygon._Unfilled) + if (ctx->_TriangleCaps & DD_TRI_UNFILLED) ind |= SS_UNFILLED_BIT; - if ((ctx->_TriangleCaps & DD_SEPERATE_SPECULAR) || - ctx->RenderMode == GL_SELECT || - !ctx->Visual.RGBAflag) - ind |= SS_COPY_EXTRAS; + if (ctx->Visual.RGBAflag) + ind |= SS_RGBA_BIT; swsetup->Triangle = tri_tab[ind]; swsetup->Line = line_tab[ind]; - swsetup->Points = points_tab[ind]; swsetup->Quad = quad_tab[ind]; + swsetup->Points = swsetup_points; } diff --git a/src/mesa/swrast_setup/ss_tritmp.h b/src/mesa/swrast_setup/ss_tritmp.h index 054fcf9eb7..d04a36b18b 100644 --- a/src/mesa/swrast_setup/ss_tritmp.h +++ b/src/mesa/swrast_setup/ss_tritmp.h @@ -30,8 +30,8 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2, GLuint pv) { - struct vertex_buffer *VB = TNL_VB(ctx); - SWvertex *verts = SWSETUP_VB(VB)->verts; + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; SWvertex *v[3]; GLfloat offset; GLfloat z[3]; @@ -44,22 +44,22 @@ static void TAG(triangle)(GLcontext *ctx, v[2] = &verts[e2]; if (IND & (SS_TWOSIDE_BIT | SS_FLAT_BIT)) { - SS_COLOR(c[0], v[0]->color); - - if (IND & SS_TWOSIDE_BIT) { - SS_COLOR(c[1], v[1]->color); - SS_COLOR(c[2], v[2]->color); - } - - if (IND & SS_COPY_EXTRAS) { + if (IND & SS_RGBA_BIT) { + SS_COLOR(c[0], v[0]->color); SS_SPEC(s[0], v[0]->specular); + + if (IND & SS_TWOSIDE_BIT) { + SS_COLOR(c[1], v[1]->color); + SS_COLOR(c[2], v[2]->color); + + SS_SPEC(s[1], v[1]->specular); + SS_SPEC(s[2], v[2]->specular); + } + } else { SS_IND(i[0], v[0]->index); if (IND & SS_TWOSIDE_BIT) { - SS_SPEC(s[1], v[1]->specular); SS_IND(i[1], v[1]->index); - - SS_SPEC(s[2], v[2]->specular); SS_IND(i[2], v[2]->index); } } @@ -75,39 +75,45 @@ static void TAG(triangle)(GLcontext *ctx, if (IND & (SS_TWOSIDE_BIT | SS_UNFILLED_BIT)) { - GLuint facing = (cc < 0.0) ^ ctx->Polygon.FrontBit; + GLuint facing = (cc < 0.0) ^ ctx->Polygon._FrontBit; if (IND & SS_UNFILLED_BIT) mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode; if (IND & SS_TWOSIDE_BIT) { - GLubyte (*vbcolor)[4] = VB->Color[facing]->data; - GLubyte (*vbspec)[4] = VB->SecondaryColor[facing]->data; - GLuint *vbindex = VB->Index[facing]->data; - if (IND & SS_FLAT_BIT) { - SS_COLOR(v[0]->color, vbcolor[pv]); - SS_COLOR(v[1]->color, vbcolor[pv]); - SS_COLOR(v[2]->color, vbcolor[pv]); + if (IND & SS_RGBA_BIT) { + GLubyte (*vbcolor)[4] = VB->ColorPtr[facing]->data; + GLubyte (*vbspec)[4] = VB->SecondaryColorPtr[facing]->data; + + SS_COLOR(v[0]->color, vbcolor[pv]); + SS_COLOR(v[1]->color, vbcolor[pv]); + SS_COLOR(v[2]->color, vbcolor[pv]); - if (IND & SS_COPY_EXTRAS) { SS_SPEC(v[0]->specular, vbspec[pv]); SS_SPEC(v[1]->specular, vbspec[pv]); SS_SPEC(v[2]->specular, vbspec[pv]); - + } else { + GLuint *vbindex = VB->IndexPtr[facing]->data; + SS_IND(v[0]->index, vbindex[pv]); SS_IND(v[1]->index, vbindex[pv]); SS_IND(v[2]->index, vbindex[pv]); } } else { - SS_COLOR(v[0]->color, vbcolor[e0]); - SS_COLOR(v[1]->color, vbcolor[e1]); - SS_COLOR(v[2]->color, vbcolor[e2]); + if (IND & SS_RGBA_BIT) { + GLubyte (*vbcolor)[4] = VB->ColorPtr[facing]->data; + GLubyte (*vbspec)[4] = VB->SecondaryColorPtr[facing]->data; + + SS_COLOR(v[0]->color, vbcolor[e0]); + SS_COLOR(v[1]->color, vbcolor[e1]); + SS_COLOR(v[2]->color, vbcolor[e2]); - if (IND & SS_COPY_EXTRAS) { SS_SPEC(v[0]->specular, vbspec[e0]); SS_SPEC(v[1]->specular, vbspec[e1]); SS_SPEC(v[2]->specular, vbspec[e2]); + } else { + GLuint *vbindex = VB->IndexPtr[facing]->data; SS_IND(v[0]->index, vbindex[e0]); SS_IND(v[1]->index, vbindex[e1]); @@ -139,14 +145,15 @@ static void TAG(triangle)(GLcontext *ctx, } else if (IND & SS_FLAT_BIT) { - GLubyte *color = VB->Color[0]->data[pv]; - GLubyte *spec = VB->SecondaryColor[0]->data[pv]; - GLuint index = VB->Index[0]->data[pv]; + if (IND & SS_RGBA_BIT) { + GLubyte *color = VB->ColorPtr[0]->data[pv]; + GLubyte *spec = VB->SecondaryColorPtr[0]->data[pv]; - SS_COLOR(v[0]->color, color); - - if (IND & SS_COPY_EXTRAS) { + SS_COLOR(v[0]->color, color); SS_SPEC(v[0]->specular, spec); + } + else { + GLuint index = VB->IndexPtr[0]->data[pv]; SS_IND(v[0]->index, index); } } @@ -158,9 +165,9 @@ static void TAG(triangle)(GLcontext *ctx, v[1]->win[2] += offset; v[2]->win[2] += offset; } - if (ef[e0]&0x1) { ef[e0] &= ~0x1; _swrast_Point( ctx, v[0] ); } - if (ef[e1]&0x1) { ef[e1] &= ~0x1; _swrast_Point( ctx, v[1] ); } - if (ef[e2]&0x2) { ef[e2] &= ~0x2; _swrast_Point( ctx, v[2] ); } + if (ef[e0]) _swrast_Point( ctx, v[0] ); + if (ef[e1]) _swrast_Point( ctx, v[1] ); + if (ef[e2]) _swrast_Point( ctx, v[2] ); } else if (mode == GL_LINE) { GLubyte *ef = VB->EdgeFlagPtr->data; if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetLine) { @@ -168,9 +175,9 @@ static void TAG(triangle)(GLcontext *ctx, v[1]->win[2] += offset; v[2]->win[2] += offset; } - if (ef[e0]&0x1) { ef[e0] &= ~0x1; _swrast_Line( ctx, v[0], v[1] ); } - if (ef[e1]&0x1) { ef[e1] &= ~0x1; _swrast_Line( ctx, v[1], v[2] ); } - if (ef[e2]&0x2) { ef[e2] &= ~0x2; _swrast_Line( ctx, v[2], v[0] ); } + if (ef[e0]) _swrast_Line( ctx, v[0], v[1] ); + if (ef[e1]) _swrast_Line( ctx, v[1], v[2] ); + if (ef[e2]) _swrast_Line( ctx, v[2], v[0] ); } else { if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetFill) { v[0]->win[2] += offset; @@ -187,22 +194,22 @@ static void TAG(triangle)(GLcontext *ctx, } if (IND & (SS_FLAT_BIT | SS_TWOSIDE_BIT)) { - SS_COLOR(v[0]->color, c[0]); + if (IND & SS_RGBA_BIT) { + SS_COLOR(v[0]->color, c[0]); + SS_SPEC(v[0]->specular, s[0]); - if (IND & SS_TWOSIDE_BIT) { - SS_COLOR(v[1]->color, c[1]); - SS_COLOR(v[2]->color, c[2]); + if (IND & SS_TWOSIDE_BIT) { + SS_COLOR(v[1]->color, c[1]); + SS_COLOR(v[2]->color, c[2]); + SS_SPEC(v[1]->specular, s[1]); + SS_SPEC(v[2]->specular, s[2]); + } } - - if (IND & SS_COPY_EXTRAS) { - SS_SPEC(v[0]->specular, s[0]); + else { SS_IND(v[0]->index, i[0]); if (IND & SS_TWOSIDE_BIT) { - SS_SPEC(v[1]->specular, s[1]); SS_IND(v[1]->index, i[1]); - - SS_SPEC(v[2]->specular, s[2]); SS_IND(v[2]->index, i[2]); } } @@ -217,15 +224,27 @@ static void TAG(quad)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, GLuint pv ) { - TAG(triangle)( ctx, v0, v1, v3, pv ); - TAG(triangle)( ctx, v1, v2, v3, pv ); + if (IND & SS_UNFILLED_BIT) { + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + GLubyte ef1 = VB->EdgeFlagPtr->data[v1]; + GLubyte ef3 = VB->EdgeFlagPtr->data[v3]; + VB->EdgeFlagPtr->data[v1] = 0; + TAG(triangle)( ctx, v0, v1, v3, pv ); + VB->EdgeFlagPtr->data[v1] = ef1; + VB->EdgeFlagPtr->data[v3] = 0; + TAG(triangle)( ctx, v1, v2, v3, pv ); + VB->EdgeFlagPtr->data[v3] = ef3; + } else { + TAG(triangle)( ctx, v0, v1, v3, pv ); + TAG(triangle)( ctx, v1, v2, v3, pv ); + } } static void TAG(line)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint pv ) { - struct vertex_buffer *VB = TNL_VB(ctx); - SWvertex *verts = SWSETUP_VB(VB)->verts; + struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; + SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; GLubyte c[2][4], s[2][4]; GLuint i[2]; SWvertex *vert0 = &verts[v0]; @@ -233,16 +252,18 @@ static void TAG(line)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint pv ) if (IND & SS_FLAT_BIT) { - GLubyte *color = VB->Color[0]->data[pv]; - GLubyte *spec = VB->SecondaryColor[0]->data[pv]; - GLuint index = VB->Index[0]->data[pv]; + if (IND & SS_RGBA_BIT) { + GLubyte *color = VB->ColorPtr[0]->data[pv]; + GLubyte *spec = VB->SecondaryColorPtr[0]->data[pv]; - SS_COLOR(c[0], vert0->color); - SS_COLOR(vert0->color, color); + SS_COLOR(c[0], vert0->color); + SS_COLOR(vert0->color, color); - if (IND & SS_COPY_EXTRAS) { SS_SPEC(s[0], vert0->specular); SS_SPEC(vert0->specular, spec); + } + else { + GLuint index = VB->IndexPtr[0]->data[pv]; SS_IND(i[0], vert0->index); SS_IND(vert0->index, index); @@ -252,36 +273,23 @@ static void TAG(line)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint pv ) _swrast_Line( ctx, vert0, vert1 ); if (IND & SS_FLAT_BIT) { - SS_COLOR(vert0->color, c[0]); - - if (IND & SS_COPY_EXTRAS) { + if (IND & SS_RGBA_BIT) { + SS_COLOR(vert0->color, c[0]); SS_SPEC(vert0->specular, s[0]); + } + else { SS_IND(vert0->index, i[0]); } } } -static void TAG(points)( GLcontext *ctx, GLuint first, GLuint last ) -{ - struct vertex_buffer *VB = TNL_VB(ctx); - SWvertex *verts = SWSETUP_VB(VB)->verts; - int i; - - for(i=first;i<=last;i++) - if(VB->ClipMask[i]==0) - _swrast_Point( ctx, &verts[i] ); -} - - - static void TAG(init)( void ) { tri_tab[IND] = TAG(triangle); quad_tab[IND] = TAG(quad); line_tab[IND] = TAG(line); - points_tab[IND] = TAG(points); } diff --git a/src/mesa/swrast_setup/ss_vb.c b/src/mesa/swrast_setup/ss_vb.c index 25f2299f47..f6720dc2f7 100644 --- a/src/mesa/swrast_setup/ss_vb.c +++ b/src/mesa/swrast_setup/ss_vb.c @@ -31,7 +31,6 @@ #include "swrast/swrast.h" #include "tnl/t_context.h" -#include "tnl/t_stages.h" #include "math/m_vector.h" #include "ss_context.h" @@ -44,8 +43,8 @@ * in this module, but not the rest of the swrast module. */ -typedef void (*SetupFunc)( struct vertex_buffer *VB, - GLuint start, GLuint end ); +typedef void (*SetupFunc)( GLcontext *ctx, + GLuint start, GLuint end, GLuint newinputs ); #define COLOR 0x1 #define INDEX 0x2 @@ -59,47 +58,145 @@ typedef void (*SetupFunc)( struct vertex_buffer *VB, static SetupFunc setup_func[MAX_SETUPFUNC]; +#define IND (0) +#define TAG(x) x##_none +#include "ss_vbtmp.h" + #define IND (COLOR) #define TAG(x) x##_color #include "ss_vbtmp.h" -#define IND (INDEX) -#define TAG(x) x##_index +#define IND (COLOR|SPEC) +#define TAG(x) x##_color_spec +#include "ss_vbtmp.h" + +#define IND (COLOR|FOG) +#define TAG(x) x##_color_fog +#include "ss_vbtmp.h" + +#define IND (COLOR|SPEC|FOG) +#define TAG(x) x##_color_spec_fog +#include "ss_vbtmp.h" + +#define IND (COLOR|TEX0) +#define TAG(x) x##_color_tex0 +#include "ss_vbtmp.h" + +#define IND (COLOR|TEX0|SPEC) +#define TAG(x) x##_color_tex0_spec +#include "ss_vbtmp.h" + +#define IND (COLOR|TEX0|FOG) +#define TAG(x) x##_color_tex0_fog #include "ss_vbtmp.h" -#define IND (TEX0|COLOR) -#define TAG(x) x##_tex0_color +#define IND (COLOR|TEX0|SPEC|FOG) +#define TAG(x) x##_color_tex0_spec_fog #include "ss_vbtmp.h" -#define IND (TEX0|COLOR|SPEC) -#define TAG(x) x##_tex0_color_spec +#define IND (COLOR|MULTITEX) +#define TAG(x) x##_color_multitex #include "ss_vbtmp.h" -#define IND (TEX0|COLOR|SPEC|FOG) -#define TAG(x) x##_tex0_color_spec_fog +#define IND (COLOR|MULTITEX|SPEC) +#define TAG(x) x##_color_multitex_spec #include "ss_vbtmp.h" -#define IND (MULTITEX|COLOR) -#define TAG(x) x##_multitex_color +#define IND (COLOR|MULTITEX|FOG) +#define TAG(x) x##_color_multitex_fog #include "ss_vbtmp.h" -#define IND (MULTITEX|COLOR|SPEC|FOG) -#define TAG(x) x##_multitex_color_spec_fog +#define IND (COLOR|MULTITEX|SPEC|FOG) +#define TAG(x) x##_color_multitex_spec_fog #include "ss_vbtmp.h" -#define IND (TEX0|COLOR|POINT) -#define TAG(x) x##_tex0_color_point +#define IND (COLOR|POINT) +#define TAG(x) x##_color_point #include "ss_vbtmp.h" -#define IND (MULTITEX|COLOR|SPEC|INDEX|POINT|FOG) -#define TAG(x) x##_multitex_color_spec_index_point_fog +#define IND (COLOR|SPEC|POINT) +#define TAG(x) x##_color_spec_point #include "ss_vbtmp.h" -#define IND (COLOR|INDEX|TEX0) -#define TAG(x) x##_selection_feedback +#define IND (COLOR|FOG|POINT) +#define TAG(x) x##_color_fog_point #include "ss_vbtmp.h" +#define IND (COLOR|SPEC|FOG|POINT) +#define TAG(x) x##_color_spec_fog_point +#include "ss_vbtmp.h" + +#define IND (COLOR|TEX0|POINT) +#define TAG(x) x##_color_tex0_point +#include "ss_vbtmp.h" + +#define IND (COLOR|TEX0|SPEC|POINT) +#define TAG(x) x##_color_tex0_spec_point +#include "ss_vbtmp.h" + +#define IND (COLOR|TEX0|FOG|POINT) +#define TAG(x) x##_color_tex0_fog_point +#include "ss_vbtmp.h" +#define IND (COLOR|TEX0|SPEC|FOG|POINT) +#define TAG(x) x##_color_tex0_spec_fog_point +#include "ss_vbtmp.h" + +#define IND (COLOR|MULTITEX|POINT) +#define TAG(x) x##_color_multitex_point +#include "ss_vbtmp.h" + +#define IND (COLOR|MULTITEX|SPEC|POINT) +#define TAG(x) x##_color_multitex_spec_point +#include "ss_vbtmp.h" + +#define IND (COLOR|MULTITEX|FOG|POINT) +#define TAG(x) x##_color_multitex_fog_point +#include "ss_vbtmp.h" + +#define IND (COLOR|MULTITEX|SPEC|FOG|POINT) +#define TAG(x) x##_color_multitex_spec_fog_point +#include "ss_vbtmp.h" + +#define IND (INDEX) +#define TAG(x) x##_index +#include "ss_vbtmp.h" + +#define IND (INDEX|TEX0) +#define TAG(x) x##_index_tex0 +#include "ss_vbtmp.h" + +#define IND (INDEX|FOG) +#define TAG(x) x##_index_fog +#include "ss_vbtmp.h" + +#define IND (INDEX|TEX0|FOG) +#define TAG(x) x##_index_tex0_fog +#include "ss_vbtmp.h" + +#define IND (INDEX|POINT) +#define TAG(x) x##_index_point +#include "ss_vbtmp.h" + +#define IND (INDEX|TEX0|POINT) +#define TAG(x) x##_index_tex0_point +#include "ss_vbtmp.h" + +#define IND (INDEX|FOG|POINT) +#define TAG(x) x##_index_fog_point +#include "ss_vbtmp.h" + +#define IND (INDEX|TEX0|FOG|POINT) +#define TAG(x) x##_index_tex0_fog_point +#include "ss_vbtmp.h" + + +static void +rs_invalid( GLcontext *ctx, GLuint start, GLuint end, GLuint newinputs ) +{ + fprintf(stderr, "swrast_setup: invalid setup function\n"); + (void) (ctx && start && end && newinputs); +} void _swsetup_vb_init( GLcontext *ctx ) @@ -108,45 +205,41 @@ _swsetup_vb_init( GLcontext *ctx ) (void) ctx; for (i = 0 ; i < Elements(setup_func) ; i++) - setup_func[i] = rs_multitex_color_spec_index_point_fog; + setup_func[i] = rs_invalid; - /* Some specialized cases: - */ - setup_func[0] = rs_color; + setup_func[0] = rs_none; setup_func[COLOR] = rs_color; - + setup_func[COLOR|SPEC] = rs_color_spec; + setup_func[COLOR|FOG] = rs_color_fog; + setup_func[COLOR|SPEC|FOG] = rs_color_spec_fog; + setup_func[COLOR|TEX0] = rs_color_tex0; + setup_func[COLOR|TEX0|SPEC] = rs_color_tex0_spec; + setup_func[COLOR|TEX0|FOG] = rs_color_tex0_fog; + setup_func[COLOR|TEX0|SPEC|FOG] = rs_color_tex0_spec_fog; + setup_func[COLOR|MULTITEX] = rs_color_multitex; + setup_func[COLOR|MULTITEX|SPEC] = rs_color_multitex_spec; + setup_func[COLOR|MULTITEX|FOG] = rs_color_multitex_fog; + setup_func[COLOR|MULTITEX|SPEC|FOG] = rs_color_multitex_spec_fog; + setup_func[COLOR|POINT] = rs_color_point; + setup_func[COLOR|SPEC|POINT] = rs_color_spec_point; + setup_func[COLOR|FOG|POINT] = rs_color_fog_point; + setup_func[COLOR|SPEC|FOG|POINT] = rs_color_spec_fog_point; + setup_func[COLOR|TEX0|POINT] = rs_color_tex0_point; + setup_func[COLOR|TEX0|SPEC|POINT] = rs_color_tex0_spec_point; + setup_func[COLOR|TEX0|FOG|POINT] = rs_color_tex0_fog_point; + setup_func[COLOR|TEX0|SPEC|FOG|POINT] = rs_color_tex0_spec_fog_point; + setup_func[COLOR|MULTITEX|POINT] = rs_color_multitex_point; + setup_func[COLOR|MULTITEX|SPEC|POINT] = rs_color_multitex_spec_point; + setup_func[COLOR|MULTITEX|FOG|POINT] = rs_color_multitex_fog_point; + setup_func[COLOR|MULTITEX|SPEC|FOG|POINT] = rs_color_multitex_spec_fog_point; setup_func[INDEX] = rs_index; - - setup_func[TEX0] = rs_tex0_color; - setup_func[TEX0|COLOR] = rs_tex0_color; - - setup_func[SPEC] = rs_tex0_color_spec; - setup_func[COLOR|SPEC] = rs_tex0_color_spec; - setup_func[TEX0|SPEC] = rs_tex0_color_spec; - setup_func[TEX0|COLOR|SPEC] = rs_tex0_color_spec; - - setup_func[MULTITEX] = rs_multitex_color; - setup_func[MULTITEX|COLOR] = rs_multitex_color; - - setup_func[FOG] = rs_tex0_color_spec_fog; - setup_func[COLOR|FOG] = rs_tex0_color_spec_fog; - setup_func[SPEC|FOG] = rs_tex0_color_spec_fog; - setup_func[COLOR|SPEC|FOG] = rs_tex0_color_spec_fog; - setup_func[TEX0|FOG] = rs_tex0_color_spec_fog; - setup_func[TEX0|COLOR|FOG] = rs_tex0_color_spec_fog; - setup_func[TEX0|SPEC|FOG] = rs_tex0_color_spec_fog; - setup_func[TEX0|COLOR|SPEC|FOG] = rs_tex0_color_spec_fog; - - setup_func[MULTITEX|SPEC] = rs_multitex_color_spec_fog; - setup_func[MULTITEX|COLOR|SPEC] = rs_multitex_color_spec_fog; - setup_func[MULTITEX|FOG] = rs_multitex_color_spec_fog; - setup_func[MULTITEX|SPEC|FOG] = rs_multitex_color_spec_fog; - setup_func[MULTITEX|COLOR|SPEC|FOG] = rs_multitex_color_spec_fog; - - setup_func[TEX0|POINT] = rs_tex0_color_point; - setup_func[TEX0|COLOR|POINT] = rs_tex0_color_point; - - setup_func[COLOR|INDEX|TEX0] = rs_selection_feedback; + setup_func[INDEX|TEX0] = rs_index_tex0; + setup_func[INDEX|FOG] = rs_index_fog; + setup_func[INDEX|TEX0|FOG] = rs_index_tex0_fog; + setup_func[INDEX|POINT] = rs_index_point; + setup_func[INDEX|TEX0|POINT] = rs_index_tex0_point; + setup_func[INDEX|FOG|POINT] = rs_index_fog_point; + setup_func[INDEX|TEX0|FOG|POINT] = rs_index_tex0_fog_point; } @@ -154,7 +247,7 @@ void _swsetup_choose_rastersetup_func(GLcontext *ctx) { SScontext *swsetup = SWSETUP_CONTEXT(ctx); - int funcindex; + int funcindex = 0; if (ctx->RenderMode == GL_RENDER) { if (ctx->Visual.RGBAflag) { @@ -179,11 +272,16 @@ _swsetup_choose_rastersetup_func(GLcontext *ctx) if (ctx->Fog.Enabled) funcindex |= FOG; } - else { - /* feedback or section */ - funcindex = (COLOR | INDEX | TEX0); - } - - swsetup->RasterSetup = setup_func[funcindex]; + else if (ctx->RenderMode == GL_FEEDBACK) { + if (ctx->Visual.RGBAflag) + funcindex = (COLOR | TEX0); /* is feedback color subject to fogging? */ + else + funcindex = (INDEX | TEX0); + } + else + funcindex = 0; + + swsetup->BuildProjVerts = setup_func[funcindex]; + ASSERT(setup_func[funcindex] != rs_invalid); } diff --git a/src/mesa/swrast_setup/ss_vbtmp.h b/src/mesa/swrast_setup/ss_vbtmp.h index 7ed4d51441..f5a4c449e7 100644 --- a/src/mesa/swrast_setup/ss_vbtmp.h +++ b/src/mesa/swrast_setup/ss_vbtmp.h @@ -26,80 +26,92 @@ */ -static void TAG(rs)(struct vertex_buffer *VB, GLuint start, GLuint end) +static void TAG(rs)(GLcontext *ctx, GLuint start, GLuint end, GLuint newinputs ) { - GLcontext *ctx = VB->ctx; TNLcontext *tnl = TNL_CONTEXT(ctx); + struct vertex_buffer *VB = &tnl->vb; SWvertex *v; - GLfloat (*eye)[4]; - GLfloat (*win)[4]; + GLfloat (*proj)[4]; /* projected clip coordinates */ GLfloat (*tc[MAX_TEXTURE_UNITS])[4]; GLubyte (*color)[4]; GLubyte (*spec)[4]; GLuint *index; GLfloat *fog; GLfloat *pointSize; - GLuint sz[MAX_TEXTURE_UNITS]; - GLuint szeye; + GLuint tsz[MAX_TEXTURE_UNITS]; int i; + GLfloat *m = ctx->Viewport._WindowMap.m; + const GLfloat sx = m[0]; + const GLfloat sy = m[5]; + const GLfloat sz = m[10]; + const GLfloat tx = m[12]; + const GLfloat ty = m[13]; + const GLfloat tz = m[14]; + GLuint maxtex = 0; - /* TODO: Do window map here. - */ -/* GLfloat *m = VB->ctx->Viewport.WindowMap.m; */ -/* const GLfloat sx = m[0]; */ -/* const GLfloat sy = m[5]; */ -/* const GLfloat sz = m[10] * ctx->Visual->DepthMaxF; */ -/* const GLfloat tx = m[12]; */ -/* const GLfloat ty = m[13]; */ -/* const GLfloat tz = m[14] * ctx->Visual->DepthMaxF; */ - +/* fprintf(stderr, "%s\n", __FUNCTION__); */ /* TODO: Get import_client_data to pad vectors out to 4 cleanly. */ - _tnl_import_client_data( VB, tnl->_RenderFlags, - (VB->ClipOrMask - ? /* VEC_CLEAN| */VEC_WRITABLE|VEC_GOOD_STRIDE - : /* VEC_CLEAN| */VEC_GOOD_STRIDE)); - + if (VB->importable_data) + VB->import_data( ctx, VB->importable_data & newinputs, + (VB->ClipOrMask + ? VEC_NOT_WRITEABLE|VEC_BAD_STRIDE + : VEC_BAD_STRIDE)); + if (IND & TEX0) { tc[0] = VB->TexCoordPtr[0]->data; - sz[0] = VB->TexCoordPtr[0]->size; + tsz[0] = VB->TexCoordPtr[0]->size; } if (IND & MULTITEX) { - for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) { - tc[i] = VB->TexCoordPtr[i]->data; - sz[i] = VB->TexCoordPtr[i]->size; + for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) { + if (VB->TexCoordPtr[i]) { + maxtex = i+1; + tc[i] = VB->TexCoordPtr[i]->data; + tsz[i] = VB->TexCoordPtr[i]->size; + } + else tc[i] = 0; } } - fog = VB->FogCoordPtr->data; - eye = VB->EyePtr->data; - szeye = VB->EyePtr->size; - win = VB->Win.data; - color = VB->Color[0]->data; - spec = VB->SecondaryColor[0]->data; - index = VB->Index[0]->data; - pointSize = VB->PointSize.data; + /* Tie up some dangling pointers for flat/twoside code in ss_tritmp.h + */ + if ((ctx->_TriangleCaps & DD_SEPERATE_SPECULAR) == 0) { + VB->SecondaryColorPtr[0] = VB->ColorPtr[0]; + VB->SecondaryColorPtr[1] = VB->ColorPtr[1]; + } + + + proj = VB->ProjectedClipPtr->data; + if (IND & FOG) + fog = VB->FogCoordPtr->data; + if (IND & COLOR) + color = VB->ColorPtr[0]->data; + if (IND & SPEC) + spec = VB->SecondaryColorPtr[0]->data; + if (IND & INDEX) + index = VB->IndexPtr[0]->data; + if (IND & POINT) + pointSize = VB->PointSizePtr->data; - v = &(SWSETUP_VB(VB)->verts[start]); + v = &(SWSETUP_CONTEXT(ctx)->verts[start]); for (i=start; i < end; i++, v++) { if (VB->ClipMask[i] == 0) { - COPY_4FV( v->win, win[i] ); + v->win[0] = sx * proj[i][0] + tx; + v->win[1] = sy * proj[i][1] + ty; + v->win[2] = sz * proj[i][2] + tz; + v->win[3] = proj[i][3]; -#if 0 - if (IND & EYE) - COPY_4FV( v->eye, eye[i] ); -#endif if (IND & TEX0) - COPY_CLEAN_4V( v->texcoord[0], sz[0], tc[0][i] ); + COPY_CLEAN_4V( v->texcoord[0], tsz[0], tc[0][i] ); if (IND & MULTITEX) { GLuint u; - for (u = 0 ; u < MAX_TEXTURE_UNITS ; u++) - if (ctx->Texture.Unit[u]._ReallyEnabled) - COPY_CLEAN_4V( v->texcoord[u], sz[u], tc[u][i] ); + for (u = 0 ; u < maxtex ; u++) + if (tc[u]) + COPY_CLEAN_4V( v->texcoord[u], tsz[u], tc[u][i] ); } if (IND & COLOR) @@ -122,3 +134,4 @@ static void TAG(rs)(struct vertex_buffer *VB, GLuint start, GLuint end) #undef TAG #undef IND +#undef SETUP_FLAGS diff --git a/src/mesa/swrast_setup/swrast_setup.h b/src/mesa/swrast_setup/swrast_setup.h index aa32f06f24..e5ea966821 100644 --- a/src/mesa/swrast_setup/swrast_setup.h +++ b/src/mesa/swrast_setup/swrast_setup.h @@ -37,18 +37,14 @@ _swsetup_CreateContext( GLcontext *ctx ); extern void _swsetup_DestroyContext( GLcontext *ctx ); -extern void -_swsetup_RegisterVB( struct vertex_buffer *VB ); - -extern void -_swsetup_UnregisterVB( struct vertex_buffer *VB ); - extern void _swsetup_InvalidateState( GLcontext *ctx, GLuint new_state ); extern void -_swsetup_RasterSetup( struct vertex_buffer *VB, - GLuint start, GLuint end ); +_swsetup_BuildProjectedVertices( GLcontext *ctx, + GLuint start, + GLuint end, + GLuint new_inputs ); extern void _swsetup_Quad( GLcontext *ctx, GLuint v0, GLuint v1, @@ -66,5 +62,8 @@ _swsetup_Line( GLcontext *ctx, GLuint v0, GLuint v1, GLuint pv ); extern void _swsetup_Points( GLcontext *ctx, GLuint first, GLuint last ); +extern void +_swsetup_IndexedPoints( GLcontext *ctx, GLuint first, GLuint last ); + #endif -- cgit v1.2.3