From 635e5dc39adf09051bdacadbc402ddf22f7807a3 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 6 Feb 2021 00:14:12 +0200 Subject: [PATCH] Depracate the srgb parameter of Texture::image functions Now that texture datafiles can be used to specify import settings on a per-texture basis and the Blender exporter uses them, there's no need for this anymore. --- source/resources.cpp | 2 +- source/resources.h | 4 ++-- source/texture.cpp | 33 +++++++++++++++++++++------------ source/texture.h | 17 ++++++++--------- source/texture1d.cpp | 4 ++-- source/texture1d.h | 2 +- source/texture2d.cpp | 22 ++++++---------------- source/texture2d.h | 9 +++------ source/texture3d.cpp | 4 ++-- source/texture3d.h | 8 +++----- source/texturecube.cpp | 17 +++++++++++------ source/texturecube.h | 6 ++++-- 12 files changed, 64 insertions(+), 64 deletions(-) diff --git a/source/resources.cpp b/source/resources.cpp index 8de2529f..c28cdd07 100644 --- a/source/resources.cpp +++ b/source/resources.cpp @@ -155,7 +155,7 @@ Texture2D *Resources::create_texture2d(const string &name) if(resource_manager) resource_manager->set_resource_location(*tex, *this, name); else - tex->image(image, srgb_conversion); + tex->image(image); return tex.release(); } diff --git a/source/resources.h b/source/resources.h index 0b374499..6f04a260 100644 --- a/source/resources.h +++ b/source/resources.h @@ -35,9 +35,9 @@ public: /** Enables or disables sRGB conversion. If enabled, textures and material colors are converted from sRGB to linear color space when loaded. */ - void set_srgb_conversion(bool); + DEPRECATED void set_srgb_conversion(bool); - bool get_srgb_conversion() const { return srgb_conversion; } + DEPRECATED bool get_srgb_conversion() const { return srgb_conversion; } void set_resource_manager(ResourceManager *); diff --git a/source/texture.cpp b/source/texture.cpp index 24994f7c..ab570048 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -193,22 +193,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 @@ -279,12 +279,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); @@ -315,6 +312,18 @@ void Texture::Loader::load_external_image(Graphics::Image &img, const std::strin } void Texture::Loader::external_image(const string &fn) +{ + 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); @@ -322,7 +331,7 @@ void Texture::Loader::external_image(const string &fn) { Graphics::Image img; load_external_image(img, fn); - obj.image(img, get_levels(), srgb); + obj.image(img, get_levels()); } } @@ -342,7 +351,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) diff --git a/source/texture.h b/source/texture.h index 6ee0b8a1..c4e72031 100644 --- a/source/texture.h +++ b/source/texture.h @@ -30,7 +30,6 @@ protected: { protected: unsigned levels; - bool srgb; public: Loader(Texture &); @@ -44,6 +43,8 @@ protected: private: void external_image(const std::string &); + void external_image_srgb(const std::string &); + void external_image_common(const std::string &); void filter(TextureFilter); void generate_mipmap(bool); void image_data(const std::string &); @@ -76,6 +77,7 @@ protected: PixelFormat format; PixelFormat storage_fmt; FormatSwizzle swizzle; + bool use_srgb_format; bool auto_gen_mipmap; Sampler default_sampler; @@ -135,19 +137,16 @@ public: DEPRECATED void set_compare_func(Predicate); /// Loads a Graphics::Image from a file and uploads it to the texture. - virtual void load_image(const std::string &, bool srgb = false); + virtual void load_image(const std::string &, unsigned = 0); - virtual void load_image(const std::string &, unsigned, bool srgb = false); + DEPRECATED void load_image(const std::string &, bool srgb); /** Uploads an image to the texture. If storage has not been defined, it will be set to match the image. Otherwise the image must be compatible - with the defined storage. Semantics depend on the type of texture. + with the defined storage. Semantics depend on the type of texture. */ + virtual void image(const Graphics::Image &, unsigned = 0) = 0; - If srgb is true and storage is determined by this call, then an sRGB pixel - format will be used. */ - virtual void image(const Graphics::Image &, bool srgb = false); - - virtual void image(const Graphics::Image &, unsigned, bool srgb = false) = 0; + DEPRECATED void image(const Graphics::Image &, bool srgb); GLenum get_target() const { return target; } unsigned get_id() const { return id; } diff --git a/source/texture1d.cpp b/source/texture1d.cpp index 553d4ffa..592e4d77 100644 --- a/source/texture1d.cpp +++ b/source/texture1d.cpp @@ -119,7 +119,7 @@ void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelComponents co sub_image(level, x, wd, data); } -void Texture1D::image(const Graphics::Image &img, unsigned lv, bool srgb) +void Texture1D::image(const Graphics::Image &img, unsigned lv) { if(img.get_height()!=1) throw incompatible_data("Texture1D::image"); @@ -127,7 +127,7 @@ void Texture1D::image(const Graphics::Image &img, unsigned lv, bool srgb) unsigned w = img.get_width(); PixelFormat fmt = pixelformat_from_image(img); if(width==0) - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w, lv); + storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv); else if(w!=width) throw incompatible_data("Texture1D::image"); diff --git a/source/texture1d.h b/source/texture1d.h index 2b2a6b19..b14ff917 100644 --- a/source/texture1d.h +++ b/source/texture1d.h @@ -40,7 +40,7 @@ public: DEPRECATED void image(unsigned, PixelComponents, DataType, const void *); void sub_image(unsigned, int, unsigned, const void *); DEPRECATED void sub_image(unsigned, int, unsigned, PixelComponents, DataType, const void *); - virtual void image(const Graphics::Image &, unsigned, bool = false); + virtual void image(const Graphics::Image &, unsigned = 0); using Texture::image; unsigned get_width() const { return width; } diff --git a/source/texture2d.cpp b/source/texture2d.cpp index fa92f1c9..cee932f7 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -18,7 +18,6 @@ class Texture2D::AsyncLoader: public Resource::AsyncLoader private: Texture2D &texture; IO::Seekable &io; - bool srgb_conversion; Buffer pixel_buffer; char *mapped_address; Graphics::Image image; @@ -28,7 +27,6 @@ private: public: AsyncLoader(Texture2D &, IO::Seekable &); - void set_srgb_conversion(bool); virtual bool needs_sync() const; virtual bool process(); }; @@ -149,18 +147,18 @@ void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht sub_image(level, x, y, wd, ht, data); } -void Texture2D::image(const Graphics::Image &img, unsigned lv, bool srgb) +void Texture2D::image(const Graphics::Image &img, unsigned lv) { - image(img, lv, srgb, false); + image(img, lv, false); } -void Texture2D::image(const Graphics::Image &img, unsigned lv, bool srgb, bool from_buffer) +void Texture2D::image(const Graphics::Image &img, unsigned lv, bool from_buffer) { unsigned w = img.get_width(); unsigned h = img.get_height(); PixelFormat fmt = pixelformat_from_image(img); if(width==0) - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w, h, lv); + storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, lv); else if(w!=width || h!=height || (lv && lv!=levels)) throw incompatible_data("Texture2D::image"); @@ -188,11 +186,9 @@ void Texture2D::get_level_size(unsigned level, unsigned &w, unsigned &h) const h = 1; } -Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *res) +Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *) { AsyncLoader *ldr = new AsyncLoader(*this, io); - if(res) - ldr->set_srgb_conversion(res->get_srgb_conversion()); return ldr; } @@ -248,17 +244,11 @@ void Texture2D::Loader::storage_levels(PixelFormat fmt, unsigned w, unsigned h, Texture2D::AsyncLoader::AsyncLoader(Texture2D &t, IO::Seekable &i): texture(t), io(i), - srgb_conversion(false), pixel_buffer(PIXEL_UNPACK_BUFFER), mapped_address(0), phase(0) { } -void Texture2D::AsyncLoader::set_srgb_conversion(bool c) -{ - srgb_conversion = c; -} - bool Texture2D::AsyncLoader::needs_sync() const { return phase%2; @@ -299,7 +289,7 @@ bool Texture2D::AsyncLoader::process() else glGenTextures(1, &texture.id); } - texture.image(image, 0, srgb_conversion, true); + texture.image(image, 0, true); } ++phase; diff --git a/source/texture2d.h b/source/texture2d.h index b7070e8f..7553b6b7 100644 --- a/source/texture2d.h +++ b/source/texture2d.h @@ -72,16 +72,13 @@ public: /** Updates the contents of the entire texture from an image. If storage has not been defined, it will be set to match the image. Otherwise the - image must match the defined storage. - - If srgb is true and storage is determined by this call, then an sRGB pixel - format will be used. */ - virtual void image(const Graphics::Image &, unsigned lv, bool srgb = false); + image must match the defined storage. */ + virtual void image(const Graphics::Image &, unsigned lv = 0); using Texture::image; private: - void image(const Graphics::Image &, unsigned, bool, bool); + void image(const Graphics::Image &, unsigned, bool); public: unsigned get_width() const { return width; } diff --git a/source/texture3d.cpp b/source/texture3d.cpp index 13bb3ff4..667f8c31 100644 --- a/source/texture3d.cpp +++ b/source/texture3d.cpp @@ -138,7 +138,7 @@ void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsi sub_image(level, x, y, z, wd, ht, dp, data); } -void Texture3D::image(const Graphics::Image &img, unsigned lv, bool srgb) +void Texture3D::image(const Graphics::Image &img, unsigned lv) { unsigned w = img.get_width(); unsigned h = img.get_height(); @@ -161,7 +161,7 @@ void Texture3D::image(const Graphics::Image &img, unsigned lv, bool srgb) PixelFormat fmt = pixelformat_from_image(img); if(width==0) - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w, h, d, lv); + storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, d, lv); else if(w!=width || h!=height || d!=depth) throw incompatible_data("Texture3D::load_image"); diff --git a/source/texture3d.h b/source/texture3d.h index d67d03be..1f50e056 100644 --- a/source/texture3d.h +++ b/source/texture3d.h @@ -72,11 +72,9 @@ public: /** Updates the contents of the entire texture from an image. If storage has not been defined, it will be set to match the image. In this case the image will be treated as a stack of square layers and its height must be - divisible by its width. Otherwise the image must match the defined storage. - - If srgb is true and storage is determined by this call, then an sRGB pixel - format will be used. */ - virtual void image(const Graphics::Image &, unsigned, bool = false); + divisible by its width. Otherwise the image must match the defined + storage. */ + virtual void image(const Graphics::Image &, unsigned = 0); using Texture::image; diff --git a/source/texturecube.cpp b/source/texturecube.cpp index 824ff2cc..9ea33eab 100644 --- a/source/texturecube.cpp +++ b/source/texturecube.cpp @@ -165,7 +165,7 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, sub_image(face, level, x, y, wd, ht, data); } -void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool srgb) +void TextureCube::image(TextureCubeFace face, const Graphics::Image &img) { unsigned w = img.get_width(); unsigned h = img.get_height(); @@ -175,7 +175,7 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool s if(w!=h) throw incompatible_data("TextureCube::image"); - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w); + storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w); } else if(w!=size || h!=size) throw incompatible_data("TextureCube::image"); @@ -186,7 +186,12 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool s image(face, 0, img.get_data()); } -void TextureCube::image(const Graphics::Image &img, unsigned lv, bool srgb) +void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool) +{ + image(face, img); +} + +void TextureCube::image(const Graphics::Image &img, unsigned lv) { unsigned w = img.get_width(); unsigned h = img.get_height(); @@ -197,7 +202,7 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv, bool srgb) PixelFormat fmt = pixelformat_from_image(img); if(size==0) - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w, lv); + storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv); else if(w!=size || h!=size) throw incompatible_data("TextureCube::image"); @@ -301,7 +306,7 @@ void TextureCube::Loader::external_image(TextureCubeFace face, const string &fn) RefPtr io = get_collection().open_raw(fn); img.load_io(*io); - obj.image(face, img, srgb); + obj.image(face, img); } void TextureCube::Loader::image_data(TextureCubeFace face, const string &data) @@ -310,7 +315,7 @@ void TextureCube::Loader::image_data(TextureCubeFace face, const string &data) IO::Memory mem(data.data(), data.size()); img.load_io(mem); - obj.image(face, img, srgb); + obj.image(face, img); } void TextureCube::Loader::raw_data(TextureCubeFace face, const string &data) diff --git a/source/texturecube.h b/source/texturecube.h index 82356200..ae305153 100644 --- a/source/texturecube.h +++ b/source/texturecube.h @@ -94,9 +94,11 @@ public: int x, int y, unsigned w, unsigned h, PixelComponents comp, DataType type, const void *data); - void image(TextureCubeFace, const Graphics::Image &, bool = false); + void image(TextureCubeFace, const Graphics::Image &); - virtual void image(const Graphics::Image &, unsigned, bool = false); + DEPRECATED void image(TextureCubeFace, const Graphics::Image &, bool); + + virtual void image(const Graphics::Image &, unsigned = 0); using Texture::image; unsigned get_size() const { return size; } -- 2.43.0