Renderer

High-level rendering utilities.

Overview

Typical use cases:

  • Managing rendering backends and pipelines

  • Handling frame rendering and window management

Header

<RaeptorCogs/Renderer.hpp>

Metadata

Author

Estorc

Version

v1.0

Copyright

Copyright (c) 2025 Estorc MIT License.

Classes

Classes

Class

Description

RaeptorCogs::Singletons::Renderer

Renderer singleton class.

class Renderer

Renderer singleton class.

Manages the rendering backend and provides high-level rendering functionalities.

RaeptorCogs::Renderer().initialize(RaeptorCogs::GraphicsBackend::GL); // Initialize OpenGL backend
RaeptorCogs::Window* window = RaeptorCogs::Renderer().createWindow(800, 600, "My Window"); // Create a window
RaeptorCogs::StartLoop([&]() {
     // Update logic here ...
     RaeptorCogs::Renderer().render(window); // Render to a window
}); // Start the main loop
RaeptorCogs::Renderer().destroyWindow(window); // Destroy the window
RaeptorCogs::Destroy(); // Cleanup RaeptorCogs and the renderer

Public Functions

void initialize(GraphicsBackend backend = GraphicsBackend::GL)

Initialize the renderer with the specified graphics backend.

RaeptorCogs::Renderer().initialize(RaeptorCogs::GraphicsBackend::GL); // Initialize OpenGL backend

See also

GraphicsBackend

Note

This method must be called before any rendering operations.

Parameters:

backend – The graphics backend to use. Defaults to OpenGL (GL).

bool isInitialized() const

Check if the renderer backend is initialized.

if (RaeptorCogs::Renderer().isInitialized()) {
   // Renderer is ready for use
}

Note

Useful for lazy initialization checks.

Returns:

true if the renderer backend is initialized, false otherwise.

void setRenderListID(int index)

Set the current render list ID.

RaeptorCogs::Renderer().setRenderListID(1); // Set render list ID to 1
// Now graphics added will go to render list 1 and be rendered accordingly

Note

A render list is a collection of graphics to be rendered together.

Parameters:

index – The index of the render list to set as current.

void add(Graphic2D&)

Add a graphic to the renderer.

Parameters:

graphic – Pointer to the graphic to be added.

void remove(Graphic2D&)

Remove a graphic from the renderer.

Parameters:

graphic – Pointer to the graphic to be removed.

void add(Component&)

Add a component to the renderer.

Parameters:

component – Pointer to the component to be added.

void remove(Component&)

Remove a component from the renderer.

Parameters:

component – Pointer to the component to be removed.

virtual void render(Window &window, int width = 0, int height = 0)

Render the scene to the specified target.

RaeptorCogs::Window* window = RaeptorCogs::Renderer().createWindow(800, 600, "My Window");
RaeptorCogs::Renderer().render(*window); // Render to the window

Note

If a window is provided, renders to that window; otherwise, renders to the default framebuffer.

Parameters:
  • window – Reference to the target window.

  • width – Width of the rendering area. If 0, uses the window’s width.

  • height – Height of the rendering area. If 0, uses the window’s height.

virtual void render(Texture &texture, int width = 0, int height = 0)

Render the scene to the specified texture.

RaeptorCogs::Window* window = RaeptorCogs::Renderer().createWindow(800, 600, "My Window");
RaeptorCogs::Renderer().render(window); // Render to the window

Note

Renders the scene directly into the provided texture.

Parameters:
  • texture – Reference to the target texture.

  • width – Width of the rendering area. If 0, uses the texture’s width.

  • height – Height of the rendering area. If 0, uses the texture’s height.

GAPI::Common::RendererBackend &getBackend()

Get the active renderer backend.

Returns:

Reference to the active renderer backend.

void CreateImGuiFrame()

Create a new ImGui frame.

Note

Must be called at the beginning of each frame before any ImGui rendering.

Private Functions

Renderer() = default

Private constructor for the Renderer singleton.

Ensures that the Renderer can only be instantiated through the SingletonAccessor.

~Renderer()

Destructor for the Renderer singleton.

Cleans up the active rendering backend.

void setBackend(GraphicsBackend backend)

Set the rendering backend.

Note

Called during initialization.

Parameters:

backend – The graphics backend to use.

Private Members

GAPI::Common::RendererBackend *activeBackend = nullptr

Pointer to the active rendering backend.

Manages the rendering operations and backend-specific implementations.

See also

GraphicsBackend

Note

Initialized during renderer setup.

friend SingletonAccessor< Renderer >