From 40441b39e2de148acf8e455cff39c4c2c09e47bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 10 Dec 2011 02:06:07 +0100 Subject: [PATCH] Removed unnecessary templating of AbstractTexture::DataHelper. --- src/AbstractTexture.h | 38 ++++++++++++++++++-------------------- src/CubeMapTexture.h | 32 ++++++++++++++++---------------- src/Texture.h | 4 ++-- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index d38f03faa..fa778a169 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -222,15 +222,14 @@ class AbstractTexture { * @param mipLevel Mip level * @param internalFormat Internal texture format * @param dimensions %Texture dimensions - * @param colorFormat Color format of passed data. Data size - * per color channel is detected from format of passed data - * array. + * @param colorFormat Color format of passed data + * @param type Data type * @param data %Texture data * * Calls @c glTexImage1D, @c glTexImage2D, @c glTexImage3D depending * on dimension count. */ - template inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data); + inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, GLenum type, const void* data); /** * @brief Set texture subdata @@ -238,15 +237,14 @@ class AbstractTexture { * @param mipLevel Mip level * @param offset Offset where to put data in the texture * @param dimensions %Texture dimensions - * @param colorFormat Color format of passed data. Data size - * per color channel is detected from format of passed data - * array. + * @param colorFormat Color format of passed data + * @param type Data type * @param data %Texture data * * Calls @c glTexSubImage1D, @c glTexSubImage2D, @c glTexSubImage3D * depending on dimension count. */ - template inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector& offset, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data); + inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector& offset, const Math::Vector& dimensions, ColorFormat colorFormat, GLenum type, const void* data); #endif }; @@ -259,34 +257,34 @@ class AbstractTexture { template<> struct AbstractTexture::DataHelper<1> { inline constexpr static GLenum target() { return GL_TEXTURE_1D; } - template inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { - glTexImage1D(target, mipLevel, static_cast(internalFormat), dimensions.at(0), 0, static_cast(colorFormat), TypeTraits::glType(), data); + inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, GLenum type, const void* data) { + glTexImage1D(target, mipLevel, static_cast(internalFormat), dimensions.at(0), 0, static_cast(colorFormat), type, data); } - template inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector& offset, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { - glTexSubImage1D(target, mipLevel, offset.at(0), dimensions.at(0), static_cast(colorFormat), TypeTraits::glType(), data); + inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector& offset, const Math::Vector& dimensions, ColorFormat colorFormat, GLenum type, const void* data) { + glTexSubImage1D(target, mipLevel, offset.at(0), dimensions.at(0), static_cast(colorFormat), type, data); } }; template<> struct AbstractTexture::DataHelper<2> { inline constexpr static GLenum target() { return GL_TEXTURE_2D; } - template inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { - glTexImage2D(target, mipLevel, static_cast(internalFormat), dimensions.at(0), dimensions.at(1), 0, static_cast(colorFormat), TypeTraits::glType(), data); + inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, GLenum type, const void* data) { + glTexImage2D(target, mipLevel, static_cast(internalFormat), dimensions.at(0), dimensions.at(1), 0, static_cast(colorFormat), type, data); } - template inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector& offset, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { - glTexSubImage2D(target, mipLevel, offset.at(0), offset.at(1), dimensions.at(0), dimensions.at(1), static_cast(colorFormat), TypeTraits::glType(), data); + inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector& offset, const Math::Vector& dimensions, ColorFormat colorFormat, GLenum type, const void* data) { + glTexSubImage2D(target, mipLevel, offset.at(0), offset.at(1), dimensions.at(0), dimensions.at(1), static_cast(colorFormat), type, data); } }; template<> struct AbstractTexture::DataHelper<3> { inline constexpr static GLenum target() { return GL_TEXTURE_3D; } - template inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { - glTexImage3D(target, mipLevel, static_cast(internalFormat), dimensions.at(0), dimensions.at(1), dimensions.at(2), 0, static_cast(colorFormat), TypeTraits::glType(), data); + inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, GLenum type, const void* data) { + glTexImage3D(target, mipLevel, static_cast(internalFormat), dimensions.at(0), dimensions.at(1), dimensions.at(2), 0, static_cast(colorFormat), type, data); } - template inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector& offset, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { - glTexSubImage3D(target, mipLevel, offset.at(0), offset.at(1), offset.at(2), dimensions.at(0), dimensions.at(1), dimensions.at(2), static_cast(colorFormat), TypeTraits::glType(), data); + inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector& offset, const Math::Vector& dimensions, ColorFormat colorFormat, GLenum type, const void* data) { + glTexSubImage3D(target, mipLevel, offset.at(0), offset.at(1), offset.at(2), dimensions.at(0), dimensions.at(1), dimensions.at(2), static_cast(colorFormat), type, data); } }; #endif diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index de46487f0..36fb462dd 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -67,7 +67,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setData() */ template inline void setDataPositiveX(GLint mipLevel, InternalFormat internalFormat, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setData(GL_TEXTURE_CUBE_MAP_POSITIVE_X, mipLevel, internalFormat, _dimensions, colorFormat, data); + setData(GL_TEXTURE_CUBE_MAP_POSITIVE_X, mipLevel, internalFormat, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -76,7 +76,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setSubData() */ template inline void setSubDataPositiveX(GLint mipLevel, const Math::Vector& offset, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setSubData(GL_TEXTURE_CUBE_MAP_POSITIVE_X, mipLevel, offset, _dimensions, colorFormat, data); + setSubData(GL_TEXTURE_CUBE_MAP_POSITIVE_X, mipLevel, offset, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -85,7 +85,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setData() */ template inline void setDataNegativeX(GLint mipLevel, InternalFormat internalFormat, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setData(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, mipLevel, internalFormat, _dimensions, colorFormat, data); + setData(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, mipLevel, internalFormat, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -94,7 +94,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setSubData() */ template inline void setSubDataNegativeX(GLint mipLevel, const Math::Vector& offset, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setSubData(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, mipLevel, offset, _dimensions, colorFormat, data); + setSubData(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, mipLevel, offset, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -103,7 +103,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setData() */ template inline void setDataPositiveY(GLint mipLevel, InternalFormat internalFormat, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setData(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mipLevel, internalFormat, _dimensions, colorFormat, data); + setData(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mipLevel, internalFormat, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -112,7 +112,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setSubData() */ template inline void setSubDataPositiveY(GLint mipLevel, const Math::Vector& offset, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setSubData(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mipLevel, offset, _dimensions, colorFormat, data); + setSubData(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mipLevel, offset, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -121,7 +121,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setData() */ template inline void setDataNegativeY(GLint mipLevel, InternalFormat internalFormat, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setData(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, mipLevel, internalFormat, _dimensions, colorFormat, data); + setData(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, mipLevel, internalFormat, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -130,7 +130,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setSubData() */ template inline void setSubDataNegativeY(GLint mipLevel, const Math::Vector& offset, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setSubData(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, mipLevel, offset, _dimensions, colorFormat, data); + setSubData(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, mipLevel, offset, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -139,7 +139,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setData() */ template inline void setDataPositiveZ(GLint mipLevel, InternalFormat internalFormat, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setData(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, mipLevel, internalFormat, _dimensions, colorFormat, data); + setData(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, mipLevel, internalFormat, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -148,7 +148,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setSubData() */ template inline void setSubDataPositiveZ(GLint mipLevel, const Math::Vector& offset, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setSubData(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, mipLevel, offset, _dimensions, colorFormat, data); + setSubData(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, mipLevel, offset, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -157,7 +157,7 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setData() */ template inline void setDataNegativeZ(GLint mipLevel, InternalFormat internalFormat, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setData(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, mipLevel, internalFormat, _dimensions, colorFormat, data); + setData(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, mipLevel, internalFormat, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } /** @@ -166,19 +166,19 @@ class CubeMapTexture: public Texture2D { * @copydetails Texture::setSubData() */ template inline void setSubDataNegativeZ(GLint mipLevel, const Math::Vector& offset, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { - setSubData(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, mipLevel, offset, _dimensions, colorFormat, data); + setSubData(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, mipLevel, offset, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); } private: - template void setData(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { + void setData(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& _dimensions, ColorFormat colorFormat, GLenum type, const void* data) { bind(); - DataHelper::template set::TextureType>(target, mipLevel, internalFormat, _dimensions, colorFormat, data); + DataHelper::set(target, mipLevel, internalFormat, _dimensions, colorFormat, type, data); unbind(); } - template void setSubData(GLenum target, GLint mipLevel, const Math::Vector& offset, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { + void setSubData(GLenum target, GLint mipLevel, const Math::Vector& offset, const Math::Vector& dimensions, ColorFormat colorFormat, GLenum type, const void* data) { bind(); - DataHelper::template setSub::TextureType>(target, mipLevel, dimensions, colorFormat, data); + DataHelper::setSub(target, mipLevel, offset, dimensions, colorFormat, type, data); unbind(); } }; diff --git a/src/Texture.h b/src/Texture.h index 2e1054ebc..d6d44ae5c 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -87,7 +87,7 @@ template class Texture: public AbstractTexture { */ template inline void setData(GLint mipLevel, InternalFormat internalFormat, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { bind(); - DataHelper::template set::TextureType>(target, mipLevel, internalFormat, _dimensions, colorFormat, data); + DataHelper::set(target, mipLevel, internalFormat, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); unbind(); } @@ -102,7 +102,7 @@ template class Texture: public AbstractTexture { */ template inline void setSubData(GLint mipLevel, const Math::Vector& offset, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { bind(); - DataHelper::template setSub::TextureType>(target, mipLevel, offset, _dimensions, colorFormat, data); + DataHelper::setSub(target, mipLevel, offset, _dimensions, colorFormat, TypeTraits::TextureType>::glType(), data); unbind(); } };