move cgl to separate repo

This commit is contained in:
2020-06-28 12:40:12 -04:00
parent 465f863687
commit ea3b7a0691
13 changed files with 2 additions and 8440 deletions

View File

@@ -1,67 +0,0 @@
#pragma once
#include <memory>
#include <glad/glad.h>
namespace cgl {
template<class T>
class Buffer {
GLuint id{};
public:
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(const Buffer &) = delete;
Buffer(Buffer &&o) noexcept {
id = std::exchange(o.id, 0);
};
~Buffer() {
glDeleteBuffers(1, &id);
id = 0;
}
operator GLuint() const {
return id;
}
[[nodiscard]] size_t size() const {
GLint res;
glGetNamedBufferParameteriv(id, GL_BUFFER_SIZE, &res);
return (size_t) res;
}
[[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);
}
void put(const std::vector<T> &data, GLenum usage = GL_STATIC_DRAW) {
glNamedBufferData(id, sizeof(T) * data.size(), &data[0], usage);
}
void bound(GLenum target, const std::function<void()> &action) const {
glBindBuffer(target, id);
action();
glBindBuffer(target, 0);
}
};
}