]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/pipelinestate.cpp
Add a helper function to set variables and flags in PipelineState
[libs/gl.git] / source / core / pipelinestate.cpp
index a3b9e640fafee04308a9ed397c84ca3e933bbaed..66188d910c085f9ecafffae6467c43358393d95d 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)
 {
@@ -39,40 +39,39 @@ PipelineState::~PipelineState()
                last_applied = 0;
 }
 
-void PipelineState::set_shader_program(const Program *p)
+template<typename T>
+void PipelineState::set(T &target, T value, unsigned flag)
 {
-       if(p!=shprog)
+       if(value!=target)
        {
-               shprog = p;
-               changes |= SHPROG;
+               target = value;
+               changes |= flag;
        }
 }
 
+void PipelineState::set_shader_program(const Program *p)
+{
+       set(shprog, p, SHPROG);
+}
+
 void PipelineState::set_vertex_setup(const VertexSetup *s)
 {
-       if(s!=vertex_setup)
-       {
-               vertex_setup = s;
-               changes |= VERTEX_SETUP;
-       }
+       set(vertex_setup, s, VERTEX_SETUP);
 }
 
-void PipelineState::set_winding_test(const WindingTest *w)
+void PipelineState::set_front_face(FaceWinding w)
 {
-       if(w!=winding_test)
-       {
-               winding_test = w;
-               changes |= WINDING_TEST;
-       }
+       set(front_face, w, FACE_CULL);
+}
+
+void PipelineState::set_face_cull(CullMode c)
+{
+       set(face_cull, c, FACE_CULL);
 }
 
 void PipelineState::set_enabled_clip_planes(unsigned p)
 {
-       if(p!=enabled_clip_planes)
-       {
-               enabled_clip_planes = p;
-               changes |= CLIP_PLANES;
-       }
+       set(enabled_clip_planes, p, CLIP_PLANES);
 }
 
 void PipelineState::set_texture(unsigned binding, const Texture *tex, const Sampler *samp)
@@ -132,12 +131,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);