1 /*
2 * OpenGL function forwarding to the display driver
3 *
4 * Copyright (c) 1999 Lionel Ulmer
5 * Copyright (c) 2005 Raphael Junqueira
6 * Copyright (c) 2006 Roderick Colenbrander
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdlib.h>
29
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"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
40
41 static HDC default_hdc = 0;
42
43 typedef struct opengl_context
44 {
45 HDC hdc;
46 } *OPENGL_Context;
47
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.
53 */
54 static DC* OPENGL_GetDefaultDC(void)
55 {
56 if(!default_hdc)
57 default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
58
59 return get_dc_ptr(default_hdc);
60 }
61
62 /***********************************************************************
63 * wglCopyContext (OPENGL32.@)
64 */
65 BOOL WINAPI wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
66 {
67 DC *dc;
68 BOOL ret = FALSE;
69 OPENGL_Context ctx = (OPENGL_Context)hglrcSrc;
70
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;
75
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;
79
80 if (!dc->funcs->pwglCopyContext) FIXME(" :stub\n");
81 else ret = dc->funcs->pwglCopyContext(hglrcSrc, hglrcDst, mask);
82
83 release_dc_ptr( dc );
84 return ret;
85 }
86
87 /***********************************************************************
88 * wglCreateContext (OPENGL32.@)
89 */
90 HGLRC WINAPI wglCreateContext(HDC hdc)
91 {
92 HGLRC ret = 0;
93 DC * dc = get_dc_ptr( hdc );
94
95 TRACE("(%p)\n",hdc);
96
97 if (!dc) return 0;
98
99 update_dc( dc );
100 if (!dc->funcs->pwglCreateContext) FIXME(" :stub\n");
101 else ret = dc->funcs->pwglCreateContext(dc->physDev);
102
103 release_dc_ptr( dc );
104 return ret;
105 }
106
107
108 /***********************************************************************
109 * wglDeleteContext (OPENGL32.@)
110 */
111 BOOL WINAPI wglDeleteContext(HGLRC hglrc)
112 {
113 DC *dc;
114 BOOL ret = FALSE;
115 OPENGL_Context ctx = (OPENGL_Context)hglrc;
116
117 TRACE("hglrc: (%p)\n", hglrc);
118 if(ctx == NULL)
119 return FALSE;
120
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;
124
125 if (!dc->funcs->pwglDeleteContext) FIXME(" :stub\n");
126 else ret = dc->funcs->pwglDeleteContext(hglrc);
127
128 release_dc_ptr( dc );
129 return ret;
130 }
131
132 /***********************************************************************
133 * wglGetCurrentContext (OPENGL32.@)
134 */
135 HGLRC WINAPI wglGetCurrentContext(void)
136 {
137 HGLRC ret = NtCurrentTeb()->glContext;
138 TRACE(" returning %p\n", ret);
139 return ret;
140 }
141
142 /***********************************************************************
143 * wglGetCurrentDC (OPENGL32.@)
144 */
145 HDC WINAPI wglGetCurrentDC(void)
146 {
147 OPENGL_Context ctx = (OPENGL_Context)wglGetCurrentContext();
148
149 TRACE(" found context: %p\n", ctx);
150 if(ctx == NULL)
151 return NULL;
152
153 /* Retrieve the current DC from the active context */
154 TRACE(" returning hdc: %p\n", ctx->hdc);
155 return ctx->hdc;
156 }
157
158 /***********************************************************************
159 * wglGetPbufferDCARB
160 */
161 static HDC WINAPI wglGetPbufferDCARB(void *pbuffer)
162 {
163 HDC ret = 0;
164
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);
168
169 TRACE("(%p)\n", pbuffer);
170
171 if (!dc) return 0;
172
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
175 */
176 if (!dc->funcs->pwglGetPbufferDCARB) FIXME(" :stub\n");
177 else ret = dc->funcs->pwglGetPbufferDCARB(dc->physDev, pbuffer);
178
179 TRACE("(%p), hdc=%p\n", pbuffer, ret);
180
181 release_dc_ptr( dc );
182 return ret;
183 }
184
185 /***********************************************************************
186 * wglMakeCurrent (OPENGL32.@)
187 */
188 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
189 {
190 BOOL ret = FALSE;
191 DC * dc = NULL;
192
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 {
197 if( hdc == NULL && !wglGetCurrentContext() )
198 {
199 WARN( "Current context is NULL\n");
200 SetLastError( ERROR_INVALID_HANDLE );
201 return FALSE;
202 }
203 dc = OPENGL_GetDefaultDC();
204 }
205 else
206 dc = get_dc_ptr( hdc );
207
208 TRACE("hdc: (%p), hglrc: (%p)\n", hdc, hglrc);
209
210 if (!dc) return FALSE;
211
212 update_dc( dc );
213 if (!dc->funcs->pwglMakeCurrent) FIXME(" :stub\n");
214 else ret = dc->funcs->pwglMakeCurrent(dc->physDev,hglrc);
215
216 release_dc_ptr( dc );
217 return ret;
218 }
219
220 /***********************************************************************
221 * wglMakeContextCurrentARB
222 */
223 static BOOL WINAPI wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc)
224 {
225 BOOL ret = FALSE;
226 DC *DrawDC;
227 DC *ReadDC;
228
229 TRACE("hDrawDC: (%p), hReadDC: (%p) hglrc: (%p)\n", hDrawDC, hReadDC, hglrc);
230
231 /* Both hDrawDC and hReadDC need to be valid */
232 DrawDC = get_dc_ptr( hDrawDC );
233 if (!DrawDC) return FALSE;
234
235 ReadDC = get_dc_ptr( hReadDC );
236 if (!ReadDC) {
237 release_dc_ptr( DrawDC );
238 return FALSE;
239 }
240
241 update_dc( DrawDC );
242 update_dc( ReadDC );
243 if (!DrawDC->funcs->pwglMakeContextCurrentARB) FIXME(" :stub\n");
244 else ret = DrawDC->funcs->pwglMakeContextCurrentARB(DrawDC->physDev, ReadDC->physDev, hglrc);
245
246 release_dc_ptr( DrawDC );
247 release_dc_ptr( ReadDC );
248 return ret;
249 }
250
251 /**************************************************************************************
252 * WINE-specific wglSetPixelFormat which can set the iPixelFormat multiple times
253 *
254 */
255 static BOOL WINAPI wglSetPixelFormatWINE(HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
256 {
257 INT bRet = FALSE;
258 DC * dc = get_dc_ptr( hdc );
259
260 TRACE("(%p,%d,%p)\n", hdc, iPixelFormat, ppfd);
261
262 if (!dc) return 0;
263
264 update_dc( dc );
265 if (!dc->funcs->pwglSetPixelFormatWINE) FIXME(" :stub\n");
266 else bRet = dc->funcs->pwglSetPixelFormatWINE(dc->physDev, iPixelFormat, ppfd);
267
268 release_dc_ptr( dc );
269 return bRet;
270 }
271
272 /***********************************************************************
273 * wglShareLists (OPENGL32.@)
274 */
275 BOOL WINAPI wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
276 {
277 DC *dc;
278 BOOL ret = FALSE;
279 OPENGL_Context ctx = (OPENGL_Context)hglrc1;
280
281 TRACE("hglrc1: (%p); hglrc: (%p)\n", hglrc1, hglrc2);
282 if(ctx == NULL)
283 return FALSE;
284
285 /* Retrieve the HDC associated with the context to access the display driver */
286 dc = get_dc_ptr(ctx->hdc);
287 if (!dc) return FALSE;
288
289 if (!dc->funcs->pwglShareLists) FIXME(" :stub\n");
290 else ret = dc->funcs->pwglShareLists(hglrc1, hglrc2);
291
292 release_dc_ptr( dc );
293 return ret;
294 }
295
296 /***********************************************************************
297 * wglUseFontBitmapsA (OPENGL32.@)
298 */
299 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
300 {
301 BOOL ret = FALSE;
302 DC * dc = get_dc_ptr( hdc );
303
304 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
305
306 if (!dc) return FALSE;
307
308 if (!dc->funcs->pwglUseFontBitmapsA) FIXME(" :stub\n");
309 else ret = dc->funcs->pwglUseFontBitmapsA(dc->physDev, first, count, listBase);
310
311 release_dc_ptr( dc );
312 return ret;
313 }
314
315 /***********************************************************************
316 * wglUseFontBitmapsW (OPENGL32.@)
317 */
318 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
319 {
320 BOOL ret = FALSE;
321 DC * dc = get_dc_ptr( hdc );
322
323 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
324
325 if (!dc) return FALSE;
326
327 if (!dc->funcs->pwglUseFontBitmapsW) FIXME(" :stub\n");
328 else ret = dc->funcs->pwglUseFontBitmapsW(dc->physDev, first, count, listBase);
329
330 release_dc_ptr( dc );
331 return ret;
332 }
333
334 /***********************************************************************
335 * Internal wglGetProcAddress for retrieving WGL extensions
336 */
337 PROC WINAPI wglGetProcAddress(LPCSTR func)
338 {
339 PROC ret = NULL;
340 DC *dc;
341
342 if(!func)
343 return NULL;
344
345 TRACE("func: '%s'\n", func);
346
347 /* Retrieve the global hDC to get access to the driver. */
348 dc = OPENGL_GetDefaultDC();
349 if (!dc) return NULL;
350
351 if (!dc->funcs->pwglGetProcAddress) FIXME(" :stub\n");
352 else ret = dc->funcs->pwglGetProcAddress(func);
353
354 release_dc_ptr( dc );
355
356 /* At the moment we implement one WGL extension which requires a HDC. When we
357 * are looking up this call and when the Extension is available (that is the case
358 * when a non-NULL value is returned by wglGetProcAddress), we return the address
359 * of a wrapper function which will handle the HDC->PhysDev conversion.
360 */
361 if(ret && strcmp(func, "wglMakeContextCurrentARB") == 0)
362 return (PROC)wglMakeContextCurrentARB;
363 else if(ret && strcmp(func, "wglGetPbufferDCARB") == 0)
364 return (PROC)wglGetPbufferDCARB;
365 else if(ret && strcmp(func, "wglSetPixelFormatWINE") == 0)
366 return (PROC)wglSetPixelFormatWINE;
367
368 return ret;
369 }
370
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.