Vivid
Loading...
Searching...
No Matches
VertexBufferLayout.h
1#pragma once
2
3#include "common/types/OpenGLTypes.h"
4#include "utils/Error.h"
5
6namespace Vivid
7{
9 {
10 unsigned int type;
11 unsigned int count;
12 unsigned char normalised;
13
14 static unsigned int GetSizeOfType(unsigned int type)
15 {
16 switch (type)
17 {
18 case GL_FLOAT:
19 return 4;
20 case GL_UNSIGNED_INT:
21 return 4;
22 case GL_UNSIGNED_BYTE:
23 return 1;
24 break;
25 }
26 ASSERT(false);
27 return 0;
28 }
29 };
30
32 {
33 private:
34 unsigned int m_Stride;
35 Vector<VertexBufferElement> m_Elements;
36
37 void Push(unsigned int type, unsigned int count, unsigned char normalized)
38 {
39 m_Elements.push_back({ type, count, normalized });
40 m_Stride += count * VertexBufferElement::GetSizeOfType(type);
41 };
42
43 public:
45 : m_Stride(0)
46 {
47 }
48
49 void AddFloat(unsigned int count) { Push(GL_FLOAT, count, GL_FALSE); }
50
51 void AddUnsignedInt(unsigned int count) { Push(GL_UNSIGNED_INT, count, GL_FALSE); }
52
53 void AddUnsignedByte(unsigned int count) { Push(GL_UNSIGNED_BYTE, count, GL_TRUE); }
54
55 inline const Vector<VertexBufferElement> GetElements() const { return m_Elements; };
56
57 inline unsigned int GetStride() const { return m_Stride; };
58 };
59}