Browse Source

Added safety dummy parameter to AbstractTexture::DataHelper::set*Data().

Previously it was possible to pass e.g. one-dimensional image to 3D
texture, now it will be reported by the compiler as error.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
eca97de2fc
  1. 12
      src/AbstractTexture.h
  2. 8
      src/CubeMapTexture.h
  3. 4
      src/Texture.h

12
src/AbstractTexture.h

@ -575,11 +575,11 @@ template<> struct AbstractTexture::DataHelper<1> {
glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast<GLint>(wrapping[0]));
}
template<class T> inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, T* image) {
template<class Image> inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image, const Math::Vector<1, GLsizei>& = Math::Vector<Image::Dimensions, GLsizei>()) {
glTexImage1D(target, mipLevel, internalFormat, image->dimensions()[0], 0, static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
template<class T> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, T* image) {
template<class Image> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image, const Math::Vector<1, GLsizei>& = Math::Vector<Image::Dimensions, GLsizei>()) {
glTexSubImage1D(target, mipLevel, offset[0], image->dimensions()[0], static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
};
@ -594,11 +594,11 @@ template<> struct AbstractTexture::DataHelper<2> {
static void setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping);
template<class T> inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, T* image) {
template<class Image> inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image, const Math::Vector<2, GLsizei>& = Math::Vector<Image::Dimensions, GLsizei>()) {
glTexImage2D(target, mipLevel, internalFormat, image->dimensions()[0], image->dimensions()[1], 0, static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
template<class T> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, T* image) {
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());
}
};
@ -612,11 +612,11 @@ template<> struct AbstractTexture::DataHelper<3> {
static void setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping);
template<class T> inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, T* image) {
template<class Image> inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image, const Math::Vector<3, GLsizei>& = Math::Vector<Image::Dimensions, GLsizei>()) {
glTexImage3D(target, mipLevel, internalFormat, image->dimensions()[0], image->dimensions()[1], image->dimensions()[2], 0, static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
template<class T> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, T* image) {
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());
}
};

8
src/CubeMapTexture.h

@ -83,19 +83,19 @@ class CubeMapTexture: public AbstractTexture {
}
/**
* @copydoc Texture::setData(GLint, InternalFormat, T*)
* @copydoc Texture::setData(GLint, InternalFormat, Image*)
* @param coordinate Coordinate
*/
template<class T> inline void setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, T* image) {
template<class Image> inline void setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) {
bind();
DataHelper<2>::set(static_cast<GLenum>(coordinate), mipLevel, internalFormat, image);
}
/**
* @copydoc Texture::setSubData(GLint, const Math::Vector<Dimensions, GLint>&, T*)
* @copydoc Texture::setSubData(GLint, const Math::Vector<Dimensions, GLint>&, Image*)
* @param coordinate Coordinate
*/
template<class T> inline void setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const T* image) {
template<class Image> inline void setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) {
bind();
DataHelper<2>::setSub(static_cast<GLenum>(coordinate), mipLevel, offset, image);
}

4
src/Texture.h

@ -135,7 +135,7 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
* Sets texture data from given image. The image is not deleted
* afterwards.
*/
template<class T> inline void setData(GLint mipLevel, InternalFormat internalFormat, T* image) {
template<class Image> inline void setData(GLint mipLevel, InternalFormat internalFormat, Image* image) {
bind();
DataHelper<Dimensions>::set(_target, mipLevel, internalFormat, image);
}
@ -150,7 +150,7 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
* Sets texture subdata from given image. The image is not deleted
* afterwards.
*/
template<class T> inline void setSubData(GLint mipLevel, const Math::Vector<Dimensions, GLint>& offset, T* image) {
template<class Image> inline void setSubData(GLint mipLevel, const Math::Vector<Dimensions, GLint>& offset, Image* image) {
bind();
DataHelper<Dimensions>::setSub(_target, mipLevel, offset, image);
}

Loading…
Cancel
Save