[PATCH 5/7] wined3d: Use wglCreateContextAttribsARB() to create GL contexts when available.

Matteo Bruni mbruni at codeweavers.com
Thu Apr 18 14:20:02 CDT 2013


---
 dlls/wined3d/context.c         | 36 +++++++++++++++++++++++++-----------
 dlls/wined3d/directx.c         |  3 +++
 dlls/wined3d/wined3d_gl.h      |  1 +
 dlls/wined3d/wined3d_private.h |  2 ++
 4 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 516e8c2..f7f6762 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -1367,24 +1367,38 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
         goto out;
     }
 
-    if (!(ctx = wglCreateContext(hdc)))
+    if (gl_info->supported[WGL_ARB_CREATE_CONTEXT])
     {
-        ERR("Failed to create a WGL context.\n");
-        context_release(ret);
-        goto out;
-    }
+        HGLRC prev_ctx = (device->context_count) ? device->contexts[0]->glCtx : NULL;
 
-    if (device->context_count)
+        TRACE("Creating a new GL context via wglCreateContextAttribsARB.\n");
+        if (!(ctx = gl_info->p_wglCreateContextAttribsARB(hdc, prev_ctx, NULL)))
+        {
+            ERR("Failed to create a WGL context.\n");
+            context_release(ret);
+            goto out;
+        }
+    }
+    else
     {
-        if (!wglShareLists(device->contexts[0]->glCtx, ctx))
+        if (!(ctx = wglCreateContext(hdc)))
         {
-            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);
-            if (!wglDeleteContext(ctx))
-                ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError());
             goto out;
         }
+        if (device->context_count)
+        {
+            if (!wglShareLists(device->contexts[0]->glCtx, ctx))
+            {
+                ERR("wglShareLists(%p, %p) failed, last error %#x.\n",
+                        device->contexts[0]->glCtx, ctx, GetLastError());
+                context_release(ret);
+                if (!wglDeleteContext(ctx))
+                    ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError());
+                goto out;
+            }
+        }
     }
 
     if (!device_context_add(device, ret))
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index 4efcdff..966bdca 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -209,6 +209,7 @@ static const struct wined3d_extension_map gl_extension_map[] =
 
 static const struct wined3d_extension_map wgl_extension_map[] =
 {
+    {"WGL_ARB_create_context",              WGL_ARB_CREATE_CONTEXT           },
     {"WGL_ARB_pixel_format",                WGL_ARB_PIXEL_FORMAT             },
     {"WGL_EXT_swap_control",                WGL_EXT_SWAP_CONTROL             },
     {"WGL_WINE_pixel_format_passthrough",   WGL_WINE_PIXEL_FORMAT_PASSTHROUGH},
@@ -2376,6 +2377,8 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info)
     /* note that we still need the above wglGetProcAddress calls to initialize the table */
     gl_info->gl_ops.ext = ((struct opengl_funcs *)NtCurrentTeb()->glTable)->ext;
 #endif
+
+    gl_info->p_wglCreateContextAttribsARB = (void *)wglGetProcAddress("wglCreateContextAttribsARB");
 }
 
 static void wined3d_adapter_init_limits(struct wined3d_gl_info *gl_info)
diff --git a/dlls/wined3d/wined3d_gl.h b/dlls/wined3d/wined3d_gl.h
index e4a5bb8..a24310a 100644
--- a/dlls/wined3d/wined3d_gl.h
+++ b/dlls/wined3d/wined3d_gl.h
@@ -153,6 +153,7 @@ enum wined3d_gl_extension
     /* SGI */
     SGIS_GENERATE_MIPMAP,
     /* WGL extensions */
+    WGL_ARB_CREATE_CONTEXT,
     WGL_ARB_PIXEL_FORMAT,
     WGL_EXT_SWAP_CONTROL,
     WGL_WINE_PIXEL_FORMAT_PASSTHROUGH,
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 1ee9b9f..ffb22fe 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1555,6 +1555,8 @@ struct wined3d_gl_info
     struct opengl_funcs gl_ops;
     struct wined3d_fbo_ops fbo_ops;
 
+    HGLRC WINAPI (*p_wglCreateContextAttribsARB)(HDC hdc, HGLRC share, const int *attribs);
+
     struct wined3d_format *formats;
 };
 
-- 
1.8.1.5




More information about the wine-patches mailing list