Migrate to NanoGUI / Eigen for GUI and linear algebra.

Also introduce a GUI play/pause button.
This commit is contained in:
David Allemang
2020-10-10 22:59:51 -04:00
parent 5e3b4defd7
commit 916e9a8906
13 changed files with 640 additions and 331 deletions

View File

@@ -0,0 +1,75 @@
#pragma once
#include <functional>
#include <string>
#include <utility>
#include <nanogui/opengl.h>
#include <cgl/error.hpp>
#include <cgl/buffer.hpp>
namespace cgl {
class VertexArray {
GLuint id{};
public:
VertexArray() {
glCreateVertexArrays(1, &id);
}
VertexArray(VertexArray &) = delete;
VertexArray(VertexArray &&o) noexcept {
id = std::exchange(o.id, 0);
}
~VertexArray() {
glDeleteVertexArrays(1, &id);
id = 0;
}
operator GLuint() const {
return id;
}
void bound(const std::function<void()> &action) const {
glBindVertexArray(id);
action();
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);
});
});
}
};
}