X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fsampler.cpp;h=4da13833330dac12eace04b145f9ffacd4a0510b;hp=ffd7762568f665baf551808558a3231ca8ba93fe;hb=d16d28d2ccf7c6255204f02975834f713ff1df08;hpb=9b3bce7ae76ff8c0c81315d2505ea96bf422a318 diff --git a/source/core/sampler.cpp b/source/core/sampler.cpp index ffd77625..4da13833 100644 --- a/source/core/sampler.cpp +++ b/source/core/sampler.cpp @@ -1,61 +1,16 @@ -#include -#include -#include -#include -#include -#include #include +#include "device.h" #include "error.h" #include "sampler.h" -#include "texture.h" 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); - 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, min_filter); - if(dirty_params&MAG_FILTER) - glSamplerParameteri(id, GL_TEXTURE_MAG_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); - if(dirty_params&WRAP_T) - glSamplerParameteri(id, GL_TEXTURE_WRAP_T, wrap_t); - if(dirty_params&WRAP_R) - glSamplerParameteri(id, GL_TEXTURE_WRAP_R, 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); - } - + SamplerBackend::update(dirty_params); dirty_params = 0; } @@ -67,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; } @@ -81,21 +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); - if(EXT_texture3D) - set_wrap_r(w); -} - void Sampler::set_wrap_s(TextureWrap w) { wrap_s = w; @@ -110,11 +60,17 @@ void Sampler::set_wrap_t(TextureWrap w) void Sampler::set_wrap_r(TextureWrap w) { - static Require _req(EXT_texture3D); wrap_r = 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; @@ -129,22 +85,11 @@ void Sampler::disable_compare() void Sampler::set_compare(Predicate f) { - static Require _req(ARB_shadow); compare = true; cmp_func = 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)