adding stub for wglChoosePixelFormatARB, wglSwapIntervalEXT, wglGetSwapIntervalEXT
[reactos.git] / reactos / dll / 3rdparty / 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 "GL/wmesa.h"
49 #include "mtypes.h"
50 #include "glapi.h"
51
52 GLAPI const char * GLAPIENTRY wglGetExtensionsStringEXT (void);
53 GLAPI BOOL GLAPIENTRY wglChoosePixelFormatARB (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
54 GLAPI BOOL GLAPIENTRY wglSwapIntervalEXT (int interval);
55 GLAPI int GLAPIENTRY wglGetSwapIntervalEXT (void);
56
57 #define MAX_MESA_ATTRS 20
58
59 typedef struct wmesa_context *PWMC;
60
61 typedef struct _icdTable {
62 DWORD size;
63 PROC table[418];
64 } ICDTABLE, *PICDTABLE;
65
66 #ifdef USE_MGL_NAMESPACE
67 # define GL_FUNC(func) mgl##func
68 #else
69 # define GL_FUNC(func) gl##func
70 #endif
71
72
73 static ICDTABLE icdTable = { 418, {
74 #define ICD_ENTRY(func) (PROC)GL_FUNC(func),
75 #include "icdlist.h"
76 #undef ICD_ENTRY
77 } };
78
79 struct __pixelformat__
80 {
81 PIXELFORMATDESCRIPTOR pfd;
82 GLboolean doubleBuffered;
83 };
84
85 struct __pixelformat__ pix[] =
86 {
87 /* Double Buffer, alpha */
88 { { sizeof(PIXELFORMATDESCRIPTOR), 1,
89 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_SWAP_COPY,
90 PFD_TYPE_RGBA,
91 24, 8, 0, 8, 8, 8, 16, 8, 24,
92 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
93 GL_TRUE
94 },
95 /* Single Buffer, alpha */
96 { { sizeof(PIXELFORMATDESCRIPTOR), 1,
97 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL, /* | PFD_SUPPORT_GDI ? */
98 PFD_TYPE_RGBA,
99 24, 8, 0, 8, 8, 8, 16, 8, 24,
100 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
101 GL_FALSE
102 },
103 /* Double Buffer, no alpha */
104 { { sizeof(PIXELFORMATDESCRIPTOR), 1,
105 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_SWAP_COPY,
106 PFD_TYPE_RGBA,
107 24, 8, 0, 8, 8, 8, 16, 0, 0,
108 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
109 GL_TRUE
110 },
111 /* Single Buffer, no alpha */
112 { { sizeof(PIXELFORMATDESCRIPTOR), 1,
113 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL, /* | PFD_SUPPORT_GDI ? */
114 PFD_TYPE_RGBA,
115 24, 8, 0, 8, 8, 8, 16, 0, 0,
116 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
117 GL_FALSE
118 },
119 };
120
121 int qt_pix = sizeof(pix) / sizeof(pix[0]);
122
123 typedef struct {
124 WMesaContext ctx;
125 HDC hdc;
126 } MesaWglCtx;
127
128 #define MESAWGL_CTX_MAX_COUNT 20
129
130 static MesaWglCtx wgl_ctx[MESAWGL_CTX_MAX_COUNT];
131
132 static unsigned ctx_count = 0;
133 static int ctx_current = -1;
134 static unsigned curPFD = 0;
135
136 WGLAPI BOOL GLAPIENTRY DrvCopyContext(HGLRC hglrcSrc,HGLRC hglrcDst,UINT mask)
137 {
138 (void) hglrcSrc; (void) hglrcDst; (void) mask;
139 return(FALSE);
140 }
141
142 WGLAPI HGLRC GLAPIENTRY DrvCreateContext(HDC hdc)
143 {
144 HWND hWnd;
145 int i = 0;
146
147 if(!(hWnd = WindowFromDC(hdc)))
148 {
149 SetLastError(0);
150 return(NULL);
151 }
152 if (!ctx_count)
153 {
154 for(i=0;i<MESAWGL_CTX_MAX_COUNT;i++)
155 {
156 wgl_ctx[i].ctx = NULL;
157 wgl_ctx[i].hdc = NULL;
158 }
159 }
160 for( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
161 {
162 if ( wgl_ctx[i].ctx == NULL )
163 {
164 wgl_ctx[i].ctx = WMesaCreateContext( hdc, NULL, GL_TRUE,
165 pix[curPFD-1].doubleBuffered,
166 pix[curPFD-1].pfd.cAlphaBits ? GL_TRUE : GL_FALSE);
167 if (wgl_ctx[i].ctx == NULL)
168 break;
169 wgl_ctx[i].hdc = hdc;
170 ctx_count++;
171 return ((HGLRC)wgl_ctx[i].ctx);
172 }
173 }
174 SetLastError(0);
175 return(NULL);
176 }
177
178 WGLAPI BOOL GLAPIENTRY DrvDeleteContext(HGLRC hglrc)
179 {
180 int i;
181 for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
182 {
183 if ( wgl_ctx[i].ctx == (PWMC) hglrc )
184 {
185 WMesaMakeCurrent((PWMC) hglrc, NULL);
186 WMesaDestroyContext(wgl_ctx[i].ctx);
187 wgl_ctx[i].ctx = NULL;
188 wgl_ctx[i].hdc = NULL;
189 ctx_count--;
190 return(TRUE);
191 }
192 }
193 SetLastError(0);
194 return(FALSE);
195 }
196
197 WGLAPI HGLRC GLAPIENTRY DrvCreateLayerContext(HDC hdc,int iLayerPlane)
198 {
199 if (iLayerPlane == 0)
200 return DrvCreateContext(hdc);
201 SetLastError(0);
202 return(NULL);
203 }
204
205 WGLAPI PICDTABLE GLAPIENTRY DrvSetContext(HDC hdc,HGLRC hglrc,void *callback)
206 {
207 int i;
208 (void) callback;
209
210 /* new code suggested by Andy Sy */
211 if (!hdc || !hglrc) {
212 WMesaMakeCurrent(NULL, NULL);
213 ctx_current = -1;
214 return NULL;
215 }
216
217 for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
218 {
219 if ( wgl_ctx[i].ctx == (PWMC) hglrc )
220 {
221 wgl_ctx[i].hdc = hdc;
222 WMesaMakeCurrent( (PWMC) hglrc , hdc);
223 ctx_current = i;
224 return &icdTable;
225 }
226 }
227 return NULL;
228 }
229
230 WGLAPI void GLAPIENTRY DrvReleaseContext(HGLRC hglrc)
231 {
232 (void) hglrc;
233 WMesaMakeCurrent(NULL, NULL);
234 ctx_current = -1;
235 }
236
237 WGLAPI BOOL GLAPIENTRY DrvShareLists(HGLRC hglrc1,HGLRC hglrc2)
238 {
239 (void) hglrc1; (void) hglrc2;
240 return(TRUE);
241 }
242
243 WGLAPI BOOL GLAPIENTRY DrvDescribeLayerPlane(HDC hdc,int iPixelFormat,
244 int iLayerPlane,UINT nBytes,
245 LPLAYERPLANEDESCRIPTOR plpd)
246 {
247 (void) hdc; (void) iPixelFormat; (void) iLayerPlane; (void) nBytes; (void) plpd;
248 SetLastError(0);
249 return(FALSE);
250 }
251
252 WGLAPI int GLAPIENTRY DrvSetLayerPaletteEntries(HDC hdc,int iLayerPlane,
253 int iStart,int cEntries,
254 CONST COLORREF *pcr)
255 {
256 (void) hdc; (void) iLayerPlane; (void) iStart; (void) cEntries; (void) pcr;
257 SetLastError(0);
258 return(0);
259 }
260
261 WGLAPI int GLAPIENTRY DrvGetLayerPaletteEntries(HDC hdc,int iLayerPlane,
262 int iStart,int cEntries,
263 COLORREF *pcr)
264 {
265 (void) hdc; (void) iLayerPlane; (void) iStart; (void) cEntries; (void) pcr;
266 SetLastError(0);
267 return(0);
268 }
269
270 WGLAPI BOOL GLAPIENTRY DrvRealizeLayerPalette(HDC hdc,int iLayerPlane,BOOL bRealize)
271 {
272 (void) hdc; (void) iLayerPlane; (void) bRealize;
273 SetLastError(0);
274 return(FALSE);
275 }
276
277 WGLAPI BOOL GLAPIENTRY DrvSwapLayerBuffers(HDC hdc,UINT fuPlanes)
278 {
279 (void) fuPlanes;
280 if( !hdc )
281 {
282 WMesaSwapBuffers(hdc);
283 return(TRUE);
284 }
285 SetLastError(0);
286 return(FALSE);
287 }
288
289 WGLAPI int GLAPIENTRY DrvDescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes,
290 LPPIXELFORMATDESCRIPTOR ppfd)
291 {
292 int qt_valid_pix;
293 (void) hdc;
294
295 qt_valid_pix = qt_pix;
296 if( (nBytes != sizeof(PIXELFORMATDESCRIPTOR)) || (iPixelFormat < 1) || (iPixelFormat >qt_valid_pix) )
297 {
298 SetLastError(0);
299 return(0);
300 }
301
302 if(ppfd==NULL)
303 {
304 return(qt_valid_pix);
305 }
306
307 *ppfd = pix[iPixelFormat - 1].pfd;
308 return(qt_valid_pix);
309 }
310
311 /*
312 * GetProcAddress - return the address of an appropriate extension
313 */
314
315 static struct {
316 const char *name;
317 PROC func;
318 } wgl_ext[] = {
319 {"wglGetExtensionsStringARB", (PROC)wglGetExtensionsStringARB},
320 {"wglGetExtensionsStringEXT", (PROC)wglGetExtensionsStringEXT},
321 {"wglSwapIntervalEXT", (PROC)wglSwapIntervalEXT},
322 {"wglGetSwapIntervalEXT", (PROC)wglGetSwapIntervalEXT},
323 // {"wglGetPixelFormatAttribivARB", (PROC)wglGetPixelFormatAttribivARB},
324 // {"wglGetPixelFormatAttribfvARB", (PROC)wglGetPixelFormatAttribfvARB},
325 {"wglChoosePixelFormatARB", (PROC)wglChoosePixelFormatARB},
326 // {"wglCreatePbufferARB", (PROC)wglCreatePbufferARB},
327 // {"wglGetPbufferDCARB", (PROC)wglGetPbufferDCARB},
328 // {"wglReleasePbufferDCARB", (PROC)wglReleasePbufferDCARB},
329 // {"wglDestroyPbufferARB", (PROC)wglDestroyPbufferARB},
330 // {"wglQueryPbufferARB", (PROC)wglQueryPbufferARB},
331 // {"wglSetPbufferAttribARB", (PROC)wglSetPbufferAttribARB},
332 // {"wglBindTexImageARB", (PROC)wglBindTexImageARB},
333 // {"wglReleaseTexImageARB", (PROC)wglReleaseTexImageARB},
334 // {"wglCreateBufferRegionARB", (PROC)wglCreateBufferRegionARB},
335 // {"wglDeleteBufferRegionARB", (PROC)wglDeleteBufferRegionARB},
336 // {"wglSaveBufferRegionARB", (PROC)wglSaveBufferRegionARB},
337 // {"wglRestoreBufferRegionARB", (PROC)wglRestoreBufferRegionARB},
338 // {"wglMakeContextCurrentARB", (PROC)wglMakeContextCurrentARB},
339 // {"wglGetCurrentReadDCARB", (PROC)wglGetCurrentReadDCARB},
340 {NULL, NULL}
341 };
342
343 WGLAPI PROC GLAPIENTRY DrvGetProcAddress(LPCSTR lpszProc)
344 {
345 int i;
346 PROC p = (PROC) (int) _glapi_get_proc_address((const char *) lpszProc);
347 if (p)
348 return p;
349
350 for (i = 0; wgl_ext[i].name; i++)
351 {
352 if (!strcmp(lpszProc, wgl_ext[i].name))
353 {
354 return wgl_ext[i].func;
355 }
356 }
357
358 SetLastError(0);
359 return(NULL);
360 }
361
362 WGLAPI BOOL GLAPIENTRY DrvSetPixelFormat(HDC hdc,int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
363 {
364 int qt_valid_pix;
365
366 qt_valid_pix = qt_pix;
367
368 if (iPixelFormat < 1 || iPixelFormat > qt_valid_pix) {
369 if (ppfd == NULL) {
370 PIXELFORMATDESCRIPTOR my_pfd;
371 if (!DrvDescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &my_pfd)) {
372 SetLastError(0);
373 return FALSE;
374 }
375 } else if (ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR)) {
376 SetLastError(0);
377 return FALSE;
378 }
379 }
380 curPFD = iPixelFormat;
381
382 return TRUE;
383 }
384
385 WGLAPI BOOL GLAPIENTRY DrvSwapBuffers(HDC hdc)
386 {
387 (void) hdc;
388 if (ctx_current < 0)
389 return FALSE;
390
391 if(wgl_ctx[ctx_current].ctx == NULL) {
392 SetLastError(0);
393 return(FALSE);
394 }
395 WMesaSwapBuffers(hdc);
396 return(TRUE);
397 }
398
399 WGLAPI BOOL GLAPIENTRY DrvValidateVersion(DWORD version)
400 {
401 (void) version;
402 return TRUE;
403 }