fix double vbo free, didn't seem to cause issues though. also now freeing the element buffer

main
Brett 2024-01-09 13:56:51 -05:00
parent c078081022
commit 7836c7f022
5 changed files with 27 additions and 7 deletions

View File

@ -95,7 +95,8 @@ namespace blt::gfx
std::vector<normal_t> normals;
// maps between vertex indices -> face (constructed vertex)
HASHMAP<std::int32_t, constructed_vertex_t> vertex_data;
//HASHMAP<std::int32_t, constructed_vertex_t> vertex_data;
std::vector<constructed_vertex_t> vertex_data;
struct object_data
{
std::string object_name;

@ -1 +1 @@
Subproject commit 8411810ab5df8f330f9d7cf96a96179375dc4704
Subproject commit 9147a85dc32f06be2a4cfe4e422fdbc52679adc5

View File

@ -22,6 +22,8 @@
#include <cctype>
#include <charconv>
#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<typename T = float>
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<std::int32_t>(indices[0])], uvs[get<std::int32_t>(indices[1])], normals[get<std::int32_t>(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());
}
}

View File

@ -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);
}

View File

@ -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);