From b075d05d82610d9aa3614b378688136b28d32720 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 26 May 2015 14:11:56 +0200 Subject: [PATCH] Graphics/RenderQueue: Replace AddLight method by variations Former-commit-id: 79ad49d60bd8d397aa606cded7c0dd2d20a078dc --- .../Nazara/Graphics/AbstractRenderQueue.hpp | 45 +++++++++++++++++-- .../Nazara/Graphics/DeferredRenderQueue.hpp | 5 --- .../Nazara/Graphics/ForwardRenderQueue.hpp | 4 -- src/Nazara/Graphics/AbstractRenderQueue.cpp | 22 +++++++++ src/Nazara/Graphics/DeferredRenderQueue.cpp | 35 +-------------- src/Nazara/Graphics/ForwardRenderQueue.cpp | 32 +------------ 6 files changed, 66 insertions(+), 77 deletions(-) diff --git a/include/Nazara/Graphics/AbstractRenderQueue.hpp b/include/Nazara/Graphics/AbstractRenderQueue.hpp index 367d6ec78..d6a66ef38 100644 --- a/include/Nazara/Graphics/AbstractRenderQueue.hpp +++ b/include/Nazara/Graphics/AbstractRenderQueue.hpp @@ -15,11 +15,10 @@ #include #include #include +#include class NzDrawable; -class NzLight; class NzMaterial; -class NzSprite; class NzTexture; struct NzMeshData; @@ -41,11 +40,49 @@ class NAZARA_API NzAbstractRenderQueue : NzNonCopyable virtual void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr positionPtr, NzSparsePtr sizePtr, NzSparsePtr anglePtr, NzSparsePtr colorPtr = nullptr) = 0; virtual void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr positionPtr, NzSparsePtr sizePtr, NzSparsePtr anglePtr, NzSparsePtr alphaPtr) = 0; virtual void AddDrawable(const NzDrawable* drawable) = 0; - virtual void AddLight(const NzLight* light) = 0; + virtual void AddDirectionalLight(const NzColor& color, float ambientFactor, float diffuseFactor, const NzVector3f& direction); virtual void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) = 0; + virtual void AddPointLight(const NzColor& color, float ambientFactor, float diffuseFactor, const NzVector3f& position, float radius, float attenuation); + virtual void AddSpotLight(const NzColor& color, float ambientFactor, float diffuseFactor, const NzVector3f& position, const NzVector3f& direction, float radius, float attenuation, float innerAngle, float outerAngle); virtual void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) = 0; - virtual void Clear(bool fully) = 0; + virtual void Clear(bool fully); + + protected: + struct DirectionalLight + { + NzColor color; + NzVector3f direction; + float ambientFactor; + float diffuseFactor; + }; + + struct PointLight + { + NzColor color; + NzVector3f position; + float ambientFactor; + float attenuation; + float diffuseFactor; + float radius; + }; + + struct SpotLight + { + NzColor color; + NzVector3f direction; + NzVector3f position; + float ambientFactor; + float attenuation; + float diffuseFactor; + float innerAngle; + float outerAngle; + float radius; + }; + + std::vector m_directionalLights; + std::vector m_pointLights; + std::vector m_spotLights; }; #endif // NAZARA_ABSTRACTRENDERQUEUE_HPP diff --git a/include/Nazara/Graphics/DeferredRenderQueue.hpp b/include/Nazara/Graphics/DeferredRenderQueue.hpp index 6b59462fc..84c8c4101 100644 --- a/include/Nazara/Graphics/DeferredRenderQueue.hpp +++ b/include/Nazara/Graphics/DeferredRenderQueue.hpp @@ -38,7 +38,6 @@ class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzObjectL void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr positionPtr, NzSparsePtr sizePtr, NzSparsePtr anglePtr, NzSparsePtr colorPtr = nullptr) override; void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr positionPtr, NzSparsePtr sizePtr, NzSparsePtr anglePtr, NzSparsePtr alphaPtr) override; void AddDrawable(const NzDrawable* drawable) override; - void AddLight(const NzLight* light) override; void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override; void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) override; @@ -83,12 +82,8 @@ class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzObjectL }; typedef std::map ModelBatches; - typedef std::vector LightContainer; ModelBatches opaqueModels; - LightContainer directionalLights; - LightContainer pointLights; - LightContainer spotLights; NzForwardRenderQueue* m_forwardQueue; private: diff --git a/include/Nazara/Graphics/ForwardRenderQueue.hpp b/include/Nazara/Graphics/ForwardRenderQueue.hpp index 9ac81b692..6cc002fa6 100644 --- a/include/Nazara/Graphics/ForwardRenderQueue.hpp +++ b/include/Nazara/Graphics/ForwardRenderQueue.hpp @@ -40,7 +40,6 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzObjectLi void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr positionPtr, NzSparsePtr sizePtr, NzSparsePtr anglePtr, NzSparsePtr colorPtr = nullptr) override; void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr positionPtr, NzSparsePtr sizePtr, NzSparsePtr anglePtr, NzSparsePtr alphaPtr) override; void AddDrawable(const NzDrawable* drawable) override; - void AddLight(const NzLight* light) override; void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override; void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) override; @@ -168,7 +167,6 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzObjectLi const NzMaterial* material; }; - typedef std::vector LightContainer; typedef std::vector TransparentModelContainer; BatchedBillboardContainer billboards; @@ -177,8 +175,6 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzObjectLi TransparentModelContainer transparentModels; std::vector transparentModelData; std::vector otherDrawables; - LightContainer directionalLights; - LightContainer lights; }; #endif // NAZARA_FORWARDRENDERQUEUE_HPP diff --git a/src/Nazara/Graphics/AbstractRenderQueue.cpp b/src/Nazara/Graphics/AbstractRenderQueue.cpp index 4ceea80f5..c3e2662f7 100644 --- a/src/Nazara/Graphics/AbstractRenderQueue.cpp +++ b/src/Nazara/Graphics/AbstractRenderQueue.cpp @@ -6,3 +6,25 @@ #include NzAbstractRenderQueue::~NzAbstractRenderQueue() = default; + +void NzAbstractRenderQueue::AddDirectionalLight(const NzColor& color, float ambientFactor, float diffuseFactor, const NzVector3f& direction) +{ + m_directionalLights.push_back(DirectionalLight{color, direction, ambientFactor, diffuseFactor}); +} + +void NzAbstractRenderQueue::AddPointLight(const NzColor& color, float ambientFactor, float diffuseFactor, const NzVector3f& position, float radius, float attenuation) +{ + m_pointLights.push_back(PointLight{color, position, ambientFactor, attenuation, diffuseFactor, radius}); +} + +void NzAbstractRenderQueue::AddSpotLight(const NzColor& color, float ambientFactor, float diffuseFactor, const NzVector3f& position, const NzVector3f& direction, float radius, float attenuation, float innerAngle, float outerAngle) +{ + m_spotLights.push_back(SpotLight{color, direction, position, ambientFactor, attenuation, diffuseFactor, innerAngle, outerAngle, radius}); +} + +void NzAbstractRenderQueue::Clear(bool fully) +{ + m_directionalLights.clear(); + m_pointLights.clear(); + m_spotLights.clear(); +} diff --git a/src/Nazara/Graphics/DeferredRenderQueue.cpp b/src/Nazara/Graphics/DeferredRenderQueue.cpp index 071178ad8..ceccdff52 100644 --- a/src/Nazara/Graphics/DeferredRenderQueue.cpp +++ b/src/Nazara/Graphics/DeferredRenderQueue.cpp @@ -75,37 +75,6 @@ void NzDeferredRenderQueue::AddDrawable(const NzDrawable* drawable) m_forwardQueue->AddDrawable(drawable); } -void NzDeferredRenderQueue::AddLight(const NzLight* light) -{ - #if NAZARA_GRAPHICS_SAFE - if (!light) - { - NazaraError("Invalid light"); - return; - } - #endif - - // On trie la lumière (elles sont traitées différement selon leur type) - switch (light->GetLightType()) - { - case nzLightType_Directional: - directionalLights.push_back(light); - break; - - case nzLightType_Point: - pointLights.push_back(light); - break; - - case nzLightType_Spot: - spotLights.push_back(light); - break; - } - - // On envoie également la lumière au forward-shading - ///TODO: Possibilité pour une lumière de se réserver au Deferred Shading - m_forwardQueue->AddLight(light); -} - void NzDeferredRenderQueue::AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) { if (material->IsEnabled(nzRendererParameter_Blend)) @@ -154,9 +123,7 @@ void NzDeferredRenderQueue::AddSprites(const NzMaterial* material, const NzVerte void NzDeferredRenderQueue::Clear(bool fully) { - directionalLights.clear(); - pointLights.clear(); - spotLights.clear(); + NzAbstractRenderQueue::Clear(fully); if (fully) opaqueModels.clear(); diff --git a/src/Nazara/Graphics/ForwardRenderQueue.cpp b/src/Nazara/Graphics/ForwardRenderQueue.cpp index 59d61a3df..d10e4317c 100644 --- a/src/Nazara/Graphics/ForwardRenderQueue.cpp +++ b/src/Nazara/Graphics/ForwardRenderQueue.cpp @@ -370,34 +370,6 @@ void NzForwardRenderQueue::AddDrawable(const NzDrawable* drawable) otherDrawables.push_back(drawable); } -void NzForwardRenderQueue::AddLight(const NzLight* light) -{ - #if NAZARA_GRAPHICS_SAFE - if (!light) - { - NazaraError("Invalid light"); - return; - } - #endif - - switch (light->GetLightType()) - { - case nzLightType_Directional: - directionalLights.push_back(light); - break; - - case nzLightType_Point: - case nzLightType_Spot: - lights.push_back(light); - break; - - #ifdef NAZARA_DEBUG - default: - NazaraError("Light type not handled (0x" + NzString::Number(light->GetLightType(), 16) + ')'); - #endif - } -} - void NzForwardRenderQueue::AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) { if (material->IsEnabled(nzRendererParameter_Blend)) @@ -481,8 +453,8 @@ void NzForwardRenderQueue::AddSprites(const NzMaterial* material, const NzVertex void NzForwardRenderQueue::Clear(bool fully) { - directionalLights.clear(); - lights.clear(); + NzAbstractRenderQueue::Clear(fully); + otherDrawables.clear(); transparentModels.clear(); transparentModelData.clear();