Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::editor::ImGuiRuntimeRenderer Class Reference

Draws one frame of UI draw data through donner::gpu. More...

#include "donner/editor/gui/ImGuiRuntimeRenderer.h"

Public Member Functions

std::weak_ptr< const void > retirementLifetime () const
 Owner token for deferred registration release; expires before renderer fields are destroyed.
 ~ImGuiRuntimeRenderer ()
 Destructor.
 ImGuiRuntimeRenderer (const ImGuiRuntimeRenderer &)=delete
ImGuiRuntimeRenderer & operator= (const ImGuiRuntimeRenderer &)=delete
 ImGuiRuntimeRenderer (ImGuiRuntimeRenderer &&)=delete
ImGuiRuntimeRenderer & operator= (ImGuiRuntimeRenderer &&)=delete
gpu::Status buildFontAtlas (ImFontAtlas &atlas)
 Uploads atlas as the font texture, registers it, and publishes its identifier as the atlas texture id.
gpu::Status render (const ImDrawData &drawData, gpu::RenderPassEncoder &pass, const gpu::Extent2d &targetSizePx)
 Records drawData into pass.
std::vector< UiTextureId > advanceFrame ()
 Advances one presentation frame: releases the registrations whose retirement frames have passed and drops the bind group cached for each, so a cache entry and its device bind group do not outlive the registration they were built for.
void retainTextureBackingUntilReleased (UiTextureId id, gpu::Texture texture, gpu::TextureView view)
 Transfers backing handles for a retired registration until its exact generation is released.
size_t retainedTextureBackingCountForTest () const
 Number of retired texture backings still held. Test accessor.
void resetRendererState ()
 Drops the cached per-texture bind groups and the recorded pipeline selection, so the next render rebinds from scratch.
size_t cachedBindingCount () const
 Number of bind groups currently cached, one per registration drawn since the last reset.
void install ()
 Publishes this renderer on the current ImGui context, so UI code that owns a texture can reach the registry its draw commands are resolved through without every panel being handed one.
void uninstall ()
 Stops publishing this renderer on the current ImGui context, if it is the published one.
UiTextureId fontAtlasTexture () const
 Identifier of the registered font atlas, null until buildFontAtlas succeeds.
UiTextureRegistry & registry () const
 Registry this renderer resolves draw commands through.
gpu::Device & device () const
 Device this renderer draws on. A texture registered for it must belong to this device, which is not necessarily the device its pixels were rendered on.
uint64_t vertexCapacityBytes () const
 Bytes currently allocated for vertices.
uint64_t indexCapacityBytes () const
 Bytes currently allocated for indices.

Static Public Member Functions

static gpu::Result< std::unique_ptr< ImGuiRuntimeRenderer > > Create (gpu::Device &device, UiTextureRegistry &registry, gpu::TextureFormat targetFormat)
 Creates a renderer drawing into targetFormat attachments.

Static Public Attributes

static constexpr uint64_t kMaxVertexBytes = uint64_t(64) * 1024 * 1024
 Largest vertex payload one frame may upload.
static constexpr uint64_t kMaxIndexBytes = uint64_t(32) * 1024 * 1024
 Largest index payload one frame may upload.

Detailed Description

Draws one frame of UI draw data through donner::gpu.

The renderer owns the compiled UI draw program, one pipeline per alpha interpretation, the per-frame vertex and index buffers, the projection uniform, the sampler, and the font atlas it registers. It resolves the texture of every draw command through a UiTextureRegistry, so a command naming a stale, foreign or retired registration is refused before any GPU work is recorded rather than reaching a backend as an unchecked address.

Vertex and index storage grows to fit a frame and never shrinks within a frame, which matches how the UI layer itself grows its draw lists. Growth is bounded: a frame needing more than kMaxVertexBytes or kMaxIndexBytes is refused with gpu::GpuErrorType::LimitExceeded instead of allocating whatever the draw data asked for.

Member Function Documentation

◆ advanceFrame()

std::vector< UiTextureId > donner::editor::ImGuiRuntimeRenderer::advanceFrame ( )

Advances one presentation frame: releases the registrations whose retirement frames have passed and drops the bind group cached for each, so a cache entry and its device bind group do not outlive the registration they were built for.

Returns the released identifiers so the caller can drop whatever backing it held for them.

◆ buildFontAtlas()

gpu::Status donner::editor::ImGuiRuntimeRenderer::buildFontAtlas ( ImFontAtlas & atlas)

Uploads atlas as the font texture, registers it, and publishes its identifier as the atlas texture id.

Replaces and retires a previously built atlas, so rebuilding after a font change does not strand the old registration.

Parameters
atlasFont atlas whose RGBA32 pixels are uploaded.

◆ Create()

gpu::Result< std::unique_ptr< ImGuiRuntimeRenderer > > donner::editor::ImGuiRuntimeRenderer::Create ( gpu::Device & device,
UiTextureRegistry & registry,
gpu::TextureFormat targetFormat )
static

Creates a renderer drawing into targetFormat attachments.

Parameters
deviceDevice that owns every resource created here; must outlive the renderer.
registryRegistry every draw command's texture is resolved through; must outlive the renderer.
targetFormatColor attachment format the pipelines are built for.

◆ install()

void donner::editor::ImGuiRuntimeRenderer::install ( )

Publishes this renderer on the current ImGui context, so UI code that owns a texture can reach the registry its draw commands are resolved through without every panel being handed one.

Transitional: the renderer is held in its own pointer rather than the context's renderer-backend slot, because UI code that still calls the previous backend's functions would read whatever occupies that slot as its own data type. This reverts to the idiomatic slot once the last caller of the previous backend is gone.

The caller keeps ownership; uninstall must run before the renderer is destroyed.

◆ render()

gpu::Status donner::editor::ImGuiRuntimeRenderer::render ( const ImDrawData & drawData,
gpu::RenderPassEncoder & pass,
const gpu::Extent2d & targetSizePx )

Records drawData into pass.

Nothing is recorded for empty draw data or a degenerate framebuffer.

A command this renderer cannot record is skipped and the rest of the frame is still recorded; the first such failure is returned once the frame is complete. A draw naming a texture the registry refuses, or carrying a user callback other than the render-state reset, therefore costs that draw rather than the whole interface, and still reports why. A failure that leaves the pass unusable for the commands after it - exceeding the upload bounds, or a failed state rebind - ends the frame instead.

Parameters
drawDataDraw data for the frame.
passOpen render pass whose attachment matches the renderer's target format.
targetSizePxAttachment extent in device pixels; scissor rectangles are clamped to it.

◆ resetRendererState()

void donner::editor::ImGuiRuntimeRenderer::resetRendererState ( )

Drops the cached per-texture bind groups and the recorded pipeline selection, so the next render rebinds from scratch.

The buffers and their capacity are retained.


The documentation for this class was generated from the following file: