90d013695d
- Replace window class with cbt::opengl::context - Add buffer resource (VBO, EBO, UBO, SSBO) with move semantics - Add texture resource with format/type enums and filtering - Add descriptor_set for Vulkan-style resource binding - All resources use RAII with proper cleanup
73 lines
1.4 KiB
C++
73 lines
1.4 KiB
C++
#include "cbt/opengl/buffer.hpp"
|
|
|
|
#include "glad/glad.h"
|
|
|
|
namespace cbt::opengl {
|
|
|
|
buffer::buffer() {
|
|
glGenBuffers(1, &m_id);
|
|
}
|
|
|
|
buffer::buffer(buffer_type type)
|
|
: m_type(type) {
|
|
glGenBuffers(1, &m_id);
|
|
}
|
|
|
|
buffer::~buffer() {
|
|
if (m_id) {
|
|
glDeleteBuffers(1, &m_id);
|
|
}
|
|
}
|
|
|
|
buffer::buffer(buffer&& other) noexcept
|
|
: m_id(other.m_id)
|
|
, m_type(other.m_type) {
|
|
other.m_id = 0;
|
|
}
|
|
|
|
buffer& buffer::operator=(buffer&& other) noexcept {
|
|
if (this != &other) {
|
|
if (m_id) {
|
|
glDeleteBuffers(1, &m_id);
|
|
}
|
|
m_id = other.m_id;
|
|
m_type = other.m_type;
|
|
other.m_id = 0;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
auto buffer::bind() const -> void {
|
|
glBindBuffer(static_cast<GLenum>(m_type), m_id);
|
|
}
|
|
|
|
auto buffer::unbind() const -> void {
|
|
glBindBuffer(static_cast<GLenum>(m_type), 0);
|
|
}
|
|
|
|
auto buffer::upload(const void* data, size_t size) -> void {
|
|
bind();
|
|
glBufferData(static_cast<GLenum>(m_type), size, data, GL_STATIC_DRAW);
|
|
unbind();
|
|
}
|
|
|
|
auto buffer::upload(std::vector<uint8_t> data) -> void {
|
|
upload(data.data(), data.size());
|
|
}
|
|
|
|
auto buffer::upload_dynamic(const void* data, size_t size) -> void {
|
|
bind();
|
|
glBufferData(static_cast<GLenum>(m_type), size, data, GL_DYNAMIC_DRAW);
|
|
unbind();
|
|
}
|
|
|
|
auto buffer::id() const -> GLuint {
|
|
return m_id;
|
|
}
|
|
|
|
auto buffer::valid() const -> bool {
|
|
return m_id != 0;
|
|
}
|
|
|
|
}
|