]> git.tdb.fi Git - libs/gl.git/commitdiff
Decouple the Predicate enum from OpenGL constants
authorMikko Rasa <tdb@tdb.fi>
Wed, 18 Aug 2021 14:13:25 +0000 (17:13 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 18 Aug 2021 14:15:06 +0000 (17:15 +0300)
source/core/predicate.cpp
source/core/predicate.h
source/core/sampler.cpp
source/core/stencil.cpp
source/core/tests.cpp

index a1953733c676d3ccac0f449db4d9ce3c749dba4f..4afc6c0343ca89166283c6f3268c1bc9880c9d4f 100644 (file)
@@ -6,6 +6,22 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
+GLenum get_gl_predicate(Predicate pred)
+{
+       switch(pred)
+       {
+       case NEVER: return GL_NEVER;
+       case ALWAYS: return GL_ALWAYS;
+       case LESS: return GL_LESS;
+       case LEQUAL: return GL_LEQUAL;
+       case EQUAL: return GL_EQUAL;
+       case GREATER: return GL_GREATER;
+       case GEQUAL: return GL_GEQUAL;
+       case NOTEQUAL: return GL_NOTEQUAL;
+       default: throw invalid_argument("get_gl_predicate");
+       }
+}
+
 void operator>>(const LexicalConverter &conv, Predicate &pred)
 {
        const string &str = conv.get();
index 13c22e84dc0b4300ad98bd268179aebaa8937e1d..c7e5991ea03c2c205b8b07a7fa310b2c1927c7f7 100644 (file)
@@ -9,16 +9,18 @@ namespace GL {
 
 enum Predicate
 {
-       NEVER    = GL_NEVER,
-       ALWAYS   = GL_ALWAYS,
-       LESS     = GL_LESS,
-       LEQUAL   = GL_LEQUAL,
-       EQUAL    = GL_EQUAL,
-       GREATER  = GL_GREATER,
-       GEQUAL   = GL_GEQUAL,
-       NOTEQUAL = GL_NOTEQUAL
+       NEVER,
+       ALWAYS,
+       LESS,
+       LEQUAL,
+       EQUAL,
+       GREATER,
+       GEQUAL,
+       NOTEQUAL
 };
 
+GLenum get_gl_predicate(Predicate);
+
 void operator>>(const LexicalConverter &, Predicate &);
 void operator<<(LexicalConverter &, Predicate);
 
index ffd7762568f665baf551808558a3231ca8ba93fe..c810789b605130626c1e84d4f27ecd9f7ce6a81e 100644 (file)
@@ -53,7 +53,7 @@ void Sampler::update() const
        {
                glSamplerParameteri(id, GL_TEXTURE_COMPARE_MODE, (compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE));
                if(compare)
-                       glSamplerParameteri(id, GL_TEXTURE_COMPARE_FUNC, cmp_func);
+                       glSamplerParameteri(id, GL_TEXTURE_COMPARE_FUNC, get_gl_predicate(cmp_func));
        }
 
        dirty_params = 0;
index 9de8b1f0d66952dc25d15d1148a64daa885201a3..28d59f19aa97538cf8e443f31918015eef437753 100644 (file)
@@ -5,7 +5,7 @@ namespace GL {
 
 void stencil_func(Predicate func, int ref, unsigned mask)
 {
-       glStencilFunc(func, ref, mask);
+       glStencilFunc(get_gl_predicate(func), ref, mask);
 }
 
 void stencil_op(StencilOp sfail, StencilOp dfail, StencilOp dpass)
index 8e24bb52facc436a0a75451a57726737a574bb22..e1ad526115b5386a8c5007cf1e7a9563f52d8498 100644 (file)
@@ -18,7 +18,7 @@ void DepthTest::bind() const
        if(set_current(this))
        {
                glEnable(GL_DEPTH_TEST);
-               glDepthFunc(pred);
+               glDepthFunc(get_gl_predicate(pred));
                glDepthMask(write);
        }
 }