[PATCH 4/5] opengl32: Store the OpenGL context version in the handle value.

Matteo Bruni mbruni at codeweavers.com
Wed Jan 14 09:27:34 CST 2015


---
 dlls/opengl32/wgl.c | 45 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c
index 3a5e148..0fee5c9 100644
--- a/dlls/opengl32/wgl.c
+++ b/dlls/opengl32/wgl.c
@@ -53,7 +53,14 @@ enum wgl_handle_type
 {
     HANDLE_CONTEXT = 0 << 12,
     HANDLE_PBUFFER = 1 << 12,
-    HANDLE_TYPE_MASK = 15 << 12
+    HANDLE_TYPE_MASK = 7 << 12
+};
+
+enum wgl_opengl_version
+{
+    OPENGL_1 = 0 << 15,
+    OPENGL_3 = 1 << 15,
+    OPENGL_VER_MASK = 1 << 15
 };
 
 struct opengl_context
@@ -97,11 +104,12 @@ static inline struct opengl_funcs *get_dc_funcs( HDC hdc )
     return funcs;
 }
 
-static inline HANDLE next_handle( struct wgl_handle *ptr, enum wgl_handle_type type )
+static inline HANDLE next_handle( struct wgl_handle *ptr, enum wgl_handle_type type,
+                                  enum wgl_opengl_version ver )
 {
     WORD generation = HIWORD( ptr->handle ) + 1;
     if (!generation) generation++;
-    ptr->handle = MAKELONG( ptr - wgl_handles, generation ) | type;
+    ptr->handle = MAKELONG( ptr - wgl_handles, generation ) | type | ver;
     return ULongToHandle( ptr->handle );
 }
 
@@ -109,12 +117,12 @@ static inline HANDLE next_handle( struct wgl_handle *ptr, enum wgl_handle_type t
 static inline struct wgl_handle *get_current_context_ptr(void)
 {
     if (!NtCurrentTeb()->glCurrentRC) return NULL;
-    return &wgl_handles[LOWORD(NtCurrentTeb()->glCurrentRC) & ~HANDLE_TYPE_MASK];
+    return &wgl_handles[LOWORD(NtCurrentTeb()->glCurrentRC) & ~(HANDLE_TYPE_MASK | OPENGL_VER_MASK)];
 }
 
 static struct wgl_handle *get_handle_ptr( HANDLE handle, enum wgl_handle_type type )
 {
-    unsigned int index = LOWORD( handle ) & ~HANDLE_TYPE_MASK;
+    unsigned int index = LOWORD( handle ) & ~(HANDLE_TYPE_MASK | OPENGL_VER_MASK);
 
     EnterCriticalSection( &wgl_section );
     if (index < handle_count && ULongToHandle(wgl_handles[index].handle) == handle)
@@ -130,7 +138,8 @@ static void release_handle_ptr( struct wgl_handle *ptr )
     if (ptr) LeaveCriticalSection( &wgl_section );
 }
 
-static HANDLE alloc_handle( enum wgl_handle_type type, struct opengl_funcs *funcs, void *user_ptr )
+static HANDLE alloc_handle( enum wgl_handle_type type, enum wgl_opengl_version ver,
+                            struct opengl_funcs *funcs, void *user_ptr )
 {
     HANDLE handle = 0;
     struct wgl_handle *ptr = NULL;
@@ -145,7 +154,7 @@ static HANDLE alloc_handle( enum wgl_handle_type type, struct opengl_funcs *func
     {
         ptr->funcs = funcs;
         ptr->u.context = user_ptr;
-        handle = next_handle( ptr, type );
+        handle = next_handle( ptr, type, ver );
     }
     else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
     LeaveCriticalSection( &wgl_section );
@@ -270,8 +279,24 @@ HGLRC WINAPI wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *attrib
     {
         if ((context = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*context) )))
         {
+            enum wgl_opengl_version version = OPENGL_1;
+
+            if (attribs)
+            {
+                while (*attribs)
+                {
+                    if (attribs[0] == WGL_CONTEXT_MAJOR_VERSION_ARB)
+                    {
+                        if (attribs[1] >= 3)
+                            version = OPENGL_3;
+                        break;
+                    }
+                    attribs += 2;
+                }
+            }
+
             context->drv_ctx = drv_ctx;
-            if (!(ret = alloc_handle( HANDLE_CONTEXT, funcs, context )))
+            if (!(ret = alloc_handle( HANDLE_CONTEXT, version, funcs, context )))
                 HeapFree( GetProcessHeap(), 0, context );
         }
         if (!ret) funcs->wgl.p_wglDeleteContext( drv_ctx );
@@ -384,7 +409,7 @@ HGLRC WINAPI wglCreateContext(HDC hdc)
     if ((context = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*context) )))
     {
         context->drv_ctx = drv_ctx;
-        if (!(ret = alloc_handle( HANDLE_CONTEXT, funcs, context )))
+        if (!(ret = alloc_handle( HANDLE_CONTEXT, OPENGL_1, funcs, context )))
             HeapFree( GetProcessHeap(), 0, context );
     }
     if (!ret) funcs->wgl.p_wglDeleteContext( drv_ctx );
@@ -956,7 +981,7 @@ HPBUFFERARB WINAPI wglCreatePbufferARB( HDC hdc, int format, int width, int heig
 
     if (!funcs || !funcs->ext.p_wglCreatePbufferARB) return 0;
     if (!(pbuffer = funcs->ext.p_wglCreatePbufferARB( hdc, format, width, height, attribs ))) return 0;
-    ret = alloc_handle( HANDLE_PBUFFER, funcs, pbuffer );
+    ret = alloc_handle( HANDLE_PBUFFER, 0, funcs, pbuffer );
     if (!ret) funcs->ext.p_wglDestroyPbufferARB( pbuffer );
     return ret;
 }
-- 
2.0.5




More information about the wine-patches mailing list