ENH: Use entt

This commit is contained in:
David Allemang
2023-02-04 21:20:53 -05:00
parent 65e4960f09
commit e792e93eb9
5 changed files with 145 additions and 174 deletions

View File

@@ -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);
}
};
}

View File

@@ -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);
}
};
}

View File

@@ -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));
}
};
}