wined3d: Use WGL_ARB_create_context when available.

This commit is contained in:
Henri Verbeet 2013-04-19 08:34:11 +02:00 committed by Alexandre Julliard
parent 147765a505
commit 5115f55eeb
3 changed files with 53 additions and 12 deletions

View File

@ -1266,11 +1266,11 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
const struct wined3d_format *color_format;
struct wined3d_context *ret;
BOOL auxBuffers = FALSE;
HGLRC ctx, share_ctx;
int pixel_format;
unsigned int s;
int swap_interval;
DWORD state;
HGLRC ctx;
HDC hdc;
TRACE("swapchain %p, target %p, window %p.\n", swapchain, target, swapchain->win_handle);
@ -1367,19 +1367,28 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
goto out;
}
if (!(ctx = wglCreateContext(hdc)))
share_ctx = device->context_count ? device->contexts[0]->glCtx : NULL;
if (gl_info->p_wglCreateContextAttribsARB)
{
ERR("Failed to create a WGL context.\n");
context_release(ret);
goto out;
}
if (device->context_count)
{
if (!wglShareLists(device->contexts[0]->glCtx, ctx))
if (!(ctx = gl_info->p_wglCreateContextAttribsARB(hdc, share_ctx, NULL)))
{
ERR("wglShareLists(%p, %p) failed, last error %#x.\n",
device->contexts[0]->glCtx, ctx, GetLastError());
ERR("Failed to create a WGL context.\n");
context_release(ret);
goto out;
}
}
else
{
if (!(ctx = wglCreateContext(hdc)))
{
ERR("Failed to create a WGL context.\n");
context_release(ret);
goto out;
}
if (share_ctx && !wglShareLists(share_ctx, ctx))
{
ERR("wglShareLists(%p, %p) failed, last error %#x.\n", share_ctx, ctx, GetLastError());
context_release(ret);
if (!wglDeleteContext(ctx))
ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError());

View File

@ -296,6 +296,35 @@ static void WineD3D_ReleaseFakeGLContext(const struct wined3d_fake_gl_ctx *ctx)
ERR("Failed to restore previous GL context.\n");
}
static void wined3d_create_fake_gl_context_attribs(struct wined3d_fake_gl_ctx *fake_gl_ctx,
struct wined3d_gl_info *gl_info)
{
HGLRC new_ctx;
if (!(gl_info->p_wglCreateContextAttribsARB = (void *)wglGetProcAddress("wglCreateContextAttribsARB")))
return;
if (!(new_ctx = gl_info->p_wglCreateContextAttribsARB(fake_gl_ctx->dc, NULL, NULL)))
{
ERR("Failed to create a context using wglCreateContextAttribsARB(), last error %#x.\n", GetLastError());
gl_info->p_wglCreateContextAttribsARB = NULL;
return;
}
if (!wglMakeCurrent(fake_gl_ctx->dc, new_ctx))
{
ERR("Failed to make new context current, last error %#x.\n", GetLastError());
if (!wglDeleteContext(new_ctx))
ERR("Failed to delete new context, last error %#x.\n", GetLastError());
gl_info->p_wglCreateContextAttribsARB = NULL;
return;
}
if (!wglDeleteContext(fake_gl_ctx->gl_ctx))
ERR("Failed to delete old context, last error %#x.\n", GetLastError());
fake_gl_ctx->gl_ctx = new_ctx;
}
/* Do not call while under the GL lock. */
static BOOL WineD3D_CreateFakeGLContext(struct wined3d_fake_gl_ctx *ctx)
{
@ -4919,6 +4948,8 @@ static BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, UINT ordinal)
return FALSE;
}
wined3d_create_fake_gl_context_attribs(&fake_gl_ctx, gl_info);
if (!wined3d_adapter_init_gl_caps(adapter))
{
ERR("Failed to initialize GL caps for adapter %p.\n", adapter);

View File

@ -1552,6 +1552,7 @@ struct wined3d_gl_info
BOOL supported[WINED3D_GL_EXT_COUNT];
GLint wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP + 1];
HGLRC (WINAPI *p_wglCreateContextAttribsARB)(HDC dc, HGLRC share, const GLint *attribs);
struct opengl_funcs gl_ops;
struct wined3d_fbo_ops fbo_ops;