From 6917f25d040868fb9f8fc586af468a019338e23c Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 13 Aug 2017 17:48:33 +0100 Subject: Updating docs --- spritebatch_8hpp_source.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'spritebatch_8hpp_source.html') diff --git a/spritebatch_8hpp_source.html b/spritebatch_8hpp_source.html index 4cc7be0c..f111d3c5 100644 --- a/spritebatch_8hpp_source.html +++ b/spritebatch_8hpp_source.html @@ -68,14 +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_; }
68  GLsizei num_vertices() const { return num_vertices_; }
69  GLuint texture() const { return texture_; }
71 };
72 
73 class SpriteBatch {
74  // member variables
75 public:
76  static const int NUM_VERTICES = 6;
77 
78 private:
79  GLuint vbo_ = 0;
80  GLuint vao_ = 0;
81  std::vector<Glyph> glyphs_;
82  std::vector<Glyph*> glyph_ptrs_;
83  std::vector<RenderBatch> render_batches_;
84 
85  // member functions
86 public:
87  SpriteBatch();
88  SpriteBatch(const SpriteBatch&) = delete;
89  SpriteBatch(SpriteBatch&&) = delete;
90  ~SpriteBatch();
91 
92  SpriteBatch& operator=(const SpriteBatch&) = delete;
93  SpriteBatch& operator=(SpriteBatch&&) = delete;
94 
95  // initialize vaos and vbos
96  void init();
97  void begin();
98  void end();
99  // adds a sprite to the sprite batch to be rendered later
100  void draw(const glm::vec4& destination_rect, const glm::vec4& uv_rect,
101  GLuint texture, const Color& color, float depth);
102  // render the batch
103  void render();
104 
105 private:
106  void createVertexArray();
107  void createRenderBatches();
108  void sortGlyphs();
109 };
110 
111 } // yage
112 
113 #endif
GLsizei num_vertices() const
num_vertices
Definition: spritebatch.hpp:68
-
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 private:
52  GLsizei num_vertices_;
53  GLint offset_;
54  GLuint texture_;
55 
56 public:
57  RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture);
58 
59  GLint offset() const { return offset_; }
60  GLsizei num_vertices() const { return num_vertices_; }
61  GLuint texture() const { return texture_; }
62 };
63 
64 class SpriteBatch {
65 public:
66  static const int NUM_VERTICES = 6;
67 
68 private:
69  GLuint vbo_ = 0;
70  GLuint vao_ = 0;
71  std::vector<Glyph> glyphs_;
72  std::vector<Glyph*> glyph_ptrs_;
73  std::vector<RenderBatch> render_batches_;
74 
75  // member functions
76 public:
77  SpriteBatch();
78  SpriteBatch(const SpriteBatch&) = delete;
79  SpriteBatch(SpriteBatch&&) = delete;
80  ~SpriteBatch();
81 
82  SpriteBatch& operator=(const SpriteBatch&) = delete;
83  SpriteBatch& operator=(SpriteBatch&&) = delete;
84 
85  // initialize vaos and vbos
86  void init();
87  void begin();
88  void end();
89  // adds a sprite to the sprite batch to be rendered later
90  void draw(const glm::vec4& destination_rect, const glm::vec4& uv_rect,
91  GLuint texture, const Color& color, float depth);
92  // render the batch
93  void render();
94 
95 private:
96  void createVertexArray();
97  void createRenderBatches();
98  void sortGlyphs();
99 };
100 
101 } // yage
102 
103 #endif
Glyph with information of the texture.
Definition: spritebatch.hpp:25
Definition: camera2d.hpp:17
-
GLint offset() const
Offset.
Definition: spritebatch.hpp:66
-- cgit