From: Mikko Rasa Date: Wed, 18 Aug 2021 14:13:25 +0000 (+0300) Subject: Decouple the Predicate enum from OpenGL constants X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=669e9bfc18d2f5e28a9c715e1a69b7637a2d9c8b;p=libs%2Fgl.git Decouple the Predicate enum from OpenGL constants --- diff --git a/source/core/predicate.cpp b/source/core/predicate.cpp index a1953733..4afc6c03 100644 --- a/source/core/predicate.cpp +++ b/source/core/predicate.cpp @@ -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(); diff --git a/source/core/predicate.h b/source/core/predicate.h index 13c22e84..c7e5991e 100644 --- a/source/core/predicate.h +++ b/source/core/predicate.h @@ -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); diff --git a/source/core/sampler.cpp b/source/core/sampler.cpp index ffd77625..c810789b 100644 --- a/source/core/sampler.cpp +++ b/source/core/sampler.cpp @@ -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; diff --git a/source/core/stencil.cpp b/source/core/stencil.cpp index 9de8b1f0..28d59f19 100644 --- a/source/core/stencil.cpp +++ b/source/core/stencil.cpp @@ -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) diff --git a/source/core/tests.cpp b/source/core/tests.cpp index 8e24bb52..e1ad5261 100644 --- a/source/core/tests.cpp +++ b/source/core/tests.cpp @@ -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); } }