void Renderer::apply_state()
{
+ if(!state->shprog)
+ throw invalid_operation("Renderer::apply_state");
+
/* We (mostly) let the objects themselves figure out if the binding has
changed */
else
Clipping::unbind();
- if(state->shprog)
- {
- bool shprog_changed = (state->shprog!=Program::current());
- state->shprog->bind();
+ bool shprog_changed = (state->shprog!=Program::current());
+ state->shprog->bind();
- if(changed&MATRIX)
- {
- standard_shdata.uniform("eye_obj_matrix", state->modelview_matrix);
- LinAl::SquareMatrix<float, 3> nm = state->modelview_matrix.block<3, 3>(0, 0);
- nm = transpose(invert(nm));
- standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0));
- changed = (changed&~MATRIX)|STANDARD_SHDATA;
- }
+ if(changed&MATRIX)
+ {
+ standard_shdata.uniform("eye_obj_matrix", state->modelview_matrix);
+ LinAl::SquareMatrix<float, 3> nm = state->modelview_matrix.block<3, 3>(0, 0);
+ nm = transpose(invert(nm));
+ standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0));
+ changed = (changed&~MATRIX)|STANDARD_SHDATA;
+ }
- if(state->material && ((changed&MATERIAL_SHDATA) || shprog_changed))
- {
- state->material->get_shader_data().apply();
- changed &= ~MATERIAL_SHDATA;
- }
+ if(state->material && ((changed&MATERIAL_SHDATA) || shprog_changed))
+ {
+ state->material->get_shader_data().apply();
+ changed &= ~MATERIAL_SHDATA;
+ }
- if((changed&STANDARD_SHDATA) || shprog_changed)
- {
- standard_shdata.apply();
- changed &= ~STANDARD_SHDATA;
- }
+ if((changed&STANDARD_SHDATA) || shprog_changed)
+ {
+ standard_shdata.apply();
+ changed &= ~STANDARD_SHDATA;
+ }
- bool extra_shdata = (shdata_stack.size()>state->shdata_count);
+ bool extra_shdata = (shdata_stack.size()>state->shdata_count);
- if((changed&SHADER_DATA) || shprog_changed || extra_shdata)
- {
- if(extra_shdata)
- shdata_stack.erase(shdata_stack.begin()+state->shdata_count, shdata_stack.end());
- for(vector<const ProgramData *>::const_iterator i=shdata_stack.begin(); i!=shdata_stack.end(); ++i)
- (*i)->apply();
- changed &= ~SHADER_DATA;
- }
+ if((changed&SHADER_DATA) || shprog_changed || extra_shdata)
+ {
+ if(extra_shdata)
+ shdata_stack.erase(shdata_stack.begin()+state->shdata_count, shdata_stack.end());
+ for(vector<const ProgramData *>::const_iterator i=shdata_stack.begin(); i!=shdata_stack.end(); ++i)
+ (*i)->apply();
+ changed &= ~SHADER_DATA;
}
- else
- Program::unbind();
if(state->vertex_setup)
state->vertex_setup->bind();