From dbc029e18ed3d4bb2160dbb68028cccb286127ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 28 Aug 2019 11:04:24 +0200 Subject: [PATCH] GL: added BufferTexture::size(). Why the heck was it not here? Did I fear GL errors too much? --- doc/changelog.dox | 3 ++- doc/opengl-mapping.dox | 2 +- src/Magnum/GL/BufferTexture.cpp | 8 ++++++++ src/Magnum/GL/BufferTexture.h | 17 +++++++++++++++++ src/Magnum/GL/Test/BufferTextureGLTest.cpp | 22 ++++++++++++++++++++-- 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 572bc78cd..964a559a8 100644 --- a/doc/changelog.dox +++ b/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 diff --git a/doc/opengl-mapping.dox b/doc/opengl-mapping.dox index 35990b682..653cfe379 100644 --- a/doc/opengl-mapping.dox +++ b/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} | | diff --git a/src/Magnum/GL/BufferTexture.cpp b/src/Magnum/GL/BufferTexture.cpp index 93c638792..c33af0b76 100644 --- a/src/Magnum/GL/BufferTexture.cpp +++ b/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; diff --git a/src/Magnum/GL/BufferTexture.h b/src/Magnum/GL/BufferTexture.h index 88f6ccdcd..793e56b42 100644 --- a/src/Magnum/GL/BufferTexture.h +++ b/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 diff --git a/src/Magnum/GL/Test/BufferTextureGLTest.cpp b/src/Magnum/GL/Test/BufferTextureGLTest.cpp index d69b2ca8e..e1805ab13 100644 --- a/src/Magnum/GL/Test/BufferTextureGLTest.cpp +++ b/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(); }