Added Shader::SendColor(Color)

Former-commit-id: e3af0e2cb75a437304ee274a6123114b41dd7d94
This commit is contained in:
Jérôme Leclercq 2012-11-08 14:25:48 +01:00
parent 7cc520be95
commit 94bb765a77
5 changed files with 44 additions and 4 deletions

View File

@ -8,6 +8,7 @@
#define NAZARA_SHADER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/String.hpp>
@ -51,6 +52,7 @@ 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);

View File

@ -318,6 +318,27 @@ bool NzGLSLShader::SendBoolean(int location, bool value)
return true;
}
bool NzGLSLShader::SendColor(int location, const NzColor& color)
{
NzVector3f vecColor(color.r/255.f, color.g/255.f, color.b/255.f);
if (glProgramUniform3fv)
glProgramUniform3fv(m_program, location, 1, vecColor);
else
{
if (!Lock())
{
NazaraError("Failed to lock shader");
return false;
}
glUniform3fv(location, 1, vecColor);
Unlock();
}
return true;
}
bool NzGLSLShader::SendDouble(int location, double value)
{
if (glProgramUniform1d)

View File

@ -41,6 +41,7 @@ class NzGLSLShader : public NzShaderImpl, NzResourceListener
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);

View File

@ -327,6 +327,25 @@ bool NzShader::SendBoolean(int location, bool value)
return m_impl->SendBoolean(location, value);
}
bool NzShader::SendColor(int location, const NzColor& color)
{
#if NAZARA_RENDERER_SAFE
if (!m_impl)
{
NazaraError("Shader not created");
return false;
}
if (location == -1)
{
NazaraError("Invalid location");
return false;
}
#endif
return m_impl->SendColor(location, color);
}
bool NzShader::SendDouble(int location, double value)
{
#if NAZARA_RENDERER_SAFE

View File

@ -9,10 +9,6 @@
#include <Nazara/Renderer/Shader.hpp>
class NzTexture;
class NzVertexBuffer;
class NzVertexDeclaration;
class NzShaderImpl
{
friend class NzRenderer;
@ -41,6 +37,7 @@ class NzShaderImpl
virtual bool Lock() = 0;
virtual bool SendBoolean(int location, bool value) = 0;
virtual bool SendColor(int location, const NzColor& color) = 0;
virtual bool SendDouble(int location, double value) = 0;
virtual bool SendFloat(int location, float value) = 0;
virtual bool SendInteger(int location, int value) = 0;