-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawable.cpp
More file actions
93 lines (78 loc) · 1.95 KB
/
drawable.cpp
File metadata and controls
93 lines (78 loc) · 1.95 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
86
87
88
89
90
91
92
93
#include "drawable.h"
#include <la.h>
Drawable::Drawable(OpenGLContext* context)
: bufIdx(), bufPos(), bufNor(), bufUV(),
idxBound(false), posBound(false), norBound(false), uvBound(false),
context(context)
{}
void Drawable::destroy()
{
context->glDeleteBuffers(1, &bufIdx);
context->glDeleteBuffers(1, &bufPos);
context->glDeleteBuffers(1, &bufNor);
context->glDeleteBuffers(1, &bufUV);
}
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 count;
}
void Drawable::generateIdx()
{
idxBound = true;
// Create a VBO on our GPU and store its handle in bufIdx
context->glGenBuffers(1, &bufIdx);
}
void Drawable::generatePos()
{
posBound = true;
// Create a VBO on our GPU and store its handle in bufPos
context->glGenBuffers(1, &bufPos);
}
void Drawable::generateNor()
{
norBound = true;
// Create a VBO on our GPU and store its handle in bufNor
context->glGenBuffers(1, &bufNor);
}
void Drawable::generateUV()
{
uvBound = true;
// Create a VBO on our GPU and store its handle in bufCol
context->glGenBuffers(1, &bufUV);
}
bool Drawable::bindIdx()
{
if(idxBound) {
context->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufIdx);
}
return idxBound;
}
bool Drawable::bindPos()
{
if(posBound){
context->glBindBuffer(GL_ARRAY_BUFFER, bufPos);
}
return posBound;
}
bool Drawable::bindNor()
{
if(norBound){
context->glBindBuffer(GL_ARRAY_BUFFER, bufNor);
}
return norBound;
}
bool Drawable::bindUV()
{
if(uvBound){
context->glBindBuffer(GL_ARRAY_BUFFER, bufUV);
}
return uvBound;
}