From: Mikko Rasa Date: Sat, 30 Jan 2021 17:57:58 +0000 (+0200) Subject: Deprecate the mipmap_levels parameter in Texture X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=aead6d04308d7873dc99aa4572ce1590a89ebcbd;p=libs%2Fgl.git Deprecate the mipmap_levels parameter in Texture Instead specify the desired amount of mipmap levels when loading an image. This can be more robustly checked against the defined storage. --- diff --git a/source/texture.cpp b/source/texture.cpp index 68e44861..401cb968 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -63,7 +63,6 @@ Texture::Texture(GLenum t, ResourceManager *m): ifmt(RGB), min_filter(NEAREST_MIPMAP_LINEAR), mag_filter(LINEAR), - mipmap_levels(0), max_anisotropy(1.0f), wrap_s(REPEAT), wrap_t(REPEAT), @@ -183,8 +182,6 @@ void Texture::update_parameter(int mask) const glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle_orders+swizzle*4); } } - if(mask&MIPMAP_LEVELS) - set_parameter_i(GL_TEXTURE_MAX_LEVEL, (mipmap_levels ? mipmap_levels-1 : 1000)); } void Texture::set_parameter_i(GLenum param, int value) const @@ -221,12 +218,6 @@ void Texture::set_filter(TextureFilter f) set_mag_filter(f==NEAREST ? NEAREST : LINEAR); } -void Texture::set_mipmap_levels(unsigned l) -{ - mipmap_levels = l; - update_parameter(MIPMAP_LEVELS); -} - void Texture::set_max_anisotropy(float a) { if(a<1.0f) @@ -308,11 +299,21 @@ void Texture::set_compare_func(Predicate f) } void Texture::load_image(const string &fn, bool srgb) +{ + load_image(fn, 0, srgb); +} + +void Texture::load_image(const string &fn, unsigned lv, bool srgb) { Graphics::Image img; img.load_file(fn); - image(img, srgb); + image(img, lv, srgb); +} + +void Texture::image(const Graphics::Image &img, bool srgb) +{ + image(img, 0, srgb); } void Texture::bind_to(unsigned i) const @@ -386,6 +387,7 @@ 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 @@ -413,7 +415,7 @@ void Texture::Loader::external_image(const string &fn) throw IO::file_not_found(fn); img.load_io(*io); - obj.image(img, srgb); + obj.image(img, levels, srgb); } void Texture::Loader::filter(TextureFilter f) @@ -432,7 +434,7 @@ void Texture::Loader::image_data(const string &data) IO::Memory mem(data.data(), data.size()); img.load_io(mem); - obj.image(img, srgb); + obj.image(img, levels, srgb); } void Texture::Loader::mag_filter(TextureFilter f) @@ -452,7 +454,7 @@ void Texture::Loader::min_filter(TextureFilter f) void Texture::Loader::mipmap_levels(unsigned l) { - obj.set_mipmap_levels(l); + levels = l; } void Texture::Loader::wrap(TextureWrap w) diff --git a/source/texture.h b/source/texture.h index 3fa29f60..8aac0592 100644 --- a/source/texture.h +++ b/source/texture.h @@ -74,6 +74,7 @@ protected: class Loader: public DataFile::CollectionObjectLoader { protected: + unsigned levels; bool srgb; public: @@ -106,8 +107,7 @@ protected: COMPARE = 64, COMPARE_FUNC = 128, MAX_ANISOTROPY = 256, - FORMAT_SWIZZLE = 512, - MIPMAP_LEVELS = 1024 + FORMAT_SWIZZLE = 512 }; enum FormatSwizzle @@ -123,7 +123,6 @@ protected: FormatSwizzle swizzle; TextureFilter min_filter; TextureFilter mag_filter; - unsigned mipmap_levels; float max_anisotropy; TextureWrap wrap_s; TextureWrap wrap_t; @@ -157,7 +156,7 @@ public: is not applicable to magnification, LINEAR is used instead. */ void set_filter(TextureFilter); - void set_mipmap_levels(unsigned); + DEPRECATED void set_mipmap_levels(unsigned) { } void set_max_anisotropy(float); @@ -191,13 +190,17 @@ public: /// 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, bool srgb = false); + /** 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. 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) = 0; + virtual void image(const Graphics::Image &, bool srgb = false); + + virtual void image(const Graphics::Image &, unsigned, bool srgb = false) = 0; GLenum get_target() const { return target; } unsigned get_id() const { return id; } diff --git a/source/texture1d.cpp b/source/texture1d.cpp index d88b88c0..d09a9570 100644 --- a/source/texture1d.cpp +++ b/source/texture1d.cpp @@ -71,13 +71,16 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void return sub_image(level, 0, w, fmt, type, data); BindRestore _bind(this); + + if(!allocated) + glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1); glTexImage1D(target, level, ifmt, w, 0, get_upload_format(fmt), type, data); allocated |= 1<