Browse Source

Updated and simplified AbstractShaderProgram documentation.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
b97e6f8bce
  1. 47
      src/AbstractShaderProgram.h

47
src/AbstractShaderProgram.h

@ -63,8 +63,8 @@ static const GLint SpecularTextureLayer = 1;
- **Uniform locations** for setting uniform data (see below) (private - **Uniform locations** for setting uniform data (see below) (private
constants), for example: constants), for example:
@code @code
static const GLint TransformationMatrixUniform = 0; static const GLint TransformationUniform = 0;
static const GLint ProjectionMatrixUniform = 1; static const GLint ProjectionUniform = 1;
static const GLint DiffuseTextureUniform = 2; static const GLint DiffuseTextureUniform = 2;
static const GLint SpecularTextureUniform = 3; static const GLint SpecularTextureUniform = 3;
@endcode @endcode
@ -81,13 +81,16 @@ MyShader() {
} }
@endcode @endcode
- **Uniform setting functions**, which will provide public interface for - **Uniform setting functions**, which will provide public interface for
protected setUniform() functions. Example: protected setUniform() functions. For usability purposes you can implement
also method chaining. Example:
@code @code
void setTransformationMatrixUniform(const Matrix4& matrix) { MyShader* setTransformation(const Matrix4& matrix) {
setUniform(TransformationMatrixUniform, matrix); setUniform(TransformationUniform, matrix);
return this;
} }
void setProjectionMatrixUniform(const Matrix4& matrix) { MyShader* setProjection(const Matrix4& matrix) {
setUniform(ProjectionMatrixUniform, matrix); setUniform(ProjectionUniform, matrix);
return this;
} }
@endcode @endcode
@ -144,8 +147,8 @@ code, e.g.:
@code @code
#version 430 #version 430
// or #extension GL_ARB_explicit_uniform_location: enable // or #extension GL_ARB_explicit_uniform_location: enable
layout(location = 0) uniform mat4 transformationMatrix; layout(location = 0) uniform mat4 transformation;
layout(location = 1) uniform mat4 projectionMatrix; layout(location = 1) uniform mat4 projection;
@endcode @endcode
@requires_gl (for explicit uniform location instead of using uniformLocation()) @requires_gl (for explicit uniform location instead of using uniformLocation())
@requires_gl43 Extension @extension{ARB,explicit_uniform_location} (for @requires_gl43 Extension @extension{ARB,explicit_uniform_location} (for
@ -154,8 +157,8 @@ layout(location = 1) uniform mat4 projectionMatrix;
If you don't have the required extension, you can get uniform location using If you don't have the required extension, you can get uniform location using
uniformLocation() after linking stage: uniformLocation() after linking stage:
@code @code
GLint transformationMatrixUniform = uniformLocation("transformationMatrix"); GLint transformationUniform = uniformLocation("transformation");
GLint projectionMatrixUniform = uniformLocation("projectionMatrix"); GLint projectionUniform = uniformLocation("projection");
@endcode @endcode
@subsection AbstractShaderProgram-texture-layer Binding texture layer uniforms @subsection AbstractShaderProgram-texture-layer Binding texture layer uniforms
@ -183,18 +186,18 @@ setUniform(SpecularTextureUniform, SpecularTextureLayer);
@section AbstractShaderProgram-rendering-workflow Rendering workflow @section AbstractShaderProgram-rendering-workflow Rendering workflow
Basic workflow with %AbstractShaderProgram subclasses is: instancing the class Basic workflow with %AbstractShaderProgram subclasses is: instancing the class
(once at the beginning), then in Object::draw() reimplementation calling (once at the beginning), then in draw event setting uniforms and marking the
use(), setting uniforms, binding required textures to their respective layers shader for use, binding required textures to their respective layers using
using AbstractTexture::bind(GLint) and calling Mesh::draw(). For example: AbstractTexture::bind(GLint) and calling Mesh::draw(). For example:
@code @code
void draw(const Magnum::Matrix4& transformationMatrix, Magnum::Camera* camera) { shader->setTransformation(transformation)
shader.use(); ->setProjection(projection)
shader.setTransformationMatrixUniform(transformationMatrix); ->use();
shader.setProjectionMatrixUniform(camera->projectionMatrix());
diffuseTexture.bind(MyShader::DiffuseTextureLayer); diffuseTexture->bind(MyShader::DiffuseTextureLayer);
specularTexture.bind(MyShader::SpecularTextureLayer); specularTexture->bind(MyShader::SpecularTextureLayer);
mesh.draw();
} mesh.draw();
@endcode @endcode
@todo Uniform arrays support @todo Uniform arrays support

Loading…
Cancel
Save