gdk-graphics  1b6d84e044c2c953fd7c9501e628a67e80f4da0d
vertex_data.h
1 // © Joseph Cameron - All Rights Reserved
2 
3 #ifndef GDK_GFX_VERTEX_DATA_VIEW_H
4 #define GDK_GFX_VERTEX_DATA_VIEW_H
5 
6 #include <optional>
7 #include <stdexcept>
8 #include <string>
9 #include <unordered_map>
10 #include <vector>
11 
16 {
17 public:
19  using attribute_component_type = float;
20 
22  const size_t aDataLength,
23  const size_t aComponentCount);
24 
25  attribute_component_type *data_begin() const;
26 
27  size_t data_size() const;
28 
29  size_t component_count() const;
30 
31 private:
34  attribute_component_type *m_pData;
35 
37  size_t m_DataLength;
38 
40  size_t m_ComponentCount;
41 };
42 
44 class vertex_data final
45 {
46 public:
47  using index_value_type = unsigned short;
48 
49  enum class PrimitiveMode
50  {
51  Triangles
52  };
53 
54  using attribute_data_type =
55  std::unordered_map<std::string, attribute_data_view>;
56 
58  {
60 
61  value_type *const begin; //TODO: iter type? + const end?
62 
63  const std::size_t size;
64  };
65 
66  PrimitiveMode getPrimitiveMode() const;
67 
68  const std::vector<attribute_data_view::attribute_component_type> &getData() const;
69 
70  const std::vector<std::pair<std::string, std::size_t>> &attribute_format() const;
71 
72  size_t attribute_offset(const std::string &aName) const;
73 
74  size_t vertex_size() const;
75 
76  size_t interleaved_data_size() const;
77 
78  //TODO: this returns a constant, need index support
79  std::vector<index_value_type> getIndexData() const;
80 
83  void operator+=(const vertex_data &&other);
86  void push_back(const vertex_data &&other);
87 
89  void clear();
90 
91  vertex_data(const attribute_data_type &aAttributeData);
92 
93  interleaved_data_view view_to_interleaved_data();
94 
95  //TODO: transform method?
96  // throw if name is not 3 component attribute?
97  //void transform(std::string name, sca, rot, tra)
98 
99 private:
101  PrimitiveMode m_PrimitiveMode = PrimitiveMode::Triangles;
102 
104  std::vector<attribute_data_view::attribute_component_type> m_Data;
105 
107  std::vector<std::pair<std::string, size_t>> m_Format;
108 
110  std::unordered_map<std::string, size_t> m_AttributeOffsets;
111 };
112 
113 #endif
114 
used to construct a model. Vertex data represents a set of vertex data in system memory ...
Definition: vertex_data.h:44
Definition: vertex_data.h:57
a view on to the data for a given attribute e.g: "uv", "position". a view does not own its data...
Definition: vertex_data.h:15
float attribute_component_type
all vertex components must be of this type.
Definition: vertex_data.h:19