-
Notifications
You must be signed in to change notification settings - Fork 2
/
Buffer.h
97 lines (73 loc) · 1.83 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
#pragma once
#include<GL/glew.h>
#include<vector>
class VertexBuffer
{
private:
GLuint m_Renderer_ID;
public:
VertexBuffer();
VertexBuffer(const void* data, unsigned int size);
~VertexBuffer();
void Bind();
void UnBind();
void InitVertexBuffer(const void* data, unsigned int size) {
glGenBuffers(1, &m_Renderer_ID);
glBindBuffer(GL_ARRAY_BUFFER, m_Renderer_ID);
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
}
};
class IndexBuffer
{
private:
GLuint m_Renderer_ID;
unsigned int m_Count;
public:
IndexBuffer();
IndexBuffer(const void* data, unsigned int count);
~IndexBuffer();
void Bind();
void UnBind();
inline unsigned int GetCount() { return m_Count; }
void InitIndexBuffer(const void* data,unsigned int count)
{
glGenBuffers(1, &m_Renderer_ID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Renderer_ID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data, GL_STATIC_DRAW);
}
};
struct VertexBufferElement {
GLint _id;
unsigned int type;
unsigned int count;
bool normalize;
};
class BufferLayout {
private:
std::vector<VertexBufferElement> m_Elements;
unsigned int m_typeSize;
unsigned int m_Stride;
public:
BufferLayout(unsigned int stride) :m_Stride(stride) { }
template<typename T>
void Push(GLint _id, unsigned int count, bool normalise)
{
static_assert(false);
}
template<>
void Push<float>(GLint _id, unsigned int count, bool normalise)
{
m_typeSize = sizeof(float);
m_Elements.push_back({ _id, GL_FLOAT, count, normalise });
}
inline std::vector<VertexBufferElement> GetElements() { return m_Elements; }
inline unsigned int GetStride() { return m_Stride; }
inline unsigned int GetTypeSize() { return m_typeSize; }
};
class VertixAttrib {
private:
public:
VertixAttrib();
~VertixAttrib();
void AddBuffer(VertexBuffer& vb, BufferLayout& layout);
};