From eca97de2fccbb77cbd5b9bbec8b1f1ff7b9988f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 May 2012 18:00:58 +0200 Subject: [PATCH] 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. --- src/AbstractTexture.h | 12 ++++++------ src/CubeMapTexture.h | 8 ++++---- src/Texture.h | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 24bcf854f..6aeb7132d 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -575,11 +575,11 @@ template<> struct AbstractTexture::DataHelper<1> { glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); } - template inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, T* image) { + template inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image, const Math::Vector<1, GLsizei>& = Math::Vector()) { glTexImage1D(target, mipLevel, internalFormat, image->dimensions()[0], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, T* image) { + template inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image, const Math::Vector<1, GLsizei>& = Math::Vector()) { glTexSubImage1D(target, mipLevel, offset[0], image->dimensions()[0], static_cast(image->components()), static_cast(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 inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, T* image) { + template inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image, const Math::Vector<2, GLsizei>& = Math::Vector()) { glTexImage2D(target, mipLevel, internalFormat, image->dimensions()[0], image->dimensions()[1], 0, 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, T* image) { + 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()); } }; @@ -612,11 +612,11 @@ template<> struct AbstractTexture::DataHelper<3> { static void setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping); - template inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, T* image) { + template inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image, const Math::Vector<3, GLsizei>& = Math::Vector()) { glTexImage3D(target, mipLevel, internalFormat, image->dimensions()[0], image->dimensions()[1], image->dimensions()[2], 0, 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, T* image) { + 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()); } }; diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 211356bfe..aedb52a5f 100644 --- a/src/CubeMapTexture.h +++ b/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 inline void setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, T* image) { + template inline void setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) { bind(); DataHelper<2>::set(static_cast(coordinate), mipLevel, internalFormat, image); } /** - * @copydoc Texture::setSubData(GLint, const Math::Vector&, T*) + * @copydoc Texture::setSubData(GLint, const Math::Vector&, Image*) * @param coordinate Coordinate */ - template inline void setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const T* image) { + template inline void setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { bind(); DataHelper<2>::setSub(static_cast(coordinate), mipLevel, offset, image); } diff --git a/src/Texture.h b/src/Texture.h index 2b01e6760..ec1709cf4 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -135,7 +135,7 @@ template class Texture: public AbstractTexture { * Sets texture data from given image. The image is not deleted * afterwards. */ - template inline void setData(GLint mipLevel, InternalFormat internalFormat, T* image) { + template inline void setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { bind(); DataHelper::set(_target, mipLevel, internalFormat, image); } @@ -150,7 +150,7 @@ template class Texture: public AbstractTexture { * Sets texture subdata from given image. The image is not deleted * afterwards. */ - template inline void setSubData(GLint mipLevel, const Math::Vector& offset, T* image) { + template inline void setSubData(GLint mipLevel, const Math::Vector& offset, Image* image) { bind(); DataHelper::setSub(_target, mipLevel, offset, image); }