From 728ddb19a3294e64feba6b600b8770580e3378fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 May 2012 18:29:50 +0200 Subject: [PATCH] Ability to set texture subdata from image with one less dimensions. It is now possible to call Texture2D::setSubData() with 1D image and Texture3D::setSubData() with 2D image. --- src/AbstractTexture.h | 8 ++++++++ src/Texture.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 6aeb7132d..f48e2ca6d 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -601,6 +601,10 @@ template<> struct AbstractTexture::DataHelper<2> { template inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image, const Math::Vector<2, GLsizei>& = Math::Vector()) { glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->dimensions()[0], image->dimensions()[1], static_cast(image->components()), static_cast(image->type()), image->data()); } + + template inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image, const Math::Vector<1, GLsizei>& = Math::Vector()) { + glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->dimensions()[0], 1, static_cast(image->components()), static_cast(image->type()), image->data()); + } }; template<> struct AbstractTexture::DataHelper<3> { enum class Target: GLenum { @@ -619,6 +623,10 @@ template<> struct AbstractTexture::DataHelper<3> { template inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image, const Math::Vector<3, GLsizei>& = Math::Vector()) { glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->dimensions()[0], image->dimensions()[1], image->dimensions()[2], static_cast(image->components()), static_cast(image->type()), image->data()); } + + template inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image, const Math::Vector<2, GLsizei>& = Math::Vector()) { + glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->dimensions()[0], image->dimensions()[1], 1, static_cast(image->components()), static_cast(image->type()), image->data()); + } }; #endif diff --git a/src/Texture.h b/src/Texture.h index ec1709cf4..644d1300e 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -145,10 +145,16 @@ template class Texture: public AbstractTexture { * @param mipLevel Mip level * @param offset Offset where to put data in the texture * @param image Image, BufferedImage or for example - * Trade::ImageData of the same dimension count + * Trade::ImageData * * Sets texture subdata from given image. The image is not deleted - * afterwards. + * afterwards. The image can have either the same dimension count or + * have one dimension less, but at least one dimension. + * + * If the image has one dimension less than the texture, the image is + * taken as if it had the last dimension equal to 1. It can be used + * for e.g. updating 3D texture with multiple 2D images or for filling + * 1D texture array (which is two-dimensional) with 1D images. */ template inline void setSubData(GLint mipLevel, const Math::Vector& offset, Image* image) { bind();