-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawable.cpp
More file actions
85 lines (71 loc) · 1.67 KB
/
drawable.cpp
File metadata and controls
85 lines (71 loc) · 1.67 KB
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
#include "drawable.h"
#include <la.h>
Drawable::Drawable(OpenGLContext* context)
: m_count(-1), m_bufIdx(), m_bufPos(), m_bufCol(),
m_idxBound(false), m_posBound(false), m_colBound(false),
mp_context(context)
{}
Drawable::~Drawable()
{
destroy();
}
void Drawable::destroy()
{
mp_context->glDeleteBuffers(1, &m_bufIdx);
mp_context->glDeleteBuffers(1, &m_bufPos);
mp_context->glDeleteBuffers(1, &m_bufCol);
}
GLenum Drawable::drawMode()
{
// Since we want every three indices in bufIdx to be
// read to draw our Drawable, we tell that the draw mode
// of this Drawable is GL_TRIANGLES
// If we wanted to draw a wireframe, we would return GL_LINES
return GL_TRIANGLES;
}
int Drawable::elemCount()
{
return m_count;
}
void Drawable::generateIdx()
{
m_idxBound = true;
// Create a VBO on our GPU and store its handle in bufIdx
mp_context->glGenBuffers(1, &m_bufIdx);
}
void Drawable::generatePos()
{
m_posBound = true;
// Create a VBO on our GPU and store its handle in bufPos
mp_context->glGenBuffers(1, &m_bufPos);
}
void Drawable::generateCol()
{
m_colBound = true;
// Create a VBO on our GPU and store its handle in bufCol
mp_context->glGenBuffers(1, &m_bufCol);
}
bool Drawable::bindIdx()
{
if (m_idxBound)
{
mp_context->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_bufIdx);
}
return m_idxBound;
}
bool Drawable::bindPos()
{
if (m_posBound)
{
mp_context->glBindBuffer(GL_ARRAY_BUFFER, m_bufPos);
}
return m_posBound;
}
bool Drawable::bindCol()
{
if (m_colBound)
{
mp_context->glBindBuffer(GL_ARRAY_BUFFER, m_bufCol);
}
return m_colBound;
}