-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvbo.cpp
57 lines (46 loc) · 1.18 KB
/
vbo.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
#include "complain.hpp"
#include "vbo.hpp"
#include "gl_error.hpp"
#include "shader_program.hpp"
#include <stdexcept>
#include <algorithm>
#include <iterator>
using namespace plush;
VBO::VBO(GLenum target, GLenum usage)
: m_target(target), m_usage(usage)
{
glGenBuffers(1, &m_id);
ON_GL_ERROR_COMPLAIN();
}
VBO::~VBO()
{
glDeleteBuffers(1, &m_id);
}
void VBO::bind()
{
glBindBuffer(m_target, m_id);
ON_GL_ERROR_COMPLAIN();
}
void VBO::unbind()
{
glBindBuffer(m_target, 0);
ON_GL_ERROR_COMPLAIN();
}
void VBO::data(size_t byteSize, const void* src)
{
bind();
glBufferData(m_target, byteSize, src, m_usage);
ON_GL_ERROR_COMPLAIN();
}
/////////////////////////////////////////////////////////////////////////////
// ArrayBuffer
/////////////////////////////////////////////////////////////////////////////
ArrayBuffer::ArrayBuffer(GLenum usage) : VBO(GL_ARRAY_BUFFER, usage)
{
}
/////////////////////////////////////////////////////////////////////////////
// ElementArrayBuffer
/////////////////////////////////////////////////////////////////////////////
ElementArrayBuffer::ElementArrayBuffer(GLenum usage) : VBO(GL_ELEMENT_ARRAY_BUFFER, usage)
{
}