28#include <initializer_list>
31#include <unordered_map>
120 const std::string& vertexSrc,
const std::string& fragmentSrc,
121 std::initializer_list<AttribBinding> bindings,
123 bool deferLink =
false);
135 const std::string& vertexPath,
const std::string& fragmentPath);
145 const std::string& vertexSrc,
146 const std::string& fragmentSrc,
147 std::initializer_list<AttribBinding> bindings = {},
149 bool deferLink =
false);
179 void setUniform(
const std::string& name,
const glm::vec2& value)
const;
180 void setUniform(
const std::string& name,
const glm::vec3& value)
const;
181 void setUniform(
const std::string& name,
const glm::vec4& value)
const;
182 void setUniform(
const std::string& name,
const glm::mat3& value)
const;
183 void setUniform(
const std::string& name,
const glm::mat4& value)
const;
213 bool hasUniform(
const std::string& name)
const;
216 const std::vector<GfxUniformInfo>&
getActiveUniforms()
const { ensureLinked();
return activeUniforms_; }
266 bool compile(
const std::string& vertexSrc,
const std::string& fragmentSrc,
267 const std::vector<AttribBinding>& bindings = {},
268 std::string* outLog =
nullptr,
271 bool deferLink =
false);
273 void reflectActiveUniforms();
278 void ensureLinked()
const;
281 i32 cacheUniformLocation(
const std::string& name,
bool warnOnMiss)
const;
285 bool writeParam(
const std::string& name,
DrawParamType type,
const void* src)
const;
287 GfxDevice* device_ =
nullptr;
291 mutable bool linked_ =
true;
292 std::vector<std::function<void(
Shader&)>> afterLink_;
295 mutable std::unordered_map<std::string, i32> uniformCache_;
296 mutable std::unordered_map<std::string, i32> attribCache_;
297 std::vector<GfxUniformInfo> activeUniforms_;
299 DrawParamsLayout drawParams_;
302 mutable std::vector<u8> paramsShadow_;
303 mutable bool paramsDirty_ =
false;
Per-draw shader parameter block — the UBO home for what used to be loose uniforms.
Backend-agnostic graphics enumerations.
Math utilities and GLM configuration for ESEngine.
Core type definitions and utilities for ESEngine.
Abstract graphics device interface.
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.
u32 getProgramId() const
Gets the program handle's raw value, for command payloads and sort keys.
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 > createFromFile(GfxDevice &device, const std::string &vertexPath, const std::string &fragmentPath)
Creates a shader from file paths.
void bind() const
Binds the shader for rendering.
void commitParams()
Uploads the shadow (when dirty) and binds this shader's params UBO at DRAW_PARAMS_BINDING.
GfxShaderLanguage language() const
The source language this program was compiled from.
void adoptDrawParams(DrawParamsLayout layout)
Adopts the layout rewriteLooseUniforms produced for this program.
void whenLinked(std::function< void(Shader &)> fn)
Runs fn on this shader once it has linked: at once for one that has.
bool hasDrawParams() const
True when this program carries a DrawParams block.
void setUniform(const std::string &name, i32 value) const
Sets an integer uniform.
Shader & operator=(const Shader &)=delete
i32 getAttribLocation(const std::string &name) const
Gets the location of a vertex attribute.
bool isValid() const
Checks if the shader compiled and linked successfully.
Shader(const Shader &)=delete
bool hasUniform(const std::string &name) const
True if the linked program declares this uniform.
i32 getUniformLocation(const std::string &name) const
void unbind() const
Unbinds the shader.
const std::vector< GfxUniformInfo > & getActiveUniforms() const
Returns reflected metadata for every active uniform, populated at link time.
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.
ShaderHandle handle() const
Gets the device program handle.
DrawParamType
GLSL type of one lifted uniform (the subset the rewriter supports).
std::int32_t i32
Signed 32-bit integer.
GfxShaderLanguage
Shader source language a backend consumes.
std::unique_ptr< T > Unique
Unique ownership smart pointer.
std::uint32_t u32
Unsigned 32-bit integer.
std::uint8_t u8
Unsigned 8-bit integer.
ShaderStageFailure
Which pipeline stage rejected a shader during compile/link.
float f32
32-bit floating point
A shader's DrawParams layout: lifted members + 16-aligned block size.
Result returned by Shader::createEx when you need the raw driver log.
ShaderStageFailure failedStage