2 * OpenGL function forwarding to the display driver
4 * Copyright (c) 1999 Lionel Ulmer
5 * Copyright (c) 2005 Raphael Junqueira
6 * Copyright (c) 2006 Roderick Colenbrander
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
36 #include "gdi_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
41 static HDC default_hdc = 0;
43 /* We route all wgl functions from opengl32.dll through gdi32.dll to
44 * the display driver. Various wgl calls have a hDC as one of their parameters.
45 * Using get_dc_ptr we get access to the functions exported by the driver.
46 * Some functions don't receive a hDC. This function creates a global hdc and
47 * if there's already a global hdc, it returns it.
49 static DC* OPENGL_GetDefaultDC(void)
52 default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
54 return get_dc_ptr(default_hdc);
57 /***********************************************************************
58 * wglCreateContext (OPENGL32.@)
60 HGLRC WINAPI wglCreateContext(HDC hdc)
63 DC * dc = get_dc_ptr( hdc );
69 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglCreateContext );
71 ret = physdev->funcs->pwglCreateContext( physdev );
77 /***********************************************************************
78 * wglCreateContextAttribsARB
80 static HGLRC WINAPI wglCreateContextAttribsARB(HDC hdc, HGLRC hShareContext, const int *attributeList)
83 DC * dc = get_dc_ptr( hdc );
89 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglCreateContextAttribsARB );
91 ret = physdev->funcs->pwglCreateContextAttribsARB( physdev, hShareContext, attributeList );
97 /***********************************************************************
98 * wglMakeCurrent (OPENGL32.@)
100 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
105 /* When the context hglrc is NULL, the HDC is ignored and can be NULL.
106 * In that case use the global hDC to get access to the driver. */
109 if (hdc == NULL && !NtCurrentTeb()->glContext)
111 WARN( "Current context is NULL\n");
112 SetLastError( ERROR_INVALID_HANDLE );
115 dc = OPENGL_GetDefaultDC();
118 dc = get_dc_ptr( hdc );
120 TRACE("hdc: (%p), hglrc: (%p)\n", hdc, hglrc);
124 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglMakeCurrent );
126 ret = physdev->funcs->pwglMakeCurrent( physdev, hglrc );
127 release_dc_ptr( dc );
132 /***********************************************************************
133 * wglMakeContextCurrentARB
135 static BOOL WINAPI wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc)
138 PHYSDEV draw_physdev, read_physdev;
142 TRACE("hDrawDC: (%p), hReadDC: (%p) hglrc: (%p)\n", hDrawDC, hReadDC, hglrc);
144 /* Both hDrawDC and hReadDC need to be valid */
145 DrawDC = get_dc_ptr( hDrawDC );
146 if (!DrawDC) return FALSE;
148 ReadDC = get_dc_ptr( hReadDC );
150 release_dc_ptr( DrawDC );
156 draw_physdev = GET_DC_PHYSDEV( DrawDC, pwglMakeContextCurrentARB );
157 read_physdev = GET_DC_PHYSDEV( ReadDC, pwglMakeContextCurrentARB );
158 if (draw_physdev->funcs == read_physdev->funcs)
159 ret = draw_physdev->funcs->pwglMakeContextCurrentARB(draw_physdev, read_physdev, hglrc);
160 release_dc_ptr( DrawDC );
161 release_dc_ptr( ReadDC );
165 /**************************************************************************************
166 * WINE-specific wglSetPixelFormat which can set the iPixelFormat multiple times
169 static BOOL WINAPI wglSetPixelFormatWINE(HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
172 DC * dc = get_dc_ptr( hdc );
174 TRACE("(%p,%d,%p)\n", hdc, iPixelFormat, ppfd);
178 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglSetPixelFormatWINE );
180 bRet = physdev->funcs->pwglSetPixelFormatWINE( physdev, iPixelFormat, ppfd );
181 release_dc_ptr( dc );
186 /***********************************************************************
187 * Internal wglGetProcAddress for retrieving WGL extensions
189 PROC WINAPI wglGetProcAddress(LPCSTR func)
197 TRACE("func: '%s'\n", func);
199 /* Retrieve the global hDC to get access to the driver. */
200 dc = OPENGL_GetDefaultDC();
203 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglGetProcAddress );
204 ret = physdev->funcs->pwglGetProcAddress(func);
205 release_dc_ptr( dc );
208 /* At the moment we implement one WGL extension which requires a HDC. When we
209 * are looking up this call and when the Extension is available (that is the case
210 * when a non-NULL value is returned by wglGetProcAddress), we return the address
211 * of a wrapper function which will handle the HDC->PhysDev conversion.
213 if(ret && strcmp(func, "wglCreateContextAttribsARB") == 0)
214 return (PROC)wglCreateContextAttribsARB;
215 else if(ret && strcmp(func, "wglMakeContextCurrentARB") == 0)
216 return (PROC)wglMakeContextCurrentARB;
217 else if(ret && strcmp(func, "wglSetPixelFormatWINE") == 0)
218 return (PROC)wglSetPixelFormatWINE;