This is a snapshot of a work-in-progress documentation theme. If you feel lost, miss something, or want to see the original Doxygen docs instead, head over to the archived version of this documentation page.

Magnum::AbstractShaderProgram class

Base for shader program implementations.

Subclassing workflow

This class is designed to be used via subclassing. Subclasses define these functions and properties:

  • Attribute definitions with location and type for configuring meshes, for example:

    typedef Attribute<0, Vector3> Position;
    typedef Attribute<1, Vector3> Normal;
    typedef Attribute<2, Vector2> TextureCoordinates;
  • Output attribute locations, if desired, for example:

    enum: UnsignedInt {
        ColorOutput = 0,
        NormalOutput = 1
    };
  • Constructor, which loads, compiles and attaches particular shaders and links the program together, for example:

    MyShader() {
        // Load shader sources
        Shader vert(Version::GL430, Shader::Type::Vertex);
        Shader frag(Version::GL430, Shader::Type::Fragment);
        vert.addFile("MyShader.vert");
        frag.addFile("MyShader.frag");
    
        // Invoke parallel compilation for best performance
        CORRADE_INTERNAL_ASSERT_OUTPUT(Shader::compile({vert, frag}));
    
        // Attach the shaders
        attachShaders({vert, frag});
    
        // Link the program together
        CORRADE_INTERNAL_ASSERT_OUTPUT(link());
    }
  • Uniform setting functions, which will provide public interface for protected setUniform() functions. For usability purposes you can implement also method chaining. Example:

    MyShader& setProjectionMatrix(const Matrix4& matrix) {
        setUniform(0, matrix);
        return *this;
    }
    MyShader& setTransformationMatrix(const Matrix4& matrix) {
        setUniform(1, matrix);
        return *this;
    }
    MyShader& setNormalMatrix(const Matrix3x3& matrix) {
        setUniform(2, matrix);
        return *this;
    }
  • Texture and texture image setting functions in which you bind the textures/images to particular texture/image units using *Texture::bind() / *Texture::bindImage() and similar, for example:

    MyShader& setDiffuseTexture(Texture2D& texture) {
        texture.bind(0);
        return *this;
    }
    MyShader& setSpecularTexture(Texture2D& texture) {
        texture.bind(1);
        return *this;
    }
  • Transform feedback setup function, if needed, in which you bind buffers to particular indices using TransformFeedback::attachBuffer() and similar, possibly with overloads based on desired use cases, e.g.:

    MyShader& setTransformFeedback(TransformFeedback& feedback, Buffer& positions, Buffer& data) {
        feedback.attachBuffers(0, {positions, data});
        return *this;
    }
    MyShader& setTransformFeedback(TransformFeedback& feedback, Int totalCount, Buffer& positions, GLintptr positionsOffset, Buffer& data, GLintptr dataOffset) {
        feedback.attachBuffers(0, {
            std::make_tuple(positions, positionsOffset, totalCount*sizeof(Vector3)),
            std::make_tuple(data, dataOffset, totalCount*sizeof(Vector2ui))
        });
        return *this;
    }

Binding attribute location

The preferred workflow is to specify attribute location for vertex shader input attributes and fragment shader output attributes explicitly in the shader code, e.g.:

// GLSL 3.30, GLSL ES 3.00 or
#extension GL_ARB_explicit_attrib_location: require
layout(location = 0) in vec4 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec2 textureCoordinates;

Similarly for ouput attributes, you can also specify blend equation color index for them (see Renderer::BlendFunction for more information about using color input index):

layout(location = 0, index = 0) out vec4 color;
layout(location = 1, index = 1) out vec3 normal;

If you don't have the required version/extension, declare the attributes without layout() qualifier and use functions bindAttributeLocation() and bindFragmentDataLocation() / bindFragmentDataLocationIndexed() between attaching the shaders and linking the program. Note that additional syntax changes may be needed for GLSL 1.20 and GLSL ES.

in vec4 position;
in vec3 normal;
in vec2 textureCoordinates;
out vec4 color;
out vec3 normal;
// Shaders attached...

bindAttributeLocation(Position::Location, "position");
bindAttributeLocation(Normal::Location, "normal");
bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates");

