From 1f3c360cb288836dc24dd4cb6d8ab5f9562d8f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 14 Oct 2012 01:15:16 +0200 Subject: [PATCH] Using bindInternal() directly in AbstractTexture::DataHelper. --- src/AbstractTexture.cpp | 18 ++++++++++-------- src/AbstractTexture.h | 33 +++++++++++++++++++++------------ src/CubeMapTexture.h | 9 +++------ src/CubeMapTextureArray.h | 12 ++++-------- src/Texture.h | 9 +++------ 5 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index a2b5f3e1f..0822455e0 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -189,20 +189,22 @@ AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components comp } #ifndef DOXYGEN_GENERATING_OUTPUT -void AbstractTexture::DataHelper<2>::setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping) { +void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Math::Vector<2, Wrapping>& wrapping) { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(target != GL_TEXTURE_RECTANGLE || ((wrapping[0] == Wrapping::ClampToEdge || wrapping[0] == Wrapping::ClampToBorder) && (wrapping[0] == Wrapping::ClampToEdge || wrapping[1] == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); + CORRADE_ASSERT(texture->_target != GL_TEXTURE_RECTANGLE || ((wrapping[0] == Wrapping::ClampToEdge || wrapping[0] == Wrapping::ClampToBorder) && (wrapping[0] == Wrapping::ClampToEdge || wrapping[1] == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); #endif - glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); - glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast(wrapping[1])); + texture->bindInternal(); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_T, static_cast(wrapping[1])); } -void AbstractTexture::DataHelper<3>::setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping) { - glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); - glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast(wrapping[1])); +void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture* texture, const Math::Vector<3, Wrapping>& wrapping) { + texture->bindInternal(); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_T, static_cast(wrapping[1])); #ifndef MAGNUM_TARGET_GLES - glTexParameteri(target, GL_TEXTURE_WRAP_R, static_cast(wrapping[2])); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_R, static_cast(wrapping[2])); #endif } #endif diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 075372add..a0ad2e615 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -714,15 +714,18 @@ template<> struct AbstractTexture::DataHelper<1> { inline constexpr static Target target() { return Target::Texture1D; } - inline static void setWrapping(GLenum target, const Math::Vector<1, Wrapping>& wrapping) { - glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); + inline static void setWrapping(AbstractTexture* texture, const Math::Vector<1, Wrapping>& wrapping) { + texture->bindInternal(); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); } - template inline static typename std::enable_if::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + texture->bindInternal(); glTexImage1D(target, mipLevel, internalFormat, image->size()[0], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image) { + texture->bindInternal(); glTexSubImage1D(target, mipLevel, offset[0], image->size()[0], static_cast(image->components()), static_cast(image->type()), image->data()); } }; @@ -739,17 +742,20 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { inline constexpr static Target target() { return Target::Texture2D; } - static void setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping); + static void setWrapping(AbstractTexture* texture, const Math::Vector<2, Wrapping>& wrapping); - template inline static typename std::enable_if::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + texture->bindInternal(); glTexImage2D(target, mipLevel, internalFormat, image->size()[0], image->size()[1], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { + texture->bindInternal(); glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->size()[0], image->size()[1], static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { + texture->bindInternal(); glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->size()[0], 1, static_cast(image->components()), static_cast(image->type()), image->data()); } }; @@ -761,17 +767,20 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { inline constexpr static Target target() { return Target::Texture3D; } - static void setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping); + static void setWrapping(AbstractTexture* texture, const Math::Vector<3, Wrapping>& wrapping); - template inline static typename std::enable_if::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + texture->bindInternal(); glTexImage3D(target, mipLevel, internalFormat, image->size()[0], image->size()[1], image->size()[2], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { + texture->bindInternal(); glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->size()[0], image->size()[1], image->size()[2], static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { + texture->bindInternal(); glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->size()[0], image->size()[1], 1, static_cast(image->components()), static_cast(image->type()), image->data()); } }; diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index a6d1c170f..e94df7529 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -86,8 +86,7 @@ class CubeMapTexture: public AbstractTexture { * @copydoc Texture::setWrapping() */ inline CubeMapTexture* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { - bindInternal(); - DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP, wrapping); + DataHelper<3>::setWrapping(this, wrapping); return this; } @@ -97,8 +96,7 @@ class CubeMapTexture: public AbstractTexture { * @return Pointer to self (for method chaining) */ template inline CubeMapTexture* setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) { - bindInternal(); - DataHelper<2>::set(static_cast(coordinate), mipLevel, internalFormat, image); + DataHelper<2>::set(this, static_cast(coordinate), mipLevel, internalFormat, image); return this; } @@ -108,8 +106,7 @@ class CubeMapTexture: public AbstractTexture { * @return Pointer to self (for method chaining) */ template inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { - bindInternal(); - DataHelper<2>::setSub(static_cast(coordinate), mipLevel, offset, image); + DataHelper<2>::setSub(this, static_cast(coordinate), mipLevel, offset, image); return this; } }; diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 50689e746..00fb98a04 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -60,8 +60,7 @@ class CubeMapTextureArray: public AbstractTexture { * @copydoc Texture::setWrapping() */ inline CubeMapTextureArray* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { - bindInternal(); - DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP_ARRAY, wrapping); + DataHelper<3>::setWrapping(this, wrapping); return this; } @@ -73,8 +72,7 @@ class CubeMapTextureArray: public AbstractTexture { * The images are ordered the same way as Coordinate enum. */ template inline CubeMapTextureArray* setData(GLint mipLevel, InternalFormat internalFormat, T* image) { - bindInternal(); - DataHelper<3>::set(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image); + DataHelper<3>::set(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image); return this; } @@ -97,8 +95,7 @@ class CubeMapTextureArray: public AbstractTexture { * @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) */ template inline CubeMapTextureArray* setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) { - bindInternal(); - DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector())); + DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector())); return this; } @@ -118,8 +115,7 @@ class CubeMapTextureArray: public AbstractTexture { * @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*) */ template inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { - bindInternal(); - DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector<3, GLint>(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); + DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector<3, GLint>(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); return this; } }; diff --git a/src/Texture.h b/src/Texture.h index ff3454151..417b85ec9 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -130,8 +130,7 @@ template class Texture: public AbstractTexture { * that can easily create all values the same) */ inline Texture* setWrapping(const Math::Vector& wrapping) { - bindInternal(); - DataHelper::setWrapping(_target, wrapping); + DataHelper::setWrapping(this, wrapping); return this; } @@ -148,8 +147,7 @@ template class Texture: public AbstractTexture { * @see bind(), @fn_gl{TexImage1D}, @fn_gl{TexImage2D}, @fn_gl{TexImage3D} */ template inline Texture* setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { - bindInternal(); - DataHelper::set(_target, mipLevel, internalFormat, image); + DataHelper::set(this, _target, mipLevel, internalFormat, image); return this; } @@ -172,8 +170,7 @@ template class Texture: public AbstractTexture { * @see bind(), @fn_gl{TexSubImage1D}, @fn_gl{TexSubImage2D}, @fn_gl{TexSubImage3D} */ template inline Texture* setSubData(GLint mipLevel, const typename DimensionTraits::VectorType& offset, Image* image) { - bindInternal(); - DataHelper::setSub(_target, mipLevel, offset, image); + DataHelper::setSub(this, _target, mipLevel, offset, image); return this; } };