From 9f7ae0b34ff5cddc0118dafd548850f3691599fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 14 Oct 2012 14:52:45 +0200 Subject: [PATCH] Overloaded AbstractTexture methods in subclasses for better chaining. Allows to conveniently set the data after fully configuring the texture, so OpenGL can optimize the data to match the settings. Advice taken from http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesForWorkingWithTextureData/TechniquesForWorkingWithTextureData.html#//apple_ref/doc/uid/TP40008793-CH104-SW1 --- src/AbstractTexture.h | 3 +++ src/CubeMapTexture.h | 26 ++++++++++++++++++++++++++ src/CubeMapTextureArray.h | 26 ++++++++++++++++++++++++++ src/Texture.h | 26 ++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index c9e4b16ec..f53d7c690 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -63,6 +63,9 @@ To achieve least state changes, fully configure each texture in one run -- method chaining comes in handy -- and try to have often used textures in dedicated layers, not occupied by other textures. +Always fully configure the texture before setting the texture data, so OpenGL +can optimize the data to match your settings. + @todo Add glPixelStore encapsulation @todo Texture copying */ diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index ef5de7806..110214c42 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -109,6 +109,32 @@ class CubeMapTexture: public AbstractTexture { DataHelper<2>::setSub(this, static_cast(coordinate), mipLevel, offset, image); return this; } + + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline CubeMapTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { + AbstractTexture::setMinificationFilter(filter, mipmap); + return this; + } + inline CubeMapTexture* setMagnificationFilter(Filter filter) { + AbstractTexture::setMagnificationFilter(filter); + return this; + } + #ifndef MAGNUM_TARGET_GLES + inline CubeMapTexture* setBorderColor(const Color4& color) { + AbstractTexture::setBorderColor(color); + return this; + } + inline CubeMapTexture* setMaxAnisotropy(GLfloat anisotropy) { + AbstractTexture::setMaxAnisotropy(anisotropy); + return this; + } + #endif + inline CubeMapTexture* generateMipmap() { + AbstractTexture::generateMipmap(); + return this; + } + #endif }; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 0af738bef..165e38e54 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -118,6 +118,32 @@ class CubeMapTextureArray: public AbstractTexture { DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector3(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); return this; } + + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline CubeMapTextureArray* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { + AbstractTexture::setMinificationFilter(filter, mipmap); + return this; + } + inline CubeMapTextureArray* setMagnificationFilter(Filter filter) { + AbstractTexture::setMagnificationFilter(filter); + return this; + } + #ifndef MAGNUM_TARGET_GLES + inline CubeMapTextureArray* setBorderColor(const Color4& color) { + AbstractTexture::setBorderColor(color); + return this; + } + inline CubeMapTextureArray* setMaxAnisotropy(GLfloat anisotropy) { + AbstractTexture::setMaxAnisotropy(anisotropy); + return this; + } + #endif + inline CubeMapTextureArray* generateMipmap() { + AbstractTexture::generateMipmap(); + return this; + } + #endif }; } diff --git a/src/Texture.h b/src/Texture.h index dcbc3a190..0dd5bcf2d 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -188,6 +188,32 @@ template class Texture: public AbstractTexture { DataHelper::setSub(this, _target, mipLevel, offset, image); return this; } + + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline Texture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { + AbstractTexture::setMinificationFilter(filter, mipmap); + return this; + } + inline Texture* setMagnificationFilter(Filter filter) { + AbstractTexture::setMagnificationFilter(filter); + return this; + } + #ifndef MAGNUM_TARGET_GLES + inline Texture* setBorderColor(const Color4& color) { + AbstractTexture::setBorderColor(color); + return this; + } + inline Texture* setMaxAnisotropy(GLfloat anisotropy) { + AbstractTexture::setMaxAnisotropy(anisotropy); + return this; + } + #endif + inline Texture* generateMipmap() { + AbstractTexture::generateMipmap(); + return this; + } + #endif }; #ifndef MAGNUM_TARGET_GLES