wininet: Moved InternetFindNextFileW implementation to vtbl.
[wine.git] / dlls / gdi32 / opengl.c
blobf948cda04b500c707c6724cbfd2fba0a5463cc44
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 HDC default_hdc = 0;
43 typedef struct opengl_context
45 HDC hdc;
46 } *OPENGL_Context;
48 /* We route all wgl functions from opengl32.dll through gdi32.dll to
49 * the display driver. Various wgl calls have a hDC as one of their parameters.
50 * Using get_dc_ptr we get access to the functions exported by the driver.
51 * Some functions don't receive a hDC. This function creates a global hdc and
52 * if there's already a global hdc, it returns it.
54 static DC* OPENGL_GetDefaultDC(void)
56 if(!default_hdc)
57 default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
59 return get_dc_ptr(default_hdc);
62 /***********************************************************************
63 * wglCopyContext (OPENGL32.@)
65 BOOL WINAPI wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
67 DC *dc;
68 BOOL ret = FALSE;
69 OPENGL_Context ctx = (OPENGL_Context)hglrcSrc;
71 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
72 /* If no context is set, this call doesn't have a purpose */
73 if(!hglrcSrc || !hglrcDst)
74 return FALSE;
76 /* Retrieve the HDC associated with the context to access the display driver */
77 dc = get_dc_ptr(ctx->hdc);
78 if (!dc) return FALSE;
80 if (!dc->funcs->pwglCopyContext) FIXME(" :stub\n");
81 else ret = dc->funcs->pwglCopyContext(hglrcSrc, hglrcDst, mask);
83 release_dc_ptr( dc );
84 return ret;
87 /***********************************************************************
88 * wglCreateContext (OPENGL32.@)
90 HGLRC WINAPI wglCreateContext(HDC hdc)
92 HGLRC ret = 0;
93 DC * dc = get_dc_ptr( hdc );
95 TRACE("(%p)\n",hdc);
97 if (!dc) return 0;
99 update_dc( dc );
100 if (!dc->funcs->pwglCreateContext) FIXME(" :stub\n");
101 else ret = dc->funcs->pwglCreateContext(dc->physDev);
103 release_dc_ptr( dc );
104 return ret;
108 /***********************************************************************
109 * wglDeleteContext (OPENGL32.@)
111 BOOL WINAPI wglDeleteContext(HGLRC hglrc)
113 DC *dc;
114 BOOL ret = FALSE;
115 OPENGL_Context ctx = (OPENGL_Context)hglrc;
117 TRACE("hglrc: (%p)\n", hglrc);
118 if(ctx == NULL)
119 return FALSE;
121 /* Retrieve the HDC associated with the context to access the display driver */
122 dc = get_dc_ptr(ctx->hdc);
123 if (!dc) return FALSE;
125 if (!dc->funcs->pwglDeleteContext) FIXME(" :stub\n");
126 else ret = dc->funcs->pwglDeleteContext(hglrc);
128 release_dc_ptr( dc );
129 return ret;
132 /***********************************************************************
133 * wglGetCurrentContext (OPENGL32.@)
135 HGLRC WINAPI wglGetCurrentContext(void)
137 HGLRC ret = NtCurrentTeb()->glContext;
138 TRACE(" returning %p\n", ret);
139 return ret;
142 /***********************************************************************
143 * wglGetCurrentDC (OPENGL32.@)
145 HDC WINAPI wglGetCurrentDC(void)
147 OPENGL_Context ctx = (OPENGL_Context)wglGetCurrentContext();
149 TRACE(" found context: %p\n", ctx);
150 if(ctx == NULL)
151 return NULL;
153 /* Retrieve the current DC from the active context */
154 TRACE(" returning hdc: %p\n", ctx->hdc);
155 return ctx->hdc;
158 /***********************************************************************
159 * wglGetPbufferDCARB
161 static HDC WINAPI wglGetPbufferDCARB(void *pbuffer)
163 HDC ret = 0;
165 /* Create a device context to associate with the pbuffer */
166 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
167 DC *dc = get_dc_ptr(hdc);
169 TRACE("(%p)\n", pbuffer);
171 if (!dc) return FALSE;
173 /* The display driver has to do the rest of the work because
174 * we need access to lowlevel datatypes which we can't access here
176 if (!dc->funcs->pwglGetPbufferDCARB) FIXME(" :stub\n");
177 else ret = dc->funcs->pwglGetPbufferDCARB(dc->physDev, pbuffer);
179 TRACE("(%p), hdc=%p\n", pbuffer, ret);
181 release_dc_ptr( dc );
182 return ret;
185 /***********************************************************************
186 * wglMakeCurrent (OPENGL32.@)
188 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
190 BOOL ret = FALSE;
191 DC * dc = NULL;
193 /* When the context hglrc is NULL, the HDC is ignored and can be NULL.
194 * In that case use the global hDC to get access to the driver. */
195 if(hglrc == NULL)
196 dc = OPENGL_GetDefaultDC();
197 else
198 dc = get_dc_ptr( hdc );
200 TRACE("hdc: (%p), hglrc: (%p)\n", hdc, hglrc);
202 if (!dc) return FALSE;
204 update_dc( dc );
205 if (!dc->funcs->pwglMakeCurrent) FIXME(" :stub\n");
206 else ret = dc->funcs->pwglMakeCurrent(dc->physDev,hglrc);
208 release_dc_ptr( dc );
209 return ret;
212 /***********************************************************************
213 * wglMakeContextCurrentARB
215 static BOOL WINAPI wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc)
217 BOOL ret = FALSE;
218 DC *DrawDC;
219 DC *ReadDC;
221 TRACE("hDrawDC: (%p), hReadDC: (%p) hglrc: (%p)\n", hDrawDC, hReadDC, hglrc);
223 /* Both hDrawDC and hReadDC need to be valid */
224 DrawDC = get_dc_ptr( hDrawDC );
225 if (!DrawDC) return FALSE;
227 ReadDC = get_dc_ptr( hReadDC );
228 if (!ReadDC) {
229 release_dc_ptr( DrawDC );
230 return FALSE;
233 update_dc( DrawDC );
234 update_dc( ReadDC );
235 if (!DrawDC->funcs->pwglMakeContextCurrentARB) FIXME(" :stub\n");
236 else ret = DrawDC->funcs->pwglMakeContextCurrentARB(DrawDC->physDev, ReadDC->physDev, hglrc);
238 release_dc_ptr( DrawDC );
239 release_dc_ptr( ReadDC );
240 return ret;
243 /***********************************************************************
244 * wglShareLists (OPENGL32.@)
246 BOOL WINAPI wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
248 DC *dc;
249 BOOL ret = FALSE;
250 OPENGL_Context ctx = (OPENGL_Context)hglrc1;
252 TRACE("hglrc1: (%p); hglrc: (%p)\n", hglrc1, hglrc2);
253 if(ctx == NULL)
254 return FALSE;
256 /* Retrieve the HDC associated with the context to access the display driver */
257 dc = get_dc_ptr(ctx->hdc);
258 if (!dc) return FALSE;
260 if (!dc->funcs->pwglShareLists) FIXME(" :stub\n");
261 else ret = dc->funcs->pwglShareLists(hglrc1, hglrc2);
263 release_dc_ptr( dc );
264 return ret;
267 /***********************************************************************
268 * wglUseFontBitmapsA (OPENGL32.@)
270 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
272 BOOL ret = FALSE;
273 DC * dc = get_dc_ptr( hdc );
275 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
277 if (!dc) return FALSE;
279 if (!dc->funcs->pwglUseFontBitmapsA) FIXME(" :stub\n");
280 else ret = dc->funcs->pwglUseFontBitmapsA(dc->physDev, first, count, listBase);
282 release_dc_ptr( dc );
283 return ret;
286 /***********************************************************************
287 * wglUseFontBitmapsW (OPENGL32.@)
289 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
291 BOOL ret = FALSE;
292 DC * dc = get_dc_ptr( hdc );
294 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
296 if (!dc) return FALSE;
298 if (!dc->funcs->pwglUseFontBitmapsW) FIXME(" :stub\n");
299 else ret = dc->funcs->pwglUseFontBitmapsW(dc->physDev, first, count, listBase);
301 release_dc_ptr( dc );
302 return ret;
305 /***********************************************************************
306 * Internal wglGetProcAddress for retrieving WGL extensions
308 PROC WINAPI wglGetProcAddress(LPCSTR func)
310 PROC ret = NULL;
311 DC *dc;
313 if(!func)
314 return NULL;
316 TRACE("func: '%s'\n", func);
318 /* Retrieve the global hDC to get access to the driver. */
319 dc = OPENGL_GetDefaultDC();
320 if (!dc) return FALSE;
322 if (!dc->funcs->pwglGetProcAddress) FIXME(" :stub\n");
323 else ret = dc->funcs->pwglGetProcAddress(func);
325 release_dc_ptr( dc );
327 /* At the moment we implement one WGL extension which requires a HDC. When we
328 * are looking up this call and when the Extension is available (that is the case
329 * when a non-NULL value is returned by wglGetProcAddress), we return the address
330 * of a wrapper function which will handle the HDC->PhysDev conversion.
332 if(ret && strcmp(func, "wglMakeContextCurrentARB") == 0)
333 return (PROC)wglMakeContextCurrentARB;
334 else if(ret && strcmp(func, "wglGetPbufferDCARB") == 0)
335 return (PROC)wglGetPbufferDCARB;
337 return ret;