Browse Source

Compressed image support, part 14: queries for compressed block sizes.

pull/132/head
Vladimír Vondruš 11 years ago
parent
commit
56cdc71a52
  1. 2
      doc/opengl-support.dox
  2. 28
      src/Magnum/AbstractTexture.cpp
  3. 11
      src/Magnum/AbstractTexture.h
  4. 28
      src/Magnum/CubeMapTexture.h
  5. 28
      src/Magnum/CubeMapTextureArray.h
  6. 22
      src/Magnum/RectangleTexture.h
  7. 33
      src/Magnum/Texture.h
  8. 28
      src/Magnum/TextureArray.h

2
doc/opengl-support.dox

@ -179,7 +179,7 @@ GLSL 4.30 | done
@extension{ARB,explicit_uniform_location} | done @extension{ARB,explicit_uniform_location} | done
@extension{ARB,fragment_layer_viewport} | done (shading language only) @extension{ARB,fragment_layer_viewport} | done (shading language only)
@extension{ARB,framebuffer_no_attachments} | | @extension{ARB,framebuffer_no_attachments} | |
@extension{ARB,internalformat_query2} | | @extension{ARB,internalformat_query2} | only compressed texture block queries
@extension{ARB,invalidate_subdata} | done @extension{ARB,invalidate_subdata} | done
@extension{ARB,multi_draw_indirect} | | @extension{ARB,multi_draw_indirect} | |
@extension{ARB,program_interface_query} | | @extension{ARB,program_interface_query} | |

28
src/Magnum/AbstractTexture.cpp

