forked from christopher-besch/opengl_reference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertexBufferLayout.h
108 lines (89 loc) · 2.45 KB
/
VertexBufferLayout.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once
#include <vector>
#include "Renderer.h"
// one vertex buffer attribute
struct VertexBufferElement
{
// OpenGL type
unsigned int type;
unsigned int count;
unsigned char normalized;
static unsigned int get_size_of_type(unsigned int type)
{
switch (type)
{
case GL_FLOAT: return 4;
case GL_UNSIGNED_INT: return 4;
case GL_UNSIGNED_BYTE: return 1;
}
ASSERT(false);
return 0;
}
};
// all vertex buffer attributes for one vertex buffer
class VertexBufferLayout
{
private:
std::vector<VertexBufferElement> m_elements;
unsigned int m_stride;
public:
VertexBufferLayout()
: m_stride(0) {}
template<typename T>
void push(unsigned int count)
{
// when the type is unmatched
ASSERT(false);
// this seems to create problems with gcc
static_assert(false);
}
/////////////////////////////
// appears to be msvc only //
/////////////////////////////
// template<>
// void push<float>(unsigned int count)
// {
// <- hard coded for now
// m_elements.push_back({ GL_FLOAT, count, GL_FALSE });
// m_stride += count * VertexBufferElement::get_size_of_type(GL_FLOAT);
// }
// template<>
// void push<unsigned int>(unsigned int count)
// {
// m_elements.push_back({ GL_UNSIGNED_INT, count, GL_FALSE });
// m_stride += count * VertexBufferElement::get_size_of_type(GL_UNSIGNED_INT);
// }
// template<>
// void push<unsigned char>(unsigned int count)
// {
// m_elements.push_back({ GL_UNSIGNED_BYTE, count, GL_TRUE });
// m_stride += count * VertexBufferElement::get_size_of_type(GL_UNSIGNED_BYTE);
// }
inline const std::vector<VertexBufferElement>& get_elements() const
{
return m_elements;
}
inline unsigned int get_stride() const
{
return m_stride;
}
};
template<>
inline void VertexBufferLayout::push<float>(unsigned int count)
{
// <- hard coded for now
m_elements.push_back({ GL_FLOAT, count, GL_FALSE });
m_stride += count * VertexBufferElement::get_size_of_type(GL_FLOAT);
}
template<>
inline void VertexBufferLayout::push<unsigned int>(unsigned int count)
{
m_elements.push_back({ GL_UNSIGNED_INT, count, GL_FALSE });
m_stride += count * VertexBufferElement::get_size_of_type(GL_UNSIGNED_INT);
}
template<>
inline void VertexBufferLayout::push<unsigned char>(unsigned int count)
{
m_elements.push_back({ GL_UNSIGNED_BYTE, count, GL_TRUE });
m_stride += count * VertexBufferElement::get_size_of_type(GL_UNSIGNED_BYTE);
}