Renderer API
Headers: src/render/renderer.h, src/render/shaderSystem.h, src/render/geometry.h, src/render/api/postProcess.h
Namespace: glitter::render
glitter::render::Renderer
Abstract base class for all render backends. The concrete Vulkan implementation is chosen at startup from engine_configuration::renderer_config::use and instantiated via RendererRegistry. Retrieve via engine::renderer().
Window & context
| Member | Returns | Description |
|---|---|---|
prepareWindowAttributes() | void | Set SDL attributes before the window is created |
getWindowFlags() | uint64_t | SDL Uint64 window flags required by this renderer (e.g. SDL_WINDOW_VULKAN) |
initializeContext(window) | void | Create the GPU context bound to the given SDL window |
destroyContext(window) | void | Destroy the GPU context for a window |
makeCurrent(window) | void | Make the context current on the calling thread |
swapBuffers(window) | void | Present the back buffer |
Rendering
| Member | Returns | Description |
|---|---|---|
clear() | void | Clear colour and depth buffers |
setViewPort(w, h) | void | Set the render viewport dimensions |
draw(sceneObject) | void | Submit draw calls produced by a single scene object |
drawScene(graph, shaders, aspectRatio) | void | Render the full scene graph, injecting camera and model uniforms from shader binding metadata |
Lifecycle
| Member | Returns | Description |
|---|---|---|
configure(config) | void | Apply engine configuration (shadow flags, SSAO, etc.). Called before initializeContext. |
preBake(shaders) | void | Pre-compute IBL data (irradiance, specular, BRDF LUT) before the first frame. Vulkan uses this for compute pipelines; other renderers are no-ops. |
waitForIdle() | void | Block until all in-flight GPU work completes and release scene-local GPU resources. Call before clearing the scene graph. |
Resources & environment
| Member | Returns | Description |
|---|---|---|
createRenderContext(params) | RenderContext* | Create a low-level GPU context (nullptr if not supported) |
createPostProcess(w, h, shader) | IPostProcess* | Create the post-process pipeline (nullptr if not supported) |
processEvent(sdlEvent) | void | Forward an SDL event to the renderer (e.g. for ImGui input). Called once per event before game dispatch. |
setSceneFileHash(hash) | void | Associate a 16-char hex content hash with the current scene, used as a probe disk-cache key |
loadEnvironment(envUri, res) | void | Load a pre-computed IBL environment from a descriptor URI (e.g. "environments://neutral.json"). Replaces runtime IBL baking for the scene's lifetime. |
setBackgroundBlur(amount) | void | Set skydome blur (0 = sharp, 1 = fully blurred). Sourced from "properties": { "blur": … } in the scene's environment node. |
setImGuiCallback(fn) | void | Register a callback invoked each frame inside the active ImGui frame (after the built-in debug panel). No-op on renderers without ImGui. |
Queries
| Member | Returns | Description |
|---|---|---|
getRenderName() | std::string | Human-readable renderer name (e.g. "Vulkan") |
getRendererVariant() | RendererVariant | Enum variant for compile-time renderer dispatch |
glitter::render::RendererRegistry
Static registry of renderer factories. Populated by assembly_registration() during engine init. Adding a new renderer requires only a register_renderer() call there — no changes to the engine core.
| Member | Returns | Description |
|---|---|---|
register_renderer(name, factory) | void (static) | Register a factory function under a name string |
create_renderer(name) | Renderer* (static) | Instantiate a renderer by name; falls back to the default if the name is unknown |
get_default_renderer() | std::string (static) | Name of the default renderer |
clear() | void (static) | Remove all registered factories (used in tests) |
glitter::render::ShaderSystem
Engine-level facade for shader loading. Knows the active renderer variant so callers only supply a filename or URI. Retrieve via engine::shaders().
Constructor
ShaderSystem(glitter::resources& res, RenderContext& ctx)
Methods
| Member | Returns | Description |
|---|---|---|
loadShader(filename) | expected<ShaderHandle, string> | Load and compile a single-pass shader by filename from the shaders:// scheme |
loadShader(uri<res::shader>) | expected<ShaderHandle, string> | Load and compile a shader from a typed shader URI |
loadShaderPass(filename, passName) | expected<ShaderHandle, string> | Load and compile a named pass from a family shader |
loadShaderPass(uri<res::shader>, passName) | expected<ShaderHandle, string> | Load a named pass from a typed shader URI |
bindings(handle) | const ShaderBindings* | Get the binding layout for a loaded shader; nullptr if not found or has no bindings |
resourceSystem() | glitter::resources& | Access the underlying resource system |
glitter::render::IPostProcess
Post-processing pipeline interface (tonemap + optional FXAA). Retrieve via engine::postProcess().
| Member | Returns | Description |
|---|---|---|
beginOffscreen() | void | Bind the offscreen FBO and enable depth testing — call at the start of pre-render |
draw(fxaa) | void | Unbind FBO and blit the fullscreen quad with post-processing to the screen. Pass fxaa = true to enable FXAA. |
resize(width, height) | void | Recreate FBO attachments after a window resize. Called automatically by the renderer — game code normally does not need to call this. |
glitter::render::Geometry
Plain-data struct plus factory functions for procedural mesh primitives. All primitives are centered at the origin with outward normals.
Struct fields
| Field | Type | Description |
|---|---|---|
size | int | Vertex count |
vbuffersize | int | Vertex buffer byte size |
tbuffersize | int | Texcoord buffer byte size |
nbuffersize | int | Normal buffer byte size |
vertices() | std::span<glm::vec3> | Vertex positions |
texcoords() | std::span<glm::vec2> | UV coordinates |
normals() | std::span<glm::vec3> | Vertex normals |
Factory functions
| Function | Returns | Description |
|---|---|---|
createSphere(radius, rings, sectors) | Geometry | UV sphere |
createPlane(width, depth, subdivisions, uvScale) | Geometry | Flat quad plane |
createCube(sx, sy, sz, uvScale) | Geometry | Axis-aligned box |
createCylinder(radius, height, segments, uvScale) | Geometry | Capped cylinder |
createCapsule(radius, height, segments, uvScale) | Geometry | Cylinder with hemispherical caps |
free(geometry) | void | Release geometry buffer memory |
normalizeVertices(vbuffer, size) | void | Normalise vertex positions in-place |
uvScale controls tiling: world units per texture repeat (1.0 = one tile per unit).