19#include <SDL2/SDL_vulkan.h>
29#include <glm/gtc/packing.hpp>
36#include "common/config.h"
40#include "zeroerr/assert.h"
45#include <assimp/mesh.h>
46#include <assimp/matrix3x3.h>
47#include <assimp/matrix4x4.h>
48#include <assimp/vector3.h>
49#include <glm/gtc/matrix_transform.hpp>
51#include "graphics/shaders/textured_vert_spv.inc"
52#include "graphics/shaders/textured_frag_spv.inc"
53#include "graphics/shaders/mesh3d_vert_spv.inc"
54#include "graphics/shaders/mesh3d_frag_spv.inc"
55#include "graphics/shaders/mesh3d_hair_vert_spv.inc"
56#include "graphics/shaders/mesh3d_hair_frag_spv.inc"
63void transitionSampledColorForTransfer(vk::CommandBuffer cb, vkb::ColorTarget &image,
64 vk::ImageLayout newLayout) {
65 vk::ImageMemoryBarrier barrier{};
66 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
67 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
68 barrier.oldLayout =
image.currentLayout();
69 barrier.newLayout = newLayout;
70 barrier.image =
image.image();
71 barrier.subresourceRange = {vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1};
72 vk::PipelineStageFlags srcStages;
73 vk::PipelineStageFlags dstStages;
74 if (newLayout == vk::ImageLayout::eTransferSrcOptimal) {
75 barrier.srcAccessMask = vk::AccessFlagBits::eShaderRead;
76 barrier.dstAccessMask = vk::AccessFlagBits::eTransferRead;
77 srcStages = vk::PipelineStageFlagBits::eVertexShader |
78 vk::PipelineStageFlagBits::eFragmentShader |
79 vk::PipelineStageFlagBits::eComputeShader;
80 dstStages = vk::PipelineStageFlagBits::eTransfer;
82 barrier.srcAccessMask = vk::AccessFlagBits::eTransferRead;
83 barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead;
84 srcStages = vk::PipelineStageFlagBits::eTransfer;
85 dstStages = vk::PipelineStageFlagBits::eVertexShader |
86 vk::PipelineStageFlagBits::eFragmentShader |
87 vk::PipelineStageFlagBits::eComputeShader;
89 cb.pipelineBarrier(srcStages, dstStages, {}, 0,
nullptr, 0,
nullptr, 1, &barrier);
90 image.setCurrentLayout(newLayout);
101std::vector<uint32_t> loadSpirvBytes(
const void *data,
size_t size) {
102 if (!data ||
size < 4 || (
size % 4) != 0)
104 const auto *words =
static_cast<const uint32_t *
>(data);
105 if (words[0] != 0x07230203)
106 throw Exception(
"SPIR-V: bad magic (expected 0x07230203)");
107 return std::vector<uint32_t>(words, words +
size / 4);
110std::vector<uint32_t> readSpirvFile(
const std::string &
path) {
111 auto *fs = filesystem::Filesystem::create();
112 std::unique_ptr<filesystem::FileData> fd(fs->read(
path));
113 if (!fd)
throw Exception(
"newShaderFromSpvFile: failed to read '%s'",
path.c_str());
114 return loadSpirvBytes(fd->getData(), fd->getSize());
121std::vector<uint32_t> compileShaderStage(
const std::string &
source,
const char *stage,
GlslStage glslStage) {
122 if (
source.empty())
throw Exception(
"newShader: empty %s GLSL", stage);
125 }
catch (
const std::exception &
error) {
128 throw Exception(
"newShader: GLSL compile failed for %s:\n%s", stage,
error.what());
134void Graphics::ensurePresentCaptureHook() {
140 presentModel.after_render_before_present =
nullptr;
143void Graphics::ensureReadbackSlots() {
146 const size_t want = std::max<size_t>(2, frameSlotCount());
147 if (!screenReadbackSlots.empty() && screenReadbackSlots.size() >= want &&
148 screenReadbackBytes ==
bytes)
153 for (
auto &
slot : screenReadbackSlots) {
155 slot.staging.unmap();
156 slot.mapped =
nullptr;
158 slot.staging.release();
160 screenReadbackSlots.clear();
161 screenReadbackSlots.resize(want);
162 for (
auto &
slot : screenReadbackSlots) {
163 slot.staging = vkb::GenericBuffer(device, vk::BufferUsageFlagBits::eTransferDst,
164 vk::DeviceSize(
bytes),
165 vk::MemoryPropertyFlagBits::eHostVisible |
166 vk::MemoryPropertyFlagBits::eHostCoherent);
168 screenReadbackBytes =
bytes;
169 readbackReady =
false;
170 readbackCpuSynced =
false;
171 readbackWriteSlot = 0;
174bool Graphics::recordSwapchainReadback(vk::CommandBuffer cb) {
176 if (!presentModel.has_acquired_image)
return false;
177 const vk::Format fmt = swapchain.image_format;
178 const bool bgra = (fmt == vk::Format::eB8G8R8A8Unorm || fmt == vk::Format::eB8G8R8A8Srgb);
179 const bool rgba = (fmt == vk::Format::eR8G8B8A8Unorm || fmt == vk::Format::eR8G8B8A8Srgb);
180 if (!bgra && !rgba)
return false;
183 const uint32_t imageIndex = presentModel.acquired_image_index;
184 auto &images = swapchain.get_images();
185 if (imageIndex >= images.size())
return false;
187 ensureReadbackSlots();
188 if (screenReadbackSlots.empty())
return false;
190 const size_t slot = size_t(presentRecording.slot().index) % screenReadbackSlots.size();
191 readbackWriteSlot =
slot;
192 const vk::Image
image = images[imageIndex];
198 vk::Extent2D{uint32_t(pixelWidth), uint32_t(pixelHeight)},
199 vk::ImageAspectFlagBits::eColor, 0, vk::ImageLayout::ePresentSrcKHR);
203void Graphics::syncReadbackCpu() {
204 if (!readbackReady || screenReadbackSlots.empty())
return;
205 if (readbackCpuSynced && !lastFrameRgba.empty())
return;
206 if (readbackWriteSlot >= screenReadbackSlots.size())
return;
208 const size_t bytes = screenReadbackBytes;
209 if (
bytes == 0)
return;
213 presentModel.waitForFrameSlot(readbackWriteSlot);
215 auto &
slot = screenReadbackSlots[readbackWriteSlot];
219 lastFrameRgba.resize(
bytes);
222 const size_t words =
bytes / 8;
223 const uint64_t *src64 =
static_cast<const uint64_t *
>(
slot.mapped);
224 uint64_t *dst64 =
reinterpret_cast<uint64_t *
>(lastFrameRgba.data());
225 for (
size_t i = 0; i < words; ++i) {
226 const uint64_t
v = src64[i];
227 dst64[i] = (
v & 0xFF00FF00FF00FF00ull) |
228 ((
v & 0x000000FF000000FFull) << 16) |
229 ((
v >> 16) & 0x000000FF000000FFull);
231 for (
size_t i = words * 8; i <
bytes; i += 4) {
232 const uint32_t
v = *
reinterpret_cast<const uint32_t *
>(
233 static_cast<const uint8_t *
>(
slot.mapped) + i);
234 const uint32_t
out = (
v & 0xFF00FF00u) | ((
v & 0xFFu) << 16) | ((
v >> 16) & 0xFFu);
235 std::memcpy(lastFrameRgba.data() + i, &
out, 4);
238 std::memcpy(lastFrameRgba.data(),
slot.mapped,
bytes);
240 readbackCpuSynced =
true;
243void Graphics::destroyReadbackResources() {
244 destroyFrameCapture();
245 for (
auto &
slot : screenReadbackSlots) {
247 slot.staging.unmap();
248 slot.mapped =
nullptr;
250 slot.staging.release();
252 screenReadbackSlots.clear();
253 screenReadbackBytes = 0;
254 readbackReady =
false;
255 readbackCpuSynced =
false;
256 hasPresentedFrame =
false;
261 if (!hasPresentedFrame || lastFrameRgba.empty())
262 throw Exception(
"Graphics::newImageData: no presented frame");
264 std::memcpy(img->getData(), lastFrameRgba.data(), lastFrameRgba.size());
270 if (!hasPresentedFrame || lastFrameRgba.empty())
271 throw Exception(
"Graphics::getPixel: no presented frame");
273 throw Exception(
"Graphics::getPixel: out of bounds (%d,%d)",
x,
y);
277 const int cx = std::min(std::max(pxX, 0),
pixelWidth - 1);
279 const size_t i = (size_t(
cy) * size_t(
pixelWidth) + size_t(
cx)) * 4;
280 float r = lastFrameRgba[i + 0] / 255.f;
281 float g = lastFrameRgba[i + 1] / 255.f;
282 float b = lastFrameRgba[i + 2] / 255.f;
283 float a = lastFrameRgba[i + 3] / 255.f;
285 const vk::Format fmt = swapchain.image_format;
286 if (fmt == vk::Format::eB8G8R8A8Srgb || fmt == vk::Format::eR8G8B8A8Srgb) {
287 auto toLinear = [](
float u) {
288 return (
u <= 0.04045f) ? (
u / 12.92f) : std::pow((
u + 0.055f) / 1.055f, 2.4f);
298 const glm::mat4&
viewProj,
int maskW,
int maskH) {
299 if (!initialized || maskW <= 0 || maskH <= 0)
return nullptr;
302 createGBufferResources(maskW, maskH);
303 if (!gbufferPipeline || !gbufferRenderPass)
return nullptr;
304 auto *
slot = currentGBufferSlot();
305 if (!
slot || !
slot->framebuffer || !whiteTexture)
return nullptr;
311 std::vector<GBufferDraw> idDraws;
312 idDraws.reserve(draws.size());
313 auto u8 = [](
float x) -> uint32_t {
return uint32_t(std::lround(std::clamp(
x, 0.f, 1.f) * 255.f)); };
314 for (
const auto &
d : draws) {
315 if (!
d.mesh || !
d.mesh->gpuHandle)
continue;
318 gd.albedo = whiteTexture;
320 gd.push.modelR0 = glm::vec4(
d.model[0][0],
d.model[1][0],
d.model[2][0],
d.model[3][0]);
321 gd.push.modelR1 = glm::vec4(
d.model[0][1],
d.model[1][1],
d.model[2][1],
d.model[3][1]);
322 gd.push.modelR2 = glm::vec4(
d.model[0][2],
d.model[1][2],
d.model[2][2],
d.model[3][2]);
323 const uint32_t packed =
324 u8(
d.idColor.r) | (u8(
d.idColor.g) << 8) | (u8(
d.idColor.b) << 16) | (u8(
d.idColor.a) << 24);
326 gd.push.clip = glm::vec4(0.1f, 100.f, glm::uintBitsToFloat(packed), -1.f);
327 idDraws.push_back(gd);
329 if (idDraws.empty())
return nullptr;
331 const uint32_t
w = uint32_t(maskW);
332 const uint32_t
h = uint32_t(maskH);
333 const vk::DeviceSize byteSize = vk::DeviceSize(
w) * vk::DeviceSize(
h) * 4;
334 vkb::GenericBuffer staging(device, vk::BufferUsageFlagBits::eTransferDst, byteSize,
335 vk::MemoryPropertyFlagBits::eHostVisible |
336 vk::MemoryPropertyFlagBits::eHostCoherent);
338 vkb::executeImmediately(device.instance, uploadPool, device.getQueue(vkb::QueueType::graphics),
339 [&](vk::CommandBuffer cb) {
340 std::array<vk::ClearValue, 6> clears{};
341 clears[0].color = vk::ClearColorValue(std::array<float, 4>{0, 0, 0, 0});
342 clears[1].color = vk::ClearColorValue(std::array<float, 4>{0, 0, 0, 0});
343 clears[2].color = vk::ClearColorValue(std::array<float, 4>{0, 0, 0, 0});
344 clears[3].color = vk::ClearColorValue(std::array<float, 4>{0, 1, 1, 1});
345 clears[4].color = vk::ClearColorValue(std::array<float, 4>{0, 0, 0, 0});
346 clears[5].depthStencil = vk::ClearDepthStencilValue{1.0f, 0};
347 vk::RenderPassBeginInfo rpBegin{};
348 rpBegin.renderPass = gbufferRenderPass;
349 rpBegin.framebuffer =
slot->framebuffer;
350 rpBegin.renderArea = vk::Rect2D{{0, 0}, {
w,
h}};
351 rpBegin.clearValueCount = uint32_t(clears.size());
352 rpBegin.pClearValues = clears.data();
353 slot->normal.beginColorAttachment();
354 slot->depthColor.beginColorAttachment();
355 slot->albedo.beginColorAttachment();
356 slot->pbrParams.beginColorAttachment();
357 slot->emissive.beginColorAttachment();
358 slot->depth.beginDepthAttachment();
359 cb.beginRenderPass(rpBegin, vk::SubpassContents::eInline);
360 setViewportAndScissor(cb,
w,
h);
361 cb.bindPipeline(vk::PipelineBindPoint::eGraphics, gbufferPipeline);
362 for (
const auto &
d : idDraws) {
363 auto *gpuMesh =
static_cast<GpuMesh *
>(
d.mesh->gpuHandle);
364 if (!gpuMesh)
continue;
365 if (whiteTexture && whiteTexture->
gpuHandle && texSetLayout) {
367 cb.bindDescriptorSets(vk::PipelineBindPoint::eGraphics,
368 gbufferPipelineLayout, 0, 1,
369 gpuTex->descriptorSet.ptr(), 0,
nullptr);
371 cb.pushConstants(gbufferPipelineLayout,
372 vk::ShaderStageFlagBits::eVertex |
373 vk::ShaderStageFlagBits::eFragment,
374 0,
sizeof(GBufferPush), &
d.push);
375 drawIndexedMesh(cb, *gpuMesh);
378 slot->normal.endSampledLayout();
379 slot->depthColor.endSampledLayout();
380 slot->albedo.endSampledLayout();
381 slot->pbrParams.endSampledLayout();
382 slot->emissive.endSampledLayout();
383 slot->depth.endSampledLayout();
386 slot->albedo.setLayout(cb, vk::ImageLayout::eTransferSrcOptimal);
387 vk::BufferImageCopy
region{};
388 region.imageSubresource = {vk::ImageAspectFlagBits::eColor, 0, 0, 1};
389 region.imageExtent = vk::Extent3D{
w,
h, 1};
390 cb.copyImageToBuffer(
slot->albedo.image(),
391 vk::ImageLayout::eTransferSrcOptimal, staging.buffer,
393 slot->albedo.setLayout(cb, vk::ImageLayout::eShaderReadOnlyOptimal);
397 void *mapped = staging.map();
398 std::memcpy(img->getData(), mapped,
size_t(byteSize));
406 rc->getGBuffer()->setTargets(
int(
w),
int(
h), &
slot->depthColorTex, &
slot->normalTex, &
slot->albedoTex,
407 &
slot->depthTex, &
slot->pbrParamsTex, &
slot->emissiveTex);
413 if (!initialized)
return nullptr;
414 auto *
slot = currentGBufferSlot();
415 if (!
slot)
return nullptr;
416 vkb::ColorTarget *src =
nullptr;
417 if (attachment ==
"depth")
418 src = &
slot->depthColor;
419 else if (attachment ==
"normal")
421 else if (attachment ==
"albedo")
423 else if (attachment ==
"pbrParams")
424 src = &
slot->pbrParams;
425 else if (attachment ==
"emissive")
426 src = &
slot->emissive;
430 const uint32_t
w = uint32_t(gbufferWidth);
431 const uint32_t
h = uint32_t(gbufferHeight);
432 if (
w == 0 ||
h == 0)
return nullptr;
434 const bool hdr = attachment ==
"emissive";
435 const vk::DeviceSize byteSize = vk::DeviceSize(
w) * vk::DeviceSize(
h) * (hdr ? 8 : 4);
436 if (gbufferPending) recordDeferredFrameGraph();
437 vkb::GenericBuffer staging(
device, vk::BufferUsageFlagBits::eTransferDst, byteSize,
438 vk::MemoryPropertyFlagBits::eHostVisible |
439 vk::MemoryPropertyFlagBits::eHostCoherent);
440 vkb::executeImmediately(
441 device.instance, uploadPool,
device.getQueue(vkb::QueueType::graphics), [&](vk::CommandBuffer cb) {
442 detail::recordFrameReadback(cb, src->image(), staging.buffer, vk::Extent2D{w, h},
443 vk::ImageAspectFlagBits::eColor, 0, vk::ImageLayout::eShaderReadOnlyOptimal);
444 src->setCurrentLayout(vk::ImageLayout::eShaderReadOnlyOptimal);
448 void *mapped = staging.map();
450 auto *
pixels =
static_cast<uint8_t *
>(img->getData());
451 const auto *halves =
static_cast<const uint16_t *
>(mapped);
452 for (
size_t i = 0; i < size_t(
w) * size_t(
h) * 4; ++i)
453 pixels[i] = uint8_t(std::lround(std::clamp(glm::unpackHalf1x16(halves[i]), 0.f, 1.f) * 255.f));
455 std::memcpy(img->getData(), mapped,
size_t(byteSize));
459 if (attachment ==
"depth") {
460 auto *
pixels =
static_cast<uint8_t *
>(img->getData());
461 const size_t pixelCount = size_t(
w) * size_t(
h);
462 for (
size_t i = 0; i < pixelCount; ++i) {
471 if (!initialized)
return nullptr;
472 auto *
slot = currentDecalSlot();
473 auto *gslot = currentGBufferSlot();
474 if (!
slot || !gslot || !
slot->framebuffer || !decalPipeline || !decalRenderPass || !gbufferPipeline ||
475 !gbufferRenderPass || !gslot->framebuffer)
477 vkb::ColorTarget *src =
nullptr;
478 if (attachment ==
"normal")
480 else if (attachment ==
"params")
482 else if (attachment ==
"albedo")
487 const uint32_t
w = uint32_t(decalWidth);
488 const uint32_t
h = uint32_t(decalHeight);
489 if (
w == 0 ||
h == 0)
return nullptr;
490 if (gbufferPending) recordDeferredFrameGraph();
492 const vk::DeviceSize byteSize = vk::DeviceSize(
w) * vk::DeviceSize(
h) * 4;
493 vkb::GenericBuffer staging(
device, vk::BufferUsageFlagBits::eTransferDst, byteSize,
494 vk::MemoryPropertyFlagBits::eHostVisible |
495 vk::MemoryPropertyFlagBits::eHostCoherent);
496 vkb::executeImmediately(
device.instance, uploadPool,
device.getQueue(vkb::QueueType::graphics),
497 [&](vk::CommandBuffer cb) {
500 recordDecalPassInto(cb, *slot, *gslot);
501 transitionSampledColorForTransfer(
502 cb, *src, vk::ImageLayout::eTransferSrcOptimal);
503 vk::BufferImageCopy region{};
504 region.imageSubresource = {vk::ImageAspectFlagBits::eColor, 0, 0,
506 region.imageExtent = vk::Extent3D{
w,
h, 1};
507 cb.copyImageToBuffer(src->image(),
508 vk::ImageLayout::eTransferSrcOptimal,
510 transitionSampledColorForTransfer(
511 cb, *src, vk::ImageLayout::eShaderReadOnlyOptimal);
515 void *mapped = staging.map();
516 std::memcpy(img->getData(), mapped,
size_t(byteSize));
526 if (!initialized)
throw Exception(
"newCanvas: graphics not initialized");
527 if (
w <= 0 ||
h <= 0)
throw Exception(
"newCanvas: invalid size");
528 ensureOffscreenPipelines();
529 auto c = std::make_unique<OffscreenCanvas>(
this,
w,
h);
531 ownedCanvases.push_back(std::move(
c));
539 if (!initialized)
throw Exception(
"newHDRCanvas: graphics not initialized");
540 if (
w <= 0 ||
h <= 0)
throw Exception(
"newHDRCanvas: invalid size");
541 ensureHdrOffscreenPipelines();
542 auto c = std::make_unique<OffscreenCanvas>(
this,
w,
h,
true);
544 ownedCanvases.push_back(std::move(
c));
548void Graphics::beginPathSceneOutput() {
549 if (sceneColorPassOpen) endSceneColorRenderPass();
554void Graphics::retirePathSceneOutput() { invalidateTextureBindings(); }
558 if (next ==
static_cast<Canvas *
>(
this)) next =
nullptr;
559 if (next == activeCanvas)
return;
560 bool hasSolid =
false;
561 for (
const auto &sb : solidBatches)
562 if (!sb.batch.empty()) hasSolid =
true;
563 if (hasSolid || !texturedBatches.empty() || !litBatches.empty()) flushBatch();
564 if (next && sceneColorPassOpen) {
565 endSceneColorRenderPass();
566 queueSceneColorResolve();
572 return activeCanvas !=
nullptr;
576 return activeCanvas ? activeCanvas :
const_cast<Graphics *
>(
this);
585 if (initialized &&
changed) swapchainDirty =
true;
588void Graphics::clear2DBatches() {
589 solidBatches.
clear();
590 texturedBatches.clear();
592 overlaySpans.clear();
593 engine3DSpans.clear();
594 gpuParticleDraws_.clear();
595 pendingSceneResolve.reset();
596 pendingUiResolve.reset();
597 sceneColorComposited =
false;
600void Graphics::noteSolidOverlay(uint32_t
idx) {
601 if (
idx >= solidBatches.size())
return;
602 const uint32_t
n = uint32_t(solidBatches[
idx].batch.vertices().size());
604 if (!spans.empty() && spans.back().kind == OverlayKind::Solid &&
605 spans.back().index ==
idx) {
606 spans.back().vertCount =
n - spans.back().vertBegin;
609 const uint32_t
begin =
n >= 6u ?
n - 6u : 0
u;
613void Graphics::noteTexturedOverlay(Texture *tex, uint32_t
idx) {
618 sceneColorComposited =
true;
620 if (!spans.empty() && spans.back().kind == OverlayKind::Textured && spans.back().index ==
idx)
622 spans.push_back({OverlayKind::Textured,
idx, 0, 0});
625void Graphics::noteLitOverlay(uint32_t
idx) {
627 if (!spans.empty() && spans.back().kind == OverlayKind::Lit && spans.back().index ==
idx)
629 spans.push_back({OverlayKind::Lit,
idx, 0, 0});
634 if (
frameHad3D && activeCanvas ==
nullptr)
return;
636 hasPendingClear =
true;
639 oc->clear(
clearColor, std::nullopt, std::nullopt);
645 auto it = std::find_if(solidBatches.begin(), solidBatches.end(),
646 [&](
const SolidBatch &sb) { return sb.blend == blend; });
647 if (it == solidBatches.end()) {
649 it = solidBatches.end() - 1;
652 noteSolidOverlay(uint32_t(it - solidBatches.begin()));
656 const int targetWidth = activeCanvas ? activeCanvas->getWidth() :
getWidth();
657 const int targetHeight = activeCanvas ? activeCanvas->getHeight() :
getHeight();
661 const glm::vec2 ndc = glm::vec2(vertex.clipPosition) / vertex.clipPosition.w;
662 return glm::vec2((ndc.x + 1.f) * 0.5f *
static_cast<float>(targetWidth),
663 (ndc.y + 1.f) * 0.5f *
static_cast<float>(targetHeight));
667 auto it = std::find_if(solidBatches.begin(), solidBatches.end(),
668 [&](
const SolidBatch &batch) { return batch.blend == resolvedBatch.blend; });
669 if (it == solidBatches.end()) {
670 solidBatches.push_back(SolidBatch{resolvedBatch.blend,
Batcher{}});
671 it = solidBatches.end() - 1;
673 for (std::size_t i = resolvedBatch.firstVertex; i < resolvedBatch.firstVertex + resolvedBatch.vertexCount;
675 it->batch.addTriangle(logicalPoint(
triangles.vertices[i]), logicalPoint(
triangles.vertices[i + 1]),
679 const auto batchIndex =
static_cast<std::uint32_t
>(it - solidBatches.begin());
680 const std::uint32_t
count =
static_cast<std::uint32_t
>(resolvedBatch.vertexCount);
681 const std::uint32_t
end =
static_cast<std::uint32_t
>(it->batch.vertices().size());
682 spans.push_back({OverlayKind::Solid, batchIndex,
end -
count,
count});
688 auto it = std::find_if(solidBatches.begin(), solidBatches.end(),
689 [&](
const SolidBatch &sb) { return sb.blend == blend; });
690 if (it == solidBatches.end()) {
692 it = solidBatches.end() - 1;
695 noteSolidOverlay(uint32_t(it - solidBatches.begin()));
702 auto wrapMode = [](
bool repeat) {
703 return repeat ? vk::SamplerAddressMode::eRepeat : vk::SamplerAddressMode::eClampToEdge;
710 : vk::SamplerMipmapMode::eLinear;
714 float maxLod = useMips ? std::min(
sampler.maxLod,
float(mipLevels - 1)) : 0.f;
718 bool enableAniso =
false;
719 if (
sampler.maxAnisotropy > 1.f && maxSamplerAnisotropy > 1.f) {
721 aniso = std::min(
sampler.maxAnisotropy, maxSamplerAnisotropy);
724 vkb::SamplerBuilder sb;
725 return sb.magFilter(toFilter(
sampler.mag))
726 .minFilter(toFilter(
sampler.min))
727 .mipmapMode(useMips ? toMip(
sampler.mipmap) : vk::SamplerMipmapMode::eNearest)
730 .addressModeW(wrapMode(
sampler.repeatW))
732 .anisotropyEnable(enableAniso ? VK_TRUE : VK_FALSE)
733 .maxAnisotropy(aniso)
734 .minLod(useMips ?
sampler.minLod : 0.f)
746 drawTexturedRectShaderUV(
texture,
shader,
x,
y,
w,
h, 0.f, 0.f, 1.f, 1.f,
color);
750 float v0,
float u1,
float v1,
const Color &
color) {
751 drawTexturedRectShaderUV(
texture,
currentShader,
x,
y,
w,
h, u0, v0, u1, v1,
color);
755 float h,
float u0,
float v0,
float u1,
float v1,
761 if (texturedBatches.empty() || texturedBatches.back().texture !=
texture ||
762 texturedBatches.back().depth !=
nullptr ||
763 texturedBatches.back().shader !=
shader ||
764 texturedBatches.back().blend !=
blend) {
767 texturedBatches.back().batch.addTexturedRect(
x,
y,
w,
h,
color, u0, v0, u1, v1, rotatedUV);
768 noteTexturedOverlay(
texture, uint32_t(texturedBatches.size() - 1));
772 float w,
float h,
float degrees,
float u0,
float v0,
779 if (texturedBatches.empty() || texturedBatches.back().texture !=
texture ||
780 texturedBatches.back().depth !=
nullptr ||
781 texturedBatches.back().shader !=
shader ||
782 texturedBatches.back().blend !=
blend) {
785 texturedBatches.back().batch.addTexturedRectRotated(
cx,
cy,
w,
h,
degrees,
color, u0, v0, u1, v1,
787 noteTexturedOverlay(
texture, uint32_t(texturedBatches.size() - 1));
800 if (texturedBatches.empty() || texturedBatches.back().texture !=
color ||
801 texturedBatches.back().depth !=
depth || texturedBatches.back().shader !=
shader) {
802 texturedBatches.push_back(
805 texturedBatches.back().batch.addTexturedRect(
x,
y,
w,
h,
tint, 0.f, 0.f, 1.f, 1.f);
806 noteTexturedOverlay(
color, uint32_t(texturedBatches.size() - 1));
816 if (texturedBatches.empty() || texturedBatches.back().texture !=
color ||
817 texturedBatches.back().depth !=
depth || texturedBatches.back().motion != motion ||
818 texturedBatches.back().shader !=
shader) {
820 batch.motion = motion;
821 texturedBatches.push_back(std::move(batch));
823 texturedBatches.back().batch.addTexturedRect(
x,
y,
w,
h,
tint, 0.f, 0.f, 1.f, 1.f);
824 noteTexturedOverlay(
color, uint32_t(texturedBatches.size() - 1));
834 if (texturedBatches.empty() || texturedBatches.back().texture !=
color ||
835 texturedBatches.back().depth !=
depth || texturedBatches.back().motion != motion ||
836 texturedBatches.back().extra != extra || texturedBatches.back().shader !=
shader) {
838 batch.motion = motion;
840 texturedBatches.push_back(std::move(batch));
842 texturedBatches.back().batch.addTexturedRect(
x,
y,
w,
h,
tint, 0.f, 0.f, 1.f, 1.f);
843 noteTexturedOverlay(
color, uint32_t(texturedBatches.size() - 1));
853 if (texturedBatches.empty() || texturedBatches.back().texture !=
color ||
854 texturedBatches.back().depth !=
depth || texturedBatches.back().motion != motion ||
855 texturedBatches.back().extra != extra || texturedBatches.back().specular != specular ||
856 texturedBatches.back().shader !=
shader) {
858 batch.motion = motion;
860 batch.specular = specular;
861 texturedBatches.push_back(std::move(batch));
863 texturedBatches.back().batch.addTexturedRect(
x,
y,
w,
h,
tint, 0.f, 0.f, 1.f, 1.f);
864 noteTexturedOverlay(
color, uint32_t(texturedBatches.size() - 1));
869 float u1,
float v1,
float strengthPixels,
float opacity,
bool rotatedUV) {
875 batch.effect = TexturedBatch::Effect::SceneColorDistortion;
877 Color(strengthPixels, 0.f, 0.f,
opacity), u0, v0, u1, v1,
879 texturedBatches.push_back(std::move(batch));
882 noteTexturedOverlay(
nullptr, uint32_t(texturedBatches.size() - 1));
886void Graphics::drawUiTextureRects(
void* commandBuffer,
const std::vector<UiTextureDraw>& draws,
887 std::size_t bufferOffset) {
888 if (!commandBuffer || draws.empty() || !uiTexturePipeline || uiColorWidth <= 0 ||
892 vk::CommandBuffer cb(
static_cast<VkCommandBuffer
>(commandBuffer));
893 auto &buffers = currentFrame2DBuffers().uiTexBufs;
894 std::size_t bufferIndex = bufferOffset;
895 setViewportAndScissor(cb, uint32_t(uiColorWidth), uint32_t(uiColorHeight));
898 if (!
draw.texture || !
draw.texture->gpuHandle ||
draw.w <= 0.f ||
draw.h <= 0.f)
907 batch.
toNDC(uiColorWidth, uiColorHeight);
908 std::vector<TexturedVertex>
vertices;
910 for (
const auto &vertex : batch.
vertices())
913 while (bufferIndex >= buffers.size()) buffers.emplace_back();
914 vkb::HostVertexBuffer &vertexBuffer = buffers[bufferIndex++];
917 const int clipX = std::clamp(
int(std::floor(
draw.clipX)), 0, uiColorWidth);
918 const int clipY = std::clamp(
int(std::floor(
draw.clipY)), 0, uiColorHeight);
919 const int clipRight = std::clamp(
int(std::ceil(
draw.clipX +
draw.clipW)), 0, uiColorWidth);
920 const int clipBottom = std::clamp(
int(std::ceil(
draw.clipY +
draw.clipH)), 0, uiColorHeight);
921 if (clipRight <= clipX || clipBottom <= clipY)
continue;
922 const vk::Rect2D scissor{{clipX, clipY},
923 {uint32_t(clipRight - clipX), uint32_t(clipBottom - clipY)}};
924 cb.setScissor(0, 1, &scissor);
925 cb.bindPipeline(vk::PipelineBindPoint::eGraphics,
926 draw.opaque ? uiTextureOpaquePipeline : uiTexturePipeline);
927 cb.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, texPipelineLayout, 0, 1, &set, 0,
929 const vk::DeviceSize
offset = 0;
930 cb.bindVertexBuffers(0, 1, vertexBuffer, &
offset);
931 cb.draw(uint32_t(
vertices.size()), 1, 0, 0);
937void Graphics::ensureFlatNormalTexture() {
938 if (flatNormalTexture)
return;
939 const uint8_t
px[4] = {128, 128, 255, 255};
949 ensureFlatNormalTexture();
951 if (litBatches.empty() || litBatches.back().albedo !=
albedo || litBatches.back().normal !=
normal ||
952 litBatches.back().blend !=
blend) {
955 litBatches.back().batch.addTexturedRect(
x,
y,
w,
h,
color, u0, v0, u1, v1);
956 noteLitOverlay(uint32_t(litBatches.size() - 1));
966 ensureFlatNormalTexture();
968 if (litBatches.empty() || litBatches.back().albedo !=
albedo || litBatches.back().normal !=
normal ||
969 litBatches.back().blend !=
blend) {
972 litBatches.back().batch.addTexturedRectRotated(
cx,
cy,
w,
h,
degrees,
color, u0, v0, u1, v1);
973 noteLitOverlay(uint32_t(litBatches.size() - 1));
977 ASSERT(
albedo !=
nullptr);
978 ASSERT(
normal !=
nullptr);
979 auto &sets = offscreen ? offscreenLit2dSets : currentLit2dSets();
980 vkb::GenericBuffer &ubo = offscreen ? offscreenLighting2dUbo : currentLighting2dUbo();
982 auto it = sets.find(
key);
983 if (it != sets.end())
return it->second;
985 vk::DescriptorSetAllocateInfo alloc{};
986 alloc.descriptorPool = descriptorPool;
987 alloc.descriptorSetCount = 1;
988 alloc.pSetLayouts = &lit2dSetLayout;
989 vkb::UnboundSet unbound{
device->allocateDescriptorSets(alloc).front()};
991 vkb::DescriptorSetUpdater updater;
992 updater.beginDescriptorSet(unbound)
993 .beginImages(0, 0, vk::DescriptorType::eCombinedImageSampler)
994 .image(vkb::SampledImage::forLaterSample(
albedo->sampler,
albedo->image.imageView()))
995 .beginImages(1, 0, vk::DescriptorType::eCombinedImageSampler)
996 .image(vkb::SampledImage::forLaterSample(
normal->sampler,
normal->image.imageView()))
997 .beginBuffers(2, 0, vk::DescriptorType::eUniformBuffer)
998 .buffer(ubo.buffer, 0,
sizeof(Lighting2DUBO))
1001 vkb::BoundSet bound = std::move(unbound).publish();
1002 sets.emplace(
key, bound);
1006vkb::BoundSet Graphics::post2SetFor(GpuTexture *
color, GpuTexture *
depth, GpuTexture *motion,
1007 GpuTexture *extra, GpuTexture *specular) {
1009 vk::ImageView colorView =
color->imageView();
1010 if (!colorView)
return {};
1012 if (!motion || !motion->sampler || !motion->imageView()) motion =
color;
1013 if (!extra || !extra->sampler || !extra->imageView()) extra =
color;
1014 if (!specular || !specular->sampler || !specular->imageView()) specular =
color;
1016 auto it = post2Sets.find(
key);
1017 if (it != post2Sets.end())
return it->second;
1019 auto sets = vkb::DescriptorSetBuilder().layout(texSetLayout).build(
device.instance, descriptorPool);
1021 vkb::UnboundSet unbound{sets[0]};
1022 vkb::DescriptorSetUpdater updater;
1023 updater.beginDescriptorSet(unbound)
1024 .beginImages(0, 0, vk::DescriptorType::eCombinedImageSampler)
1025 .image(vkb::SampledImage::forLaterSample(
color->sampler, colorView))
1026 .beginImages(1, 0, vk::DescriptorType::eCombinedImageSampler)
1027 .image(vkb::SampledImage::forLaterSample(
depth->sampler,
depth->imageView()))
1028 .beginImages(2, 0, vk::DescriptorType::eCombinedImageSampler)
1029 .image(vkb::SampledImage::forLaterSample(motion->sampler, motion->imageView()))
1030 .beginImages(3, 0, vk::DescriptorType::eCombinedImageSampler)
1031 .image(vkb::SampledImage::forLaterSample(extra->sampler, extra->imageView()))
1032 .beginImages(4, 0, vk::DescriptorType::eCombinedImageSampler)
1033 .image(vkb::SampledImage::forLaterSample(specular->sampler, specular->imageView()))
1034 .update(
device.instance);
1035 vkb::BoundSet bound = std::move(unbound).publish();
1036 post2Sets.emplace(
key, bound);
1040void Graphics::drawLitBatches(vk::CommandBuffer cb,
int viewW,
int viewH, std::vector<LitBatch> &batches,
1041 std::vector<vkb::HostVertexBuffer> &texBufs,
size_t &texBufIndex,
bool offscreen,
1043 if (batches.empty() || !lit2dPipelineLayout)
return;
1044 lighting2dFrame.meta.y = float(viewW);
1045 lighting2dFrame.meta.z = float(viewH);
1046 vkb::GenericBuffer &ubo = offscreen ? offscreenLighting2dUbo : currentLighting2dUbo();
1047 ubo.updateLocal(frameToken(), &lighting2dFrame,
sizeof(Lighting2DUBO));
1049 for (
auto &lb : batches) {
1050 if (lb.batch.empty() || !lb.albedo || !lb.albedo->gpuHandle)
continue;
1051 vk::Pipeline litPipeline = selectLit2DPipeline(lb.blend, offscreen, hdr);
1052 if (!litPipeline)
continue;
1053 ensureFlatNormalTexture();
1054 Texture *ntex = lb.normal ? lb.normal : flatNormalTexture;
1055 if (!ntex || !ntex->gpuHandle)
continue;
1056 auto *albedoGpu =
static_cast<GpuTexture *
>(lb.albedo->gpuHandle);
1057 auto *normalGpu =
static_cast<GpuTexture *
>(ntex->gpuHandle);
1059 Batcher ndc = lb.batch;
1060 ndc.toNDC(viewW, viewH);
1061 std::vector<TexturedVertex> gpuVerts;
1062 gpuVerts.reserve(ndc.vertices().size());
1064 gpuVerts.push_back(TexturedVertex{
v.pos,
v.color,
v.uv});
1067 if (texBufIndex >= texBufs.size()) texBufs.emplace_back();
1068 vkb::HostVertexBuffer &vb = texBufs[texBufIndex++];
1069 vb.allocate<TexturedVertex>(frameToken(),
device, gpuVerts);
1071 vk::DescriptorSet set = lit2dSetFor(albedoGpu, normalGpu, offscreen);
1072 cb.bindPipeline(vk::PipelineBindPoint::eGraphics, litPipeline);
1073 cb.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, lit2dPipelineLayout, 0, 1, &set, 0,
1075 vk::DeviceSize
offset = 0;
1076 cb.bindVertexBuffers(0, 1, vb, &
offset);
1077 cb.draw(uint32_t(gpuVerts.size()), 1, 0, 0);
1083 const std::vector<uint32_t> &fragSpv) {
1084 ASSERT(initialized);
1085 if (!initialized)
throw Exception(
"newShaderFromSpv: graphics not initialized");
1086 if (fragSpv.empty())
throw Exception(
"newShaderFromSpv: empty fragment SPIR-V");
1088 std::vector<uint32_t>
vert = vertSpv;
1090 vert.assign(textured_vert_spv, textured_vert_spv + textured_vert_spv_count);
1091 if (
vert[0] != 0x07230203 || fragSpv[0] != 0x07230203)
1092 throw Exception(
"newShaderFromSpv: SPIR-V magic mismatch");
1094 auto gpu = std::make_unique<GpuShader>();
1095 gpu->pipelineLayout = shaderPipelineLayout;
1096 gpu->swapchainPipeline =
1097 createTexturedStylePipeline(
vert, fragSpv, renderpass, shaderPipelineLayout);
1098 gpu->swapchainOpaquePipeline = createTexturedStylePipeline(
1100 if (offscreenRenderPass) {
1101 gpu->offscreenPipeline =
1102 createTexturedStylePipeline(
vert, fragSpv, offscreenRenderPass, shaderPipelineLayout);
1103 gpu->offscreenOpaquePipeline = createTexturedStylePipeline(
1107 auto sh = std::make_unique<Shader>();
1108 sh->setSpirv(std::move(
vert), fragSpv);
1109 sh->gpuHandle =
gpu.get();
1112 ownedShaders.push_back(std::move(sh));
1113 ownedGpuShaders.push_back(std::move(
gpu));
1118 if (fragPath.empty())
throw Exception(
"newShaderFromSpvFile: empty fragPath");
1119 std::vector<uint32_t>
vert;
1120 if (!vertPath.empty())
vert = readSpirvFile(vertPath);
1121 auto frag = readSpirvFile(fragPath);
1126 if (fragGlsl.empty())
throw Exception(
"newShader: empty fragment GLSL");
1127 std::vector<uint32_t>
vert;
1134 const std::vector<uint32_t> &fragSpv) {
1135 ASSERT(initialized);
1136 if (!initialized)
throw Exception(
"newMeshShaderFromSpv: graphics not initialized");
1137 createMesh3DPipeline();
1138 if (!mesh3dShaderPipelineLayout)
1139 throw Exception(
"newMeshShaderFromSpv: mesh3d pipeline layout missing");
1141 std::vector<uint32_t>
vert = vertSpv;
1142 std::vector<uint32_t>
frag = fragSpv;
1144 vert.assign(mesh3d_vert_spv, mesh3d_vert_spv + mesh3d_vert_spv_count);
1146 frag.assign(mesh3d_frag_spv, mesh3d_frag_spv + mesh3d_frag_spv_count);
1147 if (
vert[0] != 0x07230203 ||
frag[0] != 0x07230203)
1148 throw Exception(
"newMeshShaderFromSpv: SPIR-V magic mismatch");
1150 auto gpu = std::make_unique<GpuShader>();
1151 gpu->isMesh3D =
true;
1152 gpu->pipelineLayout = mesh3dShaderPipelineLayout;
1153 ensureOffscreen3DResources();
1154 gpu->mesh3dPipeline = createMesh3DStylePipeline(
vert,
frag, mesh3dShaderPipelineLayout,
1155 activeScenePass(), activeSceneSamples());
1158 gpu->mesh3dXrayPipeline = createMesh3DXrayPipeline(
vert,
frag, mesh3dShaderPipelineLayout,
1159 activeScenePass(), activeSceneSamples());
1160 gpu->mesh3dOffscreenPipeline = createMesh3DStylePipeline(
1161 vert,
frag, mesh3dShaderPipelineLayout, offscreen3DRenderPass,
1162 vk::SampleCountFlagBits::e1);
1163 gpu->mesh3dHdrOffscreenPipeline = createMesh3DStylePipeline(
1164 vert,
frag, mesh3dShaderPipelineLayout, hdrOffscreen3DRenderPass,
1165 vk::SampleCountFlagBits::e1);
1167 auto sh = std::make_unique<Shader>();
1169 sh->setSpirv(std::move(
vert), std::move(
frag));
1170 sh->gpuHandle =
gpu.get();
1171 gpu->owner = sh.get();
1174 ownedShaders.push_back(std::move(sh));
1175 ownedGpuShaders.push_back(std::move(
gpu));
1180 const std::vector<uint32_t> &fragSpv) {
1181 ASSERT(initialized);
1182 if (!initialized)
throw Exception(
"newHairShaderFromSpv: graphics not initialized");
1183 createMesh3DPipeline();
1184 if (fragSpv.empty())
throw Exception(
"newHairShaderFromSpv: empty fragment SPIR-V");
1185 if (!mesh3dShaderPipelineLayout)
1186 throw Exception(
"newHairShaderFromSpv: mesh3d pipeline layout missing");
1188 std::vector<uint32_t>
vert = vertSpv;
1190 vert.assign(mesh3d_hair_vert_spv, mesh3d_hair_vert_spv + mesh3d_hair_vert_spv_count);
1191 if (
vert[0] != 0x07230203 || fragSpv[0] != 0x07230203)
1192 throw Exception(
"newHairShaderFromSpv: SPIR-V magic mismatch");
1194 auto gpu = std::make_unique<GpuShader>();
1195 gpu->isMesh3D =
true;
1196 gpu->isHair3D =
true;
1197 gpu->pipelineLayout = mesh3dShaderPipelineLayout;
1198 ensureOffscreen3DResources();
1199 gpu->mesh3dPipeline = createMesh3DHairPipeline(
vert, fragSpv, mesh3dShaderPipelineLayout,
1200 activeScenePass(), activeSceneSamples());
1201 gpu->mesh3dOffscreenPipeline = createMesh3DHairPipeline(
1202 vert, fragSpv, mesh3dShaderPipelineLayout, offscreen3DRenderPass,
1203 vk::SampleCountFlagBits::e1);
1204 gpu->mesh3dHdrOffscreenPipeline = createMesh3DHairPipeline(
1205 vert, fragSpv, mesh3dShaderPipelineLayout, hdrOffscreen3DRenderPass,
1206 vk::SampleCountFlagBits::e1);
1208 auto sh = std::make_unique<Shader>();
1210 sh->setSpirv(std::move(
vert), fragSpv);
1211 sh->gpuHandle =
gpu.get();
1212 gpu->owner = sh.get();
1215 ownedShaders.push_back(std::move(sh));
1216 ownedGpuShaders.push_back(std::move(
gpu));
1221 throw Exception(
"newHairShaderFromWgsl: WGSL is only supported on the WebGPU backend");
1228 auto gpuIt = std::find_if(ownedGpuShaders.begin(), ownedGpuShaders.end(),
1229 [&](
const std::unique_ptr<GpuShader> &
g) {
1230 return g.get() == gpu;
1232 if (gpuIt == ownedGpuShaders.end())
return false;
1234 auto shIt = std::find_if(ownedShaders.begin(), ownedShaders.end(),
1235 [&](
const std::unique_ptr<Shader> &
s) {
1236 return s.get() == shader;
1238 if (shIt == ownedShaders.end())
return false;
1242 waitForSharedGpuResources();
1243 if (
gpu->swapchainPipeline)
device->destroyPipeline(
gpu->swapchainPipeline);
1244 if (
gpu->offscreenPipeline)
device->destroyPipeline(
gpu->offscreenPipeline);
1245 if (
gpu->swapchainOpaquePipeline)
device->destroyPipeline(
gpu->swapchainOpaquePipeline);
1246 if (
gpu->offscreenOpaquePipeline)
device->destroyPipeline(
gpu->offscreenOpaquePipeline);
1247 if (
gpu->hdrOffscreenPipeline)
device->destroyPipeline(
gpu->hdrOffscreenPipeline);
1248 if (
gpu->hdrOffscreenOpaquePipeline)
1249 device->destroyPipeline(
gpu->hdrOffscreenOpaquePipeline);
1250 if (
gpu->mesh3dPipeline)
device->destroyPipeline(
gpu->mesh3dPipeline);
1251 if (
gpu->mesh3dXrayPipeline)
device->destroyPipeline(
gpu->mesh3dXrayPipeline);
1252 if (
gpu->mesh3dOffscreenPipeline)
1253 device->destroyPipeline(
gpu->mesh3dOffscreenPipeline);
1254 if (
gpu->mesh3dHdrOffscreenPipeline)
1255 device->destroyPipeline(
gpu->mesh3dHdrOffscreenPipeline);
1256 shader->gpuHandle =
nullptr;
1257 ownedGpuShaders.erase(gpuIt);
1259 (void)shIt->release();
1260 ownedShaders.erase(shIt);
1265 if (fragGlsl.empty())
throw Exception(
"newMeshShader: empty fragment GLSL");
1266 std::vector<uint32_t>
vert;
1273 throw Exception(
"newMeshShaderFromWgsl: WGSL mesh shaders are only supported on the "
1274 "WebGPU backend; use newMeshShaderFromSpv on Vulkan.");
1278 throw Exception(
"newShaderFromWgsl: WGSL shaders are only supported on the WebGPU "
1279 "backend; use newShaderFromSpv on Vulkan.");
1282void Graphics::flushBatch() {
1285 if (!initialized)
return;
1288 if (!oc)
throw Exception(
"flushBatch: active canvas is not an OffscreenCanvas");
1289 flushToOffscreen(oc);
1295void Graphics::abortOpen3DFrame() {
1296 const bool hadScene = sceneColorPassOpen;
1297 const bool had3D = swapchainPassOpen;
1299 if (hadScene) endSceneColorRenderPass();
1301 sceneColorPassOpen =
false;
1307 if (hadScene) beginSwapchainColorPass();
1308 presentRecording = swapchainPass.endRenderPass();
1311 ? recordSwapchainReadback(presentRecording.commandBuffer())
1313 submitGpuTimingPrefix();
1314 presentRecording.end().submitAndPresent();
1315 submittedPresentSequence_ = presentSequence_;
1316 presentRecording = {};
1318 hasPresentedFrame =
true;
1319 readbackReady =
true;
1320 readbackCpuSynced =
false;
1325 presentRecording = {};
1327 swapchainPassOpen =
false;
1328 sceneColorPassOpen =
false;
1330 hasPendingClear =
false;
1331 flushingSwapchain_ =
false;
1335void Graphics::flushToSwapchain() {
1337 if (flushingSwapchain_)
return;
1338 flushingSwapchain_ =
true;
1339 bool completed =
false;
1344 g->flushingSwapchain_ =
false;
1345 if (!*completed)
g->abortOpen3DFrame();
1347 } guard{
this, &completed};
1349 const bool continue3D = swapchainPassOpen;
1350 const bool hadScenePass = sceneColorPassOpen;
1351 const bool hasScenePath = hadScenePass || pendingSceneResolveSource !=
nullptr;
1354 endSceneColorRenderPass();
1355 queueSceneColorResolve();
1362 if (!beginPresentCommandBuffer()) {
1363 dropPendingOffscreenPasses();
1364 hasPendingClear =
false;
1368 recordDeferredFrameGraph();
1371 if (!(continue3D && !hasScenePath))
1372 recordGpuParticleCompute(presentRecording.commandBuffer());
1374 materializeSceneColorResolve();
1380 renderUiOverlayPass();
1386 const bool useHdrCompose =
1388 if (useHdrCompose) {
1389 if (!beginPresentComposePass()) {
1391 beginSwapchainColorPass();
1392 swapchainPassOpen =
true;
1394 }
else if (hasScenePath || !continue3D) {
1395 beginSwapchainColorPass();
1396 swapchainPassOpen =
true;
1399 auto solid = std::move(solidBatches);
1400 auto textured = std::move(texturedBatches);
1401 auto lit = std::move(litBatches);
1402 auto spans = std::move(overlaySpans);
1403 auto engineSpans = std::move(engine3DSpans);
1404 auto gpuParticleDraws = std::move(gpuParticleDraws_);
1405 auto sceneResolve = std::move(pendingSceneResolve);
1406 auto uiResolve = std::move(pendingUiResolve);
1407 const bool autoScene = sceneResolve.has_value() && !sceneColorComposited;
1411 auto &cb = currentPresentCb();
1412 setViewportAndScissor(cb, swapchain.extent.width, swapchain.extent.height);
1416 auto &frameBufs = currentFrame2DBuffers();
1417 std::vector<vkb::HostVertexBuffer> &solidBufs = frameBufs.solidBufs;
1418 std::vector<vkb::HostVertexBuffer> &texBufs = frameBufs.texBufs;
1419 size_t texBufIndex = 0;
1421 auto swapchainTexPipe = [&](
BlendMode mode) -> vk::Pipeline {
1422 if (presentComposeActive_) {
1425 return hdrOffscreenAdditiveTexPipeline;
1427 return hdrOffscreenPremultipliedTexPipeline;
1429 return hdrOffscreenMultiplyTexPipeline;
1431 return hdrOffscreenOpaqueTexPipeline;
1434 return hdrOffscreenTexPipeline;
1439 return additiveTexPipeline;
1441 return premultipliedTexPipeline;
1443 return multiplyTexPipeline;
1445 return opaqueTexPipeline;
1451 auto swapchainSolidPipe = [&](
BlendMode mode) -> vk::Pipeline {
1452 if (presentComposeActive_) {
1455 return hdrOffscreenAdditiveSolidPipeline;
1457 return hdrOffscreenPremultipliedSolidPipeline;
1459 return hdrOffscreenMultiplySolidPipeline;
1461 return hdrOffscreenSolidAlphaPipeline;
1464 return hdrOffscreenSolidPipeline;
1469 return additiveSolidPipeline;
1471 return premultipliedSolidPipeline;
1473 return multiplySolidPipeline;
1475 return solidAlphaPipeline;
1481 const vk::Pipeline tonemapPipe =
1482 presentComposeActive_ && hdrOffscreenTonemapPipeline ? hdrOffscreenTonemapPipeline
1483 : sceneTonemapPipeline;
1484 const vk::Pipeline distortionPipe =
1485 presentComposeActive_ && hdrOffscreenParticleDistortionPipeline
1486 ? hdrOffscreenParticleDistortionPipeline
1487 : particleDistortionPipeline;
1488 const bool litAvailable = lit2dPipeline || (presentComposeActive_ && hdrOffscreenLitPipeline);
1490 auto drawTextured = [&](TexturedBatch &
tb,
bool toneMapScene =
false) {
1492 if (
tb.batch.empty() || !
tb.texture || !
tb.texture->gpuHandle)
return;
1493 auto *
gpu =
static_cast<GpuTexture *
>(
tb.texture->gpuHandle);
1494 vk::DescriptorSet texSet =
gpu->descriptorSet;
1495 Texture *depthTexture = toneMapScene ? sceneTex :
tb.depth;
1496 if ((depthTexture && depthTexture->gpuHandle) || (
tb.motion &&
tb.motion->gpuHandle) ||
1497 (
tb.extra &&
tb.extra->gpuHandle)) {
1499 depthTexture ?
static_cast<GpuTexture *
>(depthTexture->gpuHandle) : nullptr;
1501 tb.motion ?
static_cast<GpuTexture *
>(
tb.motion->gpuHandle) : nullptr;
1502 auto *extraGpu =
tb.extra ?
static_cast<GpuTexture *
>(
tb.extra->gpuHandle) : nullptr;
1504 tb.specular ?
static_cast<GpuTexture *
>(
tb.specular->gpuHandle) : nullptr;
1505 if (vk::DescriptorSet combo =
1506 post2SetFor(
gpu, depthGpu, motionGpu, extraGpu, specularGpu))
1509 Batcher ndc =
tb.batch;
1511 std::vector<TexturedVertex> gpuVerts;
1512 gpuVerts.reserve(ndc.vertices().size());
1516 if (texBufIndex >= texBufs.size()) texBufs.emplace_back();
1517 vkb::HostVertexBuffer &vb = texBufs[texBufIndex++];
1518 vb.allocate<TexturedVertex>(frameToken(),
device, gpuVerts);
1520 if (
tb.effect == TexturedBatch::Effect::SceneColorDistortion) {
1521 if (!distortionPipe)
return;
1522 cb.bindPipeline(vk::PipelineBindPoint::eGraphics, distortionPipe);
1523 cb.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, texPipelineLayout, 0, 1, &texSet, 0,
nullptr);
1524 }
else if (
tb.effect == TexturedBatch::Effect::DisplayEncode) {
1525 if (!tonemapPipe)
return;
1526 cb.bindPipeline(vk::PipelineBindPoint::eGraphics, tonemapPipe);
1527 cb.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, texPipelineLayout, 0, 1, &texSet, 0,
1529 }
else if (
tb.shader &&
tb.shader->gpuHandle) {
1530 auto *gs =
static_cast<GpuShader *
>(
tb.shader->gpuHandle);
1531 vk::Pipeline customPipeline =
nullptr;
1532 if (presentComposeActive_) {
1533 ensureShaderHdrOffscreenPipeline(
tb.shader);
1535 ? gs->hdrOffscreenOpaquePipeline
1536 : gs->hdrOffscreenPipeline;
1539 ? gs->swapchainOpaquePipeline
1540 : gs->swapchainPipeline;
1542 if (!customPipeline)
return;
1543 cb.bindPipeline(vk::PipelineBindPoint::eGraphics, customPipeline);
1544 cb.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, shaderPipelineLayout, 0, 1,
1545 &texSet, 0,
nullptr);
1546 cb.pushConstants(shaderPipelineLayout,
1547 vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, 0,
1550 vk::Pipeline pipe = toneMapScene ? tonemapPipe : swapchainTexPipe(
tb.blend);
1552 cb.bindPipeline(vk::PipelineBindPoint::eGraphics, pipe);
1553 cb.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, texPipelineLayout, 0, 1,
1554 &texSet, 0,
nullptr);
1556 vk::DeviceSize
offset = 0;
1557 cb.bindVertexBuffers(0, 1, vb, &
offset);
1558 cb.draw(uint32_t(gpuVerts.size()), 1, 0, 0);
1561 std::vector<bool> solidUploaded(solid.size(),
false);
1562 auto uploadSolid = [&](
size_t idx) {
1563 if (
idx >= solid.size() || solidUploaded[
idx] || solid[
idx].batch.empty())
return;
1564 vk::Pipeline pipe = swapchainSolidPipe(solid[
idx].
blend);
1566 Batcher ndc = solid[
idx].batch;
1568 std::vector<ColorVertex> gpuVerts;
1569 gpuVerts.reserve(ndc.vertices().size());
1571 gpuVerts.push_back(ColorVertex{
v.
pos,
v.
color});
1572 if (solidBufs.size() <=
idx) solidBufs.resize(
idx + 1);
1573 solidBufs[
idx].allocate<ColorVertex>(frameToken(),
device, gpuVerts);
1574 solidUploaded[
idx] =
true;
1577 auto drawSolidSpan = [&](uint32_t batchIndex, uint32_t
begin, uint32_t
count) {
1578 if (batchIndex >= solid.size() ||
count == 0 || solid[batchIndex].batch.empty())
return;
1579 vk::Pipeline pipe = swapchainSolidPipe(solid[batchIndex].
blend);
1581 uploadSolid(batchIndex);
1582 vk::DeviceSize
offset = 0;
1583 cb.bindPipeline(vk::PipelineBindPoint::eGraphics, pipe);
1584 cb.bindVertexBuffers(0, 1, solidBufs[batchIndex], &
offset);
1588 auto replaySpans = [&](
const std::vector<OverlaySpan> &
list) {
1589 for (
const auto &sp :
list) {
1590 if (sp.kind == OverlayKind::Solid && sp.index < solid.size() && sp.vertCount > 0) {
1591 drawSolidSpan(sp.index, sp.vertBegin, sp.vertCount);
1592 }
else if (sp.kind == OverlayKind::Textured && (texPipeline || hdrOffscreenTexPipeline) &&
1593 sp.index < textured.size()) {
1594 drawTextured(textured[sp.index]);
1595 }
else if (sp.kind == OverlayKind::Lit && litAvailable && sp.index < lit.size()) {
1596 std::vector<LitBatch> one;
1597 one.push_back(std::move(lit[sp.index]));
1598 drawLitBatches(cb,
width,
height, one, texBufs, texBufIndex,
false);
1599 }
else if (sp.kind == OverlayKind::GpuParticles && sp.index < gpuParticleDraws.size()) {
1600 drawGpuParticleRequest(cb, gpuParticleDraws[sp.index]);
1605 bool engineDrawn =
false;
1606 auto drawEngine3D = [&]() {
1607 if (engineDrawn)
return;
1609 replaySpans(engineSpans);
1612 auto drawPlacedSceneResolve = [&](TexturedBatch &
placed) {
1613 if (!sceneResolve) {
1617 TexturedBatch blit = *sceneResolve;
1618 const glm::vec4 acesColor = sceneResolve->batch.vertices().empty()
1619 ? glm::vec4(1.f, 1.f, 1.f, 65536.f)
1621 const auto &src =
placed.batch.vertices();
1622 if (src.size() >= 6) {
1623 const float x = src[0].pos.x;
1624 const float y = src[0].pos.y;
1625 const float w = src[1].pos.x -
x;
1626 const float h = src[2].pos.y -
y;
1627 const glm::vec4
tint = src[0].color;
1629 blit.batch.addTexturedRect(
x,
y,
w,
h,
1631 tint.b * acesColor.b, acesColor.a),
1632 src[0].uv.x, src[0].uv.y, src[1].uv.x, src[2].uv.y);
1634 drawTextured(blit,
true);
1639 if (autoScene && sceneResolve) {
1640 drawTextured(*sceneResolve,
true);
1644 if (spans.empty() && engineSpans.empty()) {
1645 for (
size_t i = 0; i < solid.size(); ++i) {
1646 if (!solid[i].batch.empty())
1647 drawSolidSpan(uint32_t(i), 0, uint32_t(solid[i].batch.vertices().size()));
1649 if (texPipeline || hdrOffscreenTexPipeline) {
1650 for (
auto &
tb : textured) drawTextured(
tb);
1652 if (litAvailable) drawLitBatches(cb,
width,
height, lit, texBufs, texBufIndex,
false);
1654 for (
const auto &sp : spans) {
1655 if (sp.kind == OverlayKind::Solid && sp.index < solid.size() && sp.vertCount > 0) {
1656 drawSolidSpan(sp.index, sp.vertBegin, sp.vertCount);
1657 }
else if (sp.kind == OverlayKind::Textured &&
1658 (texPipeline || hdrOffscreenTexPipeline) && sp.index < textured.size()) {
1663 const bool placedScene =
1664 sceneResolve && textured[sp.index].texture == sceneTex &&
1665 textured[sp.index].effect != TexturedBatch::Effect::SceneColorDistortion;
1667 drawPlacedSceneResolve(textured[sp.index]);
1669 drawTextured(textured[sp.index]);
1674 }
else if (sp.kind == OverlayKind::Lit && litAvailable && sp.index < lit.size()) {
1675 std::vector<LitBatch> one;
1676 one.push_back(std::move(lit[sp.index]));
1677 drawLitBatches(cb,
width,
height, one, texBufs, texBufIndex,
false);
1678 }
else if (sp.kind == OverlayKind::GpuParticles && sp.index < gpuParticleDraws.size()) {
1679 drawGpuParticleRequest(cb, gpuParticleDraws[sp.index]);
1684 if (uiResolve) drawTextured(*uiResolve);
1692 VkCommandBuffer
raw =
static_cast<VkCommandBuffer
>(cb);
1696 if (presentComposeActive_) {
1697 endPresentComposePass();
1698 beginSwapchainColorPass();
1699 swapchainPassOpen =
true;
1700 auto &presentCb = currentPresentCb();
1701 setViewportAndScissor(presentCb, swapchain.extent.width, swapchain.extent.height);
1702 encodePresentComposeToSwapchain(presentCb);
1705 presentRecording = swapchainPass.endRenderPass();
1707 const bool captured =
1709 writeGpuTimestampEnd();
1710 recordFrameCapture(presentRecording.commandBuffer());
1713 submitGpuTimingPrefix();
1714 presentRecording.end().submitAndPresent();
1715 submittedPresentSequence_ = presentSequence_;
1717 markFrameCaptureSubmitted();
1718 presentRecording = {};
1720 hasPresentedFrame =
true;
1721 readbackReady =
true;
1722 readbackCpuSynced =
false;
1724 hasPendingClear =
false;
1725 swapchainPassOpen =
false;
graphics::Texture * albedo
vk::UniqueSampler sampler
Entity-ID / isolated visibility capture kept off Graphics.h.
std::shared_ptr< OceanGpuSpectrum > gpu
std::weak_ptr< PrimitiveScene > scene
#define EV_PROFILE_MODULE(module, name)
Profile the enclosing scope, tagged with a module for grouping.
std::array< double, 2 > vertices[3]
EVENGINE_API_FOUNDATION public API.
Accumulates solid / textured quads in logical (Y-down) coordinates. Used by RenderSystem; not a publi...
void addTexturedRect(float x, float y, float w, float h, const Color &color, float u0, float v0, float u1, float v1, bool rotatedUV=false)
Adds textured rect.
void addTexturedRectRotated(float cx, float cy, float w, float h, float degrees, const Color &color, float u0, float v0, float u1, float v1, bool rotatedUV=false)
Textured quad rotated degrees (clockwise, screen Y-down) around (cx, cy).
void toNDC(int logicalW, int logicalH)
To ndc.
const std::vector< BatchVertex > & vertices() const
Vertices.
virtual void clear(std::optional< Color > color, std::optional< int > stencil, std::optional< double > depth)=0
Clears .
bool screenReadbackEnabled
virtual image::ImageData * readGBufferToImageData(const std::string &attachment)
Read a G-buffer attachment back to CPU as RGBA8. name is one of "depth" (RGBA8 linear depth),...
virtual void drawTexturedRectShader4(Texture *color, Texture *depth, Texture *motion, Texture *extra, Shader *shader, float x, float y, float w, float h, const Color &tint)=0
Post draw with four sampled textures at bindings 0, 1, 2 and 3.
virtual Shader * newMeshShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Create a Mesh3D custom shader (MeshVertex + Frame UBO + albedo). Empty vert → default mesh3d....
int getWidth() const
Returns the width.
virtual Shader * newHairShaderFromWgsl(const std::string &vertWgsl, const std::string &fragWgsl)=0
Create an alpha-blended hair/card shader from WGSL on WebGPU.
virtual Shader * newShaderFromWgsl(const std::string &vertWgsl, const std::string &fragWgsl)=0
Create a 2D custom shader from WGSL source (WebGPU backend). Empty vert → default textured vertex sha...
virtual void drawTexturedRectShaderUV(Texture *texture, Shader *shader, float x, float y, float w, float h, float u0, float v0, float u1, float v1, const Color &color, bool rotatedUV=false, BlendMode blend=BlendMode::Alpha)=0
UV draw with an explicit Shader (nullptr = default textured pipeline).
virtual Shader * newMeshShader(const std::string &vertGlsl, const std::string &fragGlsl)=0
Creates a mesh shader. @ownership Caller deletes unless documented otherwise.
virtual void drawTexturedRectLitUVRotated(Texture *albedo, Texture *normal, float cx, float cy, float w, float h, float degrees, float u0, float v0, float u1, float v1, const Color &color, BlendMode blend=BlendMode::Alpha)=0
Lit 2D draw rotated degrees clockwise (screen Y-down) around (cx, cy). Fragment tangent frame is rebu...
bool recordingEngine3D_
True while RenderSystem3D is submitting (AO / engine overlays).
virtual void setLighting2D(const Lighting2DUBO &ubo)=0
Upload per-frame / per-canvas 2D lighting constants for subsequent lit draws.
virtual image::ImageData * readDecalLayerToImageData(const std::string &attachment)
Read back a DecalLayer attachment ("albedo" | "normal" | "params") to CPU. Renders the pending G-buff...
virtual SceneColorDistortionStatus drawSceneColorDistortionUVRotated(Texture *displacement, float cx, float cy, float w, float h, float degrees, float u0, float v0, float u1, float v1, float strengthPixels, float opacity, bool rotatedUV=false)
Draws scene color distortion uv rotated.
SceneColorDistortionStatus
Refract the resolved 3D scene color through a displacement texture.
virtual Canvas * getCanvas() const =0
Returns the canvas.
virtual bool isDisplayHdrActive() const
True when the live swapchain is scRGB or HDR10.
virtual void drawSolidRect(float x, float y, float w, float h, float r, float g, float b, float a=1.f)
RGBA-float overload matching the script-facing drawSolidRect name.
void ensureFileTexturesReady()
Finish CPU decode and GPU upload for outstanding newTextureFromFile results. @thread Game/render thre...
virtual Shader * newShader(const std::string &vertGlsl, const std::string &fragGlsl)=0
Compile GLSL source with the engine's build-time GLSL compiler. Empty vertGlsl → default textured ver...
virtual void drawTexturedRectShaderUVRotated(Texture *texture, Shader *shader, float cx, float cy, float w, float h, float degrees, float u0, float v0, float u1, float v1, const Color &color, bool rotatedUV=false, BlendMode blend=BlendMode::Alpha)=0
UV draw rotated degrees clockwise (screen Y-down) around the rect center. texture may be null → solid...
virtual Texture * newTexture(int width, int height, const uint8_t *rgba, bool repeatU=false, bool repeatV=false)=0
Creates a texture. @ownership Caller deletes unless documented otherwise.
void setCanvas()
Sets the canvas.
void * presentOverlayUser_
virtual Shader * newHairShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Hair/fur card shader (alpha blend + Kajiya-Kay). Empty vert → mesh3d_hair.vert. Owned by Graphics.
virtual void drawSolidRectRotated(float cx, float cy, float w, float h, float degrees, const Color &color, BlendMode blend=BlendMode::Alpha)=0
Rotated solid quad degrees clockwise (screen Y-down) around (cx, cy).
virtual bool releaseShader(Shader *shader)
Eagerly releases a shader created by this Graphics.
virtual bool isCanvasActive() const =0
True when canvas active.
virtual void drawTexturedRectShaderDepthMotion(Texture *color, Texture *depth, Texture *motion, Shader *shader, float x, float y, float w, float h, const Color &tint)=0
Post draw with color, depth/history and motion/reactive textures.
virtual float getMaxAnisotropy() const =0
Device max supported anisotropy (1 if unsupported). Valid after initWithWindow.
virtual void drawTexturedRectUV(Texture *texture, float x, float y, float w, float h, float u0, float v0, float u1, float v1, const Color &color)=0
Draw a textured sub-rect (atlas / tile UVs). texture may be null → solid.
virtual void drawTexturedRect(Texture *texture, float x, float y, float w, float h, float r, float g, float b, float a=1.f)
RGBA-float overload matching the script-facing drawTexturedRect name.
virtual Shader * newShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Create a custom 2D shader from SPIR-V words (vert + frag). Owned by Graphics. Vertex stage may be emp...
virtual Canvas * newHDRCanvas(int width, int height)=0
Create an engine-internal linear RGBA16F post-process target.
virtual Texture * getSceneColorTexture()
Sampleable 3D color target for the current frame (RGB = lit, A = linear depth). Valid after begin3DFr...
PresentOverlayFn presentOverlayFn_
virtual void drawTexturedRectShader5(Texture *color, Texture *depth, Texture *motion, Texture *extra, Texture *specular, Shader *shader, float x, float y, float w, float h, const Color &tint)=0
Post draw with five sampled textures at bindings 0 through 4.
virtual Canvas * newCanvas(int width, int height)=0
Create an offscreen render target (sampleable). Owned by Graphics.
virtual Shader * newMeshShaderFromWgsl(const std::string &vertWgsl, const std::string &fragWgsl)=0
Create a Mesh3D custom shader from WGSL source (WebGPU backend). The WGSL must declare the engine's F...
virtual void setViewportSize(int width, int height, int pixelwidth, int pixelheight)=0
Sets the current graphics display viewport dimensions.
virtual void drawTexturedRectLitUV(Texture *albedo, Texture *normal, float x, float y, float w, float h, float u0, float v0, float u1, float v1, const Color &color, BlendMode blend=BlendMode::Alpha)=0
Lit 2D draw (albedo + normal map). Uses Lighting2DUBO from setLighting2D. normal may be null → treate...
int getHeight() const
Returns the height.
virtual Shader * newShaderFromSpvFile(const std::string &vertPath, const std::string &fragPath)=0
Load SPIR-V from files via Filesystem (empty vertPath → default textured vert).
virtual void drawTexturedRectShader(Texture *texture, Shader *shader, float x, float y, float w, float h, const Color &color)=0
Draw with an explicit Shader (nullptr = default textured pipeline).
virtual void applyPendingResourceChanges()
Publish queued resource state before its next consuming draw. @thread Graphics thread; no callbacks....
virtual void drawTexturedRectShaderDepth(Texture *color, Texture *depth, Shader *shader, float x, float y, float w, float h, const Color &tint)=0
Fullscreen/post draw sampling color at binding 0 and depth at binding 1 (hardware D32,...
virtual void drawPrimitiveCanvas(const PrimitiveCanvas2D &canvas)=0
Resolves and queues one frame-local primitive Canvas.
Frame-local Skia-style recorder for 2D line primitives.
Declarative, compilable 3D render control.
static constexpr uint32_t kPushConstantBytes
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
EVENGINE_API_BACKENDS public API.
Color getPixel(int x, int y) override
Returns the pixel.
image::ImageData * renderEntityIdMask(const std::vector< EntityIdDraw > &draws, const glm::mat4 &viewProj, int width, int height) override
Renders entity id mask. @ownership Result transfers to caller. Draw inputs are borrowed only for this...
image::ImageData * newImageData() override
Creates a image data. @ownership Caller deletes unless documented otherwise.
void clear(std::optional< Color > color, std::optional< int > stencil, std::optional< double > depth) override
Clears .
OffscreenCanvas public API.
Represents raw pixel data.
void recordFrameReadback(vk::CommandBuffer cb, vk::Image source, vk::Buffer destination, vk::Extent2D extent, vk::ImageAspectFlags aspect, uint32_t layer, vk::ImageLayout originalLayout)
FilterMode
Mag/min filter for texture sampling.
std::vector< std::uint32_t > compileGlslToSpirv(const std::string &source, GlslStage stage, const std::string &debugName)
Compile GLSL text to SPIR-V words.
ResolvedPrimitiveTriangles resolvePrimitiveStrokes2D(const PrimitiveCanvas2D &canvas, glm::ivec2 viewport)
Resolves 2D stroke segment bodies into clip-space triangles.
eve::Color Color
RGBA color used by every graphics draw call. Lives inside eve::graphics so including a graphics heade...
MipmapMode
Mipmap filter; Disabled turns off mip sampling (maxLod clamped to 0).
eve::BlendMode BlendMode
Compatibility alias for the shared 2D blend mode.
GlslStage
GLSL stage accepted by compileGlslToSpirv.
ControlEdit combo(const char *label, int &selected, const std::vector< const char * > &items)
Shared immediate renderer for indexed combo boxes.
WidgetDesc list(std::string listId, const std::vector< std::string > &items, const std::function< WidgetDesc(const std::string &, int)> &itemFn)
Expand a string list into a Group of item widgets. itemFn(label, index) builds each row; keys default...
BlendMode
Render-neutral 2D blend mode shared by graphics-facing modules.
Lighting2DUBO public API.
Resolved triangle vertex consumed by primitive GPU backends.
One contiguous 2D blend/order batch in the resolved vertex stream.
Sampler state for a Texture (filter, wrap, mip LOD, anisotropy). Defaults match historical engine beh...
vkb::BoundSet descriptorSet
TexturedVertex public API.
Backend-internal textured rectangle queued by a UI presenter.