1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 * Fake WGL API implementation.
33 * These functions implement the WGL API, on top of the ICD DDI, so that the
34 * resulting DLL can be used as a drop-in replacement for the system's
37 * These functions never get called for ICD drivers, which use exclusively the
38 * ICD DDI, i.e., the Drv* entrypoints.
43 #include "util/u_debug.h"
45 #include "stw_context.h"
46 #include "stw_pixelformat.h"
48 #include "stw_ext_context.h"
52 overrideOpenGL32EntryPoints(void);
54 WINGDIAPI BOOL APIENTRY
60 return DrvCopyContext( (DHGLRC
)(UINT_PTR
)hglrcSrc
,
61 (DHGLRC
)(UINT_PTR
)hglrcDst
,
65 WINGDIAPI HGLRC APIENTRY
69 overrideOpenGL32EntryPoints();
70 return (HGLRC
) DrvCreateContext(hdc
);
73 WINGDIAPI HGLRC APIENTRY
74 wglCreateLayerContext(
78 overrideOpenGL32EntryPoints();
79 return (HGLRC
) DrvCreateLayerContext( hdc
, iLayerPlane
);
82 WINGDIAPI BOOL APIENTRY
86 return DrvDeleteContext((DHGLRC
)(UINT_PTR
)hglrc
);
90 WINGDIAPI HGLRC APIENTRY
91 wglGetCurrentContext( VOID
)
93 return (HGLRC
)(UINT_PTR
)stw_get_current_context();
96 WINGDIAPI HDC APIENTRY
97 wglGetCurrentDC( VOID
)
99 return stw_get_current_dc();
102 WINGDIAPI HDC APIENTRY
103 wglGetCurrentReadDCARB( VOID
)
105 return stw_get_current_read_dc();
109 WINGDIAPI BOOL APIENTRY
114 return DrvSetContext( hdc
, (DHGLRC
)(UINT_PTR
)hglrc
, NULL
) ? TRUE
: FALSE
;
118 WINGDIAPI BOOL APIENTRY
122 return DrvSwapBuffers( hdc
);
126 WINGDIAPI DWORD WINAPI
127 wglSwapMultipleBuffers(UINT n
,
132 for (i
=0; i
< n
; ++i
)
133 wglSwapBuffers(ps
->hdc
);
139 WINGDIAPI BOOL APIENTRY
144 return DrvSwapLayerBuffers( hdc
, fuPlanes
);
147 WINGDIAPI PROC APIENTRY
151 return DrvGetProcAddress( lpszProc
);
155 WINGDIAPI
int APIENTRY
156 wglChoosePixelFormat(
158 CONST PIXELFORMATDESCRIPTOR
*ppfd
)
160 if (ppfd
->nSize
!= sizeof( PIXELFORMATDESCRIPTOR
) || ppfd
->nVersion
!= 1)
162 if (ppfd
->iPixelType
!= PFD_TYPE_RGBA
)
164 if (!(ppfd
->dwFlags
& PFD_DRAW_TO_WINDOW
))
166 if (!(ppfd
->dwFlags
& PFD_SUPPORT_OPENGL
))
168 if (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
)
170 if (ppfd
->dwFlags
& PFD_SUPPORT_GDI
)
172 if (!(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) && (ppfd
->dwFlags
& PFD_STEREO
))
175 return stw_pixelformat_choose( hdc
, ppfd
);
178 WINGDIAPI
int APIENTRY
179 wglDescribePixelFormat(
183 LPPIXELFORMATDESCRIPTOR ppfd
)
185 return DrvDescribePixelFormat( hdc
, iPixelFormat
, nBytes
, ppfd
);
188 WINGDIAPI
int APIENTRY
192 return stw_pixelformat_get( hdc
);
195 WINGDIAPI BOOL APIENTRY
199 const PIXELFORMATDESCRIPTOR
*ppfd
)
201 /* SetPixelFormat (hence wglSetPixelFormat) must not touch ppfd, per
202 * http://msdn.microsoft.com/en-us/library/dd369049(v=vs.85).aspx
206 return DrvSetPixelFormat( hdc
, iPixelFormat
);
210 WINGDIAPI BOOL APIENTRY
227 WINGDIAPI BOOL APIENTRY
232 return DrvShareLists((DHGLRC
)(UINT_PTR
)hglrc1
,
233 (DHGLRC
)(UINT_PTR
)hglrc2
);
236 WINGDIAPI BOOL APIENTRY
253 WINGDIAPI BOOL APIENTRY
262 LPGLYPHMETRICSFLOAT lpgmf
)
278 WINGDIAPI BOOL APIENTRY
287 LPGLYPHMETRICSFLOAT lpgmf
)
303 WINGDIAPI BOOL APIENTRY
304 wglDescribeLayerPlane(
309 LPLAYERPLANEDESCRIPTOR plpd
)
311 return DrvDescribeLayerPlane(hdc
, iPixelFormat
, iLayerPlane
, nBytes
, plpd
);
314 WINGDIAPI
int APIENTRY
315 wglSetLayerPaletteEntries(
320 CONST COLORREF
*pcr
)
322 return DrvSetLayerPaletteEntries(hdc
, iLayerPlane
, iStart
, cEntries
, pcr
);
325 WINGDIAPI
int APIENTRY
326 wglGetLayerPaletteEntries(
333 return DrvGetLayerPaletteEntries(hdc
, iLayerPlane
, iStart
, cEntries
, pcr
);
336 WINGDIAPI BOOL APIENTRY
337 wglRealizeLayerPalette(
352 /* When this library is used as a opengl32.dll drop-in replacement, ensure we
353 * use the wglCreate/Destroy entrypoints above, and not the true opengl32.dll,
354 * which could happen if this library's name is not opengl32.dll exactly.
356 * For example, Qt 5.4 bundles this as opengl32sw.dll:
357 * https://blog.qt.io/blog/2014/11/27/qt-weekly-21-dynamic-opengl-implementation-loading-in-qt-5-4/
360 overrideOpenGL32EntryPoints(void)
362 wglCreateContext_func
= &wglCreateContext
;
363 wglDeleteContext_func
= &wglDeleteContext
;