/* Called in place of do_lighting when the light table may have changed. */ static void validate_lighting( GLcontext *ctx, struct tnl_pipeline_stage *stage ) { light_func *tab; if (ctx->ShaderObjects._VertexShaderPresent) return; if (!ctx->Light.Enabled || ctx->VertexProgram._Enabled) return; if (ctx->Visual.rgbMode) { if (ctx->Light._NeedVertices) { if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) tab = _tnl_light_spec_tab; else tab = _tnl_light_tab; } else { if (ctx->Light.EnabledList.next == ctx->Light.EnabledList.prev) tab = _tnl_light_fast_single_tab; else tab = _tnl_light_fast_tab; } } else tab = _tnl_light_ci_tab; LIGHT_STAGE_DATA(stage)->light_func_tab = tab; /* This and the above should only be done on _NEW_LIGHT: */ TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx ); }
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 idx; if (!ctx->Light.Enabled || ctx->VertexProgram._Current) return GL_TRUE; /* Make sure we can talk about position x,y and z: */ 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); } input = &store->Input; } idx = 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[idx]( ctx, VB, stage, input ); VB->AttribPtr[_TNL_ATTRIB_COLOR0] = VB->ColorPtr[0]; VB->AttribPtr[_TNL_ATTRIB_COLOR1] = VB->SecondaryColorPtr[0]; VB->AttribPtr[_TNL_ATTRIB_COLOR_INDEX] = VB->IndexPtr[0]; return GL_TRUE; }
static void dtr( struct tnl_pipeline_stage *stage ) { struct light_stage_data *store = LIGHT_STAGE_DATA(stage); if (store) { _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 = NULL; } }
/* Called the first time stage->run is called. In effect, don't * allocate data until the first time the stage is run. */ static GLboolean init_lighting( GLcontext *ctx, struct tnl_pipeline_stage *stage ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct light_stage_data *store; GLuint size = tnl->vb.Size; stage->privatePtr = MALLOC(sizeof(*store)); store = LIGHT_STAGE_DATA(stage); if (!store) return GL_FALSE; /* Do onetime init. */ init_lighting_tables(); _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 ); store->LitColor[0].size = 4; store->LitColor[1].size = 4; store->LitSecondary[0].size = 3; store->LitSecondary[1].size = 3; store->LitIndex[0].size = 1; store->LitIndex[0].stride = sizeof(GLfloat); store->LitIndex[1].size = 1; store->LitIndex[1].stride = sizeof(GLfloat); return GL_TRUE; }