From f3a07f82f4a67c66d234b2b9a1d868a00d68ca77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 03:07:01 +0200 Subject: [PATCH] Method chaining for textures. --- src/AbstractTexture.cpp | 10 ++++++---- src/AbstractTexture.h | 18 +++++++++++++----- src/CubeMapTexture.h | 11 ++++++++--- src/CubeMapTextureArray.h | 14 ++++++++++---- src/Texture.h | 12 +++++++++--- 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index fdce8c9ea..8def7f62b 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -48,23 +48,25 @@ GLfloat AbstractTexture::maxSupportedAnisotropy() { } #endif -void AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { +AbstractTexture* AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", ); + CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", this); #endif bind(); glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, static_cast(filter)|static_cast(mipmap)); + return this; } -void AbstractTexture::generateMipmap() { +AbstractTexture* AbstractTexture::generateMipmap() { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", ); + CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", this); #endif bind(); glGenerateMipmap(_target); + return this; } #ifndef MAGNUM_TARGET_GLES diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 5dd213d17..c3dec918a 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -587,6 +587,7 @@ class MAGNUM_EXPORT AbstractTexture { * @param mipmap Mipmap filtering. If set to anything else than * BaseMipLevel, make sure textures for all mip levels are set or * call generateMipmap(). + * @return Pointer to self (for method chaining) * * Sets filter used when the object pixel size is smaller than the * texture size. @@ -595,55 +596,62 @@ class MAGNUM_EXPORT AbstractTexture { * @ref AbstractTexture::Mipmap "Mipmap" documentation for more * information. */ - void setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel); + AbstractTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel); /** * @brief Set magnification filter * @param filter Filter + * @return Pointer to self (for method chaining) * * Sets filter used when the object pixel size is larger than largest * texture size. */ - inline void setMagnificationFilter(Filter filter) { + inline AbstractTexture* setMagnificationFilter(Filter filter) { bind(); glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, static_cast(filter)); + return this; } #ifndef MAGNUM_TARGET_GLES /** * @brief Set border color + * @return Pointer to self (for method chaining) * * Border color when @ref AbstractTexture::Wrapping "wrapping" is set * to `ClampToBorder`. * @requires_gl */ - inline void setBorderColor(const Color4& color) { + inline AbstractTexture* setBorderColor(const Color4& color) { bind(); glTexParameterfv(_target, GL_TEXTURE_BORDER_COLOR, color.data()); + return this; } /** * @brief Set max anisotropy + * @return Pointer to self (for method chaining) * * Default value is `1.0`, which means no anisotropy. Set to value * greater than `1.0` for anisotropic filtering. * @see maxSupportedAnisotropy() * @requires_extension @extension{EXT,texture_filter_anisotropic} */ - inline void setMaxAnisotropy(GLfloat anisotropy) { + inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) { bind(); glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); + return this; } #endif /** * @brief Generate mipmap + * @return Pointer to self (for method chaining) * * Can not be used for rectangle textures. * @see setMinificationFilter() * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - void generateMipmap(); + AbstractTexture* generateMipmap(); protected: #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 44ae71fce..9ce2ae96d 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -81,27 +81,32 @@ class CubeMapTexture: public AbstractTexture { /** * @copydoc Texture::setWrapping() */ - inline void setWrapping(const Math::Vector<3, Wrapping>& wrapping) { + inline CubeMapTexture* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { bind(); DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP, wrapping); + return this; } /** * @copydoc Texture::setData(GLint, InternalFormat, Image*) * @param coordinate Coordinate + * @return Pointer to self (for method chaining) */ - template inline void setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) { + template inline CubeMapTexture* setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) { bind(); DataHelper<2>::set(static_cast(coordinate), mipLevel, internalFormat, image); + return this; } /** * @copydoc Texture::setSubData(GLint, const Math::Vector&, Image*) * @param coordinate Coordinate + * @return Pointer to self (for method chaining) */ - template inline void setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { + template inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { bind(); DataHelper<2>::setSub(static_cast(coordinate), mipLevel, offset, image); + return this; } }; diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 0a1f0ebca..2f5801147 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -66,9 +66,10 @@ class CubeMapTextureArray: public AbstractTexture { /** * @copydoc Texture::setWrapping() */ - inline void setWrapping(const Math::Vector<3, Wrapping>& wrapping) { + inline CubeMapTextureArray* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { bind(); DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP_ARRAY, wrapping); + return this; } /** @@ -78,9 +79,10 @@ class CubeMapTextureArray: public AbstractTexture { * for all layers. Each group of 6 2D images is one cube map layer. * The images are ordered the same way as Coordinate enum. */ - template inline void setData(GLint mipLevel, InternalFormat internalFormat, T* image) { + template inline CubeMapTextureArray* setData(GLint mipLevel, InternalFormat internalFormat, T* image) { bind(); DataHelper<3>::set(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image); + return this; } /** @@ -89,6 +91,7 @@ class CubeMapTextureArray: public AbstractTexture { * @param offset Offset where to put data in the texture * @param image Three-dimensional Image, BufferedImage or for * example Trade::ImageData + * @return Pointer to self (for method chaining) * * Sets texture subdata from given image. The image is not deleted * afterwards. @@ -100,9 +103,10 @@ class CubeMapTextureArray: public AbstractTexture { * * @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) */ - template inline void setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) { + template inline CubeMapTextureArray* setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) { bind(); DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector())); + return this; } /** @@ -113,15 +117,17 @@ class CubeMapTextureArray: public AbstractTexture { * @param offset Offset where to put data in the texture * @param image Two-dimensional Image, BufferedImage or for * example Trade::ImageData + * @return Pointer to self (for method chaining) * * Sets texture subdata from given image. The image is not deleted * afterwards. * * @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*) */ - template inline void setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { + template inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { bind(); 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())); + return this; } }; diff --git a/src/Texture.h b/src/Texture.h index d31d2039b..61f1013b3 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -114,6 +114,7 @@ template class Texture: public AbstractTexture { /** * @brief Set wrapping * @param wrapping Wrapping type for all texture dimensions + * @return Pointer to self (for method chaining) * * Sets wrapping type for coordinates out of range (0, 1) for normal * textures and (0, textureSizeInGivenDirection-1) for rectangle @@ -122,9 +123,10 @@ template class Texture: public AbstractTexture { * see @ref AbstractTexture::Wrapping "Wrapping" documentation for * more information. */ - inline void setWrapping(const Math::Vector& wrapping) { + inline Texture* setWrapping(const Math::Vector& wrapping) { bind(); DataHelper::setWrapping(_target, wrapping); + return this; } /** @@ -133,13 +135,15 @@ template class Texture: public AbstractTexture { * @param internalFormat Internal texture format * @param image Image, BufferedImage or for example * Trade::ImageData of the same dimension count + * @return Pointer to self (for method chaining) * * Sets texture data from given image. The image is not deleted * afterwards. */ - template inline void setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { + template inline Texture* setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { bind(); DataHelper::set(_target, mipLevel, internalFormat, image); + return this; } /** @@ -148,6 +152,7 @@ template class Texture: public AbstractTexture { * @param offset Offset where to put data in the texture * @param image Image, BufferedImage or for example * Trade::ImageData + * @return Pointer to self (for method chaining) * * Sets texture subdata from given image. The image is not deleted * afterwards. The image can have either the same dimension count or @@ -158,9 +163,10 @@ template class Texture: public AbstractTexture { * for e.g. updating 3D texture with multiple 2D images or for filling * 1D texture array (which is two-dimensional) with 1D images. */ - template inline void setSubData(GLint mipLevel, const Math::Vector& offset, Image* image) { + template inline Texture* setSubData(GLint mipLevel, const Math::Vector& offset, Image* image) { bind(); DataHelper::setSub(_target, mipLevel, offset, image); + return this; } };