|
Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
|
GPU shader program for rendering. More...
#include <Shader.hpp>
Public Member Functions | |
| Shader ()=default | |
| ~Shader () | |
| Shader (const Shader &)=delete | |
| Shader & | operator= (const Shader &)=delete |
| Shader (Shader &&other) noexcept | |
| Shader & | operator= (Shader &&other) noexcept |
| GfxShaderLanguage | language () const |
| The source language this program was compiled from. | |
| void | whenLinked (std::function< void(Shader &)> fn) |
Runs fn on this shader once it has linked: at once for one that has. | |
| void | bind () const |
| Binds the shader for rendering. | |
| void | unbind () const |
| Unbinds the shader. | |
| void | setUniform (const std::string &name, i32 value) const |
| Sets an integer uniform. | |
| void | setUniform (const std::string &name, f32 value) const |
| void | setUniform (const std::string &name, const glm::vec2 &value) const |
| void | setUniform (const std::string &name, const glm::vec3 &value) const |
| void | setUniform (const std::string &name, const glm::vec4 &value) const |
| void | setUniform (const std::string &name, const glm::mat3 &value) const |
| void | setUniform (const std::string &name, const glm::mat4 &value) const |
| void | setUniform (i32 location, i32 value) const |
| void | setUniform (i32 location, f32 value) const |
| void | setUniform (i32 location, const glm::vec2 &value) const |
| void | setUniform (i32 location, const glm::vec3 &value) const |
| void | setUniform (i32 location, const glm::vec4 &value) const |
| void | setUniform (i32 location, const glm::mat3 &value) const |
| void | setUniform (i32 location, const glm::mat4 &value) const |
| i32 | getAttribLocation (const std::string &name) const |
| Gets the location of a vertex attribute. | |
| i32 | getUniformLocation (const std::string &name) const |
| bool | hasUniform (const std::string &name) const |
| True if the linked program declares this uniform. | |
| const std::vector< GfxUniformInfo > & | getActiveUniforms () const |
| Returns reflected metadata for every active uniform, populated at link time. | |
| void | adoptDrawParams (DrawParamsLayout layout) |
| Adopts the layout rewriteLooseUniforms produced for this program. | |
| bool | hasDrawParams () const |
| True when this program carries a DrawParams block. | |
| void | commitParams () |
| Uploads the shadow (when dirty) and binds this shader's params UBO at DRAW_PARAMS_BINDING. | |
| bool | isValid () const |
| Checks if the shader compiled and linked successfully. | |
| ShaderHandle | handle () const |
| Gets the device program handle. | |
| u32 | getProgramId () const |
| Gets the program handle's raw value, for command payloads and sort keys. | |
Static Public Member Functions | |
| static Unique< Shader > | create (GfxDevice &device, const std::string &vertexSrc, const std::string &fragmentSrc, GfxShaderLanguage language=GfxShaderLanguage::GLSL_ES300) |
| Creates a shader from source code strings. | |
| static Unique< Shader > | createWithBindings (GfxDevice &device, const std::string &vertexSrc, const std::string &fragmentSrc, std::initializer_list< AttribBinding > bindings, GfxShaderLanguage language=GfxShaderLanguage::GLSL_ES300, bool deferLink=false) |
| Creates a shader with explicit attribute bindings applied before linking. | |
| static Unique< Shader > | createFromFile (GfxDevice &device, const std::string &vertexPath, const std::string &fragmentPath) |
| Creates a shader from file paths. | |
| static ShaderCompileOutcome | createEx (GfxDevice &device, const std::string &vertexSrc, const std::string &fragmentSrc, std::initializer_list< AttribBinding > bindings={}, GfxShaderLanguage language=GfxShaderLanguage::GLSL_ES300, bool deferLink=false) |
| Creates a shader and exposes the driver log on failure. | |
GPU shader program for rendering.
Encapsulates an OpenGL/WebGL shader program consisting of a vertex shader and fragment shader. Provides uniform setting with location caching for performance.
Definition at line 86 of file Shader.hpp.
|
default |
Referenced by Shader(), Shader(), operator=(), operator=(), and whenLinked().
| esengine::Shader::~Shader | ( | ) |
Definition at line 34 of file Shader.cpp.
References esengine::Invalid.
|
delete |
References Shader().
|
noexcept |
Definition at line 47 of file Shader.cpp.
References Shader(), and esengine::Invalid.
| void esengine::Shader::adoptDrawParams | ( | DrawParamsLayout | layout | ) |
Adopts the layout rewriteLooseUniforms produced for this program.
Allocates the zeroed CPU shadow, so unset members read 0 — the same value their loose-uniform ancestors read. From here on the name-based setUniform overloads write into the shadow instead of issuing loose uniform uploads; commitParams() flushes it.
Definition at line 371 of file Shader.cpp.
References esengine::DRAW_PARAMS_FALLBACK_SIZE, and ES_LOG_WARN.
| void esengine::Shader::bind | ( | ) | const |
Binds the shader for rendering.
Definition at line 151 of file Shader.cpp.
Referenced by esengine::ParticlePlugin::init(), and esengine::MaterialStore::seedSamplers().
| void esengine::Shader::commitParams | ( | ) |
Uploads the shadow (when dirty) and binds this shader's params UBO at DRAW_PARAMS_BINDING.
Call before any draw with this shader — the binding slot is shared, so the previous committer's buffer is bound otherwise. No-op for shaders without a DrawParams block.
Definition at line 382 of file Shader.cpp.
References esengine::DRAW_PARAMS_BINDING, esengine::Invalid, esengine::GfxContent::retained(), and esengine::Uniform.
Referenced by esengine::draw_mesh(), esengine::draw_meshWithUniforms(), esengine::PostProcessPipeline::drawSelectionGround(), esengine::PostProcessPipeline::drawSelectionOutline(), esengine::PostProcessPipeline::encodeRgbm(), esengine::PostProcessPipeline::grabDepth(), and esengine::PostProcessPipeline::grabScene().
|
static |
Creates a shader from source code strings.
| vertexSrc | Vertex shader GLSL source |
| fragmentSrc | Fragment shader GLSL source |
Definition at line 90 of file Shader.cpp.
References language(), and esengine::makeUnique().
Referenced by createFromFile(), and esengine::resource::ResourceManager::createShader().
|
static |
Creates a shader and exposes the driver log on failure.
Same behaviour as createWithBindings but returns a ShaderCompileOutcome so callers (notably ShaderLoader) can remap the GL log back to the original .esshader file and line numbers.
Definition at line 326 of file Shader.cpp.
References esengine::ShaderCompileOutcome::failedStage, language(), esengine::ShaderCompileOutcome::log, esengine::makeUnique(), and esengine::ShaderCompileOutcome::shader.
Referenced by esengine::resource::ResourceManager::createShader().
|
static |
Creates a shader from file paths.
| vertexPath | Path to vertex shader file |
| fragmentPath | Path to fragment shader file |
Definition at line 112 of file Shader.cpp.
References create(), and ES_LOG_ERROR.
Referenced by esengine::resource::ResourceManager::loadShader().
|
static |
Creates a shader with explicit attribute bindings applied before linking.
| vertexSrc | Vertex shader GLSL source |
| fragmentSrc | Fragment shader GLSL source |
| bindings | Attribute location bindings |
Definition at line 100 of file Shader.cpp.
References language(), and esengine::makeUnique().
Referenced by esengine::resource::ResourceManager::createShaderWithBindings().
|
inline |
Returns reflected metadata for every active uniform, populated at link time.
Definition at line 216 of file Shader.hpp.
| i32 esengine::Shader::getAttribLocation | ( | const std::string & | name | ) | const |
Gets the location of a vertex attribute.
| name | Attribute name in shader |
Definition at line 485 of file Shader.cpp.
|
inline |
Gets the program handle's raw value, for command payloads and sort keys.
Definition at line 257 of file Shader.hpp.
Referenced by esengine::RenderFrame::batchProgram(), esengine::RenderFrame::batchProgram(), esengine::RenderFrame::displayProgram(), esengine::ParticlePlugin::init(), esengine::ShapePlugin::init(), esengine::MaterialStore::meshProgram(), esengine::MaterialStore::prepassCoverageProgram(), and esengine::MaterialStore::shadowProgram().
| i32 esengine::Shader::getUniformLocation | ( | const std::string & | name | ) | const |
Definition at line 360 of file Shader.cpp.
Referenced by setUniform(), setUniform(), setUniform(), setUniform(), setUniform(), setUniform(), and setUniform().
|
inline |
Gets the device program handle.
Definition at line 254 of file Shader.hpp.
Referenced by esengine::applyMeshPipeline(), esengine::PostProcessPipeline::canDrawMaterialOver(), and esengine::ImmediateDraw::init().
|
inline |
True when this program carries a DrawParams block.
Definition at line 232 of file Shader.hpp.
| bool esengine::Shader::hasUniform | ( | const std::string & | name | ) | const |
True if the linked program declares this uniform.
Silent probe (no "not found" warning), for call sites that intentionally supply a superset of uniforms — e.g. the post-process pipeline applies a whole effect's uniform set to each of its sub-pass shaders, which each use only a subset.
Definition at line 364 of file Shader.cpp.
Referenced by esengine::PostProcessPipeline::drawMaterialOver(), esengine::PostProcessPipeline::drawSelectionGround(), esengine::PostProcessPipeline::drawSelectionOutline(), esengine::PostProcessPipeline::encodeRgbm(), esengine::PostProcessPipeline::grabDepth(), esengine::PostProcessPipeline::grabScene(), and esengine::MaterialStore::seedSamplers().
|
inline |
Checks if the shader compiled and linked successfully.
Definition at line 251 of file Shader.hpp.
References esengine::Invalid.
Referenced by esengine::ImmediateDraw::init(), esengine::ParticlePlugin::init(), esengine::MaterialStore::prepassCoverageProgram(), and esengine::MaterialStore::shadowProgram().
|
inline |
The source language this program was compiled from.
Definition at line 126 of file Shader.hpp.
Referenced by create(), createEx(), createWithBindings(), esengine::PostProcessPipeline::drawMaterialOver(), esengine::ParticlePlugin::init(), operator=(), and esengine::MaterialStore::seedSamplers().
References Shader(), esengine::GLSL_ES300, and language().
Definition at line 65 of file Shader.cpp.
References Shader(), and esengine::Invalid.
| void esengine::Shader::setUniform | ( | const std::string & | name, |
| const glm::mat3 & | value ) const |
Definition at line 447 of file Shader.cpp.
References getUniformLocation(), and esengine::Mat3.
| void esengine::Shader::setUniform | ( | const std::string & | name, |
| const glm::mat4 & | value ) const |
Definition at line 452 of file Shader.cpp.
References getUniformLocation(), and esengine::Mat4.
| void esengine::Shader::setUniform | ( | const std::string & | name, |
| const glm::vec2 & | value ) const |
Definition at line 432 of file Shader.cpp.
References getUniformLocation(), and esengine::Vec2.
| void esengine::Shader::setUniform | ( | const std::string & | name, |
| const glm::vec3 & | value ) const |
Definition at line 437 of file Shader.cpp.
References getUniformLocation(), and esengine::Vec3.
| void esengine::Shader::setUniform | ( | const std::string & | name, |
| const glm::vec4 & | value ) const |
Definition at line 442 of file Shader.cpp.
References getUniformLocation(), and esengine::Vec4.
| void esengine::Shader::setUniform | ( | const std::string & | name, |
| f32 | value ) const |
Definition at line 427 of file Shader.cpp.
References esengine::Float, and getUniformLocation().
| void esengine::Shader::setUniform | ( | const std::string & | name, |
| i32 | value ) const |
Sets an integer uniform.
| name | Uniform name in shader |
| value | Integer value |
Definition at line 422 of file Shader.cpp.
References getUniformLocation(), and esengine::Int.
Referenced by esengine::draw_mesh(), esengine::draw_meshWithUniforms(), esengine::PostProcessPipeline::drawMaterialOver(), esengine::PostProcessPipeline::drawSelectionGround(), esengine::PostProcessPipeline::drawSelectionOutline(), esengine::PostProcessPipeline::encodeRgbm(), esengine::PostProcessPipeline::grabDepth(), esengine::PostProcessPipeline::grabScene(), esengine::ParticlePlugin::init(), and esengine::MaterialStore::seedSamplers().
| void esengine::Shader::setUniform | ( | i32 | location, |
| const glm::mat3 & | value ) const |
Definition at line 477 of file Shader.cpp.
| void esengine::Shader::setUniform | ( | i32 | location, |
| const glm::mat4 & | value ) const |
Definition at line 481 of file Shader.cpp.
| void esengine::Shader::setUniform | ( | i32 | location, |
| const glm::vec2 & | value ) const |
Definition at line 465 of file Shader.cpp.
| void esengine::Shader::setUniform | ( | i32 | location, |
| const glm::vec3 & | value ) const |
Definition at line 469 of file Shader.cpp.
| void esengine::Shader::setUniform | ( | i32 | location, |
| const glm::vec4 & | value ) const |
Definition at line 473 of file Shader.cpp.
Definition at line 461 of file Shader.cpp.
Definition at line 457 of file Shader.cpp.
| void esengine::Shader::unbind | ( | ) | const |
Unbinds the shader.
Definition at line 173 of file Shader.cpp.
References esengine::Invalid.
Referenced by esengine::ParticlePlugin::init(), and esengine::MaterialStore::seedSamplers().
| void esengine::Shader::whenLinked | ( | std::function< void(Shader &)> | fn | ) |
Runs fn on this shader once it has linked: at once for one that has.
What is done to a program only after it links (a sampler pinned to its unit) is handed here, so a shader made with deferLink is not waited for just to be finished.
Definition at line 164 of file Shader.cpp.
References Shader().
Referenced by esengine::ParticlePlugin::init(), and esengine::MaterialStore::seedSamplers().