wgl: Move wglGetCurrentDC to gdi32.
[wine/dibdrv.git] / dlls / gdi / opengl.c
blob95e09c6a5f38a6e66687754682a1af7b993df564
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.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
46 HDC hdc;
47 } *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()
57 if(!default_hdc)
58 default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
60 return DC_GetDCPtr(default_hdc);
63 /***********************************************************************
64 * wglCreateContext (OPENGL32.@)
66 HGLRC WINAPI wglCreateContext(HDC hdc)
68 HGLRC ret = 0;
69 DC * dc = DC_GetDCPtr( hdc );
71 TRACE("(%p)\n",hdc);
73 if (!dc) return 0;
75 if (!dc->funcs->pwglCreateContext) FIXME(" :stub\n");
76 else ret = dc->funcs->pwglCreateContext(dc->physDev);
78 GDI_ReleaseObj( hdc );
79 return ret;
82 /***********************************************************************
83 * wglGetCurrentContext (OPENGL32.@)
85 HGLRC WINAPI wglGetCurrentContext(void)
87 HGLRC ret = NtCurrentTeb()->glContext;
88 TRACE(" returning %p\n", ret);
89 return ret;
92 /***********************************************************************
93 * wglGetCurrentDC (OPENGL32.@)
95 HDC WINAPI wglGetCurrentDC(void)
97 OPENGL_Context ctx = (OPENGL_Context)wglGetCurrentContext();
99 TRACE(" found context: %p\n", ctx);
100 if(ctx == NULL)
101 return NULL;
103 /* Retrieve the current DC from the active context */
104 TRACE(" returning hdc: %p\n", ctx->hdc);
105 return ctx->hdc;
108 /***********************************************************************
109 * wglMakeCurrent (OPENGL32.@)
111 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
113 BOOL ret = FALSE;
114 DC * dc = NULL;
116 /* When the context hglrc is NULL, the HDC is ignored and can be NULL.
117 * In that case use the global hDC to get access to the driver. */
118 if(hglrc == NULL)
119 dc = OPENGL_GetDefaultDC();
120 else
121 dc = DC_GetDCPtr( hdc );
123 TRACE("hdc: (%p), hglrc: (%p)\n", hdc, hglrc);
125 if (!dc) return FALSE;
127 if (!dc->funcs->pwglMakeCurrent) FIXME(" :stub\n");
128 else ret = dc->funcs->pwglMakeCurrent(dc->physDev,hglrc);
130 if(hglrc == NULL)
131 GDI_ReleaseObj(default_hdc);
132 else
133 GDI_ReleaseObj(hdc);
135 return ret;
138 /***********************************************************************
139 * wglUseFontBitmapsA (OPENGL32.@)
141 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
143 BOOL ret = FALSE;
144 DC * dc = DC_GetDCPtr( hdc );
146 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
148 if (!dc) return FALSE;
150 if (!dc->funcs->pwglUseFontBitmapsA) FIXME(" :stub\n");
151 else ret = dc->funcs->pwglUseFontBitmapsA(dc->physDev, first, count, listBase);
153 GDI_ReleaseObj( hdc);
154 return ret;
157 /***********************************************************************
158 * wglUseFontBitmapsW (OPENGL32.@)
160 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
162 BOOL ret = FALSE;
163 DC * dc = DC_GetDCPtr( hdc );
165 TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
167 if (!dc) return FALSE;
169 if (!dc->funcs->pwglUseFontBitmapsW) FIXME(" :stub\n");
170 else ret = dc->funcs->pwglUseFontBitmapsW(dc->physDev, first, count, listBase);
172 GDI_ReleaseObj( hdc);
173 return ret;