bindFragmentDataLocationIndexed(ColorOutput, 0, "color");
bindFragmentDataLocationIndexed(NormalOutput, 1, "normal");

// Link...

Uniform locations

The preferred workflow is to specify uniform locations directly in the shader code, e.g.:

// GLSL 4.30, GLSL ES 3.10 or
#extension GL_ARB_explicit_uniform_location: require
layout(location = 0) uniform mat4 projectionMatrix;
layout(location = 1) uniform mat4 transformationMatrix;
layout(location = 2) uniform mat3 normalMatrix;

If you don't have the required version/extension, declare the uniforms without the layout() qualifier, get uniform location using uniformLocation() after linking stage and then use the queried location in uniform setting functions. Note that additional syntax changes may be needed for GLSL 1.20 and GLSL ES.

uniform mat4 projectionMatrix;
uniform mat4 transformationMatrix;
uniform mat3 normalMatrix;
Int projectionMatrixUniform = uniformLocation("projectionMatrix");
Int transformationMatrixUniform = uniformLocation("transformationMatrix");
Int normalMatrixUniform = uniformLocation("normalMatrix");

Uniform block bindings

The preferred workflow is to specify uniform block binding directly in the shader code, e.g.:

// GLSL 4.20, GLSL ES 3.10 or
#extension GL_ARB_shading_language_420pack: require
layout(std140, binding = 0) uniform matrices {
    mat4 projectionMatrix;
    mat4 transformationMatrix;
};
layout(std140, binding = 1) uniform material {
    vec4 diffuse;
    vec4 specular;
};

If you don't have the required version/extension, declare the uniform blocks without the layout() qualifier, get uniform block index using uniformBlockIndex() and then map it to the uniform buffer binding using setUniformBlockBinding(). Note that additional syntax changes may be needed for GLSL ES.

layout(std140) uniform matrices {
    mat4 projectionMatrix;
    mat4 transformationMatrix;
};
layout(std140) uniform material {
    vec4 diffuse;
    vec4 specular;
};
setUniformBlockBinding(uniformBlockIndex("matrices"), 0);
setUniformBlockBinding(uniformBlockIndex("material"), 1);

Shader storage block bindings

The workflow is to specify shader storage block binding directly in the shader code, e.g.:

// GLSL 4.30 or GLSL ES 3.10
layout(std430, binding = 0) buffer vertices {
    vec3 position;
    vec3 color;
};
layout(std430, binding = 1) buffer normals {
    vec3 normal;
};

Specifying texture and image binding units

The preferred workflow is to specify texture/image binding unit directly in the shader code, e.g.:

// GLSL 4.20, GLSL ES 3.10 or
#extension GL_ARB_shading_language_420pack: require
layout(binding = 0) uniform sampler2D diffuseTexture;
layout(binding = 1) uniform sampler2D specularTexture;

If you don't have the required version/extension, declare the uniforms without the binding qualifier and set the texture binding unit using setUniform(Int, Int). Note that additional syntax changes may be needed for GLSL ES.

uniform sampler2D diffuseTexture;
uniform sampler2D specularTexture;
setUniform(uniformLocation("diffuseTexture"), 0);
setUniform(uniformLocation("specularTexture"), 1);

Specifying transform feedback binding points

The preferred workflow is to specify output binding points directly in the shader code, e.g.:

// GLSL 4.40, or
#extension GL_ARB_enhanced_layouts: require
layout(xfb_buffer = 0, xfb_stride = 32) out block {
    layout(xfb_offset = 0) vec3 position;
    layout(xfb_offset = 16) vec3 normal;
};
layout(xfb_buffer = 1) out vec3 velocity;

If you don't have the required version/extension, declare the uniforms without the xfb_* qualifier and set the binding points using setTransformFeedbackOutputs(). Equivalent setup for the previous code would be the following:

out block {
    vec3 position;
    vec3 normal;
};
out vec3 velocity;
setTransformFeedbackOutputs({
        // Buffer 0
        "position", "gl_SkipComponents1", "normal", "gl_SkipComponents1",
        // Buffer 1
        "gl_NextBuffer", "velocity"
    }, TransformFeedbackBufferMode::InterleavedAttributes);

Rendering workflow

