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
48 #include "../gdi/wmesadef.h"
53 #define MAX_MESA_ATTRS 20
56 typedef struct _icdTable
{
59 } ICDTABLE
, *PICDTABLE
;
61 #ifdef USE_MGL_NAMESPACE
62 # define GL_FUNC(func) mgl##func
64 # define GL_FUNC(func) gl##func
67 static ICDTABLE icdTable
= { 336, {
68 #define ICD_ENTRY(func) (PROC)GL_FUNC(func),
73 struct __pixelformat__
75 PIXELFORMATDESCRIPTOR pfd
;
76 GLboolean doubleBuffered
;
79 struct __pixelformat__ pix
[] =
81 /* Double Buffer, alpha */
82 { { sizeof(PIXELFORMATDESCRIPTOR
), 1,
83 PFD_DRAW_TO_WINDOW
|PFD_SUPPORT_OPENGL
|PFD_DOUBLEBUFFER
|PFD_SWAP_COPY
,
85 24, 8, 0, 8, 8, 8, 16, 8, 24,
86 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
89 /* Single Buffer, alpha */
90 { { sizeof(PIXELFORMATDESCRIPTOR
), 1,
91 PFD_DRAW_TO_WINDOW
|PFD_SUPPORT_OPENGL
, /* | PFD_SUPPORT_GDI ? */
93 24, 8, 0, 8, 8, 8, 16, 8, 24,
94 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
97 /* Double Buffer, no alpha */
98 { { sizeof(PIXELFORMATDESCRIPTOR
), 1,
99 PFD_DRAW_TO_WINDOW
|PFD_SUPPORT_OPENGL
|PFD_DOUBLEBUFFER
|PFD_SWAP_COPY
,
101 24, 8, 0, 8, 8, 8, 16, 0, 0,
102 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
105 /* Single Buffer, no alpha */
106 { { sizeof(PIXELFORMATDESCRIPTOR
), 1,
107 PFD_DRAW_TO_WINDOW
|PFD_SUPPORT_OPENGL
, /* | PFD_SUPPORT_GDI ? */
109 24, 8, 0, 8, 8, 8, 16, 0, 0,
110 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
115 int qt_pix
= sizeof(pix
) / sizeof(pix
[0]);
122 #define MESAWGL_CTX_MAX_COUNT 20
124 static MesaWglCtx wgl_ctx
[MESAWGL_CTX_MAX_COUNT
];
126 static unsigned ctx_count
= 0;
127 static int ctx_current
= -1;
128 static unsigned curPFD
= 0;
130 WGLAPI BOOL GLAPIENTRY
DrvCopyContext(HGLRC hglrcSrc
,HGLRC hglrcDst
,UINT mask
)
132 (void) hglrcSrc
; (void) hglrcDst
; (void) mask
;
136 WGLAPI HGLRC GLAPIENTRY
DrvCreateContext(HDC hdc
)
141 if(!(hWnd
= WindowFromDC(hdc
)))
148 for(i
=0;i
<MESAWGL_CTX_MAX_COUNT
;i
++)
150 wgl_ctx
[i
].ctx
= NULL
;
151 wgl_ctx
[i
].hdc
= NULL
;
154 for( i
= 0; i
< MESAWGL_CTX_MAX_COUNT
; i
++ )
156 if ( wgl_ctx
[i
].ctx
== NULL
)
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
)
163 wgl_ctx
[i
].hdc
= hdc
;
165 return ((HGLRC
)wgl_ctx
[i
].ctx
);
172 WGLAPI BOOL GLAPIENTRY
DrvDeleteContext(HGLRC hglrc
)
175 for ( i
= 0; i
< MESAWGL_CTX_MAX_COUNT
; i
++ )
177 if ( wgl_ctx
[i
].ctx
== (PWMC
) hglrc
)
179 WMesaMakeCurrent((PWMC
) hglrc
);
180 WMesaDestroyContext();
181 wgl_ctx
[i
].ctx
= NULL
;
182 wgl_ctx
[i
].hdc
= NULL
;
191 WGLAPI HGLRC GLAPIENTRY
DrvCreateLayerContext(HDC hdc
,int iLayerPlane
)
193 if (iLayerPlane
== 0)
194 return DrvCreateContext(hdc
);
199 WGLAPI PICDTABLE GLAPIENTRY
DrvSetContext(HDC hdc
,HGLRC hglrc
,void *callback
)
204 /* new code suggested by Andy Sy */
205 if (!hdc
|| !hglrc
) {
206 WMesaMakeCurrent(NULL
);
211 for ( i
= 0; i
< MESAWGL_CTX_MAX_COUNT
; i
++ )
213 if ( wgl_ctx
[i
].ctx
== (PWMC
) hglrc
)
215 wgl_ctx
[i
].hdc
= hdc
;
216 WMesaMakeCurrent( (PWMC
) hglrc
);
224 WGLAPI
void GLAPIENTRY
DrvReleaseContext(HGLRC hglrc
)
227 WMesaMakeCurrent(NULL
);
231 WGLAPI BOOL GLAPIENTRY
DrvShareLists(HGLRC hglrc1
,HGLRC hglrc2
)
233 (void) hglrc1
; (void) hglrc2
;
237 WGLAPI BOOL GLAPIENTRY
DrvDescribeLayerPlane(HDC hdc
,int iPixelFormat
,
238 int iLayerPlane
,UINT nBytes
,
239 LPLAYERPLANEDESCRIPTOR plpd
)
241 (void) hdc
; (void) iPixelFormat
; (void) iLayerPlane
; (void) nBytes
; (void) plpd
;
246 WGLAPI
int GLAPIENTRY
DrvSetLayerPaletteEntries(HDC hdc
,int iLayerPlane
,
247 int iStart
,int cEntries
,
250 (void) hdc
; (void) iLayerPlane
; (void) iStart
; (void) cEntries
; (void) pcr
;
255 WGLAPI
int GLAPIENTRY
DrvGetLayerPaletteEntries(HDC hdc
,int iLayerPlane
,
256 int iStart
,int cEntries
,
259 (void) hdc
; (void) iLayerPlane
; (void) iStart
; (void) cEntries
; (void) pcr
;
264 WGLAPI BOOL GLAPIENTRY
DrvRealizeLayerPalette(HDC hdc
,int iLayerPlane
,BOOL bRealize
)
266 (void) hdc
; (void) iLayerPlane
; (void) bRealize
;
271 WGLAPI BOOL GLAPIENTRY
DrvSwapLayerBuffers(HDC hdc
,UINT fuPlanes
)
283 WGLAPI
int GLAPIENTRY
DrvDescribePixelFormat(HDC hdc
,int iPixelFormat
,UINT nBytes
,
284 LPPIXELFORMATDESCRIPTOR ppfd
)
289 qt_valid_pix
= qt_pix
;
291 return(qt_valid_pix
);
292 if(iPixelFormat
< 1 || iPixelFormat
> qt_valid_pix
|| nBytes
!= sizeof(PIXELFORMATDESCRIPTOR
))
297 *ppfd
= pix
[iPixelFormat
- 1].pfd
;
298 return(qt_valid_pix
);
302 * GetProcAddress - return the address of an appropriate extension
304 WGLAPI PROC GLAPIENTRY
DrvGetProcAddress(LPCSTR lpszProc
)
306 PROC p
= (PROC
) (int) _glapi_get_proc_address((const char *) lpszProc
);
314 WGLAPI BOOL GLAPIENTRY
DrvSetPixelFormat(HDC hdc
,int iPixelFormat
)
319 qt_valid_pix
= qt_pix
;
320 if(iPixelFormat
< 1 || iPixelFormat
> qt_valid_pix
)
325 curPFD
= iPixelFormat
;
329 WGLAPI BOOL GLAPIENTRY
DrvSwapBuffers(HDC hdc
)
335 if(wgl_ctx
[ctx_current
].ctx
== NULL
) {
343 WGLAPI BOOL GLAPIENTRY
DrvValidateVersion(DWORD version
)