All Classes Files Functions Variables Typedefs Pages
VertexSet.hpp
1 #pragma once
2 
3 #include "GLException.hpp"
4 #include "VertexSlot.hpp"
5 #include "VertexLayout.hpp"
6 #include "../service/StaticLogger.hpp"
7 
8 namespace lumina {
9 namespace internal {
10 
11 template <typename... Cs>
12 class VertexSet {
13 public:
14 
15  // subscript operator
16  VertexSlotAssign<Cs...> operator[](int index) {
17  // Test if index is valid (not even asan detects overflow: the memory
18  // after this block is somehow allocated by OpenGL anyways)
19  if(index >= m_slotCount) {
20  slogError("[VertexSet] Index <", index, "> out of bounds <",
21  m_slotCount, ">!");
22  throw GLException("[VertexSet] Index out of bounds!");
23  }
24 
25  // calculate offset and return another helper object
26  auto* buf = static_cast<char*>(m_buffer)
28  return VertexSlotAssign<Cs...>(buf);
29  }
30 
31  int size() { return m_slotCount; }
32 
33  void* buf() const { return m_buffer; }
34 
35 private:
36  // internal data
37  void* m_buffer;
38  int m_slotCount;
39 
40  VertexSet(int vertexCount)
41  : m_buffer(nullptr),
42  m_slotCount(vertexCount) {}
43 
44  // declare friends
45  friend ::lumina::HotVertexSeq<Cs...>;
46 };
47 
48 template <>
49 class VertexSet<> {
50 public:
51  // subscript operator
52  VertexFloatSlot operator[](int index) {
53  // Test if index is valid (not even asan detects overflow: the memory
54  // after this block is somehow allocated by OpenGL anyways)
55  if(index >= m_slotCount) {
56  slogError("[VertexSet] Index <", index, "> out of bounds <",
57  m_slotCount, ">!");
58  throw GLException("[VertexSet] Index out of bounds!");
59  }
60 
61  // calculate offset and return another helper object
62  auto* buf = static_cast<char*>(m_buffer)
63  + index * m_slotSize * sizeof(float);
64  return VertexFloatSlot(buf, m_slotSize);
65  }
66 
67  int size() { return m_slotCount; }
68 
69  void* buf() const { return m_buffer; }
70 
71 private:
72  // internal data
73  void* m_buffer;
74  int m_slotCount;
75  int m_slotSize;
76 
77  VertexSet(int vertexCount, int slotSize)
78  : m_buffer(nullptr),
79  m_slotCount(vertexCount),
80  m_slotSize(slotSize) {}
81 
82  // declare friends
83  friend ::lumina::HotVertexSeq<>;
84 };
85 
86 
87 }
88 }
Definition: VertexSlot.hpp:52
Definition: GLException.hpp:7
Definition: VertexSet.hpp:12
Definition: VertexSlot.fpp:7
Definition: VertexLayout.hpp:57