]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/pipelinestate.cpp
Refactor winding-based culling
[libs/gl.git] / source / core / pipelinestate.cpp
index a3b9e640fafee04308a9ed397c84ca3e933bbaed..cfeed9ab26fcd29a1734e225e82a3a33a02a04dc 100644 (file)
@@ -12,7 +12,6 @@
 #include "texture.h"
 #include "uniformblock.h"
 #include "vertexsetup.h"
-#include "windingtest.h"
 
 using namespace std;
 
@@ -25,7 +24,8 @@ vector<int> PipelineState::bound_tex_targets;
 PipelineState::PipelineState():
        shprog(0),
        vertex_setup(0),
-       winding_test(0),
+       front_face(COUNTERCLOCKWISE),
+       face_cull(NO_CULL),
        enabled_clip_planes(0),
        changes(0)
 {
@@ -57,12 +57,21 @@ void PipelineState::set_vertex_setup(const VertexSetup *s)
        }
 }
 
-void PipelineState::set_winding_test(const WindingTest *w)
+void PipelineState::set_front_face(FaceWinding w)
 {
-       if(w!=winding_test)
+       if(w!=front_face)
        {
-               winding_test = w;
-               changes |= WINDING_TEST;
+               front_face = w;
+               changes |= FACE_CULL;
+       }
+}
+
+void PipelineState::set_face_cull(CullMode c)
+{
+       if(c!=face_cull)
+       {
+               face_cull = c;
+               changes |= FACE_CULL;
        }
 }
 
@@ -132,12 +141,14 @@ void PipelineState::apply(unsigned mask) const
                        vertex_setup->refresh();
        }
 
-       if(mask&WINDING_TEST)
+       if(mask&FACE_CULL)
        {
-               if(winding_test)
+               glFrontFace(front_face==CLOCKWISE ? GL_CW : GL_CCW);
+
+               if(face_cull!=NO_CULL)
                {
                        glEnable(GL_CULL_FACE);
-                       glFrontFace(winding_test->get_winding());
+                       glCullFace(face_cull==CULL_FRONT ? GL_FRONT : GL_BACK);
                }
                else
                        glDisable(GL_CULL_FACE);