X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fsampler.cpp;h=4da13833330dac12eace04b145f9ffacd4a0510b;hp=5ea10c43f6657c13eb3d0fe88824602d09420988;hb=HEAD;hpb=6c1cb01d562bb8fbfe6559f00d42e811caebc8cd diff --git a/source/core/sampler.cpp b/source/core/sampler.cpp index 5ea10c43..4da13833 100644 --- a/source/core/sampler.cpp +++ b/source/core/sampler.cpp @@ -1,10 +1,5 @@ -#include -#include -#include -#include -#include -#include #include +#include "device.h" #include "error.h" #include "sampler.h" @@ -13,50 +8,9 @@ using namespace std; namespace Msp { namespace GL { -Sampler::Sampler(): - min_filter(NEAREST_MIPMAP_LINEAR), - mag_filter(LINEAR), - max_anisotropy(1.0f), - wrap_s(REPEAT), - wrap_t(REPEAT), - wrap_r(REPEAT), - border_color(Color(0.0f, 0.0f, 0.0f, 0.0f)), - compare(false), - cmp_func(LEQUAL), - 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 - glGenSamplers(1, &id); -} - void Sampler::update() const { - if(dirty_params&MIN_FILTER) - glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, get_gl_filter(min_filter)); - if(dirty_params&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, get_gl_wrap(wrap_s)); - if(dirty_params&WRAP_T) - glSamplerParameteri(id, GL_TEXTURE_WRAP_T, get_gl_wrap(wrap_t)); - if(dirty_params&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, get_gl_predicate(cmp_func)); - } - + SamplerBackend::update(dirty_params); dirty_params = 0; } @@ -68,6 +22,8 @@ void Sampler::set_min_filter(TextureFilter f) void Sampler::set_mag_filter(TextureFilter f) { + if(is_mipmapped(f)) + throw invalid_argument("Sampler::set_mag_filter"); mag_filter = f; dirty_params |= MAG_FILTER; } @@ -82,20 +38,14 @@ void Sampler::set_max_anisotropy(float a) { if(a<1.0f) throw invalid_argument("Sampler::set_max_anisotropy"); - else if(a>1.0f) - static Require _req(EXT_texture_filter_anisotropic); + if(a>Device::get_current().get_info().limits.max_anisotropy) + throw out_of_range("Sampler::set_max_anisotropy"); + bool supported = check_anisotropic(a>1.0f); max_anisotropy = a; - if(EXT_texture_filter_anisotropic) + if(supported) dirty_params |= MAX_ANISOTROPY; } -void Sampler::set_wrap(TextureWrap w) -{ - set_wrap_s(w); - set_wrap_t(w); - set_wrap_r(w); -} - void Sampler::set_wrap_s(TextureWrap w) { wrap_s = w; @@ -114,6 +64,13 @@ void Sampler::set_wrap_r(TextureWrap w) dirty_params |= WRAP_R; } +void Sampler::set_wrap(TextureWrap w) +{ + set_wrap_s(w); + set_wrap_t(w); + set_wrap_r(w); +} + void Sampler::set_border_color(const Color &c) { border_color = c; @@ -133,16 +90,6 @@ void Sampler::set_compare(Predicate f) dirty_params |= COMPARE; } -void Sampler::set_debug_name(const string &name) -{ -#ifdef DEBUG - if(id && KHR_debug) - glObjectLabel(GL_SAMPLER, id, name.size(), name.c_str()); -#else - (void)name; -#endif -} - Sampler::Loader::Loader(Sampler &s): DataFile::ObjectLoader(s) @@ -216,32 +163,6 @@ 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")