]> git.tdb.fi Git - libs/gl.git/commitdiff
Make the sampler-related enums independent of OpenGL constants
authorMikko Rasa <tdb@tdb.fi>
Sat, 18 Sep 2021 12:40:30 +0000 (15:40 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 18 Sep 2021 13:20:18 +0000 (16:20 +0300)
source/core/sampler.cpp
source/core/sampler.h

index c810789b605130626c1e84d4f27ecd9f7ce6a81e..45db298064bce9ade85a978f52ed8bebd70d743a 100644 (file)
@@ -36,17 +36,17 @@ Sampler::Sampler():
 void Sampler::update() const
 {
        if(dirty_params&MIN_FILTER)
-               glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, min_filter);
+               glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, get_gl_filter(min_filter));
        if(dirty_params&MAG_FILTER)
-               glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, mag_filter);
+               glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, get_gl_filter(mag_filter));
        if(dirty_params&MAX_ANISOTROPY)
                glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
        if(dirty_params&WRAP_S)
-               glSamplerParameteri(id, GL_TEXTURE_WRAP_S, wrap_s);
+               glSamplerParameteri(id, GL_TEXTURE_WRAP_S, get_gl_wrap(wrap_s));
        if(dirty_params&WRAP_T)
-               glSamplerParameteri(id, GL_TEXTURE_WRAP_T, wrap_t);
+               glSamplerParameteri(id, GL_TEXTURE_WRAP_T, get_gl_wrap(wrap_t));
        if(dirty_params&WRAP_R)
-               glSamplerParameteri(id, GL_TEXTURE_WRAP_R, wrap_r);
+               glSamplerParameteri(id, GL_TEXTURE_WRAP_R, get_gl_wrap(wrap_r));
        if(dirty_params&BORDER_COLOR)
                glSamplerParameterfv(id, GL_TEXTURE_BORDER_COLOR, &border_color.r);
        if(dirty_params&COMPARE)
@@ -218,6 +218,32 @@ bool is_mipmapped(TextureFilter filter)
                filter==LINEAR_MIPMAP_NEAREST || filter==LINEAR_MIPMAP_LINEAR);
 }
 
+GLenum get_gl_filter(TextureFilter filter)
+{
+       switch(filter)
+       {
+       case NEAREST: return GL_NEAREST;
+       case LINEAR: return GL_LINEAR;
+       case NEAREST_MIPMAP_NEAREST: return GL_NEAREST_MIPMAP_NEAREST;
+       case NEAREST_MIPMAP_LINEAR: return GL_NEAREST_MIPMAP_LINEAR;
+       case LINEAR_MIPMAP_NEAREST: return GL_LINEAR_MIPMAP_NEAREST;
+       case LINEAR_MIPMAP_LINEAR: return GL_LINEAR_MIPMAP_LINEAR;
+       default: throw invalid_argument("get_gl_filter");
+       }
+}
+
+GLenum get_gl_wrap(TextureWrap wrap)
+{
+       switch(wrap)
+       {
+       case REPEAT: return GL_REPEAT;
+       case CLAMP_TO_EDGE: return GL_CLAMP_TO_EDGE;
+       case CLAMP_TO_BORDER: return GL_CLAMP_TO_BORDER;
+       case MIRRORED_REPEAT: return GL_MIRRORED_REPEAT;
+       default: throw invalid_argument("get_gl_wrap");
+       }
+}
+
 void operator>>(const LexicalConverter &c, TextureFilter &tf)
 {
        if(c.get()=="NEAREST")
index 43d1e5412a2fe3df0bb732ac42bc6b1344e1b003..524a8fc5f95f01fbee29faa87a7f731c50b0e55d 100644 (file)
@@ -12,38 +12,38 @@ namespace GL {
 enum TextureFilter
 {
        /// No filtering
-       NEAREST = GL_NEAREST,
+       NEAREST,
 
        /// Bilinear filtering
-       LINEAR = GL_LINEAR,
+       LINEAR,
 
        /// Mipmapping without filtering
-       NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
+       NEAREST_MIPMAP_NEAREST,
 
        /// Linear filtering between two mipmap levels
-       NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
+       NEAREST_MIPMAP_LINEAR,
 
        /// Bilinear filtering on the closest mipmap level
-       LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
+       LINEAR_MIPMAP_NEAREST,
 
        /// Trilinear filtering between two mipmap levels
-       LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
+       LINEAR_MIPMAP_LINEAR
 };
 
 
 enum TextureWrap
 {
        /// Tile the texture infinitely
-       REPEAT = GL_REPEAT,
+       REPEAT,
 
        /// Extend the texels at the edge of the texture to infinity
-       CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
+       CLAMP_TO_EDGE,
 
        /// Sampling outside the texture will return border color
-       CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER,
+       CLAMP_TO_BORDER,
 
        /// Tile the texture, with every other repetition mirrored
-       MIRRORED_REPEAT = GL_MIRRORED_REPEAT
+       MIRRORED_REPEAT
 };
 
 
@@ -159,6 +159,8 @@ public:
 
 
 bool is_mipmapped(TextureFilter);
+GLenum get_gl_filter(TextureFilter);
+GLenum get_gl_wrap(TextureWrap);
 
 void operator>>(const LexicalConverter &, TextureFilter &);
 void operator>>(const LexicalConverter &, TextureWrap &);