|
Aegis2D
Modular C++26 2D game engine for networked games
|
Vertex and fragment shaders linked into one OpenGL program. More...
#include <aegis2d/render/opengl/shader.hpp>
Public Member Functions | |
| ShaderProgram (const ShaderSources &sources) | |
| Compiles both stages and links them. | |
| ShaderProgram (const ShaderProgram &)=delete | |
| ShaderProgram & | operator= (const ShaderProgram &)=delete |
| ShaderProgram (ShaderProgram &&other) noexcept | |
Takes over the program of other, which becomes empty. | |
| ShaderProgram & | operator= (ShaderProgram &&other) noexcept |
Deletes this program and takes over the program of other. | |
| ~ShaderProgram () | |
| Deletes the program. | |
| void | use () const |
| Makes the program current for the next draw calls. | |
| std::uint32_t | id () const noexcept |
| OpenGL name of the program. | |
| bool | has_uniform (std::string_view name) |
| Tells whether the linked program has an active uniform of this name. | |
| void | set_uniform (std::string_view name, std::int32_t value) |
Sets an int (or sampler) uniform. | |
| void | set_uniform (std::string_view name, float value) |
Sets a float uniform. | |
| void | set_uniform (std::string_view name, Vec2 value) |
Sets a vec2 uniform. | |
| void | set_uniform (std::string_view name, Color value) |
Sets a vec4 uniform from a color. | |
| void | set_uniform (std::string_view name, const Vec4 &value) |
Sets a vec4 uniform. | |
| void | set_uniform (std::string_view name, const Mat4 &matrix) |
Sets a mat4 uniform. | |
Static Public Member Functions | |
| static std::string_view | version_directive () noexcept |
#version line prepended to every stage. | |
Vertex and fragment shaders linked into one OpenGL program.
The sources are written without #version: the program prepends the line matching the context (#version 450 core, or #version 410 core with AEGIS2D_MACOS_GL41), so the same shaders run on every platform.
Uniforms are set with glProgramUniform*, without binding the program; their locations are looked up once and cached. A uniform the driver optimized away (or a misspelt name) is ignored, as OpenGL does; has_uniform() tells which.
Needs a current Context; destroy the program before the context.
|
explicit |
Compiles both stages and links them.
| sources | GLSL sources without #version line. |
| ShaderError | with the driver's log if a stage does not compile or the program does not link. |
|
delete |
|
noexcept |
Takes over the program of other, which becomes empty.
| other | Program to move from. |
| aegis2d::render::opengl::ShaderProgram::~ShaderProgram | ( | ) |
Deletes the program.
| bool aegis2d::render::opengl::ShaderProgram::has_uniform | ( | std::string_view | name | ) |
Tells whether the linked program has an active uniform of this name.
| name | Uniform name as written in the GLSL source. |
false for unknown names and uniforms the driver optimized away.
|
noexcept |
OpenGL name of the program.
|
delete |
|
noexcept |
Deletes this program and takes over the program of other.
| other | Program to move from. |
| void aegis2d::render::opengl::ShaderProgram::set_uniform | ( | std::string_view | name, |
| Color | value | ||
| ) |
Sets a vec4 uniform from a color.
| name | Uniform name. |
| value | New value, as (r, g, b, a). |
| void aegis2d::render::opengl::ShaderProgram::set_uniform | ( | std::string_view | name, |
| const Mat4 & | matrix | ||
| ) |
Sets a mat4 uniform.
| name | Uniform name. |
| matrix | New value; GLM and GLSL both store matrices column by column. |
| void aegis2d::render::opengl::ShaderProgram::set_uniform | ( | std::string_view | name, |
| const Vec4 & | value | ||
| ) |
Sets a vec4 uniform.
| name | Uniform name. |
| value | New value. |
| void aegis2d::render::opengl::ShaderProgram::set_uniform | ( | std::string_view | name, |
| float | value | ||
| ) |
Sets a float uniform.
| name | Uniform name. |
| value | New value. |
| void aegis2d::render::opengl::ShaderProgram::set_uniform | ( | std::string_view | name, |
| std::int32_t | value | ||
| ) |
Sets an int (or sampler) uniform.
| name | Uniform name. |
| value | New value. |
| void aegis2d::render::opengl::ShaderProgram::set_uniform | ( | std::string_view | name, |
| Vec2 | value | ||
| ) |
Sets a vec2 uniform.
| name | Uniform name. |
| value | New value. |
| void aegis2d::render::opengl::ShaderProgram::use | ( | ) | const |
Makes the program current for the next draw calls.
|
staticnoexcept |
#version line prepended to every stage.
"#version 450 core\n", or "#version 410 core\n" with AEGIS2D_MACOS_GL41.