Browse Source

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.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
728ddb19a3
  1. 8
      src/AbstractTexture.h
  2. 10
      src/Texture.h

8
src/AbstractTexture.h

@ -601,6 +601,10 @@ template<> struct AbstractTexture::DataHelper<2> {
template<class Image> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image, const Math::Vector<2, GLsizei>& = Math::Vector<Image::Dimensions, GLsizei>()) {
glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->dimensions()[0], image->dimensions()[1], static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
template<class Image> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image, const Math::Vector<1, GLsizei>& = Math::Vector<Image::Dimensions, GLsizei>()) {
glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->dimensions()[0], 1, static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
};
template<> struct AbstractTexture::DataHelper<3> {
enum class Target: GLenum {
@ -619,6 +623,10 @@ template<> struct AbstractTexture::DataHelper<3> {
template<class Image> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image, const Math::Vector<3, GLsizei>& = Math::Vector<Image::Dimensions, GLsizei>()) {
glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->dimensions()[0], image->dimensions()[1], image->dimensions()[2], static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
template<class Image> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image, const Math::Vector<2, GLsizei>& = Math::Vector<Image::Dimensions, GLsizei>()) {
glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->dimensions()[0], image->dimensions()[1], 1, static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
};
#endif

10
src/Texture.h

@ -145,10 +145,16 @@ template<size_t textureDimensions> 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<class Image> inline void setSubData(GLint mipLevel, const Math::Vector<Dimensions, GLint>& offset, Image* image) {
bind();

Loading…
Cancel
Save