Renderer
The renderer owns GPU state and draw logic for rendering a Scene with a specified Camera. Construct one alongside your Window and call Render once per frame from your main loop.
This class defines the rendering interface only. The actual rendering implementation is provided by a backend, and multiple backends (for example, OpenGL or Vulkan) may exist behind this interface.
vglx::Renderer renderer({
.framebuffer_width = window.FramebufferWidth(),
.framebuffer_height = window.FramebufferHeight(),
.clear_color = 0x444444
});
auto ok = renderer.Initialize();
if (!ok) {
HandleError(ok.error());
}The renderer assumes a valid graphics context is current on the calling thread. When the window is resized, call SetViewport to adjust the render area (or recreate with new parameters if you manage your own framebuffers).
Construction
Constructors
Renderer()
Constructs a renderer.
GPU resources are not created until Initialize is called.
Renderer::Renderer(const Renderer::Parameters& params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the renderer. |
Types
Renderer::ToneMapping enum
Tone mapping operator applied to the final HDR frame before display.
| Value | Description |
|---|---|
| None | No tone mapping. HDR values are clamped to [0, 1]. |
| ACESFilmic | ACES filmic curve. Compresses highlights and preserves shadows. |
Renderer::DriverInfo struct
Driver and hardware identity strings reported by the rendering backend.
| Parameter | Description |
|---|---|
| vendor std::string | Driver vendor string. |
| renderer std::string | Hardware renderer string. |
| version std::string | Graphics API version string. |
| glsl_version std::string | Shading language version string. |
Renderer::Limits struct
Hardware limits reported by the rendering backend.
| Parameter | Description |
|---|---|
| max_anisotropy float | Max anisotropy for texture sampling. |
| max_samples int | Max MSAA sample count. |
| max_texture_units int | Max texture units per shader. |
| max_texture_size int | Max 2D texture dimension. |
| max_cube_map_size int | Max cube map face dimension. |
| max_renderbuffer_size int | Max renderbuffer dimension. |
Renderer::Parameters struct
Parameters for constructing a Renderer object.
| Parameter | Description |
|---|---|
| framebuffer_width int | Current framebuffer width in pixels. |
| framebuffer_height int | Current framebuffer height in pixels. |
| sample_count int | Antialiasing level (e.g., 4x MSAA). |
| clear_color Color | Clear color used at the start of a frame. |
| tone_mapping ToneMapping | Tone mapping operator applied to the final frame. |
| exposure float | Exposure scale applied to HDR values before tone mapping. |
Functions
Returns the color texture associated with an offscreen render target.
When rendering to a RenderTarget the renderer attaches a 2D texture that receives the color output of the frame. This method retrieves that texture so it can be bound in subsequent passes.
The returned pointer is shared with the render target and remains valid as long as both the renderer and the render target are alive. If target is null or does not have an associated color texture an empty pointer is returned.
std::shared_ptr<Texture2D> Renderer::CreateTextureFromRenderTarget(RenderTarget* target);| Parameter | Description |
|---|---|
| target | Render target whose color texture should be retrieved. |
GetDriverInfo() constDriverInfo&
Returns driver and hardware identity strings reported by the rendering backend.
Must be called after Initialize has succeeded.
const DriverInfo& Renderer::GetDriverInfo() const;Returns hardware limits reported by the rendering backend.
Must be called after Initialize has succeeded.
const Limits& Renderer::GetLimits() const;Initialize() std::expected<void, std::string>
Initializes GPU state and allocates required resources.
std::expected<void, std::string> Renderer::Initialize();Render() void
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 tye per-frame update routine Scene::Advance prior to rendering.
void Renderer::Render(Scene* scene, Camera* camera, RenderTarget* target=nullptr);| Parameter | Description |
|---|---|
| scene | Pointer to the scene to render. |
| camera | Pointer to the active camera. |
| target |
RenderedObjectsPerFrame() size_t
Returns the number of renderable objects drawn in the last frame.
Intended for statistics overlays and debugging.
size_t Renderer::RenderedObjectsPerFrame() const;SetClearColor() void
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.
void Renderer::SetClearColor(const Color& color);| Parameter | Description |
|---|---|
| color | Clear color in RGB format. |
SetExposure() void
Sets the exposure scale for subsequent frames.
Multiplies HDR color values before tone mapping is applied. Higher values brighten the image; lower values darken it.
void Renderer::SetExposure(float exposure);| Parameter | Description |
|---|---|
| exposure | Linear exposure multiplier. Defaults to 1.0. |
SetToneMapping() void
Sets the tone mapping operator for subsequent frames.
Changes how HDR color values are mapped to the display range. Takes effect immediately on the next call to Render.
void Renderer::SetToneMapping(ToneMapping tone_mapping);| Parameter | Description |
|---|---|
| tone_mapping | Tone mapping operator to apply. |
SetViewport() void
Sets the active viewport rectangle in pixels.
Adjusts the area of the framebuffer that subsequent draw calls will target. This should be called whenever the window or framebuffer size changes, or when rendering to a specific sub-region of the target surface.
When using the runtime-managed rendering path, the viewport is updated automatically. In manual initialization flows, you are responsible for calling this method whenever the framebuffer dimensions change.
void Renderer::SetViewport(int x, int y, int width, int height);| Parameter | Description |
|---|---|
| x | Left pixel of the viewport. |
| y | Bottom pixel of the viewport. |
| width | Viewport width in pixels. |
| height | Viewport height in pixels. |