glcontext: implement the debug callback

For both GL_KHR_debug and ARB_debug_output.  This allows us to
receive errors and other hints from the GL instead of querying after
every GL operation.
This commit is contained in:
Matthew Waters 2014-08-20 23:24:12 +10:00 committed by Tim-Philipp Müller
parent d7a465f9da
commit 61b95b0300
3 changed files with 168 additions and 1 deletions

View file

@ -216,7 +216,7 @@ gst_gl_context_egl_create_context (GstGLContext * context,
GstGLWindow *window = NULL;
EGLNativeWindowType window_handle = (EGLNativeWindowType) 0;
gint i = 0;
EGLint context_attrib[3];
EGLint context_attrib[5];
EGLint majorVersion;
EGLint minorVersion;
const gchar *egl_exts;
@ -334,6 +334,10 @@ gst_gl_context_egl_create_context (GstGLContext * context,
context_attrib[i++] = EGL_CONTEXT_CLIENT_VERSION;
context_attrib[i++] = 2;
}
#if !defined(GST_DISABLE_GST_DEBUG)
context_attrib[i++] = EGL_CONTEXT_FLAGS_KHR;
context_attrib[i++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
#endif
context_attrib[i++] = EGL_NONE;
egl->egl_context =

View file

@ -65,6 +65,7 @@
#include "eagl/gstglcontext_eagl.h"
#endif
GST_DEBUG_CATEGORY_STATIC (gst_performance);
static GModule *module_self;
#if GST_GL_HAVE_OPENGL
@ -238,6 +239,7 @@ _init_debug (void)
if (g_once_init_enter (&_init)) {
GST_DEBUG_CATEGORY_INIT (gst_gl_context_debug, "glcontext", 0,
"glcontext element");
GST_DEBUG_CATEGORY_GET (gst_performance, "GST_PERFORMANCE");
g_once_init_leave (&_init, 1);
}
}
@ -597,6 +599,154 @@ gst_gl_context_create (GstGLContext * context,
return alive;
}
#ifndef GL_DEBUG_TYPE_ERROR
#define GL_DEBUG_TYPE_ERROR 0x824C
#endif
#ifndef GL_DEBUG_TYPE_DEPRECATED_BEHAVIOUR
#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOUR 0x824D
#endif
#ifndef GL_DEBUG_TYPE_UNDEFINED_BEHAVIOUR
#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOUR 0x824E
#endif
#ifndef GL_DEBUG_TYPE_PORTABILITY
#define GL_DEBUG_TYPE_PORTABILITY 0x824F
#endif
#ifndef GL_DEBUG_TYPE_PERFORMANCE
#define GL_DEBUG_TYPE_PERFORMANCE 0x8250
#endif
#ifndef GL_DEBUG_TYPE_MARKER
#define GL_DEBUG_TYPE_MARKER 0x8268
#endif
#ifndef GL_DEBUG_TYPE_OTHER
#define GL_DEBUG_TYPE_OTHER 0x8251
#endif
#ifndef GL_DEBUG_SEVERITY_HIGH
#define GL_DEBUG_SEVERITY_HIGH 0x9146
#endif
#ifndef GL_DEBUG_SEVERITY_MEDIUM
#define GL_DEBUG_SEVERITY_MEDIUM 0x9147
#endif
#ifndef GL_DEBUG_SEVERITY_LOW
#define GL_DEBUG_SEVERITY_LOW 0x9148
#endif
#ifndef GL_DEBUG_SEVERITY_NOTIFICATION
#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B
#endif
#ifndef GL_DEBUG_SOURCE_API
#define GL_DEBUG_SOURCE_API 0x8246
#endif
#ifndef GL_DEBUG_SOURCE_WINDOW_SYSTEM
#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247
#endif
#ifndef GL_DEBUG_SOURCE_SHADER_COMPILER
#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248
#endif
#ifndef GL_DEBUG_SOURCE_THIRD_PARTY
#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249
#endif
#ifndef GL_DEBUG_SOURCE_APPLICATION
#define GL_DEBUG_SOURCE_APPLICATION 0x824A
#endif
#ifndef GL_DEBUG_SOURCE_OTHER
#define GL_DEBUG_SOURCE_OTHER 0x824B
#endif
#if !defined(GST_DISABLE_GST_DEBUG)
static inline const gchar *
_debug_severity_to_string (GLenum severity)
{
switch (severity) {
case GL_DEBUG_SEVERITY_HIGH:
return "high";
case GL_DEBUG_SEVERITY_MEDIUM:
return "medium";
case GL_DEBUG_SEVERITY_LOW:
return "low";
case GL_DEBUG_SEVERITY_NOTIFICATION:
return "notification";
default:
return "invalid";
}
}
static inline const gchar *
_debug_source_to_string (GLenum source)
{
switch (source) {
case GL_DEBUG_SOURCE_API:
return "API";
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
return "winsys";
case GL_DEBUG_SOURCE_SHADER_COMPILER:
return "shader compiler";
case GL_DEBUG_SOURCE_THIRD_PARTY:
return "third party";
case GL_DEBUG_SOURCE_APPLICATION:
return "application";
case GL_DEBUG_SOURCE_OTHER:
return "other";
default:
return "invalid";
}
}
static inline const gchar *
_debug_type_to_string (GLenum type)
{
switch (type) {
case GL_DEBUG_TYPE_ERROR:
return "error";
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOUR:
return "deprecated";
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOUR:
return "undefined";
case GL_DEBUG_TYPE_PORTABILITY:
return "portability";
case GL_DEBUG_TYPE_PERFORMANCE:
return "performance";
case GL_DEBUG_TYPE_MARKER:
return "debug marker";
case GL_DEBUG_TYPE_OTHER:
return "other";
default:
return "invalid";
}
}
static void
_gst_gl_debug_callback (GLenum source, GLenum type, GLuint id, GLenum severity,
GLsizei length, const gchar * message, gpointer user_data)
{
GstGLContext *context = user_data;
const gchar *severity_str = _debug_severity_to_string (severity);
const gchar *source_str = _debug_source_to_string (source);
const gchar *type_str = _debug_type_to_string (type);
switch (type) {
case GL_DEBUG_TYPE_ERROR:
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOUR:
GST_ERROR_OBJECT (context, "%s: GL %s from %s id:%u, %s", severity_str,
type_str, source_str, id, message);
break;
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOUR:
case GL_DEBUG_TYPE_PORTABILITY:
GST_FIXME_OBJECT (context, "%s: GL %s from %s id:%u, %s", severity_str,
type_str, source_str, id, message);
break;
case GL_DEBUG_TYPE_PERFORMANCE:
GST_CAT_DEBUG_OBJECT (gst_performance, context, "%s: GL %s from %s id:%u,"
" %s", severity_str, type_str, source_str, id, message);
break;
default:
GST_DEBUG_OBJECT (context, "%s: GL %s from %s id:%u, %s", severity_str,
type_str, source_str, id, message);
break;
}
}
#endif
static gboolean
_create_context_info (GstGLContext * context, GstGLAPI gl_api, gint * gl_major,
gint * gl_minor, GError ** error)
@ -836,6 +986,16 @@ gst_gl_context_create_thread (GstGLContext * context)
context->priv->alive = TRUE;
if (gl->DebugMessageCallback) {
#if !defined(GST_DISABLE_GST_DEBUG)
GST_INFO ("Enabling GL context debugging");
/* enable them all */
gl->DebugMessageControl (GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0,
GL_TRUE);
gl->DebugMessageCallback (_gst_gl_debug_callback, context);
#endif
}
g_cond_signal (&context->priv->create_cond);
// g_mutex_unlock (&context->priv->render_lock);

View file

@ -178,6 +178,9 @@ gst_gl_context_glx_create_context (GstGLContext * context,
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
//GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
#if !defined(GST_DISABLE_GST_DEBUG)
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
#endif
None
};