diff --git a/include/blt/gfx/loader/obj_loader.h b/include/blt/gfx/loader/obj_loader.h index 222e5e0..048ce21 100644 --- a/include/blt/gfx/loader/obj_loader.h +++ b/include/blt/gfx/loader/obj_loader.h @@ -95,7 +95,8 @@ namespace blt::gfx std::vector normals; // maps between vertex indices -> face (constructed vertex) - HASHMAP vertex_data; + //HASHMAP vertex_data; + std::vector vertex_data; struct object_data { std::string object_name; diff --git a/libraries/BLT b/libraries/BLT index 8411810..9147a85 160000 --- a/libraries/BLT +++ b/libraries/BLT @@ -1 +1 @@ -Subproject commit 8411810ab5df8f330f9d7cf96a96179375dc4704 +Subproject commit 9147a85dc32f06be2a4cfe4e422fdbc52679adc5 diff --git a/src/blt/gfx/loader/obj_loader.cpp b/src/blt/gfx/loader/obj_loader.cpp index dd5e3fb..80b8d46 100644 --- a/src/blt/gfx/loader/obj_loader.cpp +++ b/src/blt/gfx/loader/obj_loader.cpp @@ -22,6 +22,8 @@ #include #include #include "blt/std/assert.h" +#include "blt/std/utility.h" +#include "blt/std/memory.h" namespace blt::gfx { @@ -55,9 +57,10 @@ namespace blt::gfx } }; - float get(std::string_view str) + template + T get(std::string_view str) { - float x; + T x; const auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), x); // probably not needed. if (ec != std::errc()) @@ -152,6 +155,20 @@ namespace blt::gfx void obj_loader::parse_face(char_tokenizer& tokenizer) { - + auto vertexes = blt::string::split(std::string(tokenizer.read_fully()), ' '); + if (vertexes.size() == 3) + { + for (const auto& v : vertexes) + { + auto indices = blt::string::split(v, '/'); + BLT_ASSERT(indices.size() == 3 && "Must have vertex, uv, and normal indices!!"); + vertex_data.push_back( + {vertices[get(indices[0])], uvs[get(indices[1])], normals[get(indices[2])]}); + } + } else if (vertexes.size() == 4) + { + BLT_WARN("Currently unable to process non-triangulated meshes!"); + } else + BLT_WARN("Unsupported vertex count! %d", vertexes.size()); } } \ No newline at end of file diff --git a/src/blt/gfx/model.cpp b/src/blt/gfx/model.cpp index c695b32..a5bc876 100644 --- a/src/blt/gfx/model.cpp +++ b/src/blt/gfx/model.cpp @@ -75,6 +75,7 @@ namespace blt::gfx return; glDeleteBuffers(1, &bufferID_); bufferID_ = 0; + BLT_DEBUG("Deleted VBO!"); } void vbo_t::allocate(GLsizeiptr size, GLint mem_type, const void* data) @@ -126,6 +127,7 @@ namespace blt::gfx // free all VBOs for (size_t i = 0; i < VBOs.used(); i++) VBOs[i] = nullptr; + element.destroy(); // then free the vertex array glDeleteVertexArrays(1, &vaoID); } diff --git a/src/blt/gfx/renderer/batch_2d_renderer.cpp b/src/blt/gfx/renderer/batch_2d_renderer.cpp index 9566043..e2791ba 100644 --- a/src/blt/gfx/renderer/batch_2d_renderer.cpp +++ b/src/blt/gfx/renderer/batch_2d_renderer.cpp @@ -46,8 +46,8 @@ namespace blt::gfx indices_vbo.allocate(sizeof(square_indices), square_indices); square_vao = new vertex_array(); - square_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); - square_vao->bindVBO(vertices_vbo, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); + auto tb = square_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); + square_vao->bindVBO(tb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float)); square_vao->bindElement(indices_vbo); shader = new shader_t(shader_2d_textured_vert, shader_2d_textured_frag);