Commit c43ad4fd authored by Frédéric Larue's avatar Frédéric Larue

gpuAssert function added to the GPU module in order to track possible GL errors in debug mode.

parent 5ffe4bb5
......@@ -57,7 +57,7 @@ namespace GPU
inline void SetAlignment( GLenum alignParam, unsigned int stride )
{
static const int alignment[8] = { 8, 1, 2, 1, 4, 1, 2, 1 };
glPixelStorei( alignParam, alignment[stride & 7] );
gpuAssert( glPixelStorei( alignParam, alignment[stride & 7] ) );
}
inline void SetPackAlignment( unsigned int stride )
......
......@@ -14,14 +14,14 @@
bool GPU::RenderBuffer::Allocate()
{
glGenRenderbuffersEXT( 1, &m_Id );
gpuAssert( glGenRenderbuffersEXT( 1, &m_Id ) );
return m_Id != 0;
}
bool GPU::RenderBuffer::Unallocate()
{
glDeleteRenderbuffersEXT( 1, &m_Id );
gpuAssert( glDeleteRenderbuffersEXT( 1, &m_Id ) );
m_Id = 0;
return true;
}
......@@ -34,9 +34,9 @@ bool GPU::RenderBuffer::Create( const GLenum internalFormats[],
if( w && h && Instantiate() )
{
GLint prevBuffer;
glGetIntegerv( GL_RENDERBUFFER_BINDING, &prevBuffer );
gpuAssert( glGetIntegerv( GL_RENDERBUFFER_BINDING, &prevBuffer ) );
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_Id );
gpuAssert( glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_Id ) );
int currentFormatId = -1;
GLint isSupported;
......@@ -46,26 +46,28 @@ bool GPU::RenderBuffer::Create( const GLenum internalFormats[],
{
m_Width = m_Height = 0;
std::cout << "RenderBuffer error - specified internal format(s) not supported." << std::endl;
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, prevBuffer );
gpuAssert( glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, prevBuffer ) );
return false;
}
if( glGetInternalformativ )
glGetInternalformativ( GL_RENDERBUFFER, internalFormats[currentFormatId], GL_INTERNALFORMAT_SUPPORTED, 1, &isSupported );
{
gpuAssert( glGetInternalformativ( GL_RENDERBUFFER, internalFormats[currentFormatId], GL_INTERNALFORMAT_SUPPORTED, 1, &isSupported ) );
}
else
{
glGetError();
glRenderbufferStorageEXT( GL_RENDERBUFFER, internalFormats[currentFormatId], w, h );
isSupported = glGetError() == GL_NO_ERROR;
isSupported = (glGetError() == GL_NO_ERROR);
}
} while( !isSupported );
glRenderbufferStorageEXT( GL_RENDERBUFFER, internalFormats[currentFormatId], w, h );
gpuAssert( glRenderbufferStorageEXT( GL_RENDERBUFFER, internalFormats[currentFormatId], w, h ) );
m_Width = w;
m_Height = h;
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, prevBuffer );
gpuAssert( glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, prevBuffer ) );
return true;
}
......@@ -79,10 +81,10 @@ GLint GPU::RenderBuffer::InternalFormat() const
if( m_Id )
{
GLint prevBuffer;
glGetIntegerv( GL_RENDERBUFFER_BINDING, &prevBuffer );
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_Id );
glGetRenderbufferParameterivEXT( GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_INTERNAL_FORMAT, &format );
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, prevBuffer );
gpuAssert( glGetIntegerv( GL_RENDERBUFFER_BINDING, &prevBuffer ) );
gpuAssert( glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_Id ) );
gpuAssert( glGetRenderbufferParameterivEXT( GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_INTERNAL_FORMAT, &format ) );
gpuAssert( glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, prevBuffer ) );
}
return format;
}
......@@ -99,12 +101,12 @@ bool GPU::FrameBuffer::Create( const unsigned int w,
m_Height = h;
GLint prevBuffer;
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prevBuffer );
gpuAssert( glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prevBuffer ) );
glGenFramebuffersEXT( 1, &m_Id );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id );
gpuAssert( glGenFramebuffersEXT( 1, &m_Id ) );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id ) );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, prevBuffer );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, prevBuffer ) );
return true;
}
......@@ -120,7 +122,7 @@ void GPU::FrameBuffer::Release()
m_Buffers.clear();
m_EnabledBuffers.clear();
glDeleteFramebuffersEXT( 1, &m_Id );
gpuAssert( glDeleteFramebuffersEXT( 1, &m_Id ) );
m_Id = 0;
}
}
......@@ -153,15 +155,15 @@ bool GPU::FrameBuffer::Attach( const GLuint attachment,
Detach( attachment );
GLint prevBuffer;
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prevBuffer );
gpuAssert( glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prevBuffer ) );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id );
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, attachment, GL_RENDERBUFFER, buff.Id() );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id ) );
gpuAssert( glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, attachment, GL_RENDERBUFFER, buff.Id() ) );
m_Buffers[ attachment ] = new RenderBuffer( buff );
Enable( attachment );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, prevBuffer );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, prevBuffer ) );
return true;
}
......@@ -180,15 +182,15 @@ bool GPU::FrameBuffer::Attach( const GLuint attachment,
Detach( attachment );
GLint prevBuffer;
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prevBuffer );
gpuAssert( glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prevBuffer ) );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id );
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, tex.Id(), 0 );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id ) );
gpuAssert( glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, tex.Id(), 0 ) );
m_Buffers[ attachment ] = new Texture2D( tex );
Enable( attachment );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, prevBuffer );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, prevBuffer ) );
return true;
}
......@@ -208,15 +210,15 @@ bool GPU::FrameBuffer::Attach( const GLuint attachment,
Detach( attachment );
GLint prevBuffer;
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prevBuffer );
gpuAssert( glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prevBuffer ) );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id );
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment, targetCubeFace, tex.Id(), 0 );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id ) );
gpuAssert( glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment, targetCubeFace, tex.Id(), 0 ) );
m_Buffers[ attachment ] = new TextureCube( tex );
Enable( attachment );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, prevBuffer );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, prevBuffer ) );
return true;
}
......@@ -266,24 +268,28 @@ void GPU::FrameBuffer::Disable( const GLuint attachment )
void GPU::FrameBuffer::Bind() const
{
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &m_PrevBuffer );
glGetIntegerv( GL_VIEWPORT, m_PrevViewport );
gpuAssert( glGetIntegerv( GL_FRAMEBUFFER_BINDING, &m_PrevBuffer ) );
gpuAssert( glGetIntegerv( GL_VIEWPORT, m_PrevViewport ) );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id ) );
if( !m_EnabledBuffers.empty() )
glDrawBuffersARB( (GLsizei) m_EnabledBuffers.size(), &m_EnabledBuffers.front() );
{
gpuAssert( glDrawBuffersARB( (GLsizei) m_EnabledBuffers.size(), &m_EnabledBuffers.front() ) );
}
else
glDrawBuffersARB( 0, NULL );
{
gpuAssert( glDrawBuffersARB( 0, NULL ) );
}
glViewport( 0, 0, m_Width, m_Height );
gpuAssert( glViewport( 0, 0, m_Width, m_Height ) );
}
void GPU::FrameBuffer::Unbind() const
{
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_PrevBuffer );
glViewport( m_PrevViewport[0], m_PrevViewport[1], m_PrevViewport[2], m_PrevViewport[3] );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_PrevBuffer ) );
gpuAssert( glViewport( m_PrevViewport[0], m_PrevViewport[1], m_PrevViewport[2], m_PrevViewport[3] ) );
}
......@@ -299,18 +305,18 @@ bool GPU::FrameBuffer::DumpTo( const GLuint attachment,
{
// Read data from the buffer into which the mask has been painted.
GLint prevBuffer, prevAlignment;
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prevBuffer );
glGetIntegerv( GL_PACK_ALIGNMENT, &prevAlignment );
gpuAssert( glGetIntegerv( GL_FRAMEBUFFER_BINDING, &prevBuffer ) );
gpuAssert( glGetIntegerv( GL_PACK_ALIGNMENT, &prevAlignment ) );
const int alignment[8] = { 8, 1, 2, 1, 4, 1, 2, 1 };
glPixelStorei( GL_PACK_ALIGNMENT, alignment[stride & 7] );
gpuAssert( glPixelStorei( GL_PACK_ALIGNMENT, alignment[stride & 7] ) );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id );
glReadBuffer( attachment );
glReadPixels( x, y, w, h, format, type, buffer );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_Id ) );
gpuAssert( glReadBuffer( attachment ) );
gpuAssert( glReadPixels( x, y, w, h, format, type, buffer ) );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, prevBuffer );
glPixelStorei( GL_PACK_ALIGNMENT, prevAlignment );
gpuAssert( glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, prevBuffer ) );
gpuAssert( glPixelStorei( GL_PACK_ALIGNMENT, prevAlignment ) );
return true;
}
......
......@@ -11,3 +11,27 @@
#include <windows.h>
#endif
#include <GL/gl.h>
#ifdef NDEBUG
#define gpuAssert( expression ) expression
#else
#include <assert.h>
#include <stdio.h>
#define gpuAssert( expression ) \
{ \
expression; \
GLenum err = glGetError(); \
if( err != GL_NO_ERROR ) \
{ \
const GLubyte* errStr = glewGetErrorString( err ); \
printf( "gpuAssert( %s ): %s\n", #expression, errStr ); \
assert( err == GL_NO_ERROR ); \
} \
}
#endif
\ No newline at end of file
......@@ -18,14 +18,14 @@
bool GPU::Shader::PgObject::Allocate()
{
m_Id = glCreateShaderObjectARB( m_PgType );
gpuAssert( m_Id = glCreateShaderObjectARB( m_PgType ) );
return m_Id != 0;
}
bool GPU::Shader::PgObject::Unallocate()
{
glDeleteObjectARB( m_Id );
gpuAssert( glDeleteObjectARB( m_Id ) );
m_Id = 0;
return true;
}
......@@ -69,12 +69,12 @@ bool GPU::Shader::PgObject::CompileSrcString( const char *sourceString,
if( Instantiate() )
{
// Create the shader object.
glShaderSourceARB ( m_Id, 1, (const GLcharARB**) &sourceString, NULL );
glCompileShaderARB( m_Id );
gpuAssert( glShaderSourceARB ( m_Id, 1, (const GLcharARB**) &sourceString, NULL ) );
gpuAssert( glCompileShaderARB( m_Id ) );
// Check the compilation status.
GLint status;
glGetObjectParameterivARB( m_Id, GL_OBJECT_COMPILE_STATUS_ARB, &status );
gpuAssert( glGetObjectParameterivARB( m_Id, GL_OBJECT_COMPILE_STATUS_ARB, &status ) );
if( status )
return true;
......@@ -93,11 +93,11 @@ bool GPU::Shader::PgObject::CompileSrcString( const char *sourceString,
std::string GPU::Shader::GetLogs( GLuint pgId )
{
GLint logLength;
glGetObjectParameterivARB( pgId, GL_OBJECT_INFO_LOG_LENGTH_ARB, &logLength );
gpuAssert( glGetObjectParameterivARB( pgId, GL_OBJECT_INFO_LOG_LENGTH_ARB, &logLength ) );
std::string infoLog;
infoLog.resize( logLength );
glGetInfoLogARB( pgId, logLength, &logLength, &infoLog[0] );
gpuAssert( glGetInfoLogARB( pgId, logLength, &logLength, &infoLog[0] ) );
return infoLog;
}
......@@ -112,7 +112,7 @@ void GPU::Shader::RecoverActiveUniforms()
GLint count;
GLcharARB nameBuffer[512];
glGetObjectParameterivARB( m_Id, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &count );
gpuAssert( glGetObjectParameterivARB( m_Id, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &count ) );
for( GLint i=0; i<count; ++i )
{
......@@ -120,7 +120,7 @@ void GPU::Shader::RecoverActiveUniforms()
GLint size;
GLenum type;
glGetActiveUniformARB(
gpuAssert( glGetActiveUniformARB(
m_Id,
i,
sizeof(nameBuffer),
......@@ -128,7 +128,7 @@ void GPU::Shader::RecoverActiveUniforms()
&size,
&type,
nameBuffer
);
) );
std::string name( nameBuffer );
......@@ -172,7 +172,7 @@ void GPU::Shader::RecoverActiveUniforms()
case GL_UNSIGNED_INT_SAMPLER_2D_RECT:
{
Uniform &smpl = m_Samplers[name];
smpl.location = glGetUniformLocationARB( m_Id, nameBuffer );
gpuAssert( smpl.location = glGetUniformLocationARB( m_Id, nameBuffer ) );
smpl.size = size;
smpl.type = type;
break;
......@@ -180,7 +180,7 @@ void GPU::Shader::RecoverActiveUniforms()
default:
{
Uniform &unif = m_Uniforms[name];
unif.location = glGetUniformLocationARB( m_Id, nameBuffer );
gpuAssert( unif.location = glGetUniformLocationARB( m_Id, nameBuffer ) );
unif.size = size;
unif.type = type;
break;
......@@ -197,7 +197,7 @@ void GPU::Shader::RecoverActiveAttributes()
GLint count;
GLcharARB nameBuffer[512];
glGetObjectParameterivARB( m_Id, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &count );
gpuAssert( glGetObjectParameterivARB( m_Id, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &count ) );
for( GLint i=0; i<count; ++i )
{
......@@ -205,7 +205,7 @@ void GPU::Shader::RecoverActiveAttributes()
GLint size;
GLenum type;
glGetActiveAttribARB(
gpuAssert( glGetActiveAttribARB(
m_Id,
i,
sizeof(nameBuffer),
......@@ -213,9 +213,10 @@ void GPU::Shader::RecoverActiveAttributes()
&size,
&type,
nameBuffer
);
) );
GLint attribId = glGetAttribLocationARB( m_Id, nameBuffer );
GLint attribId;
gpuAssert( attribId = glGetAttribLocationARB( m_Id, nameBuffer ) );
if( attribId != -1 )
m_Attributes[ std::string(nameBuffer) ] = attribId;
}
......@@ -224,29 +225,33 @@ void GPU::Shader::RecoverActiveAttributes()
bool GPU::Shader::Link( std::string *logs )
{
if( !m_Id && !(m_Id = glCreateProgramObjectARB()) )
return false;
if( !m_Id )
{
gpuAssert( m_Id = glCreateProgramObjectARB() );
if( !m_Id )
return false;
}
if( m_VertPg.IsInstantiated() )
glAttachObjectARB( m_Id, m_VertPg.Id() );
gpuAssert( glAttachObjectARB( m_Id, m_VertPg.Id() ) );
if( m_FragPg.IsInstantiated() )
glAttachObjectARB( m_Id, m_FragPg.Id() );
gpuAssert( glAttachObjectARB( m_Id, m_FragPg.Id() ) );
if( m_GeomPg.IsInstantiated() )
glAttachObjectARB( m_Id, m_GeomPg.Id() );
gpuAssert( glAttachObjectARB( m_Id, m_GeomPg.Id() ) );
glLinkProgramARB( m_Id );
gpuAssert( glLinkProgramARB( m_Id ) );
GLint status;
glGetObjectParameterivARB( m_Id, GL_OBJECT_LINK_STATUS_ARB, &status );
gpuAssert( glGetObjectParameterivARB( m_Id, GL_OBJECT_LINK_STATUS_ARB, &status ) );
if( !status )
{
if( logs )
*logs = GetLogs( m_Id );
glDeleteObjectARB( m_Id );
gpuAssert( glDeleteObjectARB( m_Id ) );
m_Id = 0;
return false;
......@@ -268,21 +273,21 @@ GPU::Shader& GPU::Shader::Attach( const PgObject &pg )
case GL_VERTEX_SHADER_ARB:
{
if( m_Id && m_VertPg.IsInstantiated() )
glDetachObjectARB( m_Id, m_VertPg.Id() );
gpuAssert( glDetachObjectARB( m_Id, m_VertPg.Id() ) );
m_VertPg = * (VertPg*) &pg;
break;
}
case GL_FRAGMENT_SHADER_ARB:
{
if( m_Id && m_FragPg.IsInstantiated() )
glDetachObjectARB( m_Id, m_FragPg.Id() );
gpuAssert( glDetachObjectARB( m_Id, m_FragPg.Id() ) );
m_FragPg = * (FragPg*) &pg;
break;
}
case GL_GEOMETRY_SHADER_EXT:
{
if( m_Id && m_GeomPg.IsInstantiated() )
glDetachObjectARB( m_Id, m_GeomPg.Id() );
gpuAssert( glDetachObjectARB( m_Id, m_GeomPg.Id() ) );
m_GeomPg = * (GeomPg*) &pg;
break;
}
......@@ -295,7 +300,7 @@ GPU::Shader& GPU::Shader::Attach( const PgObject &pg )
GPU::Shader& GPU::Shader::DetachVertPg()
{
if( m_Id && m_VertPg.IsInstantiated() )
glDetachObjectARB( m_Id, m_VertPg.Id() );
gpuAssert( glDetachObjectARB( m_Id, m_VertPg.Id() ) );
m_VertPg.Release();
return *this;
}
......@@ -304,7 +309,7 @@ GPU::Shader& GPU::Shader::DetachVertPg()
GPU::Shader& GPU::Shader::DetachFragPg()
{
if( m_Id && m_FragPg.IsInstantiated() )
glDetachObjectARB( m_Id, m_FragPg.Id() );
gpuAssert( glDetachObjectARB( m_Id, m_FragPg.Id() ) );
m_FragPg.Release();
return *this;
}
......@@ -313,7 +318,7 @@ GPU::Shader& GPU::Shader::DetachFragPg()
GPU::Shader& GPU::Shader::DetachGeomPg()
{
if( m_Id && m_GeomPg.IsInstantiated() )
glDetachObjectARB( m_Id, m_GeomPg.Id() );
gpuAssert( glDetachObjectARB( m_Id, m_GeomPg.Id() ) );
m_GeomPg.Release();
return *this;
}
......@@ -351,21 +356,21 @@ void GPU::Shader::Release()
{
if( m_VertPg.Id() )
{
glDetachObjectARB( m_Id, m_VertPg.Id() );
gpuAssert( glDetachObjectARB( m_Id, m_VertPg.Id() ) );
m_VertPg.Release();
}
if( m_FragPg.Id() )
{
glDetachObjectARB( m_Id, m_FragPg.Id() );
gpuAssert( glDetachObjectARB( m_Id, m_FragPg.Id() ) );
m_FragPg.Release();
}
if( m_GeomPg.Id() )
{
glDetachObjectARB( m_Id, m_GeomPg.Id() );
gpuAssert( glDetachObjectARB( m_Id, m_GeomPg.Id() ) );
m_GeomPg.Release();
}
glDeleteObjectARB( m_Id );
gpuAssert( glDeleteObjectARB( m_Id ) );
m_Id = 0;
m_Uniforms.clear();
......@@ -382,30 +387,31 @@ void GPU::Shader::SetUniform( const std::string& name,
UniformMap::iterator uu = m_Uniforms.find( name );
if( uu != m_Uniforms.end() )
{
GLuint activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB );
glUseProgramObjectARB( m_Id );
GLuint activeProgBackup;
gpuAssert( activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB ) );
gpuAssert( glUseProgramObjectARB( m_Id ) );
Uniform &u = uu->second;
switch( u.type )
{
case GL_FLOAT: glUniform1fvARB( u.location, u.size, (GLfloat*) value ); break;
case GL_FLOAT_VEC2_ARB: glUniform2fvARB( u.location, u.size, (GLfloat*) value ); break;
case GL_FLOAT_VEC3_ARB: glUniform3fvARB( u.location, u.size, (GLfloat*) value ); break;
case GL_FLOAT_VEC4_ARB: glUniform4fvARB( u.location, u.size, (GLfloat*) value ); break;
case GL_INT: glUniform1ivARB( u.location, u.size, (GLint*) value ); break;
case GL_INT_VEC2_ARB: glUniform2ivARB( u.location, u.size, (GLint*) value ); break;
case GL_INT_VEC3_ARB: glUniform3ivARB( u.location, u.size, (GLint*) value ); break;
case GL_INT_VEC4_ARB: glUniform4ivARB( u.location, u.size, (GLint*) value ); break;
case GL_BOOL_ARB: glUniform1ivARB( u.location, u.size, (GLint*) value ); break;
case GL_BOOL_VEC2_ARB: glUniform2ivARB( u.location, u.size, (GLint*) value ); break;
case GL_BOOL_VEC3_ARB: glUniform3ivARB( u.location, u.size, (GLint*) value ); break;
case GL_BOOL_VEC4_ARB: glUniform4ivARB( u.location, u.size, (GLint*) value ); break;
case GL_FLOAT_MAT2_ARB: glUniformMatrix2fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break;
case GL_FLOAT_MAT3_ARB: glUniformMatrix3fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break;
case GL_FLOAT_MAT4_ARB: glUniformMatrix4fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break;
case GL_FLOAT: gpuAssert( glUniform1fvARB( u.location, u.size, (GLfloat*) value ) ); break;
case GL_FLOAT_VEC2_ARB: gpuAssert( glUniform2fvARB( u.location, u.size, (GLfloat*) value ) ); break;
case GL_FLOAT_VEC3_ARB: gpuAssert( glUniform3fvARB( u.location, u.size, (GLfloat*) value ) ); break;
case GL_FLOAT_VEC4_ARB: gpuAssert( glUniform4fvARB( u.location, u.size, (GLfloat*) value ) ); break;
case GL_INT: gpuAssert( glUniform1ivARB( u.location, u.size, (GLint*) value ) ); break;
case GL_INT_VEC2_ARB: gpuAssert( glUniform2ivARB( u.location, u.size, (GLint*) value ) ); break;
case GL_INT_VEC3_ARB: gpuAssert( glUniform3ivARB( u.location, u.size, (GLint*) value ) ); break;
case GL_INT_VEC4_ARB: gpuAssert( glUniform4ivARB( u.location, u.size, (GLint*) value ) ); break;
case GL_BOOL_ARB: gpuAssert( glUniform1ivARB( u.location, u.size, (GLint*) value ) ); break;
case GL_BOOL_VEC2_ARB: gpuAssert( glUniform2ivARB( u.location, u.size, (GLint*) value ) ); break;
case GL_BOOL_VEC3_ARB: gpuAssert( glUniform3ivARB( u.location, u.size, (GLint*) value ) ); break;
case GL_BOOL_VEC4_ARB: gpuAssert( glUniform4ivARB( u.location, u.size, (GLint*) value ) ); break;
case GL_FLOAT_MAT2_ARB: gpuAssert( glUniformMatrix2fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ) ); break;
case GL_FLOAT_MAT3_ARB: gpuAssert( glUniformMatrix3fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ) ); break;
case GL_FLOAT_MAT4_ARB: gpuAssert( glUniformMatrix4fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ) ); break;
}
glUseProgramObjectARB( activeProgBackup );
gpuAssert( glUseProgramObjectARB( activeProgBackup ) );
}
}
......@@ -416,12 +422,13 @@ void GPU::Shader::SetSamplers( const std::string& name,
UniformMap::iterator s = m_Samplers.find( name );
if( s != m_Samplers.end() )
{
GLuint activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB );
glUseProgramObjectARB( m_Id );
GLuint activeProgBackup;
gpuAssert( activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB ) );
gpuAssert( glUseProgramObjectARB( m_Id ) );
glUniform1ivARB( s->second.location, s->second.size, (GLint*) texUnit );
gpuAssert( glUniform1ivARB( s->second.location, s->second.size, (GLint*) texUnit ) );
glUseProgramObjectARB( activeProgBackup );
gpuAssert( glUseProgramObjectARB( activeProgBackup ) );
}
}
......@@ -436,12 +443,13 @@ void GPU::Shader::SetSamplers( const std::string& name,
for( GLint i=0; i<s->second.size; ++i )
texUnits[i] = firstTexUnit + i;
GLuint activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB );
glUseProgramObjectARB( m_Id );
GLuint activeProgBackup;
gpuAssert( activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB ) );
gpuAssert( glUseProgramObjectARB( m_Id ) );
glUniform1ivARB( s->second.location, s->second.size, texUnits );
gpuAssert( glUniform1ivARB( s->second.location, s->second.size, texUnits ) );
glUseProgramObjectARB( activeProgBackup );
gpuAssert( glUseProgramObjectARB( activeProgBackup ) );
delete[] texUnits;
}
......
......@@ -180,8 +180,8 @@ namespace GPU
inline const GeomPg& GeomProgram() const { return m_GeomPg; }
inline GeomPg& GeomProgram() { return m_GeomPg; }
inline void Bind() { glUseProgramObjectARB( m_Id ); BindSamplers(); }
inline void Unbind() { UnbindSamplers(); glUseProgramObjectARB( 0 ); }
inline void Bind() { gpuAssert( glUseProgramObjectARB( m_Id ) ); BindSamplers(); }
inline void Unbind() { UnbindSamplers(); gpuAssert( glUseProgramObjectARB( 0 ) ); }
void SetUniform( const std::string& name,
const void *value );
......@@ -242,7 +242,7 @@ namespace GPU