Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vertex_data.h
Go to the documentation of this file.
1 #ifndef VERTEX_DATA_H
2 #define VERTEX_DATA_H
3 #ifdef __APPLE__
4 #include <OpenGL/gl3.h>
5 #else
6 #include <GL/glew.h>
7 #endif
8 #include <glm/vec4.hpp>
9 #include <glm/vec3.hpp>
10 #include <glm/vec2.hpp>
11 #include <vector>
12 #include <map>
13 namespace Graphics {
17  class VertexData {
18  public:
22  enum DATA_TYPE : unsigned int {
23  GEOMETRY = 0,
27  RESERVED2 = 4,
28  RESERVED3 = 5,
29  RESERVED4 = 6,
30  RESERVED5 = 7,
31  RESERVED6 = 8,
32  RESERVED7 = 9,
33  RESERVED8 = 10,
34  RESERVED9 = 11,
35  ONE_WIDE = 12,
36  TWO_WIDE = 13,
37  THREE_WIDE = 14,
38  FOUR_WIDE = 15
39  };
40 
41  private:
42  std::map<DATA_TYPE, std::vector<float>> float_vector1s;
43  std::map<DATA_TYPE, std::vector<glm::vec2>> float_vector2s;
44  std::map<DATA_TYPE, std::vector<glm::vec3>> float_vector3s;
45  std::map<DATA_TYPE, std::vector<glm::vec4>> float_vector4s;
46  std::map<DATA_TYPE, std::vector<double>> double_vector1s;
47  std::map<DATA_TYPE, std::vector<glm::dvec2>> double_vector2s;
48  std::map<DATA_TYPE, std::vector<glm::dvec3>> double_vector3s;
49  std::map<DATA_TYPE, std::vector<glm::dvec4>> double_vector4s;
50  std::map<DATA_TYPE, std::vector<int>> int_vector1s;
51  std::map<DATA_TYPE, std::vector<glm::ivec2>> int_vector2s;
52  std::map<DATA_TYPE, std::vector<glm::ivec3>> int_vector3s;
53  std::map<DATA_TYPE, std::vector<glm::ivec4>> int_vector4s;
54  std::map<DATA_TYPE, std::vector<unsigned int>> unsigned_int_vector1s;
55  std::map<DATA_TYPE, std::vector<glm::uvec2>> unsigned_int_vector2s;
56  std::map<DATA_TYPE, std::vector<glm::uvec3>> unsigned_int_vector3s;
57  std::map<DATA_TYPE, std::vector<glm::uvec4>> unsigned_int_vector4s;
58  std::vector<unsigned int> indices;
59  unsigned int index_count;
60  unsigned int vertex_count;
61  GLenum primitive_type;
62  float highest_z;
63 
64  const unsigned char ANY = 0;
65 
66  const std::map<GLenum, unsigned char> divisibility {
67  {GL_TRIANGLES, 3},
68  {GL_TRIANGLE_STRIP, ANY},
69  {GL_TRIANGLE_FAN, ANY},
70  {GL_LINES, 2},
71  {GL_LINE_LOOP, ANY},
72  {GL_LINE_STRIP, ANY},
73  {GL_QUADS, 4}
74  };
75 
76  const std::map<GLenum, unsigned char> minimum {
77  {GL_TRIANGLES, 3},
78  {GL_TRIANGLE_STRIP, 3},
79  {GL_TRIANGLE_FAN, 3},
80  {GL_LINES, 2},
81  {GL_LINE_STRIP, 2},
82  {GL_LINE_LOOP, 3},
83  {GL_QUADS, 4}
84  };
85 
86  void checkDivisibility(const unsigned int size);
87  void checkMinimum(const unsigned int size);
88  void clearDataType(const DATA_TYPE& type);
89 
90  void setHighestZIfHigher(float z) noexcept;
91 
92  template<class T>
93  bool mapCompare(std::map<DATA_TYPE, std::vector<T>> lhs, std::map<DATA_TYPE, std::vector<T>> rhs);
94 
95  public:
99  static const std::map<DATA_TYPE, unsigned int> DataWidth;
100 
106  VertexData(const GLenum primitive_type = GL_TRIANGLES);
107 
113  VertexData(const VertexData& vertex_data);
121  VertexData operator=(const VertexData& vertex_data);
122 
126  ~VertexData();
127 
135  bool operator==(const VertexData& other);
143  bool operator!=(const VertexData& other);
144 
153  void addIndices(const std::vector<unsigned int>& indices);
154 
163  template<typename T>
164  void addVec(DATA_TYPE data_type, const std::vector<T>& vec);
165 
171  unsigned int getIndexCount() const noexcept;
177  unsigned int getVertexCount() const noexcept;
178 
184  template<typename T>
185  std::map<DATA_TYPE, std::vector<T>> getCollapsedVectors() const;
186 
192  std::vector<unsigned int> getIndices() const noexcept;
193 
199  float highestZ() const noexcept;
200 
206  unsigned int numberVertexBufferObjects() const noexcept;
212  unsigned int generateVertexArrayObject() const;
213 
219  std::string to_string() const noexcept;
220  };
221 }
222 
223 #endif
Definition: vertex_data.h:24
Definition: vertex_data.h:30
Definition: vertex_data.h:29
Definition: vertex_data.h:33
static const std::map< DATA_TYPE, unsigned int > DataWidth
Definition: vertex_data.h:99
unsigned int numberVertexBufferObjects() const noexcept
Returns number of vertex buffer objects needed for this vertex data.
Definition: vertex_data.cpp:684
void addIndices(const std::vector< unsigned int > &indices)
Adds indices.
Definition: vertex_data.cpp:187
Definition: vertex_data.h:38
Definition: vertex_data.h:37
DATA_TYPE
VertexData possible types.
Definition: vertex_data.h:22
unsigned int getVertexCount() const noexcept
Gets the vertex count.
Definition: vertex_data.cpp:532
VertexData(const GLenum primitive_type=GL_TRIANGLES)
VertexData constructor.
Definition: vertex_data.cpp:9
VertexData operator=(const VertexData &vertex_data)
= operator
Definition: vertex_data.cpp:38
Definition: vertex_data.h:27
Definition: vertex_data.h:26
Class for vertex data.
Definition: vertex_data.h:17
std::string to_string() const noexcept
Returns a string representation of the object.
Definition: vertex_data.cpp:763
Definition: vertex_data.h:23
unsigned int generateVertexArrayObject() const
Generates an opengl vertex array object.
Definition: vertex_data.cpp:691
std::vector< unsigned int > getIndices() const noexcept
Gets the indices.
Definition: vertex_data.cpp:540
bool operator!=(const VertexData &other)
!= operator
Definition: vertex_data.cpp:127
void addVec(DATA_TYPE data_type, const std::vector< T > &vec)
Adds a vector of data for a certain data type.
bool operator==(const VertexData &other)
== operator
Definition: vertex_data.cpp:87
Definition: vertex_data.h:32
float highestZ() const noexcept
Returns the highest Z value found in this vertex data.
Definition: vertex_data.cpp:680
Definition: vertex_data.h:31
std::map< DATA_TYPE, std::vector< T > > getCollapsedVectors() const
Gets a map of collapsed type vectors to a data types.
~VertexData()
Destroys the object.
Definition: vertex_data.cpp:63
Definition: vertex_data.h:34
unsigned int getIndexCount() const noexcept
Gets the index count.
Definition: vertex_data.cpp:536
Definition: vertex_data.h:28
Definition: vertex_data.h:25
Definition: vertex_data.h:36
Definition: vertex_data.h:35