Huge graphics overhaul

This commit is contained in:
NaifBanana
2026-08-20 08:14:29 -05:00
parent 960689ecb6
commit 3bad580793
19 changed files with 1534 additions and 252 deletions
+73 -12
View File
@@ -67,7 +67,7 @@ class VAOError : public Error<VAOError> {
using Base::Base;
enum Codes : unsigned int {
UNDEFINED, INVALID_ATTRIBUTE, INVALID_VAO
UNDEFINED, INVALID_ATTRIBUTE
};
static const std::string type;
@@ -90,7 +90,10 @@ class VAO : public OpenGLObject {
if(_id) {
glBindVertexArray(_id);
} else {
THROW(VAOError(Codes::INVALID_VAO));
THROW(OGLError(
OGLError::Codes::INVALID_OBJECT,
"w/ VertexArrayObject"
));
}
}
virtual void unbind() const override { glBindVertexArray(0); }
@@ -119,14 +122,29 @@ class VAO : public OpenGLObject {
if (!_id) {
glGenVertexArrays(1, &_id);
}
bind();
return _id;
}
};
using VBO = ArrayBuffer<false>;
class VertexError : public Error<VertexError> {
protected:
using Base = Error<VertexError>;
public:
using Base::Base;
enum Codes : unsigned int {
UNDEFINED, MISALIGNED_DATA
};
static const std::string type;
static const ErrorCodeMap ErrorMessages;
};
using VBO = ArrayBuffer;
using VertBufVec = SharedVector<VBO>;
using EBO = ElementBuffer<false>;
using EBO = ElementBuffer;
struct VertexData {
std::shared_ptr<VBO> vbo;
@@ -136,27 +154,70 @@ struct VertexData {
using VertexDataVec = std::vector<VertexData>;
class VertexGroup {
protected:
using Codes = VertexError::Codes;
VertexDataVec _vertex_data;
std::shared_ptr<EBO> _ebo;
std::shared_ptr<VAO> _vao;
GLenum _primitive;
public:
GLenum primitive=GL_TRIANGLES;
VertexGroup(VertexGroup&&);
VertexGroup& operator=(VertexGroup&&);
VertexGroup(const VertexData&);
VertexGroup(const VertexDataVec&);
VertexGroup(const ByteVector&, const VertexAttributeList&);
VertexGroup(
const VertexDataVec& vertex_data,
const std::shared_ptr<EBO>& ebo
)
: _vao(std::make_shared<VAO>()), _ebo(ebo) {
setBuffers(vertex_data);
}
template<typename... T>
VertexGroup(
const VertexDataVec& vertex_data,
T... args
)
: VertexGroup(vertex_data, std::make_shared<EBO>(args...)) {
setBuffers(vertex_data);
}
template<typename... T>
VertexGroup(
const VertexData& vertex_data,
T... args
)
: VertexGroup(VertexDataVec{vertex_data}, args...) {}
template<typename... T>
VertexGroup(
const ByteVector& vertex_data,
const VertexAttributeList& vertex_specification,
T... args
) : VertexGroup({
std::make_shared<VBO>(vertex_data),
vertex_specification},
args...
) {}
void bind() const {
_ebo->bind();
_vao->bind();
_ebo->bind();
}
void unbind() const {
_vao->unbind();
_ebo->unbind();
}
void draw() const;
VertexDataVec getBuffers();
VertexData getBuffers(size_t);
size_t setBuffers(const VertexDataVec&);
size_t addBuffer(const VertexData&);
size_t addBuffer(const ByteVector& data, const VertexAttributeList& attrs);
VertexDataVec dropBuffers();
VertexData dropBuffer(size_t);
VertexAttributePointer attribute(size_t) const;
@@ -167,10 +228,10 @@ class VertexGroup {
void enable();
void disable();
protected:
VertexDataVec _vertex_data;
std::shared_ptr<EBO> _ebo;
std::shared_ptr<VAO> _vao;
std::shared_ptr<EBO> indices() const;
std::shared_ptr<EBO> indices(const std::vector<unsigned int>& data);
std::shared_ptr<EBO> indices(std::shared_ptr<EBO> buffer);
};
} // namespace nb