fix double vbo free, didn't seem to cause issues though. also now freeing the element buffer
parent
c078081022
commit
7836c7f022
|
@ -95,7 +95,8 @@ namespace blt::gfx
|
||||||
std::vector<normal_t> normals;
|
std::vector<normal_t> normals;
|
||||||
|
|
||||||
// maps between vertex indices -> face (constructed vertex)
|
// 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
|
struct object_data
|
||||||
{
|
{
|
||||||
std::string object_name;
|
std::string object_name;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8411810ab5df8f330f9d7cf96a96179375dc4704
|
Subproject commit 9147a85dc32f06be2a4cfe4e422fdbc52679adc5
|
|
@ -22,6 +22,8 @@
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include "blt/std/assert.h"
|
#include "blt/std/assert.h"
|
||||||
|
#include "blt/std/utility.h"
|
||||||
|
#include "blt/std/memory.h"
|
||||||
|
|
||||||
namespace blt::gfx
|
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);
|
const auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), x);
|
||||||
// probably not needed.
|
// probably not needed.
|
||||||
if (ec != std::errc())
|
if (ec != std::errc())
|
||||||
|
@ -152,6 +155,20 @@ namespace blt::gfx
|
||||||
|
|
||||||
void obj_loader::parse_face(char_tokenizer& tokenizer)
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -75,6 +75,7 @@ namespace blt::gfx
|
||||||
return;
|
return;
|
||||||
glDeleteBuffers(1, &bufferID_);
|
glDeleteBuffers(1, &bufferID_);
|
||||||
bufferID_ = 0;
|
bufferID_ = 0;
|
||||||
|
BLT_DEBUG("Deleted VBO!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void vbo_t::allocate(GLsizeiptr size, GLint mem_type, const void* data)
|
void vbo_t::allocate(GLsizeiptr size, GLint mem_type, const void* data)
|
||||||
|
@ -126,6 +127,7 @@ namespace blt::gfx
|
||||||
// free all VBOs
|
// free all VBOs
|
||||||
for (size_t i = 0; i < VBOs.used(); i++)
|
for (size_t i = 0; i < VBOs.used(); i++)
|
||||||
VBOs[i] = nullptr;
|
VBOs[i] = nullptr;
|
||||||
|
element.destroy();
|
||||||
// then free the vertex array
|
// then free the vertex array
|
||||||
glDeleteVertexArrays(1, &vaoID);
|
glDeleteVertexArrays(1, &vaoID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ namespace blt::gfx
|
||||||
indices_vbo.allocate(sizeof(square_indices), square_indices);
|
indices_vbo.allocate(sizeof(square_indices), square_indices);
|
||||||
|
|
||||||
square_vao = new vertex_array();
|
square_vao = new vertex_array();
|
||||||
square_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0);
|
auto tb = 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));
|
square_vao->bindVBO(tb, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float));
|
||||||
square_vao->bindElement(indices_vbo);
|
square_vao->bindElement(indices_vbo);
|
||||||
|
|
||||||
shader = new shader_t(shader_2d_textured_vert, shader_2d_textured_frag);
|
shader = new shader_t(shader_2d_textured_vert, shader_2d_textured_frag);
|
||||||
|
|
Loading…
Reference in New Issue