jubilant-funicular
InstanceBatch.h
1 #ifndef NTA_INSTANCEBATCH_H_INCLUDED
2 #define NTA_INSTANCEBATCH_H_INCLUDED
3 
4 #include "nta/SpriteBatch.h"
5 
6 namespace nta {
8  struct InstancedGlyph {
9  InstancedGlyph(GLuint texture) : count(1), tex(texture) {
10  glGenVertexArrays(1, &vao);
11  }
12  GLuint gen_vbo() {
13  vbos.push_back(0);
14  glGenBuffers(1, &vbos.back());
15  return vbos.back();
16  }
17 
19  GLsizei count;
21  GLuint tex;
22  GLuint vao;
23  std::vector<GLuint> vbos;
24  };
26  class InstanceBatch {
27  private:
28  std::vector<InstancedGlyph> m_glyphs;
29  public:
30  InstanceBatch() {}
31  ~InstanceBatch() { begin(); }
33  void begin();
35  void end() const {}
37  void reset() { begin(); }
39  void add_glyph(crvec4 posRect, GLuint texture = 0,
40  crvec4 uvRect = glm::vec4(0,0,1,1),
41  crvec4 color = glm::vec4(1));
47  void add_instance_data(const VertexAttrib* attribs, std::size_t num_attribs,
48  void* data, GLsizeiptr size, GLuint divisor = 1);
49  void render() const;
50  };
51 }
52 
53 #endif // NTA_INSTANCEBATCH_H_INCLUDED
nta::InstancedGlyph::tex
GLuint tex
The texture.
Definition: InstanceBatch.h:21
nta::InstancedGlyph::count
GLsizei count
The number of instances.
Definition: InstanceBatch.h:19
nta::InstanceBatch::add_instance_data
void add_instance_data(const VertexAttrib *attribs, std::size_t num_attribs, void *data, GLsizeiptr size, GLuint divisor=1)
Definition: InstanceBatch.cpp:33
nta::InstanceBatch::begin
void begin()
Clears out data from the previous frame.
Definition: InstanceBatch.cpp:4
nta::InstanceBatch
Definition: InstanceBatch.h:26
nta::InstanceBatch::end
void end() const
Doesn't actually do anything. This is purely cosmetic.
Definition: InstanceBatch.h:35
nta::VertexAttrib
represents an attribute of a vertex (e.g. a call to glVertexAttribPointer)
Definition: Vertex.h:13
nta
Definition: Animation2D.h:6
nta::InstanceBatch::add_glyph
void add_glyph(crvec4 posRect, GLuint texture=0, crvec4 uvRect=glm::vec4(0, 0, 1, 1), crvec4 color=glm::vec4(1))
Definition: InstanceBatch.cpp:13
nta::InstancedGlyph
Represents a Glyph to be drawn multiple times with slight variations.
Definition: InstanceBatch.h:8
nta::InstanceBatch::reset
void reset()
If you don't want to follow the begin/end pattern, you can just call reset instead before adding glyp...
Definition: InstanceBatch.h:37