12-07-2022, 11:48 AM
(This post was last modified: 12-08-2022, 12:31 AM by Brian Beuken.)
Pretty sure I have this elsewhere on this forum but adding it again for students to see.
OpenGLES2.0 has limited error handling
GLint err = glGetError();
Only gives you an indication that an error happend once, sometime ago... you need to step back and find it
Its far easier to check an error when it happens, and OpenGLES3.0 allows that. You need to install some libs, your system may not need all of them but best to try and install them.
sudo apt-get install libglx-mesa0-dbgsym libglapi-mesa-dbgsym libgl1-mesa-dri-dbgsym
Also as this is also an extension it will also need libdl added so add dl to your binary libs it shouldn't need to be installed it should be onboard
Next you need a small callback function somewhere in your code but you need to set that up I use this, which is the actual callback and the init function, this lives in my main.cpp file and is called after openGL is initialised.
My sincere thanks tomy collegue Phil de Groot for working this out, its proved very helpful.
OpenGLES2.0 has limited error handling
GLint err = glGetError();
Only gives you an indication that an error happend once, sometime ago... you need to step back and find it
Its far easier to check an error when it happens, and OpenGLES3.0 allows that. You need to install some libs, your system may not need all of them but best to try and install them.
sudo apt-get install libglx-mesa0-dbgsym libglapi-mesa-dbgsym libgl1-mesa-dri-dbgsym
Also as this is also an extension it will also need libdl added so add dl to your binary libs it shouldn't need to be installed it should be onboard
Next you need a small callback function somewhere in your code but you need to set that up I use this, which is the actual callback and the init function, this lives in my main.cpp file and is called after openGL is initialised.
My sincere thanks tomy collegue Phil de Groot for working this out, its proved very helpful.
Code:
#include <csignal> //Raise and SIGTRAP constants.
#include <GLES2/gl2ext.h>
void OpenGLErrorCallbackHandler(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
{
// try to stop the jetson complaining
if (id != 0x00020092) // this seems to stop the strange recompile error but not an issue for Pi, confused!!
{
switch (severity)
{ // we can choose to ignore most of the minor error reports, here we just focus on high and med
case GL_DEBUG_SEVERITY_HIGH_KHR:
case GL_DEBUG_SEVERITY_MEDIUM_KHR:
std::cout << "OpenGL High/Med Error: " << message << std::endl;
//Set a hard-coded breakpoint for only the error that we encounter.
static bool onlyBreakOnFirst = true;
if (onlyBreakOnFirst)
{
raise(SIGTRAP);
onlyBreakOnFirst = false;
}
break;
case GL_DEBUG_SEVERITY_LOW_KHR:
case GL_DEBUG_SEVERITY_NOTIFICATION_KHR:
// std::cout << "OpenGL Low/Notice Warning: " << message << std::endl;
//
break;
default:
break; //Ignore.
}
}
};
void InstallOpenGLErrorCallback()
{
PFNGLDEBUGMESSAGECALLBACKKHRPROC peglDebugMessageControlKHR = (PFNGLDEBUGMESSAGECALLBACKKHRPROC)eglGetProcAddress("glDebugMessageCallback");
if (!(peglDebugMessageControlKHR != 0)) {
printf("failed to eglGetProcAddress eglDebugMessageControlKHR\n");
raise(SIGTRAP); //Be sure that we know about this.
}
else {
glEnable(GL_DEBUG_OUTPUT_KHR);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR);
peglDebugMessageControlKHR(OpenGLErrorCallbackHandler, nullptr);
}
}
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's