GlPortal Class Reference  0.1.1
Source code documentation of the free and open 3D action puzzle game.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VBO.hpp
Go to the documentation of this file.
1 #ifndef VBO_HPP
2 #define VBO_HPP
3 
4 #include <cstdint>
5 #include <vector>
6 
7 namespace radix {
8 
9 class VBO {
10 protected:
11  std::size_t size;
12  unsigned int id;
13 
14 public:
15  enum Usage : uint8_t {
16  Static = 0,
19 
20  Draw = 1 << 2,
23  };
24  constexpr static Usage DefaultUsage = static_cast<Usage>(Static | Draw);
25 
26  // Ctor / dtor
27  VBO();
28  VBO(std::size_t size, Usage usage = DefaultUsage);
29  ~VBO();
30  // No copy
31  VBO(const VBO&) = delete;
32  VBO& operator=(const VBO&) = delete;
33  // Move
34  VBO(VBO&&);
35  VBO& operator=(VBO&&);
36 
37  operator unsigned int() const { return id; }
38  void setSize(std::size_t size, Usage usage = DefaultUsage);
39  std::size_t getSize() const {
40  return size;
41  }
42 
43  void setData(const void *data, std::size_t count, Usage usage = DefaultUsage);
44 
45  template <typename T>
46  void setData(const std::vector<T> &data, Usage usage = DefaultUsage) {
47  setData(data.data(), data.size()*sizeof(T), usage);
48  }
49  template <typename T>
50  void setData(const T *data, std::size_t count, Usage usage = DefaultUsage) {
51  setData(data, count*sizeof(T), usage);
52  }
53 
54  void update(const void *data, std::size_t count = 0, std::size_t offset = 0);
55 
56  template <typename T>
57  void update(const std::vector<T> &data, std::size_t count = 0, std::size_t offset = 0) {
58  if (count == 0) {
59  count = data.size();
60  }
61  update(data.data(), count*sizeof(T), offset);
62  }
63  template <typename T>
64  void update(const T *data, std::size_t count, std::size_t offset = 0) {
65  update(data, count*sizeof(T), offset);
66  }
67  void bind() const;
68 };
69 
70 constexpr inline VBO::Usage operator|(const VBO::Usage a, const VBO::Usage b) {
71  return static_cast<VBO::Usage>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
72 }
73 
74 } /* namespace radix */
75 
76 #endif /* VBO_HPP */
Definition: VBO.hpp:20
void setSize(std::size_t size, Usage usage=DefaultUsage)
Definition: VBO.cpp:82
void update(const T *data, std::size_t count, std::size_t offset=0)
Definition: VBO.hpp:64
void setData(const T *data, std::size_t count, Usage usage=DefaultUsage)
Definition: VBO.hpp:50
Definition: GameController.hpp:7
static constexpr Usage DefaultUsage
Definition: VBO.hpp:24
void update(const void *data, std::size_t count=0, std::size_t offset=0)
Definition: VBO.cpp:98
Definition: VBO.hpp:9
~VBO()
Definition: VBO.cpp:74
Usage
Definition: VBO.hpp:15
Definition: VBO.hpp:22
VBO()
Definition: VBO.cpp:51
Definition: VBO.hpp:18
Definition: VBO.hpp:16
std::size_t getSize() const
Definition: VBO.hpp:39
std::size_t size
Definition: VBO.hpp:11
void update(const std::vector< T > &data, std::size_t count=0, std::size_t offset=0)
Definition: VBO.hpp:57
Definition: VBO.hpp:21
constexpr VBO::Usage operator|(const VBO::Usage a, const VBO::Usage b)
Definition: VBO.hpp:70
Definition: VBO.hpp:17
unsigned int id
Definition: VBO.hpp:12
void bind() const
Definition: VBO.cpp:78
void setData(const std::vector< T > &data, Usage usage=DefaultUsage)
Definition: VBO.hpp:46
VBO & operator=(const VBO &)=delete
void setData(const void *data, std::size_t count, Usage usage=DefaultUsage)
Definition: VBO.cpp:90