opengl32: Move wglCreateContext to the WGL driver.
[wine/multimedia.git] / dlls / gdi32 / opengl.c
blobf8e5de76e5fc94286296c50a02b1660b6dad7e2a
1 /*
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
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdlib.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winerror.h"
34 #include "winternl.h"
35 #include "winnt.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)
58 if(!default_hdc)
59 default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
61 return get_dc_ptr(default_hdc);
64 /***********************************************************************
65 * Internal wglGetProcAddress for retrieving WGL extensions
67 PROC WINAPI wglGetProcAddress(LPCSTR func)
69 PROC ret = NULL;
70 DC *dc;
72 if(!func)
73 return NULL;
75 TRACE("func: '%s'\n", func);
77 /* Retrieve the global hDC to get access to the driver. */
78 dc = OPENGL_GetDefaultDC();
79 if (dc)
81 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglGetProcAddress );
82 ret = physdev->funcs->pwglGetProcAddress(func);
83 release_dc_ptr( dc );
85 return ret;
88 /***********************************************************************
89 * __wine_get_wgl_driver (GDI32.@)
91 const struct wgl_funcs * CDECL __wine_get_wgl_driver( HDC hdc, UINT version )
93 const struct wgl_funcs *ret = NULL;
94 DC * dc = get_dc_ptr( hdc );
96 if (dc)
98 PHYSDEV physdev = GET_DC_PHYSDEV( dc, wine_get_wgl_driver );
99 ret = physdev->funcs->wine_get_wgl_driver( physdev, version );
100 release_dc_ptr( dc );
102 return ret;
105 /******************************************************************************
106 * ChoosePixelFormat (GDI32.@)
108 INT WINAPI ChoosePixelFormat( HDC hdc, const PIXELFORMATDESCRIPTOR *pfd )
110 if (!wglChoosePixelFormat)
112 if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
113 if (!(wglChoosePixelFormat = (void *)GetProcAddress( opengl32, "wglChoosePixelFormat" )))
114 return 0;
116 return wglChoosePixelFormat( hdc, pfd );
119 /******************************************************************************
120 * DescribePixelFormat (GDI32.@)
122 INT WINAPI DescribePixelFormat( HDC hdc, INT fmt, UINT size, PIXELFORMATDESCRIPTOR *pfd )
124 if (!wglDescribePixelFormat)
126 if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
127 if (!(wglDescribePixelFormat = (void *)GetProcAddress( opengl32, "wglDescribePixelFormat" )))
128 return 0;
130 return wglDescribePixelFormat( hdc, fmt, size, pfd );
133 /******************************************************************************
134 * SetPixelFormat (GDI32.@)
136 BOOL WINAPI SetPixelFormat( HDC hdc, INT fmt, const PIXELFORMATDESCRIPTOR *pfd )
138 if (!wglSetPixelFormat)
140 if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
141 if (!(wglSetPixelFormat = (void *)GetProcAddress( opengl32, "wglSetPixelFormat" )))
142 return 0;
144 return wglSetPixelFormat( hdc, fmt, pfd );
147 /******************************************************************************
148 * SwapBuffers (GDI32.@)
150 BOOL WINAPI SwapBuffers( HDC hdc )
152 if (!wglSwapBuffers)
154 if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
155 if (!(wglSwapBuffers = (void *)GetProcAddress( opengl32, "wglSwapBuffers" )))
156 return 0;
158 return wglSwapBuffers( hdc );