diff options
author | wm4 <wm4@mplayer2.org> | 2012-03-18 19:22:49 +0100 |
---|---|---|
committer | wm4 <wm4@mplayer2.org> | 2012-03-31 02:58:52 +0200 |
commit | 35c29bdd52c04098f928fd7151a7f2e94337bea0 (patch) | |
tree | bc0143fa89aa91664a365413fd026be4ff028ae8 | |
parent | 59125ce71e378ae169eaecc8ac04d72bda3d130d (diff) | |
download | mpv-35c29bdd52c04098f928fd7151a7f2e94337bea0.tar.bz2 mpv-35c29bdd52c04098f928fd7151a7f2e94337bea0.tar.xz |
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.
-rw-r--r-- | libvo/gl_common.c | 43 | ||||
-rw-r--r-- | 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 fc83ab9f7f..223404fd85 100644 --- a/libvo/gl_common.c +++ b/libvo/gl_common.c @@ -487,11 +487,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} }; @@ -1856,7 +1851,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) { @@ -1870,13 +1864,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), @@ -1886,13 +1889,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(); @@ -1913,7 +1916,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 5b35e0aa63..2f6b4b5083 100644 --- a/libvo/gl_common.h +++ b/libvo/gl_common.h @@ -567,10 +567,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 }; |