mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
ENH: Use entt
This commit is contained in:
@@ -10,20 +10,12 @@ namespace cgl {
|
||||
GLuint id{};
|
||||
|
||||
public:
|
||||
using Element = T;
|
||||
|
||||
Buffer() {
|
||||
glCreateBuffers(1, &id);
|
||||
}
|
||||
|
||||
Buffer(const T &data, GLenum usage = GL_STATIC_DRAW)
|
||||
: Buffer() {
|
||||
put(data, usage);
|
||||
}
|
||||
|
||||
Buffer(const std::vector<T> &data, GLenum usage = GL_STATIC_DRAW)
|
||||
: Buffer() {
|
||||
put(data, usage);
|
||||
}
|
||||
|
||||
Buffer(Buffer &) = delete;
|
||||
|
||||
Buffer(Buffer &&o) noexcept {
|
||||
@@ -60,12 +52,5 @@ namespace cgl {
|
||||
std::copy(begin, end, (T*) ptr);
|
||||
glUnmapNamedBuffer(id);
|
||||
}
|
||||
|
||||
void bound(GLenum target, const std::function<void()> &action) const {
|
||||
glBindBuffer(target, id);
|
||||
action();
|
||||
glBindBuffer(target, 0);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -83,11 +83,5 @@ namespace cgl {
|
||||
glUseProgramStages(id, GL_COMPUTE_SHADER_BIT, pgm);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void bound(const std::function<void()> &action) const {
|
||||
glBindProgramPipeline(id);
|
||||
action();
|
||||
glBindProgramPipeline(0);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -33,43 +33,34 @@ namespace cgl {
|
||||
return id;
|
||||
}
|
||||
|
||||
void bound(const std::function<void()> &action) const {
|
||||
glBindVertexArray(id);
|
||||
action();
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void pointer(
|
||||
void format(
|
||||
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);
|
||||
});
|
||||
});
|
||||
) {
|
||||
glEnableVertexArrayAttrib(id, index);
|
||||
glVertexArrayAttribFormat(id, index, size, type, normalized, stride);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void ipointer(
|
||||
void iformat(
|
||||
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);
|
||||
});
|
||||
});
|
||||
) {
|
||||
glEnableVertexArrayAttrib(id, index);
|
||||
glVertexArrayAttribIFormat(id, index, size, type, stride);
|
||||
}
|
||||
|
||||
template<class Buf>
|
||||
void vertexBuffer(
|
||||
GLuint index,
|
||||
Buf &buf,
|
||||
unsigned offset = 0
|
||||
) {
|
||||
glVertexArrayVertexBuffer(id, index, buf, offset, sizeof(typename Buf::Element));
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user