From e85db91c6b6a326e3339020bc434063db6c957f9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Feb 2021 15:12:25 +0000 Subject: Fix test-obj by splitting mesh processing Don't invoke GL parts from test code --- gfx/models/obj.h | 3 +++ gfx/models/obj.impl.cpp | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'gfx/models') diff --git a/gfx/models/obj.h b/gfx/models/obj.h index 2921e34..71733fe 100644 --- a/gfx/models/obj.h +++ b/gfx/models/obj.h @@ -12,6 +12,7 @@ #include class Mesh; +class Vertex; class ObjParser : yyFlexLexer { public: @@ -38,6 +39,8 @@ public: std::vector objects; glm::length_t axis {0}; + using NamedMeshData = std::pair, std::vector>>; + [[nodiscard]] std::vector createMeshData() const; using NamedMesh = std::pair>; [[nodiscard]] std::vector createMeshes() const; }; diff --git a/gfx/models/obj.impl.cpp b/gfx/models/obj.impl.cpp index 0c1303a..5ac15ac 100644 --- a/gfx/models/obj.impl.cpp +++ b/gfx/models/obj.impl.cpp @@ -1,6 +1,6 @@ #include "obj.h" #include -#include +#include // IWYU pragma: keep #include #include #include @@ -12,8 +12,19 @@ std::vector ObjParser::createMeshes() const { std::vector out; + const auto data {createMeshData()}; + std::transform(data.begin(), data.end(), std::back_inserter(out), [](auto && obj) { + return std::make_pair(obj.first, std::make_shared(obj.second.first, obj.second.second)); + }); + return out; +} + +std::vector +ObjParser::createMeshData() const +{ + std::vector out; out.reserve(objects.size()); - for (const auto & obj : objects) { + std::transform(objects.begin(), objects.end(), std::back_inserter(out), [this](auto && obj) { std::vector overtices; std::vector vertexOrder; std::vector indices; @@ -36,7 +47,7 @@ ObjParser::createMeshes() const f(idx - 1); } } - out.emplace_back(obj.first, std::make_shared(overtices, indices)); - } + return std::make_pair(obj.first, std::make_pair(overtices, indices)); + }); return out; } -- cgit v1.2.3