From e8b49088a03f58ebfd47a3c564e8cb81c6839f7c Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 13 Aug 2017 17:40:57 +0100 Subject: Updating docs --- spritebatch_8hpp_source.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spritebatch_8hpp_source.html') diff --git a/spritebatch_8hpp_source.html b/spritebatch_8hpp_source.html index 6a16a174..91b39ed0 100644 --- a/spritebatch_8hpp_source.html +++ b/spritebatch_8hpp_source.html @@ -68,12 +68,12 @@ $(function() {
spritebatch.hpp
-
1 /* ----------------------------------------------------------------------------
2  * spritebatch.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_SPRITE_BATCH_HPP
10 #define YAGE_SPRITE_BATCH_HPP
11 
12 #include "vertex.hpp"
13 
14 #include <GL/glew.h>
15 #include <glm/glm.hpp>
16 
17 #include <vector>
18 
19 namespace yage {
20 
21 class SpriteBatch;
22 
25 class Glyph {
26  // member variables
27 private:
28  GLuint texture_;
29  float depth_;
30  Vertex top_left_;
31  Vertex top_right_;
32  Vertex bottom_right_;
33  Vertex bottom_left_;
34 
35  // member functions
36 public:
37  Glyph(GLuint texture, float depth, const Vertex& top_left,
38  const Vertex& top_right, const Vertex& bottom_right,
39  const Vertex& bottom_left);
40 
41  GLuint texture() const { return texture_; }
42  float depth() const { return depth_; }
43  Vertex top_left() const { return top_left_; }
44  Vertex top_right() const { return top_right_; }
45  Vertex bottom_right() const { return bottom_right_; }
46  Vertex bottom_left() const { return bottom_left_; }
47 };
48 
49 class RenderBatch {
50  friend SpriteBatch;
51  // member variables
52 private:
53  GLsizei num_vertices_;
54  GLint offset_;
55  GLuint texture_;
56 
57  // member functions
58 public:
59  RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture);
60 
66  GLint offset() const { return offset_; }
67  GLsizei num_vertices() const { return num_vertices_; }
68  GLuint texture() const { return texture_; }
70 };
71 
72 class SpriteBatch {
73  // member variables
74 public:
75  static const int NUM_VERTICES = 6;
76 
77 private:
78  GLuint vbo_ = 0;
79  GLuint vao_ = 0;
80  std::vector<Glyph> glyphs_;
81  std::vector<Glyph*> glyph_ptrs_;
82  std::vector<RenderBatch> render_batches_;
83 
84  // member functions
85 public:
86  SpriteBatch();
87  SpriteBatch(const SpriteBatch&) = delete;
88  SpriteBatch(SpriteBatch&&) = delete;
89  ~SpriteBatch();
90 
91  SpriteBatch& operator=(const SpriteBatch&) = delete;
92  SpriteBatch& operator=(SpriteBatch&&) = delete;
93 
94  // initialize vaos and vbos
95  void init();
96  void begin();
97  void end();
98  // adds a sprite to the sprite batch to be rendered later
99  void draw(const glm::vec4& destination_rect, const glm::vec4& uv_rect,
100  GLuint texture, const Color& color, float depth);
101  // render the batch
102  void render();
103 
104 private:
105  void createVertexArray();
106  void createRenderBatches();
107  void sortGlyphs();
108 };
109 
110 } // yage
111 
112 #endif
Glyph with information of the texture.
Definition: spritebatch.hpp:25
+
1 /* ----------------------------------------------------------------------------
2  * spritebatch.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_SPRITE_BATCH_HPP
10 #define YAGE_SPRITE_BATCH_HPP
11 
12 #include "vertex.hpp"
13 
14 #include <GL/glew.h>
15 #include <glm/glm.hpp>
16 
17 #include <vector>
18 
19 namespace yage {
20 
21 class SpriteBatch;
22 
25 class Glyph {
26  // member variables
27 private:
28  GLuint texture_;
29  float depth_;
30  Vertex top_left_;
31  Vertex top_right_;
32  Vertex bottom_right_;
33  Vertex bottom_left_;
34 
35  // member functions
36 public:
37  Glyph(GLuint texture, float depth, const Vertex& top_left,
38  const Vertex& top_right, const Vertex& bottom_right,
39  const Vertex& bottom_left);
40 
41  GLuint texture() const { return texture_; }
42  float depth() const { return depth_; }
43  Vertex top_left() const { return top_left_; }
44  Vertex top_right() const { return top_right_; }
45  Vertex bottom_right() const { return bottom_right_; }
46  Vertex bottom_left() const { return bottom_left_; }
47 };
48 
49 class RenderBatch {
50  friend SpriteBatch;
51  // member variables
52 private:
53  GLsizei num_vertices_;
54  GLint offset_;
55  GLuint texture_;
56 
57  // member functions
58 public:
59  RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture);
60 
64  GLint offset() const { return offset_; }
65  GLsizei num_vertices() const { return num_vertices_; }
66  GLuint texture() const { return texture_; }
68 };
69 
70 class SpriteBatch {
71  // member variables
72 public:
73  static const int NUM_VERTICES = 6;
74 
75 private:
76  GLuint vbo_ = 0;
77  GLuint vao_ = 0;
78  std::vector<Glyph> glyphs_;
79  std::vector<Glyph*> glyph_ptrs_;
80  std::vector<RenderBatch> render_batches_;
81 
82  // member functions
83 public:
84  SpriteBatch();
85  SpriteBatch(const SpriteBatch&) = delete;
86  SpriteBatch(SpriteBatch&&) = delete;
87  ~SpriteBatch();
88 
89  SpriteBatch& operator=(const SpriteBatch&) = delete;
90  SpriteBatch& operator=(SpriteBatch&&) = delete;
91 
92  // initialize vaos and vbos
93  void init();
94  void begin();
95  void end();
96  // adds a sprite to the sprite batch to be rendered later
97  void draw(const glm::vec4& destination_rect, const glm::vec4& uv_rect,
98  GLuint texture, const Color& color, float depth);
99  // render the batch
100  void render();
101 
102 private:
103  void createVertexArray();
104  void createRenderBatches();
105  void sortGlyphs();
106 };
107 
108 } // yage
109 
110 #endif
Glyph with information of the texture.
Definition: spritebatch.hpp:25
Definition: camera2d.hpp:17
-- cgit