Author: jgardou
Date: Thu Jul 12 14:06:34 2012
New Revision: 56873

URL: http://svn.reactos.org/svn/reactos?rev=56873&view=rev
Log:
[OPENGL32]
 * Track pixel format with window handle for device contexts
 * Fix SetPixelFormat in case pixel format were already set

Modified:
    trunk/reactos/dll/win32/opengl32/opengl32.h
    trunk/reactos/dll/win32/opengl32/wgl.c

Modified: trunk/reactos/dll/win32/opengl32/opengl32.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/opengl32/opengl32.h?rev=56873&r1=56872&r2=56873&view=diff
==============================================================================
--- trunk/reactos/dll/win32/opengl32/opengl32.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/opengl32/opengl32.h [iso-8859-1] Thu Jul 12 
14:06:34 2012
@@ -158,7 +158,7 @@
 /* OpenGL private device context data */
 typedef struct tagGLDCDATA
 {
-    HDC hdc;           /*!< Device context handle for which this data is */
+    HANDLE handle;     /*!< Handle for which this data is (HWND for device, 
HDC for memory context) */
     GLDRIVERDATA *icd; /*!< Driver used for this DC */
     int pixel_format;  /*!< Selected pixel format */
 

Modified: trunk/reactos/dll/win32/opengl32/wgl.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/opengl32/wgl.c?rev=56873&r1=56872&r2=56873&view=diff
==============================================================================
--- trunk/reactos/dll/win32/opengl32/wgl.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/opengl32/wgl.c [iso-8859-1] Thu Jul 12 14:06:34 2012
@@ -250,6 +250,7 @@
 ROSGL_GetPrivateDCData( HDC hdc )
 {
     GLDCDATA *data;
+    HANDLE handle;
 
     /* check hdc */
     if (GetObjectType( hdc ) != OBJ_DC && GetObjectType( hdc ) != OBJ_MEMDC)
@@ -267,11 +268,17 @@
         return NULL; /* FIXME: do we have to expect such an error and handle 
it? */
     }
 
+    /* We must use the window to identify our data, as pixel format is
+     * specific to a window for device context */
+    handle = WindowFromDC(hdc);
+    if(!handle)
+        handle = hdc;
+
     /* look for data in list */
     data = OPENGL32_processdata.dcdata_list;
     while (data != NULL)
     {
-        if (data->hdc == hdc) /* found */
+        if (data->handle == handle) /* found */
             break;
         data = data->next;
     }
@@ -288,7 +295,7 @@
         }
         else
         {
-            data->hdc = hdc;
+            data->handle = handle;
 
             /* append data to list */
             if (OPENGL32_processdata.dcdata_list == NULL)
@@ -1111,34 +1118,32 @@
 WINAPI
 rosglSetPixelFormat( HDC hdc, int iFormat, CONST PIXELFORMATDESCRIPTOR *pfd )
 {
-    GLDRIVERDATA *icd;
     GLDCDATA *dcdata;
+    GLDRIVERDATA* icd;
 
     DBGTRACE( "Called!" );
 
-    /* load ICD */
-    icd = ROSGL_ICDForHDC( hdc );
-    if (icd == NULL)
-    {
-        DBGPRINT( "Warning: ICDForHDC() failed" );
+    /* Get private DC data */
+    dcdata = ROSGL_GetPrivateDCData( hdc );
+    if (dcdata == NULL)
+    {
+        DBGPRINT( "Error: ROSGL_GetPrivateDCData() failed!" );
         return FALSE;
     }
-
-    /* call ICD */
+    /* you can set the same pixel format twice, but you can't modify it */
+    if(dcdata->pixel_format) return dcdata->pixel_format == iFormat;
+
+    icd = ROSGL_ICDForHDC(hdc);
+    if(icd == NULL)
+        return 0;
+
+    /* Call ICD function */
     if (!icd->DrvSetPixelFormat( hdc, iFormat, pfd ))
     {
         DBGPRINT( "Warning: DrvSetPixelFormat(format=%d) failed (%d)",
                   iFormat, GetLastError() );
         return FALSE;
     }
-
-    /* store format in private DC data */
-    dcdata = ROSGL_GetPrivateDCData( hdc );
-    if (dcdata == NULL)
-    {
-        DBGPRINT( "Error: ROSGL_GetPrivateDCData() failed!" );
-        return FALSE;
-    }
     dcdata->pixel_format = iFormat;
 
     return TRUE;


Reply via email to