X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftexture.cpp;h=f6594ab14c7e5143434ac0823c862427c70f2c9d;hp=703ea96c5fabfddb2cb8b33c65cb8056df205f16;hb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;hpb=99e833421259dd90b164a9c49d63c936c343c65f diff --git a/source/texture.cpp b/source/texture.cpp index 703ea96c..f6594ab1 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -28,6 +28,7 @@ Texture::Texture(GLenum t, ResourceManager *m): format(RGB8), storage_fmt(RGB8), swizzle(NO_SWIZZLE), + use_srgb_format(false), auto_gen_mipmap(false), default_sampler(*this) { @@ -193,22 +194,22 @@ void Texture::set_compare_func(Predicate f) default_sampler.set_compare(f); } -void Texture::load_image(const string &fn, bool srgb) +void Texture::load_image(const string &fn, bool) { - load_image(fn, 0, srgb); + load_image(fn, 0U); } -void Texture::load_image(const string &fn, unsigned lv, bool srgb) +void Texture::load_image(const string &fn, unsigned lv) { Graphics::Image img; img.load_file(fn); - image(img, lv, srgb); + image(img, lv); } -void Texture::image(const Graphics::Image &img, bool srgb) +void Texture::image(const Graphics::Image &img, bool) { - image(img, 0, srgb); + image(img, 0U); } void Texture::bind_to(unsigned i) const @@ -225,6 +226,7 @@ void Texture::bind_to(unsigned i) const } TexUnit &unit = TexUnit::get_unit(i); + const Texture *cur = unit.get_texture(); if(unit.set_texture(this)) { if(manager) @@ -238,7 +240,8 @@ void Texture::bind_to(unsigned i) const glBindTexture(target, id); } - default_sampler.bind_to(i); + if(!unit.get_sampler() || unit.get_sampler()==&cur->default_sampler) + default_sampler.bind_to(i); } } @@ -260,6 +263,9 @@ void Texture::unbind_from(unsigned i) unit.bind(); glBindTexture(cur->target, 0); } + + if(unit.get_sampler()==&cur->default_sampler) + Sampler::unbind_from(i); } } @@ -279,12 +285,9 @@ Texture::Loader::Loader(Texture &t, Collection &c): void Texture::Loader::init() { levels = 0; - if(Resources *res = dynamic_cast(coll)) - srgb = res->get_srgb_conversion(); - else - srgb = false; add("external_image", &Loader::external_image); + add("external_image_srgb", &Loader::external_image); add("filter", &Loader::filter); add("generate_mipmap", &Loader::generate_mipmap); add("image_data", &Loader::image_data); @@ -316,9 +319,26 @@ void Texture::Loader::load_external_image(Graphics::Image &img, const std::strin void Texture::Loader::external_image(const string &fn) { - Graphics::Image img; - load_external_image(img, fn); - obj.image(img, get_levels(), srgb); + obj.use_srgb_format = false; + external_image_common(fn); +} + +void Texture::Loader::external_image_srgb(const string &fn) +{ + obj.use_srgb_format = true; + external_image_common(fn); +} + +void Texture::Loader::external_image_common(const string &fn) +{ + if(obj.manager) + obj.manager->set_resource_location(obj, get_collection(), fn); + else + { + Graphics::Image img; + load_external_image(img, fn); + obj.image(img, get_levels()); + } } void Texture::Loader::filter(TextureFilter f) @@ -337,7 +357,7 @@ void Texture::Loader::image_data(const string &data) IO::Memory mem(data.data(), data.size()); img.load_io(mem); - obj.image(img, get_levels(), srgb); + obj.image(img, get_levels()); } void Texture::Loader::mag_filter(TextureFilter f)