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)
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")
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
};
bool is_mipmapped(TextureFilter);
+GLenum get_gl_filter(TextureFilter);
+GLenum get_gl_wrap(TextureWrap);
void operator>>(const LexicalConverter &, TextureFilter &);
void operator>>(const LexicalConverter &, TextureWrap &);