Repository navigation
Expand file tree
/
Copy pathrenderable.cpp
More file actions
67 lines (56 loc) · 1.41 KB
/
Copy pathrenderable.cpp
File metadata and controls
67 lines (56 loc) · 1.41 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
#include "renderable.h"
void * Renderable::GetVertexBufferPointer()
{
return nullptr;
}
int Renderable::GetPrimitiveCount()
{
return 0;
}
void Renderable::Draw()
{
int primitiveCount = GetPrimitiveCount();
if (primitiveCount <= 0 || PrimitiveSize <= 0) {
return;
}
void* vptr = GetVertexBufferPointer();
glBindVertexArray(VAO);
if (VAO <= 0) {
glBindBuffer(GL_ARRAY_BUFFER, VBO);
EnableAttributes();
bool isPointerSet = false;
if (VBO <= 0) {
if (vptr) {
for (auto i = attributes.begin(); i != attributes.end(); i++) {
isPointerSet = true;
glVertexAttribPointer(i->index, i->size, i->type, i->normalized, i->stride, (GLbyte*)vptr + i->buffer_byte_offset);
}
}
}
else {
for (auto i = attributes.begin(); i != attributes.end(); i++) {
isPointerSet = true;
glVertexAttribPointer(i->index, i->size, i->type, i->normalized, i->stride, (void*)i->buffer_byte_offset);
}
}
if (isPointerSet) {
glDrawArrays(PrimitiveType, 0, primitiveCount);
}
DisableAttributes();
}
else {
glDrawArrays(PrimitiveType, 0, primitiveCount);
}
}
void Renderable::EnableAttributes()
{
for (auto i = attributes.begin(); i != attributes.end(); i++) {
glEnableVertexAttribArray(i->index);
}
}
void Renderable::DisableAttributes()
{
for (auto i = attributes.begin(); i != attributes.end(); i++) {
glDisableVertexAttribArray(i->index);
}
}