diff options
author | Keith Whitwell <[email protected]> | 2003-11-24 15:23:18 +0000 |
---|---|---|
committer | Keith Whitwell <[email protected]> | 2003-11-24 15:23:18 +0000 |
commit | ae0eaf93e092ac8e8b1c98f3e986de96940663fa (patch) | |
tree | 56aae7c4b985f657384df5e088227c4dd08130fb /src/mesa/tnl/t_vb_light.c | |
parent | 57c9814b9e87924696df4c741861c29d4236d1eb (diff) |
Merge vtx-0-2-branch
Diffstat (limited to 'src/mesa/tnl/t_vb_light.c')
-rw-r--r-- | src/mesa/tnl/t_vb_light.c | 274 |
1 files changed, 138 insertions, 136 deletions
diff --git a/src/mesa/tnl/t_vb_light.c b/src/mesa/tnl/t_vb_light.c index 3252df9b30f..d7872675ca8 100644 --- a/src/mesa/tnl/t_vb_light.c +++ b/src/mesa/tnl/t_vb_light.c @@ -38,68 +38,93 @@ #include "t_context.h" #include "t_pipeline.h" -#define LIGHT_FLAGS 0x1 /* must be first */ -#define LIGHT_TWOSIDE 0x2 -#define LIGHT_COLORMATERIAL 0x4 -#define MAX_LIGHT_FUNC 0x8 +#define LIGHT_TWOSIDE 0x1 +#define LIGHT_MATERIAL 0x2 +#define MAX_LIGHT_FUNC 0x4 typedef void (*light_func)( GLcontext *ctx, struct vertex_buffer *VB, - struct gl_pipeline_stage *stage, + struct tnl_pipeline_stage *stage, GLvector4f *input ); +struct material_cursor { + const GLfloat *ptr; + GLuint stride; + GLfloat *current; +}; + struct light_stage_data { - struct gl_client_array FloatColor; - struct gl_client_array LitColor[2]; - struct gl_client_array LitSecondary[2]; - GLvector1ui LitIndex[2]; + GLvector4f Input; + GLvector4f LitColor[2]; + GLvector4f LitSecondary[2]; + GLvector4f LitIndex[2]; light_func *light_func_tab; + + struct material_cursor mat[MAT_ATTRIB_MAX]; + GLuint mat_count; + GLuint mat_bitmask; }; #define LIGHT_STAGE_DATA(stage) ((struct light_stage_data *)(stage->privatePtr)) -static void import_color_material( GLcontext *ctx, - struct gl_pipeline_stage *stage ) + +/* In the case of colormaterial, the effected material attributes + * should already have been bound to point to the incoming color data, + * prior to running the pipeline. + */ +static void update_materials( GLcontext *ctx, + struct light_stage_data *store ) { - struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; - struct gl_client_array *to = &LIGHT_STAGE_DATA(stage)->FloatColor; - struct gl_client_array *from = VB->ColorPtr[0]; - GLuint count = VB->Count; - - if (!to->Ptr) { - to->Ptr = (GLubyte *) ALIGN_MALLOC( VB->Size * 4 * sizeof(GLfloat), 32 ); - to->Type = GL_FLOAT; + GLuint i; + + for (i = 0 ; i < store->mat_count ; i++) { + COPY_4V(store->mat[i].current, store->mat[i].ptr); + STRIDE_F(store->mat[i].ptr, store->mat[i].stride); } + + _mesa_update_material( ctx, store->mat_bitmask ); + _mesa_validate_all_lighting_tables( ctx ); +} + +static GLuint prepare_materials( GLcontext *ctx, + struct vertex_buffer *VB, + struct light_stage_data *store ) +{ + GLuint i; + + store->mat_count = 0; + store->mat_bitmask = 0; - /* No need to transform the same value 3000 times. + /* If ColorMaterial enabled, overwrite affected AttrPtr's with + * the color pointer. This could be done earlier. */ - if (!from->StrideB) { - to->StrideB = 0; - count = 1; + if (ctx->Light.ColorMaterialEnabled) { + GLuint bitmask = ctx->Light.ColorMaterialBitmask; + for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) + if (bitmask & (1<<i)) + VB->AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = VB->ColorPtr[0]; + } + + for (i = _TNL_ATTRIB_MAT_FRONT_AMBIENT ; i < _TNL_ATTRIB_INDEX ; i++) { + if (VB->AttribPtr[i]->stride) { + GLuint j = store->mat_count++; + GLuint attr = i - _TNL_ATTRIB_MAT_FRONT_AMBIENT; + store->mat[j].ptr = VB->AttribPtr[i]->start; + store->mat[j].stride = VB->AttribPtr[i]->stride; + store->mat[j].current = ctx->Light.Material.Attrib[attr]; + store->mat_bitmask |= (1<<attr); + } } - else - to->StrideB = 4 * sizeof(GLfloat); - _math_trans_4fc( (GLfloat (*)[4]) to->Ptr, - from->Ptr, - from->StrideB, - from->Type, - from->Size, - 0, - count); - - VB->ColorPtr[0] = to; -} + /* FIXME: Is this already done? + */ + _mesa_update_material( ctx, ~0 ); + _mesa_validate_all_lighting_tables( ctx ); -static void update_materials( GLcontext *ctx, - const struct gl_material *src, - GLuint bitmask ) -{ - _mesa_copy_materials( &ctx->Light.Material, src, bitmask ); - _mesa_update_material( ctx, bitmask ); + return store->mat_count; } /* Tables for all the shading functions. @@ -114,32 +139,16 @@ static light_func _tnl_light_ci_tab[MAX_LIGHT_FUNC]; #define IDX (0) #include "t_vb_lighttmp.h" -#define TAG(x) x##_tw +#define TAG(x) x##_twoside #define IDX (LIGHT_TWOSIDE) #include "t_vb_lighttmp.h" -#define TAG(x) x##_fl -#define IDX (LIGHT_FLAGS) -#include "t_vb_lighttmp.h" - -#define TAG(x) x##_tw_fl -#define IDX (LIGHT_FLAGS|LIGHT_TWOSIDE) +#define TAG(x) x##_material +#define IDX (LIGHT_MATERIAL) #include "t_vb_lighttmp.h" -#define TAG(x) x##_cm -#define IDX (LIGHT_COLORMATERIAL) -#include "t_vb_lighttmp.h" - -#define TAG(x) x##_tw_cm -#define IDX (LIGHT_TWOSIDE|LIGHT_COLORMATERIAL) -#include "t_vb_lighttmp.h" - -#define TAG(x) x##_fl_cm -#define IDX (LIGHT_FLAGS|LIGHT_COLORMATERIAL) -#include "t_vb_lighttmp.h" - -#define TAG(x) x##_tw_fl_cm -#define IDX (LIGHT_FLAGS|LIGHT_TWOSIDE|LIGHT_COLORMATERIAL) +#define TAG(x) x##_twoside_material +#define IDX (LIGHT_TWOSIDE|LIGHT_MATERIAL) #include "t_vb_lighttmp.h" @@ -149,55 +158,64 @@ static void init_lighting( void ) if (!done) { init_light_tab(); - init_light_tab_tw(); - init_light_tab_fl(); - init_light_tab_tw_fl(); - init_light_tab_cm(); - init_light_tab_tw_cm(); - init_light_tab_fl_cm(); - init_light_tab_tw_fl_cm(); + init_light_tab_twoside(); + init_light_tab_material(); + init_light_tab_twoside_material(); done = 1; } } -static GLboolean run_lighting( GLcontext *ctx, struct gl_pipeline_stage *stage ) +static GLboolean run_lighting( GLcontext *ctx, + struct tnl_pipeline_stage *stage ) { struct light_stage_data *store = LIGHT_STAGE_DATA(stage); TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; GLvector4f *input = ctx->_NeedEyeCoords ? VB->EyePtr : VB->ObjPtr; - GLuint ind; + GLuint idx; -/* _tnl_print_vert_flags( __FUNCTION__, stage->changed_inputs ); */ - - /* Make sure we can talk about elements 0..2 in the vector we are - * lighting. + /* Make sure we can talk about position x,y and z: */ - if (stage->changed_inputs & (VERT_BIT_EYE|VERT_BIT_POS)) { - if (input->size <= 2) { - if (input->flags & VEC_NOT_WRITEABLE) { - ASSERT(VB->importable_data & VERT_BIT_POS); - - VB->import_data( ctx, VERT_BIT_POS, VEC_NOT_WRITEABLE ); - input = ctx->_NeedEyeCoords ? VB->EyePtr : VB->ObjPtr; - - ASSERT((input->flags & VEC_NOT_WRITEABLE) == 0); + if (stage->changed_inputs & _TNL_BIT_POS) { + if (input->size <= 2 && input == VB->ObjPtr) { + + _math_trans_4f( store->Input.data, + VB->ObjPtr->data, + VB->ObjPtr->stride, + GL_FLOAT, + VB->ObjPtr->size, + 0, + VB->Count ); + + if (input->size <= 2) { + /* Clean z. + */ + _mesa_vector4f_clean_elem(&store->Input, VB->Count, 2); + } + + if (input->size <= 1) { + /* Clean y. + */ + _mesa_vector4f_clean_elem(&store->Input, VB->Count, 1); } - _mesa_vector4f_clean_elem(input, VB->Count, 2); + input = &store->Input; } } + + idx = 0; - if (VB->Flag) - ind = LIGHT_FLAGS; - else - ind = 0; + if (prepare_materials( ctx, VB, store )) + idx |= LIGHT_MATERIAL; + + if (ctx->Light.Model.TwoSide) + idx |= LIGHT_TWOSIDE; /* The individual functions know about replaying side-effects * vs. full re-execution. */ - store->light_func_tab[ind]( ctx, VB, stage, input ); + store->light_func_tab[idx]( ctx, VB, stage, input ); return GL_TRUE; } @@ -206,9 +224,8 @@ static GLboolean run_lighting( GLcontext *ctx, struct gl_pipeline_stage *stage ) /* Called in place of do_lighting when the light table may have changed. */ static GLboolean run_validate_lighting( GLcontext *ctx, - struct gl_pipeline_stage *stage ) + struct tnl_pipeline_stage *stage ) { - GLuint ind = 0; light_func *tab; if (ctx->Visual.rgbMode) { @@ -228,13 +245,8 @@ static GLboolean run_validate_lighting( GLcontext *ctx, else tab = _tnl_light_ci_tab; - if (ctx->Light.ColorMaterialEnabled) - ind |= LIGHT_COLORMATERIAL; - - if (ctx->Light.Model.TwoSide) - ind |= LIGHT_TWOSIDE; - LIGHT_STAGE_DATA(stage)->light_func_tab = &tab[ind]; + LIGHT_STAGE_DATA(stage)->light_func_tab = tab; /* This and the above should only be done on _NEW_LIGHT: */ @@ -246,23 +258,13 @@ static GLboolean run_validate_lighting( GLcontext *ctx, return stage->run( ctx, stage ); } -static void alloc_4chan( struct gl_client_array *a, GLuint sz ) -{ - a->Ptr = (GLubyte *) ALIGN_MALLOC( sz * sizeof(GLchan) * 4, 32 ); - a->Size = 4; - a->Type = CHAN_TYPE; - a->Stride = 0; - a->StrideB = sizeof(GLchan) * 4; - a->Enabled = 0; - a->Flags = 0; -} /* Called the first time stage->run is called. In effect, don't * allocate data until the first time the stage is run. */ static GLboolean run_init_lighting( GLcontext *ctx, - struct gl_pipeline_stage *stage ) + struct tnl_pipeline_stage *stage ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct light_stage_data *store; @@ -277,15 +279,18 @@ static GLboolean run_init_lighting( GLcontext *ctx, */ init_lighting(); - store->FloatColor.Ptr = 0; - - alloc_4chan( &store->LitColor[0], size ); - alloc_4chan( &store->LitColor[1], size ); - alloc_4chan( &store->LitSecondary[0], size ); - alloc_4chan( &store->LitSecondary[1], size ); + _mesa_vector4f_alloc( &store->Input, 0, size, 32 ); + _mesa_vector4f_alloc( &store->LitColor[0], 0, size, 32 ); + _mesa_vector4f_alloc( &store->LitColor[1], 0, size, 32 ); + _mesa_vector4f_alloc( &store->LitSecondary[0], 0, size, 32 ); + _mesa_vector4f_alloc( &store->LitSecondary[1], 0, size, 32 ); + _mesa_vector4f_alloc( &store->LitIndex[0], 0, size, 32 ); + _mesa_vector4f_alloc( &store->LitIndex[1], 0, size, 32 ); - _mesa_vector1ui_alloc( &store->LitIndex[0], 0, size, 32 ); - _mesa_vector1ui_alloc( &store->LitIndex[1], 0, size, 32 ); + store->LitIndex[0].size = 1; + store->LitIndex[0].stride = sizeof(GLfloat); + store->LitIndex[1].size = 1; + store->LitIndex[1].stride = sizeof(GLfloat); /* Now validate the stage derived data... */ @@ -299,52 +304,49 @@ static GLboolean run_init_lighting( GLcontext *ctx, * Check if lighting is enabled. If so, configure the pipeline stage's * type, inputs, and outputs. */ -static void check_lighting( GLcontext *ctx, struct gl_pipeline_stage *stage ) +static void check_lighting( GLcontext *ctx, struct tnl_pipeline_stage *stage ) { stage->active = ctx->Light.Enabled && !ctx->VertexProgram.Enabled; if (stage->active) { if (stage->privatePtr) stage->run = run_validate_lighting; - stage->inputs = VERT_BIT_NORMAL|VERT_BIT_MATERIAL; + stage->inputs = _TNL_BIT_NORMAL|_TNL_BITS_MAT_ANY; if (ctx->Light._NeedVertices) - stage->inputs |= VERT_BIT_EYE; /* effectively, even when lighting in obj */ + stage->inputs |= _TNL_BIT_POS; if (ctx->Light.ColorMaterialEnabled) - stage->inputs |= VERT_BIT_COLOR0; + stage->inputs |= _TNL_BIT_COLOR0; - stage->outputs = VERT_BIT_COLOR0; + stage->outputs = _TNL_BIT_COLOR0; if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) - stage->outputs |= VERT_BIT_COLOR1; + stage->outputs |= _TNL_BIT_COLOR1; } } -static void dtr( struct gl_pipeline_stage *stage ) +static void dtr( struct tnl_pipeline_stage *stage ) { struct light_stage_data *store = LIGHT_STAGE_DATA(stage); if (store) { - ALIGN_FREE( (void *) store->LitColor[0].Ptr ); - ALIGN_FREE( (void *) store->LitColor[1].Ptr ); - ALIGN_FREE( (void *) store->LitSecondary[0].Ptr ); - ALIGN_FREE( (void *) store->LitSecondary[1].Ptr ); - - if (store->FloatColor.Ptr) - ALIGN_FREE( (void *) store->FloatColor.Ptr ); - - _mesa_vector1ui_free( &store->LitIndex[0] ); - _mesa_vector1ui_free( &store->LitIndex[1] ); + _mesa_vector4f_free( &store->Input ); + _mesa_vector4f_free( &store->LitColor[0] ); + _mesa_vector4f_free( &store->LitColor[1] ); + _mesa_vector4f_free( &store->LitSecondary[0] ); + _mesa_vector4f_free( &store->LitSecondary[1] ); + _mesa_vector4f_free( &store->LitIndex[0] ); + _mesa_vector4f_free( &store->LitIndex[1] ); FREE( store ); stage->privatePtr = 0; } } -const struct gl_pipeline_stage _tnl_lighting_stage = +const struct tnl_pipeline_stage _tnl_lighting_stage = { "lighting", /* name */ _NEW_LIGHT, /* recheck */ _NEW_LIGHT|_NEW_MODELVIEW, /* recalc -- modelview dependency * otherwise not captured by inputs - * (which may be VERT_BIT_POS) */ + * (which may be _TNL_BIT_POS) */ GL_FALSE, /* active? */ 0, /* inputs */ 0, /* outputs */ |