diff --git a/demo/main.cpp b/demo/main.cpp index 90a71da6b1f60f589672b1ba40361dc5836195e7..2a06613c70f451f62420472221c0599c164e7a58 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -226,8 +226,8 @@ public: // add mesh as a component constexpr char shader[] = "phong"; - fggl::gfx::StaticMesh staticMesh{mesh, shader}; - m_world->set<fggl::gfx::StaticMesh>(foundation, &staticMesh); + fggl::data::StaticMesh staticMesh{mesh, shader}; + m_world->set<fggl::data::StaticMesh>(foundation, &staticMesh); } // create building prototype @@ -259,8 +259,8 @@ public: } mesh.removeDups(); - fggl::gfx::StaticMesh staticMesh{mesh, shader}; - m_world->set<fggl::gfx::StaticMesh>(bunker, &staticMesh); + fggl::data::StaticMesh staticMesh{mesh, shader}; + m_world->set<fggl::data::StaticMesh>(bunker, &staticMesh); } for (int i=0; i<3; ++i) { diff --git a/fggl/gfx/ogl4/models.cpp b/fggl/gfx/ogl4/models.cpp index d6ff011fd6d3f8b06e422bbb07875bf8d8efa2f2..5e8e7629996db18773a21a77ac697a08c29a67b5 100644 --- a/fggl/gfx/ogl4/models.cpp +++ b/fggl/gfx/ogl4/models.cpp @@ -70,14 +70,14 @@ namespace fggl::gfx::ogl4 { void StaticModelRenderer::resolveModels(ecs3::World &world) { // FIXME: this needs something reactive or performance will suck. - auto renderables = world.findMatching<gfx::StaticMesh>(); + auto renderables = world.findMatching<data::StaticMesh>(); for (auto& renderable : renderables){ auto currModel = world.get<StaticModel>( renderable ); if ( currModel != nullptr ){ continue; } - auto* meshComp = world.get<gfx::StaticMesh>(renderable); + auto* meshComp = world.get<data::StaticMesh>(renderable); auto* modelComp = world.add<StaticModel>(renderable); setupComponent(modelComp, m_phong, meshComp->mesh); @@ -152,9 +152,10 @@ namespace fggl::gfx::ogl4 { auto shader = model->pipeline; if ( shader == nullptr ) { spdlog::warn("shader was null, aborting render"); - return; + continue; } + // setup shader uniforms shader->use(); shader->setUniformMtx(shader->uniform("model"), transform->model()); shader->setUniformMtx(shader->uniform("view"), viewMatrix); diff --git a/include/fggl/data/model.hpp b/include/fggl/data/model.hpp index f59db12079b6c0807ce29a919579ad8a48383010..6dfa2cf11fad34f4aaed285da12e37e97a12e3a3 100644 --- a/include/fggl/data/model.hpp +++ b/include/fggl/data/model.hpp @@ -3,6 +3,8 @@ #include <tuple> #include <vector> +#include <string> + #include <fggl/math/types.hpp> namespace fggl::data { @@ -127,6 +129,17 @@ namespace fggl::data { std::vector<unsigned int> m_index; }; + struct StaticMesh { + constexpr static const char name[] = "StaticMesh"; + data::Mesh mesh; + std::string pipeline; + + inline StaticMesh() : mesh(), pipeline() {} + + inline StaticMesh(const data::Mesh &aMesh, std::string aPipeline) : + mesh(aMesh), pipeline(std::move(aPipeline)) {} + }; + class Model { public: Model() = default; diff --git a/include/fggl/gfx/common.hpp b/include/fggl/gfx/common.hpp index 82845e227cf888ffe6ea3ea682860ebc509cead8..302a195589a6174d9239bd6e2b91d2fa6abf5a69 100644 --- a/include/fggl/gfx/common.hpp +++ b/include/fggl/gfx/common.hpp @@ -13,16 +13,6 @@ namespace fggl::gfx { - struct StaticMesh { - constexpr static const char name[] = "StaticMesh"; - data::Mesh mesh; - std::string pipeline; - - inline StaticMesh() : mesh(), pipeline() {} - - inline StaticMesh(const data::Mesh &aMesh, std::string aPipeline) : - mesh(aMesh), pipeline(std::move(aPipeline)) {} - }; } diff --git a/include/fggl/gfx/ogl/compat.hpp b/include/fggl/gfx/ogl/compat.hpp index 8592b40fd868cdc3eef94ed31ed1fba98bdfb543..c68c7f2f9ab648e0fbc32aa7fdd7c79ed20afe17 100644 --- a/include/fggl/gfx/ogl/compat.hpp +++ b/include/fggl/gfx/ogl/compat.hpp @@ -42,7 +42,7 @@ namespace fggl::gfx { } void uploadMesh(ecs3::World *world, ecs::entity_t entity) { - auto *meshData = world->get<gfx::StaticMesh>(entity); + auto *meshData = world->get<data::StaticMesh>(entity); auto pipeline = cache.get(meshData->pipeline); auto glMesh = renderer.upload(meshData->mesh); @@ -65,21 +65,24 @@ namespace fggl::gfx { } void onLoad(ecs3::ModuleManager &manager, ecs3::TypeRegistry &types) override { - // TODO implement dependencies - types.make<fggl::gfx::StaticMesh>(); - types.make<fggl::data::HeightMap>(); - types.make<fggl::gfx::Camera>(); + // mesh dependencies + types.make<data::StaticMesh>(); + types.make<data::HeightMap>(); - // FIXME probably shouldn't be doing this... + // camera dependencies + types.make<fggl::gfx::Camera>(); types.make<fggl::input::FreeCamKeys>(); - // opengl - types.make<fggl::gfx::GlRenderToken>(); + /* + * old API stuff - not used + // opengl + types.make<fggl::gfx::GlRenderToken>(); - // callbacks - auto upload_cb = [this](auto a, auto b) { this->uploadMesh(a, b); }; - manager.onAdd<fggl::gfx::StaticMesh>(upload_cb); - manager.onAdd<fggl::data::HeightMap>([this](auto a, auto b) { this->uploadHeightmap(a, b); }); + // callbacks + auto upload_cb = [this](auto a, auto b) { this->uploadMesh(a, b); }; + manager.onAdd<fggl::gfx::StaticMesh>(upload_cb); + manager.onAdd<fggl::data::HeightMap>([this](auto a, auto b) { this->uploadHeightmap(a, b); }); + */ } };