Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ebe2d9d4f5 | |||
| 6d2272f62e | |||
| 31666f9112 | |||
| bd49bdb297 | |||
| a8173488ca |
Regular → Executable
+3
-6
@@ -1,6 +1,3 @@
|
||||
#ifndef EditorRenderSystem_h__
|
||||
#define EditorRenderSystem_h__
|
||||
|
||||
#include "../Core/System.h"
|
||||
#include "../Rendering/IRenderer.h"
|
||||
#include "../Rendering/ModelJob.h"
|
||||
@@ -17,11 +14,11 @@ public:
|
||||
private:
|
||||
IRenderer* m_Renderer;
|
||||
RenderFrame* m_RenderFrame;
|
||||
Camera* m_EditorCamera;
|
||||
Camera* m_Camera;
|
||||
EntityWrapper m_CurrentCamera = EntityWrapper::Invalid;
|
||||
|
||||
EventRelay<EditorRenderSystem, Events::SetCamera> m_ESetCamera;
|
||||
bool OnSetCamera(Events::SetCamera& e);
|
||||
};
|
||||
|
||||
#endif
|
||||
void enqueueModel(RenderScene& scene, EntityWrapper entity, const glm::mat4& modelMatrix, const std::string& modelResource, ComponentWrapper cModel, bool wireframe);
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef EditorWidgetRenderSystem_h__
|
||||
#define EditorWidgetRenderSystem_h__
|
||||
|
||||
#include "../Core/System.h"
|
||||
#include "../Rendering/IRenderer.h"
|
||||
#include "../Rendering/ModelJob.h"
|
||||
#include "../Rendering/Camera.h"
|
||||
#include "../Rendering/ESetCamera.h"
|
||||
|
||||
class EditorWidgetRenderSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
EditorWidgetRenderSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame);
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
IRenderer* m_Renderer;
|
||||
RenderFrame* m_RenderFrame;
|
||||
Camera* m_EditorCamera;
|
||||
EntityWrapper m_CurrentCamera = EntityWrapper::Invalid;
|
||||
|
||||
EventRelay<EditorWidgetRenderSystem, Events::SetCamera> m_ESetCamera;
|
||||
bool OnSetCamera(Events::SetCamera& e);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -164,7 +164,7 @@ struct ModelJob : RenderJob
|
||||
std::vector<const ::RawModel::TextureProperties*> SpecularTexture;
|
||||
std::vector<const ::RawModel::TextureProperties*> IncandescenceTexture;
|
||||
float Shininess = 0.f;
|
||||
glm::vec4 Color;
|
||||
glm::vec4 Color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
||||
const ::Model* Model = nullptr;
|
||||
::Skeleton* Skeleton = nullptr;
|
||||
std::vector<::Skeleton::AnimationData> Animations;
|
||||
@@ -182,6 +182,7 @@ struct ModelJob : RenderJob
|
||||
glm::vec4 FillColor = glm::vec4(0);
|
||||
float FillPercentage = 0.0;
|
||||
bool IsShielded;
|
||||
bool Wireframe = false;
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = ShaderID << 20 + ModelID << 10 + TextureID;
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
bool StencilMask(GLuint mask);
|
||||
bool DepthMask(GLboolean flag);
|
||||
bool DepthFunc(GLenum func);
|
||||
bool PolygonMode(GLenum face, GLenum mode);
|
||||
bool AlphaFunc(GLenum func, GLclampf thresholder);
|
||||
|
||||
private:
|
||||
|
||||
@@ -157,7 +157,7 @@ void EditorGUI::drawEntitiesRecursive(World* world, EntityID parent)
|
||||
auto entityChildren = world->GetEntityChildren();
|
||||
auto range = entityChildren.equal_range(parent);
|
||||
for (auto it = range.first; it != range.second; it++) {
|
||||
if (EditorGUI::drawEntityNode(EntityWrapper(world, it->second))) {
|
||||
if (drawEntityNode(EntityWrapper(world, it->second))) {
|
||||
drawEntitiesRecursive(world, it->second);
|
||||
ImGui::TreePop();
|
||||
}
|
||||
@@ -217,6 +217,7 @@ bool EditorGUI::drawEntityNode(EntityWrapper entity)
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::PushID(("EntityNode" + std::to_string(entity.ID)).c_str());
|
||||
ImGui::SetNextTreeNodeOpened(true, ImGuiSetCond_Once);
|
||||
if (ImGui::TreeNode(formatEntityName(entity).c_str())) {
|
||||
// Handle drop events for reparenting
|
||||
@@ -224,8 +225,10 @@ bool EditorGUI::drawEntityNode(EntityWrapper entity)
|
||||
entityChangeParent(m_CurrentlyDragging, entity);
|
||||
m_CurrentlyDragging = EntityWrapper::Invalid;
|
||||
}
|
||||
ImGui::PopID();
|
||||
return true;
|
||||
} else {
|
||||
ImGui::PopID();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
+59
-64
@@ -1,81 +1,44 @@
|
||||
#include "Editor/EditorRenderSystem.h"
|
||||
|
||||
EditorRenderSystem::EditorRenderSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame)
|
||||
EditorRenderSystem::EditorRenderSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame)
|
||||
: System(params)
|
||||
, m_Renderer(renderer)
|
||||
, m_RenderFrame(renderFrame)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorRenderSystem::OnSetCamera);
|
||||
auto resolution = Rectangle::Rectangle(1280, 720);
|
||||
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||
auto resolution = renderer->Resolution();
|
||||
m_Camera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||
}
|
||||
|
||||
void EditorRenderSystem::Update(double dt)
|
||||
{
|
||||
if (m_CurrentCamera.Valid()) {
|
||||
ComponentWrapper cameraTransform = m_CurrentCamera["Transform"];
|
||||
m_EditorCamera->SetPosition(cameraTransform["Position"]);
|
||||
m_EditorCamera->SetOrientation(glm::quat((const glm::vec3&)cameraTransform["Orientation"]));
|
||||
m_Camera->SetPosition(Transform::AbsolutePosition(m_CurrentCamera));
|
||||
m_Camera->SetOrientation(Transform::AbsoluteOrientation(m_CurrentCamera));
|
||||
}
|
||||
|
||||
RenderScene scene;
|
||||
scene.ClearDepth = true;
|
||||
scene.Camera = m_EditorCamera;
|
||||
scene.Viewport = Rectangle(1920, 1080);
|
||||
scene.Camera = m_Camera;
|
||||
|
||||
auto cSceneLight = m_World->GetComponents("SceneLight");
|
||||
if (cSceneLight != nullptr) {
|
||||
//these are hardcoded since they want special light treatment and a component just for widgets is stupid.
|
||||
scene.AmbientColor = glm::vec4(0.8, 0.8, 0.8, 1.0);
|
||||
}
|
||||
|
||||
auto models = m_World->GetComponents("Model");
|
||||
if (models != nullptr) {
|
||||
for (auto& cModel : *models) {
|
||||
if (!(bool)cModel["Visible"]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string& resource = cModel["Resource"];
|
||||
|
||||
Model* model;
|
||||
try {
|
||||
model = ResourceManager::Load<::Model, true>(resource);
|
||||
} catch (const Resource::StillLoadingException&) {
|
||||
continue;
|
||||
} catch (const std::exception&) {
|
||||
try {
|
||||
model = ResourceManager::Load<::Model>("Models/Core/Error.mesh");
|
||||
} catch (const std::exception&) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
EntityWrapper entity(m_World, cModel.EntityID);
|
||||
glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, entity.World);
|
||||
for (auto matGroup : model->MaterialGroups()) {
|
||||
std::shared_ptr<ModelJob> modelJob = std::make_shared<ModelJob>(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World, glm::vec4(0), 0.f, false);
|
||||
if (cModel["Transparent"]) {
|
||||
scene.Jobs.TransparentObjects.push_back(modelJob);
|
||||
} else {
|
||||
scene.Jobs.OpaqueObjects.push_back(modelJob);
|
||||
}
|
||||
}
|
||||
auto cameras = m_World->GetComponents("Camera");
|
||||
if (cameras != nullptr) {
|
||||
for (auto& cCamera : *cameras) {
|
||||
EntityWrapper entity(m_World, cCamera.EntityID);
|
||||
entity["Model"]["Resource"] = "Models/Widgets/Camera.mesh";
|
||||
glm::mat4 modelMatrix = Transform::ModelMatrix(entity);
|
||||
enqueueModel(scene, entity, modelMatrix, "Models/Widgets/Camera.mesh", entity["Model"], false);
|
||||
}
|
||||
}
|
||||
|
||||
auto pointLights = m_World->GetComponents("PointLight");
|
||||
if (pointLights != nullptr) {
|
||||
for (auto& cPointLight : *pointLights) {
|
||||
bool visible = cPointLight["Visible"];
|
||||
if (!visible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
EntityWrapper entity(m_World, cPointLight.EntityID);
|
||||
ComponentWrapper& cTransform = entity["Transform"];
|
||||
std::shared_ptr<PointLightJob> pointLightJob = std::make_shared<PointLightJob>(cTransform, cPointLight, entity.World);
|
||||
scene.Jobs.PointLight.push_back(pointLightJob);
|
||||
auto aabbs = m_World->GetComponents("AABB");
|
||||
if (aabbs != nullptr) {
|
||||
for (auto& cAABB : *aabbs) {
|
||||
EntityWrapper entity(m_World, cAABB.EntityID);
|
||||
glm::vec3 absPosition = Transform::AbsolutePosition(entity) + (glm::vec3)cAABB["Origin"];
|
||||
glm::vec3 absScale = Transform::AbsoluteScale(entity) * (glm::vec3)cAABB["Size"];
|
||||
glm::mat4 modelMatrix = glm::translate(absPosition) * glm::scale(absScale);
|
||||
entity["Model"]["Resource"] = "Models/Core/UnitCube.mesh";
|
||||
enqueueModel(scene, entity, modelMatrix, "Models/Core/UnitCube.mesh", entity["Model"], true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,12 +49,44 @@ bool EditorRenderSystem::OnSetCamera(Events::SetCamera& e)
|
||||
{
|
||||
ComponentWrapper cTransform = e.CameraEntity["Transform"];
|
||||
ComponentWrapper cCamera = e.CameraEntity["Camera"];
|
||||
m_EditorCamera->SetFOV(static_cast<float>((double)cCamera["FOV"]));
|
||||
m_EditorCamera->SetNearClip(static_cast<float>((double)cCamera["NearClip"]));
|
||||
m_EditorCamera->SetFarClip(static_cast<float>((double)cCamera["FarClip"]));
|
||||
m_EditorCamera->SetPosition(cTransform["Position"]);
|
||||
m_EditorCamera->SetOrientation(glm::quat((const glm::vec3&)cTransform["Orientation"]));
|
||||
m_Camera->SetFOV(static_cast<float>((double)cCamera["FOV"]));
|
||||
m_Camera->SetNearClip(static_cast<float>((double)cCamera["NearClip"]));
|
||||
m_Camera->SetFarClip(static_cast<float>((double)cCamera["FarClip"]));
|
||||
m_Camera->SetPosition(cTransform["Position"]);
|
||||
m_Camera->SetOrientation(glm::quat((const glm::vec3&)cTransform["Orientation"]));
|
||||
m_CurrentCamera = e.CameraEntity;
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorRenderSystem::enqueueModel(RenderScene& scene, EntityWrapper entity, const glm::mat4& modelMatrix, const std::string& modelResource, ComponentWrapper cModel, bool wireframe)
|
||||
{
|
||||
Model* model;
|
||||
try {
|
||||
model = ResourceManager::Load<::Model, true>(modelResource);
|
||||
} catch (const Resource::StillLoadingException&) {
|
||||
return;
|
||||
} catch (const std::exception&) {
|
||||
try {
|
||||
model = ResourceManager::Load<::Model>("Models/Core/Error.mesh");
|
||||
} catch (const std::exception&) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto matGroup : model->MaterialGroups()) {
|
||||
std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob(
|
||||
model,
|
||||
m_Camera,
|
||||
modelMatrix,
|
||||
matGroup,
|
||||
cModel,
|
||||
m_World,
|
||||
glm::vec4(1.f, 1.f, 1.f, 1.f),
|
||||
0.f,
|
||||
false
|
||||
));
|
||||
modelJob->Wireframe = wireframe;
|
||||
scene.Jobs.OpaqueObjects.push_back(modelJob);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "Editor/EditorSystem.h"
|
||||
#include "Core/UniformScaleSystem.h"
|
||||
#include "Editor/EditorRenderSystem.h"
|
||||
#include "Editor/EditorWidgetRenderSystem.h"
|
||||
#include "Editor/EditorWidgetSystem.h"
|
||||
#include "Core/EntityFile.h"
|
||||
|
||||
@@ -13,7 +13,7 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame
|
||||
m_EditorWorldSystemPipeline = new SystemPipeline(m_EditorWorld, m_EventBroker, IsClient, IsServer);
|
||||
m_EditorWorldSystemPipeline->AddSystem<UniformScaleSystem>(0);
|
||||
m_EditorWorldSystemPipeline->AddSystem<EditorWidgetSystem>(0, m_Renderer);
|
||||
m_EditorWorldSystemPipeline->AddSystem<EditorRenderSystem>(1, m_Renderer, m_RenderFrame);
|
||||
m_EditorWorldSystemPipeline->AddSystem<EditorWidgetRenderSystem>(2, m_Renderer, m_RenderFrame);
|
||||
|
||||
m_EditorCamera = importEntity(EntityWrapper(m_EditorWorld, EntityID_Invalid), "Schema/Entities/Empty.xml");
|
||||
m_ActualCamera = m_EditorCamera;
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "Editor/EditorWidgetRenderSystem.h"
|
||||
|
||||
EditorWidgetRenderSystem::EditorWidgetRenderSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame)
|
||||
: System(params)
|
||||
, m_Renderer(renderer)
|
||||
, m_RenderFrame(renderFrame)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorWidgetRenderSystem::OnSetCamera);
|
||||
auto resolution = Rectangle::Rectangle(1280, 720);
|
||||
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||
}
|
||||
|
||||
void EditorWidgetRenderSystem::Update(double dt)
|
||||
{
|
||||
if (m_CurrentCamera.Valid()) {
|
||||
ComponentWrapper cameraTransform = m_CurrentCamera["Transform"];
|
||||
m_EditorCamera->SetPosition(cameraTransform["Position"]);
|
||||
m_EditorCamera->SetOrientation(glm::quat((const glm::vec3&)cameraTransform["Orientation"]));
|
||||
}
|
||||
|
||||
RenderScene scene;
|
||||
scene.ClearDepth = true;
|
||||
scene.Camera = m_EditorCamera;
|
||||
scene.Viewport = Rectangle(1920, 1080);
|
||||
|
||||
auto cSceneLight = m_World->GetComponents("SceneLight");
|
||||
if (cSceneLight != nullptr) {
|
||||
//these are hardcoded since they want special light treatment and a component just for widgets is stupid.
|
||||
scene.AmbientColor = glm::vec4(0.8, 0.8, 0.8, 1.0);
|
||||
}
|
||||
|
||||
auto models = m_World->GetComponents("Model");
|
||||
if (models != nullptr) {
|
||||
for (auto& cModel : *models) {
|
||||
if (!(bool)cModel["Visible"]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string& resource = cModel["Resource"];
|
||||
|
||||
Model* model;
|
||||
try {
|
||||
model = ResourceManager::Load<::Model, true>(resource);
|
||||
} catch (const Resource::StillLoadingException&) {
|
||||
continue;
|
||||
} catch (const std::exception&) {
|
||||
try {
|
||||
model = ResourceManager::Load<::Model>("Models/Core/Error.mesh");
|
||||
} catch (const std::exception&) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
EntityWrapper entity(m_World, cModel.EntityID);
|
||||
glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, entity.World);
|
||||
for (auto matGroup : model->MaterialGroups()) {
|
||||
std::shared_ptr<ModelJob> modelJob = std::make_shared<ModelJob>(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World, glm::vec4(0), 0.f, false);
|
||||
if (cModel["Transparent"]) {
|
||||
scene.Jobs.TransparentObjects.push_back(modelJob);
|
||||
} else {
|
||||
scene.Jobs.OpaqueObjects.push_back(modelJob);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto pointLights = m_World->GetComponents("PointLight");
|
||||
if (pointLights != nullptr) {
|
||||
for (auto& cPointLight : *pointLights) {
|
||||
bool visible = cPointLight["Visible"];
|
||||
if (!visible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
EntityWrapper entity(m_World, cPointLight.EntityID);
|
||||
ComponentWrapper& cTransform = entity["Transform"];
|
||||
std::shared_ptr<PointLightJob> pointLightJob = std::make_shared<PointLightJob>(cTransform, cPointLight, entity.World);
|
||||
scene.Jobs.PointLight.push_back(pointLightJob);
|
||||
}
|
||||
}
|
||||
|
||||
m_RenderFrame->Add(scene);
|
||||
}
|
||||
|
||||
bool EditorWidgetRenderSystem::OnSetCamera(Events::SetCamera& e)
|
||||
{
|
||||
ComponentWrapper cTransform = e.CameraEntity["Transform"];
|
||||
ComponentWrapper cCamera = e.CameraEntity["Camera"];
|
||||
m_EditorCamera->SetFOV(static_cast<float>((double)cCamera["FOV"]));
|
||||
m_EditorCamera->SetNearClip(static_cast<float>((double)cCamera["NearClip"]));
|
||||
m_EditorCamera->SetFarClip(static_cast<float>((double)cCamera["FarClip"]));
|
||||
m_EditorCamera->SetPosition(cTransform["Position"]);
|
||||
m_EditorCamera->SetOrientation(glm::quat((const glm::vec3&)cTransform["Orientation"]));
|
||||
m_CurrentCamera = e.CameraEntity;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -429,6 +429,12 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
if (modelJob) {
|
||||
//bind forward program
|
||||
//TODO: JOHAN/TOBIAS: Bind shader based on ModelJob->ShaderID;
|
||||
RenderState jobState;
|
||||
if (modelJob->Wireframe) {
|
||||
jobState.Disable(GL_CULL_FACE);
|
||||
jobState.PolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
}
|
||||
|
||||
switch (modelJob->Type) {
|
||||
case RawModel::MaterialType::Basic:
|
||||
case RawModel::MaterialType::SingleTextures:
|
||||
|
||||
@@ -155,6 +155,20 @@ bool RenderState::AlphaFunc(GLenum func, GLclampf thresholder)
|
||||
return !GLERROR("AlphaFunc");
|
||||
}
|
||||
|
||||
bool RenderState::PolygonMode(GLenum face, GLenum mode)
|
||||
{
|
||||
GLint originalMode[2];
|
||||
glGetIntegerv(GL_POLYGON_MODE, &originalMode[0]);
|
||||
if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
|
||||
m_ResetFunctions.push_back(std::bind(glPolygonMode, GL_FRONT, originalMode[0]));
|
||||
}
|
||||
if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
|
||||
m_ResetFunctions.push_back(std::bind(glPolygonMode, GL_BACK, originalMode[1]));
|
||||
}
|
||||
glPolygonMode(face, mode);
|
||||
return !GLERROR("RenderState::PolygonMode");
|
||||
}
|
||||
|
||||
RenderState::~RenderState()
|
||||
{
|
||||
for (auto& f : boost::adaptors::reverse(m_ResetFunctions)) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Collision/EntityAABB.h"
|
||||
#include "Collision/TriggerSystem.h"
|
||||
#include "Collision/CollisionSystem.h"
|
||||
#include "Editor/EditorRenderSystem.h"
|
||||
#include "Systems/RaptorCopterSystem.h"
|
||||
#include "Systems/HealthSystem.h"
|
||||
#include "Systems/PlayerMovementSystem.h"
|
||||
@@ -164,6 +165,7 @@ Game::Game(int argc, char* argv[])
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<FillFrustumOctreeSystem>(updateOrderLevel, m_OctreeFrustrumCulling);
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<EditorRenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
|
||||
m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame, m_OctreeFrustrumCulling);
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<EditorSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
|
||||
|
||||
Reference in New Issue
Block a user