From c65e3d5defce51609aff485a85e2adc1f15ff2e2 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 25 Dec 2012 12:26:40 +0100 Subject: [PATCH] It is now possible to use const shaders A non-constant shader is no longer required to bind or to send uniform Former-commit-id: 8fd7c03b65a2d9fcea69516c023fee034299148c --- include/Nazara/Renderer/Renderer.hpp | 4 ++-- include/Nazara/Renderer/Shader.hpp | 28 ++++++++++++++-------------- src/Nazara/Renderer/DebugDrawer.cpp | 4 ++-- src/Nazara/Renderer/Material.cpp | 2 +- src/Nazara/Renderer/Renderer.cpp | 6 +++--- src/Nazara/Renderer/Shader.cpp | 28 ++++++++++++++-------------- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/include/Nazara/Renderer/Renderer.hpp b/include/Nazara/Renderer/Renderer.hpp index 6679ee730..09e84eae3 100644 --- a/include/Nazara/Renderer/Renderer.hpp +++ b/include/Nazara/Renderer/Renderer.hpp @@ -44,7 +44,7 @@ class NAZARA_API NzRenderer static unsigned int GetMaxRenderTargets(); static unsigned int GetMaxTextureUnits(); static float GetPointSize(); - static NzShader* GetShader(); + static const NzShader* GetShader(); static NzRenderTarget* GetTarget(); static NzRectui GetViewport(); @@ -67,7 +67,7 @@ class NAZARA_API NzRenderer static void SetLineWidth(float size); static void SetMatrix(nzMatrixType type, const NzMatrix4f& matrix); static void SetPointSize(float size); - static bool SetShader(NzShader* shader); + static bool SetShader(const NzShader* shader); static void SetStencilCompareFunction(nzRendererComparison compareFunc); static void SetStencilFailOperation(nzStencilOperation failOperation); static void SetStencilMask(nzUInt32 mask); diff --git a/include/Nazara/Renderer/Shader.hpp b/include/Nazara/Renderer/Shader.hpp index 8d25b964f..194b86de8 100644 --- a/include/Nazara/Renderer/Shader.hpp +++ b/include/Nazara/Renderer/Shader.hpp @@ -51,20 +51,20 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable bool Lock(); - bool SendBoolean(int location, bool value); - bool SendColor(int location, const NzColor& color); - bool SendDouble(int location, double value); - bool SendFloat(int location, float value); - bool SendInteger(int location, int value); - bool SendMatrix(int location, const NzMatrix4d& matrix); - bool SendMatrix(int location, const NzMatrix4f& matrix); - bool SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit = nullptr); - bool SendVector(int location, const NzVector2d& vector); - bool SendVector(int location, const NzVector2f& vector); - bool SendVector(int location, const NzVector3d& vector); - bool SendVector(int location, const NzVector3f& vector); - bool SendVector(int location, const NzVector4d& vector); - bool SendVector(int location, const NzVector4f& vector); + bool SendBoolean(int location, bool value) const; + bool SendColor(int location, const NzColor& color) const; + bool SendDouble(int location, double value) const; + bool SendFloat(int location, float value) const; + bool SendInteger(int location, int value) const; + bool SendMatrix(int location, const NzMatrix4d& matrix) const; + bool SendMatrix(int location, const NzMatrix4f& matrix) const; + bool SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit = nullptr) const; + bool SendVector(int location, const NzVector2d& vector) const; + bool SendVector(int location, const NzVector2f& vector) const; + bool SendVector(int location, const NzVector3d& vector) const; + bool SendVector(int location, const NzVector3f& vector) const; + bool SendVector(int location, const NzVector4d& vector) const; + bool SendVector(int location, const NzVector4f& vector) const; void Unlock(); diff --git a/src/Nazara/Renderer/DebugDrawer.cpp b/src/Nazara/Renderer/DebugDrawer.cpp index 2db643949..8f0474a4a 100644 --- a/src/Nazara/Renderer/DebugDrawer.cpp +++ b/src/Nazara/Renderer/DebugDrawer.cpp @@ -124,7 +124,7 @@ void NzDebugDrawer::Draw(const NzCubef& cube) if (!vertexBuffer->Unmap()) NazaraWarning("Failed to unmap buffer"); - NzShader* oldShader = NzRenderer::GetShader(); + const NzShader* oldShader = NzRenderer::GetShader(); if (!NzRenderer::SetShader(shader)) { @@ -198,7 +198,7 @@ void NzDebugDrawer::Draw(const NzSkeleton* skeleton) if (vertexCount > 0) { - NzShader* oldShader = NzRenderer::GetShader(); + const NzShader* oldShader = NzRenderer::GetShader(); if (!NzRenderer::SetShader(shader)) { diff --git a/src/Nazara/Renderer/Material.cpp b/src/Nazara/Renderer/Material.cpp index 6ae220351..7bdbe6064 100644 --- a/src/Nazara/Renderer/Material.cpp +++ b/src/Nazara/Renderer/Material.cpp @@ -30,7 +30,7 @@ NzMaterial::~NzMaterial() void NzMaterial::Apply() const { - NzShader* shader = NzRenderer::GetShader(); + const NzShader* shader = NzRenderer::GetShader(); #if NAZARA_RENDERER_SAFE if (!shader) { diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 88270570f..772e04b4e 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -76,7 +76,7 @@ namespace nzUInt32 s_stencilMask; const NzIndexBuffer* s_indexBuffer; NzRenderTarget* s_target; - NzShader* s_shader; + const NzShader* s_shader; const NzVertexBuffer* s_vertexBuffer; const NzVertexDeclaration* s_vertexDeclaration; bool s_vaoUpdated; @@ -322,7 +322,7 @@ float NzRenderer::GetPointSize() return pointSize; } -NzShader* NzRenderer::GetShader() +const NzShader* NzRenderer::GetShader() { return s_shader; } @@ -742,7 +742,7 @@ void NzRenderer::SetPointSize(float size) glPointSize(size); } -bool NzRenderer::SetShader(NzShader* shader) +bool NzRenderer::SetShader(const NzShader* shader) { if (s_shader == shader) return true; diff --git a/src/Nazara/Renderer/Shader.cpp b/src/Nazara/Renderer/Shader.cpp index d27dbcda8..c1680b3ba 100644 --- a/src/Nazara/Renderer/Shader.cpp +++ b/src/Nazara/Renderer/Shader.cpp @@ -300,7 +300,7 @@ bool NzShader::Lock() return m_impl->Lock(); } -bool NzShader::SendBoolean(int location, bool value) +bool NzShader::SendBoolean(int location, bool value) const { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -319,7 +319,7 @@ bool NzShader::SendBoolean(int location, bool value) return m_impl->SendBoolean(location, value); } -bool NzShader::SendColor(int location, const NzColor& color) +bool NzShader::SendColor(int location, const NzColor& color) const { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -338,7 +338,7 @@ bool NzShader::SendColor(int location, const NzColor& color) return m_impl->SendColor(location, color); } -bool NzShader::SendDouble(int location, double value) +bool NzShader::SendDouble(int location, double value) const { #if NAZARA_RENDERER_SAFE if (!NzRenderer::HasCapability(nzRendererCap_FP64)) @@ -363,7 +363,7 @@ bool NzShader::SendDouble(int location, double value) return m_impl->SendDouble(location, value); } -bool NzShader::SendFloat(int location, float value) +bool NzShader::SendFloat(int location, float value) const { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -382,7 +382,7 @@ bool NzShader::SendFloat(int location, float value) return m_impl->SendFloat(location, value); } -bool NzShader::SendInteger(int location, int value) +bool NzShader::SendInteger(int location, int value) const { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -401,7 +401,7 @@ bool NzShader::SendInteger(int location, int value) return m_impl->SendInteger(location, value); } -bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) +bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) const { #if NAZARA_RENDERER_SAFE if (!NzRenderer::HasCapability(nzRendererCap_FP64)) @@ -426,7 +426,7 @@ bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) return m_impl->SendMatrix(location, matrix); } -bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix) +bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix) const { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -445,7 +445,7 @@ bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix) return m_impl->SendMatrix(location, matrix); } -bool NzShader::SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit) +bool NzShader::SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit) const { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -464,7 +464,7 @@ bool NzShader::SendTexture(int location, const NzTexture* texture, nzUInt8* text return m_impl->SendTexture(location, texture, textureUnit); } -bool NzShader::SendVector(int location, const NzVector2d& vector) +bool NzShader::SendVector(int location, const NzVector2d& vector) const { #if NAZARA_RENDERER_SAFE if (!NzRenderer::HasCapability(nzRendererCap_FP64)) @@ -489,7 +489,7 @@ bool NzShader::SendVector(int location, const NzVector2d& vector) return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(int location, const NzVector2f& vector) +bool NzShader::SendVector(int location, const NzVector2f& vector) const { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -508,7 +508,7 @@ bool NzShader::SendVector(int location, const NzVector2f& vector) return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(int location, const NzVector3d& vector) +bool NzShader::SendVector(int location, const NzVector3d& vector) const { #if NAZARA_RENDERER_SAFE if (!NzRenderer::HasCapability(nzRendererCap_FP64)) @@ -533,7 +533,7 @@ bool NzShader::SendVector(int location, const NzVector3d& vector) return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(int location, const NzVector3f& vector) +bool NzShader::SendVector(int location, const NzVector3f& vector) const { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -552,7 +552,7 @@ bool NzShader::SendVector(int location, const NzVector3f& vector) return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(int location, const NzVector4d& vector) +bool NzShader::SendVector(int location, const NzVector4d& vector) const { #if NAZARA_RENDERER_SAFE if (!NzRenderer::HasCapability(nzRendererCap_FP64)) @@ -577,7 +577,7 @@ bool NzShader::SendVector(int location, const NzVector4d& vector) return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(int location, const NzVector4f& vector) +bool NzShader::SendVector(int location, const NzVector4f& vector) const { #if NAZARA_RENDERER_SAFE if (!m_impl)