2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
27 * Author: Gregor Anich
29 * ICD (Installable Client Driver) interface.
30 * Based on the windows GDI/WGL driver.
38 #define GL_GLEXT_PROTOTYPES
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);
57 #define MAX_MESA_ATTRS 20
59 typedef struct wmesa_context
*PWMC
;
61 typedef struct _icdTable
{
64 } ICDTABLE
, *PICDTABLE
;
66 #ifdef USE_MGL_NAMESPACE
67 # define GL_FUNC(func) mgl##func
69 # define GL_FUNC(func) gl##func
73 static ICDTABLE icdTable
= { 418, {
74 #define ICD_ENTRY(func) (PROC)GL_FUNC(func),
79 struct __pixelformat__
81 PIXELFORMATDESCRIPTOR pfd
;
82 GLboolean doubleBuffered
;
85 struct __pixelformat__ pix
[] =
87 /* Double Buffer, alpha */
88 { { sizeof(PIXELFORMATDESCRIPTOR
), 1,
89 PFD_DRAW_TO_WINDOW
|PFD_SUPPORT_OPENGL
|PFD_DOUBLEBUFFER
|PFD_SWAP_COPY
,
91 24, 8, 0, 8, 8, 8, 16, 8, 24,
92 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
95 /* Single Buffer, alpha */
96 { { sizeof(PIXELFORMATDESCRIPTOR
), 1,
97 PFD_DRAW_TO_WINDOW
|PFD_SUPPORT_OPENGL
, /* | PFD_SUPPORT_GDI ? */
99 24, 8, 0, 8, 8, 8, 16, 8, 24,
100 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
103 /* Double Buffer, no alpha */
104 { { sizeof(PIXELFORMATDESCRIPTOR
), 1,
105 PFD_DRAW_TO_WINDOW
|PFD_SUPPORT_OPENGL
|PFD_DOUBLEBUFFER
|PFD_SWAP_COPY
,
107 24, 8, 0, 8, 8, 8, 16, 0, 0,
108 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
111 /* Single Buffer, no alpha */
112 { { sizeof(PIXELFORMATDESCRIPTOR
), 1,
113 PFD_DRAW_TO_WINDOW
|PFD_SUPPORT_OPENGL
, /* | PFD_SUPPORT_GDI ? */
115 24, 8, 0, 8, 8, 8, 16, 0, 0,
116 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
121 int qt_pix
= sizeof(pix
) / sizeof(pix
[0]);
128 #define MESAWGL_CTX_MAX_COUNT 20
130 static MesaWglCtx wgl_ctx
[MESAWGL_CTX_MAX_COUNT
];
132 static unsigned ctx_count
= 0;
133 static int ctx_current
= -1;
134 static unsigned curPFD
= 0;
136 WGLAPI BOOL GLAPIENTRY
DrvCopyContext(HGLRC hglrcSrc
,HGLRC hglrcDst
,UINT mask
)
138 (void) hglrcSrc
; (void) hglrcDst
; (void) mask
;
142 WGLAPI HGLRC GLAPIENTRY
DrvCreateContext(HDC hdc
)
147 if(!(hWnd
= WindowFromDC(hdc
)))
154 for(i
=0;i
<MESAWGL_CTX_MAX_COUNT
;i
++)
156 wgl_ctx
[i
].ctx
= NULL
;
157 wgl_ctx
[i
].hdc
= NULL
;
160 for( i
= 0; i
< MESAWGL_CTX_MAX_COUNT
; i
++ )
162 if ( wgl_ctx
[i
].ctx
== NULL
)
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
)
169 wgl_ctx
[i
].hdc
= hdc
;
171 return ((HGLRC
)wgl_ctx
[i
].ctx
);
178 WGLAPI BOOL GLAPIENTRY
DrvDeleteContext(HGLRC hglrc
)
181 for ( i
= 0; i
< MESAWGL_CTX_MAX_COUNT
; i
++ )
183 if ( wgl_ctx
[i
].ctx
== (PWMC
) hglrc
)
185 WMesaMakeCurrent((PWMC
) hglrc
, NULL
);
186 WMesaDestroyContext(wgl_ctx
[i
].ctx
);
187 wgl_ctx
[i
].ctx
= NULL
;
188 wgl_ctx
[i
].hdc
= NULL
;
197 WGLAPI HGLRC GLAPIENTRY
DrvCreateLayerContext(HDC hdc
,int iLayerPlane
)
199 if (iLayerPlane
== 0)
200 return DrvCreateContext(hdc
);
205 WGLAPI PICDTABLE GLAPIENTRY
DrvSetContext(HDC hdc
,HGLRC hglrc
,void *callback
)
210 /* new code suggested by Andy Sy */
211 if (!hdc
|| !hglrc
) {
212 WMesaMakeCurrent(NULL
, NULL
);
217 for ( i
= 0; i
< MESAWGL_CTX_MAX_COUNT
; i
++ )
219 if ( wgl_ctx
[i
].ctx
== (PWMC
) hglrc
)
221 wgl_ctx
[i
].hdc
= hdc
;
222 WMesaMakeCurrent( (PWMC
) hglrc
, hdc
);
230 WGLAPI
void GLAPIENTRY
DrvReleaseContext(HGLRC hglrc
)
233 WMesaMakeCurrent(NULL
, NULL
);
237 WGLAPI BOOL GLAPIENTRY
DrvShareLists(HGLRC hglrc1
,HGLRC hglrc2
)
239 (void) hglrc1
; (void) hglrc2
;
243 WGLAPI BOOL GLAPIENTRY
DrvDescribeLayerPlane(HDC hdc
,int iPixelFormat
,
244 int iLayerPlane
,UINT nBytes
,
245 LPLAYERPLANEDESCRIPTOR plpd
)
247 (void) hdc
; (void) iPixelFormat
; (void) iLayerPlane
; (void) nBytes
; (void) plpd
;
252 WGLAPI
int GLAPIENTRY
DrvSetLayerPaletteEntries(HDC hdc
,int iLayerPlane
,
253 int iStart
,int cEntries
,
256 (void) hdc
; (void) iLayerPlane
; (void) iStart
; (void) cEntries
; (void) pcr
;
261 WGLAPI
int GLAPIENTRY
DrvGetLayerPaletteEntries(HDC hdc
,int iLayerPlane
,
262 int iStart
,int cEntries
,
265 (void) hdc
; (void) iLayerPlane
; (void) iStart
; (void) cEntries
; (void) pcr
;
270 WGLAPI BOOL GLAPIENTRY
DrvRealizeLayerPalette(HDC hdc
,int iLayerPlane
,BOOL bRealize
)
272 (void) hdc
; (void) iLayerPlane
; (void) bRealize
;
277 WGLAPI BOOL GLAPIENTRY
DrvSwapLayerBuffers(HDC hdc
,UINT fuPlanes
)
282 WMesaSwapBuffers(hdc
);
289 WGLAPI
int GLAPIENTRY
DrvDescribePixelFormat(HDC hdc
,int iPixelFormat
,UINT nBytes
,
290 LPPIXELFORMATDESCRIPTOR ppfd
)
295 qt_valid_pix
= qt_pix
;
296 if( (nBytes
!= sizeof(PIXELFORMATDESCRIPTOR
)) || (iPixelFormat
< 1) || (iPixelFormat
>qt_valid_pix
) )
304 return(qt_valid_pix
);
307 *ppfd
= pix
[iPixelFormat
- 1].pfd
;
308 return(qt_valid_pix
);
312 * GetProcAddress - return the address of an appropriate extension
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},
343 WGLAPI PROC GLAPIENTRY
DrvGetProcAddress(LPCSTR lpszProc
)
346 PROC p
= (PROC
) (int) _glapi_get_proc_address((const char *) lpszProc
);
350 for (i
= 0; wgl_ext
[i
].name
; i
++)
352 if (!strcmp(lpszProc
, wgl_ext
[i
].name
))
354 return wgl_ext
[i
].func
;
362 WGLAPI BOOL GLAPIENTRY
DrvSetPixelFormat(HDC hdc
,int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
366 qt_valid_pix
= qt_pix
;
368 if (iPixelFormat
< 1 || iPixelFormat
> qt_valid_pix
) {
370 PIXELFORMATDESCRIPTOR my_pfd
;
371 if (!DrvDescribePixelFormat(hdc
, iPixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &my_pfd
)) {
375 } else if (ppfd
->nSize
!= sizeof(PIXELFORMATDESCRIPTOR
)) {
380 curPFD
= iPixelFormat
;
385 WGLAPI BOOL GLAPIENTRY
DrvSwapBuffers(HDC hdc
)
391 if(wgl_ctx
[ctx_current
].ctx
== NULL
) {
395 WMesaSwapBuffers(hdc
);
399 WGLAPI BOOL GLAPIENTRY
DrvValidateVersion(DWORD version
)