From: Mikko Rasa Date: Sat, 15 Jan 2011 18:13:41 +0000 (+0000) Subject: Move winding test to Renderer::State X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ccbcce1d5c7fae8ec644e465ac936f5c39000e57;p=libs%2Fgl.git Move winding test to Renderer::State Clear winding test after rendering a Mesh --- diff --git a/source/mesh.cpp b/source/mesh.cpp index 67f9698c..c111817d 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -124,6 +124,8 @@ void Mesh::draw(Renderer &renderer) const for(list::const_iterator i=batches.begin(); i!=batches.end(); ++i) renderer.draw(*i); + + renderer.set_winding_test(0); } diff --git a/source/renderer.cpp b/source/renderer.cpp index 2680d902..46df5bf5 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -31,8 +31,7 @@ Renderer::Renderer(const Camera *c): state(&state_stack.back()), vertex_array(0), vertex_array_changed(false), - element_buffer(0), - winding_test(0) + element_buffer(0) { MatrixStack::modelview().push(); if(camera) @@ -56,6 +55,7 @@ Renderer::~Renderer() Material::unbind(); Program::unbind(); Buffer::unbind_from(ELEMENT_ARRAY_BUFFER); + WindingTest::unbind(); } void Renderer::set_texture(const Texture *t) @@ -105,7 +105,7 @@ void Renderer::set_element_buffer(const Buffer *b) void Renderer::set_winding_test(const WindingTest *w) { - winding_test = w; + state->winding_test = w; } void Renderer::push_state() @@ -130,7 +130,6 @@ void Renderer::escape() { apply_state(); Buffer::unbind_from(ELEMENT_ARRAY_BUFFER); - WindingTest::unbind(); } void Renderer::draw(const Batch &batch) @@ -142,18 +141,16 @@ void Renderer::draw(const Batch &batch) // Until VertexArray acquires VAO support and becomes Bindable if(vertex_array_changed) + { vertex_array->apply(); + vertex_array_changed = false; + } if(element_buffer) element_buffer->bind_to(ELEMENT_ARRAY_BUFFER); else Buffer::unbind_from(ELEMENT_ARRAY_BUFFER); - if(winding_test) - winding_test->bind(); - else - WindingTest::unbind(); - batch.draw(); } @@ -186,6 +183,11 @@ void Renderer::apply_state() else Program::unbind(); + if(state->winding_test) + state->winding_test->bind(); + else + WindingTest::unbind(); + if(mtx_changed) { MatrixStack::modelview() = mtx_stack.top(); @@ -198,7 +200,8 @@ Renderer::State::State(): texture(0), texturing(0), material(0), - shprog(0) + shprog(0), + winding_test(0) { } diff --git a/source/renderer.h b/source/renderer.h index d8ace373..ef17b3e6 100644 --- a/source/renderer.h +++ b/source/renderer.h @@ -53,6 +53,7 @@ private: const Material *material; const Program *shprog; std::vector shdata; + const WindingTest *winding_test; State(); }; @@ -76,7 +77,6 @@ private: const VertexArray *vertex_array; bool vertex_array_changed; const Buffer *element_buffer; - const WindingTest *winding_test; public: Renderer(const Camera *);