]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a flag to RenderPass to render the back faces of a mesh
authorMikko Rasa <tdb@tdb.fi>
Mon, 9 Sep 2013 16:00:40 +0000 (19:00 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 9 Sep 2013 16:00:40 +0000 (19:00 +0300)
This is useful for transparency effects.

source/renderer.cpp
source/renderer.h
source/renderpass.cpp
source/renderpass.h
source/windingtest.cpp
source/windingtest.h

index 3a44dcd3c0b21bd5afd1fac151405d6e0936f5d1..31d9621ef89195688ed0febaed9e9cbc67d12169 100644 (file)
@@ -112,6 +112,11 @@ void Renderer::set_winding_test(const WindingTest *w)
        state->winding_test = w;
 }
 
+void Renderer::set_reverse_winding(bool r)
+{
+       state->reverse_winding = r;
+}
+
 void Renderer::push_state()
 {
        state_stack.push_back(state_stack.back());
@@ -220,7 +225,12 @@ void Renderer::apply_state()
                Program::unbind();
 
        if(state->winding_test)
-               state->winding_test->bind();
+       {
+               if(state->reverse_winding)
+                       state->winding_test->get_reverse().bind();
+               else
+                       state->winding_test->bind();
+       }
        else
                WindingTest::unbind();
 
index 00f970042b9505383fcbd139cf7e0bf9bd1bba75..1254b7adf3951ffc6b2dfd1d1890e9ceb8598290 100644 (file)
@@ -125,6 +125,7 @@ public:
        void set_vertex_array(const VertexArray *);
        void set_element_buffer(const Buffer *);
        void set_winding_test(const WindingTest *);
+       void set_reverse_winding(bool);
 
        /** Saves the current state so it can be restored later. */
        void push_state();
index 9ee79d4bb464340e438945c5aba50d843ed1ed0d..158e9fc8390206aea6025f7fae37ab844048068c 100644 (file)
@@ -20,7 +20,8 @@ RenderPass::RenderPass():
        shprog(0),
        shdata(0),
        material(0),
-       texturing(0)
+       texturing(0),
+       back_faces(false)
 { }
 
 RenderPass::RenderPass(const RenderPass &other):
@@ -28,7 +29,8 @@ RenderPass::RenderPass(const RenderPass &other):
        shdata(other.shdata ? new ProgramData(*other.shdata) : 0),
        material(other.material),
        texturing(other.texturing ? new Texturing(*other.texturing) : 0),
-       tex_names(other.tex_names)
+       tex_names(other.tex_names),
+       back_faces(other.back_faces)
 { }
 
 RenderPass::~RenderPass()
@@ -70,6 +72,7 @@ void RenderPass::apply(Renderer &renderer) const
        renderer.set_texturing(texturing);
        renderer.set_material(material.get());
        renderer.set_shader_program(shprog, shdata.get());
+       renderer.set_reverse_winding(back_faces);
 }
 
 
@@ -90,6 +93,7 @@ void RenderPass::Loader::init()
        add("shader",   &RenderPass::shprog);
        add("material", &Loader::material_inline);
        add("material", &Loader::material);
+       add("back_faces",&RenderPass::back_faces);
        add("texunit",  &Loader::texunit);
        add("texunit",  &Loader::texunit_named);
        add("uniforms", &Loader::uniforms);
index e891802e3fa970e1a9005469a1783800d7cb24d3..934a213e3e815f0f855dfc10ca3b9add2c2193e5 100644 (file)
@@ -63,6 +63,7 @@ private:
        RefPtr<const Material> material;
        Texturing *texturing;
        std::map<std::string, unsigned> tex_names;
+       bool back_faces;
 
        RenderPass &operator=(const RenderPass &);
 public:
@@ -78,6 +79,8 @@ public:
        void set_texture(unsigned, const Texture *);
        const Texturing *get_texturing() const { return texturing; }
        int get_texture_index(const std::string &) const;
+       void set_back_faces(bool);
+       bool get_back_faces() const { return back_faces; }
 
        void apply(Renderer &) const;
 };
index de9e0a2530562a33deb9e84a61e5d691dafa8bd8..acbc20fc5ba127688c89c95caa0d5207a7c66f24 100644 (file)
@@ -44,13 +44,23 @@ void WindingTest::unbind()
                glDisable(GL_CULL_FACE);
 }
 
-WindingTest &WindingTest::clockwise()
+const WindingTest &WindingTest::get_reverse() const
+{
+       if(!test)
+               return *this;
+       else if(winding==CLOCKWISE)
+               return counterclockwise();
+       else
+               return clockwise();
+}
+
+const WindingTest &WindingTest::clockwise()
 {
        static WindingTest test(CLOCKWISE);
        return test;
 }
 
-WindingTest &WindingTest::counterclockwise()
+const WindingTest &WindingTest::counterclockwise()
 {
        static WindingTest test(COUNTERCLOCKWISE);
        return test;
index 0869d565e6842d7691c341188ee9eb1418bdb849..d8a4c421722ed6997ab5f4162f10a74813e5d5f8 100644 (file)
@@ -34,8 +34,10 @@ public:
 
        static void unbind();
 
-       static WindingTest &clockwise();
-       static WindingTest &counterclockwise();
+       const WindingTest &get_reverse() const;
+
+       static const WindingTest &clockwise();
+       static const WindingTest &counterclockwise();
 };
 
 } // namespace GL