Rendering a frame¶
How to create the renderer, describe what a frame contains, render into the window or into a target, read
pixels back, draw sprites and debug lines, and tune the look. Headers: conjure/renderer/renderer.h,
conjure/renderer/render_scene.h, conjure/renderer/camera.h, conjure/renderer/light.h,
conjure/renderer/render_settings.h, conjure/renderer/render_target.h, conjure/renderer/sprite_batch.h,
conjure/renderer/debug_draw.h, conjure/renderer/gpu_ids.h, conjure/renderer/limits.h,
conjure/renderer/components.h and conjure/renderer/imgui_renderer.h. Everything is in namespace
conjure::renderer.
| Name | Rendering a frame |
| Module | Renderer |
#include |
conjure/renderer/camera.h, conjure/renderer/components.h, conjure/renderer/debug_draw.h, conjure/renderer/gpu_ids.h, conjure/renderer/imgui_renderer.h, conjure/renderer/light.h, conjure/renderer/limits.h, conjure/renderer/render_scene.h, conjure/renderer/render_settings.h, conjure/renderer/render_target.h, conjure/renderer/renderer.h, conjure/renderer/sprite_batch.h |
| Engineering Handbook | Engineering handbook |
Syntax¶
#include "conjure/renderer/render_scene.h"
#include "conjure/renderer/renderer.h"
using namespace conjure;
void fill_frame(renderer::renderer &frame, renderer::gpu_mesh_id mesh, renderer::gpu_material_id material) {
renderer::render_scene &scene = frame.begin_extract();
renderer::render_view view = {}; // target invalid = the swapchain
view.cameraData.verticalFovRadians = 1.0472f;
view.cameraPosition = math::vec3(0.0f, 2.0f, 6.0f);
view.viewFromWorld = math::look_at(view.cameraPosition, math::vec3(0.0f), math::vec3(0.0f, 1.0f, 0.0f));
scene.views.push_back(view);
const std::span<renderer::mesh_instance> instances = scene.allocate_meshes(100);
for (u32 index = 0; index < instances.size(); ++index) {
instances[index].mesh = mesh;
instances[index].materials[0] = material;
const math::vec3 position(static_cast<f32>(index % 10) - 5.0f, 0.0f, -static_cast<f32>(index / 10));
instances[index].worldFromLocal = glm::translate(math::mat4(1.0f), position);
instances[index].worldBounds = math::aabb{position - math::vec3(0.5f), position + math::vec3(0.5f)};
}
renderer::light sun = {};
sun.type = renderer::light_type::DIRECTIONAL;
sun.direction = glm::normalize(math::vec3(0.3f, -1.0f, 0.2f));
sun.castsShadows = true;
scene.lights.push_back(sun);
frame.end_extract();
}
The engine calls render_frame() after extraction; the pair of scenes inside the renderer means the frame being
rendered and the frame being extracted never share a buffer.
At a glance¶
| You want to... | Use |
|---|---|
| Create the renderer | renderer::create(renderer_desc) with a device, a shader library and (optionally) a swapchain and job system |
| Put an asset on the GPU / take it off | upload_mesh(id, mesh), upload_texture, upload_material, upload_environment; release_*(gpuId) |
| Find the GPU id of an asset uploaded earlier | find_mesh(assetId), find_texture, find_material, find_environment |
| Render what the engine extracted | render_scene &scene = begin_extract(); ... end_extract(); render_frame(); |
| Render a scene you built yourself | render(scene) |
| Render off-screen | create_render_target(desc), set render_view::target, read_back(target) for the pixels |
| Add a view of your own to the engine's frame | submit_view(view) every frame it should be drawn (an editor viewport, a screenshot) |
| Give the window a colour wherever no view draws | set_back_buffer_clear(colour) (sRGB, as a theme writes it); std::nullopt clears nothing |
| Smooth jagged edges | the anti-aliasing group of the rendering settings: MSAA at 2, 4 or 8 samples, FXAA, or both; set_anti_aliasing(settings) overrides it, clear_anti_aliasing_override() ends that (Anti-aliasing) |
| Show a view's picture over a backdrop of your own | view_flags::KEEP_COVERAGE_ALPHA: the image stays transparent where nothing drew |
| React to window events | resize_swapchain(size), on_device_lost() |
| Know what happened | stats() (render_stats), frame_count(), pending_upload_count(), is_lost() |
| Draw sprites | push sprite values into render_scene::sprites (world or screen space) |
| Draw debug lines | render_scene::debugDraw.line(...), box, sphere, frustum, axes, grid; debug_draw for timed shapes |
| Project and unproject | clip_from_view(camera, aspect), frustum_from_clip(clipFromWorld), ray_from_viewport(...) |
| Register the renderer's components for the ECS | register_components(typeRegistry) |
Variables and Properties¶
Types, fields, and state are described in the reference sections below.
Creating the renderer¶
renderer_desc names the rhi::device, the rhi::shader_library (the index conjure_add_shaders built), an
optional rhi::swapchain (null = headless, every view must name a target), an optional core::jobs::job_system
(culling and draw-list building run on it), the cascade and atlas resolutions, and enableImGui. The atlas
resolution is clamped to [256, 16384] and rounded down to a power of two, with a WARN when that changes it (3000
becomes 2048); desc() still reports the value you passed.
renderer::create builds every pipeline, binding layout, fallback resource and the BRDF lookup table up front;
it fails with SHADER_NOT_FOUND (naming the shader key), PIPELINE_CREATION_FAILED, RESOURCE_CREATION_FAILED
or INVALID_ARGUMENT. Nothing is created mid-frame afterwards.
Uploads and GPU ids¶
upload_mesh(assetId, mesh) and friends copy the payload bytes immediately, reserve a slot and return a
gpu_mesh_id (gpu_texture_id, gpu_material_id, gpu_environment_id) that is valid at once; until the upload
runs at the start of a later frame the id draws the fallback. Uploading under an asset id already known replaces
the GPU mirror and keeps the id. release_* makes the id stale now and frees the GPU objects a few frames later.
A stale id draws the fallback and WARNs once. Uploads are budgeted (UPLOAD_BUDGET_BYTES_PER_FRAME, 64 MB per
frame); render_stats::uploadsPending says how many wait.
Tip
Upload textures before the materials that use them: a material resolves its textures by asset id at upload
time (find_texture), and a texture that arrives later is picked up at the next flush.
Describing a frame¶
render_scene member |
Meaning |
|---|---|
views |
up to MAX_VIEWS render_views: cameraData (camera), viewFromWorld, cameraPosition, viewport (empty = whole target), target (invalid = swapchain), flags (DRAW_DEBUG, NO_POST_PROCESS, SKIP_SHADOWS, ISOLATED_SHADOWS, KEEP_COVERAGE_ALPHA), layerMask |
meshes |
mesh_instance: mesh, materials[MAX_MATERIAL_SLOTS], worldFromLocal, worldBounds (used for culling: fill it), entityId, layerMask, castsShadows, receivesShadows; allocate_meshes(count) sizes the array once so jobs can fill ranges |
lights |
light: type (DIRECTIONAL, POINT, SPOT), position, direction, colour, intensity (lux or candela), range, cone angles, sourceRadius, castsShadows, filter, shadowResolution (256, 512 or 1024) |
sprites |
sprite values in WORLD or SCREEN space; sorted and batched by the renderer |
environment |
environment_settings: the environment id, intensity and rotation |
postProcess, shadows, ssao |
post_process_settings (exposure_mode::AUTOMATIC or MANUAL, EV limits, bloom, tonemap_operator::ACES_FITTED, REINHARD_EXTENDED, AGX or NONE), shadow_settings (cascades, filtering), ssao_settings |
debugDraw |
a debug_draw_buffer of lines for this frame |
frameIndex, deltaSeconds |
timing for exposure adaptation |
camera is projection only (PERSPECTIVE with verticalFovRadians or ORTHOGRAPHIC with
orthographicHeight, near and far planes); the view's viewFromWorld matrix places it. clip_from_view(camera,
aspect) builds the reverse-Z projection, frustum_from_clip the culling planes and ray_from_viewport a picking
ray from a pixel.
Everything beyond a budget is clamped and counted, never fatal: views past MAX_VIEWS are skipped
(render_stats::viewsSkipped), lights past MAX_LIGHTS_PER_VIEW dropped (lightsDropped), sprites past
MAX_SPRITES_PER_FRAME dropped (spritesDropped), and debug vertices past MAX_DEBUG_VERTICES refused
(debug_draw_buffer::dropped_count(), never logged). A view whose camera clip_from_view would reject (near
not above zero, far not beyond near, a field of view outside (0, pi), an orthographic height not above zero, or a
non-finite value) renders with those fields clamped or reset to the defaults. A view naming a render target the
renderer does not know, for example one that was destroyed, is skipped and counted in viewsSkipped.
Note
The log tells you when a problem began, the statistics how big it is now. A WARN is written by the frame in
which a problem starts and not again while it lasts, even when its size changes: 70 000 sprites one frame and
90 000 the next is one line, not two. A later frame that checks and finds the problem gone arms the WARN again.
This holds for views, lights and sprites over their budget; per view index for a clamped camera and an unknown
render target; and for a swapchain that refuses to acquire a back buffer (the frame is skipped, viewsSkipped
is the scene's view count) or to present.
Not every frame checks everything. A frame skipped at the acquire checks nothing else. The light budget and a
view's camera are checked only when a view is drawn, and the per-view state belongs to the position in
scene.views, not to the view: a frame with fewer views leaves the higher positions as they were. A view
targeting the swapchain of a renderer created without one is logged once for the life of the renderer.
A view draws an instance when the two layer masks share a bit (instance.layerMask & view.layerMask). The sun's
shadow cascades are culled with each view's own mask. The shadows of spot and point lights live in one atlas
shared by every view of the frame, so its casters are culled with the union of the masks of every view that
draws with shadows (every view without SKIP_SHADOWS). A view with view_flags::ISOLATED_SHADOWS uses only the
casters on its own mask for those shadows too, as its cascades do, and its mask stays out of the union; the atlas
is drawn again once at each change of caster set along the view order. The editor's camera views are isolated.
Note
Every view sees the local-light shadows of its own casters, whatever the view order. A view may also see the shadows of casters on layers that only another view renders.
The window: clearing and colour encoding¶
Clearing the back buffer¶
A view without a target draws into the swapchain's back buffer. By default the renderer clears nothing there,
because a game's cameras cover the whole window. A window that the views do not cover calls
set_back_buffer_clear(colour): the editor, whose panels cover it, or a game that letterboxes its cameras. Every
frame then clears the back buffer to that colour right after acquiring it, before any view and before the ImGui
pass, so a pixel that nothing draws shows the colour instead of an older frame.
back_buffer_clear()returns the colour as you gave it;set_back_buffer_clear(std::nullopt)turns the clear off.render_stats::backBufferClearedis true for a frame that cleared.- Without a swapchain there is nothing to clear, and a frame skipped at the acquire clears nothing.
- Where the back buffers cannot be transfer destinations (
rhi::swapchain::back_buffer_transfer_destination()is false, as on a Vulkan surface withoutTRANSFER_DST), the renderer draws the colour over the whole back buffer instead. That stores the same value and counts one more draw call.
The colour is display-referred sRGB in 0 to 1, as a designer or a theme file writes it: #1E1F24 is
(30 / 255, 31 / 255, 36 / 255, 1). The renderer converts it to the swapchain's encoding once, when you set it, so
the window shows exactly that colour whatever the format: linearised for an RGBA8_SRGB or float swapchain,
unchanged for RGBA8_UNORM. Alpha is never converted, channels outside 0 to 1 are clamped, and a NaN channel
reads 0.
#include "conjure/renderer/renderer.h"
#include <optional>
using namespace conjure;
// A letterboxed game: the bars outside the camera's viewport show #1E1F24, never an older frame.
void set_letterbox(renderer::renderer &frame, bool letterboxed) {
if (!letterboxed) {
frame.set_back_buffer_clear(std::nullopt); // the camera covers the window again
return;
}
frame.set_back_buffer_clear(math::vec4(30.0f / 255.0f, 31.0f / 255.0f, 36.0f / 255.0f, 1.0f));
}
Warning
set_back_buffer_clear belongs to the render thread (the main thread today), like render().
Display encoding¶
A colour target stores one of three things:
| Target format | Stores | Who encodes sRGB |
|---|---|---|
RGBA8_SRGB, BGRA8_SRGB |
linear values | the hardware, on write |
RGBA16_FLOAT, R11G11B10_FLOAT |
linear values | nobody: the values stay linear |
RGBA8_UNORM |
display values (sRGB-encoded) | the renderer's shaders, before writing |
The game runtime presents through an RGBA8_SRGB swapchain: the renderer writes a view's linear values straight
into the back buffer and the hardware encodes them. The editor presents through RGBA8_UNORM, so ImGui's colours
land as authored and blend in sRGB space, the way ImGui and the editor's themes assume. There, and in any
RGBA8_UNORM render target, the renderer finishes the view's image in an RGBA8_SRGB intermediate, and the final
blit encodes sRGB in its shader on the way in. An RGBA8_UNORM image therefore never holds linear values: it holds
the same display bytes that an RGBA8_SRGB image of the same view reads back as.
render_view::background is what a view's final image shows where nothing drew: no geometry, sprite, debug line
or sky. It is a core::rgba8 display colour, 8 bits per channel like a UI colour, and its alpha is not used. The
renderer adds it after exposure, bloom and the tonemap curve, so it is never exposed, bloomed or tonemapped, and
the encoding on the way out turns it back into the bytes you gave: a colour taken from a theme reads back
unchanged from an RGBA8_SRGB and from an RGBA8_UNORM target. A scene with an environment covers it with the
sky. Opaque black, the default, leaves the image as it would be without a background.
Keeping the coverage: view_flags::KEEP_COVERAGE_ALPHA¶
Every view's final image is opaque: alpha 1 on every pixel of its viewport, so a screenshot or a read_back of
the target holds what the window shows. A view with view_flags::KEEP_COVERAGE_ALPHA is the exception. Its image
keeps the scene's coverage as alpha: 0 where nothing drew, 1 under a solid surface or the sky, and the blended
coverage in between. render_view::background is not added. Use it for a picture you show over a backdrop of your
own; the editor's Scene panel draws its themed backdrop and grid, and they show wherever the scene drew nothing.
Warning
A KEEP_COVERAGE_ALPHA image is not opaque: where nothing drew, its alpha is 0. Composite it over something,
for example in ImGui, which blends by alpha, rather than using it as an opaque picture (a screenshot, a sprite).
Anti-aliasing¶
The renderer has two kinds of anti-aliasing, set once for every view it draws
(anti_aliasing_settings). They are independent: either, both or neither can be on, and both are off by default.
- MSAA (
msaaSampleCount: 1 is off, then 2, 4 or 8) renders the HDR, depth and normal targets with that many samples per pixel and resolves them before exposure (the passesmsaa_depth_resolveandmsaa_hdr_resolve). It smooths the edges of geometry, on every view. - FXAA (
post = post_anti_aliasing::FXAA) filters the tonemapped image before the screen sprites (the passfxaa). It also smooths the shading and alpha-test edges MSAA leaves, and it softens pixel art.fxaaSubpixelsets how much it softens: 0 filters edges only (the sharpest), 1 is the softest, 0.75 by default. Views that do not post-process skip it.
The value is the anti-aliasing group of the rendering settings: the project's rendering.defaults.anti_aliasing
(project.json), replaced by the group of a scene's render_settings
component that sets overrideAntiAliasing, resolved into render_scene::antiAliasing every frame. It has no camera
layer: one value renders every view, because the sample count fixes pipelines and targets, so a camera without
post-processing still renders with MSAA, never with FXAA.
The renderer is created with renderer_desc::antiAliasing; the engine passes the project's value, so that count's
pipelines exist from the first frame. Each render() then uses its scene's group. set_anti_aliasing(settings)
overrides the scene's group from the next frame, whatever later scenes carry, until clear_anti_aliasing_override();
a script's Rendering.AntiAliasing sets the same override. anti_aliasing() returns the value in effect: the override
while one is set, otherwise the group of the scene the last render() was given (renderer_desc::antiAliasing before
the first).
#include "conjure/renderer/renderer.h"
using namespace conjure;
// An options menu's "4x MSAA and FXAA", above the project's and the scene's. Render thread; next frame on.
u32 apply_high_quality(renderer::renderer &target) {
renderer::anti_aliasing_settings settings = {};
settings.msaaSampleCount = 4;
settings.post = renderer::post_anti_aliasing::FXAA;
settings.fxaaSubpixel = 0.5f;
target.set_anti_aliasing(settings);
// The count the frames will use: 4, or the largest count below it that this GPU has.
return renderer::effective_msaa_sample_count(settings.msaaSampleCount, target.supported_msaa_sample_counts());
}
create()andset_anti_aliasing()sanitise the value first, with one WARN when they change it: the sample count becomes the largest of 1, 2, 4 and 8 not above it (0 becomes 1), apostoutside its enum becomesNONE, andfxaaSubpixelis clamped to [0, 1] (a NaN becomes 0.75).sanitise(anti_aliasing_settings &)does the same to a value of your own.- A sample count the GPU lacks renders with the largest one it has below it.
supported_msaa_sample_counts()is a mask of the counts this renderer can use, whose bit value is the count (bit 1 is always set), andeffective_msaa_sample_count(requested, mask)gives the outcome.anti_aliasing()returns the value in effect, not as lowered;render_stats::msaaSampleCountreports the count a frame used. render()settles the anti-aliasing before it acquires the back buffer, so a scene that changes the group renders the new count from its own frame on.- When the device refuses a multisampled pipeline or target during a frame, the renderer logs one ERROR, renders that frame or the next with a lower count, and never retries the refused one.
Warning
set_anti_aliasing(), clear_anti_aliasing_override(), anti_aliasing() and supported_msaa_sample_counts()
belong to the render thread (the main thread in v1), like render().
Note
A multisampled set of targets is large: about 133 MB per view at 1080p and 4x. When a view's size or sample count
changes, the renderer releases the old set within TRANSIENT_MSAA_EVICTION_FRAMES (3) frames instead of the usual
120.
Lit surfaces also get specular anti-aliasing on their roughness, always on: where the shading normal changes quickly across a pixel (fine normal-map detail, a glossy curve far away), the highlight widens a little instead of flickering, and a badly aliasing surface stays glossy rather than turning fully rough. Under MSAA the texture coordinates are interpolated at the centroid, so a pixel on a triangle's edge never samples outside that triangle's part of the texture, such as a neighbouring tile of an atlas.
Targets and read-back¶
create_render_target(render_target_desc {size, colourFormat, withDepth}) returns a render_target_id;
get_render_target(id) gives size(), colour_texture() (a gpu_texture_id you may draw as a sprite or in
ImGui) and frames_rendered(); resize_render_target(id, size) recreates its textures and keeps both the target
id and the colour_texture() id, so a sprite or an ImGui handle that shows the target keeps working after the
resize; destroy_render_target(id) frees it. read_back(id) waits for the GPU and returns a core::image
(RGBA8); on the null device the image is zero-filled and the right size. It fails with NOT_FOUND for an unknown
target, rhi_error::DEVICE_LOST on a lost device and RESOURCE_CREATION_FAILED when the staging texture cannot be
created or mapped, never with a blank image. is_render_target_colour_format(format) tells you which
rhi::texture_formats a target accepts: RGBA8_UNORM, RGBA8_SRGB (the default), BGRA8_SRGB, RGBA16_FLOAT and
R11G11B10_FLOAT.
Warning
An RGBA8_UNORM target holds display values (see Display encoding). read_back and ImGui
show it right, but a sprite, or anything else that samples it as colour, takes those values as linear and the
picture comes out washed out. For a target you draw as a sprite, use RGBA8_SRGB or a float format.
Sprites and debug drawing¶
A sprite has a texture id, a worldFromLocal matrix (pixel space, y down, for SCREEN sprites), a UV
rectangle, a colour, a size (world units or pixels), a sprite_space and a layer / order pair; the renderer
sorts world-space sprites with the 3D scene and screen-space ones on top.
sprite_batcher is the CPU batching the renderer uses, exposed for tools that want the vertex runs. Past
MAX_SPRITES_PER_FRAME, screen-space sprites (the HUD) keep their place: the world-space sprites last in sort
order, the front-most ones, are dropped first. dropped_count() says how many the last build dropped (the
renderer reports its own batcher's count as render_stats::spritesDropped). The WARN naming the count per space
is logged by the build in which the overflow starts and not again until a build has dropped nothing; clear()
resets the count but does not arm the WARN.
debug_draw_buffer collects lines (line, box, sphere, frustum, axes, grid); each shape takes a
debug_depth after its colour (after length for axes; sphere takes its segment count after it):
debug_depth::TESTED (the default, hidden behind geometry) or debug_depth::OVERLAY (drawn on top).
render_scene::debugDraw is one. debug_draw keeps shapes alive for a duration: line(...,
durationSeconds, depth), tick(deltaSeconds) and append_to(buffer) each frame. debug_depth is a typed
argument, so it can never be passed where the facade expects the duration. Vertices dropped at the
MAX_DEBUG_VERTICES cap are counted by dropped_count() and carried along by append and append_to.
scene.debugDraw.box(bounds, math::vec4(1.0f, 0.0f, 0.0f, 1.0f), renderer::debug_depth::OVERLAY);
debugDraw.line(from, to, math::vec4(0.0f, 1.0f, 0.0f, 1.0f), 2.0f); // depth-tested, kept for two seconds
World-space sprites and debug lines draw into the HDR target before exposure, bloom and the tonemapper, so they are post-processed like the 3D scene: a debug colour scales with the exposure, and a bright sprite can bloom. Screen-space sprites draw after the tonemapper and keep their authored colours.
Tip
A 2D game whose world sprites should keep their authored colours sets camera_component::postProcess to
false (a hand-built view sets view_flags::NO_POST_PROCESS). The view then skips exposure and bloom and
tonemaps with NONE.
The null device and statistics¶
render_stats is filled on every device: viewsRendered, passesExecuted and passNames (in order),
drawCalls, instancesDrawn, instancesCulled, trianglesDrawn, lightsRendered, shadowCascadesRendered,
shadowTilesAllocated, spritesDrawn, uploadsCompleted, fallbacksUsed, transientTexturesLive,
backBufferCleared, msaaSampleCount and more.
What a frame clamped is counted every frame, whether or not a WARN was logged for it: viewsSkipped,
lightsDropped (summed over the views drawn), spritesDropped (once per frame, both sprite spaces) and
shadowTilesDropped. A frame whose back buffer could not be acquired reports only viewsSkipped.
render_stats also answers which passes ran:
executed("tonemap") and count(name) query the pass list, which holds every executed pass of the largest frame
(MAX_VIEWS views of MAX_PASSES_PER_VIEW passes each). On the null device the rhi::device::null_stats()
counters say what was recorded (draws, dispatches, buffers and textures created, command lists submitted), which
is how every renderer test asserts without a GPU.
Note
render() fails only with rhi_error::DEVICE_LOST; after on_device_lost() every later frame fails the same
way and the engine quits. Everything else about a bad scene is clamped and logged.
Components¶
components.h declares the reflected structs the engine registers as ECS components and fills the scene from:
mesh_renderer_component {asset_ref<mesh_asset> mesh; asset_ref<material_asset> materials[MAX_MATERIAL_SLOTS];
layerMask; castsShadows; receivesShadows}, sprite_component, camera_component {camera cameraData; layerMask;
priority; isMain; postProcess}, light_component {light lightData} and environment_component.
register_components(core::reflect::type_registry &) registers their descriptions.
The engine copies mesh_renderer_component::layerMask into each mesh_instance and camera_component::layerMask
into each view, so those two masks alone decide which camera draws which mesh. The scene's layer component is a
grouping label for find_by_layer, scripts and the editor and plays no part (its 32 layers use the same bit
numbering, so a game can keep them in step). Sprites carry no mask: every view draws every sprite, and
sprite_component::layer is a sort key, not a visibility layer.
ImGui (editor builds)¶
imgui_renderer draws ImDrawData into a framebuffer: the engine's imgui_layer owns the ImGui context and
hands the draw data to renderer::set_imgui_draw_data(drawData), which draws it after the views of the next
frame into the swapchain. renderer::imgui() returns the backend (null in Distribution, without a swapchain or
when disabled); register_texture(gpuTextureId) returns the ImTextureID to show an engine texture in a panel,
and target_format() names the format the backend draws into (the swapchain's).
The backend declares itself in the ImGui context (io.BackendRendererName and
ImGuiBackendFlags_RendererHasVtxOffset) with attach_to_current_context(). The renderer starts before any layer
attaches, so imgui_layer calls it as soon as it has created its context; create() does it for a context that is
current at the time, and a frame drawn into a context without a renderer backend does it first. Calling it again is
harmless, and without a current context it does nothing.
On an RGBA8_UNORM swapchain (the editor's), ImGui's vertex colours are written as authored. A draw that samples a
texture holding linear values has the shader encode the texel to sRGB first: an *_SRGB texture, such as the
picture of a render target, which the sampler decodes, or a float texture (an RGBA16_FLOAT or R11G11B10_FLOAT
target, an HDR texture). The font atlas and RGBA8_UNORM textures, an RGBA8_UNORM render target included,
already hold display values and pass through. imgui_render_stats::srgbEncodedDraws counts the encoded draws. On
an RGBA8_SRGB swapchain nothing is converted, because the hardware encodes everything on write.
Functions¶
| Signature (short) | Purpose |
|---|---|
static result<unique_ptr<renderer>> renderer::create(const renderer_desc &) |
construction |
gpu_mesh_id upload_mesh(const asset_id &, const mesh_asset &) (and texture, material, environment) |
GPU mirrors; any thread |
void release_mesh(gpu_mesh_id) (and texture, material, environment) |
drop a mirror; any thread |
gpu_mesh_id find_mesh(const asset_id &) const (and texture, material, environment) |
id lookup |
result<render_target_id> create_render_target(const render_target_desc &), result<void> resize_render_target(id, uvec2), void destroy_render_target(id), render_target *get_render_target(id) |
targets |
render_scene &begin_extract(), void end_extract(), result<void> render_frame() |
the engine's frame |
void submit_view(const render_view &), u32 submitted_view_count() const |
queue a view no scene camera stands for: the next end_extract() appends it to the extracted scene, for one frame per call; it renders after the scene's own views and before the ImGui pass, so a panel can show its target in the same frame |
result<void> render(const render_scene &) |
render one scene now |
void set_anti_aliasing(const anti_aliasing_settings &), void clear_anti_aliasing_override(), const anti_aliasing_settings &anti_aliasing() const, u32 supported_msaa_sample_counts() const |
the run-time override of every view's anti-aliasing, and the value in effect; render thread |
string_view sanitise(anti_aliasing_settings &), u32 effective_msaa_sample_count(u32 requested, u32 supportedMask) |
the value the renderer uses, and the sample count a device gives for a request |
result<void> resize_swapchain(math::uvec2 size) |
resize the swapchain the renderer presents to: it drops its framebuffers over the back buffers first, which swapchain::resize alone cannot do |
void on_device_lost(), bool is_lost() const |
device events |
void set_imgui_draw_data(ImDrawData *), imgui_renderer *imgui() |
editor UI |
void set_back_buffer_clear(std::optional<math::vec4>), std::optional<math::vec4> back_buffer_clear() const |
clear the back buffer every frame to a display-referred colour, before every view and the ImGui pass; std::nullopt (the default) clears nothing |
void imgui_renderer::attach_to_current_context(), rhi::texture_format imgui_renderer::target_format() const |
declare the ImGui backend in the current context; the format it draws into |
result<core::image> read_back(render_target_id) |
pixels of a target |
const render_stats &stats() const, u64 frame_count() const, u32 pending_upload_count() const |
statistics |
static result<void> register_asset_types(asset_type_registry &, importer_registry &, job_system * = nullptr) |
the renderer's asset types (see Renderer assets) |
mat4 clip_from_view(const camera &, f32 aspectRatio), frustum frustum_from_clip(const mat4 &), ray ray_from_viewport(...) |
camera.h |
u16 clamp_shadow_resolution(u16) |
light.h |
result<void> register_components(core::reflect::type_registry &) |
components.h |
render_view make_camera_view(const camera_component &, const mat4 &worldFromCamera, render_target_id = {}) |
components.h: the view a camera component at a world matrix renders (rigid inverse of the matrix, the camera's data, layer mask and NO_POST_PROCESS unless postProcess); what the engine's extraction and the editor's screenshots both use |
See also:
- 📘 API: Renderer assets, Devices and swapchains, Shaders
- 🛠 Handbook: Renderer module