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
24 #include "wine/port.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
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)
57 default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
59 return DC_GetDCPtr(default_hdc);
62 /***********************************************************************
63 * wglCreateContext (OPENGL32.@)
65 HGLRC WINAPI wglCreateContext(HDC hdc)
68 DC * dc = DC_GetDCPtr( hdc );
74 if (!dc->funcs->pwglCreateContext) FIXME(" :stub\n");
75 else ret = dc->funcs->pwglCreateContext(dc->physDev);
77 DC_ReleaseDCPtr( dc );
82 /***********************************************************************
83 * wglDeleteContext (OPENGL32.@)
85 BOOL WINAPI wglDeleteContext(HGLRC hglrc)
89 OPENGL_Context ctx = (OPENGL_Context)hglrc;
91 TRACE("hglrc: (%p)\n", hglrc);
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 );
106 /***********************************************************************
107 * wglGetCurrentContext (OPENGL32.@)
109 HGLRC WINAPI wglGetCurrentContext(void)
111 HGLRC ret = NtCurrentTeb()->glContext;
112 TRACE(" returning %p\n", ret);
116 /***********************************************************************
117 * wglGetCurrentDC (OPENGL32.@)
119 HDC WINAPI wglGetCurrentDC(void)
121 OPENGL_Context ctx = (OPENGL_Context)wglGetCurrentContext();
123 TRACE(" found context: %p\n", ctx);
127 /* Retrieve the current DC from the active context */
128 TRACE(" returning hdc: %p\n", ctx->hdc);
132 /***********************************************************************
135 static HDC WINAPI wglGetPbufferDCARB(void *pbuffer)
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 );
159 /***********************************************************************
160 * wglMakeCurrent (OPENGL32.@)
162 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
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. */
170 dc = OPENGL_GetDefaultDC();
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 );
185 /***********************************************************************
186 * wglMakeContextCurrentARB
188 static BOOL WINAPI wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc)
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);
202 DC_ReleaseDCPtr(DrawDC);
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);
215 /***********************************************************************
216 * wglShareLists (OPENGL32.@)
218 BOOL WINAPI wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
222 OPENGL_Context ctx = (OPENGL_Context)hglrc1;
224 TRACE("hglrc1: (%p); hglrc: (%p)\n", hglrc1, hglrc2);
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 );
239 /***********************************************************************
240 * wglUseFontBitmapsA (OPENGL32.@)
242 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
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 );
258 /***********************************************************************
259 * wglUseFontBitmapsW (OPENGL32.@)
261 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
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 );
277 /***********************************************************************
278 * Internal wglGetProcAddress for retrieving WGL extensions
280 PROC WINAPI wglGetProcAddress(LPCSTR func)
288 TRACE("func: '%p'\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;