mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
vao pointer helper
This commit is contained in:
@@ -318,5 +318,38 @@ namespace cgl {
|
|||||||
action();
|
action();
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void pointer(
|
||||||
|
GLuint index,
|
||||||
|
const buffer<T> &buf,
|
||||||
|
unsigned size,
|
||||||
|
GLenum type,
|
||||||
|
bool normalized = false,
|
||||||
|
unsigned stride = 0
|
||||||
|
) const {
|
||||||
|
bound([&]() {
|
||||||
|
glEnableVertexAttribArray(index);
|
||||||
|
buf.bound(GL_ARRAY_BUFFER, [&]() {
|
||||||
|
glVertexAttribPointer(index, size, type, normalized, stride, nullptr);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void ipointer(
|
||||||
|
GLuint index,
|
||||||
|
const buffer<T> &buf,
|
||||||
|
unsigned size,
|
||||||
|
GLenum type,
|
||||||
|
unsigned stride = 0
|
||||||
|
) const {
|
||||||
|
bound([&]() {
|
||||||
|
glEnableVertexAttribArray(index);
|
||||||
|
buf.bound(GL_ARRAY_BUFFER, [&]() {
|
||||||
|
glVertexAttribIPointer(index, size, type, stride, nullptr);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,17 +29,17 @@ struct Matrices {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<unsigned N, class V>
|
template<unsigned N, class V>
|
||||||
struct BufferMesh {
|
struct Drawable {
|
||||||
GLenum mode{};
|
GLenum mode{};
|
||||||
cgl::vertexarray vao{};
|
cgl::vertexarray vao{};
|
||||||
cgl::buffer<Primitive<N>> ibo{};
|
cgl::buffer<Primitive<N>> ibo{};
|
||||||
cgl::buffer<V> vbo{};
|
cgl::buffer<V> vbo{};
|
||||||
|
|
||||||
BufferMesh(GLenum mode) : mode(mode), vao(), ibo(), vbo() {}
|
Drawable(GLenum mode) : mode(mode), vao(), ibo(), vbo() {}
|
||||||
|
|
||||||
BufferMesh(BufferMesh &) = delete;
|
Drawable(Drawable &) = delete;
|
||||||
|
|
||||||
BufferMesh(BufferMesh &&) = delete;
|
Drawable(Drawable &&) = delete;
|
||||||
|
|
||||||
void draw_deferred() {
|
void draw_deferred() {
|
||||||
vao.bound([&]() {
|
vao.bound([&]() {
|
||||||
@@ -152,9 +152,6 @@ void run(GLFWwindow *window) {
|
|||||||
auto group = tc::group::F4();
|
auto group = tc::group::F4();
|
||||||
|
|
||||||
auto wire_data = merge(poly_parts<2>(group));
|
auto wire_data = merge(poly_parts<2>(group));
|
||||||
auto wires = BufferMesh<2, float>(GL_LINES);
|
|
||||||
wires.ibo.put(wire_data.prims);
|
|
||||||
|
|
||||||
const auto slice_dark = glm::vec3(.5, .3, .7);
|
const auto slice_dark = glm::vec3(.5, .3, .7);
|
||||||
const auto slice_light = glm::vec3(.9, .9, .95);
|
const auto slice_light = glm::vec3(.9, .9, .95);
|
||||||
|
|
||||||
@@ -171,19 +168,14 @@ void run(GLFWwindow *window) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferMesh<4, glm::vec3> slices(GL_POINTS);
|
Drawable<2, float> wires(GL_LINES);
|
||||||
|
wires.ibo.put(wire_data.prims);
|
||||||
|
|
||||||
|
Drawable<4, glm::vec3> slices(GL_POINTS);
|
||||||
slices.ibo.put(slice_data.prims);
|
slices.ibo.put(slice_data.prims);
|
||||||
slices.vbo.put(slice_colors);
|
slices.vbo.put(slice_colors);
|
||||||
slices.vao.bound([&]() {
|
slices.vao.ipointer(0, slices.ibo, 4, GL_UNSIGNED_INT);
|
||||||
slices.ibo.bound(GL_ARRAY_BUFFER, [&]() {
|
slices.vao.pointer(1, slices.vbo, 3, GL_FLOAT);
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribIPointer(0, 4, GL_UNSIGNED_INT, 0, nullptr);
|
|
||||||
slices.vbo.bound(GL_ARRAY_BUFFER, [&]() {
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
auto vbo = cgl::buffer<glm::vec4>(points(group));
|
auto vbo = cgl::buffer<glm::vec4>(points(group));
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbo);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbo);
|
||||||
|
|||||||
Reference in New Issue
Block a user