Improved OpenGL error macro

It now supports functions that return values.
This commit is contained in:
Jonathan De Wachter 2013-08-17 12:16:49 +02:00
parent 63bbe2c91e
commit 8c906a7a3d
4 changed files with 36 additions and 15 deletions

View File

@ -43,7 +43,7 @@ namespace priv
#ifdef SFML_DEBUG #ifdef SFML_DEBUG
// In debug mode, perform a test on every OpenGL call // In debug mode, perform a test on every OpenGL call
#define glCheck(call) ((call), sf::priv::glCheckError(__FILE__, __LINE__)) #define glCheck(x) x; sf::priv::glCheckError(__FILE__, __LINE__);
#else #else

View File

@ -379,19 +379,29 @@ void RenderTarget::applyBlendMode(BlendMode mode)
// Alpha blending // Alpha blending
default : default :
case BlendAlpha : case BlendAlpha :
if (GL_blend_func_separate) if (GL_blend_func_separate)
{
glCheck(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); glCheck(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
}
else else
{
glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
}
break; break;
// Additive blending // Additive blending
case BlendAdd : case BlendAdd :
if (GL_blend_func_separate) if (GL_blend_func_separate)
{
glCheck(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE)); glCheck(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE));
}
else else
{
glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE)); glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
}
break; break;
// Multiplicative blending // Multiplicative blending

View File

