From e6215e764bc149497ab5772d9ea136809d898993 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Fri, 8 Dec 2017 01:23:27 +0000 Subject: Improving api --- yage/core/spritebatch.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'yage/core/spritebatch.cpp') 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() -- cgit