From: Mikko Rasa Date: Mon, 2 Jul 2018 12:46:13 +0000 (+0300) Subject: Explicitly define the number of mipmap levels in textures X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=03d3984ecd2c4e7c38b6a62b4b7a81bab69f8d40;p=libs%2Fgl.git Explicitly define the number of mipmap levels in textures Storage() no longer uses the minification filter to decide whether to allocate mipmaps or not. That functionality has been moved to image(), specifically the version taking a Graphics::Image. --- diff --git a/source/texture1d.cpp b/source/texture1d.cpp index c5e57df2..a1ee418b 100644 --- a/source/texture1d.cpp +++ b/source/texture1d.cpp @@ -19,7 +19,7 @@ Texture1D::Texture1D(): static Require _req(MSP_texture1D); } -void Texture1D::storage(PixelFormat fmt, unsigned wd) +void Texture1D::storage(PixelFormat fmt, unsigned wd, unsigned lv) { if(width>0) throw invalid_operation("Texture1D::storage"); @@ -28,26 +28,30 @@ void Texture1D::storage(PixelFormat fmt, unsigned wd) set_internal_format(fmt); width = wd; + levels = get_n_levels(); + if(lv) + levels = min(levels, lv); } void Texture1D::allocate(unsigned level) { if(width==0) throw invalid_operation("Texture1D::allocate"); + if(level>=levels) + throw invalid_argument("Texture1D::allocate"); if(allocated&(1<0) throw invalid_operation("Texture2D::storage"); @@ -56,26 +56,30 @@ void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht) set_internal_format(fmt); width = wd; height = ht; + levels = get_n_levels(); + if(lv>0) + levels = min(levels, lv); } void Texture2D::allocate(unsigned level) { if(width==0 || height==0) throw invalid_operation("Texture2D::allocate"); + if(level>=levels) + throw invalid_argument("Texture2D::allocate"); if(allocated&(1<0) throw invalid_operation("Texture3D::storage"); @@ -44,26 +44,30 @@ void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp) width = wd; height = ht; depth = dp; + levels = get_n_levels(); + if(lv>0) + levels = min(levels, lv); } void Texture3D::allocate(unsigned level) { if(width==0 || height==0 || depth==0) throw invalid_operation("Texture3D::allocate"); + if(level>=levels) + throw invalid_argument("Texture3D::allocate"); if(allocated&(1<0) throw invalid_operation("TextureCube::storage"); @@ -60,21 +60,25 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz) set_internal_format(fmt); size = sz; + levels = get_n_levels(); + if(lv>0) + levels = min(levels, lv); } void TextureCube::allocate(unsigned level) { if(size==0) throw invalid_operation("TextureCube::allocate"); + if(level>=levels) + throw invalid_argument("TextureCube::allocate"); if(allocated&(1<