From: Mikko Rasa Date: Thu, 3 Nov 2016 08:08:29 +0000 (+0200) Subject: Move internal format management to the Texture base class X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=cdf928f03f4d8383b8fa978abc4c255a850ec061;p=libs%2Fgl.git Move internal format management to the Texture base class --- diff --git a/source/texture.cpp b/source/texture.cpp index 581ec705..21fc7a6a 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -52,6 +52,7 @@ void operator>>(const LexicalConverter &c, TextureWrap &tw) Texture::Texture(GLenum t, ResourceManager *m): id(0), target(t), + ifmt(RGB), min_filter(NEAREST_MIPMAP_LINEAR), mag_filter(LINEAR), wrap_s(REPEAT), @@ -84,6 +85,15 @@ DataType Texture::get_alloc_type(PixelFormat fmt) return (get_base_pixelformat(fmt)==DEPTH_COMPONENT ? UNSIGNED_SHORT : UNSIGNED_BYTE); } +void Texture::set_internal_format(PixelFormat fmt) +{ + if(MSP_sized_internal_formats) + fmt = get_sized_pixelformat(fmt); + + require_pixelformat(fmt); + ifmt = fmt; +} + void Texture::update_parameter(int mask) const { if(!ARB_direct_state_access && TexUnit::current().get_texture()!=this) diff --git a/source/texture.h b/source/texture.h index f1a51767..1b80e950 100644 --- a/source/texture.h +++ b/source/texture.h @@ -109,6 +109,7 @@ protected: unsigned id; GLenum target; + PixelFormat ifmt; TextureFilter min_filter; TextureFilter mag_filter; float max_anisotropy; @@ -128,6 +129,7 @@ public: protected: static DataType get_alloc_type(PixelFormat); + void set_internal_format(PixelFormat); void update_parameter(int) const; void set_parameter_i(GLenum, int) const; diff --git a/source/texture1d.cpp b/source/texture1d.cpp index 32053e83..6affe899 100644 --- a/source/texture1d.cpp +++ b/source/texture1d.cpp @@ -13,7 +13,6 @@ namespace GL { Texture1D::Texture1D(): Texture(GL_TEXTURE_1D), - ifmt(RGB), width(0), allocated(0) { @@ -27,11 +26,7 @@ void Texture1D::storage(PixelFormat fmt, unsigned wd) if(wd==0) throw invalid_argument("Texture1D::storage"); - if(MSP_sized_internal_formats) - fmt = get_sized_pixelformat(fmt); - require_pixelformat(fmt); - - ifmt = fmt; + set_internal_format(fmt); width = wd; } diff --git a/source/texture1d.h b/source/texture1d.h index d75167b1..5e6f2549 100644 --- a/source/texture1d.h +++ b/source/texture1d.h @@ -22,7 +22,6 @@ public: }; private: - PixelFormat ifmt; unsigned width; unsigned allocated; diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 8ecebdfb..75b84ec7 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -36,7 +36,6 @@ public: Texture2D::Texture2D(ResourceManager *m): Texture(GL_TEXTURE_2D, m), - ifmt(RGB), width(0), height(0), allocated(0) @@ -54,11 +53,7 @@ void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht) if(wd==0 || ht==0) throw invalid_argument("Texture2D::storage"); - if(MSP_sized_internal_formats) - fmt = get_sized_pixelformat(fmt); - require_pixelformat(fmt); - - ifmt = fmt; + set_internal_format(fmt); width = wd; height = ht; } diff --git a/source/texture2d.h b/source/texture2d.h index 9647ad3e..1f8b5f7e 100644 --- a/source/texture2d.h +++ b/source/texture2d.h @@ -31,7 +31,6 @@ public: private: class AsyncLoader; - PixelFormat ifmt; unsigned width; unsigned height; unsigned allocated; diff --git a/source/texture3d.cpp b/source/texture3d.cpp index f64f548a..680880a8 100644 --- a/source/texture3d.cpp +++ b/source/texture3d.cpp @@ -16,7 +16,6 @@ namespace GL { Texture3D::Texture3D(GLenum t): Texture(t), - ifmt(RGB), width(0), height(0), depth(0), @@ -25,7 +24,6 @@ Texture3D::Texture3D(GLenum t): Texture3D::Texture3D(): Texture(GL_TEXTURE_3D), - ifmt(RGB), width(0), height(0), depth(0), @@ -41,11 +39,7 @@ void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp) if(wd==0 || ht==0 || dp==0) throw invalid_argument("Texture3D::storage"); - if(MSP_sized_internal_formats) - fmt = get_sized_pixelformat(fmt); - require_pixelformat(fmt); - - ifmt = fmt; + set_internal_format(fmt); width = wd; height = ht; depth = dp; diff --git a/source/texture3d.h b/source/texture3d.h index 57f3a6f8..cf336e52 100644 --- a/source/texture3d.h +++ b/source/texture3d.h @@ -27,7 +27,6 @@ public: }; private: - PixelFormat ifmt; unsigned width; unsigned height; unsigned depth; diff --git a/source/texturecube.cpp b/source/texturecube.cpp index 833ef28f..19c3bf07 100644 --- a/source/texturecube.cpp +++ b/source/texturecube.cpp @@ -45,7 +45,6 @@ unsigned TextureCube::orientations[12] = TextureCube::TextureCube(): Texture(GL_TEXTURE_CUBE_MAP), - ifmt(RGB), size(0), allocated(0) { @@ -59,11 +58,7 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz) if(sz==0) throw invalid_argument("TextureCube::storage"); - if(MSP_sized_internal_formats) - fmt = get_sized_pixelformat(fmt); - require_pixelformat(fmt); - - ifmt = fmt; + set_internal_format(fmt); size = sz; } diff --git a/source/texturecube.h b/source/texturecube.h index 9ce216fd..ea1c8296 100644 --- a/source/texturecube.h +++ b/source/texturecube.h @@ -49,7 +49,6 @@ public: }; private: - PixelFormat ifmt; unsigned size; unsigned allocated;