break render apart into multiple files

This commit is contained in:
2020-03-10 14:11:13 -04:00
parent b504e5b7c3
commit d29fc033df
10 changed files with 452 additions and 487 deletions

View File

@@ -0,0 +1,75 @@
#pragma once
#include <functional>
#include <string>
#include <utility>
#include <glad/glad.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);
});
});
}
};
}