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 GDI_ReleaseObj( hdc
);
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 GDI_ReleaseObj(ctx
->hdc
);
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
);
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
);
182 GDI_ReleaseObj(default_hdc
);
189 /***********************************************************************
190 * wglMakeContextCurrentARB
192 static BOOL WINAPI
wglMakeContextCurrentARB(HDC hDrawDC
, HDC hReadDC
, HGLRC hglrc
)
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
);
206 GDI_ReleaseObj(hDrawDC
);
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
);
219 /***********************************************************************
220 * wglShareLists (OPENGL32.@)
222 BOOL WINAPI
wglShareLists(HGLRC hglrc1
, HGLRC hglrc2
)
226 OPENGL_Context ctx
= (OPENGL_Context
)hglrc1
;
228 TRACE("hglrc1: (%p); hglrc: (%p)\n", hglrc1
, hglrc2
);
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
);
243 /***********************************************************************
244 * wglUseFontBitmapsA (OPENGL32.@)
246 BOOL WINAPI
wglUseFontBitmapsA(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
)
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
);
262 /***********************************************************************
263 * wglUseFontBitmapsW (OPENGL32.@)
265 BOOL WINAPI
wglUseFontBitmapsW(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
)
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
);
281 /***********************************************************************
282 * Internal wglGetProcAddress for retrieving WGL extensions
284 PROC WINAPI
wglGetProcAddress(LPCSTR func
)
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
;