Fix index buffer
This commit is contained in:
parent
43fd780e0b
commit
56fb496ec7
@ -86,6 +86,9 @@ namespace Global {
|
||||
attributeDescriptions[2].offset = offsetof(Vertex, texCoord);
|
||||
return attributeDescriptions;
|
||||
}
|
||||
bool operator==(const Vertex& other) const {
|
||||
return pos == other.pos && color == other.color && texCoord == other.texCoord;
|
||||
}
|
||||
};
|
||||
|
||||
const uint32_t WIDTH = 800;
|
||||
|
@ -208,10 +208,10 @@ namespace BuffersLibraries {
|
||||
Global::UniformBufferObject ubo{};
|
||||
ubo.time = time;
|
||||
// Modify the model projection transformation to rotate around the Z over time.
|
||||
ubo.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(20.0f), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
ubo.model = glm::rotate(glm::mat4(1.0f), glm::radians(180.0f), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
// Modify the view transformation to look at the object from above at a 45 degree angle.
|
||||
// This takes the eye position, center position, and the up direction.
|
||||
ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
ubo.view = glm::lookAt(glm::vec3(4.0f, 4.0f, 3.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
// 45 degree field of view, set aspect ratio, and near and far clipping range.
|
||||
ubo.proj = glm::perspective(glm::radians(45.0f), deviceLibrary.getSwapChainExtent().width / (float) deviceLibrary.getSwapChainExtent().height, 0.1f, 10.0f);
|
||||
|
||||
|
@ -1,11 +1,23 @@
|
||||
#include "buffers.h"
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#define TINY_OBJ_IMPLEMENTATION
|
||||
#include <tiny_obj_loader.h>
|
||||
#include "model.h"
|
||||
#include <unordered_map>
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/hash.hpp>
|
||||
|
||||
namespace std {
|
||||
template<> struct hash<Global::Vertex> {
|
||||
size_t operator()(Global::Vertex const& vertex) const {
|
||||
return ((hash<glm::vec3>()(vertex.pos) ^
|
||||
(hash<glm::vec3>()(vertex.color) << 1)) >> 1) ^
|
||||
(hash<glm::vec2>()(vertex.texCoord) << 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace ModelLib {
|
||||
BuffersLibraries::buffers buf;
|
||||
|
||||
std::unordered_map<Global::Vertex, uint32_t> uniqueVertices{};
|
||||
|
||||
void model::loadModel() {
|
||||
tinyobj::ObjReaderConfig readerConfig;
|
||||
@ -24,7 +36,7 @@ namespace ModelLib {
|
||||
|
||||
for (const auto& shape : shapes) {
|
||||
for (const auto& index : shape.mesh.indices) {
|
||||
Global::Vertex vertex;
|
||||
Global::Vertex vertex{};
|
||||
|
||||
vertex.pos = {
|
||||
attrib.vertices[3 * index.vertex_index + 0],
|
||||
@ -39,9 +51,13 @@ namespace ModelLib {
|
||||
|
||||
vertex.color = {1.0f, 1.0f, 1.0f};
|
||||
|
||||
Global::vertices.push_back(vertex);
|
||||
Global::indices.push_back(Global::indices.size());
|
||||
}
|
||||
if (uniqueVertices.count(vertex) == 0) {
|
||||
uniqueVertices[vertex] = static_cast<uint32_t>(Global::vertices.size());
|
||||
Global::vertices.push_back(vertex);
|
||||
}
|
||||
|
||||
Global::indices.push_back(uniqueVertices[vertex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user