1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-11 00:29:02 +00:00

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.
This commit is contained in:
wm4 2012-03-18 19:22:49 +01:00
parent 59125ce71e
commit 35c29bdd52
2 changed files with 29 additions and 18 deletions

View File

@ -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;

View File

@ -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
};