From dc476b6bf54aca0c2c8cd093b4c35c57dc8ddf8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Thu, 12 Jul 2012 14:06:34 +0000 Subject: [PATCH] [OPENGL32] * Track pixel format with window handle for device contexts * Fix SetPixelFormat in case pixel format were already set svn path=/trunk/; revision=56873 --- reactos/dll/win32/opengl32/opengl32.h | 2 +- reactos/dll/win32/opengl32/wgl.c | 45 +++++++++++++++------------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/reactos/dll/win32/opengl32/opengl32.h b/reactos/dll/win32/opengl32/opengl32.h index 8c30f9da67c..09d2687dfa1 100644 --- a/reactos/dll/win32/opengl32/opengl32.h +++ b/reactos/dll/win32/opengl32/opengl32.h @@ -158,7 +158,7 @@ typedef struct tagGLRC /* 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 */ diff --git a/reactos/dll/win32/opengl32/wgl.c b/reactos/dll/win32/opengl32/wgl.c index cdc2ae41f5b..ccc83d1b22b 100644 --- a/reactos/dll/win32/opengl32/wgl.c +++ b/reactos/dll/win32/opengl32/wgl.c @@ -250,6 +250,7 @@ GLDCDATA * ROSGL_GetPrivateDCData( HDC hdc ) { GLDCDATA *data; + HANDLE handle; /* check hdc */ if (GetObjectType( hdc ) != OBJ_DC && GetObjectType( hdc ) != OBJ_MEMDC) @@ -267,11 +268,17 @@ ROSGL_GetPrivateDCData( HDC hdc ) 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 @@ ROSGL_GetPrivateDCData( HDC hdc ) } else { - data->hdc = hdc; + data->handle = handle; /* append data to list */ if (OPENGL32_processdata.dcdata_list == NULL) @@ -1111,34 +1118,32 @@ BOOL 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" ); - return FALSE; - } - - /* call ICD */ - if (!icd->DrvSetPixelFormat( hdc, iFormat, pfd )) - { - DBGPRINT( "Warning: DrvSetPixelFormat(format=%d) failed (%d)", - iFormat, GetLastError() ); - return FALSE; - } - - /* store format in private DC data */ + /* Get private DC data */ dcdata = ROSGL_GetPrivateDCData( hdc ); if (dcdata == NULL) { DBGPRINT( "Error: ROSGL_GetPrivateDCData() failed!" ); return FALSE; } + /* 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; + } dcdata->pixel_format = iFormat; return TRUE;