test version of startmenu root with big icons
[reactos.git] / reactos / lib / mesa32 / src / drivers / windows / icd / icd.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.1
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /*
26 * File name: icd.c
27 * Author: Gregor Anich
28 *
29 * ICD (Installable Client Driver) interface.
30 * Based on the windows GDI/WGL driver.
31 */
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include <windows.h>
38 #define GL_GLEXT_PROTOTYPES
39 #include "GL/gl.h"
40 #include "GL/glext.h"
41
42 #ifdef __cplusplus
43 }
44 #endif
45
46 #include <stdio.h>
47 #include <tchar.h>
48 #include "../gdi/wmesadef.h"
49 #include "GL/wmesa.h"
50 #include "mtypes.h"
51 #include "glapi.h"
52
53 #define MAX_MESA_ATTRS 20
54
55
56 typedef struct _icdTable {
57 DWORD size;
58 PROC table[336];
59 } ICDTABLE, *PICDTABLE;
60
61 #ifdef USE_MGL_NAMESPACE
62 # define GL_FUNC(func) mgl##func
63 #else
64 # define GL_FUNC(func) gl##func
65 #endif
66
67 static ICDTABLE icdTable = { 336, {
68 #define ICD_ENTRY(func) (PROC)GL_FUNC(func),
69 #include "icdlist.h"
70 #undef ICD_ENTRY
71 } };
72
73 struct __pixelformat__
74 {
75 PIXELFORMATDESCRIPTOR pfd;
76 GLboolean doubleBuffered;
77 };
78
79 struct __pixelformat__ pix[] =
80 {
81 /* Double Buffer, alpha */
82 { { sizeof(PIXELFORMATDESCRIPTOR), 1,
83 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_SWAP_COPY,
84 PFD_TYPE_RGBA,
85 24, 8, 0, 8, 8, 8, 16, 8, 24,
86 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
87 GL_TRUE
88 },
89 /* Single Buffer, alpha */
90 { { sizeof(PIXELFORMATDESCRIPTOR), 1,
91 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL, /* | PFD_SUPPORT_GDI ? */
92 PFD_TYPE_RGBA,
93 24, 8, 0, 8, 8, 8, 16, 8, 24,
94 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
95 GL_FALSE
96 },
97 /* Double Buffer, no alpha */
98 { { sizeof(PIXELFORMATDESCRIPTOR), 1,
99 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_SWAP_COPY,
100 PFD_TYPE_RGBA,
101 24, 8, 0, 8, 8, 8, 16, 0, 0,
102 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
103 GL_TRUE
104 },
105 /* Single Buffer, no alpha */
106 { { sizeof(PIXELFORMATDESCRIPTOR), 1,
107 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL, /* | PFD_SUPPORT_GDI ? */
108 PFD_TYPE_RGBA,
109 24, 8, 0, 8, 8, 8, 16, 0, 0,
110 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
111 GL_FALSE
112 },
113 };
114
115 int qt_pix = sizeof(pix) / sizeof(pix[0]);
116
117 typedef struct {
118 WMesaContext ctx;
119 HDC hdc;
120 } MesaWglCtx;
121
122 #define MESAWGL_CTX_MAX_COUNT 20
123
124 static MesaWglCtx wgl_ctx[MESAWGL_CTX_MAX_COUNT];
125
126 static unsigned ctx_count = 0;
127 static int ctx_current = -1;
128 static unsigned curPFD = 0;
129
130 WGLAPI BOOL GLAPIENTRY DrvCopyContext(HGLRC hglrcSrc,HGLRC hglrcDst,UINT mask)
131 {
132 (void) hglrcSrc; (void) hglrcDst; (void) mask;
133 return(FALSE);
134 }
135
136 WGLAPI HGLRC GLAPIENTRY DrvCreateContext(HDC hdc)
137 {
138 HWND hWnd;
139 int i = 0;
140
141 if(!(hWnd = WindowFromDC(hdc)))
142 {
143 SetLastError(0);
144 return(NULL);
145 }
146 if (!ctx_count)
147 {
148 for(i=0;i<MESAWGL_CTX_MAX_COUNT;i++)
149 {
150 wgl_ctx[i].ctx = NULL;
151 wgl_ctx[i].hdc = NULL;
152 }
153 }
154 for( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
155 {
156 if ( wgl_ctx[i].ctx == NULL )
157 {
158 wgl_ctx[i].ctx = WMesaCreateContext( hWnd, NULL, GL_TRUE,
159 pix[curPFD-1].doubleBuffered,
160 pix[curPFD-1].pfd.cAlphaBits ? GL_TRUE : GL_FALSE);
161 if (wgl_ctx[i].ctx == NULL)
162 break;
163 wgl_ctx[i].hdc = hdc;
164 ctx_count++;
165 return ((HGLRC)wgl_ctx[i].ctx);
166 }
167 }
168 SetLastError(0);
169 return(NULL);
170 }
171
172 WGLAPI BOOL GLAPIENTRY DrvDeleteContext(HGLRC hglrc)
173 {
174 int i;
175 for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
176 {
177 if ( wgl_ctx[i].ctx == (PWMC) hglrc )
178 {
179 WMesaMakeCurrent((PWMC) hglrc);
180 WMesaDestroyContext();
181 wgl_ctx[i].ctx = NULL;
182 wgl_ctx[i].hdc = NULL;
183 ctx_count--;
184 return(TRUE);
185 }
186 }
187 SetLastError(0);
188 return(FALSE);
189 }
190
191 WGLAPI HGLRC GLAPIENTRY DrvCreateLayerContext(HDC hdc,int iLayerPlane)
192 {
193 if (iLayerPlane == 0)
194 return DrvCreateContext(hdc);
195 SetLastError(0);
196 return(NULL);
197 }
198
199 WGLAPI PICDTABLE GLAPIENTRY DrvSetContext(HDC hdc,HGLRC hglrc,void *callback)
200 {
201 int i;
202 (void) callback;
203
204 /* new code suggested by Andy Sy */
205 if (!hdc || !hglrc) {
206 WMesaMakeCurrent(NULL);
207 ctx_current = -1;
208 return NULL;
209 }
210
211 for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
212 {
213 if ( wgl_ctx[i].ctx == (PWMC) hglrc )
214 {
215 wgl_ctx[i].hdc = hdc;
216 WMesaMakeCurrent( (PWMC) hglrc );
217 ctx_current = i;
218 return &icdTable;
219 }
220 }
221 return NULL;
222 }
223
224 WGLAPI void GLAPIENTRY DrvReleaseContext(HGLRC hglrc)
225 {
226 (void) hglrc;
227 WMesaMakeCurrent(NULL);
228 ctx_current = -1;
229 }
230
231 WGLAPI BOOL GLAPIENTRY DrvShareLists(HGLRC hglrc1,HGLRC hglrc2)
232 {
233 (void) hglrc1; (void) hglrc2;
234 return(TRUE);
235 }
236
237 WGLAPI BOOL GLAPIENTRY DrvDescribeLayerPlane(HDC hdc,int iPixelFormat,
238 int iLayerPlane,UINT nBytes,
239 LPLAYERPLANEDESCRIPTOR plpd)
240 {
241 (void) hdc; (void) iPixelFormat; (void) iLayerPlane; (void) nBytes; (void) plpd;
242 SetLastError(0);
243 return(FALSE);
244 }
245
246 WGLAPI int GLAPIENTRY DrvSetLayerPaletteEntries(HDC hdc,int iLayerPlane,
247 int iStart,int cEntries,
248 CONST COLORREF *pcr)
249 {
250 (void) hdc; (void) iLayerPlane; (void) iStart; (void) cEntries; (void) pcr;
251 SetLastError(0);
252 return(0);
253 }
254
255 WGLAPI int GLAPIENTRY DrvGetLayerPaletteEntries(HDC hdc,int iLayerPlane,
256 int iStart,int cEntries,
257 COLORREF *pcr)
258 {
259 (void) hdc; (void) iLayerPlane; (void) iStart; (void) cEntries; (void) pcr;
260 SetLastError(0);
261 return(0);
262 }
263
264 WGLAPI BOOL GLAPIENTRY DrvRealizeLayerPalette(HDC hdc,int iLayerPlane,BOOL bRealize)
265 {
266 (void) hdc; (void) iLayerPlane; (void) bRealize;
267 SetLastError(0);
268 return(FALSE);
269 }
270
271 WGLAPI BOOL GLAPIENTRY DrvSwapLayerBuffers(HDC hdc,UINT fuPlanes)
272 {
273 (void) fuPlanes;
274 if( !hdc )
275 {
276 WMesaSwapBuffers();
277 return(TRUE);
278 }
279 SetLastError(0);
280 return(FALSE);
281 }
282
283 WGLAPI int GLAPIENTRY DrvDescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes,
284 LPPIXELFORMATDESCRIPTOR ppfd)
285 {
286 int qt_valid_pix;
287 (void) hdc;
288
289 qt_valid_pix = qt_pix;
290 if(ppfd == NULL)
291 return(qt_valid_pix);
292 if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || nBytes != sizeof(PIXELFORMATDESCRIPTOR))
293 {
294 SetLastError(0);
295 return(0);
296 }
297 *ppfd = pix[iPixelFormat - 1].pfd;
298 return(qt_valid_pix);
299 }
300
301 /*
302 * GetProcAddress - return the address of an appropriate extension
303 */
304 WGLAPI PROC GLAPIENTRY DrvGetProcAddress(LPCSTR lpszProc)
305 {
306 PROC p = (PROC) (int) _glapi_get_proc_address((const char *) lpszProc);
307 if (p)
308 return p;
309
310 SetLastError(0);
311 return(NULL);
312 }
313
314 WGLAPI BOOL GLAPIENTRY DrvSetPixelFormat(HDC hdc,int iPixelFormat)
315 {
316 int qt_valid_pix;
317 (void) hdc;
318
319 qt_valid_pix = qt_pix;
320 if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix)
321 {
322 SetLastError(0);
323 return(FALSE);
324 }
325 curPFD = iPixelFormat;
326 return(TRUE);
327 }
328
329 WGLAPI BOOL GLAPIENTRY DrvSwapBuffers(HDC hdc)
330 {
331 (void) hdc;
332 if (ctx_current < 0)
333 return FALSE;
334
335 if(wgl_ctx[ctx_current].ctx == NULL) {
336 SetLastError(0);
337 return(FALSE);
338 }
339 WMesaSwapBuffers();
340 return(TRUE);
341 }
342
343 WGLAPI BOOL GLAPIENTRY DrvValidateVersion(DWORD version)
344 {
345 (void) version;
346 return TRUE;
347 }