Added new RenderTechnique system
Former-commit-id: 6d65a4537232bc705333c696f2478d47f16e074a
This commit is contained in:
parent
6e20e7095b
commit
0f382fd1ad
|
|
@ -9,7 +9,9 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Graphics/RenderTechniques.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/RenderTechniques.hpp>
|
||||
#include <Nazara/Graphics/Loaders/Mesh.hpp>
|
||||
#include <Nazara/Graphics/Loaders/OBJ.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@
|
|||
#include <Nazara/Graphics/Scene.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Graphics/Camera.hpp>
|
||||
#include <Nazara/Graphics/ColorBackground.hpp>
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/RenderTechniques.hpp>
|
||||
#include <Nazara/Graphics/SceneRoot.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <functional>
|
||||
|
|
@ -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,10 +96,22 @@ void NzScene::Draw()
|
|||
}
|
||||
#endif
|
||||
|
||||
m_impl->renderTechnique->Clear(this);
|
||||
m_impl->viewer->ApplyView();
|
||||
|
||||
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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue