diff --git a/include/Nazara/Graphics/AbstractRenderTechnique.hpp b/include/Nazara/Graphics/AbstractRenderTechnique.hpp index f59548145..cb93fec7c 100644 --- a/include/Nazara/Graphics/AbstractRenderTechnique.hpp +++ b/include/Nazara/Graphics/AbstractRenderTechnique.hpp @@ -9,7 +9,9 @@ #include #include +#include #include +#include class NzBackground; class NzScene; @@ -21,11 +23,13 @@ class NAZARA_API NzAbstractRenderTechnique : NzNonCopyable virtual ~NzAbstractRenderTechnique(); virtual void Clear(const NzScene* scene) = 0; - virtual void Draw(const NzScene* scene) = 0; + virtual bool Draw(const NzScene* scene) = 0; virtual void EnableInstancing(bool instancing); + virtual NzString GetName() const; virtual NzAbstractRenderQueue* GetRenderQueue() = 0; + virtual nzRenderTechniqueType GetType() const = 0; virtual bool IsInstancingEnabled() const; diff --git a/include/Nazara/Graphics/Enums.hpp b/include/Nazara/Graphics/Enums.hpp index fadcb7949..f7b89bb70 100644 --- a/include/Nazara/Graphics/Enums.hpp +++ b/include/Nazara/Graphics/Enums.hpp @@ -26,6 +26,17 @@ enum nzLightType nzLightType_Max = nzLightType_Spot }; +enum nzRenderTechniqueType +{ + nzRenderTechniqueType_AdvancedForward, // NzAdvancedForwardRenderTechnique + nzRenderTechniqueType_BasicForward, // NzBasicForwardRenderTechnique + nzRenderTechniqueType_DeferredShading, // NzDeferredRenderTechnique + nzRenderTechniqueType_LightPrePass, // NzLightPrePassRenderTechnique + nzRenderTechniqueType_User, + + nzRenderTechniqueType_Max = nzRenderTechniqueType_User +}; + enum nzSceneNodeType { nzSceneNodeType_Light, // NzLight diff --git a/include/Nazara/Graphics/ForwardRenderTechnique.hpp b/include/Nazara/Graphics/ForwardRenderTechnique.hpp index 750823148..a0d5d98bd 100644 --- a/include/Nazara/Graphics/ForwardRenderTechnique.hpp +++ b/include/Nazara/Graphics/ForwardRenderTechnique.hpp @@ -21,10 +21,11 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique ~NzForwardRenderTechnique(); void Clear(const NzScene* scene); - void Draw(const NzScene* scene); + bool Draw(const NzScene* scene); unsigned int GetMaxLightsPerObject() const; NzAbstractRenderQueue* GetRenderQueue() override; + nzRenderTechniqueType GetType() const override; void SetMaxLightsPerObject(unsigned int lightCount); diff --git a/src/Nazara/Graphics/AbstractRenderTechnique.cpp b/src/Nazara/Graphics/AbstractRenderTechnique.cpp index 2d1bfdcd3..0d8cd751a 100644 --- a/src/Nazara/Graphics/AbstractRenderTechnique.cpp +++ b/src/Nazara/Graphics/AbstractRenderTechnique.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -30,6 +31,11 @@ void NzAbstractRenderTechnique::EnableInstancing(bool instancing) NazaraError("NazaraRenderer does not support instancing"); } +NzString NzAbstractRenderTechnique::GetName() const +{ + return NzRenderTechniques::ToString(GetType()); +} + bool NzAbstractRenderTechnique::IsInstancingEnabled() const { return m_instancingEnabled; diff --git a/src/Nazara/Graphics/ForwardRenderTechnique.cpp b/src/Nazara/Graphics/ForwardRenderTechnique.cpp index 5d861b871..abc73fe38 100644 --- a/src/Nazara/Graphics/ForwardRenderTechnique.cpp +++ b/src/Nazara/Graphics/ForwardRenderTechnique.cpp @@ -74,7 +74,7 @@ void NzForwardRenderTechnique::Clear(const NzScene* scene) background->Draw(scene); } -void NzForwardRenderTechnique::Draw(const NzScene* scene) +bool NzForwardRenderTechnique::Draw(const NzScene* scene) { m_directionalLights.SetLights(&m_renderQueue.directionalLights[0], m_renderQueue.directionalLights.size()); m_lights.SetLights(&m_renderQueue.lights[0], m_renderQueue.lights.size()); @@ -93,6 +93,8 @@ void NzForwardRenderTechnique::Draw(const NzScene* scene) for (const NzDrawable* drawable : m_renderQueue.otherDrawables) drawable->Draw(); + return true; + // Les billboards /*if (!m_renderQueue.billboards.empty()) { @@ -149,6 +151,11 @@ NzAbstractRenderQueue* NzForwardRenderTechnique::GetRenderQueue() return &m_renderQueue; } +nzRenderTechniqueType NzForwardRenderTechnique::GetType() const +{ + return nzRenderTechniqueType_BasicForward; +} + void NzForwardRenderTechnique::SetMaxLightsPerObject(unsigned int lightCount) { #if NAZARA_GRAPHICS_SAFE diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index 712d03a18..b7f74d920 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -33,6 +35,9 @@ bool NzGraphics::Initialize() // Loader générique NzLoaders_Mesh_Register(); + // RenderTechniques + NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_BasicForward), 0, []() -> NzAbstractRenderTechnique* { return new NzForwardRenderTechnique; }); + NazaraNotice("Initialized: Graphics module"); return true; diff --git a/src/Nazara/Graphics/Scene.cpp b/src/Nazara/Graphics/Scene.cpp index cc8ba216d..ff983b373 100644 --- a/src/Nazara/Graphics/Scene.cpp +++ b/src/Nazara/Graphics/Scene.cpp @@ -5,9 +5,10 @@ #include #include #include +#include #include #include -#include +#include #include #include #include @@ -34,6 +35,7 @@ struct NzSceneImpl bool update; float frameTime; float updateTime; + int renderTechniqueRanking; unsigned int updatePerSecond = 60; }; @@ -41,7 +43,7 @@ NzScene::NzScene() { m_impl = new NzSceneImpl(this); m_impl->background.reset(new NzColorBackground); - m_impl->renderTechnique.reset(new NzForwardRenderTechnique); + m_impl->renderTechnique.reset(NzRenderTechniques::GetByRanking(-1, &m_impl->renderTechniqueRanking)); } NzScene::~NzScene() @@ -94,9 +96,21 @@ void NzScene::Draw() } #endif - m_impl->renderTechnique->Clear(this); m_impl->viewer->ApplyView(); - m_impl->renderTechnique->Draw(this); + + try + { + NzErrorFlags errFlags(nzErrorFlag_ThrowException); + m_impl->renderTechnique->Clear(this); + m_impl->renderTechnique->Draw(this); + } + catch (const std::exception& e) + { + NzString oldName = m_impl->renderTechnique->GetName(); + m_impl->renderTechnique.reset(NzRenderTechniques::GetByRanking(m_impl->renderTechniqueRanking-1, &m_impl->renderTechniqueRanking)); + NazaraError("Render technique \"" + oldName + "\" failed, switched to \"" + m_impl->renderTechnique->GetName() + '"'); + return; + } } NzColor NzScene::GetAmbientColor() const diff --git a/src/Nazara/Graphics/SkyboxBackground.cpp b/src/Nazara/Graphics/SkyboxBackground.cpp index 5bc81583a..2fdc286fd 100644 --- a/src/Nazara/Graphics/SkyboxBackground.cpp +++ b/src/Nazara/Graphics/SkyboxBackground.cpp @@ -223,7 +223,6 @@ void NzSkyboxBackground::Draw(const NzScene* scene) const skyboxMatrix.SetTranslation(NzVector3f::Zero()); NzRenderer::SetIndexBuffer(m_indexBuffer); - NzRenderer::SetMatrix(nzMatrixType_Projection, viewer->GetProjectionMatrix()); NzRenderer::SetMatrix(nzMatrixType_View, skyboxMatrix); NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Scale(NzVector3f(viewer->GetZNear()))); NzRenderer::SetRenderStates(states); @@ -233,6 +232,8 @@ void NzSkyboxBackground::Draw(const NzScene* scene) const NzRenderer::SetVertexBuffer(m_vertexBuffer); NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, 36); + + NzRenderer::SetMatrix(nzMatrixType_View, viewer->GetViewMatrix()); } nzBackgroundType NzSkyboxBackground::GetBackgroundType() const