#include <msp/strings/format.h>
#include "error.h"
#include "sampler.h"
-#include "texture.h"
using namespace std;
dirty_params(0)
{
Require _req(ARB_sampler_objects);
+ Require _req2(EXT_texture3D);
+ Require _req3(ARB_shadow);
if(ARB_direct_state_access)
glCreateSamplers(1, &id);
else
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)
{
set_wrap_s(w);
set_wrap_t(w);
- if(EXT_texture3D)
- set_wrap_r(w);
+ set_wrap_r(w);
}
void Sampler::set_wrap_s(TextureWrap w)
void Sampler::set_wrap_r(TextureWrap w)
{
- static Require _req(EXT_texture3D);
wrap_r = w;
dirty_params |= WRAP_R;
}
void Sampler::set_compare(Predicate f)
{
- static Require _req(ARB_shadow);
compare = true;
cmp_func = f;
dirty_params |= COMPARE;
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")