From 692f4854a7f9fff0325a2245fac121fdd95fcdc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Feb 2013 12:40:14 +0100 Subject: [PATCH] Ability to retrieve texture image size in given mip level. --- src/AbstractTexture.cpp | 23 +++++++++++++++++++++++ src/AbstractTexture.h | 10 ++++++++++ src/CubeMapTexture.h | 14 ++++++++++++++ src/CubeMapTextureArray.h | 11 +++++++++++ src/Texture.h | 17 +++++++++++++++++ 5 files changed, 75 insertions(+) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 33d5f534a..7fe72dca1 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -464,6 +464,29 @@ namespace Implementation { } #endif +#ifndef MAGNUM_TARGET_GLES +Math::Vector<1, GLint> AbstractTexture::DataHelper<1>::imageSize(AbstractTexture* texture, GLenum target, GLint level) { + Math::Vector<1, GLint> value; + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_WIDTH, &value[0]); + return value; +} + +Vector2i AbstractTexture::DataHelper<2>::imageSize(AbstractTexture* texture, GLenum target, GLint level) { + Vector2i value; + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_WIDTH, &value[0]); + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_HEIGHT, &value[1]); + return value; +} + +Vector3i AbstractTexture::DataHelper<3>::imageSize(AbstractTexture* texture, GLenum target, GLint level) { + Vector3i value; + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_WIDTH, &value[0]); + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_HEIGHT, &value[1]); + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_DEPTH, &value[2]); + return value; +} +#endif + void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Array2D& wrapping) { #ifndef MAGNUM_TARGET_GLES CORRADE_ASSERT(texture->_target != GL_TEXTURE_RECTANGLE || ((wrapping.x() == Wrapping::ClampToEdge || wrapping.x() == Wrapping::ClampToBorder) && (wrapping.y() == Wrapping::ClampToEdge || wrapping.y() == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 328d75a15..3d190e76c 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -1308,6 +1308,8 @@ template<> struct AbstractTexture::DataHelper<1> { inline constexpr static Target target() { return Target::Texture1D; } + static Math::Vector<1, GLint> imageSize(AbstractTexture* texture, GLenum target, GLint level); + inline static void setWrapping(AbstractTexture* texture, const Array1D& wrapping) { (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping.x())); } @@ -1341,6 +1343,10 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { inline constexpr static Target target() { return Target::Texture2D; } + #ifndef MAGNUM_TARGET_GLES + static Vector2i imageSize(AbstractTexture* texture, GLenum target, GLint level); + #endif + static void setWrapping(AbstractTexture* texture, const Array2D& wrapping); inline static void setStorage(AbstractTexture* texture, GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector2i& size) { @@ -1375,6 +1381,10 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { inline constexpr static Target target() { return Target::Texture3D; } + #ifndef MAGNUM_TARGET_GLES + static Vector3i imageSize(AbstractTexture* texture, GLenum target, GLint level); + #endif + static void setWrapping(AbstractTexture* texture, const Array3D& wrapping); inline static void setStorage(AbstractTexture* texture, GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector3i& size) { diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 61dcd3b77..ed3a2c9d3 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -110,6 +110,20 @@ class CubeMapTexture: public AbstractTexture { return this; } + #ifndef MAGNUM_TARGET_GLES + /** + * @brief %Image size in given mip level + * @param coordinate Coordinate + * @param level Mip level + * + * See Texture::imageSize() for more information. + * @requires_gl %Texture image queries are not available in OpenGL ES. + */ + inline Vector2i imageSize(Coordinate coordinate, GLint level) { + return DataHelper<2>::imageSize(this, static_cast(coordinate), level); + } + #endif + /** * @brief Set storage * diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 28c2feea5..d6b25f3af 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -99,6 +99,17 @@ class CubeMapTextureArray: public AbstractTexture { return this; } + /** + * @brief %Image size in given mip level + * @param coordinate Coordinate + * @param level Mip level + * + * See Texture::imageSize() for more information. + */ + inline Vector3i imageSize(Coordinate coordinate, GLint level) { + return DataHelper<3>::imageSize(this, GL_TEXTURE_CUBE_MAP_POSITIVE_X + static_cast(coordinate), level); + } + /** * @brief Set storage * diff --git a/src/Texture.h b/src/Texture.h index 0913bd083..80cf12063 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -174,6 +174,23 @@ template class Texture: public AbstractTexture { /** @brief %Texture target */ inline constexpr Target target() const { return static_cast(_target); } + #ifndef MAGNUM_TARGET_GLES + /** + * @brief %Image size in given mip level + * + * The result is not cached in any way. If + * @extension{EXT,direct_state_access} is not available, the texture + * is bound to some layer before the operation. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @fn_gl{GetTexLevelParameter} or @fn_gl_extension{GetTextureLevelParameter,EXT,direct_state_access} + * with @def_gl{TEXTURE_WIDTH}, @def_gl{TEXTURE_HEIGHT} or @def_gl{TEXTURE_DEPTH}. + * @requires_gl %Texture image queries are not available in OpenGL ES. + */ + inline typename DimensionTraits::VectorType imageSize(GLint level) { + return DataHelper::imageSize(this, _target, level); + } + #endif + /** * @brief Set wrapping * @param wrapping Wrapping type for all texture dimensions