diff options
| author | vimene <vincent.menegaux@gmail.com> | 2025-12-29 21:21:09 +0100 |
|---|---|---|
| committer | vimene <vincent.menegaux@gmail.com> | 2025-12-29 21:21:09 +0100 |
| commit | 8ab4780f134c33a9e11ac0fe0bd866e17d3ee650 (patch) | |
| tree | e59efd8a466312b790a2d68e679700b47e748c75 /src/o3d/mesh.cpp | |
| parent | dd187445972989dc44428e8cf185964da9e5c0c4 (diff) | |
| download | engine-8ab4780f134c33a9e11ac0fe0bd866e17d3ee650.tar.gz | |
starting to merge vulkan with the engine
- refactored scene_main to be able to share code between software and
hardware renderers, while still sharing code between terminal software
renderer and graphical software renderer
- made the hardware renderer use scene objects vertices and transforms,
instead of hardcoded ones
- made the hardware renderer use the scene's camera
- made .obj parser create Vector3 instead of Vector4, which didn't made
sense
- removed unnecessary std::
- lots of small changes
Diffstat (limited to 'src/o3d/mesh.cpp')
| -rw-r--r-- | src/o3d/mesh.cpp | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/o3d/mesh.cpp b/src/o3d/mesh.cpp index c1af5cd..ce6da30 100644 --- a/src/o3d/mesh.cpp +++ b/src/o3d/mesh.cpp @@ -1,8 +1,11 @@ #include "o3d/mesh.hpp" #include <vector> #include <array> +#include <cstdint> #include <cstddef> +#include <tuple> #include "math/vector.hpp" +#include "vulkan_utils.hpp" using namespace engine::o3d; @@ -11,20 +14,37 @@ Mesh Mesh::plane(float width, float height) { h2 = height / 2; return { { - {-w2 / 2, 0.f, -h2 / 2, 1.f}, - {+w2 / 2, 0.f, -h2 / 2, 1.f}, - {+w2 / 2, 0.f, +h2 / 2, 1.f}, - {-w2 / 2, 0.f, +h2 / 2, 1.f}, + { -w2 / 2, 0.f, -h2 / 2 }, + { +w2 / 2, 0.f, -h2 / 2 }, + { +w2 / 2, 0.f, +h2 / 2 }, + { -w2 / 2, 0.f, +h2 / 2 }, }, { - {0.f, -1.f, 0.f}, - {0.f, +1.f, 0.f}, + { 0.f, -1.f, 0.f }, + { 0.f, +1.f, 0.f }, }, { - {{ {{0, 0}}, {{1, 0}}, {{2, 0}} }}, - {{ {{2, 0}}, {{3, 0}}, {{0, 0}} }}, - {{ {{0, 1}}, {{3, 1}}, {{2, 1}} }}, - {{ {{2, 1}}, {{1, 1}}, {{0, 1}} }}, + {{ {{ 0, 0 }}, {{ 1, 0 }}, {{ 2, 0 }} }}, + {{ {{ 2, 0 }}, {{ 3, 0 }}, {{ 0, 0 }} }}, + {{ {{ 0, 1 }}, {{ 3, 1 }}, {{ 2, 1 }} }}, + {{ {{ 2, 1 }}, {{ 1, 1 }}, {{ 0, 1 }} }}, } }; } + +std::tuple<std::vector<engine::vk::Vertex>, std::vector<uint16_t>> Mesh::linearize_indices() const & { + std::vector<engine::vk::Vertex> linearized_vertices; + std::vector<uint16_t> linearized_indices; + + size_t n = 0; + for (const auto& triangle_indices : this->indices) { + for (const auto& vertex_indices : triangle_indices) { + linearized_vertices.emplace_back(this->vertices[vertex_indices[0]], this->normals[vertex_indices[1]]); + linearized_indices.emplace_back(n++); + } + } + + // TODO: I'm not sure if passing vectors like that makes a copy or not, because they are passed + // to a structured which is instantly returned. I think that copy-ellision catches that + return std::tuple { linearized_vertices, linearized_indices }; +} |
