From eb585116b1aba55a0536a19d03979f25b95db8c7 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 8 Dec 2012 11:49:07 +0100 Subject: [PATCH] Shader::SendTexture can now return texture unit Former-commit-id: 38d5e5dedf94113933bb2090040feec602a4716c --- include/Nazara/Renderer/Shader.hpp | 2 +- src/Nazara/Renderer/GLSLShader.cpp | 14 ++++++++++---- src/Nazara/Renderer/GLSLShader.hpp | 2 +- src/Nazara/Renderer/Shader.cpp | 4 ++-- src/Nazara/Renderer/ShaderImpl.hpp | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/Nazara/Renderer/Shader.hpp b/include/Nazara/Renderer/Shader.hpp index 7e3b9c4f4..8d25b964f 100644 --- a/include/Nazara/Renderer/Shader.hpp +++ b/include/Nazara/Renderer/Shader.hpp @@ -58,7 +58,7 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable 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); + 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); diff --git a/src/Nazara/Renderer/GLSLShader.cpp b/src/Nazara/Renderer/GLSLShader.cpp index 79fd60388..27d5d29cf 100644 --- a/src/Nazara/Renderer/GLSLShader.cpp +++ b/src/Nazara/Renderer/GLSLShader.cpp @@ -430,7 +430,7 @@ bool NzGLSLShader::SendMatrix(int location, const NzMatrix4f& matrix) return true; } -bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) +bool NzGLSLShader::SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit) { auto it = m_textures.find(location); if (it != m_textures.end()) @@ -451,6 +451,9 @@ bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) else m_textures.erase(it); // On supprime le slot } + + if (textureUnit) + *textureUnit = slot.unit; } else { @@ -493,9 +496,6 @@ bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) slot.enabled = texture->IsValid(); slot.unit = unit; slot.texture = texture; - texture->AddResourceListener(this, location); - - m_textures[location] = slot; if (slot.enabled) { @@ -513,6 +513,12 @@ bool NzGLSLShader::SendTexture(int location, const NzTexture* texture) Unlock(); } } + + m_textures[location] = slot; + texture->AddResourceListener(this, location); + + if (textureUnit) + *textureUnit = unit; } return true; diff --git a/src/Nazara/Renderer/GLSLShader.hpp b/src/Nazara/Renderer/GLSLShader.hpp index d816f82f8..6e15d701d 100644 --- a/src/Nazara/Renderer/GLSLShader.hpp +++ b/src/Nazara/Renderer/GLSLShader.hpp @@ -47,7 +47,7 @@ class NzGLSLShader : public NzShaderImpl, NzResourceListener 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); + 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); diff --git a/src/Nazara/Renderer/Shader.cpp b/src/Nazara/Renderer/Shader.cpp index 1e38b1420..d27dbcda8 100644 --- a/src/Nazara/Renderer/Shader.cpp +++ b/src/Nazara/Renderer/Shader.cpp @@ -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) +bool NzShader::SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit) { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -461,7 +461,7 @@ bool NzShader::SendTexture(int location, const NzTexture* texture) } #endif - return m_impl->SendTexture(location, texture); + return m_impl->SendTexture(location, texture, textureUnit); } bool NzShader::SendVector(int location, const NzVector2d& vector) diff --git a/src/Nazara/Renderer/ShaderImpl.hpp b/src/Nazara/Renderer/ShaderImpl.hpp index 939c39756..39970652d 100644 --- a/src/Nazara/Renderer/ShaderImpl.hpp +++ b/src/Nazara/Renderer/ShaderImpl.hpp @@ -43,7 +43,7 @@ class NzShaderImpl virtual bool SendInteger(int location, int value) = 0; virtual bool SendMatrix(int location, const NzMatrix4d& matrix) = 0; virtual bool SendMatrix(int location, const NzMatrix4f& matrix) = 0; - virtual bool SendTexture(int location, const NzTexture* texture) = 0; + virtual bool SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit = nullptr) = 0; virtual bool SendVector(int location, const NzVector2d& vector) = 0; virtual bool SendVector(int location, const NzVector2f& vector) = 0; virtual bool SendVector(int location, const NzVector3d& vector) = 0;