Merge remote-tracking branch 'origin/master' into Menu

# Conflicts:
#	include/Engine/Rendering/DrawFinalPass.h
#	include/Engine/Rendering/RenderQueue.h
#	resources/Schema/Components.xsd
#	resources/Schema/Entities/QualityAssurance.xml
#	resources/Schema/Entities/RenderingWorld.xml
#	resources/Shaders/Sprite.vert.glsl
#	src/Engine/Rendering/DrawFinalPass.cpp
#	src/Engine/Rendering/Model.cpp
#	src/Engine/Rendering/RenderSystem.cpp
#	src/Engine/Rendering/Renderer.cpp
#	src/Game/Game.cpp
This commit is contained in:
Tleety
2016-02-10 19:52:42 +01:00
134 changed files with 6897 additions and 1540 deletions
+77 -32
View File
@@ -1,10 +1,13 @@
#include "Rendering/RenderSystem.h"
#include "Collision/Collision.h"
#include "Core/Frustum.h"
RenderSystem::RenderSystem(World* world, EventBroker* eventBroker, const IRenderer* renderer, RenderFrame* renderFrame)
RenderSystem::RenderSystem(World* world, EventBroker* eventBroker, const IRenderer* renderer, RenderFrame* renderFrame, Octree<EntityAABB>* frustumCullOctree)
: System(world, eventBroker)
, m_Renderer(renderer)
, m_RenderFrame(renderFrame)
, m_World(world)
, m_Octree(frustumCullOctree)
{
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &RenderSystem::OnSetCamera);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand);
@@ -90,14 +93,15 @@ bool RenderSystem::isChildOfCurrentCamera(EntityWrapper entity)
return entity == m_CurrentCamera || entity.IsChildOf(m_CurrentCamera);
}
void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs, std::list<std::shared_ptr<RenderJob>>& transparentJobs)
void RenderSystem::fillModels(RenderScene::Queues &Jobs)
{
auto models = m_World->GetComponents("Model");
if (models == nullptr) {
return;
}
Frustum frustum(m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix());
std::vector<EntityAABB> seenEntities;
m_Octree->ObjectsInFrustum(frustum, seenEntities);
for (auto& cModel : *models) {
for (auto& seenEntity : seenEntities) {
EntityWrapper entity = seenEntity.Entity;
ComponentWrapper cModel = entity["Model"];
bool visible = cModel["Visible"];
if (!visible) {
continue;
@@ -107,17 +111,15 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs,
continue;
}
EntityWrapper entity(m_World, cModel.EntityID);
// Only render children of a camera if that camera is currently active
if (isChildOfACamera(entity) && !isChildOfCurrentCamera(entity)) {
continue;
}
if (isChildOfACamera(entity) && !isChildOfCurrentCamera(entity)) {
continue;
}
// Hide things parented to local player if they have the HiddenFromLocalPlayer component
if (entity.HasComponent("HiddenForLocalPlayer") && (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer))) {
continue;
}
if (entity.HasComponent("HiddenForLocalPlayer") && (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer))) {
continue;
}
Model* model;
try {
@@ -142,7 +144,9 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs,
}
glm::mat4 modelMatrix = Transform::ModelMatrix(cModel.EntityID, m_World);
//Loop through all materialgroups of a model
for (auto matGroup : model->MaterialGroups()) {
//If the model has an explosioneffect component, we will add an explosioneffectjob
if (m_World->HasComponent(cModel.EntityID, "ExplosionEffect")) {
auto explosionEffectComponent = m_World->GetComponent(cModel.EntityID, "ExplosionEffect");
std::shared_ptr<ExplosionEffectJob> explosionEffectJob = std::shared_ptr<ExplosionEffectJob>(new ExplosionEffectJob(
@@ -156,14 +160,33 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs,
fillColor,
fillPercentage
));
if(explosionEffectJob->Color.a != 1.f || explosionEffectJob->EndColor.a != 1.f || explosionEffectJob->DiffuseColor.a != 1.f) {
cModel["Transparent"] = true;
}
if (m_World->HasComponent(cModel.EntityID, "Shield")){
explosionEffectJob->CalculateHash();
Jobs.ShieldObjects.push_back(explosionEffectJob);
} else if (m_World->HasComponent(cModel.EntityID, "Shielded")
|| m_World->HasComponent(cModel.EntityID, "Player")) {
if (cModel["Transparent"]) {
transparentJobs.push_back(explosionEffectJob);
if (explosionEffectJob->Color.a != 1.f || explosionEffectJob->EndColor.a != 1.f || explosionEffectJob->DiffuseColor.a != 1.f) {
cModel["Transparent"] = true;
}
if (cModel["Transparent"]) {
Jobs.TransparentShieldedObjects.push_back(explosionEffectJob);
} else {
explosionEffectJob->CalculateHash();
Jobs.OpaqueShieldedObjects.push_back(explosionEffectJob);
}
} else {
opaqueJobs.push_back(explosionEffectJob);
if (explosionEffectJob->Color.a != 1.f || explosionEffectJob->EndColor.a != 1.f || explosionEffectJob->DiffuseColor.a != 1.f) {
cModel["Transparent"] = true;
}
if (cModel["Transparent"]) {
Jobs.TransparentObjects.push_back(explosionEffectJob);
} else {
explosionEffectJob->CalculateHash();
Jobs.OpaqueObjects.push_back(explosionEffectJob);
}
}
} else {
std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob(
@@ -176,13 +199,33 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& opaqueJobs,
fillColor,
fillPercentage
));
if (modelJob->Color.a != 1.f || modelJob->DiffuseColor.a != 1.f) {
cModel["Transparent"] = true;
}
if (cModel["Transparent"]) {
transparentJobs.push_back(modelJob);
if (m_World->HasComponent(cModel.EntityID, "Shield")) {
modelJob->CalculateHash();
Jobs.ShieldObjects.push_back(modelJob);
} else if (m_World->HasComponent(cModel.EntityID, "Shielded")
|| m_World->HasComponent(cModel.EntityID, "Player")) {
if (modelJob->Color.a != 1.f || modelJob->DiffuseColor.a != 1.f) {
cModel["Transparent"] = true;
}
if (cModel["Transparent"]) {
Jobs.TransparentShieldedObjects.push_back(modelJob);
} else {
modelJob->CalculateHash();
Jobs.OpaqueShieldedObjects.push_back(modelJob);
}
} else {
opaqueJobs.push_back(modelJob);
if (modelJob->Color.a != 1.f || modelJob->DiffuseColor.a != 1.f) {
cModel["Transparent"] = true;
}
if (cModel["Transparent"]) {
Jobs.TransparentObjects.push_back(modelJob);
} else {
modelJob->CalculateHash();
Jobs.OpaqueObjects.push_back(modelJob);
}
}
}
}
@@ -244,7 +287,7 @@ void RenderSystem::fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World*
if (texts == nullptr) {
return;
}
for (auto& textComponent : *texts) {
bool visible = textComponent["Visible"];
if (!visible) {
@@ -299,11 +342,13 @@ void RenderSystem::Update(double dt)
scene.AmbientColor = (glm::vec4)(*cSceneLight->begin())["AmbientColor"];
}
fillModels(scene.OpaqueObjects, scene.TransparentObjects);
fillPointLights(scene.PointLightJobs, m_World);
fillDirectionalLights(scene.DirectionalLightJobs, m_World);
fillText(scene.TextJobs, m_World);
fillModels(scene.Jobs);
fillPointLights(scene.Jobs.PointLight, m_World);
//TODO: Make sure all objects needed are also sorted.
scene.Jobs.OpaqueObjects.sort();
fillSprites(scene.SpriteJobs, m_World);
fillDirectionalLights(scene.Jobs.DirectionalLight, m_World);
fillText(scene.Jobs.Text, m_World);
m_RenderFrame->Add(scene);
}