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();
{
apply_state();
Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
+ matrices_loaded = false;
}
void Renderer::exclude(const Renderable &renderable)
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;
+ }
}
}