libdonut  2.3.2
Application framework for cross-platform game development in C++20
Classes | Public Types | Public Member Functions | List of all members
donut::graphics::ShaderProgram Class Reference

Compiled and linked GPU shader program. More...

#include <donut/graphics/ShaderProgram.hpp>

Public Types

using UniformValue = Variant< float, vec2, vec3, vec4, i32, i32vec2, i32vec3, i32vec4, u32, u32vec2, u32vec3, u32vec4, mat2, mat3, mat4 >
 Value of a uniform shader variable. More...
 

Public Member Functions

 ShaderProgram (const ShaderProgramOptions &options)
 Compile and link a shader program. More...
 
void setUniformFloat (const ShaderParameter &parameter, float value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type float. More...
 
void setUniformVec2 (const ShaderParameter &parameter, vec2 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type vec2. More...
 
void setUniformVec3 (const ShaderParameter &parameter, vec3 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type vec3. More...
 
void setUniformVec4 (const ShaderParameter &parameter, vec4 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type vec4. More...
 
void setUniformInt (const ShaderParameter &parameter, i32 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type int. More...
 
void setUniformIVec2 (const ShaderParameter &parameter, i32vec2 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type ivec2. More...
 
void setUniformIVec3 (const ShaderParameter &parameter, i32vec3 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type ivec3. More...
 
void setUniformIVec4 (const ShaderParameter &parameter, i32vec4 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type ivec4. More...
 
void setUniformUint (const ShaderParameter &parameter, u32 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type uint. More...
 
void setUniformUVec2 (const ShaderParameter &parameter, u32vec2 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type uvec2. More...
 
void setUniformUVec3 (const ShaderParameter &parameter, u32vec3 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type uvec3. More...
 
void setUniformUVec4 (const ShaderParameter &parameter, u32vec4 value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type uvec4. More...
 
void setUniformMat2 (const ShaderParameter &parameter, const mat2 &value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type mat2. More...
 
void setUniformMat3 (const ShaderParameter &parameter, const mat3 &value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type mat3. More...
 
void setUniformMat4 (const ShaderParameter &parameter, const mat4 &value)
 Enqueue a new value to be set for a uniform shader variable of GLSL type mat4. More...
 
void setUniformSampler (const ShaderParameter &parameter, const Texture *texture)
 Insert a new texture to be bound for a uniform shader variable of a GLSL sampler type. More...
 
void clearUniformUploadQueue () noexcept
 Erase all entries from the queue of new uniform shader variable values. More...
 
void clearTextureBindings () noexcept
 Erase all entries from the list of active texture bindings. More...
 
std::span< const std::pair< std::int32_t, UniformValue > > getUniformUploadQueue () const noexcept
 Get the list of new uniform shader variable values to be uploaded to the shader. More...
 
std::span< const std::pair< std::int32_t, const Texture * > > getTextureBindings () const noexcept
 Get the list of active texture bindings to be synchronized with the shader. More...
 
Handle get () const noexcept
 Get an opaque handle to the GPU representation of the shader program. More...
 

Detailed Description

Compiled and linked GPU shader program.

Examples
example_game.cpp.

Member Typedef Documentation

◆ UniformValue

using donut::graphics::ShaderProgram::UniformValue = Variant< float, vec2, vec3, vec4, i32, i32vec2, i32vec3, i32vec4, u32, u32vec2, u32vec3, u32vec4, mat2, mat3, mat4>

Value of a uniform shader variable.

Constructor & Destructor Documentation

◆ ShaderProgram()

donut::graphics::ShaderProgram::ShaderProgram ( const ShaderProgramOptions options)
explicit

Compile and link a shader program.

Parameters
optionsshader program options, see ShaderProgramOptions.
Exceptions
graphics::Erroron failure to create a shader object, create the shader program object, compile the shader code or link the shader program.
std::bad_allocon allocation failure.

Member Function Documentation

◆ setUniformFloat()

void donut::graphics::ShaderProgram::setUniformFloat ( const ShaderParameter parameter,
float  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type float.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformVec2()

void donut::graphics::ShaderProgram::setUniformVec2 ( const ShaderParameter parameter,
vec2  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type vec2.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformVec3()

void donut::graphics::ShaderProgram::setUniformVec3 ( const ShaderParameter parameter,
vec3  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type vec3.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformVec4()

void donut::graphics::ShaderProgram::setUniformVec4 ( const ShaderParameter parameter,
vec4  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type vec4.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformInt()

void donut::graphics::ShaderProgram::setUniformInt ( const ShaderParameter parameter,
i32  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type int.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformIVec2()

void donut::graphics::ShaderProgram::setUniformIVec2 ( const ShaderParameter parameter,
i32vec2  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type ivec2.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformIVec3()

void donut::graphics::ShaderProgram::setUniformIVec3 ( const ShaderParameter parameter,
i32vec3  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type ivec3.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformIVec4()

void donut::graphics::ShaderProgram::setUniformIVec4 ( const ShaderParameter parameter,
i32vec4  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type ivec4.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformUint()

void donut::graphics::ShaderProgram::setUniformUint ( const ShaderParameter parameter,
u32  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type uint.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformUVec2()

void donut::graphics::ShaderProgram::setUniformUVec2 ( const ShaderParameter parameter,
u32vec2  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type uvec2.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformUVec3()

void donut::graphics::ShaderProgram::setUniformUVec3 ( const ShaderParameter parameter,
u32vec3  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type uvec3.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformUVec4()

void donut::graphics::ShaderProgram::setUniformUVec4 ( const ShaderParameter parameter,
u32vec4  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type uvec4.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformMat2()

void donut::graphics::ShaderProgram::setUniformMat2 ( const ShaderParameter parameter,
const mat2 &  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type mat2.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformMat3()

void donut::graphics::ShaderProgram::setUniformMat3 ( const ShaderParameter parameter,
const mat3 &  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type mat3.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformMat4()

void donut::graphics::ShaderProgram::setUniformMat4 ( const ShaderParameter parameter,
const mat4 &  value 
)

Enqueue a new value to be set for a uniform shader variable of GLSL type mat4.

Parameters
parametershader variable to set.
valuenew value to set the variable to.
Exceptions
std::bad_allocon allocation failure.
Note
The new value is not uploaded to the shader immediately; instead it is stored in this shader program's uniform upload queue to be uploaded on the next render that uses this shader.
See also
getUniformUploadQueue()
clearUniformUploadQueue()

◆ setUniformSampler()

void donut::graphics::ShaderProgram::setUniformSampler ( const ShaderParameter parameter,
const Texture texture 
)

Insert a new texture to be bound for a uniform shader variable of a GLSL sampler type.

Parameters
parametershader variable to set.
texturenon-owning read-only pointer to the new texture to bind the variable to, or nullptr to remove the binding for the given variable.
Exceptions
std::bad_allocon allocation failure.
Note
The new texture is not bound immediately; instead it is stored in this shader program's texture binding list to be uploaded on the next render that uses this shader.
Warning
The pointed-to texture must remain valid for the duration of its use in the shader.
See also
getTextureBindings()
clearTextureBindings()

◆ clearUniformUploadQueue()

void donut::graphics::ShaderProgram::clearUniformUploadQueue ( )
inlinenoexcept

Erase all entries from the queue of new uniform shader variable values.

◆ clearTextureBindings()

void donut::graphics::ShaderProgram::clearTextureBindings ( )
inlinenoexcept

Erase all entries from the list of active texture bindings.

◆ getUniformUploadQueue()

std::span<const std::pair<std::int32_t, UniformValue> > donut::graphics::ShaderProgram::getUniformUploadQueue ( ) const
inlinenoexcept

Get the list of new uniform shader variable values to be uploaded to the shader.

Returns
a non-owning read-only view over a sequence of pairs where the first element of each pair represents the location of a uniform shader variable and the second element holds its new value.

◆ getTextureBindings()

std::span<const std::pair<std::int32_t, const Texture*> > donut::graphics::ShaderProgram::getTextureBindings ( ) const
inlinenoexcept

Get the list of active texture bindings to be synchronized with the shader.

Returns
a non-owning read-only view over a sequence of pairs where the first element of each pair represents the location of a uniform shader variable and the second element is a non-owning read-only pointer to the texture that should be bound to it, or nullptr for no binding.

◆ get()

Handle donut::graphics::ShaderProgram::get ( ) const
inlinenoexcept

Get an opaque handle to the GPU representation of the shader program.

Returns
a non-owning resource handle to the GPU representation of the shader program.
Note
This function is used internally by the implementations of various abstractions and is not intended to be used outside of the graphics module. The returned handle has no meaning to application code.

The documentation for this class was generated from the following file: