Skip to content
Snippets Groups Projects
Commit 7c701103 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

move static mesh into data rather than opengl graphics

parent 02f30c6c
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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);
......
......@@ -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;
......
......@@ -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)) {}
};
}
......
......@@ -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); });
*/
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment