-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvertex_buffer.h
42 lines (33 loc) · 1.23 KB
/
vertex_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
#pragma once
#include <GL/glew.h>
#include "defines.h"
struct VertexBuffer {
VertexBuffer(void* data, uint32 numVertices) {
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &bufferId);
glBindBuffer(GL_ARRAY_BUFFER, bufferId);
glBufferData(GL_ARRAY_BUFFER, numVertices * sizeof(Vertex), data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(struct Vertex,position));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(struct Vertex,normal));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(struct Vertex,tangent));
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(struct Vertex,textureCoord));
glBindVertexArray(0);
}
virtual ~VertexBuffer() {
glDeleteBuffers(1, &bufferId);
}
void bind() {
glBindVertexArray(vao);
}
void unbind() {
glBindVertexArray(0);
}
private:
GLuint bufferId;
GLuint vao;
};