state_stack.push_back(State());
shdata_stack.reserve(32);
state = &state_stack.back();
+ add_shader_data(standard_shdata);
}
Renderer::~Renderer()
void Renderer::set_camera(const Camera &c)
{
state->camera = &c;
- changed |= CAMERA_SHDATA;
+ add_shader_data(c.get_shader_data());
set_matrix(Matrix());
}
void Renderer::set_clipping(const Clipping *c)
{
state->clipping = c;
- changed |= CLIPPING_SHDATA;
+ if(c)
+ add_shader_data(c->get_shader_data());
}
void Renderer::set_shader_program(const Program *p, const ProgramData *d)
if(state_stack.size()==1)
throw stack_underflow("Renderer::pop_state");
- const Camera *old_camera = state->camera;
- const Clipping *old_clipping = state->clipping;
state_stack.pop_back();
state = &state_stack.back();
changed |= MATRIX;
- bool camera_changed = (state->camera!=old_camera);
- if(camera_changed)
- changed |= CAMERA_SHDATA;
- if(state->clipping!=old_clipping)
- changed |= CLIPPING_SHDATA;
}
void Renderer::end()
LinAl::SquareMatrix<float, 3> nm = state->model_matrix.block<3, 3>(0, 0);
nm = transpose(invert(nm));
standard_shdata.uniform("world_obj_normal_matrix", nm);
- changed = (changed&~MATRIX)|STANDARD_SHDATA;
- }
-
- if(state->camera && ((changed&CAMERA_SHDATA) || shprog_changed))
- {
- state->camera->get_shader_data().apply();
- changed &= ~CAMERA_SHDATA;
- }
-
- if(state->clipping && ((changed&CLIPPING_SHDATA) || shprog_changed))
- {
- state->clipping->get_shader_data().apply();
- changed &= ~CLIPPING_SHDATA;
- }
-
- if((changed&STANDARD_SHDATA) || shprog_changed)
- {
- standard_shdata.apply();
- changed &= ~STANDARD_SHDATA;
+ changed &= ~MATRIX;
}
bool shdata_changed = changed&SHADER_DATA;