From 03d3984ecd2c4e7c38b6a62b4b7a81bab69f8d40 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 2 Jul 2018 15:46:13 +0300 Subject: [PATCH] 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. --- source/texture1d.cpp | 19 +++++++++++++------ source/texture1d.h | 3 ++- source/texture2d.cpp | 19 +++++++++++++------ source/texture2d.h | 10 +++++++--- source/texture3d.cpp | 19 +++++++++++++------ source/texture3d.h | 10 +++++++--- source/texturecube.cpp | 17 ++++++++++++----- source/texturecube.h | 10 +++++++--- 8 files changed, 74 insertions(+), 33 deletions(-) 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<