Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SceneRenderer::Receive(const gfx::ModelSubmittedEvent & ModelSubmission)
- {
- std::unordered_map<gfx::VertexBuffer *, std::unordered_map<gfx::GraphicsPipeline *, std::unordered_map<gfx::Material *, std::vector<ecs::ID>>>> sort_map;
- StateChanges_.clear();
- Entities_.clear();
- RenderableIDs_.clear();
- auto manager = ECSManager::GetEntityManager();
- for (auto & ent : ECSManager::GetEntityManager()->GetEntitiesWithComponents<gfx::RenderableComponent>())
- {
- auto id = ent.GetID();
- auto & ent = manager->Get(id);
- size_t renderable_id = 0;
- for (auto renderable : ent.GetComponent<gfx::RenderableComponent>()->renderables)
- {
- RenderableIDs_.push_back(renderable_id++);
- auto modl = sort_map.find(renderable.GetModel()->Buffer);
- if (modl == sort_map.end())
- {
- std::unordered_map<gfx::GraphicsPipeline*, std::unordered_map<gfx::Material *, std::vector<ecs::ID>>> material_sort_map;
- std::unordered_map<gfx::Material *, std::vector<ecs::ID>> mats;
- std::vector<ecs::ID> ids = { id };
- mats.insert(std::make_pair(renderable.GetMaterial(), ids));
- material_sort_map.insert(std::make_pair(renderable.GetMaterial()->GetPipeline(), mats));
- sort_map.insert(std::make_pair(renderable.GetModel()->Buffer, material_sort_map));
- }
- else
- {
- auto pipe = modl->second.find(renderable.GetMaterial()->GetPipeline());
- if (pipe == modl->second.end())
- {
- std::unordered_map<gfx::Material *, std::vector<ecs::ID>> mats;
- std::vector<ecs::ID> ids = { id };
- mats.insert(std::make_pair(renderable.GetMaterial(), ids));
- }
- else
- {
- auto matl = pipe->second.find(renderable.GetMaterial());
- if (matl == pipe->second.end())
- {
- std::vector<ecs::ID> ids = { id };
- pipe->second.insert(std::make_pair(renderable.GetMaterial(), ids));
- }
- else
- {
- matl->second.push_back(id);
- }
- }
- }
- }
- }
- Entities_.clear();
- size_t counter = 0;
- for (auto model : sort_map)
- {
- if (counter == StateChanges_.size()) StateChanges_.push_back(MODL);
- for (auto pipeline : model.second)
- {
- if (counter == StateChanges_.size()) StateChanges_.push_back(PIPE);
- for (auto & material : pipeline.second)
- {
- if (counter == StateChanges_.size()) StateChanges_.push_back(MATL);
- for (auto & instance : material.second)
- {
- Entities_.push_back(std::move(instance));
- if (counter == StateChanges_.size()) StateChanges_.push_back(NONE);
- counter++;
- }
- }
- }
- }
- LUMINOS_ASSERT(Entities_.size() == StateChanges_.size())
- }
Add Comment
Please, Sign In to add comment