mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
slices working, broken colors
This commit is contained in:
@@ -39,6 +39,16 @@ namespace cgl {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] size_t size() const {
|
||||||
|
GLint res;
|
||||||
|
glGetNamedBufferParameteriv(id, GL_BUFFER_SIZE, &res);
|
||||||
|
return (size_t) res;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] size_t count() const {
|
||||||
|
return size() / sizeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
void put(const T &data, GLenum usage = GL_STATIC_DRAW) {
|
void put(const T &data, GLenum usage = GL_STATIC_DRAW) {
|
||||||
glNamedBufferData(id, sizeof(T), &data, usage);
|
glNamedBufferData(id, sizeof(T), &data, usage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,18 +29,45 @@ struct Matrices {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
struct MeshRef {
|
struct DirectMesh {
|
||||||
|
cgl::buffer<Primitive<N>> ibo;
|
||||||
|
GLenum mode;
|
||||||
|
|
||||||
|
explicit DirectMesh(GLenum mode, const Mesh<N> &mesh)
|
||||||
|
: ibo(), mode(mode) {
|
||||||
|
|
||||||
|
ibo.put(mesh.prims);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw() const {
|
||||||
|
ibo.bound(GL_ELEMENT_ARRAY_BUFFER, [&]() {
|
||||||
|
glDrawElements(mode, ibo.count() * N, GL_UNSIGNED_INT, nullptr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<unsigned N>
|
||||||
|
struct DeferredMesh {
|
||||||
cgl::vertexarray vao;
|
cgl::vertexarray vao;
|
||||||
cgl::buffer<Primitive<N>> ibo;
|
cgl::buffer<Primitive<N>> ibo;
|
||||||
|
|
||||||
unsigned primitive_count;
|
explicit DeferredMesh(const Mesh<N> &mesh)
|
||||||
unsigned index_count;
|
: ibo(), vao() {
|
||||||
|
|
||||||
explicit MeshRef(const Mesh<N> &mesh) : vao(), ibo() {
|
ibo.put(mesh.prims);
|
||||||
primitive_count = mesh.size();
|
|
||||||
index_count = primitive_count * N;
|
|
||||||
|
|
||||||
ibo.put(mesh.prims);;
|
vao.bound([&]() {
|
||||||
|
ibo.bound(GL_ARRAY_BUFFER, [&]() {
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribIPointer(0, N, GL_INT, 0, nullptr);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw() const {
|
||||||
|
vao.bound([&]() {
|
||||||
|
glDrawArrays(GL_POINTS, 0, ibo.count() * N);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,6 +97,18 @@ Matrices build(GLFWwindow *window, float st) {
|
|||||||
return Matrices(proj, view);
|
return Matrices(proj, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<unsigned N>
|
||||||
|
std::vector<Mesh<N>> poly_parts(const tc::Group &group) {
|
||||||
|
std::vector<Mesh<N>> parts;
|
||||||
|
auto g_gens = gens(group);
|
||||||
|
for (const auto &sg_gens : Combos(g_gens, N - 1)) {
|
||||||
|
parts.push_back(
|
||||||
|
triangulate<N>(group, sg_gens).tile(group, g_gens, sg_gens)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
void run(GLFWwindow *window) {
|
void run(GLFWwindow *window) {
|
||||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||||
glEnable(GL_POINT_SMOOTH);
|
glEnable(GL_POINT_SMOOTH);
|
||||||
@@ -90,11 +129,16 @@ void run(GLFWwindow *window) {
|
|||||||
auto proj_pipe = cgl::pipeline();
|
auto proj_pipe = cgl::pipeline();
|
||||||
proj_pipe
|
proj_pipe
|
||||||
.stage(direct_stereo)
|
.stage(direct_stereo)
|
||||||
.stage(curve_stereo)
|
.stage(solid);
|
||||||
|
|
||||||
|
auto slice_pipe = cgl::pipeline();
|
||||||
|
slice_pipe
|
||||||
|
.stage(defer)
|
||||||
|
.stage(slice)
|
||||||
.stage(solid);
|
.stage(solid);
|
||||||
|
|
||||||
//region points
|
//region points
|
||||||
auto group = tc::group::H(4);
|
auto group = tc::group::F4();
|
||||||
auto res = group.solve();
|
auto res = group.solve();
|
||||||
auto mirrors = mirror(group);
|
auto mirrors = mirror(group);
|
||||||
|
|
||||||
@@ -106,15 +150,11 @@ void run(GLFWwindow *window) {
|
|||||||
|
|
||||||
auto g_gens = gens(group);
|
auto g_gens = gens(group);
|
||||||
|
|
||||||
const unsigned WIRES_N = 2;
|
auto wire_data = merge(poly_parts<2>(group));
|
||||||
const GLenum WIRE_MODE = GL_LINES;
|
DirectMesh<2> wires(GL_LINES, wire_data);
|
||||||
std::vector<MeshRef<WIRES_N>> wires;
|
|
||||||
|
|
||||||
for (const auto &sg_gens : Combos(g_gens, WIRES_N - 1)) {
|
auto slice_data = merge(poly_parts<4>(group));
|
||||||
const auto s = triangulate<WIRES_N>(group, sg_gens).tile(group, g_gens, sg_gens);
|
DeferredMesh<4> slices(slice_data);
|
||||||
|
|
||||||
wires.emplace_back(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
@@ -125,8 +165,6 @@ void run(GLFWwindow *window) {
|
|||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbo);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbo);
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
|
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
int width, height;
|
int width, height;
|
||||||
glfwGetFramebufferSize(window, &width, &height);
|
glfwGetFramebufferSize(window, &width, &height);
|
||||||
@@ -138,20 +176,22 @@ void run(GLFWwindow *window) {
|
|||||||
Matrices mats = build(window, st);
|
Matrices mats = build(window, st);
|
||||||
ubo.put(mats);
|
ubo.put(mats);
|
||||||
|
|
||||||
glLineWidth(1.5);
|
|
||||||
const auto wires_dark = glm::vec3(.3, .3, .3);
|
const auto wires_dark = glm::vec3(.3, .3, .3);
|
||||||
const auto wires_light = wires_dark;
|
const auto wires_light = wires_dark;
|
||||||
|
|
||||||
proj_pipe.bound([&]() {
|
glLineWidth(1.5);
|
||||||
for (const auto &ref : wires) {
|
|
||||||
glProgramUniform3f(solid, 2, 1, 1, 1);
|
|
||||||
|
|
||||||
ref.ibo.bound(GL_ELEMENT_ARRAY_BUFFER, [&]() {
|
glProgramUniform3f(solid, 2, 0.9, 0.9, 0.9);
|
||||||
glDrawElements(WIRE_MODE, ref.index_count, GL_UNSIGNED_INT, nullptr);
|
proj_pipe.bound([&]() {
|
||||||
});
|
wires.draw();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
glProgramUniform3f(solid, 2, 0.9, 0.1, 0.1);
|
||||||
|
slice_pipe.bound([&]() {
|
||||||
|
slices.draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
glfwSwapInterval(2);
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|||||||
Reference in New Issue
Block a user