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 * Internal wglGetProcAddress for retrieving WGL extensions
107 PROC WINAPI
wglGetProcAddress(LPCSTR func
)
115 TRACE("func: '%s'\n", func
);
117 /* Retrieve the global hDC to get access to the driver. */
118 dc
= OPENGL_GetDefaultDC();
121 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pwglGetProcAddress
);
122 ret
= physdev
->funcs
->pwglGetProcAddress(func
);
123 release_dc_ptr( dc
);
126 /* At the moment we implement one WGL extension which requires a HDC. When we
127 * are looking up this call and when the Extension is available (that is the case
128 * when a non-NULL value is returned by wglGetProcAddress), we return the address
129 * of a wrapper function which will handle the HDC->PhysDev conversion.
131 if(ret
&& strcmp(func
, "wglCreateContextAttribsARB") == 0)
132 return (PROC
)wglCreateContextAttribsARB
;
137 /******************************************************************************
138 * ChoosePixelFormat (GDI32.@)
140 INT WINAPI
ChoosePixelFormat( HDC hdc
, const PIXELFORMATDESCRIPTOR
*pfd
)
142 if (!wglChoosePixelFormat
)
144 if (!opengl32
) opengl32
= LoadLibraryW( opengl32W
);
145 if (!(wglChoosePixelFormat
= (void *)GetProcAddress( opengl32
, "wglChoosePixelFormat" )))
148 return wglChoosePixelFormat( hdc
, pfd
);
151 /******************************************************************************
152 * DescribePixelFormat (GDI32.@)
154 INT WINAPI
DescribePixelFormat( HDC hdc
, INT fmt
, UINT size
, PIXELFORMATDESCRIPTOR
*pfd
)
156 if (!wglDescribePixelFormat
)
158 if (!opengl32
) opengl32
= LoadLibraryW( opengl32W
);
159 if (!(wglDescribePixelFormat
= (void *)GetProcAddress( opengl32
, "wglDescribePixelFormat" )))
162 return wglDescribePixelFormat( hdc
, fmt
, size
, pfd
);
165 /******************************************************************************
166 * SetPixelFormat (GDI32.@)
168 BOOL WINAPI
SetPixelFormat( HDC hdc
, INT fmt
, const PIXELFORMATDESCRIPTOR
*pfd
)
170 if (!wglSetPixelFormat
)
172 if (!opengl32
) opengl32
= LoadLibraryW( opengl32W
);
173 if (!(wglSetPixelFormat
= (void *)GetProcAddress( opengl32
, "wglSetPixelFormat" )))
176 return wglSetPixelFormat( hdc
, fmt
, pfd
);
179 /******************************************************************************
180 * SwapBuffers (GDI32.@)
182 BOOL WINAPI
SwapBuffers( HDC hdc
)
186 if (!opengl32
) opengl32
= LoadLibraryW( opengl32W
);
187 if (!(wglSwapBuffers
= (void *)GetProcAddress( opengl32
, "wglSwapBuffers" )))
190 return wglSwapBuffers( hdc
);