Added RenderSystem and removed RenderQueueFactory

This commit is contained in:
viktorljung
2015-12-14 20:07:02 +01:00
parent ef07a9d536
commit d9ea0192d1
6 changed files with 51 additions and 57 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
#include "../Core/ConfigFile.h" #include "../Core/ConfigFile.h"
#include "../Input/EInputCommand.h" #include "../Input/EInputCommand.h"
#include "../Rendering/EPicking.h" #include "../Rendering/EPicking.h"
#include "../Rendering/RenderQueueFactory.h" #include "../Rendering/RenderSystem.h"
class EditorSystem : public ImpureSystem class EditorSystem : public ImpureSystem
{ {
@@ -1,30 +1,19 @@
#include "Rendering/RenderQueueFactory.h" #include "RenderSystem.h"
RenderSystem::RenderSystem(EventBroker* eventBrokerer, RenderQueueCollection* renderQueues)
RenderQueueFactory::RenderQueueFactory(EventBroker* eventBroker) :ImpureSystem(eventBrokerer)
{ {
m_RenderQueues = RenderQueueCollection(); m_RenderQueues = renderQueues;
m_EventBroker = eventBroker; Initialize();
} }
void RenderQueueFactory::Update(World* world)
void RenderSystem::Initialize()
{ {
m_RenderQueues.Clear();
FillModels(world, &m_RenderQueues.Forward);
FillLights(world, &m_RenderQueues.Lights);
} }
glm::mat4 RenderQueueFactory::ModelMatrix(World* world, EntityID entity) glm::vec3 RenderSystem::AbsolutePosition(World* world, EntityID entity)
{
glm::vec3 position = AbsolutePosition(world, entity);
glm::quat orientation = AbsoluteOrientation(world, entity);
glm::vec3 scale = AbsoluteScale(world, entity);
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
return modelMatrix;
}
glm::vec3 RenderQueueFactory::AbsolutePosition(World* world, EntityID entity)
{ {
glm::vec3 position; glm::vec3 position;
@@ -38,11 +27,11 @@ glm::vec3 RenderQueueFactory::AbsolutePosition(World* world, EntityID entity)
} }
entity = parent; entity = parent;
} while (entity != 0); } while (entity != 0);
return position; return position;
} }
glm::quat RenderQueueFactory::AbsoluteOrientation(World* world, EntityID entity) glm::quat RenderSystem::AbsoluteOrientation(World* world, EntityID entity)
{ {
glm::quat orientation; glm::quat orientation;
@@ -51,11 +40,11 @@ glm::quat RenderQueueFactory::AbsoluteOrientation(World* world, EntityID entity)
orientation = glm::quat((glm::vec3)transform["Orientation"]) * orientation; orientation = glm::quat((glm::vec3)transform["Orientation"]) * orientation;
entity = world->GetParent(entity); entity = world->GetParent(entity);
} while (entity != 0); } while (entity != 0);
return orientation; return orientation;
} }
glm::vec3 RenderQueueFactory::AbsoluteScale(World* world, EntityID entity) glm::vec3 RenderSystem::AbsoluteScale(World* world, EntityID entity)
{ {
glm::vec3 scale(1.f); glm::vec3 scale(1.f);
@@ -68,7 +57,17 @@ glm::vec3 RenderQueueFactory::AbsoluteScale(World* world, EntityID entity)
return scale; return scale;
} }
void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) glm::mat4 RenderSystem::ModelMatrix(World* world, EntityID entity)
{
glm::vec3 position = AbsolutePosition(world, entity);
glm::quat orientation = AbsoluteOrientation(world, entity);
glm::vec3 scale = AbsoluteScale(world, entity);
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
return modelMatrix;
}
void RenderSystem::FillModels(World* world, RenderQueue* renderQueue)
{ {
auto models = world->GetComponents("Model"); auto models = world->GetComponents("Model");
if (models == nullptr) { if (models == nullptr) {
@@ -127,14 +126,15 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
renderQueue->Add(job); renderQueue->Add(job);
} }
} }
} }
} }
void RenderQueueFactory::FillLights(World* world, RenderQueue* renderQueue)
void RenderSystem::Update(World* world, double dt)
{ {
m_RenderQueues->Clear();
FillModels(world, &m_RenderQueues->Forward);
} }
@@ -1,37 +1,33 @@
#ifndef RenderQueueFactory_h__ #ifndef RenderSystem_h__
#define RenderQueueFactory_h__ #define RenderSystem_h__
#include "../Core/World.h" #include "../Core/System.h"
#include "RenderQueue.h" #include "RenderQueue.h"
#include "../Core/ResourceManager.h"
#include "Model.h"
#include "../GLM.h" #include "../GLM.h"
#include "../Core/EventBroker.h" #include "../OpenGL.h"
#include "../Core/ResourceManager.h"
#include "ESetCamera.h" #include "ESetCamera.h"
#include "Model.h"
class RenderQueueFactory class RenderSystem : public ImpureSystem
{ {
public: public:
RenderQueueFactory(EventBroker* eventBroker); RenderSystem(EventBroker* eventBrokerer, RenderQueueCollection* renderQueues);
void Update(World* world);
virtual void Update(World* world, double dt) override;
RenderQueueCollection RenderQueues() const { return m_RenderQueues; }
static glm::vec3 AbsolutePosition(World* world, EntityID entity); static glm::vec3 AbsolutePosition(World* world, EntityID entity);
static glm::quat AbsoluteOrientation(World* world, EntityID entity); static glm::quat AbsoluteOrientation(World* world, EntityID entity);
static glm::vec3 AbsoluteScale(World* world, EntityID entity); static glm::vec3 AbsoluteScale(World* world, EntityID entity);
private: private:
EventBroker* m_EventBroker; RenderQueueCollection* m_RenderQueues;
RenderQueueCollection m_RenderQueues;
void FillModels(World* world, RenderQueue* renderQueue);
void FillLights(World* world, RenderQueue* renderQueue);
void Initialize();
glm::mat4 ModelMatrix(World* world, EntityID entity); glm::mat4 ModelMatrix(World* world, EntityID entity);
EntityID m_CurrentCamera; void FillModels(World* world, RenderQueue* renderQueue);
}; };
#endif #endif
+2 -2
View File
@@ -8,7 +8,6 @@
#include "Core/InputManager.h" #include "Core/InputManager.h"
#include "GUI/Frame.h" #include "GUI/Frame.h"
#include "Core/World.h" #include "Core/World.h"
#include "Rendering/RenderQueueFactory.h"
#include "Input/InputProxy.h" #include "Input/InputProxy.h"
#include "Input/KeyboardInputHandler.h" #include "Input/KeyboardInputHandler.h"
#include "Input/MouseInputHandler.h" #include "Input/MouseInputHandler.h"
@@ -18,6 +17,7 @@
#include "RaptorCopterSystem.h" #include "RaptorCopterSystem.h"
#include "PlayerSystem.h" #include "PlayerSystem.h"
#include "Editor/EditorSystem.h" #include "Editor/EditorSystem.h"
#include "Rendering/RenderSystem.h"
class Game class Game
{ {
@@ -38,7 +38,7 @@ private:
GUI::Frame* m_FrameStack; GUI::Frame* m_FrameStack;
World* m_World; World* m_World;
SystemPipeline* m_SystemPipeline; SystemPipeline* m_SystemPipeline;
RenderQueueFactory* m_RenderQueueFactory; RenderQueueCollection* m_RenderQueues;
EventRelay<Game, Events::InputCommand> m_EInputCommand; EventRelay<Game, Events::InputCommand> m_EInputCommand;
bool debugOnInputCommand(const Events::InputCommand& e); bool debugOnInputCommand(const Events::InputCommand& e);
+1 -1
View File
@@ -39,7 +39,7 @@ void EditorSystem::Update(World* world, double dt)
widgetModel["Visible"] = m_Visible; widgetModel["Visible"] = m_Visible;
if (m_Selection != 0) { if (m_Selection != 0) {
if (world->HasComponent(m_Selection, "Transform")) { if (world->HasComponent(m_Selection, "Transform")) {
glm::vec3 pos = RenderQueueFactory::AbsolutePosition(world, m_Selection); glm::vec3 pos = RenderSystem::AbsolutePosition(world, m_Selection);
auto widgetTransform = world->GetComponent(m_Widget, "Transform"); auto widgetTransform = world->GetComponent(m_Widget, "Transform");
widgetTransform["Position"] = pos; widgetTransform["Position"] = pos;
} else { } else {
+3 -5
View File
@@ -14,8 +14,6 @@ Game::Game(int argc, char* argv[])
// Create the core event broker // Create the core event broker
m_EventBroker = new EventBroker(); m_EventBroker = new EventBroker();
m_RenderQueueFactory = new RenderQueueFactory(m_EventBroker);
// Create a world // Create a world
m_World = new World(); m_World = new World();
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", ""); std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", "");
@@ -49,12 +47,13 @@ Game::Game(int argc, char* argv[])
m_FrameStack->Height = m_Renderer->Resolution().Height; m_FrameStack->Height = m_Renderer->Resolution().Height;
m_RenderQueues = new RenderQueueCollection();
// Create system pipeline // Create system pipeline
m_SystemPipeline = new SystemPipeline(m_EventBroker); m_SystemPipeline = new SystemPipeline(m_EventBroker);
m_SystemPipeline->AddSystem<RaptorCopterSystem>(); m_SystemPipeline->AddSystem<RaptorCopterSystem>();
m_SystemPipeline->AddSystem<PlayerSystem>(); m_SystemPipeline->AddSystem<PlayerSystem>();
m_SystemPipeline->AddSystem<EditorSystem>(); m_SystemPipeline->AddSystem<EditorSystem>();
m_SystemPipeline->AddSystem<RenderSystem>(m_RenderQueues);
m_LastTime = glfwGetTime(); m_LastTime = glfwGetTime();
@@ -90,9 +89,8 @@ void Game::Tick()
debugTick(dt); debugTick(dt);
m_Renderer->Update(dt); m_Renderer->Update(dt);
m_RenderQueueFactory->Update(m_World);
GLERROR("Game::Tick m_RenderQueueFactory->Update"); GLERROR("Game::Tick m_RenderQueueFactory->Update");
m_Renderer->Draw(m_RenderQueueFactory->RenderQueues()); m_Renderer->Draw(*m_RenderQueues);
GLERROR("Game::Tick m_Renderer->Draw"); GLERROR("Game::Tick m_Renderer->Draw");
m_EventBroker->Swap(); m_EventBroker->Swap();
m_EventBroker->Clear(); m_EventBroker->Clear();