]> git.tdb.fi Git - libs/gl.git/commitdiff
Move winding test to Renderer::State
authorMikko Rasa <tdb@tdb.fi>
Sat, 15 Jan 2011 18:13:41 +0000 (18:13 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 15 Jan 2011 18:13:41 +0000 (18:13 +0000)
Clear winding test after rendering a Mesh

source/mesh.cpp
source/renderer.cpp
source/renderer.h

index 67f9698cfa36468d5fb6955f49b5ce5774b95e0f..c111817d4240ff543cd50a7342067c12c0f19b26 100644 (file)
@@ -124,6 +124,8 @@ void Mesh::draw(Renderer &renderer) const
 
        for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
                renderer.draw(*i);
+
+       renderer.set_winding_test(0);
 }
 
 
index 2680d9022e9edcfe128cffec1ba246397902cd72..46df5bf52777564ea62b9d995693c57f7e0d5fa9 100644 (file)
@@ -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)
 { }
 
 
index d8ace373805e9b85f905033d01a449709af11cf9..ef17b3e62043ad847969f4b7e6102854e52fc55c 100644 (file)
@@ -53,6 +53,7 @@ private:
                const Material *material;
                const Program *shprog;
                std::vector<const ProgramData *> 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 *);