Cleanup and tweaks for nanogui

- clean up main-gui.cpp
- Add Primitive constructor from vector
- move ubo bindbufferbase to correct location
This commit is contained in:
David Allemang
2020-10-11 18:00:38 -04:00
parent 7fb70dbae6
commit c164c319fc
3 changed files with 5 additions and 201 deletions

View File

@@ -26,6 +26,10 @@ struct Primitive {
inds[N - 1] = root; inds[N - 1] = root;
} }
explicit Primitive(const std::vector<unsigned> &values) {
std::copy(values.begin(), values.begin() + N, inds.begin());
}
~Primitive() = default; ~Primitive() = default;
void apply(const tc::Cosets &table, int gen) { void apply(const tc::Cosets &table, int gen) {

View File

@@ -39,10 +39,6 @@ struct Matrices {
auto pwidth = aspect * pheight; auto pwidth = aspect * pheight;
mat4 proj = ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f); mat4 proj = ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f);
// if (!glfwGetKey(window, GLFW_KEY_LEFT_SHIFT)) {
// state.st += state.time_delta / 8;
// }
auto view = mat4::Identity(); auto view = mat4::Identity();
return Matrices(proj, view); return Matrices(proj, view);
} }
@@ -138,7 +134,6 @@ public:
prop = std::make_unique<Prop<4, vec4>>(make_slice<4>(*group, root, {}, combos, exclude)); prop = std::make_unique<Prop<4, vec4>>(make_slice<4>(*group, root, {}, combos, exclude));
ubo = std::make_unique<cgl::Buffer<Matrices>>(); ubo = std::make_unique<cgl::Buffer<Matrices>>();
glBindBufferBase(GL_UNIFORM_BUFFER, 1, *ubo);
ren = std::make_unique<SliceRenderer<4, vec4>>(); ren = std::make_unique<SliceRenderer<4, vec4>>();
} }
@@ -162,6 +157,7 @@ public:
std::get<0>(prop->vbos).put(points(*group, root, time)); std::get<0>(prop->vbos).put(points(*group, root, time));
Matrices mats = Matrices::build(*this); Matrices mats = Matrices::build(*this);
glBindBufferBase(GL_UNIFORM_BUFFER, 1, *ubo);
ubo->put(mats); ubo->put(mats);
ren->draw(*prop); ren->draw(*prop);
} }

View File

@@ -1,196 +0,0 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <chrono>
#include <cmath>
#include <iostream>
#include <random>
#include <yaml-cpp/yaml.h>
#include <tc/groups.hpp>
#include <cgl/vertexarray.hpp>
#include <cgl/shaderprogram.hpp>
#include <cgl/pipeline.hpp>
#include <util.hpp>
#include <mirror.hpp>
#include <rendering.hpp>
#include <solver.hpp>
#include <geometry.hpp>
#ifdef _WIN32
extern "C" {
__attribute__((unused)) __declspec(dllexport) int NvOptimusEnablement = 0x00000001;
}
#endif
struct Matrices {
mat4 proj;
mat4 view;
Matrices() = default;
Matrices(const mat4 &proj, const mat4 &view)
: proj(proj), view(view) {
}
};
struct State {
float time;
float time_delta;
float st;
int dimension;
};
Matrices build(GLFWwindow *window, State &state) {
int width, height;
glfwGetFramebufferSize(window, &width, &height);
auto aspect = (float) width / (float) height;
auto pheight = 1.4f;
auto pwidth = aspect * pheight;
mat4 proj = ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f);
if (!glfwGetKey(window, GLFW_KEY_LEFT_SHIFT)) {
state.st += state.time_delta / 8;
}
auto view = identity<4>();
return Matrices(proj, view);
}
template<class C>
std::vector<vec4> points(const tc::Group &group, const C &coords, const float time) {
auto cosets = group.solve();
auto mirrors = mirror<5>(group);
auto corners = plane_intersections(mirrors);
auto start = barycentric(corners, coords);
auto higher = cosets.path.walk<vec5, vec5>(start, mirrors, reflect<vec5>);
auto r = identity<5>();
r = mul(r, rot<5>(0, 2, time * .21f));
r = mul(r, rot<5>(1, 4, time * .27f));
r = mul(r, rot<5>(0, 3, time * .17f));
r = mul(r, rot<5>(1, 3, time * .25f));
r = mul(r, rot<5>(2, 3, time * .12f));
std::transform(higher.begin(), higher.end(), higher.begin(), [&](vec5 v) { return mul(v, r); });
std::vector<vec4> lower(higher.size());
std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>);
return lower;
}
template<int N, class T, class C>
Prop<4, vec4> make_slice(
const tc::Group &g,
const C &coords,
vec3 color,
T all_sg_gens,
const std::vector<std::vector<int>> &exclude
) {
Prop<N, vec4> res{};
// res.vbo.put(points(g, coords));
res.ibo.put(merge<N>(hull<N>(g, all_sg_gens, exclude)));
res.vao.ipointer(0, res.ibo, 4, GL_UNSIGNED_INT);
return res;
}
void run(const std::string &config_file, GLFWwindow *window) {
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
std::vector<int> symbol = {4, 3, 3, 3};
vec5 root = {.80, .02, .02, .02, .02};
auto group = tc::schlafli(symbol);
auto gens = generators(group);
std::vector<std::vector<int>> exclude = {{0, 1, 2}};
auto combos = Combos<int>(gens, 3);
SliceRenderer<4, vec4> ren{};
Prop<4, vec4> prop = make_slice<4>(group, root, {}, combos, exclude);
State state{};
state.dimension = 4;
glfwSetWindowUserPointer(window, &state);
auto ubo = cgl::Buffer<Matrices>();
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
while (!glfwWindowShouldClose(window)) {
auto time = (float) glfwGetTime();
state.time_delta = state.time - time;
state.time = time;
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLineWidth(1.5);
std::get<0>(prop.vbos).put(points(group, root, time));
Matrices mats{};
glViewport(0, 0, width, height);
mats = build(window, state);
ubo.put(mats);
ren.draw(prop);
glfwSwapInterval(2);
glfwSwapBuffers(window);
glfwPollEvents();
}
}
int main(int argc, char *argv[]) {
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW" << std::endl;
return EXIT_FAILURE;
}
glfwWindowHint(GLFW_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_VERSION_MAJOR, 5);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
auto window = glfwCreateWindow(
1920, 1080,
"Coset Visualization",
nullptr, nullptr);
if (!window) {
std::cerr << "Failed to create window" << std::endl;
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
glfwSwapInterval(1);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
std::cout << utilInfo();
std::string config_file = "presets/default.yaml";
if (argc > 1) config_file = std::string(argv[1]);
run(config_file, window);
glfwTerminate();
return EXIT_SUCCESS;
}