@ -116,8 +116,9 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
// Link the texture to the frame buffer // Link the texture to the frame buffer
glCheck(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0)); glCheck(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0));
// A final check, just to be sure... // A final check, just to be sure...
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) GLenum status = glCheck(glCheckFramebufferStatus(GL_FRAMEBUFFER));
if (status != GL_FRAMEBUFFER_COMPLETE)
{ {
glCheck(glBindFramebuffer(GL_FRAMEBUFFER, 0)); glCheck(glBindFramebuffer(GL_FRAMEBUFFER, 0));
err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl; err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
@ -138,7 +139,7 @@ bool RenderTextureImplFBO::activate(bool active)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void RenderTextureImplFBO::updateTexture(unsigned int) void RenderTextureImplFBO::updateTexture(unsigned int)
{ {
glFlush(); glCheck(glFlush());
} }
} // namespace priv } // namespace priv

View File

@ -228,13 +228,15 @@ void Shader::setParameter(const std::string& name, float x)
ensureGlContext(); ensureGlContext();
// Enable program // Enable program
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB); GLhandleARB program = glCheck(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
glCheck(glUseProgramObjectARB(m_shaderProgram)); glCheck(glUseProgramObjectARB(m_shaderProgram));
// Get parameter location and assign it new values // Get parameter location and assign it new values
GLint location = getParamLocation(name); GLint location = getParamLocation(name);
if (location != -1) if (location != -1)
{
glCheck(glUniform1fARB(location, x)); glCheck(glUniform1fARB(location, x));
}
// Disable program // Disable program
glCheck(glUseProgramObjectARB(program)); glCheck(glUseProgramObjectARB(program));
@ -250,13 +252,15 @@ void Shader::setParameter(const std::string& name, float x, float y)
ensureGlContext(); ensureGlContext();
// Enable program // Enable program
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB); GLhandleARB program = glCheck(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
glCheck(glUseProgramObjectARB(m_shaderProgram)); glCheck(glUseProgramObjectARB(m_shaderProgram));
// Get parameter location and assign it new values // Get parameter location and assign it new values
GLint location = getParamLocation(name); GLint location = getParamLocation(name);
if (location != -1) if (location != -1)
{
glCheck(glUniform2fARB(location, x, y)); glCheck(glUniform2fARB(location, x, y));
}
// Disable program // Disable program
glCheck(glUseProgramObjectARB(program)); glCheck(glUseProgramObjectARB(program));
@ -272,13 +276,15 @@ void Shader::setParameter(const std::string& name, float x, float y, float z)
ensureGlContext(); ensureGlContext();
// Enable program // Enable program
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB); GLhandleARB program = glCheck(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
glCheck(glUseProgramObjectARB(m_shaderProgram)); glCheck(glUseProgramObjectARB(m_shaderProgram));
// Get parameter location and assign it new values // Get parameter location and assign it new values
GLint location = getParamLocation(name); GLint location = getParamLocation(name);
if (location != -1) if (location != -1)
{
glCheck(glUniform3fARB(location, x, y, z)); glCheck(glUniform3fARB(location, x, y, z));
}
// Disable program // Disable program
glCheck(glUseProgramObjectARB(program)); glCheck(glUseProgramObjectARB(program));
@ -294,13 +300,15 @@ void Shader::setParameter(const std::string& name, float x, float y, float z, fl
ensureGlContext(); ensureGlContext();
// Enable program // Enable program
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB); GLhandleARB program = glCheck(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
glCheck(glUseProgramObjectARB(m_shaderProgram)); glCheck(glUseProgramObjectARB(m_shaderProgram));
// Get parameter location and assign it new values // Get parameter location and assign it new values
GLint location = getParamLocation(name); GLint location = getParamLocation(name);
if (location != -1) if (location != -1)
{
glCheck(glUniform4fARB(location, x, y, z, w)); glCheck(glUniform4fARB(location, x, y, z, w));
}
// Disable program // Disable program
glCheck(glUseProgramObjectARB(program)); glCheck(glUseProgramObjectARB(program));
@ -337,13 +345,15 @@ void Shader::setParameter(const std::string& name, const sf::Transform& transfor
ensureGlContext(); ensureGlContext();
// Enable program // Enable program
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB); GLhandleARB program = glCheck(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
glCheck(glUseProgramObjectARB(m_shaderProgram)); glCheck(glUseProgramObjectARB(m_shaderProgram));
// Get parameter location and assign it new values // Get parameter location and assign it new values
GLint location = getParamLocation(name); GLint location = getParamLocation(name);
if (location != -1) if (location != -1)
{
glCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.getMatrix())); glCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.getMatrix()));
}
// Disable program // Disable program
glCheck(glUseProgramObjectARB(program)); glCheck(glUseProgramObjectARB(program));
@ -462,13 +472,13 @@ bool Shader::compile(const char* vertexShaderCode, const char* fragmentShaderCod
m_params.clear(); m_params.clear();
// Create the program // Create the program
m_shaderProgram = glCreateProgramObjectARB(); m_shaderProgram = glCheck(glCreateProgramObjectARB());
// Create the vertex shader if needed // Create the vertex shader if needed
if (vertexShaderCode) if (vertexShaderCode)
{ {
// Create and compile the shader // Create and compile the shader
GLhandleARB vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); GLhandleARB vertexShader = glCheck(glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB));
glCheck(glShaderSourceARB(vertexShader, 1, &vertexShaderCode, NULL)); glCheck(glShaderSourceARB(vertexShader, 1, &vertexShaderCode, NULL));
glCheck(glCompileShaderARB(vertexShader)); glCheck(glCompileShaderARB(vertexShader));
@ -496,7 +506,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* fragmentShaderCod
if (fragmentShaderCode) if (fragmentShaderCode)
{ {
// Create and compile the shader // Create and compile the shader
GLhandleARB fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); GLhandleARB fragmentShader = glCheck(glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB));
glCheck(glShaderSourceARB(fragmentShader, 1, &fragmentShaderCode, NULL)); glCheck(glShaderSourceARB(fragmentShader, 1, &fragmentShaderCode, NULL));
glCheck(glCompileShaderARB(fragmentShader)); glCheck(glCompileShaderARB(fragmentShader));
@ -576,7 +586,7 @@ int Shader::getParamLocation(const std::string& name)
else else
{ {
// Not in cache, request the location from OpenGL // Not in cache, request the location from OpenGL
int location = glGetUniformLocationARB(m_shaderProgram, name.c_str()); int location = glCheck(glGetUniformLocationARB(m_shaderProgram, name.c_str()));
if (location != -1) if (location != -1)
{ {
// Location found: add it to the cache // Location found: add it to the cache