NBEngine/engine/NBGraphics/VAOManager.hpp
2026-03-17 01:47:05 -05:00

75 lines
2.2 KiB
C++

#pragma once
#ifndef _NB_VAO_MANAGER
#define _NB_VAO_MANAGER
#include <GLLoad.h>
#include <exception>
#include <memory>
#include <vector>
#include "Buffers.h"
#define THROW_VAO_ERROR(msg) throw VAOError(msg, __FILE__, __LINE__);
namespace NB {
class VAOError : public std::runtime_error {
public:
const bool error;
VAOError(const std::string& msg, const std::string& file="", int line=-1)
: std::runtime_error(NB::formatDebugString(msg, file, line)), error(true) {}
VAOError(bool isError=true) : std::runtime_error(""), error(isError) {}
};
class VAOManager : public OpenGLObject {
public:
typedef std::shared_ptr<Buffer> BufferManagerPointer;
//typedef BufferManager BufferManagerPointer;
VAOManager();
VAOManager(
std::vector<BufferManagerPointer>,
BufferManagerPointer elmt_buf = nullptr,
const VertexAttributeList& vert_attrs = {}
);
VAOManager(
BufferManagerPointer vert_bufs,
BufferManagerPointer elmt_buf = nullptr,
const VertexAttributeList& vert_attrs = {}
) : VAOManager(std::vector<BufferManagerPointer>(1, vert_bufs), elmt_buf, vert_attrs) {}
VAOManager(VAOManager&& rhs);
VAOManager& operator=(VAOManager&& rhs);
VertexAttributeList getLayout() const;
GLuint id() const;
unsigned int vertSize(GLuint) const;
std::vector<BufferManagerPointer> getVertexBuffers() const;
bool isInitialized() const override;
RawVec attributeData(unsigned int);
RawVec attributeData(unsigned int, const RawVec&);
void bind() const;
void unbind() const;
void addVBO(BufferManagerPointer);
void changeEBO(BufferManagerPointer);
VertexAttributeList addVertexAttributes(const VertexAttributeList&);
VertexAttributeList addVertexAttributes(VertexAttribute);
VertexAttributeList generate();
VertexAttributeList generate(VertexAttributeList);
VertexAttributeList changeLayout(unsigned int, VertexAttributePointer);
VAOError checkValid(const VertexAttributeList&);
private:
void remove() const override;
using OpenGLObject::_id;
std::map<GLuint, BufferManagerPointer> _vert_buffers;
BufferManagerPointer _elmt_buffer = nullptr;
VertexAttributeList _vert_attrs;
};
} // namespace NB
#endif // _NB_VAO_MANAGER