From 40cf035d03ba73dec914cacc06aa5d0b9cf857a1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 18 Mar 2012 19:22:49 +0100 Subject: [PATCH] gl_common: slightly change win32 GL 3 context creation The code used OpenGL 3 specific functions for querying the extension string when the actual GL 3 context wasn't created yet. This appears to work fine on nVidia, but could break otherwise. Remove the offending getFunctions call and retrieve the needed function pointer manually. (This way the wglCreateContextAttribsARB function pointer can be removed from struct GL too.) (Amusingly exposes a wine bug; they made the same mistake.) Explicitly check the extension string whether the function is available, although this probably doesn't matter in practice. Also retrieve bit depth information on win32. --- libvo/gl_common.c | 43 +++++++++++++++++++++++++++++-------------- libvo/gl_common.h | 4 ---- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/libvo/gl_common.c b/libvo/gl_common.c index db475a9eb0..5fe8e1c139 100644 --- a/libvo/gl_common.c +++ b/libvo/gl_common.c @@ -488,11 +488,6 @@ static const extfunc_desc_t extfuncs[] = { DEF_GL3_DESC(UniformMatrix3fv), DEF_GL3_DESC(UniformMatrix4x3fv), -#ifdef CONFIG_GL_WIN32 - DEF_EXT_DESC(wglCreateContextAttribsARB, NULL, - ("wglCreateContextAttribsARB")), -#endif - {-1} }; @@ -1857,7 +1852,6 @@ static int create_window_w32_gl3(struct MPGLContext *ctx, int gl_flags, HWND win = vo_w32_window; HDC windc = vo_w32_get_dc(win); HGLRC new_context = 0; - GL *gl = ctx->gl; new_context = wglCreateContext(windc); if (!new_context) { @@ -1871,13 +1865,22 @@ static int create_window_w32_gl3(struct MPGLContext *ctx, int gl_flags, goto out; } - getFunctions(ctx->gl, w32gpa, NULL, true); + const char *(GLAPIENTRY *wglGetExtensionsStringARB)(HDC hdc) + = w32gpa((const GLubyte*)"wglGetExtensionsStringARB"); - if (!gl->wglCreateContextAttribsARB) { - mp_msg(MSGT_VO, MSGL_ERR, "[gl] The current OpenGL implementation does" - " not support OpenGL 3.x \n"); - goto out; - } + if (!wglGetExtensionsStringARB) + goto unsupported; + + const char *wgl_exts = wglGetExtensionsStringARB(windc); + if (!strstr(wgl_exts, "WGL_ARB_create_context")) + goto unsupported; + + HGLRC (GLAPIENTRY *wglCreateContextAttribsARB)(HDC hDC, HGLRC hShareContext, + const int *attribList) + = w32gpa((const GLubyte*)"wglCreateContextAttribsARB"); + + if (!wglCreateContextAttribsARB) + goto unsupported; int attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, MPGL_VER_GET_MAJOR(gl_version), @@ -1887,13 +1890,13 @@ static int create_window_w32_gl3(struct MPGLContext *ctx, int gl_flags, 0 }; - *context = gl->wglCreateContextAttribsARB(windc, 0, attribs); + *context = wglCreateContextAttribsARB(windc, 0, attribs); if (! *context) { // NVidia, instead of ignoring WGL_CONTEXT_FLAGS_ARB, will error out if // it's present on pre-3.2 contexts. // Remove it from attribs and retry the context creation. attribs[6] = attribs[7] = 0; - *context = gl->wglCreateContextAttribsARB(windc, 0, attribs); + *context = wglCreateContextAttribsARB(windc, 0, attribs); } if (! *context) { int err = GetLastError(); @@ -1914,7 +1917,19 @@ static int create_window_w32_gl3(struct MPGLContext *ctx, int gl_flags, /* update function pointers */ getFunctions(ctx->gl, w32gpa, NULL, true); + int pfmt = GetPixelFormat(windc); + PIXELFORMATDESCRIPTOR pfd; + if (DescribePixelFormat(windc, pfmt, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) { + ctx->depth_r = pfd.cRedBits; + ctx->depth_g = pfd.cGreenBits; + ctx->depth_b = pfd.cBlueBits; + } + return 0; + +unsupported: + mp_msg(MSGT_VO, MSGL_ERR, "[gl] The current OpenGL implementation does" + " not support OpenGL 3.x \n"); out: wglDeleteContext(new_context); return -1; diff --git a/libvo/gl_common.h b/libvo/gl_common.h index 880ce5ba22..ef394f82d5 100644 --- a/libvo/gl_common.h +++ b/libvo/gl_common.h @@ -573,10 +573,6 @@ struct GL { const GLfloat *); void (GLAPIENTRY *UniformMatrix4x3fv)(GLint, GLsizei, GLboolean, const GLfloat *); -#ifdef CONFIG_GL_WIN32 - HGLRC (GLAPIENTRY *wglCreateContextAttribsARB)(HDC hDC, HGLRC hShareContext, - const int *attribList); -#endif }; -- 2.11.4.GIT