- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvertexarray.cpp
More file actions
Latest commit
140 lines (105 loc) · 2.81 KB
/
Copy pathvertexarray.cpp
File metadata and controls
140 lines (105 loc) · 2.81 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include<GL/glew.h>
#include<GL/gl.h>
#include<vector>
#include<cassert>
#include<iostream>
#include<cstdlib>
#include"vertexarray.h"
usingnamespacestd;
namespaceEZGraphics {
/* ------------------------------------------- */
VertexArray::VertexArray ( const VertexArray & rhs )
{
cerr << "Attempting to copy VertexArray object" << endl;
exit(1);
}
/* ------------------------------------------- */
VertexArray & VertexArray::operator= ( const VertexArray & rhs )
{
cerr << "Attempting assignment of VertexArray object" << endl;
exit(1);
}
/* ------------------------------------------- */
VertexArray::VertexArray()
{
glGenVertexArrays(1,&handle);
}
/* ------------------------------------------- */
VertexArray::~VertexArray()
{
assert(glIsVertexArray(handle));
glDeleteVertexArrays(1,&handle);
}
/* ------------------------------------------- */
voidVertexArray::attachInstancedAttribute ( const GLuint aix, const Buffer * b, GLuint divisor )
{
glBindVertexArray(handle);
b->setIndex(aix);
glEnableVertexAttribArray(aix);
glVertexAttribDivisor(aix,divisor);
glBindVertexArray(0);
}
/* ------------------------------------------- */
voidVertexArray::attachAttribute ( const GLuint aix, const Buffer * b )
{
glBindVertexArray(handle);
b->setIndex(aix);
glEnableVertexAttribArray(aix);
glBindVertexArray(0);
}
/* ------------------------------------------- */
voidVertexArray::on()
{
glBindVertexArray(handle);
}
/* ------------------------------------------- */
voidVertexArray::off()
{
glBindVertexArray(0);
}
/* ------------------------------------------- */
voidVertexArray::sendToPipeline ( GLenum ptype, GLint first, GLsizei num )
{
on();
glDrawArrays(ptype,first,num);
off();
}
/* ------------------------------------------- */
voidVertexArray::sendToPipelineInstanced ( GLenum ptype, GLint first, GLsizei num, GLsizei N )
{
on();
glDrawArraysInstanced(ptype,first,num,N);
off();
}
/* ------------------------------------------- */
voidVertexArray::setDivisor ( GLuint aix, GLuint divisor )
{
on();
glVertexAttribDivisor(aix,divisor);
off();
}
/* ------------------------------------------- */
voidVertexArray::resetDivisor ( GLuint aix )
{
setDivisor(aix,0);
}
/* ------------------------------------------- */
voidVertexArray::sendToPipelineIndexed ( GLenum ptype, IndexBuffer *b, GLint first, GLsizei num )
{
on();
b->on();
glDrawElements(ptype,num,b->getType(),(GLvoid*)(long)first);
b->off();
off();
}
/* ------------------------------------------- */
voidVertexArray::sendToPipelineInstancedIndexed ( GLenum ptype, IndexBuffer *b, GLint first, GLsizei num, GLsizei N )
{
on();
b->on();
glDrawElementsInstanced(ptype,num,b->getType(),(GLvoid*)(long)first,N);
b->off();
off();
}
/* ------------------------------------------- */
};