Browse Source

GL: added BufferTexture::size().

Why the heck was it not here? Did I fear GL errors too much?
pull/370/head
Vladimír Vondruš 7 years ago
parent
commit
dbc029e18e
  1. 3
      doc/changelog.dox
  2. 2
      doc/opengl-mapping.dox
  3. 8
      src/Magnum/GL/BufferTexture.cpp
  4. 17
      src/Magnum/GL/BufferTexture.h
  5. 22
      src/Magnum/GL/Test/BufferTextureGLTest.cpp

3
doc/changelog.dox

@ -123,6 +123,8 @@ See also:
and @cpp "mesa-implementation-color-read-format-dsa-explicit-binding" @ce,
because it's 2019 and GL drivers are *still* awful. See
@ref opengl-workarounds for more information.
- Added @ref GL::BufferTexture::size() as it was the only texture type were
this query was missing.
- New @cpp "swiftshader-no-es2-draw-instanced-entrypoints" @ce and
@cpp "swiftshader-no-es2-oes-texture-3d-entrypoints" @ce workarounds
disabling @gl_extension{ANGLE,instanced_arrays} and
@ -190,7 +192,6 @@ See also:
@ref BasicMutableImageView "MutableImageView*D" and
@ref BasicMutableCompressedImageView "MutableCompressedImageView*D" as well
@subsubsection changelog-latest-new-math Math library
- @ref Math::Frustum::begin() / @ref Math::Frustum::end() accessors for

2
doc/opengl-mapping.dox

@ -227,7 +227,7 @@ OpenGL function | Matching API
@fn_gl{GetSubroutineUniformLocation} | |
@fn_gl{GetSync} | |
@fn_gl{GetTexImage}, \n `glGetnTexImage()`, \n @fn_gl_extension{GetnTexImage,ARB,robustness}, \n `glGetTextureImage()` | @ref GL::Texture::image(), \n @ref GL::TextureArray::image(), \n @ref GL::CubeMapTexture::image(), \n @ref GL::CubeMapTextureArray::image(), \n @ref GL::RectangleTexture::image()
@fn_gl{GetTexLevelParameter}, \n `glGetTextureLevelParameter()` | @ref GL::Texture::imageSize(), \n @ref GL::TextureArray::imageSize(), \n @ref GL::CubeMapTexture::imageSize(), \n @ref GL::CubeMapTextureArray::imageSize(), \n @ref GL::RectangleTexture::imageSize()
@fn_gl{GetTexLevelParameter}, \n `glGetTextureLevelParameter()` | @ref GL::Texture::imageSize(), \n @ref GL::TextureArray::imageSize(), \n @ref GL::CubeMapTexture::imageSize(), \n @ref GL::CubeMapTextureArray::imageSize(), \n @ref GL::RectangleTexture::imageSize(), \n @ref GL::BufferTexture::imageSize()
@fn_gl{GetTexParameter}, \n `glGetTextureParameter()` | |
@fn_gl_extension{GetTextureHandle,ARB,bindless_texture} | |
@fn_gl_extension{GetTextureSamplerHandle,ARB,bindless_texture} | |

8
src/Magnum/GL/BufferTexture.cpp

@ -70,6 +70,14 @@ Int BufferTexture::offsetAlignment() {
return value;
}
Int BufferTexture::size() {
/* Can't use DataHelper<1>::imageSize(*this, 0)[0] because for 1D textures
it's not defined on ES */
Int size;
(this->*Context::current().state().texture->getLevelParameterivImplementation)(0, GL_TEXTURE_WIDTH, &size);
return size;
}
BufferTexture& BufferTexture::setBuffer(const BufferTextureFormat internalFormat, Buffer& buffer) {
(this->*Context::current().state().texture->setBufferImplementation)(internalFormat, buffer);
return *this;

17
src/Magnum/GL/BufferTexture.h

@ -156,6 +156,23 @@ class MAGNUM_GL_EXPORT BufferTexture: public AbstractTexture {
/** @brief Move assignment */
BufferTexture& operator=(BufferTexture&&) noexcept = default;
/**
* @brief Texture size
*
* Equivalent to size of the buffer attached to @ref setBuffer()
* divided by size of a particular @ref BufferTextureFormat. The result
* is not cached in any way. If @gl_extension{ARB,direct_state_access}
* (part of OpenGL 4.5) is not available, the texture is bound before
* the operation (if not already).
* @see @fn_gl2_keyword{GetTextureLevelParameter,GetTexLevelParameter},
* eventually @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and
* @fn_gl_keyword{GetTexLevelParameter} with
* @def_gl_keyword{TEXTURE_WIDTH}
* @requires_gles31 Texture image size queries are not available in
* OpenGL ES 3.0 and older.
*/
Int size();
/**
* @brief Bind texture to given image unit
* @param imageUnit Image unit

22
src/Magnum/GL/Test/BufferTextureGLTest.cpp

@ -181,7 +181,16 @@ void BufferTextureGLTest::setBuffer() {
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
buffer.setData(data, BufferUsage::StaticDraw);
texture.setBuffer(BufferTextureFormat::R8UI, buffer);
texture.setBuffer(BufferTextureFormat::RG8UI, buffer);
MAGNUM_VERIFY_NO_GL_ERROR();
#ifdef MAGNUM_TARGET_GLES
if(!Context::current().isVersionSupported(Version::GLES310))
CORRADE_SKIP("OpenGL ES 3.1 not supported, skipping image size testing.");
#endif
CORRADE_COMPARE(texture.size(), 8);
MAGNUM_VERIFY_NO_GL_ERROR();
}
@ -210,7 +219,16 @@ void BufferTextureGLTest::setBufferOffset() {
};
buffer.setData({nullptr, 1024}, BufferUsage::StaticDraw);
buffer.setSubData(256 - 16, data);
texture.setBuffer(BufferTextureFormat::R8UI, buffer, 256, 8);
texture.setBuffer(BufferTextureFormat::RGBA8UI, buffer, 256, 8);
MAGNUM_VERIFY_NO_GL_ERROR();
#ifdef MAGNUM_TARGET_GLES
if(!Context::current().isVersionSupported(Version::GLES310))
CORRADE_SKIP("OpenGL ES 3.1 not supported, skipping image size testing.");
#endif
CORRADE_COMPARE(texture.size(), 2);
MAGNUM_VERIFY_NO_GL_ERROR();
}

Loading…
Cancel
Save