In the following code the programmer puts the name of a function inside an if condition as if to check something before going ahead and registering a callback:
#if _DEBUG
if(glDebugMessageCallback) // He checks this function, presumably it returns true if it exists
{
cout << "Register OpenGL debug callback " << endl;
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(openglCallbackFunction, nullptr); // Calls the function here
GLuint unusedIds = 0;
glDebugMessageControl(GL_DONT_CARE,
GL_DONT_CARE,
GL_DONT_CARE,
0,
&unusedIds,
true);
}
else
cout << "glDebugMessageCallback not available" << endl; // So if the if condition evaluated to false, the function doesn't exist.
#endif
My question is why this way of checking if a function exists? If a function doesn't exist surely you'll get a compile error telling you that the function doesn't exist, this seems strange to me. I know basically the function address evaluates to bool, and I asked a question before about this and was told that function addresses aren't particularly useful as implicit conversion to bool, and I don't see how.
I should mention also that the function inside the if condition is a MACRO define, defined as:
#define glDebugMessageCallback GLEW_GET_FUN(__glewDebugMessageCallback)
If it being a define macro makes a difference.
Aucun commentaire:
Enregistrer un commentaire