-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinesegments.h
executable file
·118 lines (99 loc) · 3.91 KB
/
linesegments.h
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
#ifndef LINESEGMENTS_H
#define LINESEGMENTS_H
#include "shader.h"
#include <glm/vec3.hpp>
#include <vector>
class LineSegments {
public:
void Draw(Shader *edgeShader) const {
edgeShader->Use();
drawEdges();
}
LineSegments() {}
void clear() { m_vertices.clear(); }
void add_edge(glm::vec3 p1, glm::vec3 p2) {
m_vertices.push_back(p1);
m_vertices.push_back(p2);
updateMeshBuffers();
}
void initializeDrawingBuffers() {
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
// glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, (m_vertices.size() + 1) * sizeof(glm::vec3),
&m_vertices[0], GL_DYNAMIC_DRAW);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indices.size() * sizeof(GLuint),
// &m_indices[0], GL_DYNAMIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3),
(GLvoid *)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3),
(GLvoid *)offsetof(glm::vec3, y));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3),
(GLvoid *)offsetof(glm::vec3, z));
glEnableVertexAttribArray(2);
glBindVertexArray(0);
// std::cout << "printDebugInformation was called in "<<__func__<<std::endl;
// // printDebugInformation();
//
}
private:
void drawEdges() const {
glBindVertexArray(VAO);
glDrawArrays(GL_LINES, 0, m_vertices.size());
glBindVertexArray(0);
}
std::vector<glm::vec3> m_vertices;
uint VAO, VBO;
// Material material{glm::vec3(0.05, 0.05, 0.05),
// glm::vec3(0.5, 0.5, 0), // should be static constexpr
// glm::vec3(0.6, 0.6, 0.5), 128 * 0.25};
private:
void updateMeshBuffers() {
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, (m_vertices.size() + 1) * sizeof(glm::vec3),
&m_vertices[0], GL_DYNAMIC_DRAW);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indices.size() * sizeof(GLuint),
// &m_indices[0], GL_DYNAMIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3),
(GLvoid *)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3),
(GLvoid *)offsetof(glm::vec3, y));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3),
(GLvoid *)offsetof(glm::vec3, z));
glEnableVertexAttribArray(2);
glBindVertexArray(0);
}
void printDebugInformation() const {
glBindVertexArray(VAO);
for (int i = 0; i <= 1; i++) {
GLint ival;
GLvoid *pval;
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &ival);
printf("Attr %d: ENABLED = %d\n", i, ival);
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_SIZE, &ival);
printf("Attr %d: SIZE = %d\n", i, ival);
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &ival);
printf("Attr %d: STRIDE = %d\n", i, ival);
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_TYPE, &ival);
printf("Attr %d: TYPE = 0x%x\n", i, ival);
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &ival);
printf("Attr %d: NORMALIZED = %d\n", i, ival);
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &ival);
printf("Attr %d: BUFFER = %d\n", i, ival);
glGetVertexAttribPointerv(i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &pval);
printf("Attr %d: POINTER = %d\n", i, ival);
}
// Also print the numeric handle of the VAO:
printf("VAO = %ld\n", long(VAO));
}
};
#endif // LINESEGMENTS_H