Renderer
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.
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()
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::Parameters struct
Functions
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);| Parameter | Description |
|---|---|
| scene | Pointer to the scene to render. |
| camera | Pointer to the active camera. |
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. |
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. |