-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvao.cpp
61 lines (49 loc) · 1.32 KB
/
vao.cpp
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
#include "complain.hpp"
#include "vao.hpp"
#include "vbo.hpp"
#include "gl_error.hpp"
#include "shader_program.hpp"
#include <stdexcept>
using namespace plush;
VAO::VAO()
{
glGenVertexArrays(1, &m_id);
ON_GL_ERROR_COMPLAIN();
}
VAO::~VAO()
{
glDeleteVertexArrays(1, &m_id);
}
void VAO::bind()
{
glBindVertexArray(m_id);
}
void VAO::unbind()
{
glBindVertexArray(0);
}
void VAO::enableVertexAttribArray(const std::string &attribName)
{
GLint attrib = ShaderProgram::current().getAttribLocation(attribName);
if (attrib < 0) {
// attribute not found, was reported earlier, just return
return;
}
glEnableVertexAttribArray(attrib);
}
void VAO::vertexAttribPointer(const std::string &attribName,
VBO &buf,
unsigned int valueCount, GLenum valueType,
bool normalize,
int stride, int offset)
{
GLint attrib = ShaderProgram::current().getAttribLocation(attribName);
if (attrib < 0 ) {
// attribute not found, was reported earlier, just return
return;
}
buf.bind();
glVertexAttribPointer(attrib, valueCount, valueType, normalize, stride,
reinterpret_cast<GLvoid*>(offset));
ON_GL_ERROR_COMPLAIN();
}