From e9a98d76e74593e0c04277caed9e8921bf336255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 5 Dec 2011 16:39:27 +0100 Subject: [PATCH] Support for setting textures as uniforms in AbstractShaderProgram. Also updated Texture documentation. --- src/AbstractShaderProgram.h | 6 ++++++ src/AbstractTexture.h | 3 +++ src/Texture.h | 8 +++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index c72353f1b..e75ceccfa 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -22,6 +22,7 @@ #include #include "Shader.h" +#include "Texture.h" namespace Magnum { @@ -197,6 +198,11 @@ class AbstractShaderProgram { glUniformMatrix4fv(location, 1, GL_FALSE, value.data()); } + /** @copydoc setUniform(GLint, GLint) */ + void setUniform(GLint location, const AbstractTexture* value) { + setUniform(location, value->layer()); + } + private: enum State { Initialized, diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 5bcdb3d99..d1e061f58 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -127,6 +127,9 @@ class AbstractTexture { glDeleteTextures(1, &texture); } + /** @brief Texture layer */ + inline GLint layer() const { return _layer; } + /** @brief Bind texture for usage / rendering */ inline void bind() const { glActiveTexture(GL_TEXTURE0 + _layer); diff --git a/src/Texture.h b/src/Texture.h index 5961d49b1..f92559e18 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -33,9 +33,11 @@ subclassing and setting texture data from e.g. constructor with setData(). setMagnificationFilter() after creating the texture, otherwise it will be unusable. -The texture is bound via bind() and setting texture uniform on the shader to -desired texture layer. In shader, the texture is used via @c sampler1D, -@c sampler2D or @c sampler3D depending on dimension count. +The texture is bound via bind() and setting texture uniform on the shader to the +texture (see AbstractShaderProgram::setUniform(GLint, const AbstractTexture*)). +In shader, the texture is used via @c sampler1D, @c sampler2D or @c sampler3D +depending on dimension count. Note that you can have more than one texture bound +to the shader - the only requirement is to have each texture in another layer. @section RectangleTextures Rectangle textures