Skip to main content

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

MemberReturnsDescription
prepareWindowAttributes()voidSet SDL attributes before the window is created
getWindowFlags()uint64_tSDL Uint64 window flags required by this renderer (e.g. SDL_WINDOW_VULKAN)
initializeContext(window)voidCreate the GPU context bound to the given SDL window
destroyContext(window)voidDestroy the GPU context for a window
makeCurrent(window)voidMake the context current on the calling thread
swapBuffers(window)voidPresent the back buffer

Rendering

MemberReturnsDescription
clear()voidClear colour and depth buffers
setViewPort(w, h)voidSet the render viewport dimensions
draw(sceneObject)voidSubmit draw calls produced by a single scene object
drawScene(graph, shaders, aspectRatio)voidRender the full scene graph, injecting camera and model uniforms from shader binding metadata

Lifecycle

MemberReturnsDescription
configure(config)voidApply engine configuration (shadow flags, SSAO, etc.). Called before initializeContext.
preBake(shaders)voidPre-compute IBL data (irradiance, specular, BRDF LUT) before the first frame. Vulkan uses this for compute pipelines; other renderers are no-ops.
waitForIdle()voidBlock until all in-flight GPU work completes and release scene-local GPU resources. Call before clearing the scene graph.

Resources & environment

MemberReturnsDescription
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)voidForward an SDL event to the renderer (e.g. for ImGui input). Called once per event before game dispatch.
setSceneFileHash(hash)voidAssociate a 16-char hex content hash with the current scene, used as a probe disk-cache key
loadEnvironment(envUri, res)voidLoad 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)voidSet skydome blur (0 = sharp, 1 = fully blurred). Sourced from "properties": { "blur": … } in the scene's environment node.
setImGuiCallback(fn)voidRegister a callback invoked each frame inside the active ImGui frame (after the built-in debug panel). No-op on renderers without ImGui.

Queries

MemberReturnsDescription
getRenderName()std::stringHuman-readable renderer name (e.g. "Vulkan")
getRendererVariant()RendererVariantEnum 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.

MemberReturnsDescription
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

src/render/shaderSystem.h
ShaderSystem(glitter::resources& res, RenderContext& ctx)

Methods

MemberReturnsDescription
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().

MemberReturnsDescription
beginOffscreen()voidBind the offscreen FBO and enable depth testing — call at the start of pre-render
draw(fxaa)voidUnbind FBO and blit the fullscreen quad with post-processing to the screen. Pass fxaa = true to enable FXAA.
resize(width, height)voidRecreate 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

FieldTypeDescription
sizeintVertex count
vbuffersizeintVertex buffer byte size
tbuffersizeintTexcoord buffer byte size
nbuffersizeintNormal 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

FunctionReturnsDescription
createSphere(radius, rings, sectors)GeometryUV sphere
createPlane(width, depth, subdivisions, uvScale)GeometryFlat quad plane
createCube(sx, sy, sz, uvScale)GeometryAxis-aligned box
createCylinder(radius, height, segments, uvScale)GeometryCapped cylinder
createCapsule(radius, height, segments, uvScale)GeometryCylinder with hemispherical caps
free(geometry)voidRelease geometry buffer memory
normalizeVertices(vbuffer, size)voidNormalise vertex positions in-place

uvScale controls tiling: world units per texture repeat (1.0 = one tile per unit).