1 /* $Id: wgl.c,v 1.2 1999/09/19 09:59:20 tjump Exp $ */
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * WGL stuff. Added by Oleg Letsinsky, ajl@ultersys.ru
23 * Some things originated from the 3Dfx WGL functions
47 #define MAX_MESA_ATTRS 20
55 struct __pixelformat__
57 PIXELFORMATDESCRIPTOR pfd
;
58 GLboolean doubleBuffered
;
61 struct __extensions__ ext
[] = {
63 #ifdef GL_EXT_polygon_offset
64 { (PROC
)glPolygonOffsetEXT
, "glPolygonOffsetEXT" },
66 { (PROC
)glBlendEquationEXT
, "glBlendEquationEXT" },
67 { (PROC
)glBlendColorEXT
, "glBlendColorExt" },
68 { (PROC
)glVertexPointerEXT
, "glVertexPointerEXT" },
69 { (PROC
)glNormalPointerEXT
, "glNormalPointerEXT" },
70 { (PROC
)glColorPointerEXT
, "glColorPointerEXT" },
71 { (PROC
)glIndexPointerEXT
, "glIndexPointerEXT" },
72 { (PROC
)glTexCoordPointerEXT
, "glTexCoordPointer" },
73 { (PROC
)glEdgeFlagPointerEXT
, "glEdgeFlagPointerEXT" },
74 { (PROC
)glGetPointervEXT
, "glGetPointervEXT" },
75 { (PROC
)glArrayElementEXT
, "glArrayElementEXT" },
76 { (PROC
)glDrawArraysEXT
, "glDrawArrayEXT" },
77 { (PROC
)glAreTexturesResidentEXT
, "glAreTexturesResidentEXT" },
78 { (PROC
)glBindTextureEXT
, "glBindTextureEXT" },
79 { (PROC
)glDeleteTexturesEXT
, "glDeleteTexturesEXT" },
80 { (PROC
)glGenTexturesEXT
, "glGenTexturesEXT" },
81 { (PROC
)glIsTextureEXT
, "glIsTextureEXT" },
82 { (PROC
)glPrioritizeTexturesEXT
, "glPrioritizeTexturesEXT" },
83 { (PROC
)glCopyTexSubImage3DEXT
, "glCopyTexSubImage3DEXT" },
84 { (PROC
)glTexImage3DEXT
, "glTexImage3DEXT" },
85 { (PROC
)glTexSubImage3DEXT
, "glTexSubImage3DEXT" },
86 { (PROC
)glColorTableEXT
, "glColorTableEXT" },
87 { (PROC
)glColorSubTableEXT
, "glColorSubTableEXT" },
88 { (PROC
)glGetColorTableEXT
, "glGetColorTableEXT" },
89 { (PROC
)glGetColorTableParameterfvEXT
, "glGetColorTableParameterfvEXT" },
90 { (PROC
)glGetColorTableParameterivEXT
, "glGetColorTableParameterivEXT" },
91 { (PROC
)glPointParameterfEXT
, "glPointParameterfEXT" },
92 { (PROC
)glPointParameterfvEXT
, "glPointParameterfvEXT" },
93 { (PROC
)glBlendFuncSeparateINGR
, "glBlendFuncSeparateINGR" },
94 { (PROC
)glLockArraysEXT
, "glLockArraysEXT" },
95 { (PROC
)glUnlockArraysEXT
, "glUnlockArraysEXT" }
98 int qt_ext
= sizeof(ext
) / sizeof(ext
[0]);
100 struct __pixelformat__ pix
[] =
102 { { sizeof(PIXELFORMATDESCRIPTOR
), 1,
103 PFD_DRAW_TO_WINDOW
|PFD_SUPPORT_OPENGL
|PFD_GENERIC_FORMAT
|PFD_DOUBLEBUFFER
|PFD_SWAP_COPY
,
105 24, 8, 0, 8, 8, 8, 16, 8, 24,
106 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
109 { { sizeof(PIXELFORMATDESCRIPTOR
), 1,
110 PFD_DRAW_TO_WINDOW
|PFD_SUPPORT_OPENGL
|PFD_GENERIC_FORMAT
,
112 24, 8, 0, 8, 8, 8, 16, 8, 24,
113 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
118 int qt_pix
= sizeof(pix
) / sizeof(pix
[0]);
125 #define MESAWGL_CTX_MAX_COUNT 20
127 static MesaWglCtx wgl_ctx
[MESAWGL_CTX_MAX_COUNT
];
129 static unsigned ctx_count
= 0;
130 static unsigned ctx_current
= -1;
131 static unsigned curPFD
= 0;
133 GLAPI BOOL GLWINAPI
wglCopyContext(HGLRC hglrcSrc
,HGLRC hglrcDst
,UINT mask
)
138 GLAPI HGLRC GLWINAPI
wglCreateContext(HDC hdc
)
142 if(!(hWnd
= WindowFromDC(hdc
)))
149 for(i
=0;i
<MESAWGL_CTX_MAX_COUNT
;i
++)
151 wgl_ctx
[i
].ctx
= NULL
;
152 wgl_ctx
[i
].hdc
= NULL
;
155 for( i
= 0; i
< MESAWGL_CTX_MAX_COUNT
; i
++ )
157 if ( wgl_ctx
[i
].ctx
== NULL
)
159 wgl_ctx
[i
].ctx
= WMesaCreateContext( hWnd
, NULL
, GL_TRUE
,
160 pix
[curPFD
-1].doubleBuffered
);
161 if (wgl_ctx
[i
].ctx
== NULL
)
163 wgl_ctx
[i
].hdc
= hdc
;
165 return ((HGLRC
)wgl_ctx
[i
].ctx
);
172 GLAPI BOOL GLWINAPI
wglDeleteContext(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 GLAPI HGLRC GLWINAPI
wglCreateLayerContext(HDC hdc
,int iLayerPlane
)
197 GLAPI HGLRC GLWINAPI
wglGetCurrentContext(VOID
)
202 return (HGLRC
) wgl_ctx
[ctx_current
].ctx
;
205 GLAPI HDC GLWINAPI
wglGetCurrentDC(VOID
)
210 return wgl_ctx
[ctx_current
].hdc
;
213 GLAPI BOOL GLWINAPI
wglMakeCurrent(HDC hdc
,HGLRC hglrc
)
217 /* new code suggested by Andy Sy */
218 if (!hdc
|| !hglrc
) {
219 WMesaMakeCurrent(NULL
);
224 for ( i
= 0; i
< MESAWGL_CTX_MAX_COUNT
; i
++ )
226 if ( wgl_ctx
[i
].ctx
== (PWMC
) hglrc
)
228 wgl_ctx
[i
].hdc
= hdc
;
229 WMesaMakeCurrent( (WMesaContext
) hglrc
);
237 GLAPI BOOL GLWINAPI
wglShareLists(HGLRC hglrc1
,HGLRC hglrc2
)
243 static FIXED
FixedFromDouble(double d
)
245 long l
= (long) (d
* 65536L);
250 GLAPI BOOL GLWINAPI
wglUseFontBitmapsA(HDC hdc
, DWORD first
,
251 DWORD count
, DWORD listBase
)
268 font_list
= glGenLists( count
);
272 mat
.eM11
= FixedFromDouble(1);
273 mat
.eM12
= FixedFromDouble(0);
274 mat
.eM21
= FixedFromDouble(0);
275 mat
.eM22
= FixedFromDouble(1);
277 memset(&gm
,0,sizeof(gm
));
279 for (i
= 0; i
< count
; i
++)
281 glNewList( font_list
+i
, GL_COMPILE
);
283 /* allocate space for the bitmap/outline */
284 size
= GetGlyphOutline(hdc
, first
+ i
, GGO_BITMAP
, &gm
, 0, NULL
, &mat
);
285 if (size
== GDI_ERROR
)
288 err
= GetLastError();
292 hBits
= GlobalAlloc(GHND
, size
);
293 lpBits
= GlobalLock(hBits
);
295 GetGlyphOutline(hdc
, /* handle to device context */
296 first
+ i
, /* character to query */
297 GGO_BITMAP
, /* format of data to return */
298 &gm
, /* pointer to structure for metrics */
299 size
, /* size of buffer for data */
300 lpBits
, /* pointer to buffer for data */
301 &mat
/* pointer to transformation */
302 /* matrix structure */
305 if (*lpBits
== GDI_ERROR
)
308 err
= GetLastError();
316 glBitmap(gm
.gmBlackBoxX
,gm
.gmBlackBoxY
,
317 gm
.gmptGlyphOrigin
.x
,
318 gm
.gmptGlyphOrigin
.y
,
319 gm
.gmCellIncX
,gm
.gmCellIncY
,
320 (const GLubyte
* )lpBits
);
331 GLAPI BOOL GLWINAPI
wglUseFontBitmapsW(HDC hdc
,DWORD first
,DWORD count
,DWORD listBase
)
336 GLAPI BOOL GLWINAPI
wglUseFontOutlinesA(HDC hdc
,DWORD first
,DWORD count
,
337 DWORD listBase
,FLOAT deviation
,
338 FLOAT extrusion
,int format
,
339 LPGLYPHMETRICSFLOAT lpgmf
)
345 GLAPI BOOL GLWINAPI
wglUseFontOutlinesW(HDC hdc
,DWORD first
,DWORD count
,
346 DWORD listBase
,FLOAT deviation
,
347 FLOAT extrusion
,int format
,
348 LPGLYPHMETRICSFLOAT lpgmf
)
354 GLAPI BOOL GLWINAPI
wglDescribeLayerPlane(HDC hdc
,int iPixelFormat
,
355 int iLayerPlane
,UINT nBytes
,
356 LPLAYERPLANEDESCRIPTOR plpd
)
362 GLAPI
int GLWINAPI
wglSetLayerPaletteEntries(HDC hdc
,int iLayerPlane
,
363 int iStart
,int cEntries
,
370 GLAPI
int GLWINAPI
wglGetLayerPaletteEntries(HDC hdc
,int iLayerPlane
,
371 int iStart
,int cEntries
,
378 GLAPI BOOL GLWINAPI
wglRealizeLayerPalette(HDC hdc
,int iLayerPlane
,BOOL bRealize
)
384 GLAPI BOOL GLWINAPI
wglSwapLayerBuffers(HDC hdc
,UINT fuPlanes
)
395 GLAPI
int GLWINAPI
wglChoosePixelFormat(HDC hdc
,
396 CONST PIXELFORMATDESCRIPTOR
*ppfd
)
398 int i
,best
= -1,bestdelta
= 0x7FFFFFFF,delta
,qt_valid_pix
;
400 qt_valid_pix
= qt_pix
;
401 if(ppfd
->nSize
!= sizeof(PIXELFORMATDESCRIPTOR
) || ppfd
->nVersion
!= 1)
406 for(i
= 0;i
< qt_valid_pix
;i
++)
410 (ppfd
->dwFlags
& PFD_DRAW_TO_WINDOW
) &&
411 !(pix
[i
].pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
))
414 (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) &&
415 !(pix
[i
].pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
))
418 (ppfd
->dwFlags
& PFD_SUPPORT_GDI
) &&
419 !(pix
[i
].pfd
.dwFlags
& PFD_SUPPORT_GDI
))
422 (ppfd
->dwFlags
& PFD_SUPPORT_OPENGL
) &&
423 !(pix
[i
].pfd
.dwFlags
& PFD_SUPPORT_OPENGL
))
426 !(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
) &&
427 ((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != (pix
[i
].pfd
.dwFlags
& PFD_DOUBLEBUFFER
)))
430 !(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
) &&
431 ((ppfd
->dwFlags
& PFD_STEREO
) != (pix
[i
].pfd
.dwFlags
& PFD_STEREO
)))
433 if(ppfd
->iPixelType
!= pix
[i
].pfd
.iPixelType
)
435 if(delta
< bestdelta
)
451 GLAPI
int GLWINAPI
wglDescribePixelFormat(HDC hdc
,int iPixelFormat
,UINT nBytes
,
452 LPPIXELFORMATDESCRIPTOR ppfd
)
456 qt_valid_pix
= qt_pix
;
457 if(iPixelFormat
< 1 || iPixelFormat
> qt_valid_pix
|| nBytes
!= sizeof(PIXELFORMATDESCRIPTOR
))
462 *ppfd
= pix
[iPixelFormat
- 1].pfd
;
463 return(qt_valid_pix
);
467 * GetProcAddress - return the address of an appropriate extension
469 GLAPI PROC GLWINAPI
wglGetProcAddress(LPCSTR lpszProc
)
472 for(i
= 0;i
< qt_ext
;i
++)
473 if(!strcmp(lpszProc
,ext
[i
].name
))
480 GLAPI
int GLWINAPI
wglGetPixelFormat(HDC hdc
)
490 GLAPI BOOL GLWINAPI
wglSetPixelFormat(HDC hdc
,int iPixelFormat
,
491 PIXELFORMATDESCRIPTOR
*ppfd
)
495 qt_valid_pix
= qt_pix
;
496 if(iPixelFormat
< 1 || iPixelFormat
> qt_valid_pix
|| ppfd
->nSize
!= sizeof(PIXELFORMATDESCRIPTOR
))
501 curPFD
= iPixelFormat
;
505 GLAPI BOOL GLWINAPI
wglSwapBuffers(HDC hdc
)
510 if(wgl_ctx
[ctx_current
].ctx
== NULL
) {