add directrenderer for wireframes

This commit is contained in:
2020-05-21 20:49:26 -04:00
parent 293eeb3759
commit 1ed481d4a8
2 changed files with 101 additions and 103 deletions

View File

@@ -2,10 +2,10 @@ dimension: 5
groups: groups:
- symbol: [3, 4, 3] - symbol: [3, 4, 3]
slices: slices:
- root: [0.80, 0.09, 0.09, 0.09, 0.0] - root: [0.75, 0.09, 0.09, 0.09, 0.0]
color: [0.9, 0.9, 0.9] color: [0.9, 0.9, 0.9]
exclude: exclude:
- [0, 1, 2] - [0, 1, 2]
wires: wires:
- root: [0.80, 0.09, 0.09, 0.09, 0.0] - root: [0.75, 0.09, 0.09, 0.09, 0.0]
color: [0.3, 0.3, 0.3] color: [0.3, 0.3, 0.3]

View File

@@ -173,19 +173,23 @@ struct Renderer {
template<unsigned N> template<unsigned N>
struct Slice : public Prop<N> { struct Slice : public Prop<N> {
GLenum mode;
vec3 color; vec3 color;
Slice(GLenum mode, vec3 color) : Prop<N>(), mode(mode), color(color) {} Slice(vec3 color) : Prop<N>(), color(color) {}
Slice(Slice &) = delete; Slice(Slice &) = delete;
Slice(Slice &&) noexcept = default; Slice(Slice &&) noexcept = default;
template<class T, class C> template<class T, class C>
static Slice<N> build(const tc::Group &g, const C &coords, vec3 color, T all_sg_gens, static Slice<N> build(
const std::vector<std::vector<int>> &exclude) { const tc::Group &g,
Slice<N> res(GL_POINTS, color); const C &coords,
vec3 color,
T all_sg_gens,
const std::vector<std::vector<int>> &exclude
) {
Slice<N> res(color);
res.vbo.put(points(g, coords)); res.vbo.put(points(g, coords));
res.ibo.put(merge<N>(hull<N>(g, all_sg_gens, exclude))); res.ibo.put(merge<N>(hull<N>(g, all_sg_gens, exclude)));
@@ -230,39 +234,67 @@ struct SliceRenderer : public Renderer<N> {
} }
}; };
//struct Wire {
// bool curve; template<unsigned N>
// bool ortho; struct DirectRenderer : public Renderer<N> {
// vec3 color; cgl::pgm::vert direct_stereo = cgl::pgm::vert::file(
// cgl::VertexArray vao; "shaders/direct-stereo.vs.glsl");
// cgl::Buffer<vec4> vbo; cgl::pgm::frag solid = cgl::pgm::frag::file(
// cgl::Buffer<Primitive<2>> ibo; "shaders/solid.fs.glsl");
//
// Wire(bool curve, bool ortho, vec3 color) : curve(curve), ortho(ortho), color(color), vao(), ibo(), vbo() {} cgl::pipeline pipe;
//
// Wire(Wire &) = delete; DirectRenderer() {
// pipe.stage(direct_stereo);
// Wire(Wire &&) noexcept = default; pipe.stage(solid);
// }
// void draw() const {
// vao.bound([&]() { DirectRenderer(DirectRenderer &) = delete;
// ibo.bound(GL_ELEMENT_ARRAY_BUFFER, [&]() {
// glDrawElements(GL_LINES, ibo.count() * 2, GL_UNSIGNED_INT, nullptr); DirectRenderer(DirectRenderer &&) noexcept = default;
// });
// }); void bound(const std::function<void()> &action) const override {
// } pipe.bound(action);
// }
// template<class T, class C>
// static Wire build(const tc::Group &g, const C &coords, bool curve, bool ortho, vec3 color, T all_sg_gens, void _draw(const Prop<N> &prop) const override {
// const std::vector<std::vector<int>> &exclude) { glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, prop.vbo);
// Wire res(curve, ortho, color); // glProgramUniform3fv(sh.solid, 2, 1, &wire.color.front());
// glProgramUniform3f(solid, 2, .3f, .3f, .3f);
// res.vbo.put(points(g, coords)); prop.vao.bound([&]() {
// res.ibo.put(merge<2>(hull<2>(g, all_sg_gens, exclude))); prop.ibo.bound(GL_ELEMENT_ARRAY_BUFFER, [&]() {
// glDrawElements(GL_LINES, prop.ibo.count() * N, GL_UNSIGNED_INT, nullptr);
// return res; });
// } });
//}; }
};
struct Wire : public Prop<2> {
vec3 color;
Wire(vec3 color) : Prop<2>(), color(color) {}
Wire(Wire &) = delete;
Wire(Wire &&) noexcept = default;
template<class T, class C>
static Wire build(const tc::Group &g,
const C &coords,
bool curve,
bool ortho,
vec3 color,
T all_sg_gens,
const std::vector<std::vector<int>> &exclude
) {
Wire res(color);
res.vbo.put(points(g, coords));
res.ibo.put(merge<2>(hull<2>(g, all_sg_gens, exclude)));
return res;
}
};
void run(const std::string &config_file, GLFWwindow *window) { void run(const std::string &config_file, GLFWwindow *window) {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@@ -270,18 +302,8 @@ void run(const std::string &config_file, GLFWwindow *window) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Shaders sh; SliceRenderer<4> sRen{};
DirectRenderer<2> wRen{};
// auto wire_pipe = cgl::pipeline();
// wire_pipe
// .stage(sh.direct_stereo)
// .stage(sh.solid);
//
// auto slice_pipe = cgl::pipeline();
// slice_pipe
// .stage(sh.defer)
// .stage(sh.slice)
// .stage(sh.solid);
auto scene = YAML::LoadFile(config_file); auto scene = YAML::LoadFile(config_file);
@@ -291,8 +313,7 @@ void run(const std::string &config_file, GLFWwindow *window) {
state.dimension = scene["dimension"].as<int>(); state.dimension = scene["dimension"].as<int>();
auto slices = Bundle<4>(); auto slices = Bundle<4>();
// auto slices = std::vector<Slice<4>>(); auto wires = Bundle<2>();
// auto wires = std::vector<Wire>();
for (const auto &group_info : scene["groups"]) { for (const auto &group_info : scene["groups"]) {
auto symbol = group_info["symbol"].as<std::vector<int>>(); auto symbol = group_info["symbol"].as<std::vector<int>>();
@@ -323,38 +344,36 @@ void run(const std::string &config_file, GLFWwindow *window) {
} }
} }
// if (group_info["wires"].IsDefined()) { if (group_info["wires"].IsDefined()) {
// for (const auto &wire_info : group_info["wires"]) { for (const auto &wire_info : group_info["wires"]) {
// auto root = wire_info["root"].as<vec5>(); auto root = wire_info["root"].as<vec5>();
// auto color = wire_info["color"].as<vec3>(); auto color = wire_info["color"].as<vec3>();
// auto exclude = std::vector<std::vector<int>>(); auto exclude = std::vector<std::vector<int>>();
// auto curve = wire_info["curve"].IsDefined() && wire_info["curve"].as<bool>(); auto curve = wire_info["curve"].IsDefined() && wire_info["curve"].as<bool>();
// auto ortho = wire_info["ortho"].IsDefined() && wire_info["ortho"].as<bool>(); auto ortho = wire_info["ortho"].IsDefined() && wire_info["ortho"].as<bool>();
//
// if (wire_info["exclude"].IsDefined()) { if (wire_info["exclude"].IsDefined()) {
// exclude = wire_info["exclude"].as<std::vector<std::vector<int>>>(); exclude = wire_info["exclude"].as<std::vector<std::vector<int>>>();
// } }
//
// if (wire_info["subgroups"].IsDefined()) { if (wire_info["subgroups"].IsDefined()) {
// auto subgroups = wire_info["subgroups"].as<std::vector<std::vector<int>>>(); auto subgroups = wire_info["subgroups"].as<std::vector<std::vector<int>>>();
// wires.push_back(Wire::build( wires.push_back(Wire::build(
// group, root, curve, ortho, color, subgroups, exclude group, root, curve, ortho, color, subgroups, exclude
// )); ));
// } else { } else {
// auto combos = Combos<int>(gens, 1); auto combos = Combos<int>(gens, 1);
// wires.push_back(Wire::build( wires.push_back(Wire::build(
// group, root, curve, ortho, color, combos, exclude group, root, curve, ortho, color, combos, exclude
// )); ));
// } }
// } }
// } }
} }
auto ubo = cgl::Buffer<Matrices>(); auto ubo = cgl::Buffer<Matrices>();
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo); glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
SliceRenderer<4> sRen{};
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
auto time = (float) glfwGetTime(); auto time = (float) glfwGetTime();
state.time_delta = state.time - time; state.time_delta = state.time - time;
@@ -371,28 +390,7 @@ void run(const std::string &config_file, GLFWwindow *window) {
glLineWidth(1.5); glLineWidth(1.5);
// wire_pipe.bound([&]() { wRen.draw(wires);
// for (const auto &wire : wires) {
// if (wire.curve) wire_pipe.stage(sh.curve_stereo);
// else wire_pipe.unstage(GL_GEOMETRY_SHADER_BIT);
//
// if (wire.ortho) wire_pipe.stage(sh.direct_ortho);
// else wire_pipe.stage(sh.direct_stereo);
//
// glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, wire.vbo);
// glProgramUniform3fv(sh.solid, 2, 1, &wire.color.front());
// wire.draw();
// }
// });
//
// slice_pipe.bound([&]() {
// for (const auto &slice : slices) {
// glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, slice.vbo);
// glProgramUniform3fv(sh.solid, 2, 1, &slice.color.front());
// slice.draw();
// }
// });
sRen.draw(slices); sRen.draw(slices);
glfwSwapInterval(2); glfwSwapInterval(2);