Sdk/RenderSystem: Allow to change render technique

Former-commit-id: ec61a2ebff138300344e6068917f0863c3d11859
This commit is contained in:
Lynix
2016-04-16 18:40:58 +02:00
parent 104e393d65
commit c8dd28f75c
8 changed files with 43 additions and 10 deletions

View File

@@ -8,7 +8,7 @@
#define NDK_SYSTEMS_RENDERSYSTEM_HPP
#include <Nazara/Graphics/AbstractBackground.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
#include <NDK/EntityList.hpp>
#include <NDK/System.hpp>
#include <unordered_map>
@@ -25,11 +25,15 @@ namespace Ndk
inline RenderSystem(const RenderSystem& renderSystem);
~RenderSystem() = default;
template<typename T> void ChangeRenderTechnique();
inline void ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique);
inline const Nz::BackgroundRef& GetDefaultBackground() const;
inline const Nz::Matrix4f& GetCoordinateSystemMatrix() const;
inline Nz::Vector3f GetGlobalForward() const;
inline Nz::Vector3f GetGlobalRight() const;
inline Nz::Vector3f GetGlobalUp() const;
inline Nz::AbstractRenderTechnique& GetRenderTechnique() const;
inline void SetDefaultBackground(Nz::BackgroundRef background);
inline void SetGlobalForward(const Nz::Vector3f& direction);
@@ -45,11 +49,11 @@ namespace Ndk
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
std::unique_ptr<Nz::AbstractRenderTechnique> m_renderTechnique;
EntityList m_cameras;
EntityList m_drawables;
EntityList m_lights;
Nz::BackgroundRef m_background;
Nz::ForwardRenderTechnique m_renderTechnique;
Nz::Matrix4f m_coordinateSystemMatrix;
bool m_coordinateSystemInvalidated;
};

View File

@@ -9,6 +9,17 @@ namespace Ndk
{
}
template<typename T>
inline void RenderSystem::ChangeRenderTechnique()
{
ChangeRenderTechnique(std::make_unique<T>());
}
inline void RenderSystem::ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique)
{
m_renderTechnique = std::move(renderTechnique);
}
inline const Nz::BackgroundRef& RenderSystem::GetDefaultBackground() const
{
return m_background;
@@ -34,6 +45,11 @@ namespace Ndk
return Nz::Vector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32);
}
inline Nz::AbstractRenderTechnique& RenderSystem::GetRenderTechnique() const
{
return *m_renderTechnique.get();
}
inline void RenderSystem::SetDefaultBackground(Nz::BackgroundRef background)
{
m_background = std::move(background);

View File

@@ -15,6 +15,7 @@ namespace Ndk
m_coordinateSystemMatrix(Nz::Matrix4f::Identity()),
m_coordinateSystemInvalidated(true)
{
ChangeRenderTechnique<Nz::ForwardRenderTechnique>();
SetDefaultBackground(Nz::ColorBackground::New());
SetUpdateRate(0.f);
}
@@ -73,7 +74,7 @@ namespace Ndk
CameraComponent& camComponent = camera->GetComponent<CameraComponent>();
camComponent.ApplyView();
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue();
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique->GetRenderQueue();
renderQueue->Clear();
//TODO: Culling
@@ -99,7 +100,8 @@ namespace Ndk
sceneData.background = m_background;
sceneData.viewer = &camComponent;
m_renderTechnique.Draw(sceneData);
m_renderTechnique->Clear(sceneData);
m_renderTechnique->Draw(sceneData);
}
}