Browse Source

Support for setting textures as uniforms in AbstractShaderProgram.

Also updated Texture documentation.
vectorfields
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 "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,

3
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);

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
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

Loading…
Cancel
Save