diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-12-08 01:23:27 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-12-08 01:23:27 +0000 |
commit | e6215e764bc149497ab5772d9ea136809d898993 (patch) | |
tree | be10db001a2d4eedd611c7db2c5cf7907f55250c /yage/core/spritebatch.cpp | |
parent | 4738752fd7633f68911f97aeda9954ee87b5ce6e (diff) | |
download | YAGE-e6215e764bc149497ab5772d9ea136809d898993.tar.gz YAGE-e6215e764bc149497ab5772d9ea136809d898993.zip |
Improving api
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() |