-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer.h
111 lines (89 loc) · 1.97 KB
/
buffer.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
109
110
111
#pragma once
#include "GL/glew.h"
#include "GLFW/glfw3.h"
#include <vector>
using namespace std;
namespace Nata
{
class Buffer
{
public:
Buffer(){ m_ID = 0; };
~Buffer(){};
virtual void Bind() = 0;
virtual void Unbind() = 0;
protected:
unsigned int m_ID;
};
class VBO : Buffer
{
public:
VBO(const void* data, unsigned int size);
void Bind();
void Unbind();
unsigned int GetID() const { return m_ID; };
};
class IBO : Buffer
{
public:
IBO(const unsigned int* data, const unsigned int count);
void Bind();
void Unbind();
};
struct VAOAttribElement
{
unsigned int type;
unsigned int count;
unsigned char normalised;
VAOAttribElement(unsigned int type, unsigned int count, unsigned char normalised) :
type(type), count(count), normalised(normalised) {}
static unsigned int GetSizeOfType(unsigned int type)
{
switch (type)
{
case GL_FLOAT : return 4;
case GL_UNSIGNED_INT : return 4;
case GL_UNSIGNED_BYTE: return 1;
}
return 0;
}
};
class VAOAttribLayout
{
public:
vector<VAOAttribElement> Elements;
unsigned int Stride;
VAOAttribLayout() : Stride(0) {}
template<typename T>
void Push(unsigned int count) {}
template<>
void Push<float>(unsigned int count)
{
Elements.push_back(VAOAttribElement(GL_FLOAT, count, GL_FALSE));
Stride += VAOAttribElement::GetSizeOfType(GL_FLOAT) * count;
}
template<>
void Push<unsigned int>(unsigned int count)
{
Elements.push_back(VAOAttribElement(GL_UNSIGNED_INT, count, GL_FALSE));
Stride += VAOAttribElement::GetSizeOfType(GL_UNSIGNED_INT) * count;
}
template<>
void Push<unsigned char>(unsigned int count)
{
Elements.push_back(VAOAttribElement(GL_UNSIGNED_BYTE, count, GL_FALSE));
Stride += VAOAttribElement::GetSizeOfType(GL_UNSIGNED_BYTE) * count;
}
};
class VAO
{
public:
VAO();
~VAO();
void Bind();
void Unbind();
void AddBuffer(VBO& vbo, const VAOAttribLayout& layout);
protected:
unsigned int m_ID;
};
}