aboutsummaryrefslogtreecommitdiffstats
path: root/yage
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-12-08 01:23:27 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-12-08 01:23:27 +0000
commite6215e764bc149497ab5772d9ea136809d898993 (patch)
treebe10db001a2d4eedd611c7db2c5cf7907f55250c /yage
parent4738752fd7633f68911f97aeda9954ee87b5ce6e (diff)
downloadYAGE-e6215e764bc149497ab5772d9ea136809d898993.tar.gz
YAGE-e6215e764bc149497ab5772d9ea136809d898993.zip
Improving api
Diffstat (limited to 'yage')
-rw-r--r--yage/core/camera2d.cpp8
-rw-r--r--yage/core/spritebatch.cpp19
-rw-r--r--yage/core/spritebatch.h1
3 files changed, 13 insertions, 15 deletions
diff --git a/yage/core/camera2d.cpp b/yage/core/camera2d.cpp
index 52c5c50f..d5640c3f 100644
--- a/yage/core/camera2d.cpp
+++ b/yage/core/camera2d.cpp
@@ -6,14 +6,6 @@
* ----------------------------------------------------------------------------
*/
-/* ----------------------------------------------------------------------------
- * camera2d.cpp
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
#include "camera2d.h"
#include <glad/glad.h>
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()
diff --git a/yage/core/spritebatch.h b/yage/core/spritebatch.h
index 9ec7cffb..d90d6d05 100644
--- a/yage/core/spritebatch.h
+++ b/yage/core/spritebatch.h
@@ -89,7 +89,6 @@ public:
SpriteBatch &operator=(SpriteBatch &&) = delete;
// initialize vaos and vbos
- void init();
void begin();
void end();