]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/sampler.cpp
Add color write mask to blend state
[libs/gl.git] / source / core / sampler.cpp
index ffd7762568f665baf551808558a3231ca8ba93fe..5d0121254196dd3e1b8cfae52768a6d07855caec 100644 (file)
@@ -7,7 +7,6 @@
 #include <msp/strings/format.h>
 #include "error.h"
 #include "sampler.h"
-#include "texture.h"
 
 using namespace std;
 
@@ -36,24 +35,24 @@ 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)
        {
                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;
@@ -218,6 +217,32 @@ bool is_mipmapped(TextureFilter filter)
                filter==LINEAR_MIPMAP_NEAREST || filter==LINEAR_MIPMAP_LINEAR);
 }
 
+unsigned 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");
+       }
+}
+
+unsigned 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")