From 97b1f1d97b685155e279d9d02d7c6343ef233ae8 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 18 Sep 2021 15:40:30 +0300 Subject: [PATCH] Make the sampler-related enums independent of OpenGL constants --- source/core/sampler.cpp | 36 +++++++++++++++++++++++++++++++----- source/core/sampler.h | 22 ++++++++++++---------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/source/core/sampler.cpp b/source/core/sampler.cpp index c810789b..45db2980 100644 --- a/source/core/sampler.cpp +++ b/source/core/sampler.cpp @@ -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") diff --git a/source/core/sampler.h b/source/core/sampler.h index 43d1e541..524a8fc5 100644 --- a/source/core/sampler.h +++ b/source/core/sampler.h @@ -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 &); -- 2.45.2