Henri Verbeet : wined3d: Use WGL_ARB_create_context when available.

Alexandre Julliard julliard at winehq.org
Fri Apr 19 14:25:06 CDT 2013


Module: wine
Branch: master
Commit: 5115f55eebe5cb91f13896862275e236a4954744
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=5115f55eebe5cb91f13896862275e236a4954744

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Fri Apr 19 08:34:11 2013 +0200

wined3d: Use WGL_ARB_create_context when available.

---

 dlls/wined3d/context.c         |   29 +++++++++++++++++++----------
 dlls/wined3d/directx.c         |   31 +++++++++++++++++++++++++++++++
 dlls/wined3d/wined3d_private.h |    1 +
 3 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 516e8c2..0d6550a 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -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 (!(ctx = gl_info->p_wglCreateContextAttribsARB(hdc, share_ctx, NULL)))
+        {
+            ERR("Failed to create a WGL context.\n");
+            context_release(ret);
+            goto out;
+        }
     }
-
-    if (device->context_count)
+    else
     {
-        if (!wglShareLists(device->contexts[0]->glCtx, ctx))
+        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",
-                    device->contexts[0]->glCtx, ctx, GetLastError());
+            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());
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index b9640f9..8f1dfb7 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -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);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 1ee9b9f..c8b4ff9 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -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;
 




More information about the wine-cvs mailing list