-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertexAttribute.cpp
More file actions
69 lines (58 loc) · 1.74 KB
/
VertexAttribute.cpp
File metadata and controls
69 lines (58 loc) · 1.74 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
#include "VertexAttribute.h"
VertexAttribute::VertexAttribute() {
name_ = "position";
num_components_ = 0;
stride_ = 0;
offset_ = 0;
location_ = 0;
datatype_ = GL_FLOAT;
is_normalized_ = GL_FALSE;
}
VertexAttribute::VertexAttribute(const GLchar* name) {
name_ = name;
num_components_ = 0;
stride_ = 0;
offset_ = 0;
location_ = 0;
datatype_ = GL_FLOAT;
is_normalized_ = GL_FALSE;
}
// VertexAttribute::VertexAttribute(const GLchar* name, GLint num_components) {
// name_ = name;
// num_components_ = num_components;
// stride_ = 0;
// offset_ = 0;
// location_ = 0;
// datatype_ = GL_FLOAT;
// is_normalized_ = GL_FALSE;
// }
// VertexAttribute::VertexAttribute(const GLchar* name, GLint num_components, GLenum datatype) {
// name_ = name;
// num_components_ = num_components;
// stride_ = 0;
// offset_ = 0;
// location_ = 0;
// datatype_ = datatype;
// is_normalized_ = GL_FALSE;
// }
VertexAttribute::~VertexAttribute() {
}
bool VertexAttribute::equals(VertexAttribute* other) {
if(other == 0) return false;
return (std::string(this->name_).compare(other->name()) == 0);
}
bool VertexAttribute::test_used_by(GLuint gpu_program) {
return (glGetAttribLocation(gpu_program, name_) != -1);
}
void VertexAttribute::bind_location(GLuint gpu_program, GLint location) {
glBindAttribLocation(gpu_program, location, name_);
location_ = location;
}
void VertexAttribute::format() {
glVertexAttribPointer(location_, num_components_, datatype_, is_normalized_, stride_, offset_);
glEnableVertexAttribArray(location_);
}
// SETTER
void VertexAttribute::num_components(GLint num_components) { num_components_ = num_components; }
void VertexAttribute::stride(GLsizei s) { stride_ = s; }
void VertexAttribute::offset(const GLvoid* o) { offset_ = o; }