From 424d00eaf7335e1c6427f40260d55782c3fd902c Mon Sep 17 00:00:00 2001 From: Mel Date: Fri, 30 Jun 2023 15:15:00 +0200 Subject: Avoid per-frame chunk copies and don't render block faces between chunks --- src/GFX/Binder.cpp | 8 ++++---- src/GFX/Binder.hpp | 6 +++--- src/GFX/Mesh.cpp | 4 ++-- src/GFX/Mesh.hpp | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/GFX') diff --git a/src/GFX/Binder.cpp b/src/GFX/Binder.cpp index 0dce06d..e8fc559 100644 --- a/src/GFX/Binder.cpp +++ b/src/GFX/Binder.cpp @@ -4,7 +4,7 @@ namespace MC::GFX { -BindableMesh Binder::load(Mesh mesh) { +BindableMesh Binder::load(const Mesh& mesh) { auto vao = create_vao(); if (!mesh.indices().empty()) { store_indices(mesh.indices().data(), mesh.indices().size()); @@ -30,14 +30,14 @@ uint32_t Binder::create_vao() { glGenVertexArrays(1, &vao); glBindVertexArray(vao); - return static_cast(vao); + return vao; } void Binder::unbind_vao() { glBindVertexArray(0); } -void Binder::store_indices(uint32_t* indices, size_t indices_size) { +void Binder::store_indices(const uint32_t* indices, size_t indices_size) { GLuint ebo; glGenBuffers(1, &ebo); @@ -46,7 +46,7 @@ void Binder::store_indices(uint32_t* indices, size_t indices_size) { } -void Binder::store_in_attribute_list(uint32_t attribute, int attribute_size, int type_size, void* data, long data_size) { +void Binder::store_in_attribute_list(uint32_t attribute, int attribute_size, int type_size, const void* data, long data_size) { assert(type_size == sizeof(float)); GLuint vbo; diff --git a/src/GFX/Binder.hpp b/src/GFX/Binder.hpp index d8a2be9..92faebe 100644 --- a/src/GFX/Binder.hpp +++ b/src/GFX/Binder.hpp @@ -35,14 +35,14 @@ class Binder { public: Binder() = default;; - static BindableMesh load(Mesh mesh); + static BindableMesh load(const Mesh& mesh); private: static uint32_t create_vao(); static void unbind_vao(); - static void store_in_attribute_list(uint32_t attribute, int attribute_size, int type_size, void* data, long data_size); - static void store_indices(uint32_t* indices, size_t indices_size); + static void store_in_attribute_list(uint32_t attribute, int attribute_size, int type_size, const void* data, long data_size); + static void store_indices(const uint32_t* indices, size_t indices_size); }; } \ No newline at end of file diff --git a/src/GFX/Mesh.cpp b/src/GFX/Mesh.cpp index b0271bb..1869622 100644 --- a/src/GFX/Mesh.cpp +++ b/src/GFX/Mesh.cpp @@ -2,11 +2,11 @@ namespace MC::GFX { -std::vector Mesh::indices() { +const std::vector& Mesh::indices() const { return m_indices; } -std::vector Mesh::attributes() { +const std::vector& Mesh::attributes() const { return m_attributes; } diff --git a/src/GFX/Mesh.hpp b/src/GFX/Mesh.hpp index bfe8eab..1d14ba2 100644 --- a/src/GFX/Mesh.hpp +++ b/src/GFX/Mesh.hpp @@ -49,8 +49,8 @@ public: ) : m_attributes(std::move(attributes)), m_indices() {}; - std::vector indices(); - std::vector attributes(); + const std::vector& indices() const; + const std::vector& attributes() const; private: std::vector m_attributes; -- cgit 1.4.1