Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
Shader.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
16
17#include "./Shader.hpp"
18#include "./GfxDevice.hpp"
26#include "../../core/Log.hpp"
27
28#include <cstring>
29#include <cstdio>
30#include <vector>
31
32namespace esengine {
33
35 if (device_) {
36 if (program_ != ShaderHandle::Invalid) {
37 device_->deleteProgram(program_);
38 program_ = ShaderHandle::Invalid;
39 }
40 if (paramsUbo_ != BufferHandle::Invalid) {
41 device_->deleteBuffer(paramsUbo_);
42 paramsUbo_ = BufferHandle::Invalid;
43 }
44 }
45}
46
47Shader::Shader(Shader&& other) noexcept
48 : device_(other.device_)
49 , program_(other.program_)
50 , uniformCache_(std::move(other.uniformCache_))
51 , attribCache_(std::move(other.attribCache_))
52 , activeUniforms_(std::move(other.activeUniforms_))
53 , drawParams_(std::move(other.drawParams_))
54 , paramsShadow_(std::move(other.paramsShadow_))
55 , paramsDirty_(other.paramsDirty_)
56 , paramsUbo_(other.paramsUbo_) {
57 linked_ = other.linked_;
58 afterLink_ = std::move(other.afterLink_);
59 other.program_ = ShaderHandle::Invalid;
60 other.paramsUbo_ = BufferHandle::Invalid;
61 other.linked_ = true;
62 if (!linked_ && device_) device_->onProgramLinked(program_, [this] { finishLink(); });
63}
64
65Shader& Shader::operator=(Shader&& other) noexcept {
66 if (this != &other) {
67 if (device_) {
68 if (program_ != ShaderHandle::Invalid) device_->deleteProgram(program_);
69 if (paramsUbo_ != BufferHandle::Invalid) device_->deleteBuffer(paramsUbo_);
70 }
71 device_ = other.device_;
72 program_ = other.program_;
73 uniformCache_ = std::move(other.uniformCache_);
74 attribCache_ = std::move(other.attribCache_);
75 activeUniforms_ = std::move(other.activeUniforms_);
76 drawParams_ = std::move(other.drawParams_);
77 paramsShadow_ = std::move(other.paramsShadow_);
78 paramsDirty_ = other.paramsDirty_;
79 paramsUbo_ = other.paramsUbo_;
80 linked_ = other.linked_;
81 afterLink_ = std::move(other.afterLink_);
82 other.program_ = ShaderHandle::Invalid;
83 other.paramsUbo_ = BufferHandle::Invalid;
84 other.linked_ = true;
85 if (!linked_ && device_) device_->onProgramLinked(program_, [this] { finishLink(); });
86 }
87 return *this;
88}
89
90Unique<Shader> Shader::create(GfxDevice& device, const std::string& vertexSrc, const std::string& fragmentSrc,
92 auto shader = makeUnique<Shader>();
93 shader->device_ = &device;
94 if (!shader->compile(vertexSrc, fragmentSrc, {}, nullptr, nullptr, language)) {
95 return nullptr;
96 }
97 return shader;
98}
99
101 const std::string& vertexSrc, const std::string& fragmentSrc,
102 std::initializer_list<AttribBinding> bindings,
103 GfxShaderLanguage language, bool deferLink) {
104 auto shader = makeUnique<Shader>();
105 shader->device_ = &device;
106 if (!shader->compile(vertexSrc, fragmentSrc, bindings, nullptr, nullptr, language, deferLink)) {
107 return nullptr;
108 }
109 return shader;
110}
111
113 const std::string& vertexPath, const std::string& fragmentPath) {
114 auto readFile = [](const std::string& filepath) -> std::string {
115 std::FILE* file = std::fopen(filepath.c_str(), "rb");
116 if (!file) {
117 ES_LOG_ERROR("Failed to open shader file: {}", filepath);
118 return "";
119 }
120
121 std::string content;
122 char chunk[4096];
123 usize n;
124 while ((n = std::fread(chunk, 1, sizeof chunk, file)) > 0) content.append(chunk, n);
125 const bool failed = std::ferror(file) != 0;
126 std::fclose(file);
127
128 if (failed) {
129 ES_LOG_ERROR("Failed to read shader file: {}", filepath);
130 return "";
131 }
132 if (content.empty()) {
133 ES_LOG_ERROR("Shader file is empty: {}", filepath);
134 return "";
135 }
136
137 return content;
138 };
139
140 std::string vertexSrc = readFile(vertexPath);
141 std::string fragmentSrc = readFile(fragmentPath);
142
143 if (vertexSrc.empty() || fragmentSrc.empty()) {
144 ES_LOG_ERROR("Failed to load shader files: vertex={}, fragment={}", vertexPath, fragmentPath);
145 return nullptr;
146 }
147
148 return create(device, vertexSrc, fragmentSrc);
149}
150
151void Shader::bind() const {
152 // Direct program bind for setup-time use (e.g. seeding a sampler uniform). Per-frame
153 // rendering binds programs through GfxDevice::setPipeline, not here.
154 ensureLinked();
155 if (device_) device_->useProgram(program_);
156}
157
158void Shader::ensureLinked() const {
159 if (linked_ || !device_) return;
160 // The device runs finishLink as the program links; a program that failed to never does, and is not waited for twice.
161 if (!device_->finishProgram(program_)) linked_ = true;
162}
163
164void Shader::whenLinked(std::function<void(Shader&)> fn) {
165 if (!fn) return;
166 if (linked_) {
167 fn(*this);
168 return;
169 }
170 afterLink_.push_back(std::move(fn));
171}
172
173void Shader::unbind() const {
174 if (device_) device_->useProgram(ShaderHandle::Invalid);
175}
176
177bool Shader::compile(const std::string& vertexSrc, const std::string& fragmentSrc,
178 const std::vector<AttribBinding>& bindings,
179 std::string* outLog,
180 ShaderStageFailure* outFailedStage,
181 GfxShaderLanguage language,
182 bool deferLink) {
183 language_ = language;
184 linked_ = false;
185
186 // Fail fast on a language the backend cannot compile, before any GPU call —
187 // the caller gets a diagnostic instead of a backend-specific compile error.
188 if (!device_->supportsShaderLanguage(language)) {
189 if (outLog) *outLog = "backend does not support the shader source language";
190 if (outFailedStage) *outFailedStage = ShaderStageFailure::Vertex;
191 ES_LOG_ERROR("Shader::compile: backend does not support the requested shader language");
192 return false;
193 }
194
195 std::vector<GfxAttribBinding> binds;
196 binds.reserve(bindings.size());
197 for (const auto& b : bindings) {
198 binds.push_back(GfxAttribBinding{b.index, b.name});
199 }
200
202 GfxShaderSource source{language, vertexSrc.c_str(), fragmentSrc.c_str()};
203 source.deferLink = deferLink && device_->supportsDeferredLink();
204 program_ = device_->createProgram(source,
205 binds.data(), static_cast<u32>(binds.size()),
206 outLog, &stage);
207
208 if (outFailedStage) {
209 switch (stage) {
210 case GfxShaderStage::Vertex: *outFailedStage = ShaderStageFailure::Vertex; break;
211 case GfxShaderStage::Fragment: *outFailedStage = ShaderStageFailure::Fragment; break;
212 case GfxShaderStage::Link: *outFailedStage = ShaderStageFailure::Link; break;
213 case GfxShaderStage::None: *outFailedStage = ShaderStageFailure::None; break;
214 }
215 }
216
217 if (program_ == ShaderHandle::Invalid) {
218 linked_ = true;
219 return false;
220 }
221
222 if (source.deferLink) {
223 // Queued, not waited for: the device finishes it (block bindings, pinned samplers) when something first needs the program.
224 device_->onProgramLinked(program_, [this] { finishLink(); });
225 return true;
226 }
227 finishLink();
228 return true;
229}
230
231void Shader::finishLink() {
232 linked_ = true;
233 reflectActiveUniforms();
234
235 // Link the per-frame constants block to its shared binding point, so the program
236 // reads u_projection from the FrameConstants UBO with no loose uniform upload.
237 // Programs without the block (custom/user shaders) simply skip this.
238 u32 frameBlock = device_->getUniformBlockIndex(program_, FRAME_CONSTANTS_BLOCK);
239 if (frameBlock != GFX_INVALID_UNIFORM_BLOCK) {
240 device_->uniformBlockBinding(program_, frameBlock, FRAME_CONSTANTS_BINDING);
241 }
242
243 // Same for the per-material constants block (ShaderParser auto-generates it for shaders
244 // authored with #pragma param); the render path binds each material's UBO here per draw.
245 u32 materialBlock = device_->getUniformBlockIndex(program_, MATERIAL_CONSTANTS_BLOCK);
246 if (materialBlock != GFX_INVALID_UNIFORM_BLOCK) {
247 device_->uniformBlockBinding(program_, materialBlock, MATERIAL_CONSTANTS_BINDING);
248 }
249
250 // Same for the per-frame 2D light block (ShaderParser injects it for Lit-domain shaders);
251 // the render path uploads + binds the shared LightConstants UBO here once per frame.
252 u32 lightBlock = device_->getUniformBlockIndex(program_, LIGHT_CONSTANTS_BLOCK);
253 if (lightBlock != GFX_INVALID_UNIFORM_BLOCK) {
254 device_->uniformBlockBinding(program_, lightBlock, LIGHT_CONSTANTS_BINDING);
255 }
256
257 // Same for the injected frame clock (u_time).
258 u32 timeBlock = device_->getUniformBlockIndex(program_, TIME_CONSTANTS_BLOCK);
259 if (timeBlock != GFX_INVALID_UNIFORM_BLOCK) {
260 device_->uniformBlockBinding(program_, timeBlock, TIME_CONSTANTS_BINDING);
261 }
262
263 // Same for a skinned mesh's pose, which DrawList rewrites per draw.
264 u32 skinBlock = device_->getUniformBlockIndex(program_, SKIN_CONSTANTS_BLOCK);
265 if (skinBlock != GFX_INVALID_UNIFORM_BLOCK) {
266 device_->uniformBlockBinding(program_, skinBlock, SKIN_CONSTANTS_BINDING);
267 }
268
269 // And the indirect light where this draw stands, which DrawList rewrites per
270 // draw. Every Lit fragment stage declares it — whether a draw STANDS in a
271 // volume is a number in the block, not a variant.
272 u32 probeBlock = device_->getUniformBlockIndex(program_, PROBE_CONSTANTS_BLOCK);
273 if (probeBlock != GFX_INVALID_UNIFORM_BLOCK) {
274 device_->uniformBlockBinding(program_, probeBlock, PROBE_CONSTANTS_BINDING);
275 }
276
277 // And where this draw's objects start in the frame's record texture, which
278 // DrawList rewrites per draw for the same reason.
279 u32 instanceBlock = device_->getUniformBlockIndex(program_, INSTANCE_CONSTANTS_BLOCK);
280 if (instanceBlock != GFX_INVALID_UNIFORM_BLOCK) {
281 device_->uniformBlockBinding(program_, instanceBlock, INSTANCE_CONSTANTS_BINDING);
282 }
283
284 const u32 planarBlock = device_->getUniformBlockIndex(program_, PLANAR_CONSTANTS_BLOCK);
285 if (planarBlock != GFX_INVALID_UNIFORM_BLOCK) {
286 device_->uniformBlockBinding(program_, planarBlock, PLANAR_CONSTANTS_BINDING);
287 }
288
289 // Same for the per-draw params block (rewriteLooseUniforms generates it for
290 // shaders whose loose uniforms were lifted); commitParams binds the UBO.
291 u32 drawParamsBlock = device_->getUniformBlockIndex(program_, DRAW_PARAMS_BLOCK);
292 if (drawParamsBlock != GFX_INVALID_UNIFORM_BLOCK) {
293 device_->uniformBlockBinding(program_, drawParamsBlock, DRAW_PARAMS_BINDING);
294 }
295
296 // Engine-injected samplers sit on fixed units, pinned here because GLSL ES 300
297 // has no layout(binding) and a compile site that forgot one samples slot 0
298 // silently. The last two are read by the VERTEX stage.
299 struct PinnedSampler { const char* name; u32 unit; };
300 static const PinnedSampler kPinned[] = {
310 };
311 bool pinned = false;
312 for (const PinnedSampler& p : kPinned) {
313 if (!hasUniform(p.name)) continue;
314 if (!pinned) { bind(); pinned = true; }
315 setUniform(p.name, static_cast<i32>(p.unit));
316 }
317 if (pinned) unbind();
318
319 ES_LOG_DEBUG("Shader compiled successfully (program handle: {}, active uniforms: {})",
320 static_cast<u32>(program_), activeUniforms_.size());
321 auto after = std::move(afterLink_);
322 afterLink_.clear();
323 for (auto& fn : after) fn(*this);
324}
325
327 const std::string& vertexSrc,
328 const std::string& fragmentSrc,
329 std::initializer_list<AttribBinding> bindings,
331 bool deferLink) {
332 ShaderCompileOutcome outcome;
333 auto shader = makeUnique<Shader>();
334 shader->device_ = &device;
335 if (!shader->compile(vertexSrc, fragmentSrc, bindings, &outcome.log, &outcome.failedStage,
336 language, deferLink)) {
337 return outcome;
338 }
339 outcome.shader = std::move(shader);
340 return outcome;
341}
342
343void Shader::reflectActiveUniforms() {
344 activeUniforms_ = device_->getActiveUniforms(program_);
345}
346
347i32 Shader::cacheUniformLocation(const std::string& name, bool warnOnMiss) const {
348 ensureLinked();
349 auto [it, inserted] = uniformCache_.emplace(name, -1);
350 if (inserted) {
351 it->second = device_->getUniformLocation(program_, name.c_str());
352 if (it->second < 0 && warnOnMiss) {
353 ES_LOG_WARN("Shader {}: uniform '{}' not found (typo or optimized out)",
354 static_cast<u32>(program_), name);
355 }
356 }
357 return it->second;
358}
359
360i32 Shader::getUniformLocation(const std::string& name) const {
361 return cacheUniformLocation(name, /*warnOnMiss=*/true);
362}
363
364bool Shader::hasUniform(const std::string& name) const {
365 // A lifted uniform is a block member: it has no location, but callers that
366 // guard with hasUniform (e.g. the post-process pass loop) must still see it.
367 if (drawParams_.find(name) != nullptr) return true;
368 return cacheUniformLocation(name, /*warnOnMiss=*/false) >= 0;
369}
370
372 drawParams_ = std::move(layout);
373 paramsShadow_.assign(drawParams_.blockSize, 0);
374 paramsDirty_ = false; // commitParams creates the UBO from the zeroed shadow
375 if (drawParams_.blockSize > DRAW_PARAMS_FALLBACK_SIZE) {
376 ES_LOG_WARN("Shader {}: DrawParams block ({} bytes) exceeds the frame fallback ({}); "
377 "draws that skip commitParams may be rejected",
378 static_cast<u32>(program_), drawParams_.blockSize, DRAW_PARAMS_FALLBACK_SIZE);
379 }
380}
381
383 if (drawParams_.empty() || !device_) return;
384 if (paramsUbo_ == BufferHandle::Invalid) {
385 paramsUbo_ = device_->createBuffer(
386 {GfxBufferUsage::Uniform, drawParams_.blockSize, /*dynamic=*/true}, GfxContent::retained(),
387 paramsShadow_.data());
388 paramsDirty_ = false;
389 } else if (paramsDirty_) {
390 device_->updateBuffer(paramsUbo_, 0, paramsShadow_.data(), drawParams_.blockSize);
391 paramsDirty_ = false;
392 }
393 // Rebind even when clean: the slot is shared, another shader's commit (or
394 // the frame fallback) owns it otherwise.
395 device_->setUniformBuffer(DRAW_PARAMS_BINDING, paramsUbo_);
396}
397
398bool Shader::writeParam(const std::string& name, DrawParamType type, const void* src) const {
399 const DrawParamSlot* slot = drawParams_.find(name);
400 if (slot == nullptr) return false;
401 if (slot->type != type) {
402 ES_LOG_WARN("Shader {}: setUniform('{}') type mismatch with its DrawParams slot",
403 static_cast<u32>(program_), name);
404 return true; // consumed: the name has no loose location to fall back to
405 }
406 u8* dst = paramsShadow_.data() + slot->offset;
407 if (type == DrawParamType::Mat3) {
408 // std140 mat3 columns have vec4 stride; glm::mat3 is 3 packed vec3s.
409 const f32* m = static_cast<const f32*>(src);
410 for (u32 col = 0; col < 3; ++col) {
411 std::memcpy(dst + col * 16, m + col * 3, 3 * sizeof(f32));
412 }
413 } else {
414 u32 size = 0, align = 0;
415 drawParamSizeAlign(type, size, align);
416 std::memcpy(dst, src, size);
417 }
418 paramsDirty_ = true;
419 return true;
420}
421
422void Shader::setUniform(const std::string& name, i32 value) const {
423 if (writeParam(name, DrawParamType::Int, &value)) return;
424 device_->setUniform1i(getUniformLocation(name), value);
425}
426
427void Shader::setUniform(const std::string& name, f32 value) const {
428 if (writeParam(name, DrawParamType::Float, &value)) return;
429 device_->setUniform1f(getUniformLocation(name), value);
430}
431
432void Shader::setUniform(const std::string& name, const glm::vec2& value) const {
433 if (writeParam(name, DrawParamType::Vec2, glm::value_ptr(value))) return;
434 device_->setUniform2f(getUniformLocation(name), value.x, value.y);
435}
436
437void Shader::setUniform(const std::string& name, const glm::vec3& value) const {
438 if (writeParam(name, DrawParamType::Vec3, glm::value_ptr(value))) return;
439 device_->setUniform3f(getUniformLocation(name), value.x, value.y, value.z);
440}
441
442void Shader::setUniform(const std::string& name, const glm::vec4& value) const {
443 if (writeParam(name, DrawParamType::Vec4, glm::value_ptr(value))) return;
444 device_->setUniform4f(getUniformLocation(name), value.x, value.y, value.z, value.w);
445}
446
447void Shader::setUniform(const std::string& name, const glm::mat3& value) const {
448 if (writeParam(name, DrawParamType::Mat3, glm::value_ptr(value))) return;
449 device_->setUniformMat3(getUniformLocation(name), glm::value_ptr(value));
450}
451
452void Shader::setUniform(const std::string& name, const glm::mat4& value) const {
453 if (writeParam(name, DrawParamType::Mat4, glm::value_ptr(value))) return;
454 device_->setUniformMat4(getUniformLocation(name), glm::value_ptr(value));
455}
456
457void Shader::setUniform(i32 location, i32 value) const {
458 device_->setUniform1i(location, value);
459}
460
461void Shader::setUniform(i32 location, f32 value) const {
462 device_->setUniform1f(location, value);
463}
464
465void Shader::setUniform(i32 location, const glm::vec2& value) const {
466 device_->setUniform2f(location, value.x, value.y);
467}
468
469void Shader::setUniform(i32 location, const glm::vec3& value) const {
470 device_->setUniform3f(location, value.x, value.y, value.z);
471}
472
473void Shader::setUniform(i32 location, const glm::vec4& value) const {
474 device_->setUniform4f(location, value.x, value.y, value.z, value.w);
475}
476
477void Shader::setUniform(i32 location, const glm::mat3& value) const {
478 device_->setUniformMat3(location, glm::value_ptr(value));
479}
480
481void Shader::setUniform(i32 location, const glm::mat4& value) const {
482 device_->setUniformMat4(location, glm::value_ptr(value));
483}
484
485i32 Shader::getAttribLocation(const std::string& name) const {
486 ensureLinked();
487 auto [it, inserted] = attribCache_.emplace(name, -1);
488 if (inserted) {
489 it->second = device_->getAttribLocation(program_, name.c_str());
490 }
491 return it->second;
492}
493
494} // namespace esengine
Per-frame shader constants shared via a single Uniform Buffer Object.
Abstract graphics device interface.
WHERE one draw's entry is in the frame's per-object record texture, and what an entry says.
Per-frame 2D lighting constants — the third tier of the engine's constant-buffer layering (after per-...
Logging utilities for ESEngine.
#define ES_LOG_WARN(...)
Logs a warning message.
Definition Log.hpp:294
#define ES_LOG_ERROR(...)
Logs an error message.
Definition Log.hpp:296
#define ES_LOG_DEBUG(...)
Definition Log.hpp:282
Binding points for per-material shader constants — the second tier of the engine's constant-buffer la...
The indirect light where ONE draw stands, when a grid was baked for it.
GPU shader program abstraction.
The pose one skinned draw is deformed by: a bone matrix per joint.
static constexpr GfxContent retained()
Abstract graphics device interface.
Definition GfxDevice.hpp:75
bool finishProgram(ShaderHandle program)
Waits for program to link if it has not yet. False when it failed to.
i32 getUniformLocation(ShaderHandle program, const char *name)
Gets a uniform location by name, -1 when the linked program has none.
virtual bool supportsShaderLanguage(GfxShaderLanguage language) const =0
Whether this backend compiles language (GL: GLSL ES 300; WebGPU: WGSL).
std::vector< GfxUniformInfo > getActiveUniforms(ShaderHandle program)
Enumerates all active uniforms of a linked shader program.
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.
Definition Shader.cpp:326
Shader()=default
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.
Definition Shader.cpp:90
static Unique< Shader > createFromFile(GfxDevice &device, const std::string &vertexPath, const std::string &fragmentPath)
Creates a shader from file paths.
Definition Shader.cpp:112
void bind() const
Binds the shader for rendering.
Definition Shader.cpp:151
void commitParams()
Uploads the shadow (when dirty) and binds this shader's params UBO at DRAW_PARAMS_BINDING.
Definition Shader.cpp:382
GfxShaderLanguage language() const
The source language this program was compiled from.
Definition Shader.hpp:126
void adoptDrawParams(DrawParamsLayout layout)
Adopts the layout rewriteLooseUniforms produced for this program.
Definition Shader.cpp:371
void whenLinked(std::function< void(Shader &)> fn)
Runs fn on this shader once it has linked: at once for one that has.
Definition Shader.cpp:164
void setUniform(const std::string &name, i32 value) const
Sets an integer uniform.
Definition Shader.cpp:422
Shader & operator=(const Shader &)=delete
i32 getAttribLocation(const std::string &name) const
Gets the location of a vertex attribute.
Definition Shader.cpp:485
bool hasUniform(const std::string &name) const
True if the linked program declares this uniform.
Definition Shader.cpp:364
i32 getUniformLocation(const std::string &name) const
Definition Shader.cpp:360
void unbind() const
Unbinds the shader.
Definition Shader.cpp:173
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.
Definition Shader.cpp:100
DrawParamType
GLSL type of one lifted uniform (the subset the rewriter supports).
constexpr const char * SKIN_CONSTANTS_BLOCK
GLSL block name; must match the shader's declaration + Shader::compile lookup.
constexpr const char * MATERIAL_CONSTANTS_BLOCK
GLSL block name; must match ShaderParser's generated block + Shader::compile lookup.
static constexpr u32 GFX_INVALID_UNIFORM_BLOCK
Sentinel returned by getUniformBlockIndex when a program has no such block (GL_INVALID_INDEX).
Definition GfxDevice.hpp:44
constexpr Unique< T > makeUnique(Args &&... args)
Creates a Unique pointer with the given arguments.
Definition Types.hpp:99
std::int32_t i32
Signed 32-bit integer.
Definition Types.hpp:54
constexpr u32 FRAME_CONSTANTS_BINDING
Indexed uniform binding point the FrameConstants block is bound to.
constexpr const char * FRAME_CONSTANTS_BLOCK
GLSL block name; must match the shader declarations and Shader::compile lookup.
constexpr const char * LIGHTMAP_SAMPLER
The baked-light atlas, and the unit a lightmapped mesh samples it from.
constexpr const char * MORPH_DELTA_SAMPLER
The sampler a mesh's morph deltas arrive through, and the unit it is pinned to.
constexpr u32 SHADOW_2D_TEXTURE_UNIT
constexpr const char * PROBE_GRID_SAMPLER
The frame's probe atlas, read per pixel, on the bake's unit.
constexpr u32 LIGHTMAP_TEXTURE_UNIT
std::size_t usize
Size type for indexing and sizes.
Definition Types.hpp:64
constexpr u32 SHADOW_MAP_TEXTURE_UNIT
constexpr u32 WATER_SUN_TEXTURE_UNIT
GfxShaderLanguage
Shader source language a backend consumes.
Definition GfxEnums.hpp:654
constexpr u32 SKIN_CONSTANTS_BINDING
Indexed UBO binding point for the per-draw SkinConstants block.
constexpr u32 PROBE_CONSTANTS_BINDING
Indexed UBO binding point for the per-draw ProbeConstants block.
constexpr u32 MORPH_DELTA_TEXTURE_UNIT
GfxShaderStage
Which pipeline stage rejected a program during createProgram().
Definition GfxEnums.hpp:736
constexpr const char * PROBE_CONSTANTS_BLOCK
GLSL block name; must match the injected Lit header + Shader::compile lookup.
constexpr const char * INSTANCE_DATA_SAMPLER
GLSL name of the record texture; pinned to its unit by Shader::compile.
constexpr u32 LIGHT_CONSTANTS_BINDING
Indexed UBO binding point for the per-frame LightConstants block.
constexpr const char * WATER_SUN_SAMPLER
constexpr u32 DRAW_PARAMS_FALLBACK_SIZE
Size of the zeroed fallback UBO RenderContext binds at DRAW_PARAMS_BINDING each frame.
constexpr u32 TIME_CONSTANTS_BINDING
std::unique_ptr< T > Unique
Unique ownership smart pointer.
Definition Types.hpp:75
constexpr const char * SHADOW_MAP_SAMPLER
The injected shadow-map sampler, and the texture unit Shader::compile pins it to.
constexpr u32 MATERIAL_CONSTANTS_BINDING
Indexed UBO binding point for the per-material MaterialConstants block.
constexpr const char * SHADOW_2D_SAMPLER
The 2D shadow mask, and the texture unit every Lit shader samples it from.
constexpr const char * ENV_MAP_SAMPLER
The injected reflection sampler, one unit past the shadow map's.
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
static constexpr u32 MESH_INSTANCE_TEXTURE_UNIT
Definition GfxEnums.hpp:133
std::uint8_t u8
Unsigned 8-bit integer.
Definition Types.hpp:41
constexpr const char * DRAW_PARAMS_BLOCK
GLSL block name; must match the rewriter's generated block + Shader::compile lookup.
constexpr u32 SHAPE_2D_TEXTURE_UNIT
constexpr u32 DRAW_PARAMS_BINDING
Indexed UBO binding point for the per-draw DrawParams block. (0 = FrameConstants, 1 = MaterialConstan...
constexpr const char * LIGHT_CONSTANTS_BLOCK
GLSL block name; must match ShaderParser's injected block + Shader::compile lookup.
ShaderStageFailure
Which pipeline stage rejected a shader during compile/link.
Definition Shader.hpp:44
constexpr u32 ENV_MAP_TEXTURE_UNIT
constexpr const char * TIME_CONSTANTS_BLOCK
constexpr const char * INSTANCE_CONSTANTS_BLOCK
GLSL block name; must match the injected mesh header + Shader::compile lookup.
constexpr u32 PLANAR_CONSTANTS_BINDING
constexpr const char * PLANAR_CONSTANTS_BLOCK
void drawParamSizeAlign(DrawParamType t, u32 &size, u32 &align)
std140 size/base-alignment of a supported param type.
constexpr const char * SHAPE_2D_SAMPLER
The 2D light-shape mask, and the unit below the shadow mask's.
constexpr u32 INSTANCE_CONSTANTS_BINDING
Indexed UBO binding point for the per-draw InstanceConstants block. Nine and not four: slot 4 is DRAW...
float f32
32-bit floating point
Definition Types.hpp:59
One lifted uniform's slot in a shader's std140 DrawParams block.
u32 offset
std140 byte offset within the block.
A shader's DrawParams layout: lifted members + 16-aligned block size.
const DrawParamSlot * find(const std::string &name) const
Result returned by Shader::createEx when you need the raw driver log.
Definition Shader.hpp:62
ShaderStageFailure failedStage
Definition Shader.hpp:64
Unique< Shader > shader
Definition Shader.hpp:63