Graphics/RenderTechnique: Add uniform invalidation

Former-commit-id: 8f03073408a03854533d9911eb1a0605ebbb8767
This commit is contained in:
Lynix 2015-06-07 18:25:35 +02:00
parent 358fab7115
commit 0f4cf3c910
6 changed files with 36 additions and 4 deletions

View File

@ -25,9 +25,13 @@ class NAZARA_API NzDeferredGeometryPass : public NzDeferredRenderPass
struct ShaderUniforms;
const ShaderUniforms* GetShaderUniforms(const NzShader* shader) const;
void OnShaderInvalidated(const NzShader* shader) const;
struct ShaderUniforms
{
NazaraSlot(NzShader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
NazaraSlot(NzShader, OnShaderRelease, shaderReleaseSlot);
int eyePosition;
int sceneAmbient;
int textureOverlay;

View File

@ -11,6 +11,7 @@
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
#include <Nazara/Graphics/Light.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
@ -40,6 +41,7 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique
void DrawOpaqueModels(const NzScene* scene) const;
void DrawTransparentModels(const NzScene* scene) const;
const ShaderUniforms* GetShaderUniforms(const NzShader* shader) const;
void OnShaderInvalidated(const NzShader* shader) const;
void SendLightUniforms(const NzShader* shader, const NzLightUniforms& uniforms, unsigned int uniformOffset, unsigned int index) const;
static float ComputeDirectionalLightScore(const NzSpheref& object, const NzAbstractRenderQueue::DirectionalLight& light);
@ -58,6 +60,9 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique
struct ShaderUniforms
{
NazaraSlot(NzShader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
NazaraSlot(NzShader, OnShaderRelease, shaderReleaseSlot);
NzLightUniforms lightUniforms;
bool hasLightUniforms;

View File

@ -15,6 +15,7 @@
#include <Nazara/Core/ObjectListenerWrapper.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector2.hpp>
@ -102,6 +103,10 @@ class NAZARA_API NzShader : public NzRefCounted, NzNonCopyable
static bool IsStageSupported(nzShaderStage stage);
template<typename... Args> static NzShaderRef New(Args&&... args);
// Signals
NazaraSignal(OnShaderRelease, const NzShader*); //< Args: me
NazaraSignal(OnShaderUniformInvalidated, const NzShader*); //< Args: me
private:
bool PostLinkage();

View File

@ -240,12 +240,20 @@ const NzDeferredGeometryPass::ShaderUniforms* NzDeferredGeometryPass::GetShaderU
if (it == m_shaderUniforms.end())
{
ShaderUniforms uniforms;
uniforms.shaderReleaseSlot.Connect(shader->OnShaderRelease, this, OnShaderInvalidated);
uniforms.shaderUniformInvalidatedSlot.Connect(shader->OnShaderUniformInvalidated, this, OnShaderInvalidated);
uniforms.eyePosition = shader->GetUniformLocation("EyePosition");
uniforms.sceneAmbient = shader->GetUniformLocation("SceneAmbient");
uniforms.textureOverlay = shader->GetUniformLocation("TextureOverlay");
it = m_shaderUniforms.emplace(shader, uniforms).first;
it = m_shaderUniforms.emplace(shader, std::move(uniforms)).first;
}
return &it->second;
}
void NzDeferredGeometryPass::OnShaderInvalidated(const NzShader* shader) const
{
m_shaderUniforms.erase(shader);
}

View File

@ -21,8 +21,6 @@
#include <memory>
#include <Nazara/Graphics/Debug.hpp>
///TODO: Surveiller les shaders et supprimer les données uniformes en cas de changement (recompilation/destruction)
namespace
{
struct BillboardPoint
@ -738,6 +736,9 @@ const NzForwardRenderTechnique::ShaderUniforms* NzForwardRenderTechnique::GetSha
if (it == m_shaderUniforms.end())
{
ShaderUniforms uniforms;
uniforms.shaderReleaseSlot.Connect(shader->OnShaderRelease, this, OnShaderInvalidated);
uniforms.shaderUniformInvalidatedSlot.Connect(shader->OnShaderUniformInvalidated, this, OnShaderInvalidated);
uniforms.eyePosition = shader->GetUniformLocation("EyePosition");
uniforms.sceneAmbient = shader->GetUniformLocation("SceneAmbient");
uniforms.textureOverlay = shader->GetUniformLocation("TextureOverlay");
@ -760,12 +761,17 @@ const NzForwardRenderTechnique::ShaderUniforms* NzForwardRenderTechnique::GetSha
else
uniforms.hasLightUniforms = false;
it = m_shaderUniforms.emplace(shader, uniforms).first;
it = m_shaderUniforms.emplace(shader, std::move(uniforms)).first;
}
return &it->second;
}
void NzForwardRenderTechnique::OnShaderInvalidated(const NzShader* shader) const
{
m_shaderUniforms.erase(shader);
}
NzIndexBuffer NzForwardRenderTechnique::s_quadIndexBuffer;
NzVertexBuffer NzForwardRenderTechnique::s_quadVertexBuffer;
NzVertexDeclaration NzForwardRenderTechnique::s_billboardInstanceDeclaration;

View File

@ -18,6 +18,8 @@ m_program(0)
NzShader::~NzShader()
{
OnShaderRelease(this);
Destroy();
}
@ -779,6 +781,8 @@ bool NzShader::PostLinkage()
#undef CacheUniform
OnShaderUniformInvalidated(this);
return true;
}
else