Skip to content

Engine → Renderer → imgui_renderer.h

imgui_renderer

Syntax

class CONJURE_API imgui_renderer

Constructors

AccessSignatureDescription
publicexplicit imgui_renderer( create_tag);

Important

Copy constructor and assignment has been deleted.

Destructors

AccessSignatureDescription
public~imgui_renderer();

Variables

AccessNameTypeDefaultDescription
privatemImplstd::unique_ptr<impl>{}

Functions

Public

attach_to_current_context

void attach_to_current_context() noexcept;

Declares this backend in the current ImGui context: io.BackendRendererName and the capability flags (ImGuiBackendFlags_RendererHasVtxOffset, and RendererHasTextures under ImGui >= 1.92), which ImGui reads at NewFrame. create() does it for a context that is current then; the owner of a context created later (engine::imgui_layer::on_attach) calls it right after creating the context, and render() does it for a context that has no renderer backend yet. Without a current context it does nothing; calling it again is harmless.

create

[[nodiscard]] static core::result<std::unique_ptr<imgui_renderer>> create(
    rhi::device &device,
    rhi::shader_library &shaders,
    rhi::texture_format targetFormat,
    imgui_texture_resolver resolver);

Builds the pipeline (imgui.hlsl: premultiplied alpha, scissor, no depth) for the given framebuffer colour format from the "imgui" program of shader_asset's built-in table, and declares the backend in the current ImGui context, if there is one (attach_to_current_context). Fails with renderer_error::SHADER_NOT_FOUND naming the shader key when the library's index lacks a stage of that program (both stages are checked before any device object is created) or a listed blob file cannot be read (found when that stage is loaded), with PIPELINE_CREATION_FAILED when the device refuses a shader, the layouts or the pipeline, and with RESOURCE_CREATION_FAILED when it refuses the sampler or the buffers. With a null resolver no registered texture ever resolves, so each draws with the font atlas texture.

font_atlas_invalidations

[[nodiscard]] u64 font_atlas_invalidations() const noexcept;

How many times invalidate_font_atlas() was called on this backend: what an owner that rebuilds the atlas (the editor's theme applier) is checked against.

invalidate_font_atlas

void invalidate_font_atlas() noexcept;

Marks the font atlas as changed so the next render() re-uploads it (ImGui 1.91: call it after io.Fonts->Build(), or reset io.Fonts->TexID to 0, which has the same effect). A no-op under the 1.92 texture protocol, where ImGui reports the change itself.

register_texture

[[nodiscard]] u64 register_texture(
    gpu_texture_id texture);

Makes a renderer texture usable as an ImTextureID (returned packed as a u64). The id stays valid until unregister_texture or destruction; a stale texture draws with the font atlas texture instead.

render

void render(
    ImDrawData *drawData,
    nvrhi::IFramebuffer *target,
    nvrhi::ICommandList &commandList);

Draws one frame of ImGui output into target (whose colour format matches the one given at creation). Handles the texture requests carried by the draw data first (ImGui >= 1.92) or the font atlas (1.91). Declares the backend in the current context first when that context has no renderer backend yet. A null drawData or an empty frame draws nothing.

stats

[[nodiscard]] const imgui_render_stats &stats() const noexcept;

target_format

[[nodiscard]] rhi::texture_format target_format() const noexcept;

The framebuffer colour format the pipeline was built for (the swapchain's).

texture_count

[[nodiscard]] u32 texture_count() const noexcept;

Number of textures the backend currently knows (font atlas and registered ones).

unregister_texture

void unregister_texture(
    u64 textureId);

Forgets a registered texture; unknown handles are ignored.

uses_texture_protocol

[[nodiscard]] static bool uses_texture_protocol() noexcept;

True when the running ImGui implements the 1.92 texture protocol.