stw_wgl.c revision c7fc4067ebd4758dd7566b20169a428dc8926c8d
1/**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28#include <windows.h>
29
30#include "util/u_debug.h"
31#include "stw_icd.h"
32#include "stw_context.h"
33#include "stw_pixelformat.h"
34#include "stw_wgl.h"
35
36
37WINGDIAPI BOOL APIENTRY
38wglCopyContext(
39   HGLRC hglrcSrc,
40   HGLRC hglrcDst,
41   UINT mask )
42{
43   return DrvCopyContext( (DHGLRC)(UINT_PTR)hglrcSrc,
44                          (DHGLRC)(UINT_PTR)hglrcDst,
45                          mask );
46}
47
48WINGDIAPI HGLRC APIENTRY
49wglCreateContext(
50   HDC hdc )
51{
52   return (HGLRC) DrvCreateContext(hdc);
53}
54
55WINGDIAPI HGLRC APIENTRY
56wglCreateLayerContext(
57   HDC hdc,
58   int iLayerPlane )
59{
60   return (HGLRC) DrvCreateLayerContext( hdc, iLayerPlane );
61}
62
63WINGDIAPI BOOL APIENTRY
64wglDeleteContext(
65   HGLRC hglrc )
66{
67   return DrvDeleteContext((DHGLRC)(UINT_PTR)hglrc );
68}
69
70
71WINGDIAPI HGLRC APIENTRY
72wglGetCurrentContext( VOID )
73{
74   return (HGLRC)(UINT_PTR)stw_get_current_context();
75}
76
77WINGDIAPI HDC APIENTRY
78wglGetCurrentDC( VOID )
79{
80   return stw_get_current_dc();
81}
82
83WINGDIAPI BOOL APIENTRY
84wglMakeCurrent(
85   HDC hdc,
86   HGLRC hglrc )
87{
88   return DrvSetContext( hdc, (DHGLRC)(UINT_PTR)hglrc, NULL ) ? TRUE : FALSE;
89}
90
91
92WINGDIAPI BOOL APIENTRY
93wglSwapBuffers(
94   HDC hdc )
95{
96   return DrvSwapBuffers( hdc );
97}
98
99
100WINGDIAPI DWORD WINAPI
101wglSwapMultipleBuffers(UINT n,
102                       CONST WGLSWAP *ps)
103{
104   UINT i;
105
106   for (i =0; i < n; ++i)
107      wglSwapBuffers(ps->hdc);
108
109   return 0;
110}
111
112
113WINGDIAPI BOOL APIENTRY
114wglSwapLayerBuffers(
115   HDC hdc,
116   UINT fuPlanes )
117{
118   return DrvSwapLayerBuffers( hdc, fuPlanes );
119}
120
121WINGDIAPI PROC APIENTRY
122wglGetProcAddress(
123    LPCSTR lpszProc )
124{
125   return DrvGetProcAddress( lpszProc );
126}
127
128
129WINGDIAPI int APIENTRY
130wglChoosePixelFormat(
131   HDC hdc,
132   CONST PIXELFORMATDESCRIPTOR *ppfd )
133{
134   if (ppfd->nSize != sizeof( PIXELFORMATDESCRIPTOR ) || ppfd->nVersion != 1)
135      return 0;
136   if (ppfd->iPixelType != PFD_TYPE_RGBA)
137      return 0;
138   if (!(ppfd->dwFlags & PFD_DRAW_TO_WINDOW))
139      return 0;
140   if (!(ppfd->dwFlags & PFD_SUPPORT_OPENGL))
141      return 0;
142   if (ppfd->dwFlags & PFD_DRAW_TO_BITMAP)
143      return 0;
144   if (ppfd->dwFlags & PFD_SUPPORT_GDI)
145      return 0;
146   if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO))
147      return 0;
148
149   return stw_pixelformat_choose( hdc, ppfd );
150}
151
152WINGDIAPI int APIENTRY
153wglDescribePixelFormat(
154   HDC hdc,
155   int iPixelFormat,
156   UINT nBytes,
157   LPPIXELFORMATDESCRIPTOR ppfd )
158{
159   return DrvDescribePixelFormat( hdc, iPixelFormat, nBytes, ppfd );
160}
161
162WINGDIAPI int APIENTRY
163wglGetPixelFormat(
164   HDC hdc )
165{
166   return stw_pixelformat_get( hdc );
167}
168
169WINGDIAPI BOOL APIENTRY
170wglSetPixelFormat(
171   HDC hdc,
172   int iPixelFormat,
173   const PIXELFORMATDESCRIPTOR *ppfd )
174{
175    /* SetPixelFormat (hence wglSetPixelFormat) must not touch ppfd, per
176     * http://msdn.microsoft.com/en-us/library/dd369049(v=vs.85).aspx
177     */
178   (void) ppfd;
179
180   return DrvSetPixelFormat( hdc, iPixelFormat );
181}
182
183
184WINGDIAPI BOOL APIENTRY
185wglUseFontBitmapsA(
186   HDC hdc,
187   DWORD first,
188   DWORD count,
189   DWORD listBase )
190{
191   (void) hdc;
192   (void) first;
193   (void) count;
194   (void) listBase;
195
196   assert( 0 );
197
198   return FALSE;
199}
200
201WINGDIAPI BOOL APIENTRY
202wglShareLists(
203   HGLRC hglrc1,
204   HGLRC hglrc2 )
205{
206   return DrvShareLists((DHGLRC)(UINT_PTR)hglrc1,
207                        (DHGLRC)(UINT_PTR)hglrc2);
208}
209
210WINGDIAPI BOOL APIENTRY
211wglUseFontBitmapsW(
212   HDC hdc,
213   DWORD first,
214   DWORD count,
215   DWORD listBase )
216{
217   (void) hdc;
218   (void) first;
219   (void) count;
220   (void) listBase;
221
222   assert( 0 );
223
224   return FALSE;
225}
226
227WINGDIAPI BOOL APIENTRY
228wglUseFontOutlinesA(
229   HDC hdc,
230   DWORD first,
231   DWORD count,
232   DWORD listBase,
233   FLOAT deviation,
234   FLOAT extrusion,
235   int format,
236   LPGLYPHMETRICSFLOAT lpgmf )
237{
238   (void) hdc;
239   (void) first;
240   (void) count;
241   (void) listBase;
242   (void) deviation;
243   (void) extrusion;
244   (void) format;
245   (void) lpgmf;
246
247   assert( 0 );
248
249   return FALSE;
250}
251
252WINGDIAPI BOOL APIENTRY
253wglUseFontOutlinesW(
254   HDC hdc,
255   DWORD first,
256   DWORD count,
257   DWORD listBase,
258   FLOAT deviation,
259   FLOAT extrusion,
260   int format,
261   LPGLYPHMETRICSFLOAT lpgmf )
262{
263   (void) hdc;
264   (void) first;
265   (void) count;
266   (void) listBase;
267   (void) deviation;
268   (void) extrusion;
269   (void) format;
270   (void) lpgmf;
271
272   assert( 0 );
273
274   return FALSE;
275}
276
277WINGDIAPI BOOL APIENTRY
278wglDescribeLayerPlane(
279   HDC hdc,
280   int iPixelFormat,
281   int iLayerPlane,
282   UINT nBytes,
283   LPLAYERPLANEDESCRIPTOR plpd )
284{
285   return DrvDescribeLayerPlane(hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
286}
287
288WINGDIAPI int APIENTRY
289wglSetLayerPaletteEntries(
290   HDC hdc,
291   int iLayerPlane,
292   int iStart,
293   int cEntries,
294   CONST COLORREF *pcr )
295{
296   return DrvSetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
297}
298
299WINGDIAPI int APIENTRY
300wglGetLayerPaletteEntries(
301   HDC hdc,
302   int iLayerPlane,
303   int iStart,
304   int cEntries,
305   COLORREF *pcr )
306{
307   return DrvGetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
308}
309
310WINGDIAPI BOOL APIENTRY
311wglRealizeLayerPalette(
312   HDC hdc,
313   int iLayerPlane,
314   BOOL bRealize )
315{
316   (void) hdc;
317   (void) iLayerPlane;
318   (void) bRealize;
319
320   assert( 0 );
321
322   return FALSE;
323}
324