From 11b2247bf57501fb52202a7d4da68c67cef3febc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 8 Feb 2015 13:26:20 +0100 Subject: [PATCH] Clarified and fixed cube map texture image retrieval methods. Because ARB_DSA doesn't have any way to extract image of single cube map coordinate, we have to use ARB_get_texture_sub_image instead, thus for cube maps the whole thing is different. That was implemented, but wasn't mentioned in the docs and wasn't properly accounted for in implementation switcher (I was under assumption that ARB_DSA is equivalent to ARB_get_texture_sub_image, which is not). --- src/Magnum/CubeMapTexture.h | 29 ++++++++++++++++++---- src/Magnum/Implementation/TextureState.cpp | 22 ++++++++++------ src/Magnum/Texture.h | 3 ++- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/Magnum/CubeMapTexture.h b/src/Magnum/CubeMapTexture.h index 7c6964f48..889f91c78 100644 --- a/src/Magnum/CubeMapTexture.h +++ b/src/Magnum/CubeMapTexture.h @@ -379,9 +379,29 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture { #ifndef MAGNUM_TARGET_GLES /** - * @copybrief Texture::image(Int, Image&) + * @brief Read given mip level and coordinate of texture to image * - * See @ref Texture::image(Int, Image&) for more information. + * Image parameters like format and type of pixel data are taken from + * given image, image size is taken from the texture using + * @ref imageSize(). + * + * If neither @extension{ARB,get_texture_sub_image} (part of OpenGL + * 4.5) nor @extension{EXT,direct_state_access} is available, the + * texture is bound before the operation (if not already). If either + * @extension{ARB,get_texture_sub_image} or @extension{ARB,robustness} + * is available, the operation is protected from buffer overflow. + * However, if @extension{ARB,get_texture_sub_image} is not available + * and both @extension{EXT,direct_state_access} and + * @extension{ARB,robustness} are available, the robust operation is + * preferred over DSA. + * @see @fn_gl2{GetTextureLevelParameter,GetTexLevelParameter}, + * @fn_gl_extension{GetTextureLevelParameter,EXT,direct_state_access}, + * eventually @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @fn_gl{GetTexLevelParameter} with @def_gl{TEXTURE_WIDTH}, + * @def_gl{TEXTURE_HEIGHT}, then @fn_gl{GetTextureSubImage}, + * @fn_gl_extension{GetnTexImage,ARB,robustness}, + * @fn_gl_extension{GetTextureImage,EXT,direct_state_access}, + * eventually @fn_gl{GetTexImage} * @requires_gl Texture image queries are not available in OpenGL ES. */ void image(Coordinate coordinate, Int level, Image2D& image); @@ -396,10 +416,9 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture { Image2D image(Coordinate coordinate, Int level, Image2D&& image); /** - * @copybrief Texture::image(Int, BufferImage&, BufferUsage) + * @brief Read given mip level and coordinate of texture to buffer image * - * See @ref Texture::image(Int, BufferImage&, BufferUsage) for more - * information. + * See @ref image(Coordinate, Int, Image2D&) for more information. * @requires_gl Texture image queries are not available in OpenGL ES. */ void image(Coordinate coordinate, Int level, BufferImage2D& image, BufferUsage usage); diff --git a/src/Magnum/Implementation/TextureState.cpp b/src/Magnum/Implementation/TextureState.cpp index 2cb0512ee..6be17e387 100644 --- a/src/Magnum/Implementation/TextureState.cpp +++ b/src/Magnum/Implementation/TextureState.cpp @@ -205,23 +205,31 @@ TextureState::TextureState(Context& context, std::vector& extension if(context.isExtensionSupported()) { /* Extension name added above */ getImageImplementation = &AbstractTexture::getImageImplementationDSA; - getCubeImageImplementation = &CubeMapTexture::getImageImplementationDSA; } else if(context.isExtensionSupported()) { extensions.push_back(Extensions::GL::ARB::robustness::string()); - getImageImplementation = &AbstractTexture::getImageImplementationRobustness; - getCubeImageImplementation = &CubeMapTexture::getImageImplementationRobustness; } else if(context.isExtensionSupported()) { /* Extension name added above */ getImageImplementation = &AbstractTexture::getImageImplementationDSAEXT; + + } else getImageImplementation = &AbstractTexture::getImageImplementationDefault; + + /* Image retrieval implementation for cube map */ + if(context.isExtensionSupported()) { + extensions.push_back(Extensions::GL::ARB::get_texture_sub_image::string()); + getCubeImageImplementation = &CubeMapTexture::getImageImplementationDSA; + + } else if(context.isExtensionSupported()) { + /* Extension name added above */ + getCubeImageImplementation = &CubeMapTexture::getImageImplementationRobustness; + + } else if(context.isExtensionSupported()) { + /* Extension name added above */ getCubeImageImplementation = &CubeMapTexture::getImageImplementationDSAEXT; - } else { - getImageImplementation = &AbstractTexture::getImageImplementationDefault; - getCubeImageImplementation = &CubeMapTexture::getImageImplementationDefault; - } + } else getCubeImageImplementation = &CubeMapTexture::getImageImplementationDefault; #endif /* Texture storage implementation */ diff --git a/src/Magnum/Texture.h b/src/Magnum/Texture.h index 65fa4dfba..7f60bc445 100644 --- a/src/Magnum/Texture.h +++ b/src/Magnum/Texture.h @@ -645,8 +645,9 @@ template class Texture: public AbstractTexture { * @fn_gl{GetTexLevelParameter} with @def_gl{TEXTURE_WIDTH}, * @def_gl{TEXTURE_HEIGHT}, @def_gl{TEXTURE_DEPTH}, then * @fn_gl2{GetTextureImage,GetTexImage}, - * @fn_gl_extension{GetnTexImage,ARB,robustness} or + * @fn_gl_extension{GetnTexImage,ARB,robustness}, * @fn_gl_extension{GetTextureImage,EXT,direct_state_access}, + * eventually @fn_gl{GetTexImage} * @requires_gl Texture image queries are not available in OpenGL ES. */ void image(Int level, Image& image) {