Renderer::Renderer(const Camera *c):
mtx_stack(*this),
- mtx_changed(false),
+ mtx_changed(true),
+ matrices_loaded(false),
camera(c),
state_stack(1),
lighting_changed(false),
shdata_stack.reserve(32);
state = &state_stack.back();
- MatrixStack::modelview().push();
if(camera)
{
- MatrixStack::projection().push();
- camera->apply();
mtx_stack.load(camera->get_matrix());
standard_shdata.uniform("projection_matrix", camera->get_projection_matrix());
}
Renderer::~Renderer()
{
- if(camera)
- MatrixStack::projection().pop();
- MatrixStack::modelview().pop();
+ if(matrices_loaded)
+ {
+ if(camera)
+ MatrixStack::projection().pop();
+ MatrixStack::modelview().pop();
+ }
Mesh::unbind();
Texturing::unbind();
state->lighting = l;
state->lighting_matrix = mtx_stack.top();
if(l)
- /* XXX I'm not happy with this, but can't come up with anything better
- right now. */
- const_cast<Lighting *>(l)->update_shader_data(mtx_stack.top());
+ l->update_shader_data(standard_shdata, mtx_stack.top());
lighting_changed = true;
}
{
apply_state();
Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
+ matrices_loaded = false;
}
void Renderer::exclude(const Renderable &renderable)
nm(i, j) = m(i, j);
nm = transpose(invert(nm));
standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0));
- if(state->lighting)
- state->lighting->get_shader_data().apply();
if(state->material)
state->material->get_shader_data().apply();
standard_shdata.apply();
else
WindingTest::unbind();
- if(legacy_bindings && mtx_changed)
+ if(legacy_bindings)
{
- MatrixStack::modelview() = mtx_stack.top();
- mtx_changed = false;
+ if(!matrices_loaded)
+ {
+ MatrixStack::modelview().push();
+ if(camera)
+ {
+ MatrixStack::projection().push();
+ camera->apply();
+ }
+ matrices_loaded = true;
+ }
+
+ if(mtx_changed)
+ {
+ MatrixStack::modelview() = mtx_stack.top();
+ mtx_changed = false;
+ }
}
}