diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-04 21:47:16 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-04 21:47:16 +0100 |
commit | 905f72775fa91b0a467f3c0847c60cf0f85a6d80 (patch) | |
tree | 5aa86baf8ed06fd4af036d0bb6c0dbefb5498f9f /include/YAGE/spritebatch.hpp | |
parent | 55a1e0ad7c9d2661c266b2e767bfcb2f944e859f (diff) | |
download | YAGE-905f72775fa91b0a467f3c0847c60cf0f85a6d80.tar.gz YAGE-905f72775fa91b0a467f3c0847c60cf0f85a6d80.zip |
Sprite batching workin
Diffstat (limited to 'include/YAGE/spritebatch.hpp')
-rw-r--r-- | include/YAGE/spritebatch.hpp | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/include/YAGE/spritebatch.hpp b/include/YAGE/spritebatch.hpp index fcc6faec..3f40a009 100644 --- a/include/YAGE/spritebatch.hpp +++ b/include/YAGE/spritebatch.hpp @@ -11,39 +11,76 @@ namespace yage { -struct Glyph +class Glyph { - GLuint texture; - float depth; - - Vertex top_left; - Vertex top_right; - Vertex bottom_right; - Vertex bottom_left; + // member variables +private: + GLuint texture_; + float depth_; + Vertex top_left_; + Vertex top_right_; + Vertex bottom_right_; + Vertex bottom_left_; + + // member functions +public: + Glyph(GLuint texture, float depth, const Vertex &top_left, const Vertex &top_right, const Vertex &bottom_right, const Vertex &bottom_left); + + inline GLuint texture() const { return texture_; } + inline float depth() const { return depth_; } + inline Vertex top_left() const { return top_left_; } + inline Vertex top_right() const { return top_right_; } + inline Vertex bottom_right() const { return bottom_right_; } + inline Vertex bottom_left() const { return bottom_left_; } +}; + +class RenderBatch +{ + // member variables +public: + GLint offset_; +private: + GLsizei num_vertices_; + GLuint texture_; + + // member functions +public: + RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture); + + // getters + inline GLint offset() const { return offset_; } + inline GLsizei num_vertices() const { return num_vertices_; } + inline GLuint texture() const { return texture_; } }; class SpriteBatch { -public: // member variables + // member variables +public: + static const int NUM_VERTICES=6; private: GLuint vbo_=0; GLuint vao_=0; - std::vector<Glyph> glyphs_; std::vector<Glyph *> glyph_ptrs_; - -public: // member functions + std::vector<RenderBatch> render_batches_; + + // member functions +public: SpriteBatch(); ~SpriteBatch(); + // initialize vaos and vbos + void init(); void begin(); void end(); - + // adds a sprite to the sprite batch to be rendered later void draw(const glm::vec4 &destination_rect, const glm::vec4 &uv_rect, GLuint texture, const Color &color, float depth); - - void renderBatch(); + // render the batch + void render(); private: void createVertexArray(); + void createRenderBatches(); void sortGlyphs(); }; |