Basic workflow with AbstractShaderProgram subclasses is: instance shader class, configure attribute binding in meshes (see Mesh documentation for more information) and map shader outputs to framebuffer attachments if needed (see Framebuffer documentation for more information). In each draw event set all required shader parameters, bind specific framebuffer (if needed) and then call Mesh::draw(). Example:

shader.setTransformation(transformation)
    .setProjection(projection)
    .setDiffuseTexture(diffuseTexture)
    .setSpecularTexture(specularTexture);

mesh.draw(shader);

Compute workflow

Add just the Shader::Type::Compute shader and implement uniform/texture setting functions as needed. After setting up required parameters call dispatchCompute().

Mapping between GLSL and Magnum types

See Type system for more information, only types with GLSL equivalent can be used (and their super- or subclasses with the same size and underlying type). See also Attribute::DataType enum for additional type options.

Performance optimizations

The engine tracks currently used shader program to avoid unnecessary calls to glUseProgram(). Shader limits (such as maxVertexAttributes()) are cached, so repeated queries don't result in repeated glGet() calls. See also Context::resetState() and Context::State::Shaders.

If extension ARB_separate_shader_objects (part of OpenGL 4.1), EXT_direct_state_access desktop extension, EXT_separate_shader_objects OpenGL ES extension or OpenGL ES 3.1 is available, uniform setting functions use DSA functions to avoid unnecessary calls to glUseProgram(). See setUniform() documentation for more information.

To achieve least state changes, set all uniforms in one run – method chaining comes in handy.

Base classes

class AbstractObject
Base for all OpenGL objects.

Derived classes

template<UnsignedInt dimensions>
class AbstractVector
Base for vector shaders.
template<UnsignedInt dimensions>
class Flat
Flat shader.
class MeshVisualizer
Mesh visualization shader.
class Phong
Phong shader.
template<UnsignedInt dimensions>
class VertexColor
Vertex color shader.
class AbstractUiShader
Base for UI shaders.

Public types

enum class TransformFeedbackBufferMode: GLenum { InterleavedAttributes = 0x8C8C, SeparateAttributes = 0x8C8D }
Buffer mode for transform feedback.

Public static functions

static auto maxVertexAttributes() -> Int
Max supported vertex attribute count.
static auto maxAtomicCounterBufferSize() -> Int
Max supported atomic counter buffer size.
static auto maxComputeSharedMemorySize() -> Int
Max supported compute shared memory size.
static auto maxComputeWorkGroupInvocations() -> Int
Max supported compute work group invocation count.
static auto maxComputeWorkGroupCount() -> Vector3i
Max supported compute work group count.
static auto maxComputeWorkGroupSize() -> Vector3i
Max supported compute work group size.
static auto maxImageUnits() -> Int
Max supported image unit count.
static auto maxImageSamples() -> Int
Max supported image sample count.
static auto maxCombinedShaderOutputResources() -> Int
Max supported combined shader output resource count.
static auto maxShaderStorageBlockSize() -> Long
Max supported shader storage block size.
static auto maxUniformBlockSize() -> Int
Max supported uniform block size.
static auto maxUniformLocations() -> Int
Max supported explicit uniform location count.
static auto minTexelOffset() -> Int
Min supported program texel offset.
static auto maxTexelOffset() -> Int
Max supported program texel offset.

Constructors, destructors, conversion operators

AbstractShaderProgram() explicit
Constructor.
AbstractShaderProgram(NoCreateT) explicit noexcept
Construct without creating the underlying OpenGL object.
AbstractShaderProgram(const AbstractShaderProgram&) deleted
Copying is not allowed.
AbstractShaderProgram(AbstractShaderProgram&& other) noexcept
Move constructor.
~AbstractShaderProgram() pure virtual
Destructor.

Public functions

auto operator=(const AbstractShaderProgram&) -> AbstractShaderProgram& deleted
Copying is not allowed.
auto operator=(AbstractShaderProgram&& other) -> AbstractShaderProgram& noexcept
Move assignment.
auto id() const -> GLuint
OpenGL program ID.
auto label() const -> std::string
Shader program label.
auto setLabel(const std::string& label) -> AbstractShaderProgram&
Set shader program label.
template<std::size_t size>
auto setLabel(const char(&label)[size]) -> AbstractShaderProgram&
auto validate() -> std::pair<bool, std::string>
Validate program.
void dispatchCompute(const Vector3ui& workgroupCount)
Dispatch compute.
void use()
Use shader for rendering.

