Browse Source

Added function to bind fragment data locations.

pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
49c809915f
  1. 9
      src/AbstractShaderProgram.cpp
  2. 24
      src/AbstractShaderProgram.h

9
src/AbstractShaderProgram.cpp

@ -59,6 +59,15 @@ void AbstractShaderProgram::bindAttribute(GLuint location, const string& name) {
glBindAttribLocation(program, location, name.c_str());
}
void AbstractShaderProgram::bindFragmentDataLocation(GLuint location, const std::string& name) {
if(state != Initialized) {
Error() << "AbstractShaderProgram: fragment data location cannot be bound after linking.";
assert(0);
}
glBindFragDataLocation(program, location, name.c_str());
}
void AbstractShaderProgram::link() {
/* Already compiled or failed, exit */
if(state != Initialized) return;

24
src/AbstractShaderProgram.h

@ -63,7 +63,7 @@ typedef Attribute<2, Vector2> TextureCoords;
projectionMatrixUniform = uniformLocation("projectionMatrix");
// more uniforms like light location, colors etc.
@endcode
- **Uniform binding functions**, which set shader uniforms with
- **Uniform binding functions**, which set shader uniforms using
setUniform() and setUniformArray() functions. Example:
@code
void setTransformationMatrixUniform(const Matrix4& matrix) {
@ -74,6 +74,18 @@ void setTransformationMatrixUniform(const Matrix4& matrix) {
Basic workflow with AbstractShaderProgram subclasses is: instancing the class
(once at the beginning), then in every frame calling use(), setting uniforms
and calling Mesh::draw() (see its documentation for more).
@section MultipleFragmentOutputs Multiple fragment shader outputs
If your shader uses multiple fragment outputs, you can use
bindFragmentDataLocation() *before linking* to bind their names to desired
location, e.g.:
@code
bindFragmentDataLocation(0, "color");
@endcode
You should then clearly state in the documentation which output is on what
position, so the user can set framebuffer attachments for them using
Framebuffer::mapForDraw() or Framebuffer::mapDefaultForDraw().
*/
class MAGNUM_EXPORT AbstractShaderProgram {
AbstractShaderProgram(const AbstractShaderProgram& other) = delete;
@ -134,6 +146,16 @@ class MAGNUM_EXPORT AbstractShaderProgram {
*/
void bindAttribute(GLuint location, const std::string& name);
/**
* @brief Bind fragment data to given location
* @param location Location
* @param name Fragment output variable name
*
* @note This function should be called between loadShader() calls
* and link().
*/
void bindFragmentDataLocation(GLuint location, const std::string& name);
/**
* @brief Link the shader
*

Loading…
Cancel
Save