X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frenderer.cpp;h=0207f9378324aaed15a22725fbaa5897bf666bff;hb=922fac753e31d97fc88daa166e93e4c5572bd2ba;hp=af0d087398da9010816a0cce0f8bf563dc1f69d0;hpb=db2fd517dcd215e9d16345287d413f2a64f5ba03;p=libs%2Fgl.git diff --git a/source/renderer.cpp b/source/renderer.cpp index af0d0873..0207f937 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -22,7 +22,8 @@ namespace GL { 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), @@ -32,11 +33,8 @@ Renderer::Renderer(const Camera *c): 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()); } @@ -49,9 +47,12 @@ Renderer::Renderer(const Camera *c): 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(); @@ -90,9 +91,7 @@ void Renderer::set_lighting(const Lighting *l) 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(l)->update_shader_data(mtx_stack.top()); + l->update_shader_data(standard_shdata, mtx_stack.top()); lighting_changed = true; } @@ -159,6 +158,7 @@ void Renderer::escape() { apply_state(); Buffer::unbind_from(ELEMENT_ARRAY_BUFFER); + matrices_loaded = false; } void Renderer::exclude(const Renderable &renderable) @@ -246,8 +246,6 @@ void Renderer::apply_state() 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(); @@ -286,10 +284,24 @@ void Renderer::apply_state() 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; + } } }