vo_opengl: make use of newer OpenGL logging API

GL_ARB_debug_output provides a logging callback, which can be used to
diagnose problems etc. in case the driver supports it. It's enabled only
if the vo_opengl "debug" suboption is set.
This commit is contained in:
wm4 2014-12-23 02:46:44 +01:00
parent b7d0db8bfe
commit a8ffa0d0eb
5 changed files with 58 additions and 2 deletions

View File

@ -107,6 +107,7 @@ static const struct feature features[] = {
{MPGL_CAP_TEX_RG, "RG textures"},
{MPGL_CAP_1ST_CLASS_ARRAYS, "1st class shader arrays"},
{MPGL_CAP_3D_TEX, "3D textures"},
{MPGL_CAP_DEBUG, "debugging extensions"},
{MPGL_CAP_SW, "suspected software renderer"},
{0},
};
@ -462,6 +463,16 @@ static const struct gl_functions gl_functions[] = {
.extension = "GL_APPLE_rgb_422",
.provides = MPGL_CAP_APPLE_RGB_422,
},
{
.ver_core = 430,
.extension = "GL_ARB_debug_output",
.provides = MPGL_CAP_DEBUG,
.functions = (const struct gl_function[]) {
// (only functions needed by us)
DEF_FN(DebugMessageCallback),
{0}
},
},
};
#undef FN_OFFS
@ -972,6 +983,8 @@ MPGLContext *mpgl_init(struct vo *vo, const char *backend_name,
goto cleanup;
}
ctx->gl->debug_context = !!(vo_flags & VOFLAG_GL_DEBUG);
return ctx;
cleanup:

View File

@ -81,6 +81,7 @@ enum {
MPGL_CAP_APPLE_RGB_422 = (1 << 12), // GL_APPLE_rgb_422
MPGL_CAP_1ST_CLASS_ARRAYS = (1 << 13),
MPGL_CAP_3D_TEX = (1 << 14),
MPGL_CAP_DEBUG = (1 << 15),
MPGL_CAP_SW = (1 << 30), // indirect or sw renderer
};
@ -171,6 +172,9 @@ void mpgl_load_functions2(GL *gl, void *(*get_fn)(void *ctx, const char *n),
// log, lev: module and log level, as in mp_msg()
void mp_log_source(struct mp_log *log, int lev, const char *src);
typedef void (GLAPIENTRY *MP_GLDEBUGPROC)(GLenum, GLenum, GLuint, GLenum,
GLsizei, const GLchar *,const void *);
//function pointers loaded from the OpenGL library
struct GL {
int version; // MPGL_VER() mangled (e.g. 210 for 2.1)
@ -178,6 +182,7 @@ struct GL {
int glsl_version; // e.g. 130 for GLSL 1.30
char *extensions; // Equivalent to GL_EXTENSIONS
int mpgl_caps; // Bitfield of MPGL_CAP_* constants
bool debug_context; // use of e.g. GLX_CONTEXT_DEBUG_BIT_ARB
void (GLAPIENTRY *Begin)(GLenum);
void (GLAPIENTRY *End)(void);
@ -326,6 +331,9 @@ struct GL {
GLint (GLAPIENTRY *GetVideoSync)(GLuint *);
GLint (GLAPIENTRY *WaitVideoSync)(GLint, GLint, unsigned int *);
void (GLAPIENTRY *DebugMessageCallback)(MP_GLDEBUGPROC callback,
const void *userParam);
};
#endif /* MPLAYER_GL_COMMON_H */

View File

@ -127,6 +127,7 @@ struct gl_video {
struct mp_log *log;
struct gl_video_opts opts;
bool gl_debug;
bool debug_cb_set;
int depth_g;
@ -434,9 +435,39 @@ static void debug_check_gl(struct gl_video *p, const char *msg)
glCheckError(p->gl, p->log, msg);
}
static void GLAPIENTRY gl_debug_cb(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length,
const GLchar *message, const void *userParam)
{
// keep in mind that the debug callback can be asynchronous
struct gl_video *p = (void *)userParam;
int level = MSGL_ERR;
switch (severity) {
case GL_DEBUG_SEVERITY_NOTIFICATION:level = MSGL_V; break;
case GL_DEBUG_SEVERITY_LOW: level = MSGL_INFO; break;
case GL_DEBUG_SEVERITY_MEDIUM: level = MSGL_WARN; break;
case GL_DEBUG_SEVERITY_HIGH: level = MSGL_ERR; break;
}
MP_MSG(p, level, "GL: %s\n", message);
}
void gl_video_set_debug(struct gl_video *p, bool enable)
{
GL *gl = p->gl;
p->gl_debug = enable;
if (p->debug_cb_set != enable && gl->debug_context &&
gl->DebugMessageCallback)
{
if (enable) {
gl->DebugMessageCallback(gl_debug_cb, p);
} else {
gl->DebugMessageCallback(NULL, NULL);
}
p->debug_cb_set = enable;
}
}
static void texture_size(struct gl_video *p, int w, int h, int *texw, int *texh)
@ -2247,6 +2278,9 @@ void gl_video_uninit(struct gl_video *p)
mpgl_osd_destroy(p->osd);
if (p->debug_cb_set)
gl->DebugMessageCallback(NULL, NULL);
talloc_free(p);
}
@ -2452,13 +2486,13 @@ struct gl_video *gl_video_init(GL *gl, struct mp_log *log, struct osd_state *osd
.osd_state = osd,
.opts = gl_video_opts_def,
.gl_target = GL_TEXTURE_2D,
.gl_debug = true,
.scalers = {
{ .index = 0, .name = "bilinear" },
{ .index = 1, .name = "bilinear" },
},
.scratch = talloc_zero_array(p, char *, 1),
};
gl_video_set_debug(p, true);
init_gl(p);
recreate_osd(p);
return p;

View File

@ -127,7 +127,7 @@ static void flip_page(struct vo *vo)
p->glctx->swapGlBuffers(p->glctx);
p->frames_rendered++;
if (p->frames_rendered > 5)
if (p->frames_rendered > 5 && !p->use_gl_debug)
gl_video_set_debug(p->renderer, false);
if (p->use_glFinish)

View File

@ -214,6 +214,7 @@ int mpv_opengl_cb_render(struct mpv_opengl_cb_context *ctx, int fbo, int vp[4])
gl_video_config(ctx->renderer, &ctx->img_params);
struct vo_priv *p = vo->priv;
gl_video_set_options(ctx->renderer, p->renderer_opts);
ctx->gl->debug_context = p->use_gl_debug;
gl_video_set_debug(ctx->renderer, p->use_gl_debug);
}