diff options
Diffstat (limited to 'yage/core/spritebatch.cpp')
-rw-r--r-- | yage/core/spritebatch.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/yage/core/spritebatch.cpp b/yage/core/spritebatch.cpp index 00673c08..98213467 100644 --- a/yage/core/spritebatch.cpp +++ b/yage/core/spritebatch.cpp @@ -30,7 +30,10 @@ RenderBatch::RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture) { } -SpriteBatch::SpriteBatch() = default; +SpriteBatch::SpriteBatch() +{ + createVertexArray(); +} SpriteBatch::~SpriteBatch() { @@ -43,11 +46,6 @@ SpriteBatch::~SpriteBatch() } } -void SpriteBatch::init() -{ - createVertexArray(); -} - void SpriteBatch::begin() { glyphs_.clear(); @@ -94,12 +92,21 @@ void SpriteBatch::draw(const yage::Vector4f &destination_rect, void SpriteBatch::render() { + // sort and create render batches + sortGlyphs(); + createRenderBatches(); + glBindVertexArray(vao_); for (auto &&batch : render_batches_) { glBindTexture(GL_TEXTURE_2D, batch.texture()); glDrawArrays(GL_TRIANGLES, batch.offset(), batch.num_vertices()); } glBindVertexArray(0); + + // clear and reset the vectors + glyphs_.clear(); + glyph_ptrs_.clear(); + render_batches_.clear(); } void SpriteBatch::createVertexArray() |