Protected static functions

static auto link(std::initializer_list<std::reference_wrapper<AbstractShaderProgram>> shaders) -> bool
Link the shader.

Protected functions

void setRetrievableBinary(bool enabled)
Allow retrieving program binary.
void setSeparable(bool enabled)
Allow the program to be bound to individual pipeline stages.
void attachShader(Shader& shader)
Attach shader.
void attachShaders(std::initializer_list<std::reference_wrapper<Shader>> shaders)
Attach shaders.
void bindAttributeLocation(UnsignedInt location, const std::string& name)
Bind attribute to given location.
template<std::size_t size>
void bindAttributeLocation(UnsignedInt location, const char(&name)[size])
void bindFragmentDataLocationIndexed(UnsignedInt location, UnsignedInt index, const std::string& name)
Bind fragment data to given location and color input index.
template<std::size_t size>
void bindFragmentDataLocationIndexed(UnsignedInt location, UnsignedInt index, const char(&name)[size])
void bindFragmentDataLocation(UnsignedInt location, const std::string& name)
Bind fragment data to given location and first color input index.
template<std::size_t size>
void bindFragmentDataLocation(UnsignedInt location, const char(&name)[size])
void setTransformFeedbackOutputs(std::initializer_list<std::string> outputs, TransformFeedbackBufferMode bufferMode)
Specify shader outputs to be recorded in transform feedback.
auto link() -> bool
Link the shader.
auto uniformLocation(const std::string& name) -> Int
Get uniform location.
template<std::size_t size>
auto uniformLocation(const char(&name)[size]) -> Int
auto uniformBlockIndex(const std::string& name) -> UnsignedInt
Get uniform block index.
template<std::size_t size>
auto uniformBlockIndex(const char(&name)[size]) -> UnsignedInt
template<class T>
void setUniform(Int location, const T& value)
Set uniform value.
void setUniform(Int location, Containers::ArrayView<const Float> values)
Set uniform values.
void setUniform(Int location, Containers::ArrayView<const Math::Vector<2, Float>> values)
void setUniform(Int location, Containers::ArrayView<const Math::Vector<3, Float>> values)
void setUniform(Int location, Containers::ArrayView<const Math::Vector<4, Float>> values)
void setUniform(Int location, Containers::ArrayView<const Int> values)
Set uniform values.
void setUniform(Int location, Containers::ArrayView<const Math::Vector<2, Int>> values)
void setUniform(Int location, Containers::ArrayView<const Math::Vector<3, Int>> values)
void setUniform(Int location, Containers::ArrayView<const Math::Vector<4, Int>> values)
void setUniform(Int location, Containers::ArrayView<const UnsignedInt> values)
Set uniform values.
void setUniform(Int location, Containers::ArrayView<const Math::Vector<2, UnsignedInt>> values)
void setUniform(Int location, Containers::ArrayView<const Math::Vector<3, UnsignedInt>> values)
void setUniform(Int location, Containers::ArrayView<const Math::Vector<4, UnsignedInt>> values)
void setUniform(Int location, Containers::ArrayView<const Double> values)
Set uniform values.
void setUniform(Int location, Containers::ArrayView<const Math::Vector<2, Double>> values)
void setUniform(Int location, Containers::ArrayView<const Math::Vector<3, Double>> values)
void setUniform(Int location, Containers::ArrayView<const Math::Vector<4, Double>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 2, Float>> values)
Set uniform values.
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 3, Float>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 4, Float>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 3, Float>> values)
Set uniform values.
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 2, Float>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 4, Float>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 2, Float>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 4, Float>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 3, Float>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 2, Double>> values)
Set uniform values.
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 3, Double>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 4, Double>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 3, Double>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 2, Double>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 4, Double>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 2, Double>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 4, Double>> values)
void setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 3, Double>> values)
template<class T>
void setUniform(Int location, UnsignedInt count, const T* values)
Set uniform values.
void setUniformBlockBinding(UnsignedInt index, UnsignedInt binding)
Set uniform block binding.

Enum documentation

enum class Magnum::AbstractShaderProgram::TransformFeedbackBufferMode: GLenum

