Skip to content

RendererAPI

RendererAPI is the abstract backend interface. All rendering state and draw calls are issued through it. The concrete implementation is selected at construction time based on the RendererBackend enum.

Backend Selection

cpp
enum class RendererBackend { None = 0, OpenGL = 1 };

Create a backend-specific RendererAPI:

cpp
auto api = RendererAPI::create(RendererBackend::OpenGL);

Helper templates are provided for creating backend-specific objects:

cpp
// Shared ownership
Ref<T> obj = create_renderer_component_ref<T, OpenGLImpl>(backend, args...);

// Unique ownership
Scope<T> obj = create_renderer_component_scope<T, OpenGLImpl>(backend, args...);

Enumerations

DrawPrimitive

ValueMeaning
POINTSGL_POINTS
LINESGL_LINES
TRIANGLESGL_TRIANGLES

CullFaceMode

ValueMeaning
FrontCull front faces
LeftCull left
RightCull right
BackCull back faces

DepthMode

ValueMeaning
EqualGL_EQUAL
LessGL_LESS
LessEqualGL_LEQUAL

Interface

cpp
class RendererAPI {
public:
    virtual void init() = 0;

    virtual void set_viewport(uint32_t x, uint32_t y,
                              uint32_t width, uint32_t height) = 0;

    virtual void clear_color() = 0;
    virtual void clear_buffers() = 0;

    virtual void disable_buffer_testing() = 0;
    virtual void enable_buffer_testing() = 0;

    virtual void cull_face(CullFaceMode mode) = 0;
    virtual void depth(DepthMode mode) = 0;

    virtual void draw_indexed(const Ref<VertexArray>& vertex_array,
                              DrawPrimitive primitive = TRIANGLES,
                              uint32_t index_count = -1) = 0;

    virtual void draw_instanced_indexed(DrawPrimitive primitive,
                                        uint32_t index_count,
                                        uint32_t instance_count) = 0;

    virtual void draw_lines(const Ref<VertexArray>& vertex_array,
                            uint32_t vertex_count) = 0;

    void set_clear_color(const glm::vec4& color);
    RendererBackend get_backend();
};

RenderTarget

RenderTarget bundles a RendererAPI instance with a Framebuffer and MSAA config. It is the primary handle passed to passes and components.

cpp
struct MSAA { int samples; bool is_enabled; };

// Factory
Ref<RenderTarget> target = RenderTarget::create(
    RendererBackend::OpenGL,
    MSAA{ .samples = 4, .is_enabled = true },
    window_id
);

// Access
target->renderer_api();     // RendererAPI*
target->framebuffer();      // Ref<Framebuffer>
target->msaa();             // MSAA
target->window_id();        // WindowID
target->has_msaa_enabled(); // bool

Framebuffer

Framebuffer is the abstract render target. It supports multiple color attachments and a depth/stencil attachment.

Texture Formats

FormatDescription
RGBA88-bit unsigned per channel
RGBA16F16-bit float per channel (HDR)
RGBA32F32-bit float per channel
DEPTH_ONLYDepth-only (shadow maps)
RED_INTEGERSingle integer channel (picking)
DEPTH24STENCIL8Combined depth/stencil

Interface

cpp
class Framebuffer {
public:
    virtual void bind(FramebufferBindType = Default, uint32_t id = -1) = 0;
    virtual void unbind() = 0;
    virtual void resize(uint32_t width, uint32_t height) = 0;
    virtual int  read_pixel(uint32_t attachment, int x, int y) = 0;
    virtual void clear_attachment(uint32_t attachment, int value) = 0;
    virtual uint32_t get_color_attachment_id(uint32_t index = 0) const = 0;
    virtual void blit(uint32_t width, uint32_t height) = 0;
    virtual const FramebufferSpecification& get_specification() const = 0;

    static Ref<Framebuffer> create(RendererBackend backend,
                                   const FramebufferSpecification& spec);
};

GPU Buffers

VertexBuffer / IndexBuffer / VertexArray

Standard geometry buffer hierarchy. VertexArray binds one or more VertexBuffers and an optional IndexBuffer.

StorageBuffer

A shader storage buffer object (SSBO) for compute or data sharing between passes.