Browse Source

Added AbstractShaderProgram::bindFragmentDataLocationIndexed().

pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
ee55d8425c
  1. 5
      src/AbstractShaderProgram.cpp
  2. 38
      src/AbstractShaderProgram.h

5
src/AbstractShaderProgram.cpp

@ -50,6 +50,11 @@ void AbstractShaderProgram::bindFragmentDataLocation(GLuint location, const std:
glBindFragDataLocation(program, location, name.c_str()); glBindFragDataLocation(program, location, name.c_str());
} }
void AbstractShaderProgram::bindFragmentDataLocationIndexed(GLuint location, GLuint index, const std::string& name) {
CORRADE_ASSERT(state == Initialized, "AbstractShaderProgram: fragment data location cannot be bound after linking.", );
glBindFragDataLocationIndexed(program, location, index, name.c_str());
}
#endif #endif
void AbstractShaderProgram::link() { void AbstractShaderProgram::link() {

38
src/AbstractShaderProgram.h

@ -39,6 +39,8 @@ typedef Attribute<0, Vector4> Vertex;
typedef Attribute<1, Vector3> Normal; typedef Attribute<1, Vector3> Normal;
typedef Attribute<2, Vector2> TextureCoords; typedef Attribute<2, Vector2> TextureCoords;
@endcode @endcode
@todoc Output attribute location (for bindFragmentDataLocationIndexed(),
referenced also from Framebuffer::mapDefaultForDraw() / Framebuffer::mapForDraw())
- **Layers for texture uniforms** to which the textures will be bound before - **Layers for texture uniforms** to which the textures will be bound before
rendering, for example: rendering, for example:
@code @code
@ -82,18 +84,27 @@ layout(location = 0) in vec4 vertex;
layout(location = 1) in vec3 normal; layout(location = 1) in vec3 normal;
layout(location = 2) in vec2 textureCoords; layout(location = 2) in vec2 textureCoords;
@endcode @endcode
Similarly for ouput attributes, you can also specify blend equation color
index for them (see Framebuffer::BlendFunction for more information about
using color input index):
@code
layout(location = 0, index = 0) out vec4 color;
layout(location = 1, index = 1) out vec4 ambient;
@endcode
@requires_gl (for explicit input attribute location instead of using @requires_gl (for explicit input attribute location instead of using
bindAttributeLocation()) bindAttributeLocation())
@requires_gl (for explicit output attribute location or using @requires_gl (for explicit output attribute location or using
bindFragmentDataLocation()) bindFragmentDataLocation() / bindFragmentDataLocationIndexed())
@requires_gl30 Extension @extension{EXT,gpu_shader4} (for using @requires_gl30 Extension @extension{EXT,gpu_shader4} (for using
bindFragmentDataLocation()) bindFragmentDataLocation())
@requires_gl33 Extension @extension{ARB,blend_func_extended} (for using
bindFragmentDataLocationIndexed())
@requires_gl33 Extension @extension{ARB,explicit_attrib_location} (for @requires_gl33 Extension @extension{ARB,explicit_attrib_location} (for
explicit attribute location instead of using bindAttributeLocation()) explicit attribute location instead of using bindAttributeLocation())
If you don't have the required extension, you can use functions bindAttributeLocation() If you don't have the required extension, you can use functions bindAttributeLocation()
and bindFragmentDataLocation() between attaching of shaders and linking the and bindFragmentDataLocation() / bindFragmentDataLocationIndexed() between
program: attaching the shaders and linking the program:
@code @code
// Shaders attached... // Shaders attached...
@ -101,6 +112,9 @@ bindAttributeLocation(Vertex::Location, "vertex");
bindAttributeLocation(Normal::Location, "normal"); bindAttributeLocation(Normal::Location, "normal");
bindAttributeLocation(TextureCoords::Location, "textureCoords"); bindAttributeLocation(TextureCoords::Location, "textureCoords");
bindFragmentDataLocationIndexed(0, 0, "color");
bindFragmentDataLocationIndexed(1, 1, "ambient");
// Link... // Link...
@endcode @endcode
@ -249,16 +263,32 @@ class MAGNUM_EXPORT AbstractShaderProgram {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/** /**
* @brief Bind fragment data to given location * @brief Bind fragment data to given location and color input index
* @param location Location * @param location Location
* @param name Fragment output variable name * @param name Fragment output variable name
* @param index Blend equation color input index (`0` or `1`)
* *
* Binds fragment data to location which is used later for framebuffer
* operations. See also Framebuffer::BlendFunction for more
* information about using color input index.
* @requires_gl
* @requires_gl33 Extension @extension{ARB,blend_func_extended}
* @note This function should be called after attachShader() calls and * @note This function should be called after attachShader() calls and
* before link(). * before link().
* @deprecated Preferred usage is to specify attribute location * @deprecated Preferred usage is to specify attribute location
* explicitly in the shader instead of using this function. See * explicitly in the shader instead of using this function. See
* @ref AbstractShaderProgram-attribute-location "class documentation" * @ref AbstractShaderProgram-attribute-location "class documentation"
* for more information. * for more information.
*/
void bindFragmentDataLocationIndexed(GLuint location, GLuint index, const std::string& name);
/**
* @brief Bind fragment data to given location and first color input index
* @param location Location
* @param name Fragment output variable name
*
* The same as bindFragmentDataLocationIndexed(), but with `index` set
* to `0`.
* @requires_gl * @requires_gl
* @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gl30 Extension @extension{EXT,gpu_shader4}
*/ */

Loading…
Cancel
Save