cangine
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
cangine::QuadRenderer Class Reference

Batched renderer for textured quads (rectangles). More...

#include <quad_renderer.hpp>

Collaboration diagram for cangine::QuadRenderer:
Collaboration graph
[legend]

Public Member Functions

 QuadRenderer (Shader *shader)
 Constructs the renderer with a shader.
 
void beginFrame ()
 Resets the batch at the start of a frame.
 
void draw (const Transform &transform, const Rectangle &r, bool normalize=true)
 Adds a transformed rectangle to the current batch.
 
void draw (const Rectangle &r, bool normalize=true)
 Adds a rectangle to the current batch.
 
void flush ()
 Submits the accumulated batch to the GPU.
 
void setTexture (Texture *t, bool mono=false)
 Binds a texture for subsequent quads, flushing if it changes.
 
void setShader (Shader *shader)
 Replaces the shader used for drawing.
 

Private Attributes

bool currentMono = false
 Whether the bound texture is single-channel.
 
Texture * currentTexture = nullptr
 Currently bound texture, if any.
 
std::vector< Vertex > vertices
 Accumulated vertices for the current batch.
 
uint32_t quadCount = 0
 Number of quads in the current batch.
 
VAO vao
 Vertex array describing the layout.
 
VBO vbo
 Vertex buffer holding the batched data.
 
EBO ebo
 Index buffer for the quads.
 
Shader * shader
 Shader used to draw the quads.
 

Static Private Attributes

static QuadRenderer * instance = nullptr
 Singleton instance.
 
static constexpr uint32_t MAX_QUADS = 10000
 Maximum quads per batch.
 
static constexpr uint32_t MAX_VERTICES = MAX_QUADS * 4
 Vertex capacity (4 per quad).
 
static constexpr uint32_t MAX_INDICES = MAX_QUADS * 6
 Index capacity (6 per quad).
 

Detailed Description

Batched renderer for textured quads (rectangles).

Accumulates up to MAX_QUADS quads per batch and renders them with a single draw call. Supports an optional bound texture and a monochrome mode used for glyph rendering.

Constructor & Destructor Documentation

◆ QuadRenderer()

cangine::QuadRenderer::QuadRenderer ( Shader *  shader)

Constructs the renderer with a shader.

Parameters
shaderShader used for drawing quads.

Member Function Documentation

◆ beginFrame()

void cangine::QuadRenderer::beginFrame ( )

Resets the batch at the start of a frame.

◆ draw() [1/2]

void cangine::QuadRenderer::draw ( const Rectangle &  r,
bool  normalize = true 
)

Adds a rectangle to the current batch.

Parameters
rRectangle geometry to draw.
normalizeIf true, positions are normalized to clip space.

◆ draw() [2/2]

void cangine::QuadRenderer::draw ( const Transform &  transform,
const Rectangle &  r,
bool  normalize = true 
)

Adds a transformed rectangle to the current batch.

Parameters
transformTransform applied to the rectangle.
rRectangle geometry to draw.
normalizeIf true, positions are normalized to clip space.

◆ flush()

void cangine::QuadRenderer::flush ( )

Submits the accumulated batch to the GPU.

◆ setShader()

void cangine::QuadRenderer::setShader ( Shader *  shader)

Replaces the shader used for drawing.

Parameters
shaderNew shader to use.

◆ setTexture()

void cangine::QuadRenderer::setTexture ( Texture *  t,
bool  mono = false 
)

Binds a texture for subsequent quads, flushing if it changes.

Parameters
tTexture to bind.
monoIf true, treat the texture as single-channel.

Member Data Documentation

◆ currentMono

bool cangine::QuadRenderer::currentMono = false
private

Whether the bound texture is single-channel.

◆ currentTexture

Texture* cangine::QuadRenderer::currentTexture = nullptr
private

Currently bound texture, if any.

◆ ebo

EBO cangine::QuadRenderer::ebo
private

Index buffer for the quads.

◆ instance

QuadRenderer * cangine::QuadRenderer::instance = nullptr
staticprivate

Singleton instance.

◆ MAX_INDICES

constexpr uint32_t cangine::QuadRenderer::MAX_INDICES = MAX_QUADS * 6
staticconstexprprivate

Index capacity (6 per quad).

◆ MAX_QUADS

constexpr uint32_t cangine::QuadRenderer::MAX_QUADS = 10000
staticconstexprprivate

Maximum quads per batch.

◆ MAX_VERTICES

constexpr uint32_t cangine::QuadRenderer::MAX_VERTICES = MAX_QUADS * 4
staticconstexprprivate

Vertex capacity (4 per quad).

◆ quadCount

uint32_t cangine::QuadRenderer::quadCount = 0
private

Number of quads in the current batch.

◆ shader

Shader* cangine::QuadRenderer::shader
private

Shader used to draw the quads.

◆ vao

VAO cangine::QuadRenderer::vao
private

Vertex array describing the layout.

◆ vbo

VBO cangine::QuadRenderer::vbo
private

Vertex buffer holding the batched data.

◆ vertices

std::vector<Vertex> cangine::QuadRenderer::vertices
private

Accumulated vertices for the current batch.


The documentation for this class was generated from the following files: