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

Batches and draws untextured geometric primitives. More...

#include <primitive_renderer.hpp>

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

Public Member Functions

 PrimitiveRenderer (Shader *shader)
 Constructs the renderer with a shader.
 
void beginFrame ()
 Resets the batch at the start of a frame.
 
void endFrame ()
 Flushes the accumulated batch to the GPU.
 
void draw (const Triangle &t)
 Adds a triangle to the current batch.
 
void draw (const Rectangle &t)
 Adds a rectangle to the current batch.
 
void setShader (Shader *shader)
 Replaces the shader used for drawing.
 

Private Attributes

std::vector< Vertex > vertices
 Accumulated vertices for the current frame.
 
VAO vao
 Vertex array describing the layout.
 
VBO vbo
 Vertex buffer holding the batched data.
 
Shader * shader
 Shader used to draw the primitives.
 

Static Private Attributes

static PrimitiveRenderer * instance = nullptr
 Singleton instance.
 

Detailed Description

Batches and draws untextured geometric primitives.

Accumulates triangle/rectangle vertices over a frame and submits them to the GPU as a single batch, using a supplied Shader.

Constructor & Destructor Documentation

◆ PrimitiveRenderer()

cangine::PrimitiveRenderer::PrimitiveRenderer ( Shader *  shader)

Constructs the renderer with a shader.

Parameters
shaderShader used for drawing primitives.

Member Function Documentation

◆ beginFrame()

void cangine::PrimitiveRenderer::beginFrame ( )

Resets the batch at the start of a frame.

◆ draw() [1/2]

void cangine::PrimitiveRenderer::draw ( const Rectangle &  t)

Adds a rectangle to the current batch.

Parameters
tRectangle to draw.

◆ draw() [2/2]

void cangine::PrimitiveRenderer::draw ( const Triangle &  t)

Adds a triangle to the current batch.

Parameters
tTriangle to draw.

◆ endFrame()

void cangine::PrimitiveRenderer::endFrame ( )

Flushes the accumulated batch to the GPU.

◆ setShader()

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

Replaces the shader used for drawing.

Parameters
shaderNew shader to use.

Member Data Documentation

◆ instance

PrimitiveRenderer * cangine::PrimitiveRenderer::instance = nullptr
staticprivate

Singleton instance.

◆ shader

Shader* cangine::PrimitiveRenderer::shader
private

Shader used to draw the primitives.

◆ vao

VAO cangine::PrimitiveRenderer::vao
private

Vertex array describing the layout.

◆ vbo

VBO cangine::PrimitiveRenderer::vbo
private

Vertex buffer holding the batched data.

◆ vertices

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

Accumulated vertices for the current frame.


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