Browse Source

Ability to retrieve texture image size in given mip level.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
692f4854a7
  1. 23
      src/AbstractTexture.cpp
  2. 10
      src/AbstractTexture.h
  3. 14
      src/CubeMapTexture.h
  4. 11
      src/CubeMapTextureArray.h
  5. 17
      src/Texture.h

23
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>& 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", );

10
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>& wrapping) {
(texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast<GLint>(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>& 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>& wrapping);
inline static void setStorage(AbstractTexture* texture, GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector3i& size) {

14
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<GLenum>(coordinate), level);
}
#endif
/**
* @brief Set storage
*

11
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<GLenum>(coordinate), level);
}
/**
* @brief Set storage
*

17
src/Texture.h

@ -174,6 +174,23 @@ template<std::uint8_t dimensions> class Texture: public AbstractTexture {
/** @brief %Texture target */
inline constexpr Target target() const { return static_cast<Target>(_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<Dimensions, GLint>::VectorType imageSize(GLint level) {
return DataHelper<Dimensions>::imageSize(this, _target, level);
}
#endif
/**
* @brief Set wrapping
* @param wrapping Wrapping type for all texture dimensions

Loading…
Cancel
Save