From b770baa78dd580b8c71fd04ee24d558d1653f309 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Fri, 29 Dec 2023 12:35:48 -0500 Subject: [PATCH] reorder cpp file --- include/blt/gfx/shader.h | 5 --- src/blt/gfx/shader.cpp | 96 ++++++++++++++++++++-------------------- 2 files changed, 48 insertions(+), 53 deletions(-) diff --git a/include/blt/gfx/shader.h b/include/blt/gfx/shader.h index 07baf03..7907918 100644 --- a/include/blt/gfx/shader.h +++ b/include/blt/gfx/shader.h @@ -82,11 +82,6 @@ namespace blt::gfx { return i != -1; } - - inline operator int() const - { - return i; - } }; std::unordered_map uniformVars; diff --git a/src/blt/gfx/shader.cpp b/src/blt/gfx/shader.cpp index adb23fc..ce7e36a 100644 --- a/src/blt/gfx/shader.cpp +++ b/src/blt/gfx/shader.cpp @@ -22,6 +22,54 @@ namespace blt::gfx { + uniform_buffer::uniform_buffer(size_t size, GLuint location): size_(size), location_(location) + { + glGenBuffers(1, &uboID); + bind(); + glBufferData(GL_UNIFORM_BUFFER, static_cast(size), nullptr, GL_DYNAMIC_READ); + unbind(); + + glBindBufferBase(GL_UNIFORM_BUFFER, location, uboID); + } + + uniform_buffer::uniform_buffer(void* data, size_t size, GLuint location): size_(size), location_(location) + { + glGenBuffers(1, &uboID); + bind(); + glBufferData(GL_UNIFORM_BUFFER, static_cast(size), data, GL_DYNAMIC_READ); + unbind(); + + glBindBufferBase(GL_UNIFORM_BUFFER, location, uboID); + } + + uniform_buffer& uniform_buffer::resize(size_t newSize) + { + bind(); + size_ = newSize; + glBufferData(GL_UNIFORM_BUFFER, static_cast(size_), nullptr, GL_DYNAMIC_READ); + unbind(); + return *this; + } + + uniform_buffer& uniform_buffer::upload(void* data, size_t size, size_t offset) + { + bind(); + glBufferSubData(GL_UNIFORM_BUFFER, static_cast(offset), static_cast(size), data); + unbind(); + return *this; + } + + uniform_buffer& uniform_buffer::bind() + { + glBindBuffer(GL_UNIFORM_BUFFER, uboID); + return *this; + } + + uniform_buffer::~uniform_buffer() + { + glDeleteBuffers(1, &uboID); + } + static std::string removeEmptyFirstLines(const std::string& string) { auto lines = blt::string::split(string, "\n"); @@ -173,54 +221,6 @@ namespace blt::gfx move.programID = -1; } - uniform_buffer::uniform_buffer(size_t size, GLuint location): size_(size), location_(location) - { - glGenBuffers(1, &uboID); - bind(); - glBufferData(GL_UNIFORM_BUFFER, static_cast(size), nullptr, GL_DYNAMIC_READ); - unbind(); - - glBindBufferBase(GL_UNIFORM_BUFFER, location, uboID); - } - - uniform_buffer::uniform_buffer(void* data, size_t size, GLuint location): size_(size), location_(location) - { - glGenBuffers(1, &uboID); - bind(); - glBufferData(GL_UNIFORM_BUFFER, static_cast(size), data, GL_DYNAMIC_READ); - unbind(); - - glBindBufferBase(GL_UNIFORM_BUFFER, location, uboID); - } - - uniform_buffer& uniform_buffer::resize(size_t newSize) - { - bind(); - size_ = newSize; - glBufferData(GL_UNIFORM_BUFFER, static_cast(size_), nullptr, GL_DYNAMIC_READ); - unbind(); - return *this; - } - - uniform_buffer& uniform_buffer::upload(void* data, size_t size, size_t offset) - { - bind(); - glBufferSubData(GL_UNIFORM_BUFFER, static_cast(offset), static_cast(size), data); - unbind(); - return *this; - } - - uniform_buffer& uniform_buffer::bind() - { - glBindBuffer(GL_UNIFORM_BUFFER, uboID); - return *this; - } - - uniform_buffer::~uniform_buffer() - { - glDeleteBuffers(1, &uboID); - } - shader_base_t& shader_base_t::setBool(const std::string& name, bool value) { if (auto i = getUniformLocation(name))