UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vertexdata.h
Go to the documentation of this file.
1 #ifndef UGDK_GRAPHIC_VERTEXDATA_H_
2 #define UGDK_GRAPHIC_VERTEXDATA_H_
3 
4 #include <ugdk/graphic.h>
5 #include <ugdk/structure/types.h>
6 
7 #include <cstddef>
8 #include <memory>
9 #include <typeinfo>
10 
11 #ifdef SWIG
12 // Nested class not supported
13 #pragma SWIG nowarn=325
14 #endif
15 
16 namespace ugdk {
17 namespace graphic {
18 
19 class VertexBuffer;
20 class VertexData {
21  public:
22  class Mapper {
23  public:
24  Mapper(VertexData& data, bool read_from_buffer = true);
25  ~Mapper();
26 
27  void operator=(Mapper&) = delete;
28 
29  template<class T>
30  T* Get(std::size_t index) {
31  Validate(typeid(T).name(), sizeof(T), index);
32  return reinterpret_cast<T*>(mapped_ + index * data_.vertex_size());
33  }
34 
35  private:
36  VertexData& data_;
37  ugdk::uint8* mapped_;
38 
39  void Validate(const char* name, std::size_t size, std::size_t index);
40  };
41 
42  VertexData(std::size_t num_vertices, std::size_t vertex_size, bool dynamic, bool ignore_vbo = false);
43  ~VertexData();
44 
45  const std::unique_ptr<VertexBuffer>& buffer() const { return buffer_; }
46  std::size_t num_vertices() const { return num_vertices_; }
47  std::size_t vertex_size() const { return vertex_size_; }
48 
49  void CheckSizes(const char* caller_name, std::size_t test_num_vertices, std::size_t test_vertex_size) const;
50 
51  private:
52  std::unique_ptr<VertexBuffer> buffer_;
53  std::size_t num_vertices_;
54  std::size_t vertex_size_;
55 };
56 
58  VertexDataSpecification(std::size_t num, std::size_t size, bool is_dynamic)
59  : num_vertices(num), vertex_size(size), dynamic(is_dynamic){}
60 
61  std::size_t num_vertices;
62  std::size_t vertex_size;
63  bool dynamic;
64 };
65 
66 std::shared_ptr<VertexData> CreateVertexDataWithSpecification(const VertexDataSpecification&);
67 
68 } // namespace graphic
69 } // namespace ugdk
70 
71 #endif // UGDK_GRAPHIC_VERTEXDATA_H_
uint8_t uint8
Definition: types.h:12
VertexDataSpecification(std::size_t num, std::size_t size, bool is_dynamic)
Definition: vertexdata.h:58
void CheckSizes(const char *caller_name, std::size_t test_num_vertices, std::size_t test_vertex_size) const
T * Get(std::size_t index)
Definition: vertexdata.h:30
Definition: animation.h:11
std::size_t num_vertices() const
Definition: vertexdata.h:46
Definition: vertexdata.h:20
bool dynamic
Definition: vertexdata.h:63
std::size_t num_vertices
Definition: vertexdata.h:61
Definition: vertexdata.h:57
void operator=(Mapper &)=delete
const std::unique_ptr< VertexBuffer > & buffer() const
Definition: vertexdata.h:45
Mapper(VertexData &data, bool read_from_buffer=true)
std::size_t vertex_size() const
Definition: vertexdata.h:47
VertexData(std::size_t num_vertices, std::size_t vertex_size, bool dynamic, bool ignore_vbo=false)
Definition: vertexdata.h:22
std::shared_ptr< VertexData > CreateVertexDataWithSpecification(const VertexDataSpecification &)
std::size_t vertex_size
Definition: vertexdata.h:62