jubilant-funicular
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
nta::SpriteBatch Class Reference

#include <SpriteBatch.h>

Collaboration diagram for nta::SpriteBatch:
Collaboration graph
[legend]

Public Member Functions

 SpriteBatch ()
 constructor and destructor
 
void init ()
 initializes the batch
 
void begin ()
 begins collection of glyphs for the batch
 
void end ()
 ends collection of glyphs and prepares to render
 
void addGlyph (crvec4 posRect, GLuint texture=0, crvec4 uvRect=glm::vec4(0, 0, 1, 1), crvec4 color=glm::vec4(1), float depth=0.5)
 
void addGlyph (crvec4 posRect, crvec4 uvRect, GLuint texture, float depth=0.5, crvec4 color=glm::vec4(1))
 
void addGlyph (crvec2 corner1, crvec2 corner2, crvec4 uvRect, GLuint texture, float depth=0.5, crvec4 color=glm::vec4(1))
 
void addGlyph (crvec4 posRect, crvec4 uvRect, GLuint texture, crvec4 color, float angle=0.0f, float depth=0.5)
 
void addGlyph (crvec2 corner1, crvec2 corner2, crvec4 uvRect, GLuint texture, crvec4 color, float angle=0.0f, float depth=0.5)
 
void render () const
 renders the batch
 

Private Member Functions

void createVertexArrayObject ()
 creates the vertex array object
 
void createRenderBatches ()
 creates the render batches
 
void sortGlyphs ()
 sorts the glyphs
 

Static Private Member Functions

static bool compareTexture (Glyph *lhs, Glyph *rhs)
 comparers used to sort
 
static bool compareDepth (Glyph *lhs, Glyph *rhs)
 

Private Attributes

std::vector< Glyph * > m_glyphPointers
 pointers to the glyphs to be rendered (used for sorting)
 
std::vector< Glyphm_glyphs
 the glyphs to be rendered (used for fast vector operations)
 
std::vector< RenderBatchm_renderBatches
 the render batches used for rendering the glyphs
 
GLuint m_vao = 0
 ids of the vertex buffer object and vertex array object used to render the glyphs
 
GLuint m_vbo = 0
 

Detailed Description

represents a collection of sprites to be drawn

If you want to draw a shape other than a square, use PrimitiveBatch instead

Todo:

Allow for custom vertex types (Important)

Rewrite to use glDrawElements instead of glDrawArrays

Definition at line 87 of file SpriteBatch.h.

Member Function Documentation

◆ addGlyph()

void nta::SpriteBatch::addGlyph ( crvec4  posRect,
GLuint  texture = 0,
crvec4  uvRect = glm::vec4(0,0,1,1),
crvec4  color = glm::vec4(1),
float  depth = 0.5 
)

adds a glyph to the batch

Todo:
Give some of these different names?

Definition at line 100 of file SpriteBatch.cpp.

Referenced by nta::ParticleBatch2D::draw(), nta::SpriteFont::drawText(), and nta::SpriteFont::drawTexture().


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