mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
Improved OpenGL error macro
It now supports functions that return values.
This commit is contained in:
parent
63bbe2c91e
commit
8c906a7a3d
@ -43,7 +43,7 @@ namespace priv
|
||||
#ifdef SFML_DEBUG
|
||||
|
||||
// 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
|
||||
|
||||
|
@ -381,17 +381,27 @@ void RenderTarget::applyBlendMode(BlendMode mode)
|
||||
default :
|
||||
case BlendAlpha :
|
||||
if (GL_blend_func_separate)
|
||||
{
|
||||
glCheck(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
|
||||
}
|
||||
else
|
||||
{
|
||||
glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Additive blending
|
||||
case BlendAdd :
|
||||
if (GL_blend_func_separate)
|
||||
{
|
||||
glCheck(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE));
|
||||
}
|
||||
else
|
||||
{
|
||||
glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Multiplicative blending
|
||||
|
@ -117,7 +117,8 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
|
||||
glCheck(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0));
|
||||
|
||||
// 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));
|
||||
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)
|
||||
{
|
||||
glFlush();
|
||||
glCheck(glFlush());
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
@ -228,13 +228,15 @@ void Shader::setParameter(const std::string& name, float x)
|
||||
ensureGlContext();
|
||||
|
||||
// Enable program
|
||||
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
|
||||
GLhandleARB program = glCheck(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Get parameter location and assign it new values
|
||||
GLint location = getParamLocation(name);
|
||||
if (location != -1)
|
||||
{
|
||||
glCheck(glUniform1fARB(location, x));
|
||||
}
|
||||
|
||||
// Disable program
|
||||
glCheck(glUseProgramObjectARB(program));
|
||||
@ -250,13 +252,15 @@ void Shader::setParameter(const std::string& name, float x, float y)
|
||||
ensureGlContext();
|
||||
|
||||
// Enable program
|
||||
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
|
||||
GLhandleARB program = glCheck(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Get parameter location and assign it new values
|
||||
GLint location = getParamLocation(name);
|
||||
if (location != -1)
|
||||
{
|
||||
glCheck(glUniform2fARB(location, x, y));
|
||||
}
|
||||
|
||||
// Disable program
|
||||
glCheck(glUseProgramObjectARB(program));
|
||||
@ -272,13 +276,15 @@ void Shader::setParameter(const std::string& name, float x, float y, float z)
|
||||
ensureGlContext();
|
||||
|
||||
// Enable program
|
||||
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
|
||||
GLhandleARB program = glCheck(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Get parameter location and assign it new values
|
||||
GLint location = getParamLocation(name);
|
||||
if (location != -1)
|
||||
{
|
||||
glCheck(glUniform3fARB(location, x, y, z));
|
||||
}
|
||||
|
||||
// Disable program
|
||||
glCheck(glUseProgramObjectARB(program));
|
||||
@ -294,13 +300,15 @@ void Shader::setParameter(const std::string& name, float x, float y, float z, fl
|
||||
ensureGlContext();
|
||||
|
||||
// Enable program
|
||||
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
|
||||
GLhandleARB program = glCheck(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Get parameter location and assign it new values
|
||||
GLint location = getParamLocation(name);
|
||||
if (location != -1)
|
||||
{
|
||||
glCheck(glUniform4fARB(location, x, y, z, w));
|
||||
}
|
||||
|
||||
// Disable program
|
||||
glCheck(glUseProgramObjectARB(program));
|
||||
@ -337,13 +345,15 @@ void Shader::setParameter(const std::string& name, const sf::Transform& transfor
|
||||
ensureGlContext();
|
||||
|
||||
// Enable program
|
||||
GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
|
||||
GLhandleARB program = glCheck(glGetHandleARB(GL_PROGRAM_OBJECT_ARB));
|
||||
glCheck(glUseProgramObjectARB(m_shaderProgram));
|
||||
|
||||
// Get parameter location and assign it new values
|
||||
GLint location = getParamLocation(name);
|
||||
if (location != -1)
|
||||
{
|
||||
glCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.getMatrix()));
|
||||
}
|
||||
|
||||
// Disable program
|
||||
glCheck(glUseProgramObjectARB(program));
|
||||
@ -462,13 +472,13 @@ bool Shader::compile(const char* vertexShaderCode, const char* fragmentShaderCod
|
||||
m_params.clear();
|
||||
|
||||
// Create the program
|
||||
m_shaderProgram = glCreateProgramObjectARB();
|
||||
m_shaderProgram = glCheck(glCreateProgramObjectARB());
|
||||
|
||||
// Create the vertex shader if needed
|
||||
if (vertexShaderCode)
|
||||
{
|
||||
// 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(glCompileShaderARB(vertexShader));
|
||||
|
||||
@ -496,7 +506,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* fragmentShaderCod
|
||||
if (fragmentShaderCode)
|
||||
{
|
||||
// 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(glCompileShaderARB(fragmentShader));
|
||||
|
||||
@ -576,7 +586,7 @@ int Shader::getParamLocation(const std::string& name)
|
||||
else
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
// Location found: add it to the cache
|
||||
|
Loading…
Reference in New Issue
Block a user