Allolib  1.0
C++ Components For Interactive Multimedia
al_VAOMesh.hpp
1 #ifndef INCLUDE_AL_VAOMESH_HPP
2 #define INCLUDE_AL_VAOMESH_HPP
3 
4 /* Keehong Youn, 2017, younkeehong@gmail.com
5  */
6 
7 #include "al/graphics/al_BufferObject.hpp"
8 #include "al/graphics/al_Mesh.hpp"
9 #include "al/graphics/al_VAO.hpp"
10 
11 #include <iostream>
12 #include <memory>
13 #include <unordered_map>
14 
15 namespace al {
16 
17 // layout (attribute location) for (GL) <-> (glsl shader)
18 enum AttribLayout : unsigned int {
19  ATTRIB_POSITION = 0,
20  ATTRIB_COLOR = 1,
21  ATTRIB_TEXCOORD_2D = 2,
22  ATTRIB_NORMAL = 3
23  // ATTRIB_TEXCOORD_3D = 4, // also could be used for other purposes
24  // ATTRIB_TEXCOORD_1D = 5, //
25 };
26 
34 class VAOMesh : public Mesh {
35  public:
36  struct MeshAttrib {
37  unsigned int index;
38  int size;
39  BufferObject buffer;
40  MeshAttrib(unsigned int i, int s) : index(i), size(s) {}
41  };
42 
43  struct VAOWrapper {
44  unsigned int GLPrimMode = GL_TRIANGLES;
45  VAO vao;
46  MeshAttrib positionAtt{ATTRIB_POSITION, 3}, colorAtt{ATTRIB_COLOR, 4},
47  texcoord2dAtt{ATTRIB_TEXCOORD_2D, 2},
48  normalAtt{ATTRIB_NORMAL, 3} // mTexcoord3dAtt {ATTRIB_TEXCOORD_3D, 3},
49  // mTexcoord1dAtt {ATTRIB_TEXCOORD_1D, 1}
50  ;
51  BufferObject indexBuffer;
52  };
53 
54  std::shared_ptr<VAOWrapper> vaoWrapper;
55 
56  VAOMesh();
57  VAOMesh(Primitive p);
58  VAOMesh(VAOMesh const& other);
59  VAOMesh(VAOMesh&& other);
60  VAOMesh& operator=(VAOMesh const& other);
61  VAOMesh& operator=(VAOMesh&& other);
62 
63  VAO& vao() { return vaoWrapper->vao; }
64  MeshAttrib& positionAtt() { return vaoWrapper->positionAtt; }
65  MeshAttrib& colorAtt() { return vaoWrapper->colorAtt; }
66  MeshAttrib& texcoord2dAtt() { return vaoWrapper->texcoord2dAtt; }
67  MeshAttrib& normalAtt() { return vaoWrapper->normalAtt; }
68  BufferObject& indexBuffer() { return vaoWrapper->indexBuffer; }
69 
70  void update();
71 
72  void bind();
73  void unbind();
74 
75  template <typename T>
76  void updateAttrib(std::vector<T> const& data, MeshAttrib& att);
77 
78  void draw();
79 };
80 
81 } // namespace al
82 
83 #endif
Stores buffers related to rendering graphical objects.
Definition: al_Mesh.hpp:62
VAO class.
Definition: al_VAO.hpp:18
VAOMesh classStores gpu objects as shared pointer to that this class can be copied for moved this is ...
Definition: al_VAOMesh.hpp:34
Definition: al_App.hpp:23