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"
37 #include "gdi_private.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
42 static HDC default_hdc = 0;
44 typedef struct opengl_context
49 /* We route all wgl functions from opengl32.dll through gdi32.dll to
50 * the display driver. Various wgl calls have a hDC as one of their parameters.
51 * Using DC_GetDCPtr we get access to the functions exported by the driver.
52 * Some functions don't receive a hDC. This function creates a global hdc and
53 * if there's already a global hdc, it returns it.
55 static DC* OPENGL_GetDefaultDC()
58 default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
60 return DC_GetDCPtr(default_hdc);
63 /***********************************************************************
64 * wglCreateContext (OPENGL32.@)
66 HGLRC WINAPI wglCreateContext(HDC hdc)
69 DC * dc = DC_GetDCPtr( hdc );
75 if (!dc->funcs->pwglCreateContext) FIXME(" :stub\n");
76 else ret = dc->funcs->pwglCreateContext(dc->physDev);
78 GDI_ReleaseObj( hdc );
83 /***********************************************************************
84 * wglDeleteContext (OPENGL32.@)
86 BOOL WINAPI wglDeleteContext(HGLRC hglrc)
90 OPENGL_Context ctx = (OPENGL_Context)hglrc;
92 TRACE("hglrc: (%p)\n", hglrc);
96 /* Retrieve the HDC associated with the context to access the display driver */
97 dc = DC_GetDCPtr(ctx->hdc);
98 if (!dc) return FALSE;
100 if (!dc->funcs->pwglDeleteContext) FIXME(" :stub\n");
101 else ret = dc->funcs->pwglDeleteContext(hglrc);
103 GDI_ReleaseObj(ctx->hdc);
107 /***********************************************************************
108 * wglGetCurrentContext (OPENGL32.@)
110 HGLRC WINAPI wglGetCurrentContext(void)
112 HGLRC ret = NtCurrentTeb()->glContext;
113 TRACE(" returning %p\n", ret);
117 /***********************************************************************
118 * wglGetCurrentDC (OPENGL32.@)
120 HDC WINAPI wglGetCurrentDC(void)
122 OPENGL_Context ctx = (OPENGL_Context)wglGetCurrentContext();
124 TRACE(" found context: %p\n", ctx);
128 /* Retrieve the current DC from the active context */
129 TRACE(" returning hdc: %p\n", ctx->hdc);
133 /***********************************************************************
134 * wglMakeCurrent (OPENGL32.@)
136 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
141 /* When the context hglrc is NULL, the HDC is ignored and can be NULL.
142 * In that case use the global hDC to get access to the driver. */
144 dc = OPENGL_GetDefaultDC();
146 dc = DC_GetDCPtr( hdc );
148 TRACE("hdc: (%p), hglrc: (%p)\n", hdc, hglrc);
150 if (!dc) return FALSE;
152 if (!dc->funcs->pwglMakeCurrent) FIXME(" :stub\n");
153 else ret = dc->funcs->pwglMakeCurrent(dc->physDev,hglrc);
156 GDI_ReleaseObj(default_hdc);
163 /***********************************************************************
164 * wglShareLists (OPENGL32.@)
166 BOOL WINAPI wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
170 OPENGL_Context ctx = (OPENGL_Context)hglrc1;
172 TRACE("hglrc1: (%p); hglrc: (%p)\n", hglrc1, hglrc2);
176 /* Retrieve the HDC associated with the context to access the display driver */
177 dc = DC_GetDCPtr(ctx->hdc);
178 if (!dc) return FALSE;
180 if (!dc->funcs->pwglShareLists) FIXME(" :stub\n");
181 else ret = dc->funcs->pwglShareLists(hglrc1, hglrc2);
183 GDI_ReleaseObj(ctx->hdc);
187 /***********************************************************************
188 * wglUseFontBitmapsA (OPENGL32.@)
190 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
193 DC * dc = DC_GetDCPtr( hdc );
195 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
197 if (!dc) return FALSE;
199 if (!dc->funcs->pwglUseFontBitmapsA) FIXME(" :stub\n");
200 else ret = dc->funcs->pwglUseFontBitmapsA(dc->physDev, first, count, listBase);
202 GDI_ReleaseObj( hdc);
206 /***********************************************************************
207 * wglUseFontBitmapsW (OPENGL32.@)
209 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
212 DC * dc = DC_GetDCPtr( hdc );
214 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
216 if (!dc) return FALSE;
218 if (!dc->funcs->pwglUseFontBitmapsW) FIXME(" :stub\n");
219 else ret = dc->funcs->pwglUseFontBitmapsW(dc->physDev, first, count, listBase);
221 GDI_ReleaseObj( hdc);