Added VAO and some stuff
This commit is contained in:
parent
9ec4a11abf
commit
fe8d4b8e13
@ -2,6 +2,8 @@
|
||||
#ifndef _NB_CORE_TYPES
|
||||
#define _NB_CORE_TYPES
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace nb {
|
||||
|
||||
template<typename T>
|
||||
@ -16,6 +18,8 @@ T swapEndian(const T& val) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
using ByteVector = std::vector<uint8_t>;
|
||||
|
||||
} // namespace nb
|
||||
#endif // _NB_CORE_TYPES
|
||||
@ -10,6 +10,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "NBCore/Errors.hpp"
|
||||
#include "NBCore/Types.hpp"
|
||||
|
||||
namespace nb {
|
||||
|
||||
@ -101,6 +102,8 @@ public:
|
||||
template <typename ObjectType>
|
||||
class OpenGLObject {
|
||||
public:
|
||||
OpenGLObject(OpenGLObject&&) = default;
|
||||
OpenGLObject& operator=(OpenGLObject&&) = default;
|
||||
~OpenGLObject() { remove(); }
|
||||
|
||||
virtual void bind() const = 0;
|
||||
@ -110,27 +113,71 @@ public:
|
||||
|
||||
protected:
|
||||
OpenGLObject() = default;
|
||||
OpenGLObject(const OpenGLObject& rhs) = delete;
|
||||
OpenGLObject& operator=(const OpenGLObject& rhs) = delete;
|
||||
OpenGLObject(const OpenGLObject&) = delete;
|
||||
OpenGLObject& operator=(const OpenGLObject&) = delete;
|
||||
|
||||
virtual void remove() const = 0;
|
||||
|
||||
GLuint _id;
|
||||
};
|
||||
|
||||
template <typename BufferType>
|
||||
class Buffer : OpenGLObject<Buffer<BufferType>> {
|
||||
class VAO : public virtual OpenGLObject<VAO> {
|
||||
public:
|
||||
using Base = OpenGLObject<Buffer>;
|
||||
using Base = OpenGLObject<VAO>;
|
||||
using Base::Base;
|
||||
using BufferType::BufferType;
|
||||
using BufferType::GLTarget;
|
||||
|
||||
void bind() const { glBindBuffer(GLTarget, _id); }
|
||||
void unbind() const { glBindBuffer(GLTarget, 0); }
|
||||
|
||||
VAO() { glGenVertexArrays(1, &_id); }
|
||||
|
||||
void bind() const { glBindVertexArray(_id); }
|
||||
void unbind() const { glBindVertexArray(0); }
|
||||
|
||||
|
||||
protected:
|
||||
using Base::_id;
|
||||
const
|
||||
|
||||
void remove() { glDeleteVertexArrays(1, &_id); }
|
||||
|
||||
};
|
||||
|
||||
template <typename BufferType>
|
||||
class Buffer : public virtual OpenGLObject<Buffer<BufferType>> {
|
||||
public:
|
||||
using Base = OpenGLObject<Buffer>;
|
||||
using Base::Base;
|
||||
|
||||
Buffer(GLenum usage_ = GL_STATIC_DRAW) : usage(usage_) { glGenBuffers(1, &_id); }
|
||||
|
||||
void bind() const { glBindBuffer(GLTarget, _id); }
|
||||
void unbind() const { glBindBuffer(GLTarget, 0); }
|
||||
void data(void* data_, size_t size) const { glBufferData(GLTarget, size, data_, usage); }
|
||||
void data(nb::ByteVector& data_) const { glBufferData(GLTarget, data_.size(), data_.data(), usage); }
|
||||
void invalidate() const { glInvalidateBufferData(_id); }
|
||||
|
||||
|
||||
const GLenum GLTarget = BufferType::GLTarget;
|
||||
GLenum usage;
|
||||
|
||||
protected:
|
||||
using Base::_id;
|
||||
void remove() { glDeleteBuffers(1, &_id); }
|
||||
|
||||
};
|
||||
|
||||
class VertexBuffer : public virtual Buffer<VertexBuffer> {
|
||||
public:
|
||||
|
||||
static const GLenum GLTarget = GL_ARRAY_BUFFER;
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
class ElementBuffer : public virtual Buffer<ElementBuffer> {
|
||||
public:
|
||||
|
||||
static const GLenum GLTarget = GL_ELEMENT_ARRAY_BUFFER;
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user