@ -197,6 +197,14 @@ void AbstractTexture::bindImplementationMulti(const GLint firstTextureUnit, Cont
} }
#endif #endif
#ifndef MAGNUM_TARGET_GLES
Int AbstractTexture::compressedBlockDataSize(const GLenum target, const TextureFormat format) {
GLint value;
glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_SIZE, 1, &value);
return value;
}
#endif
AbstractTexture::AbstractTexture(GLenum target): _target{target}, _flags{ObjectFlag::DeleteOnDestruction} { AbstractTexture::AbstractTexture(GLenum target): _target{target}, _flags{ObjectFlag::DeleteOnDestruction} {
(this->*Context::current()->state().texture->createImplementation)(); (this->*Context::current()->state().texture->createImplementation)();
CORRADE_INTERNAL_ASSERT(_id != Implementation::State::DisengagedBinding); CORRADE_INTERNAL_ASSERT(_id != Implementation::State::DisengagedBinding);
@ -1625,6 +1633,26 @@ template void MAGNUM_EXPORT AbstractTexture::subImage<3>(GLint, const Range3Di&,
#endif #endif
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_TARGET_GLES
Math::Vector<1, GLint> AbstractTexture::DataHelper<1>::compressedBlockSize(const GLenum target, const TextureFormat format) {
GLint value;
glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_WIDTH, 1, &value);
return value;
}
Vector2i AbstractTexture::DataHelper<2>::compressedBlockSize(const GLenum target, const TextureFormat format) {
Vector2i value{Math::NoInit};
glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_WIDTH, 1, &value.x());
glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT, 1, &value.y());
return value;
}
Vector3i AbstractTexture::DataHelper<3>::compressedBlockSize(const GLenum target, const TextureFormat format) {
/** @todo use real value when OpenGL has proper queries for 3D compression formats */
return Vector3i{DataHelper<2>::compressedBlockSize(target, format), 1};
}
#endif
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
Math::Vector<1, GLint> AbstractTexture::DataHelper<1>::imageSize(AbstractTexture& texture, const GLint level) { Math::Vector<1, GLint> AbstractTexture::DataHelper<1>::imageSize(AbstractTexture& texture, const GLint level) {
Math::Vector<1, GLint> value; Math::Vector<1, GLint> value;

11
src/Magnum/AbstractTexture.h

@ -338,6 +338,10 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
#endif #endif
template<UnsignedInt textureDimensions> struct DataHelper {}; template<UnsignedInt textureDimensions> struct DataHelper {};
#ifndef MAGNUM_TARGET_GLES
static Int compressedBlockDataSize(GLenum target, TextureFormat format);
#endif
explicit AbstractTexture(GLenum target); explicit AbstractTexture(GLenum target);
explicit AbstractTexture(NoCreateT, GLenum target) noexcept: _target{target}, _id{0}, _flags{ObjectFlag::DeleteOnDestruction} {} explicit AbstractTexture(NoCreateT, GLenum target) noexcept: _target{target}, _id{0}, _flags{ObjectFlag::DeleteOnDestruction} {}
explicit AbstractTexture(GLuint id, GLenum target, ObjectFlags flags) noexcept: _target{target}, _id{id}, _flags{flags} {} explicit AbstractTexture(GLuint id, GLenum target, ObjectFlags flags) noexcept: _target{target}, _id{id}, _flags{flags} {}
@ -584,6 +588,7 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<1> { template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<1> {
static Math::Vector<1, GLint> compressedBlockSize(GLenum target, TextureFormat format);
static Math::Vector<1, GLint> imageSize(AbstractTexture& texture, GLint level); static Math::Vector<1, GLint> imageSize(AbstractTexture& texture, GLint level);
static void setWrapping(AbstractTexture& texture, const Array1D<Sampler::Wrapping>& wrapping); static void setWrapping(AbstractTexture& texture, const Array1D<Sampler::Wrapping>& wrapping);
@ -604,6 +609,9 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<1> {
}; };
#endif #endif
template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> {
#ifndef MAGNUM_TARGET_GLES
static Vector2i compressedBlockSize(GLenum target, TextureFormat format);
#endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
static Vector2i imageSize(AbstractTexture& texture, GLint level); static Vector2i imageSize(AbstractTexture& texture, GLint level);
#endif #endif
@ -646,6 +654,9 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> {
}; };
template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> {
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
#ifndef MAGNUM_TARGET_GLES
static Vector3i compressedBlockSize(GLenum target, TextureFormat format);
#endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
static Vector3i imageSize(AbstractTexture& texture, GLint level); static Vector3i imageSize(AbstractTexture& texture, GLint level);
#endif #endif

28
src/Magnum/CubeMapTexture.h

@ -102,6 +102,34 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture {
*/ */
static Vector2i maxSize(); static Vector2i maxSize();
#ifndef MAGNUM_TARGET_GLES
/**
* @copybrief Texture::compressedBlockSize()
*
* See @ref Texture::compressedBlockSize() for more information.
* @requires_gl43 Extension @extension{ARB,internalformat_query2}
* @requires_gl Compressed texture queries are not available in OpenGL
* ES.
*/
static Vector2i compressedBlockSize(TextureFormat format) {
return DataHelper<2>::compressedBlockSize(GL_TEXTURE_CUBE_MAP, format);
}
/**
* @copybrief Texture::compressedBlockDataSize()
*
* See @ref Texture::compressedBlockDataSize() for more information.
* @requires_gl43 Extension @extension{ARB,internalformat_query2}
* @requires_gl Compressed texture queries are not available in OpenGL
* ES.
* @see @ref compressedBlockSize(), @fn_gl{Getinternalformat} with
* @def_gl{TEXTURE_COMPRESSED_BLOCK_SIZE}
*/
static Int compressedBlockDataSize(TextureFormat format) {
return AbstractTexture::compressedBlockDataSize(GL_TEXTURE_CUBE_MAP, format);
}
#endif
/** /**
* @brief Wrap existing OpenGL cube map texture object * @brief Wrap existing OpenGL cube map texture object
* @param id OpenGL cube map texture ID * @param id OpenGL cube map texture ID

28
src/Magnum/CubeMapTextureArray.h

@ -98,6 +98,34 @@ class MAGNUM_EXPORT CubeMapTextureArray: public AbstractTexture {
*/ */
static Vector3i maxSize(); static Vector3i maxSize();
#ifndef MAGNUM_TARGET_GLES
/**
* @copybrief Texture::compressedBlockSize()
*
* See @ref Texture::compressedBlockSize() for more information.
* @requires_gl43 Extension @extension{ARB,internalformat_query2}
* @requires_gl Compressed texture queries are not available in OpenGL
* ES.
*/
static Vector2i compressedBlockSize(TextureFormat format) {
return DataHelper<2>::compressedBlockSize(GL_TEXTURE_CUBE_MAP_ARRAY, format);
}
/**
* @copybrief Texture::compressedBlockDataSize()
*
* See @ref Texture::compressedBlockDataSize() for more information.
* @requires_gl43 Extension @extension{ARB,internalformat_query2}
* @requires_gl Compressed texture queries are not available in OpenGL
* ES.
* @see @ref compressedBlockSize(), @fn_gl{Getinternalformat} with
* @def_gl{TEXTURE_COMPRESSED_BLOCK_SIZE}
*/
static Int compressedBlockDataSize(TextureFormat format) {
return AbstractTexture::compressedBlockDataSize(GL_TEXTURE_CUBE_MAP_ARRAY, format);
}
#endif
/** /**
* @brief Wrap existing OpenGL cube map array texture object * @brief Wrap existing OpenGL cube map array texture object
* @param id OpenGL cube map array texture ID * @param id OpenGL cube map array texture ID

22
src/Magnum/RectangleTexture.h

@ -80,6 +80,28 @@ class MAGNUM_EXPORT RectangleTexture: public AbstractTexture {
*/ */
static Vector2i maxSize(); static Vector2i maxSize();
/**
* @copybrief Texture::compressedBlockSize()
*
* See @ref Texture::compressedBlockSize() for more information.
* @requires_gl43 Extension @extension{ARB,internalformat_query2}
*/
static Vector2i compressedBlockSize(TextureFormat format) {
return DataHelper<2>::compressedBlockSize(GL_TEXTURE_RECTANGLE, format);
}
/**
* @copybrief Texture::compressedBlockDataSize()
*
* See @ref Texture::compressedBlockDataSize() for more information.
* @requires_gl43 Extension @extension{ARB,internalformat_query2}
* @see @ref compressedBlockSize(), @fn_gl{Getinternalformat} with
* @def_gl{TEXTURE_COMPRESSED_BLOCK_SIZE}
*/
static Int compressedBlockDataSize(TextureFormat format) {
return AbstractTexture::compressedBlockDataSize(GL_TEXTURE_RECTANGLE, format);
}
/** /**
* @brief Wrap existing OpenGL rectangle texture object * @brief Wrap existing OpenGL rectangle texture object
* @param id OpenGL rectangle texture ID * @param id OpenGL rectangle texture ID

33
src/Magnum/Texture.h

@ -123,6 +123,39 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
return Implementation::maxTextureSize<dimensions>(); return Implementation::maxTextureSize<dimensions>();
} }
#ifndef MAGNUM_TARGET_GLES
/**
* @brief Compressed block size
*
* If @p format is compressed, returns compressed block size (in
* pixels). For uncompressed formats returns zero vector.
* @see @ref compressedBlockDataSize(), @fn_gl{Getinternalformat} with
* @def_gl{TEXTURE_COMPRESSED_BLOCK_WIDTH},
* @def_gl{TEXTURE_COMPRESSED_BLOCK_HEIGHT}
* @requires_gl43 Extension @extension{ARB,internalformat_query2}
* @requires_gl Compressed texture queries are not available in OpenGL
* ES.
*/
static VectorTypeFor<dimensions, Int> compressedBlockSize(TextureFormat format) {
return DataHelper<dimensions>::compressedBlockSize(Implementation::textureTarget<dimensions>(), format);
}
/**
* @brief Compressed block data size
*
* If @p format is compressed, returns compressed block data size (in
* bytes). For uncompressed formats returns zero.
* @see @ref compressedBlockSize(), @fn_gl{Getinternalformat} with
* @def_gl{TEXTURE_COMPRESSED_BLOCK_SIZE}
* @requires_gl43 Extension @extension{ARB,internalformat_query2}
* @requires_gl Compressed texture queries are not available in OpenGL
* ES.
*/
static Int compressedBlockDataSize(TextureFormat format) {
return AbstractTexture::compressedBlockDataSize(Implementation::textureTarget<dimensions>(), format);
}
#endif
/** /**
* @brief Wrap existing OpenGL texture object * @brief Wrap existing OpenGL texture object
* @param id OpenGL texture ID * @param id OpenGL texture ID

28
src/Magnum/TextureArray.h

@ -111,6 +111,34 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
*/ */
static VectorTypeFor<dimensions+1, Int> maxSize(); static VectorTypeFor<dimensions+1, Int> maxSize();
#ifndef MAGNUM_TARGET_GLES
/**
* @copybrief Texture::compressedBlockSize()
*
* See @ref Texture::compressedBlockSize() for more information.
* @requires_gl43 Extension @extension{ARB,internalformat_query2}
* @requires_gl Compressed texture queries are not available in OpenGL
* ES.
*/
static VectorTypeFor<dimensions, Int> compressedBlockSize(TextureFormat format) {
return DataHelper<dimensions>::compressedBlockSize(Implementation::textureArrayTarget<dimensions>(), format);
}
/**
* @copybrief Texture::compressedBlockDataSize()
*
* See @ref Texture::compressedBlockDataSize() for more information.
* @requires_gl43 Extension @extension{ARB,internalformat_query2}
* @requires_gl Compressed texture queries are not available in OpenGL
* ES.
* @see @ref compressedBlockSize(), @fn_gl{Getinternalformat} with
* @def_gl{TEXTURE_COMPRESSED_BLOCK_SIZE}
*/
static Int compressedBlockDataSize(TextureFormat format) {
return AbstractTexture::compressedBlockDataSize(Implementation::textureArrayTarget<dimensions>(), format);
}
#endif
/** /**
* @brief Wrap existing OpenGL texture array object * @brief Wrap existing OpenGL texture array object
* @param id OpenGL texture array ID * @param id OpenGL texture array ID

Loading…
Cancel
Save