ENH: Dynamically enable and color tilings

Use multidraw and command buffer
This commit is contained in:
David Allemang
2023-02-10 13:20:34 -05:00
parent 92a55f8c74
commit 53fe3104db
7 changed files with 185 additions and 90 deletions

View File

@@ -8,6 +8,7 @@ namespace cgl {
template<class T>
class Buffer {
GLuint id{};
size_t _count = 0;
public:
using Element = T;
@@ -32,25 +33,26 @@ namespace cgl {
}
[[nodiscard]] size_t size() const {
GLint res;
glGetNamedBufferParameteriv(id, GL_BUFFER_SIZE, &res);
return (size_t) res;
return _count * sizeof(T);
}
[[nodiscard]] size_t count() const {
return size() / sizeof(T);
}
void put(const T &data, GLenum usage = GL_STATIC_DRAW) {
glNamedBufferData(id, sizeof(T), &data, usage);
return _count;
}
template<typename It>
void put(It begin, It end, GLenum usage = GL_STATIC_DRAW) {
glNamedBufferData(id, sizeof(T) * (end - begin), nullptr, usage);
_count = end - begin;
glNamedBufferData(id, sizeof(T) * _count, nullptr, usage);
void* ptr = glMapNamedBuffer(id, GL_WRITE_ONLY);
std::copy(begin, end, (T*) ptr);
glUnmapNamedBuffer(id);
}
void put(const T &data, GLenum usage = GL_STATIC_DRAW) {
T const* ptr = &data;
put(ptr, ptr + 1, usage);
}
};
}

View File

@@ -112,7 +112,7 @@ Indices<N> cell(
std::vector<Indices<N - 1>> facets;
for (auto H : G.subs(N - 2)) {
for (auto H: G.subs(N - 2)) {
auto sub_base = cell<N - 1>(H);
auto base = recontext(sub_base, G, H);
auto tiles = tile(base, G, H);
@@ -140,17 +140,53 @@ Indices<1> cell<1>(
}
template<int N>
auto hull(
const tc::Group &G
) {
std::vector<Indices<N>> parts;
struct Hull {
struct Tiling {
Eigen::Index first;
Eigen::Index count;
};
for (auto H: G.subs(N - 1)) {
auto sub_base = cell<N>(H);
auto base = recontext(sub_base, G, H);
auto tiles = tile(base, G, H);
parts.push_back(merge(tiles));
std::vector<Tiling> tilings{};
std::vector<std::vector<size_t>> subgroups{};
Indices<N> inds{};
explicit Hull(tc::Group const &G) {
std::vector<Indices<N>> parts;
Eigen::Index first = 0;
for (const auto &H: G.subs(N - 1)) {
auto sub_base = cell<N>(H);
auto base = recontext(sub_base, G, H);
auto tiles = tile(base, G, H);
auto tiling = merge(tiles);
subgroups.push_back(H.gens());
tilings.push_back({first, tiling.cols()});
parts.push_back(tiling);
first += tiling.cols();
}
inds = merge(parts);
}
};
return parts;
}
struct Points {
Eigen::Array<float, 4, Eigen::Dynamic> verts;
explicit Points(tc::Group const &G, Eigen::Vector<float, 5> root) {
auto mirrors = mirror<5>(G);
auto corners = plane_intersections(mirrors);
auto start = corners * root;
tc::Cosets table = G.solve();
tc::Path<vec5> path(table, mirrors.colwise());
Eigen::Array<float, 5, Eigen::Dynamic> higher(5, path.order());
path.walk(start, Reflect(), higher.matrix().colwise().begin());
verts = Stereo()(higher);
}
};