Browse Source

Support for setting textures as uniforms in AbstractShaderProgram.

Also updated Texture documentation.
pull/279/head
Vladimír Vondruš 15 years ago
parent
commit
e9a98d76e7
  1. 6
      src/AbstractShaderProgram.h
  2. 3
      src/AbstractTexture.h
  3. 8
      src/Texture.h

6
src/AbstractShaderProgram.h

@ -22,6 +22,7 @@
#include <map> #include <map>
#include "Shader.h" #include "Shader.h"
#include "Texture.h"
namespace Magnum { namespace Magnum {
@ -197,6 +198,11 @@ class AbstractShaderProgram {
glUniformMatrix4fv(location, 1, GL_FALSE, value.data()); glUniformMatrix4fv(location, 1, GL_FALSE, value.data());
} }
/** @copydoc setUniform(GLint, GLint) */
void setUniform(GLint location, const AbstractTexture* value) {
setUniform(location, value->layer());
}
private: private:
enum State { enum State {
Initialized, Initialized,

3
src/AbstractTexture.h

@ -127,6 +127,9 @@ class AbstractTexture {
glDeleteTextures(1, &texture); glDeleteTextures(1, &texture);
} }
/** @brief Texture layer */
inline GLint layer() const { return _layer; }
/** @brief Bind texture for usage / rendering */ /** @brief Bind texture for usage / rendering */
inline void bind() const { inline void bind() const {
glActiveTexture(GL_TEXTURE0 + _layer); glActiveTexture(GL_TEXTURE0 + _layer);

8
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 setMagnificationFilter() after creating the texture, otherwise it will be
unusable. unusable.
The texture is bound via bind() and setting texture uniform on the shader to The texture is bound via bind() and setting texture uniform on the shader to the
desired texture layer. In shader, the texture is used via @c sampler1D, texture (see AbstractShaderProgram::setUniform(GLint, const AbstractTexture*)).
@c sampler2D or @c sampler3D depending on dimension count. 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 @section RectangleTextures Rectangle textures

Loading…
Cancel
Save