oleaut32: Constify some variables.
[wine/hacks.git] / dlls / gdi32 / opengl.c
blobfddbeef0209bda81fdd78cc4beb6c769c1ac3555
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 DC_GetDCPtr 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 DC_GetDCPtr(default_hdc);
62 /***********************************************************************
63 * wglCreateContext (OPENGL32.@)
65 HGLRC WINAPI wglCreateContext(HDC hdc)
67 HGLRC ret = 0;
68 DC * dc = DC_GetDCPtr( hdc );
70 TRACE("(%p)\n",hdc);
72 if (!dc) return 0;
74 if (!dc->funcs->pwglCreateContext) FIXME(" :stub\n");
75 else ret = dc->funcs->pwglCreateContext(dc->physDev);
77 GDI_ReleaseObj( hdc );
78 return ret;
82 /***********************************************************************
83 * wglDeleteContext (OPENGL32.@)
85 BOOL WINAPI wglDeleteContext(HGLRC hglrc)
87 DC *dc;
88 BOOL ret = FALSE;
89 OPENGL_Context ctx = (OPENGL_Context)hglrc;
91 TRACE("hglrc: (%p)\n", hglrc);
92 if(ctx == NULL)
93 return FALSE;
95 /* Retrieve the HDC associated with the context to access the display driver */
96 dc = DC_GetDCPtr(ctx->hdc);
97 if (!dc) return FALSE;
99 if (!dc->funcs->pwglDeleteContext) FIXME(" :stub\n");
100 else ret = dc->funcs->pwglDeleteContext(hglrc);
102 GDI_ReleaseObj(ctx->hdc);
103 return ret;
106 /***********************************************************************
107 * wglGetCurrentContext (OPENGL32.@)
109 HGLRC WINAPI wglGetCurrentContext(void)
111 HGLRC ret = NtCurrentTeb()->glContext;
112 TRACE(" returning %p\n", ret);
113 return ret;
116 /***********************************************************************
117 * wglGetCurrentDC (OPENGL32.@)
119 HDC WINAPI wglGetCurrentDC(void)
121 OPENGL_Context ctx = (OPENGL_Context)wglGetCurrentContext();
123 TRACE(" found context: %p\n", ctx);
124 if(ctx == NULL)
125 return NULL;
127 /* Retrieve the current DC from the active context */
128 TRACE(" returning hdc: %p\n", ctx->hdc);
129 return ctx->hdc;
132 /***********************************************************************
133 * wglGetPbufferDCARB
135 static HDC WINAPI wglGetPbufferDCARB(void *pbuffer)
137 HDC ret = 0;
139 /* Create a device context to associate with the pbuffer */
140 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
141 DC *dc = DC_GetDCPtr(hdc);
143 TRACE("(%p)\n", pbuffer);
145 if (!dc) return FALSE;
147 /* The display driver has to do the rest of the work because
148 * we need access to lowlevel datatypes which we can't access here
150 if (!dc->funcs->pwglGetPbufferDCARB) FIXME(" :stub\n");
151 else ret = dc->funcs->pwglGetPbufferDCARB(dc->physDev, pbuffer);
153 TRACE("(%p), hdc=%p\n", pbuffer, ret);
155 GDI_ReleaseObj(hdc);
156 return ret;
159 /***********************************************************************
160 * wglMakeCurrent (OPENGL32.@)
162 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
164 BOOL ret = FALSE;
165 DC * dc = NULL;
167 /* When the context hglrc is NULL, the HDC is ignored and can be NULL.
168 * In that case use the global hDC to get access to the driver. */
169 if(hglrc == NULL)
170 dc = OPENGL_GetDefaultDC();
171 else
172 dc = DC_GetDCUpdate( hdc );
174 TRACE("hdc: (%p), hglrc: (%p)\n", hdc, hglrc);
176 if (!dc) return FALSE;
178 if (!dc->funcs->pwglMakeCurrent) FIXME(" :stub\n");
179 else ret = dc->funcs->pwglMakeCurrent(dc->physDev,hglrc);
181 if(hglrc == NULL)
182 GDI_ReleaseObj(default_hdc);
183 else
184 GDI_ReleaseObj(hdc);
186 return ret;
189 /***********************************************************************
190 * wglMakeContextCurrentARB
192 static BOOL WINAPI wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc)
194 BOOL ret = FALSE;
195 DC *DrawDC;
196 DC *ReadDC;
198 TRACE("hDrawDC: (%p), hReadDC: (%p) hglrc: (%p)\n", hDrawDC, hReadDC, hglrc);
200 /* Both hDrawDC and hReadDC need to be valid */
201 DrawDC = DC_GetDCPtr( hDrawDC);
202 if (!DrawDC) return FALSE;
204 ReadDC = DC_GetDCPtr( hReadDC);
205 if (!ReadDC) {
206 GDI_ReleaseObj(hDrawDC);
207 return FALSE;
210 if (!DrawDC->funcs->pwglMakeContextCurrentARB) FIXME(" :stub\n");
211 else ret = DrawDC->funcs->pwglMakeContextCurrentARB(DrawDC->physDev, ReadDC->physDev, hglrc);
213 GDI_ReleaseObj(hDrawDC);
214 GDI_ReleaseObj(hReadDC);
216 return ret;
219 /***********************************************************************
220 * wglShareLists (OPENGL32.@)
222 BOOL WINAPI wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
224 DC *dc;
225 BOOL ret = FALSE;
226 OPENGL_Context ctx = (OPENGL_Context)hglrc1;
228 TRACE("hglrc1: (%p); hglrc: (%p)\n", hglrc1, hglrc2);
229 if(ctx == NULL)
230 return FALSE;
232 /* Retrieve the HDC associated with the context to access the display driver */
233 dc = DC_GetDCPtr(ctx->hdc);
234 if (!dc) return FALSE;
236 if (!dc->funcs->pwglShareLists) FIXME(" :stub\n");
237 else ret = dc->funcs->pwglShareLists(hglrc1, hglrc2);
239 GDI_ReleaseObj(ctx->hdc);
240 return ret;
243 /***********************************************************************
244 * wglUseFontBitmapsA (OPENGL32.@)
246 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
248 BOOL ret = FALSE;
249 DC * dc = DC_GetDCPtr( hdc );
251 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
253 if (!dc) return FALSE;
255 if (!dc->funcs->pwglUseFontBitmapsA) FIXME(" :stub\n");
256 else ret = dc->funcs->pwglUseFontBitmapsA(dc->physDev, first, count, listBase);
258 GDI_ReleaseObj( hdc);
259 return ret;
262 /***********************************************************************
263 * wglUseFontBitmapsW (OPENGL32.@)
265 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
267 BOOL ret = FALSE;
268 DC * dc = DC_GetDCPtr( hdc );
270 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
272 if (!dc) return FALSE;
274 if (!dc->funcs->pwglUseFontBitmapsW) FIXME(" :stub\n");
275 else ret = dc->funcs->pwglUseFontBitmapsW(dc->physDev, first, count, listBase);
277 GDI_ReleaseObj( hdc);
278 return ret;
281 /***********************************************************************
282 * Internal wglGetProcAddress for retrieving WGL extensions
284 PROC WINAPI wglGetProcAddress(LPCSTR func)
286 PROC ret = NULL;
287 DC *dc;
289 if(!func)
290 return NULL;
292 TRACE("func: '%p'\n", func);
294 /* Retrieve the global hDC to get access to the driver. */
295 dc = OPENGL_GetDefaultDC();
296 if (!dc) return FALSE;
298 if (!dc->funcs->pwglGetProcAddress) FIXME(" :stub\n");
299 else ret = dc->funcs->pwglGetProcAddress(func);
301 GDI_ReleaseObj(default_hdc);
303 /* At the moment we implement one WGL extension which requires a HDC. When we
304 * are looking up this call and when the Extension is available (that is the case
305 * when a non-NULL value is returned by wglGetProcAddress), we return the address
306 * of a wrapper function which will handle the HDC->PhysDev conversion.
308 if(ret && strcmp(func, "wglMakeContextCurrentARB") == 0)
309 return (PROC)wglMakeContextCurrentARB;
310 else if(ret && strcmp(func, "wglGetPbufferDCARB") == 0)
311 return (PROC)wglGetPbufferDCARB;
313 return ret;