Commit 7aad66e6 authored by Frédéric Larue's avatar Frédéric Larue

Shader class now gives the possibility to set up arrays of samplers.

parent 3f884fad
......@@ -132,15 +132,60 @@ void GPU::Shader::RecoverActiveUniforms()
std::string name( nameBuffer );
if( type < GL_SAMPLER_1D_ARB || type > GL_SAMPLER_2D_RECT_SHADOW_ARB )
switch( type )
{
Uniform &unif = m_Uniforms[name];
unif.location = glGetUniformLocationARB( m_Id, nameBuffer );
unif.size = size;
unif.type = type;
case GL_SAMPLER_1D:
case GL_SAMPLER_2D:
case GL_SAMPLER_3D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_1D_SHADOW:
case GL_SAMPLER_2D_SHADOW:
case GL_SAMPLER_1D_ARRAY:
case GL_SAMPLER_2D_ARRAY:
case GL_SAMPLER_1D_ARRAY_SHADOW:
case GL_SAMPLER_2D_ARRAY_SHADOW:
case GL_SAMPLER_2D_MULTISAMPLE:
case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
case GL_SAMPLER_CUBE_SHADOW:
case GL_SAMPLER_BUFFER:
case GL_SAMPLER_2D_RECT:
case GL_SAMPLER_2D_RECT_SHADOW:
case GL_INT_SAMPLER_1D:
case GL_INT_SAMPLER_2D:
case GL_INT_SAMPLER_3D:
case GL_INT_SAMPLER_CUBE:
case GL_INT_SAMPLER_1D_ARRAY:
case GL_INT_SAMPLER_2D_ARRAY:
case GL_INT_SAMPLER_2D_MULTISAMPLE:
case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
case GL_INT_SAMPLER_BUFFER:
case GL_INT_SAMPLER_2D_RECT:
case GL_UNSIGNED_INT_SAMPLER_1D:
case GL_UNSIGNED_INT_SAMPLER_2D:
case GL_UNSIGNED_INT_SAMPLER_3D:
case GL_UNSIGNED_INT_SAMPLER_CUBE:
case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_BUFFER:
case GL_UNSIGNED_INT_SAMPLER_2D_RECT:
{
Uniform &smpl = m_Samplers[name];
smpl.location = glGetUniformLocationARB( m_Id, nameBuffer );
smpl.size = size;
smpl.type = type;
break;
}
default:
{
Uniform &unif = m_Uniforms[name];
unif.location = glGetUniformLocationARB( m_Id, nameBuffer );
unif.size = size;
unif.type = type;
break;
}
}
else
m_Samplers[name] = glGetUniformLocationARB( m_Id, nameBuffer );
}
}
......@@ -148,7 +193,7 @@ void GPU::Shader::RecoverActiveUniforms()
void GPU::Shader::RecoverActiveAttributes()
{
m_Attributes.clear();
GLint count;
GLcharARB nameBuffer[512];
......@@ -366,15 +411,15 @@ void GPU::Shader::SetUniform( const std::string& name,
void GPU::Shader::SetSampler( const std::string& name,
const GLint texUnit )
const GLint* texUnit )
{
SamplerMap::iterator s = m_Samplers.find( name );
UniformMap::iterator s = m_Samplers.find( name );
if( s != m_Samplers.end() )
{
GLuint activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB );
glUseProgramObjectARB( m_Id );
glUniform1iARB( s->second, texUnit );
glUniform1ivARB( s->second.location, s->second.size, (GLint*) texUnit );
glUseProgramObjectARB( activeProgBackup );
}
......
......@@ -122,7 +122,6 @@ namespace GPU
private:
typedef std::map<std::string,Uniform> UniformMap;
typedef std::map<std::string,GLint> SamplerMap;
typedef std::map<std::string,GLint> AttribMap;
typedef std::map<GLint,Texture*> SamplerBindingMap;
typedef std::map<GLint,VBOAttribBuffer*> AttribBindingMap;
......@@ -138,8 +137,8 @@ namespace GPU
GeomPg m_GeomPg;
UniformMap m_Uniforms;
UniformMap m_Samplers;
AttribMap m_Attributes;
SamplerMap m_Samplers;
SamplerBindingMap m_SamplerBinding;
/*****************************\
......@@ -186,8 +185,10 @@ namespace GPU
void SetUniform( const std::string& name,
const void *value );
inline void SetSampler( const std::string& name,
const GLint texUnit ) { SetSampler( name, &texUnit ); }
void SetSampler( const std::string& name,
const GLint texUnit );
const GLint* texUnit );
void SetAttrib( const std::string& name,
VBOAttribBuffer *attrib );
......@@ -202,8 +203,8 @@ namespace GPU
}
inline GLint SamplerLoc( const std::string& name ) const
{
SamplerMap::const_iterator s = m_Samplers.find( name );
return (s!=m_Samplers.end())? s->second : -1;
UniformMap::const_iterator s = m_Samplers.find( name );
return (s!=m_Samplers.end())? s->second.location : -1;
}
inline GLint AttribLoc( const std::string& name ) const
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment