Graphics: Separate Renderable and make Light a Renderable (LightComponent)
Former-commit-id: 6177d473f27ef493ba77417fc14461cb08b6f9e1
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#ifndef NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Graphics/Renderable.hpp>
|
||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <NDK/Component.hpp>
|
||||
|
||||
@@ -22,14 +22,14 @@ namespace Ndk
|
||||
|
||||
inline void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const;
|
||||
|
||||
inline void Attach(NzRenderableRef renderable);
|
||||
inline void Attach(NzInstancedRenderableRef renderable);
|
||||
|
||||
inline void EnsureTransformMatrixUpdate() const;
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
void InvalidateRenderableData(const NzRenderable* renderable, nzUInt32 flags, unsigned int index);
|
||||
void InvalidateRenderableData(const NzInstancedRenderable* renderable, nzUInt32 flags, unsigned int index);
|
||||
inline void InvalidateTransformMatrix();
|
||||
|
||||
void OnAttached() override;
|
||||
@@ -50,10 +50,10 @@ namespace Ndk
|
||||
{
|
||||
}
|
||||
|
||||
NazaraSlot(NzRenderable, OnRenderableInvalidateInstanceData, renderableInvalidationSlot);
|
||||
NazaraSlot(NzInstancedRenderable, OnInstancedRenderableInvalidateData, renderableInvalidationSlot);
|
||||
|
||||
mutable NzRenderable::InstanceData data;
|
||||
NzRenderableRef renderable;
|
||||
mutable NzInstancedRenderable::InstanceData data;
|
||||
NzInstancedRenderableRef renderable;
|
||||
mutable bool dataUpdated;
|
||||
};
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@ namespace Ndk
|
||||
}
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::Attach(NzRenderableRef renderable)
|
||||
inline void GraphicsComponent::Attach(NzInstancedRenderableRef renderable)
|
||||
{
|
||||
m_renderables.emplace_back(m_transformMatrix);
|
||||
Renderable& r = m_renderables.back();
|
||||
r.renderable = std::move(renderable);
|
||||
r.renderableInvalidationSlot.Connect(r.renderable->OnRenderableInvalidateInstanceData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size()-1));
|
||||
r.renderableInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size()-1));
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::EnsureTransformMatrixUpdate() const
|
||||
|
||||
30
SDK/include/NDK/Components/LightComponent.hpp
Normal file
30
SDK/include/NDK/Components/LightComponent.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <NDK/Component.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API LightComponent : public Component<LightComponent>, public NzLight
|
||||
{
|
||||
public:
|
||||
inline LightComponent(nzLightType lightType = nzLightType_Point);
|
||||
LightComponent(const LightComponent& light) = default;
|
||||
~LightComponent() = default;
|
||||
|
||||
LightComponent& operator=(const LightComponent& light) = default;
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Components/LightComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_LIGHTCOMPONENT_HPP
|
||||
11
SDK/include/NDK/Components/LightComponent.inl
Normal file
11
SDK/include/NDK/Components/LightComponent.inl
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline LightComponent::LightComponent(nzLightType lightType) :
|
||||
NzLight(lightType)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ namespace Ndk
|
||||
|
||||
EntityList m_cameras;
|
||||
EntityList m_drawables;
|
||||
EntityList m_lights;
|
||||
NzForwardRenderTechnique m_renderTechnique;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void GraphicsComponent::InvalidateRenderableData(const NzRenderable* renderable, nzUInt32 flags, unsigned int index)
|
||||
void GraphicsComponent::InvalidateRenderableData(const NzInstancedRenderable* renderable, nzUInt32 flags, unsigned int index)
|
||||
{
|
||||
NazaraUnused(renderable);
|
||||
|
||||
|
||||
10
SDK/src/NDK/Components/LightComponent.cpp
Normal file
10
SDK/src/NDK/Components/LightComponent.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
ComponentIndex LightComponent::componentIndex;
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <NDK/BaseSystem.hpp>
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/CollisionComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
@@ -57,6 +58,7 @@ namespace Ndk
|
||||
// Composants
|
||||
InitializeComponent<CameraComponent>("NdkCam");
|
||||
InitializeComponent<CollisionComponent>("NdkColli");
|
||||
InitializeComponent<LightComponent>("NdkLight");
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<GraphicsComponent>("NdkGfx");
|
||||
InitializeComponent<NodeComponent>("NdkNode");
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Nazara/Graphics/ColorBackground.hpp>
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
@@ -24,14 +25,22 @@ namespace Ndk
|
||||
NzAbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue();
|
||||
renderQueue->Clear();
|
||||
|
||||
for (const Ndk::EntityHandle& drawable : m_drawables)
|
||||
for (const Ndk::EntityHandle& light : m_drawables)
|
||||
{
|
||||
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
|
||||
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
|
||||
GraphicsComponent& graphicsComponent = light->GetComponent<GraphicsComponent>();
|
||||
NodeComponent& drawableNode = light->GetComponent<NodeComponent>();
|
||||
|
||||
graphicsComponent.AddToRenderQueue(renderQueue);
|
||||
}
|
||||
|
||||
for (const Ndk::EntityHandle& light : m_lights)
|
||||
{
|
||||
LightComponent& lightComponent = light->GetComponent<LightComponent>();
|
||||
NodeComponent& drawableNode = light->GetComponent<NodeComponent>();
|
||||
|
||||
lightComponent.AddToRenderQueue(renderQueue, drawableNode.GetTransformMatrix());
|
||||
}
|
||||
|
||||
NzColorBackground background;
|
||||
|
||||
NzSceneData sceneData;
|
||||
@@ -47,6 +56,7 @@ namespace Ndk
|
||||
{
|
||||
m_cameras.Remove(entity);
|
||||
m_drawables.Remove(entity);
|
||||
m_lights.Remove(entity);
|
||||
}
|
||||
|
||||
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
||||
@@ -67,6 +77,10 @@ namespace Ndk
|
||||
else
|
||||
m_drawables.Remove(entity);
|
||||
|
||||
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
|
||||
m_lights.Insert(entity);
|
||||
else
|
||||
m_lights.Remove(entity);
|
||||
}
|
||||
|
||||
SystemIndex RenderSystem::systemIndex;
|
||||
|
||||
Reference in New Issue
Block a user