diff options
| author | Mel <einebeere@gmail.com> | 2022-10-21 01:03:18 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-21 01:03:18 +0200 |
| commit | 6ed978051668c08f5a957c97570f364dd580c807 (patch) | |
| tree | e3db93c52fcd86e26bc859d46e755290d2a7f40c /src/Binder.cpp | |
| parent | 0464a83dfaebaa75d6e2d3b7431e84ebd83fccfd (diff) | |
| download | meowcraft-6ed978051668c08f5a957c97570f364dd580c807.tar.zst meowcraft-6ed978051668c08f5a957c97570f364dd580c807.zip | |
Namespace and Folder refactor
Diffstat (limited to 'src/Binder.cpp')
| -rw-r--r-- | src/Binder.cpp | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/src/Binder.cpp b/src/Binder.cpp deleted file mode 100644 index d013f08..0000000 --- a/src/Binder.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include <GL/glew.h> -#include "Binder.hpp" -#include "Mesh.hpp" - -namespace MC { - -BindableMesh Binder::load(Mesh& mesh) { - auto vao = create_vao(); - if (mesh.indices_size() > 0) { - store_indices(mesh.raw_indices(), mesh.indices_size()); - } - store_in_attribute_list(0, 3, mesh.raw(), mesh.size() * 3); - store_in_attribute_list(1, 2, mesh.raw_tex_coords(), mesh.tex_coords_size() * 2); - unbind_vao(); - - return {vao, mesh.indices_size()}; -} - -uint32_t Binder::create_vao() { - GLuint vao; - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - - return static_cast<uint32_t>(vao); -} - -uint32_t Binder::unbind_vao() { - glBindVertexArray(0); -} - -void Binder::store_indices(uint32_t* indices, size_t indices_size) { - GLuint ebo; - glGenBuffers(1, &ebo); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_size * sizeof(float), indices, GL_STATIC_DRAW); -} - -void Binder::store_in_attribute_list(uint32_t attribute, size_t size, float* data, size_t data_size) { - GLuint vbo; - glGenBuffers(1, &vbo); - - glBindBuffer(GL_ARRAY_BUFFER, vbo); - glBufferData(GL_ARRAY_BUFFER, data_size * sizeof(float), data, GL_STATIC_DRAW); - glVertexAttribPointer(attribute, size, GL_FLOAT, GL_FALSE, size * sizeof(float), nullptr); - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - -void BindableMesh::bind() const { - glBindVertexArray(m_vao); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); -} - -void BindableMesh::unbind() { - glBindVertexArray(0); - glDisableVertexAttribArray(0); - glDisableVertexAttribArray(1); -} - -size_t BindableMesh::size() const { - return m_vertex_count; -} - -} \ No newline at end of file |
