|
Rendu
A lightweight rendering engine for experimentations
|
Represents a group of shaders used for rendering. More...
#include <Program.hpp>
Classes | |
| struct | BufferDef |
| Buffer reflection information. More... | |
| struct | DynamicBufferState |
| Internal state for a dynamic uniform buffer. More... | |
| struct | ImageDef |
| Image-sampler reflection information. More... | |
| struct | Stage |
| Per-stage reflection information. More... | |
| struct | State |
| Program pipeline state. More... | |
| struct | StaticBufferState |
| Internal state for a static (external) uniform buffer. More... | |
| struct | TextureState |
| Internal state for an image. More... | |
| struct | UniformDef |
| Uniform reflection information. More... | |
Public Types | |
| enum class | Type { GRAPHICS , COMPUTE } |
| using | Uniforms = std::unordered_map< std::string, UniformDef > |
| List of named uniforms. | |
Public Member Functions | |
| Program (const std::string &name, const std::string &vertexContent, const std::string &fragmentContent, const std::string &tessControlContent="", const std::string &tessEvalContent="") | |
| Program (const std::string &name, const std::string &computeContent) | |
| void | reload (const std::string &vertexContent, const std::string &fragmentContent, const std::string &tessControlContent="", const std::string &tessEvalContent="") |
| void | reload (const std::string &computeContent) |
| bool | reloaded () const |
| bool | reloaded (bool absorb) |
| void | use () const |
| void | clean () |
| void | buffer (const UniformBufferBase &buffer, uint slot) |
| void | buffer (const Buffer &buffer, uint slot) |
| void | bufferArray (const std::vector< const Buffer * > &buffers, uint slot) |
| void | texture (const Texture *texture, uint slot, uint mip=Program::ALL_MIPS) |
| void | texture (const Texture &texture, uint slot, uint mip=Program::ALL_MIPS) |
| void | textureArray (const std::vector< const Texture * > &textures, uint slot, uint mip=Program::ALL_MIPS) |
| void | textures (const std::vector< const Texture * > &textures, size_t slot=0) |
| void | defaultTexture (uint slot) |
| void | transitionResourcesTo (Program::Type type) |
| void | update () |
| void | uniform (const std::string &name, bool t) |
| void | uniform (const std::string &name, int t) |
| void | uniform (const std::string &name, uint t) |
| void | uniform (const std::string &name, float t) |
| void | uniform (const std::string &name, const glm::vec2 &t) |
| void | uniform (const std::string &name, const glm::vec3 &t) |
| void | uniform (const std::string &name, const glm::vec4 &t) |
| void | uniform (const std::string &name, const glm::ivec2 &t) |
| void | uniform (const std::string &name, const glm::ivec3 &t) |
| void | uniform (const std::string &name, const glm::ivec4 &t) |
| void | uniform (const std::string &name, const glm::mat3 &t) |
| void | uniform (const std::string &name, const glm::mat4 &t) |
| void | getUniform (const std::string &name, bool &t) const |
| void | getUniform (const std::string &name, int &t) const |
| void | getUniform (const std::string &name, uint &t) const |
| void | getUniform (const std::string &name, float &t) const |
| void | getUniform (const std::string &name, glm::vec2 &t) const |
| void | getUniform (const std::string &name, glm::vec3 &t) const |
| void | getUniform (const std::string &name, glm::vec4 &t) const |
| void | getUniform (const std::string &name, glm::ivec2 &t) const |
| void | getUniform (const std::string &name, glm::ivec3 &t) const |
| void | getUniform (const std::string &name, glm::ivec4 &t) const |
| void | getUniform (const std::string &name, glm::mat3 &t) const |
| void | getUniform (const std::string &name, glm::mat4 &t) const |
| const Uniforms & | uniforms () const |
| const std::string & | name () const |
| Program::Type | type () const |
| const glm::uvec3 & | size () const |
| Program & | operator= (const Program &)=delete |
| Program (const Program &)=delete | |
| Program & | operator= (Program &&)=delete |
| Program (Program &&)=default | |
| const State & | getState () const |
| Stage & | stage (ShaderType type) |
Static Public Attributes | |
| static uint | ALL_MIPS = 0xFFFF |
Private Member Functions | |
| void | reflect () |
| Reflect all uniforms/textures/storage buffers and images based on the shader content. | |
| void | updateUniformMetric () const |
| Update internal metrics. | |
| const char * | retrieveUniform (const UniformDef::Location &location) const |
| char * | retrieveUniformNonConst (const UniformDef::Location &location) |
Private Attributes | |
| std::string | _name |
| Debug name. | |
| std::array< Stage, int(ShaderType::COUNT)> | _stages |
| Per-stage reflection data. | |
| State | _state |
| Program pipeline state. | |
| std::unordered_map< std::string, UniformDef > | _uniforms |
| All dynamic uniform definitions. | |
| std::unordered_map< int, DynamicBufferState > | _dynamicBuffers |
| Dynamic uniform buffer definitions (set 0). | |
| std::unordered_map< int, TextureState > | _textures |
| Dynamic image-sampler definitions (set 2). | |
| std::unordered_map< int, StaticBufferState > | _staticBuffers |
| Static uniform buffer definitions (set 3). | |
| std::array< bool, 4 > | _dirtySets |
| Marks which descriptor sets are dirty. | |
| std::array< DescriptorSet, 4 > | _currentSets |
| Descriptor sets. | |
| std::vector< uint32_t > | _currentOffsets |
| Offsets in the descriptor set for dynamic uniform buffers. | |
| bool | _reloaded = false |
| Has the program been reloaded. | |
| const Type | _type |
| Is this a compute shader. | |
Friends | |
| class | GPU |
| Utilities will need to access GPU handle. | |
Represents a group of shaders used for rendering.
Internally responsible for handling uniforms locations, shaders reloading and values caching. Uniform sets are predefined: set 0 is for dynamic uniforms, set 1 for image-samplers, set 2 for static/per-frame uniform buffers.
|
strong |
| Program::Program | ( | const std::string & | name, |
| const std::string & | vertexContent, | ||
| const std::string & | fragmentContent, | ||
| const std::string & | tessControlContent = "", |
||
| const std::string & | tessEvalContent = "" |
||
| ) |
Load, compile and link shaders into a GPU graphics program.
| name | the program name for logging |
| vertexContent | the content of the vertex shader |
| fragmentContent | the content of the fragment shader |
| tessControlContent | the content of the tessellation control shader (can be empty) |
| tessEvalContent | the content of the tessellation evaluation shader (can be empty) |
| Program::Program | ( | const std::string & | name, |
| const std::string & | computeContent | ||
| ) |
|
delete |
Copy constructor (disabled).
|
default |
Move constructor.
| void Program::buffer | ( | const Buffer & | buffer, |
| uint | slot | ||
| ) |
Bind a buffer to a given location.
| buffer | the buffer to bind |
| slot | the location to bind to |
| void Program::buffer | ( | const UniformBufferBase & | buffer, |
| uint | slot | ||
| ) |
Bind a buffer to a given location.
| buffer | the buffer to bind |
| slot | the location to bind to |
| void Program::bufferArray | ( | const std::vector< const Buffer * > & | buffers, |
| uint | slot | ||
| ) |
Bind a set of buffers to a given location.
| buffers | the buffers to bind |
| slot | the location to bind to |
| void Program::clean | ( | ) |
Delete the program on the GPU.
| void Program::defaultTexture | ( | uint | slot | ) |
Bind a default texture to a given location.
| slot | the location to bind the texture to |
|
inline |
| void Program::getUniform | ( | const std::string & | name, |
| bool & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| float & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| glm::ivec2 & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| glm::ivec3 & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| glm::ivec4 & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| glm::mat3 & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| glm::mat4 & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| glm::vec2 & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| glm::vec3 & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| glm::vec4 & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| int & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
| void Program::getUniform | ( | const std::string & | name, |
| uint & | t | ||
| ) | const |
Get a given uniform value.
| name | the uniform name |
| t | will contain the value |
|
inline |
Copy assignment operator (disabled).
Move assignment operator.
| void Program::reload | ( | const std::string & | computeContent | ) |
Load the program, compiling the shader and updating all uniform locations.
| computeContent | the content of the compute shader |
| void Program::reload | ( | const std::string & | vertexContent, |
| const std::string & | fragmentContent, | ||
| const std::string & | tessControlContent = "", |
||
| const std::string & | tessEvalContent = "" |
||
| ) |
Load the program, compiling the shader and updating all uniform locations.
| vertexContent | the content of the vertex shader |
| fragmentContent | the content of the fragment shader |
| tessControlContent | the content of the tessellation control shader (can be empty) |
| tessEvalContent | the content of the tessellation evaluation shader (can be empty) |
| bool Program::reloaded | ( | ) | const |
| bool Program::reloaded | ( | bool | absorb | ) |
Check if the program has been recently reloaded.
| absorb | should the reloaded flag be set to false afterwards |
|
inlineprivate |
Obtain a pointer to the CPU memory for a uniform.
| location | the uniform location to retrieve |
|
inlineprivate |
Obtain a pointer to the CPU memory for a uniform.
| location | the uniform location to retrieve |
| const glm::uvec3 & Program::size | ( | ) | const |
|
inline |
Query shader information for a stage.
| type | the stage to query |
| void Program::texture | ( | const Texture & | texture, |
| uint | slot, | ||
| uint | mip = Program::ALL_MIPS |
||
| ) |
Bind a texture to a given location.
| texture | the texture to bind |
| slot | the location to bind to |
| mip | the mip of the texture to bind (or all mips if left at its default value) |
| void Program::texture | ( | const Texture * | texture, |
| uint | slot, | ||
| uint | mip = Program::ALL_MIPS |
||
| ) |
Bind a texture to a given location.
| texture | the texture to bind |
| slot | the location to bind to |
| mip | the mip of the texture to bind (or all mips if left at its default value) |
| void Program::textureArray | ( | const std::vector< const Texture * > & | textures, |
| uint | slot, | ||
| uint | mip = Program::ALL_MIPS |
||
| ) |
Bind a set of textures to a given location.
| textures | the textures to bind |
| slot | the location to bind to |
| mip | the mip of the textures to bind (or all mips if left at its default value) |
| void Program::textures | ( | const std::vector< const Texture * > & | textures, |
| size_t | slot = 0 |
||
| ) |
Bind a set of textures to successive locations.
| textures | the textures to bind |
| slot | the location to bind the first texture to |
| void Program::transitionResourcesTo | ( | Program::Type | type | ) |
Ensure all currently set resources are in the proper layout/state and are synchronized for a given type of use (graphics or compute).
| type | the type of use to prepare resources for |
|
inline |
| void Program::uniform | ( | const std::string & | name, |
| bool | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| const glm::ivec2 & | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| const glm::ivec3 & | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| const glm::ivec4 & | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| const glm::mat3 & | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| const glm::mat4 & | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| const glm::vec2 & | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| const glm::vec3 & | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| const glm::vec4 & | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| float | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| int | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
| void Program::uniform | ( | const std::string & | name, |
| uint | t | ||
| ) |
Set a given uniform value.
| name | the uniform name |
| t | the value to set the uniform to |
|
inline |
| void Program::update | ( | ) |
Update internal data (descriptors,...) and bind them before a draw/dispatch.
| void Program::use | ( | ) | const |
Activate the program shaders.
|
static |
Bind all mip levels of a texture