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 const WCHAR opengl32W[] = {'o','p','e','n','g','l','3','2','.','d','l','l',0};
42 static HMODULE opengl32;
43 static INT (WINAPI *wglChoosePixelFormat)(HDC,const PIXELFORMATDESCRIPTOR *);
44 static INT (WINAPI *wglDescribePixelFormat)(HDC,INT,UINT,PIXELFORMATDESCRIPTOR*);
45 static BOOL (WINAPI *wglSetPixelFormat)(HDC,INT,const PIXELFORMATDESCRIPTOR*);
46 static BOOL (WINAPI *wglSwapBuffers)(HDC);
48 static HDC default_hdc = 0;
50 /* We route all wgl functions from opengl32.dll through gdi32.dll to
51 * the display driver. Various wgl calls have a hDC as one of their parameters.
52 * Using get_dc_ptr we get access to the functions exported by the driver.
53 * Some functions don't receive a hDC. This function creates a global hdc and
54 * if there's already a global hdc, it returns it.
56 static DC* OPENGL_GetDefaultDC(void)
59 default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
61 return get_dc_ptr(default_hdc);
64 /***********************************************************************
65 * wglCreateContext (OPENGL32.@)
67 HGLRC WINAPI wglCreateContext(HDC hdc)
70 DC * dc = get_dc_ptr( hdc );
76 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglCreateContext );
78 ret = physdev->funcs->pwglCreateContext( physdev );
84 /***********************************************************************
85 * wglCreateContextAttribsARB
87 static HGLRC WINAPI wglCreateContextAttribsARB(HDC hdc, HGLRC hShareContext, const int *attributeList)
90 DC * dc = get_dc_ptr( hdc );
96 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglCreateContextAttribsARB );
98 ret = physdev->funcs->pwglCreateContextAttribsARB( physdev, hShareContext, attributeList );
104 /**************************************************************************************
105 * WINE-specific wglSetPixelFormat which can set the iPixelFormat multiple times
108 static BOOL WINAPI wglSetPixelFormatWINE(HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
111 DC * dc = get_dc_ptr( hdc );
113 TRACE("(%p,%d,%p)\n", hdc, iPixelFormat, ppfd);
117 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglSetPixelFormatWINE );
119 bRet = physdev->funcs->pwglSetPixelFormatWINE( physdev, iPixelFormat, ppfd );
120 release_dc_ptr( dc );
125 /***********************************************************************
126 * Internal wglGetProcAddress for retrieving WGL extensions
128 PROC WINAPI wglGetProcAddress(LPCSTR func)
136 TRACE("func: '%s'\n", func);
138 /* Retrieve the global hDC to get access to the driver. */
139 dc = OPENGL_GetDefaultDC();
142 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglGetProcAddress );
143 ret = physdev->funcs->pwglGetProcAddress(func);
144 release_dc_ptr( dc );
147 /* At the moment we implement one WGL extension which requires a HDC. When we
148 * are looking up this call and when the Extension is available (that is the case
149 * when a non-NULL value is returned by wglGetProcAddress), we return the address
150 * of a wrapper function which will handle the HDC->PhysDev conversion.
152 if(ret && strcmp(func, "wglCreateContextAttribsARB") == 0)
153 return (PROC)wglCreateContextAttribsARB;
154 else if(ret && strcmp(func, "wglSetPixelFormatWINE") == 0)
155 return (PROC)wglSetPixelFormatWINE;
160 /******************************************************************************
161 * ChoosePixelFormat (GDI32.@)
163 INT WINAPI ChoosePixelFormat( HDC hdc, const PIXELFORMATDESCRIPTOR *pfd )
165 if (!wglChoosePixelFormat)
167 if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
168 if (!(wglChoosePixelFormat = (void *)GetProcAddress( opengl32, "wglChoosePixelFormat" )))
171 return wglChoosePixelFormat( hdc, pfd );
174 /******************************************************************************
175 * DescribePixelFormat (GDI32.@)
177 INT WINAPI DescribePixelFormat( HDC hdc, INT fmt, UINT size, PIXELFORMATDESCRIPTOR *pfd )
179 if (!wglDescribePixelFormat)
181 if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
182 if (!(wglDescribePixelFormat = (void *)GetProcAddress( opengl32, "wglDescribePixelFormat" )))
185 return wglDescribePixelFormat( hdc, fmt, size, pfd );
188 /******************************************************************************
189 * SetPixelFormat (GDI32.@)
191 BOOL WINAPI SetPixelFormat( HDC hdc, INT fmt, const PIXELFORMATDESCRIPTOR *pfd )
193 if (!wglSetPixelFormat)
195 if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
196 if (!(wglSetPixelFormat = (void *)GetProcAddress( opengl32, "wglSetPixelFormat" )))
199 return wglSetPixelFormat( hdc, fmt, pfd );
202 /******************************************************************************
203 * SwapBuffers (GDI32.@)
205 BOOL WINAPI SwapBuffers( HDC hdc )
209 if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
210 if (!(wglSwapBuffers = (void *)GetProcAddress( opengl32, "wglSwapBuffers" )))
213 return wglSwapBuffers( hdc );