If all renderables use modern shaders, it's not necessary to touch the
system matrix stacks at all. OpenGL ES 2.0 and OpenGL 3.0 core do not
even have system matrix stacks.
Renderer::Renderer(const Camera *c):
mtx_stack(*this),
Renderer::Renderer(const Camera *c):
mtx_stack(*this),
+ mtx_changed(true),
+ matrices_loaded(false),
camera(c),
state_stack(1),
lighting_changed(false),
camera(c),
state_stack(1),
lighting_changed(false),
shdata_stack.reserve(32);
state = &state_stack.back();
shdata_stack.reserve(32);
state = &state_stack.back();
- MatrixStack::modelview().push();
- MatrixStack::projection().push();
- camera->apply();
mtx_stack.load(camera->get_matrix());
standard_shdata.uniform("projection_matrix", camera->get_projection_matrix());
}
mtx_stack.load(camera->get_matrix());
standard_shdata.uniform("projection_matrix", camera->get_projection_matrix());
}
- if(camera)
- MatrixStack::projection().pop();
- MatrixStack::modelview().pop();
+ if(matrices_loaded)
+ {
+ if(camera)
+ MatrixStack::projection().pop();
+ MatrixStack::modelview().pop();
+ }
Mesh::unbind();
Texturing::unbind();
Mesh::unbind();
Texturing::unbind();
{
apply_state();
Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
{
apply_state();
Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
+ matrices_loaded = false;
}
void Renderer::exclude(const Renderable &renderable)
}
void Renderer::exclude(const Renderable &renderable)
else
WindingTest::unbind();
else
WindingTest::unbind();
- if(legacy_bindings && mtx_changed)
- 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;
+ }
MtxStack mtx_stack;
bool mtx_changed;
MtxStack mtx_stack;
bool mtx_changed;
const Camera *camera;
std::vector<State> state_stack;
State *state;
const Camera *camera;
std::vector<State> state_stack;
State *state;