From 5a08c9c8e230fd952311f29bc02b22c7635d0178 Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Mon, 26 Sep 2022 20:57:53 -0400 Subject: vertex buffer is not a byte vector, multi texture loading --- engine/xe_model.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'engine/xe_model.cpp') diff --git a/engine/xe_model.cpp b/engine/xe_model.cpp index 6720c13..fd97f44 100644 --- a/engine/xe_model.cpp +++ b/engine/xe_model.cpp @@ -14,7 +14,7 @@ namespace xe { Model::Model(Device &device, const Model::Builder &builder) : xeDevice{device} { - createVertexBuffers(builder.vertexData, builder.vertexSize); + createVertexBuffers(builder.vertexData.data, builder.vertexSize); createIndexBuffers(builder.indices); } @@ -26,10 +26,10 @@ std::unique_ptr Model::createModelFromFile(Device &device, const std::str return std::make_unique(device, builder); } -void Model::createVertexBuffers(const std::vector &vertexData, uint32_t vertexSize) { - vertexCount = static_cast(vertexData.size()) / (vertexSize / 4); +void Model::createVertexBuffers(const std::vector &vertexData, uint32_t vertexSize) { + vertexCount = static_cast(vertexData.size()) / vertexSize; assert(vertexCount >= 3 && "Vertex count must be atleast 3"); - VkDeviceSize bufferSize = vertexData.size() * 4; + VkDeviceSize bufferSize = vertexData.size(); Buffer stagingBuffer { xeDevice, @@ -113,7 +113,7 @@ void Model::Builder::loadModel(const std::string &filepath) { throw std::runtime_error(warn + err); } - vertexData.clear(); + vertexData.data.clear(); indices.clear(); vertexSize = 0; @@ -123,22 +123,22 @@ void Model::Builder::loadModel(const std::string &filepath) { for (const auto &index : shape.mesh.indices) { if(index.vertex_index >= 0) { - vertexData.push_back(attrib.vertices[3 * index.vertex_index + 0]); - vertexData.push_back(attrib.vertices[3 * index.vertex_index + 1]); - vertexData.push_back(attrib.vertices[3 * index.vertex_index + 2]); + vertexData.write(attrib.vertices[3 * index.vertex_index + 0]); + vertexData.write(attrib.vertices[3 * index.vertex_index + 1]); + vertexData.write(attrib.vertices[3 * index.vertex_index + 2]); vertex = true; } if(index.normal_index >= 0) { - vertexData.push_back(attrib.normals[3 * index.normal_index + 0]); - vertexData.push_back(attrib.normals[3 * index.normal_index + 1]); - vertexData.push_back(attrib.normals[3 * index.normal_index + 2]); + vertexData.write(attrib.normals[3 * index.normal_index + 0]); + vertexData.write(attrib.normals[3 * index.normal_index + 1]); + vertexData.write(attrib.normals[3 * index.normal_index + 2]); normal = true; } if(index.texcoord_index >= 0) { - vertexData.push_back(attrib.texcoords[2 * index.texcoord_index + 0]); - vertexData.push_back(attrib.texcoords[2 * index.texcoord_index + 1]); + vertexData.write(attrib.texcoords[2 * index.texcoord_index + 0]); + vertexData.write(attrib.texcoords[2 * index.texcoord_index + 1]); uvs = true; } -- cgit v1.2.3-freya