From caa98895955dfc8db14dd6fc748f6eb44d9e086f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 2 Sep 2013 22:33:34 +0200 Subject: [PATCH] Use `size >> mipLevel` to compute image size at given mip level. This is so awesome trick. --- src/AbstractTexture.cpp | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 1f2f7b345..481679606 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -683,10 +683,8 @@ void AbstractTexture::storageImplementationFallback(const GLenum target, const G const ImageFormat format = imageFormatForInternalFormat(internalFormat); const ImageType type = imageTypeForInternalFormat(internalFormat); - auto levelSize = size; for(GLsizei level = 0; level != levels; ++level) { - (this->*image1DImplementation)(target, level, internalFormat, levelSize, format, type, nullptr); - levelSize = Math::max(Math::Vector<1, GLsizei>(1), levelSize/2); + (this->*image1DImplementation)(target, level, internalFormat, Math::max(Math::Vector<1, GLsizei>(1), size >> level), format, type, nullptr); } } @@ -720,15 +718,12 @@ void AbstractTexture::storageImplementationFallback(const GLenum target, const G if(target == GL_TEXTURE_2D) #endif { - Vector2i levelSize = size; for(GLsizei level = 0; level != levels; ++level) { - (this->*image2DImplementation)(target, level, internalFormat, levelSize, format, type, nullptr); - levelSize = Math::max(Vector2i(1), levelSize/2); + (this->*image2DImplementation)(target, level, internalFormat, Math::max(Vector2i(1), size >> level), format, type, nullptr); } /* Cube map additionally needs to specify all faces */ } else if(target == GL_TEXTURE_CUBE_MAP) { - Vector2i levelSize = size; for(GLsizei level = 0; level != levels; ++level) { for(GLenum face: {GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, @@ -736,17 +731,14 @@ void AbstractTexture::storageImplementationFallback(const GLenum target, const G GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}) - (this->*image2DImplementation)(face, level, internalFormat, levelSize, format, type, nullptr); - levelSize = Math::max(Vector2i(1), levelSize/2); + (this->*image2DImplementation)(face, level, internalFormat, Math::max(Vector2i(1), size >> level), format, type, nullptr); } #ifndef MAGNUM_TARGET_GLES /* Array texture is not scaled in "layer" dimension */ } else if(target == GL_TEXTURE_1D_ARRAY) { - Vector2i levelSize = size; for(GLsizei level = 0; level != levels; ++level) { - (this->*image2DImplementation)(target, level, internalFormat, levelSize, format, type, nullptr); - levelSize.x() = Math::max(1, levelSize.x()/2); + (this->*image2DImplementation)(target, level, internalFormat, Math::max(Vector2i(1), size >> level), format, type, nullptr); } #endif @@ -785,10 +777,8 @@ void AbstractTexture::storageImplementationFallback(GLenum target, GLsizei level if(target == GL_TEXTURE_3D_OES) #endif { - Vector3i levelSize = size; for(GLsizei level = 0; level != levels; ++level) { - (this->*image3DImplementation)(target, level, internalFormat, levelSize, format, type, nullptr); - levelSize = Math::max(Vector3i(1), levelSize/2); + (this->*image3DImplementation)(target, level, internalFormat, Math::max(Vector3i(1), size >> level), format, type, nullptr); } #ifndef MAGNUM_TARGET_GLES2 @@ -800,10 +790,8 @@ void AbstractTexture::storageImplementationFallback(GLenum target, GLsizei level else if(target == GL_TEXTURE_2D_ARRAY) #endif { - Vector3i levelSize = size; for(GLsizei level = 0; level != levels; ++level) { - (this->*image3DImplementation)(target, level, internalFormat, levelSize, format, type, nullptr); - levelSize.xy() = Math::max(Vector2i(1), levelSize.xy()/2); + (this->*image3DImplementation)(target, level, internalFormat, Math::max(Vector3i(1), size >> level), format, type, nullptr); } #endif