Made implementation of glCheck and alCheck macros more robust
At the moment, glCheck(...) and alCheck(...) look like a function calls, which is misleading and can cause subtle bugs, for example when used in if statements. This change mitigates the situation by allowing those expressions to be used as single statements within if/else branches. Initializations of OpenGL handles that previously involved glCheck() calls now need to be split into separate declaration and assignment.
This commit is contained in:
parent
18193a5cde
commit
b7d984cdac
@ -50,7 +50,8 @@ namespace priv
|
|||||||
#ifdef SFML_DEBUG
|
#ifdef SFML_DEBUG
|
||||||
|
|
||||||
// If in debug mode, perform a test on every call
|
// If in debug mode, perform a test on every call
|
||||||
#define alCheck(x) x; sf::priv::alCheckError(__FILE__, __LINE__);
|
// The do-while loop is needed so that alCheck can be used as a single statement in if/else branches
|
||||||
|
#define alCheck(expr) do { expr; sf::priv::alCheckError(__FILE__, __LINE__, #expr); } while (false)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -43,7 +43,8 @@ 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(x) x; sf::priv::glCheckError(__FILE__, __LINE__);
|
// The do-while loop is needed so that glCheck can be used as a single statement in if/else branches
|
||||||
|
#define glCheck(expr) do { expr; sf::priv::glCheckError(__FILE__, __LINE__, #expr); } while (false)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -117,7 +117,8 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
|
|||||||
glCheck(GLEXT_glFramebufferTexture2D(GLEXT_GL_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0));
|
glCheck(GLEXT_glFramebufferTexture2D(GLEXT_GL_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0));
|
||||||
|
|
||||||
// A final check, just to be sure...
|
// A final check, just to be sure...
|
||||||
GLenum status = glCheck(GLEXT_glCheckFramebufferStatus(GLEXT_GL_FRAMEBUFFER));
|
GLenum status;
|
||||||
|
glCheck(status = GLEXT_glCheckFramebufferStatus(GLEXT_GL_FRAMEBUFFER));
|
||||||
if (status != GLEXT_GL_FRAMEBUFFER_COMPLETE)
|
if (status != GLEXT_GL_FRAMEBUFFER_COMPLETE)
|
||||||
{
|
{
|
||||||
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, 0));
|
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, 0));
|
||||||
|
@ -275,7 +275,8 @@ void Shader::setParameter(const std::string& name, float x)
|
|||||||
ensureGlContext();
|
ensureGlContext();
|
||||||
|
|
||||||
// Enable program
|
// Enable program
|
||||||
GLEXT_GLhandle program = glCheck(GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
|
GLEXT_GLhandle program;
|
||||||
|
glCheck(program = GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
|
||||||
glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));
|
glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));
|
||||||
|
|
||||||
// Get parameter location and assign it new values
|
// Get parameter location and assign it new values
|
||||||
@ -299,7 +300,8 @@ void Shader::setParameter(const std::string& name, float x, float y)
|
|||||||
ensureGlContext();
|
ensureGlContext();
|
||||||
|
|
||||||
// Enable program
|
// Enable program
|
||||||
GLEXT_GLhandle program = glCheck(GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
|
GLEXT_GLhandle program;
|
||||||
|
glCheck(program = GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
|
||||||
glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));
|
glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));
|
||||||
|
|
||||||
// Get parameter location and assign it new values
|
// Get parameter location and assign it new values
|
||||||
@ -323,7 +325,8 @@ void Shader::setParameter(const std::string& name, float x, float y, float z)
|
|||||||
ensureGlContext();
|
ensureGlContext();
|
||||||
|
|
||||||
// Enable program
|
// Enable program
|
||||||
GLEXT_GLhandle program = glCheck(GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
|
GLEXT_GLhandle program;
|
||||||
|
glCheck(program = GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
|
||||||
glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));
|
glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));
|
||||||
|
|
||||||
// Get parameter location and assign it new values
|
// Get parameter location and assign it new values
|
||||||
@ -347,7 +350,8 @@ void Shader::setParameter(const std::string& name, float x, float y, float z, fl
|
|||||||
ensureGlContext();
|
ensureGlContext();
|
||||||
|
|
||||||
// Enable program
|
// Enable program
|
||||||
GLEXT_GLhandle program = glCheck(GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
|
GLEXT_GLhandle program;
|
||||||
|
glCheck(program = GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
|
||||||
glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));
|
glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));
|
||||||
|
|
||||||
// Get parameter location and assign it new values
|
// Get parameter location and assign it new values
|
||||||
@ -392,7 +396,8 @@ void Shader::setParameter(const std::string& name, const Transform& transform)
|
|||||||
ensureGlContext();
|
ensureGlContext();
|
||||||
|
|
||||||
// Enable program
|
// Enable program
|
||||||
GLEXT_GLhandle program = glCheck(GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
|
GLEXT_GLhandle program;
|
||||||
|
glCheck(program = GLEXT_glGetHandle(GLEXT_GL_PROGRAM_OBJECT));
|
||||||
glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));
|
glCheck(GLEXT_glUseProgramObject(castToGlHandle(m_shaderProgram)));
|
||||||
|
|
||||||
// Get parameter location and assign it new values
|
// Get parameter location and assign it new values
|
||||||
@ -534,13 +539,15 @@ bool Shader::compile(const char* vertexShaderCode, const char* fragmentShaderCod
|
|||||||
m_params.clear();
|
m_params.clear();
|
||||||
|
|
||||||
// Create the program
|
// Create the program
|
||||||
GLEXT_GLhandle shaderProgram = glCheck(GLEXT_glCreateProgramObject());
|
GLEXT_GLhandle shaderProgram;
|
||||||
|
glCheck(shaderProgram = GLEXT_glCreateProgramObject());
|
||||||
|
|
||||||
// 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
|
||||||
GLEXT_GLhandle vertexShader = glCheck(GLEXT_glCreateShaderObject(GLEXT_GL_VERTEX_SHADER));
|
GLEXT_GLhandle vertexShader;
|
||||||
|
glCheck(vertexShader = GLEXT_glCreateShaderObject(GLEXT_GL_VERTEX_SHADER));
|
||||||
glCheck(GLEXT_glShaderSource(vertexShader, 1, &vertexShaderCode, NULL));
|
glCheck(GLEXT_glShaderSource(vertexShader, 1, &vertexShaderCode, NULL));
|
||||||
glCheck(GLEXT_glCompileShader(vertexShader));
|
glCheck(GLEXT_glCompileShader(vertexShader));
|
||||||
|
|
||||||
@ -567,7 +574,8 @@ bool Shader::compile(const char* vertexShaderCode, const char* fragmentShaderCod
|
|||||||
if (fragmentShaderCode)
|
if (fragmentShaderCode)
|
||||||
{
|
{
|
||||||
// Create and compile the shader
|
// Create and compile the shader
|
||||||
GLEXT_GLhandle fragmentShader = glCheck(GLEXT_glCreateShaderObject(GLEXT_GL_FRAGMENT_SHADER));
|
GLEXT_GLhandle fragmentShader;
|
||||||
|
glCheck(fragmentShader = GLEXT_glCreateShaderObject(GLEXT_GL_FRAGMENT_SHADER));
|
||||||
glCheck(GLEXT_glShaderSource(fragmentShader, 1, &fragmentShaderCode, NULL));
|
glCheck(GLEXT_glShaderSource(fragmentShader, 1, &fragmentShaderCode, NULL));
|
||||||
glCheck(GLEXT_glCompileShader(fragmentShader));
|
glCheck(GLEXT_glCompileShader(fragmentShader));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user