Skip to content

Renderer

Forward renderer for drawing a scene from a given camera.

The Renderer owns GPU state and draw logic for rendering a Scene with a specified Camera. It is typically constructed and driven by the Application runtime, but can also be used directly in manual setups.

Typical usage:

cpp
vglx::Renderer renderer({
  .framebuffer_width = window.FramebufferWidth(),
  .framebuffer_height = window.FramebufferHeight(),
  .clear_color = 0x444444
});

auto ok = renderer.Initialize();
if (!ok) {
  HandleError(ok.error());
}

// Per-frame:
renderer.Render(scene.get(), camera.get());

Construction

Constructors


Renderer()

cpp
vglx::Renderer::Renderer(const Renderer::Parameters &params)
ParameterDescription
paramsRenderer::Parameters

Constructs a renderer object with the given parameters. GPU resources are not created until Initialize is called.

Types

Renderer::Parameters struct

Construction parameters for Renderer.

NameTypeDescription
clear_colorColorClear color used at the start of a frame.
framebuffer_heightintCurrent framebuffer height in pixels.
framebuffer_widthintCurrent framebuffer width in pixels.

Functions

Initialize() std::expected< void, std::string >

cpp
std::expected< void, std::string > vglx::Renderer::Initialize()

Initializes GPU state and allocates required resources.

Render() void

cpp
void vglx::Renderer::Render(Scene *scene, Camera *camera)
ParameterDescription
scenePointer to the scene to render (must be non-null).
cameraPointer to the active camera (must be non-null).

Renders the given scene from the specified camera. The scene is expected to be in a consistent state for rendering. If you are using the runtime path, this is handled automatically. In direct initialization flows, call your per-frame update routine (e.g., Scene::Advance) prior to rendering.

RenderedObjectsPerFrame() size_t

cpp
size_t vglx::Renderer::RenderedObjectsPerFrame() const

Returns the number of renderable objects drawn in the last frame. Intended for statistics overlays and debugging.

SetClearColor() void

cpp
void vglx::Renderer::SetClearColor(const Color &color)
ParameterDescription
colorClear color in RGB format.

Sets the clear color for subsequent frames. The color is applied at the start of each frame when the framebuffer is cleared. Typically used to define the background color of the rendering surface.

SetViewport() void

cpp
void vglx::Renderer::SetViewport(int x, int y, int width, int height)
ParameterDescription
xLeft pixel of the viewport.
yBottom pixel of the viewport.
widthViewport width in pixels.
heightViewport height in pixels.

Sets the active viewport rectangle in pixels. Call this when the framebuffer size changes or when rendering to a sub-rectangle of the target.

Released under the MIT License.