27#include <glm/gtc/constants.hpp>
28#include <glm/gtc/type_ptr.hpp>
39constexpr glm::vec2 QUAD_LOCAL[4] = {
40 {-0.5f, -0.5f}, {0.5f, -0.5f}, {0.5f, 0.5f}, {-0.5f, 0.5f}
42constexpr glm::vec2 QUAD_UV[4] = {
43 {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}
46constexpr f32 NEAR_CLIP_NUDGE = 1e-4f;
49constexpr u32 INITIAL_INSTANCE_RECORDS = 4096;
52bool clipLineToNearPlane(glm::vec3& from, glm::vec3& to,
const glm::mat4& viewProjection) {
53 const auto side = [&viewProjection](
const glm::vec3& point) {
54 const glm::vec4 clip = viewProjection * glm::vec4(point, 1.0f);
55 return clip.z + clip.w;
57 const f32 fromSide = side(from);
58 const f32 toSide = side(to);
59 if (!std::isfinite(fromSide) || !std::isfinite(toSide))
return false;
60 if (fromSide >= 0.0f && toSide >= 0.0f)
return true;
61 if (fromSide < 0.0f && toSide < 0.0f)
return false;
63 const f32 crossing = fromSide / (fromSide - toSide);
64 const f32 t = fromSide >= 0.0f
65 ? crossing * (1.0f - NEAR_CLIP_NUDGE)
66 : crossing + (1.0f - crossing) * NEAR_CLIP_NUDGE;
67 const glm::vec3 cut = glm::mix(from, to, t);
68 if (fromSide >= 0.0f) to = cut;
74bool screenOffsetPoint(
const glm::mat4& inverseViewProjection,
75 const glm::vec4& clipAnchor,
76 const glm::vec2& offset,
77 f32 viewportWidth,
f32 viewportHeight,
79 const glm::vec4 clip = clipAnchor + glm::vec4(
80 2.0f * offset.x * clipAnchor.w / viewportWidth,
81 2.0f * offset.y * clipAnchor.w / viewportHeight,
83 const glm::vec4
world = inverseViewProjection * clip;
84 if (!std::isfinite(
world.x) || !std::isfinite(
world.y)
85 || !std::isfinite(
world.z) || !std::isfinite(
world.w)
86 || std::abs(
world.w) < 1e-9f) {
89 point = glm::vec3(world) /
world.w;
90 return std::isfinite(point.x) && std::isfinite(point.y) && std::isfinite(point.z);
99 , resource_manager_(resource_manager)
110 if (initialized_)
return;
113 white_texture_id_ = context_.getWhiteTextureId();
116 const auto target = resource_manager_.preferredShaderTarget();
121 {{0,
"a_position"}, {1,
"a_color"}, {2,
"a_texCoord"}},
122 resource_manager_.preferredShaderLanguage());
123 batch_shader_ref_ = handle;
124 Shader* shader = resource_manager_.getShader(handle);
125 if (shader && shader->
isValid()) {
126 batch_shader_ = shader->
handle();
127 device_.useProgram(batch_shader_);
130 for (
i32 i = 0; i < 8; ++i) {
131 i32 loc = device_.getUniformLocation(batch_shader_, (
"u_textures[" + std::to_string(i) +
"]").c_str());
132 if (loc >= 0) device_.setUniform1i(loc, i);
140 base_desc_.
program = batch_shader_;
143 base_desc_.blendEnabled =
true;
144 base_desc_.depthTest =
false;
145 base_desc_.depthWrite =
true;
147 base_desc_.cullEnabled =
false;
148 current_desc_ = base_desc_;
149 pipeline_ = device_.createPipeline(current_desc_);
151 ES_LOG_ERROR(
"ImmediateDraw: failed to create batch shader");
158 if (!initialized_)
return;
159 for (
auto& mesh : meshes_) {
165 doomedMeshes_.clear();
169 instanceCapacity_ = 0;
173 instancesUploaded_ = 0;
176 initialized_ =
false;
181 if (!initialized_)
return;
184 viewportWidth_ =
static_cast<f32>(std::max(viewportWidth, 1));
185 viewportHeight_ =
static_cast<f32>(std::max(viewportHeight, 1));
192 device_.invalidatePipelineCache();
197 const glm::vec4 nearPoint = inverseViewProjection_ * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);
198 const glm::vec4 farPoint = inverseViewProjection_ * glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);
199 const glm::vec3 forward = glm::vec3(farPoint) / farPoint.w - glm::vec3(nearPoint) / nearPoint.w;
200 if (glm::length(forward) > 0.0001f) viewForward_ = glm::normalize(forward);
203 deferredBatches_.clear();
204 recordedIndices_ = 0;
206 instancesUploaded_ = 0;
209 for (
const u32 id : doomedMeshes_) {
210 ResidentMesh& mesh = meshes_[
id - 1];
214 freeMeshes_.push_back(
id);
216 doomedMeshes_.clear();
218 deferredGeometry_ =
false;
219 currentTexture_ = white_texture_id_;
220 pendingGeometry_ =
false;
228 ditherPhase_ =
false;
229 if (!(current_desc_ == base_desc_)) {
230 current_desc_ = base_desc_;
231 pipeline_ = device_.createPipeline(current_desc_);
237 ditherScratch_.assign(vertices, vertices + count);
239 for (
BatchVertex& v : ditherScratch_) v.texIndex =
static_cast<f32>(
static_cast<i32>(v.texIndex) | bits);
244 if (current_desc_.blend == mode)
return;
245 if (pendingGeometry_ || pendingRun_.count)
flush();
246 current_desc_.blend = mode;
247 pipeline_ = device_.createPipeline(current_desc_);
255 if (current_desc_.depthTest == test && current_desc_.depthWrite == write)
return;
256 if (pendingGeometry_ || pendingRun_.count)
flush();
257 current_desc_.depthTest = test;
258 current_desc_.depthWrite = write;
259 pipeline_ = device_.createPipeline(current_desc_);
263 if (!initialized_ || !inFrame_)
return;
264 if (pendingRun_.count) flushRun();
265 if (!pendingGeometry_)
return;
269 deferredBatches_.push_back({pipeline_, currentTexture_, recordedIndices_,
end - recordedIndices_});
270 recordedIndices_ =
end;
271 pendingGeometry_ =
false;
277 device_.setPipeline(pipeline_);
285 pendingGeometry_ =
false;
289 if (!inFrame_)
return;
304 if (!inFrame_)
return;
305 if (recording_)
flush();
306 deferredGeometry_ = pendingGeometry_ || pendingRun_.count || !deferredBatches_.empty();
316 if (!deferredGeometry_)
return;
317 if (!deferredBatches_.empty()) {
320 device_.invalidatePipelineCache();
321 for (
const auto& batch : deferredBatches_) {
322 if (batch.mesh != 0) {
325 if (
const PipelineDesc* desc = device_.pipelineDesc(pipeline)) pipeline = instancedPipeline(*desc,
true);
327 drawRun(pipeline, batch.mesh, batch.firstInstance, batch.instanceCount);
332 if (
const PipelineDesc* desc = device_.pipelineDesc(pipeline)) {
335 pipeline = device_.createPipeline(display);
338 device_.setPipeline(pipeline);
344 deferredBatches_.clear();
347 instancesUploaded_ = 0;
348 deferredGeometry_ =
false;
354 deferredGeometry_ =
false;
357void ImmediateDraw::useTexture(
u32 textureId) {
359 if (pendingRun_.count)
flush();
360 if (textureId != currentTexture_) {
361 if (pendingGeometry_)
flush();
362 currentTexture_ = textureId;
366void ImmediateDraw::emitQuad(
const glm::vec2& center,
const glm::vec2& size,
f32 rotation,
367 const glm::vec4& color,
u32 textureId,
368 const glm::vec2& uvOffset,
const glm::vec2& uvScale) {
369 useTexture(textureId);
372 const f32 cosR = rotation != 0.0f ? std::cos(rotation) : 1.0f;
373 const f32 sinR = rotation != 0.0f ? std::sin(rotation) : 0.0f;
375 std::array<BatchVertex, 4> verts{};
376 for (
u32 i = 0; i < 4; ++i) {
377 glm::vec2 scaled = QUAD_LOCAL[i] * size;
378 glm::vec2 rotated = rotation != 0.0f
379 ? glm::vec2(scaled.x * cosR - scaled.y * sinR, scaled.x * sinR + scaled.y * cosR)
383 verts[i].position = glm::vec3(center + rotated, 0.0f);
384 verts[i].color = packed;
385 verts[i].texCoord = QUAD_UV[i] * uvScale + uvOffset;
388 u32 base = appendBatch(verts.data(), verts.size()) /
sizeof(BatchVertex);
389 u32 idx[6] = { base + 0, base + 1, base + 2, base + 2, base + 3, base + 0 };
391 pendingGeometry_ =
true;
394void ImmediateDraw::emitTriangle(
const glm::vec2& p0,
const glm::vec2& p1,
const glm::vec2& p2,
395 const glm::vec4& color) {
396 useTexture(white_texture_id_);
399 std::array<BatchVertex, 3> verts{
400 BatchVertex{ {p0, 0.0f}, packed, {0.0f, 0.0f} },
401 BatchVertex{ {p1, 0.0f}, packed, {1.0f, 0.0f} },
402 BatchVertex{ {p2, 0.0f}, packed, {1.0f, 1.0f} },
405 u32 base = appendBatch(verts.data(), verts.size()) /
sizeof(BatchVertex);
406 u32 idx[3] = { base + 0, base + 1, base + 2 };
408 pendingGeometry_ =
true;
412 const glm::vec4& color,
f32 thickness) {
413 if (!inFrame_)
return;
415 glm::vec2 delta = to - from;
416 f32 length = glm::length(delta);
417 if (length < 0.0001f)
return;
419 glm::vec2 dir = delta / length;
420 glm::vec2 center = (from + to) * 0.5f;
421 f32 angle = std::atan2(dir.y, dir.x);
423 emitQuad(center, glm::vec2(length, thickness), angle, color, white_texture_id_);
428 const glm::vec4& color,
f32 thickness) {
429 if (!inFrame_)
return;
431 glm::vec3 clippedFrom = from;
432 glm::vec3 clippedTo = to;
433 if (!clipLineToNearPlane(clippedFrom, clippedTo, viewProjection_))
return;
435 const glm::vec3 delta = clippedTo - clippedFrom;
436 const f32 length = glm::length(delta);
437 if (length < 0.0001f)
return;
438 const glm::vec3 dir = delta / length;
440 glm::vec3 side = glm::cross(dir, viewForward_);
441 f32 sideLength = glm::length(side);
442 if (sideLength < 0.0001f) {
444 side = glm::cross(dir, std::abs(dir.y) < 0.9f ? glm::vec3(0.0f, 1.0f, 0.0f)
445 : glm::vec3(1.0f, 0.0f, 0.0f));
446 sideLength = glm::length(side);
447 if (sideLength < 0.0001f)
return;
449 side *= (thickness * 0.5f) / sideLength;
451 useTexture(white_texture_id_);
453 const std::array<BatchVertex, 4> verts{
454 BatchVertex{ clippedFrom - side, packed, {0.0f, 0.0f} },
455 BatchVertex{ clippedFrom + side, packed, {1.0f, 0.0f} },
456 BatchVertex{ clippedTo + side, packed, {1.0f, 1.0f} },
457 BatchVertex{ clippedTo - side, packed, {0.0f, 1.0f} },
460 appendBatch(verts.data(), verts.size()) /
sizeof(
BatchVertex);
461 const u32 idx[6] = { base + 0, base + 1, base + 2, base + 2, base + 3, base + 0 };
463 pendingGeometry_ =
true;
468 const glm::vec4& color,
f32 thickness) {
469 if (!inFrame_ || !(thickness > 0.0f))
return;
471 glm::vec3 clippedFrom = from;
472 glm::vec3 clippedTo = to;
473 if (!clipLineToNearPlane(clippedFrom, clippedTo, viewProjection_))
return;
475 const glm::vec4 clipFrom = viewProjection_ * glm::vec4(clippedFrom, 1.0f);
476 const glm::vec4 clipTo = viewProjection_ * glm::vec4(clippedTo, 1.0f);
477 if (std::abs(clipFrom.w) < 1e-9f || std::abs(clipTo.w) < 1e-9f)
return;
478 const glm::vec2 ndcFrom = glm::vec2(clipFrom) / clipFrom.w;
479 const glm::vec2 ndcTo = glm::vec2(clipTo) / clipTo.w;
480 const glm::vec2 pixelDelta{
481 (ndcTo.x - ndcFrom.x) * viewportWidth_,
482 (ndcTo.y - ndcFrom.y) * viewportHeight_,
484 const f32 pixelLength = glm::length(pixelDelta);
485 if (!(pixelLength > 1e-6f) || !std::isfinite(pixelLength))
return;
486 const glm::vec2 normal{-pixelDelta.y / pixelLength, pixelDelta.x / pixelLength};
487 const glm::vec2 ndcOffset{
488 normal.x * thickness / viewportWidth_,
489 normal.y * thickness / viewportHeight_,
492 const auto unproject = [
this](
const glm::vec4& clip, glm::vec3& point) {
493 const glm::vec4 world = inverseViewProjection_ * clip;
494 if (!std::isfinite(world.x) || !std::isfinite(world.y) ||
495 !std::isfinite(world.z) || !std::isfinite(world.w) ||
496 std::abs(world.w) < 1e-9f) {
499 point = glm::vec3(world) / world.w;
500 return std::isfinite(point.x) && std::isfinite(point.y) && std::isfinite(point.z);
502 const glm::vec4 fromOffset{ndcOffset * clipFrom.w, 0.0f, 0.0f};
503 const glm::vec4 toOffset{ndcOffset * clipTo.w, 0.0f, 0.0f};
504 std::array<glm::vec3, 4> points;
505 if (!unproject(clipFrom - fromOffset, points[0]) ||
506 !unproject(clipFrom + fromOffset, points[1]) ||
507 !unproject(clipTo + toOffset, points[2]) ||
508 !unproject(clipTo - toOffset, points[3])) {
512 const std::array<BatchVertex, 4> verts{
519 useTexture(white_texture_id_);
521 appendBatch(verts.data(), verts.size()) /
sizeof(
BatchVertex);
522 const u32 idx[6] = { base + 0, base + 1, base + 2, base + 2, base + 3, base + 0 };
524 pendingGeometry_ =
true;
529 const glm::vec2& fromOffset,
530 const glm::vec2& toOffset,
531 const glm::vec4& color,
f32 thickness) {
532 if (!inFrame_ || !(thickness > 0.0f))
return;
534 const glm::vec4 clipAnchor = viewProjection_ * glm::vec4(anchor, 1.0f);
535 if (!std::isfinite(clipAnchor.x) || !std::isfinite(clipAnchor.y)
536 || !std::isfinite(clipAnchor.z) || !std::isfinite(clipAnchor.w)
537 || std::abs(clipAnchor.w) < 1e-9f || clipAnchor.z + clipAnchor.w < 0.0f) {
543 if (!screenOffsetPoint(inverseViewProjection_, clipAnchor, fromOffset,
544 viewportWidth_, viewportHeight_, from)
545 || !screenOffsetPoint(inverseViewProjection_, clipAnchor, toOffset,
546 viewportWidth_, viewportHeight_, to))
return;
551 const glm::vec4& color,
f32 thickness,
bool closed) {
552 if (!inFrame_ || vertices.size() < 2)
return;
554 for (
size_t i = 0; i < vertices.size() - 1; ++i) {
555 line(vertices[i], vertices[i + 1], color, thickness);
557 if (closed && vertices.size() > 2) {
558 line(vertices.back(), vertices.front(), color, thickness);
563 const glm::vec4& color,
bool filled) {
564 if (!inFrame_)
return;
567 emitQuad(position, size, 0.0f, color, white_texture_id_);
575 const glm::vec4& color,
f32 thickness) {
576 if (!inFrame_)
return;
578 f32 halfW = size.x * 0.5f;
579 f32 halfH = size.y * 0.5f;
581 glm::vec2 tl(position.x - halfW, position.y + halfH);
582 glm::vec2 tr(position.x + halfW, position.y + halfH);
583 glm::vec2 br(position.x + halfW, position.y - halfH);
584 glm::vec2 bl(position.x - halfW, position.y - halfH);
586 line(tl, tr, color, thickness);
587 line(tr, br, color, thickness);
588 line(br, bl, color, thickness);
589 line(bl, tl, color, thickness);
593 const glm::vec4& color,
bool filled,
i32 segments) {
594 if (!inFrame_ || segments < 3)
return;
597 for (
i32 i = 0; i < segments; ++i) {
598 f32 a1 =
static_cast<f32>(i) /
static_cast<f32>(segments) * glm::two_pi<f32>();
599 f32 a2 =
static_cast<f32>(i + 1) /
static_cast<f32>(segments) * glm::two_pi<f32>();
600 glm::vec2 p1 = center + glm::vec2(std::cos(a1), std::sin(a1)) * radius;
601 glm::vec2 p2 = center + glm::vec2(std::cos(a2), std::sin(a2)) * radius;
602 emitTriangle(center, p1, p2, color);
611 const glm::vec4& color,
f32 thickness,
i32 segments) {
612 if (!inFrame_ || segments < 3)
return;
614 for (
i32 i = 0; i < segments; ++i) {
615 f32 a1 =
static_cast<f32>(i) /
static_cast<f32>(segments) * glm::two_pi<f32>();
616 f32 a2 =
static_cast<f32>(i + 1) /
static_cast<f32>(segments) * glm::two_pi<f32>();
617 glm::vec2 p1 = center + glm::vec2(std::cos(a1), std::sin(a1)) * radius;
618 glm::vec2 p2 = center + glm::vec2(std::cos(a2), std::sin(a2)) * radius;
619 line(p1, p2, color, thickness);
624 if (!inFrame_ || vertices.size() < 3)
return;
626 for (
size_t i = 1; i + 1 < vertices.size(); ++i) {
627 emitTriangle(vertices[0], vertices[i], vertices[i + 1], color);
633 const glm::vec4& tint,
const f32 xform[6]) {
634 if (!inFrame_ || !positions || !indices || vertexCount == 0 || indexCount < 3)
return;
635 const u32 used = indexCount - indexCount % 3;
637 for (
u32 i = 0; i < used; ++i) {
638 if (indices[i] >= vertexCount)
return;
640 useTexture(white_texture_id_);
642 triangleVertices_.resize(vertexCount);
643 for (
u32 v = 0; v < vertexCount; ++v) {
644 const f32 x = positions[v * 2], y = positions[v * 2 + 1];
645 const glm::vec4 colour = colors
646 ? glm::vec4(colors[v * 4], colors[v * 4 + 1], colors[v * 4 + 2], colors[v * 4 + 3]) * tint
649 {xform[0] * x + xform[2] * y + xform[4], xform[1] * x + xform[3] * y + xform[5], 0.0f},
654 const u32 base = appendBatch(triangleVertices_.data(), vertexCount) /
sizeof(
BatchVertex);
655 triangleIndices_.resize(used);
656 for (
u32 i = 0; i < used; ++i) triangleIndices_[i] = base + indices[i];
658 pendingGeometry_ =
true;
659 primitiveCount_ += used / 3;
663 if (!initialized_ || !positions || !indices || vertexCount == 0 || indexCount < 3)
return 0;
664 const u32 used = indexCount - indexCount % 3;
665 for (
u32 i = 0; i < used; ++i) {
666 if (indices[i] >= vertexCount)
return 0;
668 std::vector<BatchVertex> vertices(vertexCount);
669 for (
u32 v = 0; v < vertexCount; ++v) {
670 const u32 colour = colors
671 ?
packColor(colors[v * 4], colors[v * 4 + 1], colors[v * 4 + 2], colors[v * 4 + 3])
673 vertices[v] =
BatchVertex{{positions[v * 2], positions[v * 2 + 1], 0.0f}, colour, {0.0f, 0.0f}};
685 mesh.indexCount = used;
688 if (!freeMeshes_.empty()) {
689 id = freeMeshes_.back();
690 freeMeshes_.pop_back();
691 meshes_[
id - 1] = mesh;
693 meshes_.push_back(mesh);
694 id =
static_cast<u32>(meshes_.size());
701 if (
id == 0 ||
id > meshes_.size() || !meshes_[
id - 1].live)
return;
702 meshes_[
id - 1].live =
false;
704 doomedMeshes_.push_back(
id);
708 if (!inFrame_ ||
id == 0 ||
id > meshes_.size() || !meshes_[
id - 1].live)
return;
710 if (pendingGeometry_ || (pendingRun_.count && pendingRun_.mesh !=
id))
flush();
711 if (pendingRun_.count == 0) pendingRun_ = {id,
static_cast<u32>(instances_.size()), 0};
712 InstanceRecord record;
713 std::copy(xform, xform + 6, record.xform);
715 instances_.push_back(record);
717 primitiveCount_ += meshes_[
id - 1].indexCount / 3;
721 if (!inFrame_ || !records || count == 0 ||
id == 0 ||
id > meshes_.size() || !meshes_[
id - 1].live)
return;
722 if (pendingGeometry_ || (pendingRun_.count && pendingRun_.mesh !=
id))
flush();
723 const usize first = instances_.size();
724 if (pendingRun_.count == 0) pendingRun_ = {id,
static_cast<u32>(first), 0};
725 instances_.resize(first + count);
726 std::memcpy(instances_.data() + first, records,
sizeof(InstanceRecord) * count);
727 pendingRun_.count += count;
728 primitiveCount_ += (meshes_[
id - 1].indexCount / 3) * count;
731void ImmediateDraw::flushRun() {
732 const Run run = pendingRun_;
734 if (run.count == 0)
return;
735 const PipelineHandle pipeline = instancedPipeline(current_desc_,
false);
738 deferredBatches_.push_back({pipeline, white_texture_id_, 0, 0, run.mesh, run.first, run.count});
742 drawRun(pipeline,
run.mesh,
run.first,
run.count);
745void ImmediateDraw::uploadInstances() {
746 const u32 used =
static_cast<u32>(instances_.size());
747 if (used == instancesUploaded_)
return;
748 constexpr u32 stride =
sizeof(InstanceRecord);
749 if (used > instanceCapacity_) {
751 instanceCapacity_ = std::max({used, instanceCapacity_ * 2, INITIAL_INSTANCE_RECORDS});
756 device_.resizeBuffer(instanceVbo_, instanceCapacity_ * stride,
nullptr);
758 instancesUploaded_ = 0;
761 device_.updateBuffer(instanceVbo_, instancesUploaded_ * stride, instances_.data() + instancesUploaded_,
762 (used - instancesUploaded_) * stride);
763 instancesUploaded_ = used;
768 const ResidentMesh& mesh = meshes_[
id - 1];
770 device_.setPipeline(pipeline);
772 device_.setVertexBuffer(0, mesh.vbo, 0);
774 device_.setVertexBuffer(1, instanceVbo_, first *
static_cast<u32>(
sizeof(InstanceRecord)));
775 device_.setIndexBuffer(mesh.ebo);
781 const auto target = resource_manager_.preferredShaderTarget();
786 {{0,
"a_position"}, {1,
"a_color"}, {2,
"a_texCoord"}},
787 resource_manager_.preferredShaderLanguage());
788 Shader* shader = resource_manager_.getShader(handle);
789 if (!shader || !shader->isValid()) {
790 ES_LOG_ERROR(
"ImmediateDraw: failed to create the instanced batch shader");
795 for (
i32 i = 0; i < 8; ++i) s.setUniform(
"u_textures[" + std::to_string(i) +
"]", i);
804 if (linear != instancedLinear_) {
805 instancedLinear_ = linear;
806 instancedCompiled_ = instancedDisplayCompiled_ =
false;
808 if (!instancedCompiled_) {
809 instancedCompiled_ =
true;
810 instancedShader_ = compileVariant({
"INSTANCED"});
812 if (display && !instancedDisplayCompiled_) {
813 instancedDisplayCompiled_ =
true;
814 instancedDisplayShader_ = compileVariant({
"INSTANCED",
"DISPLAY_OUTPUT"});
816 Shader* shader = resource_manager_.getShader(display ? instancedDisplayShader_ : instancedShader_);
820 VertexLayoutDesc desc;
821 desc.attributeCount = 8;
822 desc.strides[0] =
sizeof(BatchVertex);
823 desc.strides[1] =
sizeof(InstanceRecord);
824 desc.instanceStep[1] =
true;
833 instanceLayout_ = device_.createVertexLayout(desc);
835 PipelineDesc desc = state;
836 desc.program = shader->handle();
837 desc.vertexLayout = instanceLayout_;
838 return device_.createPipeline(desc);
842 u32 textureId,
const glm::vec4& tint) {
843 if (!inFrame_)
return;
844 emitQuad(position, size, 0.0f, tint, textureId);
849 f32 rotation,
u32 textureId,
const glm::vec4& tint) {
850 if (!inFrame_)
return;
851 emitQuad(position, size, rotation, tint, textureId);
Abstract graphics device interface.
Logging utilities for ESEngine.
#define ES_LOG_ERROR(...)
Logs an error message.
#define ES_LOG_INFO(...)
Logs an info message.
Rendering context containing all renderer state.
Central resource management system.
Parser for unified .esshader file format.
GPU shader program abstraction.
static constexpr GfxContent transient()
static constexpr GfxContent retained()
Abstract graphics device interface.
GPU shader program for rendering.
bool isValid() const
Checks if the shader compiled and linked successfully.
ShaderHandle handle() const
Gets the device program handle.
u32 appendVertices(LayoutId layout, const void *data, u32 byteSize)
Central manager for GPU resources.
static ParsedShader parse(const std::string &source)
Parses shader source into structured format (no include support).
static bool linearColorSpace()
static std::string assembleStage(const ParsedShader &parsed, ShaderStage stage, const std::string &platform="", const std::vector< std::string > &features={}, ShaderTargetLanguage target=ShaderTargetLanguage::GLSL_ES300)
Assembles final GLSL source for a specific stage.
constexpr const char * BATCH
std::span< const EsCmd > run(SystemFn fn, std::span< const std::uint32_t > fallback, std::span< const QuerySpec > queries, std::span< void *const > resources, CallArena &arena, WorldStamp world={})
Handle< esengine::Shader > ShaderHandle
Handle to a shader resource.
std::int32_t i32
Signed 32-bit integer.
@ Off
No stencil test; full color write.
std::size_t usize
Size type for indexing and sizes.
constexpr i32 BATCH_DITHER_BIT
constexpr i32 BATCH_DITHER_PHASE_BIT
PipelineHandle
Opaque handle to a cached pipeline; PipelineHandle{0} is the null/invalid handle.
u32 packColor(f32 r, f32 g, f32 b, f32 a)
std::uint32_t u32
Unsigned 32-bit integer.
BlendMode
Predefined blend modes for rendering.
float f32
32-bit floating point
One vertex of the shared batch stream.
Immutable description of a draw pipeline. Equality keys the pipeline cache, so two draws with the sam...