Buffer mode for transform feedback.

Enumerators
InterleavedAttributes

Attributes will be interleaved at one buffer binding point

SeparateAttributes

Each attribute will be put into separate buffer binding point

Function documentation

static Int Magnum::AbstractShaderProgram::maxVertexAttributes()

Max supported vertex attribute count.

The result is cached, repeated queries don't result in repeated OpenGL calls.

static Int Magnum::AbstractShaderProgram::maxAtomicCounterBufferSize()

Max supported atomic counter buffer size.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_shader_atomic_counters (part of OpenGL 4.2) nor OpenGL ES 3.1 is available, returns 0.

static Int Magnum::AbstractShaderProgram::maxComputeSharedMemorySize()

Max supported compute shared memory size.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_compute_shader (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns 0.

static Int Magnum::AbstractShaderProgram::maxComputeWorkGroupInvocations()

Max supported compute work group invocation count.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_compute_shader (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns 0.

static Vector3i Magnum::AbstractShaderProgram::maxComputeWorkGroupCount()

Max supported compute work group count.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_compute_shader (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns zero vector.

static Vector3i Magnum::AbstractShaderProgram::maxComputeWorkGroupSize()

Max supported compute work group size.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_compute_shader (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns zero vector.

static Int Magnum::AbstractShaderProgram::maxImageUnits()

Max supported image unit count.

The result is cached, repeated queries don't result in repeated OpenGL calls. If extension ARB_shader_image_load_store (part of OpenGL 4.2) or OpenGL ES 3.1 is not available, returns 0.

static Int Magnum::AbstractShaderProgram::maxImageSamples()

Max supported image sample count.

The result is cached, repeated queries don't result in repeated OpenGL calls. If extension ARB_shader_image_load_store (part of OpenGL 4.2) is not available, returns 0.

static Int Magnum::AbstractShaderProgram::maxCombinedShaderOutputResources()

Max supported combined shader output resource count.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_shader_image_load_store (part of OpenGL 4.2) nor extension ARB_shader_storage_buffer_object (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns 0.

static Long Magnum::AbstractShaderProgram::maxShaderStorageBlockSize()

Max supported shader storage block size.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_shader_storage_buffer_object (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns 0.

static Int Magnum::AbstractShaderProgram::maxUniformBlockSize()

Max supported uniform block size.

The result is cached, repeated queries don't result in repeated OpenGL calls. If extension ARB_uniform_buffer_object (part of OpenGL 3.1) is not available, returns 0.

static Int Magnum::AbstractShaderProgram::maxUniformLocations()

Max supported explicit uniform location count.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_explicit_uniform_location (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns 0.

static Int Magnum::AbstractShaderProgram::minTexelOffset()

Min supported program texel offset.

The result is cached, repeated queries don't result in repeated OpenGL calls. If extension EXT_gpu_shader4 (part of OpenGL 3.0) is not available, returns 0.

static Int Magnum::AbstractShaderProgram::maxTexelOffset()

Max supported program texel offset.

The result is cached, repeated queries don't result in repeated OpenGL calls. If extension EXT_gpu_shader4 (part of OpenGL 3.0) is not available, returns 0.

Magnum::AbstractShaderProgram::AbstractShaderProgram() explicit

Constructor.

Creates one OpenGL shader program.

Magnum::AbstractShaderProgram::AbstractShaderProgram(NoCreateT) explicit noexcept

Construct without creating the underlying OpenGL object.

The constructed instance is equivalent to moved-from state. Useful in cases where you will overwrite the instance later anyway. Move another object over it to make it useful.

This function can be safely used for constructing (and later destructing) objects even without any OpenGL context being active.

Magnum::AbstractShaderProgram::~AbstractShaderProgram() pure virtual

Destructor.

Deletes associated OpenGL shader program.

std::string Magnum::AbstractShaderProgram::label() const

Shader program label.

The result is not cached, repeated queries will result in repeated OpenGL calls. If OpenGL 4.3 is not supported and neither KHR_debug (covered also by ANDROID_extension_pack_es31a) nor EXT_debug_label desktop or ES extension is available, this function returns empty string.

AbstractShaderProgram& Magnum::AbstractShaderProgram::setLabel(const std::string& label)

Set shader program label.

Returns Reference to self (for method chaining)

Default is empty string. If OpenGL 4.3 is not supported and neither KHR_debug (covered also by ANDROID_extension_pack_es31a) nor EXT_debug_label desktop or ES extension is available, this function does nothing.

template<std::size_t size>
AbstractShaderProgram& Magnum::AbstractShaderProgram::setLabel(const char(&label)[size])

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

std::pair<bool, std::string> Magnum::AbstractShaderProgram::validate()

Validate program.

Returns validation status and optional validation message.

void Magnum::AbstractShaderProgram::dispatchCompute(const Vector3ui& workgroupCount)

Dispatch compute.

Parameters
workgroupCount Workgroup count in given dimension

Valid only on programs with compute shader attached.

void Magnum::AbstractShaderProgram::use()

Use shader for rendering.

static bool Magnum::AbstractShaderProgram::link(std::initializer_list<std::reference_wrapper<AbstractShaderProgram>> shaders) protected

Link the shader.

Returns false if linking of any shader failed, true if everything succeeded. Linker message (if any) is printed to error output. All attached shaders must be compiled with Shader::compile() before linking. The operation is batched in a way that allows the driver to link multiple shaders simultaneously (i.e. in multiple threads).

void Magnum::AbstractShaderProgram::setRetrievableBinary(bool enabled) protected

Allow retrieving program binary.

Initially disabled.

void Magnum::AbstractShaderProgram::setSeparable(bool enabled) protected

Allow the program to be bound to individual pipeline stages.

Initially disabled.

void Magnum::AbstractShaderProgram::attachShader(Shader& shader) protected

Attach shader.

void Magnum::AbstractShaderProgram::attachShaders(std::initializer_list<std::reference_wrapper<Shader>> shaders) protected

Attach shaders.

Convenience overload to the above, allowing the user to specify more than one shader at once. Other than that there is no other (performance) difference when using this function.

void Magnum::AbstractShaderProgram::bindAttributeLocation(UnsignedInt location, const std::string& name) protected

Bind attribute to given location.

Parameters
location Location
name Attribute name

Binds attribute to location which is used later for binding vertex buffers.

template<std::size_t size>
void Magnum::AbstractShaderProgram::bindAttributeLocation(UnsignedInt location, const char(&name)[size]) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::bindFragmentDataLocationIndexed(UnsignedInt location, UnsignedInt index, const std::string& name) protected

Bind fragment data to given location and color input index.

Parameters
location Location
index Blend equation color input index (0 or 1)
name Fragment output variable name

Binds fragment data to location which is used later for framebuffer operations. See also Renderer::BlendFunction for more information about using color input index.

template<std::size_t size>
void Magnum::AbstractShaderProgram::bindFragmentDataLocationIndexed(UnsignedInt location, UnsignedInt index, const char(&name)[size]) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::bindFragmentDataLocation(UnsignedInt location, const std::string& name) protected

Bind fragment data to given location and first color input index.

Parameters
location Location
name Fragment output variable name

The same as bindFragmentDataLocationIndexed(), but with index set to 0.

template<std::size_t size>
void Magnum::AbstractShaderProgram::bindFragmentDataLocation(UnsignedInt location, const char(&name)[size]) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setTransformFeedbackOutputs(std::initializer_list<std::string> outputs, TransformFeedbackBufferMode bufferMode) protected

Specify shader outputs to be recorded in transform feedback.

Parameters
outputs Names of output variables
bufferMode Buffer mode

Binds given output variables from vertex, geometry or tessellation shader to transform feedback buffer binding points. If TransformFeedbackBufferMode::SeparateAttributes is used, each output is bound to separate binding point. If TransformFeedbackBufferMode::InterleavedAttributes is used, the outputs are interleaved into single buffer binding point. In this case, special output name gl_NextBuffer causes the following output to be recorded into next buffer binding point and gl_SkipComponents# causes the transform feedback to offset the following output variable by # components.

bool Magnum::AbstractShaderProgram::link() protected

Link the shader.

Links single shader. If possible, prefer to link multiple shaders at once using link(std::initializer_list<std::reference_wrapper<AbstractShaderProgram>>) for improved performance, see its documentation for more information.

Int Magnum::AbstractShaderProgram::uniformLocation(const std::string& name) protected

Get uniform location.

Parameters
name Uniform name

If given uniform is not found in the linked shader, a warning is printed and -1 is returned.

template<std::size_t size>
Int Magnum::AbstractShaderProgram::uniformLocation(const char(&name)[size]) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

UnsignedInt Magnum::AbstractShaderProgram::uniformBlockIndex(const std::string& name) protected

Get uniform block index.

Parameters
name Uniform block name

If given uniform block name is not found in the linked shader, a warning is printed and 0xffffffffu is returned.

template<std::size_t size>
UnsignedInt Magnum::AbstractShaderProgram::uniformBlockIndex(const char(&name)[size]) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
void Magnum::AbstractShaderProgram::setUniform(Int location, const T& value) protected

Set uniform value.

Parameters
location Uniform location
value Value

Convenience alternative for setting one value, see setUniform(Int, Containers::ArrayView<const Float>) for more information.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Float> values) protected

Set uniform values.

Parameters
location Uniform location
values Values

If neither ARB_separate_shader_objects (part of OpenGL 4.1) nor EXT_direct_state_access desktop extension nor EXT_separate_shader_objects OpenGL ES extension nor OpenGL ES 3.1 is available, the shader is marked for use before the operation.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<2, Float>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<3, Float>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<4, Float>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Int> values) protected

Set uniform values.

Parameters
location Uniform location
values Values

If neither ARB_separate_shader_objects (part of OpenGL 4.1) nor EXT_direct_state_access desktop extension nor EXT_separate_shader_objects OpenGL ES extension nor OpenGL ES 3.1 is available, the shader is marked for use before the operation.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<2, Int>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<3, Int>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<4, Int>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const UnsignedInt> values) protected

Set uniform values.

Parameters
location Uniform location
values Values

If neither ARB_separate_shader_objects (part of OpenGL 4.1) nor EXT_direct_state_access desktop extension nor EXT_separate_shader_objects OpenGL ES extension nor OpenGL ES 3.1 is available, the shader is marked for use before the operation.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<2, UnsignedInt>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<3, UnsignedInt>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<4, UnsignedInt>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Double> values) protected

Set uniform values.

Parameters
location Uniform location
values Values

If neither ARB_separate_shader_objects (part of OpenGL 4.1) nor EXT_direct_state_access desktop extension nor EXT_separate_shader_objects OpenGL ES extension nor OpenGL ES 3.1 is available, the shader is marked for use before the operation.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<2, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<3, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::Vector<4, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 2, Float>> values) protected

Set uniform values.

Parameters
location Uniform location
values Values

If neither ARB_separate_shader_objects (part of OpenGL 4.1) nor EXT_direct_state_access desktop extension nor EXT_separate_shader_objects OpenGL ES extension nor OpenGL ES 3.1 is available, the shader is marked for use before the operation.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 3, Float>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 4, Float>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 3, Float>> values) protected

Set uniform values.

Parameters
location Uniform location
values Values

If neither ARB_separate_shader_objects (part of OpenGL 4.1) nor EXT_direct_state_access desktop extension nor EXT_separate_shader_objects OpenGL ES extension nor OpenGL ES 3.1 is available, the shader is marked for use before the operation.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 2, Float>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 4, Float>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 2, Float>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 4, Float>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 3, Float>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 2, Double>> values) protected

Set uniform values.

Parameters
location Uniform location
values Values

If neither ARB_separate_shader_objects (part of OpenGL 4.1) nor EXT_direct_state_access desktop extension nor EXT_separate_shader_objects OpenGL ES extension nor OpenGL ES 3.1 is available, the shader is marked for use before the operation.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 3, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 4, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 3, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 2, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<2, 4, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 2, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<3, 4, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Magnum::AbstractShaderProgram::setUniform(Int location, Containers::ArrayView<const Math::RectangularMatrix<4, 3, Double>> values) protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
void Magnum::AbstractShaderProgram::setUniform(Int location, UnsignedInt count, const T* values) protected

Set uniform values.

void Magnum::AbstractShaderProgram::setUniformBlockBinding(UnsignedInt index, UnsignedInt binding) protected

Set uniform block binding.

Parameters
index Uniform block index
binding Uniform block binding