From 6d410918675effd76c5b30f6dbe5b6f4b9154708 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Fri, 7 Apr 2017 22:41:55 +0100 Subject: fixed spritebatch --- include/YAGE/spritebatch.hpp | 8 +++++--- src/spritebatch.cpp | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/YAGE/spritebatch.hpp b/include/YAGE/spritebatch.hpp index 3f40a009..c5a55b17 100644 --- a/include/YAGE/spritebatch.hpp +++ b/include/YAGE/spritebatch.hpp @@ -11,6 +11,8 @@ namespace yage { +class SpriteBatch; + class Glyph { // member variables @@ -36,11 +38,11 @@ public: class RenderBatch { + friend SpriteBatch; // member variables -public: - GLint offset_; private: - GLsizei num_vertices_; + GLsizei num_vertices_; + GLint offset_; GLuint texture_; // member functions diff --git a/src/spritebatch.cpp b/src/spritebatch.cpp index 8a08ea86..d09b663b 100644 --- a/src/spritebatch.cpp +++ b/src/spritebatch.cpp @@ -18,8 +18,8 @@ Glyph::Glyph(GLuint texture, float depth, const Vertex &top_left, const Vertex & {} RenderBatch::RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture) : - offset_(offset), num_vertices_(num_vertices), + offset_(offset), texture_(texture) {} @@ -129,7 +129,7 @@ void SpriteBatch::createRenderBatches() std::vector vertices; if(glyph_ptrs_.empty()) return; - + render_batches_.reserve(glyph_ptrs_.size()*NUM_VERTICES); for(int i=0; i<(int)glyph_ptrs_.size(); ++i) @@ -137,7 +137,7 @@ void SpriteBatch::createRenderBatches() if(i==0 || (i>0 && (glyph_ptrs_[i]->texture()!=glyph_ptrs_[i-1]->texture()))) render_batches_.emplace_back(i*NUM_VERTICES, NUM_VERTICES, glyph_ptrs_[i]->texture()); else - render_batches_.back().offset_+=NUM_VERTICES; + render_batches_.back().num_vertices_+=NUM_VERTICES; vertices.push_back(glyph_ptrs_[i]->bottom_left()); vertices.push_back(glyph_ptrs_[i]->top_left()); -- cgit