msvcrt: Add a prototype for _atoldbl() & co and declare _LDOUBLE & co in stdlib.h.
[wine/wine64.git] / dlls / gdi32 / opengl.c
blob97ecaf6f6bc5eb6eff7b027253c225c2e9da0413
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 DC_ReleaseDCPtr( dc );
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 DC_ReleaseDCPtr( dc );
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 DC_ReleaseDCPtr( dc );
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 DC_ReleaseDCPtr( dc );
182 return ret;
185 /***********************************************************************
186 * wglMakeContextCurrentARB
188 static BOOL WINAPI wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc)
190 BOOL ret = FALSE;
191 DC *DrawDC;
192 DC *ReadDC;
194 TRACE("hDrawDC: (%p), hReadDC: (%p) hglrc: (%p)\n", hDrawDC, hReadDC, hglrc);
196 /* Both hDrawDC and hReadDC need to be valid */
197 DrawDC = DC_GetDCPtr( hDrawDC);
198 if (!DrawDC) return FALSE;
200 ReadDC = DC_GetDCPtr( hReadDC);
201 if (!ReadDC) {
202 DC_ReleaseDCPtr(DrawDC);
203 return FALSE;
206 if (!DrawDC->funcs->pwglMakeContextCurrentARB) FIXME(" :stub\n");
207 else ret = DrawDC->funcs->pwglMakeContextCurrentARB(DrawDC->physDev, ReadDC->physDev, hglrc);
209 DC_ReleaseDCPtr(DrawDC);
210 DC_ReleaseDCPtr(ReadDC);
212 return ret;
215 /***********************************************************************
216 * wglShareLists (OPENGL32.@)
218 BOOL WINAPI wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
220 DC *dc;
221 BOOL ret = FALSE;
222 OPENGL_Context ctx = (OPENGL_Context)hglrc1;
224 TRACE("hglrc1: (%p); hglrc: (%p)\n", hglrc1, hglrc2);
225 if(ctx == NULL)
226 return FALSE;
228 /* Retrieve the HDC associated with the context to access the display driver */
229 dc = DC_GetDCPtr(ctx->hdc);
230 if (!dc) return FALSE;
232 if (!dc->funcs->pwglShareLists) FIXME(" :stub\n");
233 else ret = dc->funcs->pwglShareLists(hglrc1, hglrc2);
235 DC_ReleaseDCPtr( dc );
236 return ret;
239 /***********************************************************************
240 * wglUseFontBitmapsA (OPENGL32.@)
242 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
244 BOOL ret = FALSE;
245 DC * dc = DC_GetDCPtr( hdc );
247 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
249 if (!dc) return FALSE;
251 if (!dc->funcs->pwglUseFontBitmapsA) FIXME(" :stub\n");
252 else ret = dc->funcs->pwglUseFontBitmapsA(dc->physDev, first, count, listBase);
254 DC_ReleaseDCPtr( dc );
255 return ret;
258 /***********************************************************************
259 * wglUseFontBitmapsW (OPENGL32.@)
261 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
263 BOOL ret = FALSE;
264 DC * dc = DC_GetDCPtr( hdc );
266 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
268 if (!dc) return FALSE;
270 if (!dc->funcs->pwglUseFontBitmapsW) FIXME(" :stub\n");
271 else ret = dc->funcs->pwglUseFontBitmapsW(dc->physDev, first, count, listBase);
273 DC_ReleaseDCPtr( dc );
274 return ret;
277 /***********************************************************************
278 * Internal wglGetProcAddress for retrieving WGL extensions
280 PROC WINAPI wglGetProcAddress(LPCSTR func)
282 PROC ret = NULL;
283 DC *dc;
285 if(!func)
286 return NULL;
288 TRACE("func: '%s'\n", func);
290 /* Retrieve the global hDC to get access to the driver. */
291 dc = OPENGL_GetDefaultDC();
292 if (!dc) return FALSE;
294 if (!dc->funcs->pwglGetProcAddress) FIXME(" :stub\n");
295 else ret = dc->funcs->pwglGetProcAddress(func);
297 DC_ReleaseDCPtr( dc );
299 /* At the moment we implement one WGL extension which requires a HDC. When we
300 * are looking up this call and when the Extension is available (that is the case
301 * when a non-NULL value is returned by wglGetProcAddress), we return the address
302 * of a wrapper function which will handle the HDC->PhysDev conversion.
304 if(ret && strcmp(func, "wglMakeContextCurrentARB") == 0)
305 return (PROC)wglMakeContextCurrentARB;
306 else if(ret && strcmp(func, "wglGetPbufferDCARB") == 0)
307 return (PROC)wglGetPbufferDCARB;
309 return ret;