2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2001 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.
33 /* fxwgl.c - Microsoft wgl functions emulation for
34 * 3Dfx VooDoo/Mesa interface
45 #define GL_GLEXT_PROTOTYPES
53 #include "GL/fxmesa.h"
57 #include "../../glide/fxdrv.h"
59 #define MAX_MESA_ATTRS 20
61 #if (_MSC_VER >= 1200)
62 #pragma warning( push )
63 #pragma warning( disable : 4273 )
66 struct __extensions__
{
71 struct __pixelformat__
{
72 PIXELFORMATDESCRIPTOR pfd
;
73 GLint mesaAttr
[MAX_MESA_ATTRS
];
76 WINGDIAPI
void GLAPIENTRY
gl3DfxSetPaletteEXT(GLuint
*);
77 static GLushort gammaTable
[3 * 256];
79 struct __pixelformat__ pix
[] = {
80 /* 16bit RGB565 single buffer with depth */
82 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
83 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
,
86 5, 0, 6, 5, 5, 11, 0, 0,
94 {FXMESA_COLORDEPTH
, 16,
96 FXMESA_DEPTH_SIZE
, 16,
97 FXMESA_STENCIL_SIZE
, 0,
102 /* 16bit RGB565 double buffer with depth */
104 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
105 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
|
106 PFD_DOUBLEBUFFER
| PFD_SWAP_COPY
,
109 5, 0, 6, 5, 5, 11, 0, 0,
117 {FXMESA_COLORDEPTH
, 16,
119 FXMESA_ALPHA_SIZE
, 0,
120 FXMESA_DEPTH_SIZE
, 16,
121 FXMESA_STENCIL_SIZE
, 0,
122 FXMESA_ACCUM_SIZE
, 0,
126 /* 16bit ARGB1555 single buffer with depth */
128 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
129 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
,
132 5, 0, 5, 5, 5, 10, 1, 15,
140 {FXMESA_COLORDEPTH
, 15,
141 FXMESA_ALPHA_SIZE
, 1,
142 FXMESA_DEPTH_SIZE
, 16,
143 FXMESA_STENCIL_SIZE
, 0,
144 FXMESA_ACCUM_SIZE
, 0,
148 /* 16bit ARGB1555 double buffer with depth */
150 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
151 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
|
152 PFD_DOUBLEBUFFER
| PFD_SWAP_COPY
,
155 5, 0, 5, 5, 5, 10, 1, 15,
163 {FXMESA_COLORDEPTH
, 15,
165 FXMESA_ALPHA_SIZE
, 1,
166 FXMESA_DEPTH_SIZE
, 16,
167 FXMESA_STENCIL_SIZE
, 0,
168 FXMESA_ACCUM_SIZE
, 0,
172 /* 32bit ARGB8888 single buffer with depth */
174 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
175 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
,
178 8, 0, 8, 8, 8, 16, 8, 24,
186 {FXMESA_COLORDEPTH
, 32,
187 FXMESA_ALPHA_SIZE
, 8,
188 FXMESA_DEPTH_SIZE
, 24,
189 FXMESA_STENCIL_SIZE
, 8,
190 FXMESA_ACCUM_SIZE
, 0,
194 /* 32bit ARGB8888 double buffer with depth */
196 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
197 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
|
198 PFD_DOUBLEBUFFER
| PFD_SWAP_COPY
,
201 8, 0, 8, 8, 8, 16, 8, 24,
209 {FXMESA_COLORDEPTH
, 32,
211 FXMESA_ALPHA_SIZE
, 8,
212 FXMESA_DEPTH_SIZE
, 24,
213 FXMESA_STENCIL_SIZE
, 8,
214 FXMESA_ACCUM_SIZE
, 0,
219 static fxMesaContext ctx
= NULL
;
220 static WNDPROC hWNDOldProc
;
221 static int curPFD
= 0;
225 static GLboolean haveDualHead
;
227 /* For the in-window-rendering hack */
229 #ifndef GR_CONTROL_RESIZE
230 /* Apparently GR_CONTROL_RESIZE can be ignored. OK? */
231 #define GR_CONTROL_RESIZE -1
234 static GLboolean gdiWindowHack
;
235 static void *dibSurfacePtr
;
236 static BITMAPINFO
*dibBMI
;
237 static HBITMAP dibHBM
;
241 env_check (const char *var
, int val
)
243 const char *env
= getenv(var
);
244 return (env
&& (env
[0] == val
));
247 static LRESULT APIENTRY
248 __wglMonitor (HWND hwnd
, UINT message
, UINT wParam
, LONG lParam
)
250 long ret
; /* Now gives the resized window at the end to hWNDOldProc */
252 if (ctx
&& hwnd
== hWND
) {
257 case WM_DISPLAYCHANGE
:
260 if (wParam
!= SIZE_MINIMIZED
) {
261 static int moving
= 0;
263 if (!FX_grSstControl(GR_CONTROL_RESIZE
)) {
265 SetWindowPos(hwnd
, 0, 0, 0, 300, 300, SWP_NOMOVE
| SWP_NOZORDER
);
267 if (!FX_grSstControl(GR_CONTROL_RESIZE
)) {
268 /*MessageBox(0,_T("Error changing windowsize"),_T("fxMESA"),MB_OK);*/
269 PostMessage(hWND
, WM_CLOSE
, 0, 0);
272 /* Do the clipping in the glide library */
273 grClipWindow(0, 0, FX_grSstScreenWidth(), FX_grSstScreenHeight());
274 /* And let the new size set in the context */
275 fxMesaUpdateScreenSize(ctx
);
290 /* Finally call the hWNDOldProc, which handles the resize with the
291 * now changed window sizes */
292 ret
= CallWindowProc(hWNDOldProc
, hwnd
, message
, wParam
, lParam
);
298 wgl_error (long error
)
300 #define WGL_INVALID_PIXELFORMAT ERROR_INVALID_PIXEL_FORMAT
301 SetLastError(0xC0000000 /* error severity */
302 |0x00070000 /* error facility (who we are) */
306 GLAPI BOOL GLAPIENTRY
307 wglCopyContext (HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
312 GLAPI HGLRC GLAPIENTRY
313 wglCreateContext (HDC hdc
)
324 if (!(hWnd
= WindowFromDC(hdc
))) {
330 wgl_error(WGL_INVALID_PIXELFORMAT
);
334 if ((oldProc
= (WNDPROC
)GetWindowLong(hWnd
, GWL_WNDPROC
)) != __wglMonitor
) {
335 hWNDOldProc
= oldProc
;
336 SetWindowLong(hWnd
, GWL_WNDPROC
, (LONG
)__wglMonitor
);
339 /* always log when debugging, or if user demands */
340 if (TDFX_DEBUG
|| env_check("MESA_FX_INFO", 'r')) {
341 freopen("MESA.LOG", "w", stderr
);
346 ShowWindow(hWnd
, SW_SHOWNORMAL
);
347 SetForegroundWindow(hWnd
);
348 Sleep(100); /* a hack for win95 */
349 if (env_check("MESA_GLX_FX", 'w') && !(GetWindowLong(hWnd
, GWL_STYLE
) & WS_POPUP
)) {
350 /* XXX todo - windowed modes */
351 error
= !(ctx
= fxMesaCreateContext((GLuint
) hWnd
, GR_RESOLUTION_NONE
, GR_REFRESH_NONE
, pix
[curPFD
- 1].mesaAttr
));
353 GetClientRect(hWnd
, &cliRect
);
354 error
= !(ctx
= fxMesaCreateBestContext((GLuint
) hWnd
, cliRect
.right
, cliRect
.bottom
, pix
[curPFD
- 1].mesaAttr
));
358 /*if (getenv("SST_DUALHEAD"))
360 ((atoi(getenv("SST_DUALHEAD")) == 1) ? GL_TRUE : GL_FALSE);
362 haveDualHead = GL_FALSE;*/
372 /* Required by the OpenGL Optimizer 1.1 (is it a Optimizer bug ?) */
373 wglMakeCurrent(hdc
, (HGLRC
)1);
378 GLAPI HGLRC GLAPIENTRY
379 wglCreateLayerContext (HDC hdc
, int iLayerPlane
)
385 GLAPI BOOL GLAPIENTRY
386 wglDeleteContext (HGLRC hglrc
)
388 if (ctx
&& hglrc
== (HGLRC
)1) {
390 fxMesaDestroyContext(ctx
);
392 SetWindowLong(WindowFromDC(hDC
), GWL_WNDPROC
, (LONG
) hWNDOldProc
);
404 GLAPI HGLRC GLAPIENTRY
405 wglGetCurrentContext (VOID
)
415 wglGetCurrentDC (VOID
)
424 GLAPI BOOL GLAPIENTRY
425 wglSwapIntervalEXT (int interval
)
432 } else if (interval
> 3) {
435 ctx
->swapInterval
= interval
;
440 wglGetSwapIntervalEXT (void)
442 return (ctx
== NULL
) ? -1 : ctx
->swapInterval
;
445 GLAPI BOOL GLAPIENTRY
446 wglGetDeviceGammaRamp3DFX (HDC hdc
, LPVOID arrays
)
448 /* gammaTable should be per-context */
449 memcpy(arrays
, gammaTable
, 3 * 256 * sizeof(GLushort
));
453 GLAPI BOOL GLAPIENTRY
454 wglSetDeviceGammaRamp3DFX (HDC hdc
, LPVOID arrays
)
456 GLint i
, tableSize
, inc
, index
;
457 GLushort
*red
, *green
, *blue
;
458 FxU32 gammaTableR
[256], gammaTableG
[256], gammaTableB
[256];
460 /* gammaTable should be per-context */
461 memcpy(gammaTable
, arrays
, 3 * 256 * sizeof(GLushort
));
463 tableSize
= FX_grGetInteger(GR_GAMMA_TABLE_ENTRIES
);
464 inc
= 256 / tableSize
;
465 red
= (GLushort
*)arrays
;
466 green
= (GLushort
*)arrays
+ 256;
467 blue
= (GLushort
*)arrays
+ 512;
468 for (i
= 0, index
= 0; i
< tableSize
; i
++, index
+= inc
) {
469 gammaTableR
[i
] = red
[index
] >> 8;
470 gammaTableG
[i
] = green
[index
] >> 8;
471 gammaTableB
[i
] = blue
[index
] >> 8;
474 grLoadGammaTable(tableSize
, gammaTableR
, gammaTableG
, gammaTableB
);
479 typedef void *HPBUFFERARB
;
481 /* WGL_ARB_pixel_format */
482 GLAPI BOOL GLAPIENTRY
483 wglGetPixelFormatAttribivARB (HDC hdc
,
487 const int *piAttributes
,
494 GLAPI BOOL GLAPIENTRY
495 wglGetPixelFormatAttribfvARB (HDC hdc
,
499 const int *piAttributes
,
506 GLAPI BOOL GLAPIENTRY
507 wglChoosePixelFormatARB (HDC hdc
,
508 const int *piAttribIList
,
509 const FLOAT
*pfAttribFList
,
518 /* WGL_ARB_render_texture */
519 GLAPI BOOL GLAPIENTRY
520 wglBindTexImageARB (HPBUFFERARB hPbuffer
, int iBuffer
)
526 GLAPI BOOL GLAPIENTRY
527 wglReleaseTexImageARB (HPBUFFERARB hPbuffer
, int iBuffer
)
533 GLAPI BOOL GLAPIENTRY
534 wglSetPbufferAttribARB (HPBUFFERARB hPbuffer
,
535 const int *piAttribList
)
541 /* WGL_ARB_pbuffer */
542 GLAPI HPBUFFERARB GLAPIENTRY
543 wglCreatePbufferARB (HDC hDC
,
547 const int *piAttribList
)
554 wglGetPbufferDCARB (HPBUFFERARB hPbuffer
)
561 wglReleasePbufferDCARB (HPBUFFERARB hPbuffer
, HDC hDC
)
567 GLAPI BOOL GLAPIENTRY
568 wglDestroyPbufferARB (HPBUFFERARB hPbuffer
)
574 GLAPI BOOL GLAPIENTRY
575 wglQueryPbufferARB (HPBUFFERARB hPbuffer
,
583 GLAPI
const char * GLAPIENTRY
584 wglGetExtensionsStringEXT (void)
586 return "WGL_3DFX_gamma_control "
587 "WGL_EXT_swap_control "
588 "WGL_EXT_extensions_string WGL_ARB_extensions_string"
589 /*WGL_ARB_pixel_format WGL_ARB_render_texture WGL_ARB_pbuffer*/;
592 GLAPI
const char * GLAPIENTRY
593 wglGetExtensionsStringARB (HDC hdc
)
595 return wglGetExtensionsStringEXT();
602 {"wglGetExtensionsStringARB", (PROC
)wglGetExtensionsStringARB
},
603 {"wglGetExtensionsStringEXT", (PROC
)wglGetExtensionsStringEXT
},
604 {"wglSwapIntervalEXT", (PROC
)wglSwapIntervalEXT
},
605 {"wglGetSwapIntervalEXT", (PROC
)wglGetSwapIntervalEXT
},
606 {"wglGetDeviceGammaRamp3DFX", (PROC
)wglGetDeviceGammaRamp3DFX
},
607 {"wglSetDeviceGammaRamp3DFX", (PROC
)wglSetDeviceGammaRamp3DFX
},
608 /* WGL_ARB_pixel_format */
609 {"wglGetPixelFormatAttribivARB", (PROC
)wglGetPixelFormatAttribivARB
},
610 {"wglGetPixelFormatAttribfvARB", (PROC
)wglGetPixelFormatAttribfvARB
},
611 {"wglChoosePixelFormatARB", (PROC
)wglChoosePixelFormatARB
},
612 /* WGL_ARB_render_texture */
613 {"wglBindTexImageARB", (PROC
)wglBindTexImageARB
},
614 {"wglReleaseTexImageARB", (PROC
)wglReleaseTexImageARB
},
615 {"wglSetPbufferAttribARB", (PROC
)wglSetPbufferAttribARB
},
616 /* WGL_ARB_pbuffer */
617 {"wglCreatePbufferARB", (PROC
)wglCreatePbufferARB
},
618 {"wglGetPbufferDCARB", (PROC
)wglGetPbufferDCARB
},
619 {"wglReleasePbufferDCARB", (PROC
)wglReleasePbufferDCARB
},
620 {"wglDestroyPbufferARB", (PROC
)wglDestroyPbufferARB
},
621 {"wglQueryPbufferARB", (PROC
)wglQueryPbufferARB
},
625 GLAPI PROC GLAPIENTRY
626 wglGetProcAddress (LPCSTR lpszProc
)
629 PROC p
= (PROC
)_glapi_get_proc_address((const char *)lpszProc
);
631 /* we can't BlendColor. work around buggy applications */
632 if (p
&& strcmp(lpszProc
, "glBlendColor")
633 && strcmp(lpszProc
, "glBlendColorEXT"))
636 for (i
= 0; wgl_ext
[i
].name
; i
++) {
637 if (!strcmp(lpszProc
, wgl_ext
[i
].name
)) {
638 return wgl_ext
[i
].func
;
646 GLAPI PROC GLAPIENTRY
647 wglGetDefaultProcAddress (LPCSTR lpszProc
)
653 GLAPI BOOL GLAPIENTRY
654 wglMakeCurrent (HDC hdc
, HGLRC hglrc
)
656 if ((hdc
== NULL
) && (hglrc
== NULL
))
659 if (!ctx
|| hglrc
!= (HGLRC
)1 || WindowFromDC(hdc
) != hWND
) {
666 fxMesaMakeCurrent(ctx
);
671 GLAPI BOOL GLAPIENTRY
672 wglShareLists (HGLRC hglrc1
, HGLRC hglrc2
)
674 if (!ctx
|| hglrc1
!= (HGLRC
)1 || hglrc1
!= hglrc2
) {
683 wglUseFontBitmaps_FX (HDC fontDevice
, DWORD firstChar
, DWORD numChars
,
692 GetTextMetrics(fontDevice
, &metric
);
694 dibInfo
= (BITMAPINFO
*)calloc(sizeof(BITMAPINFO
) + sizeof(RGBQUAD
), 1);
695 dibInfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
696 dibInfo
->bmiHeader
.biPlanes
= 1;
697 dibInfo
->bmiHeader
.biBitCount
= 1;
698 dibInfo
->bmiHeader
.biCompression
= BI_RGB
;
700 bitDevice
= CreateCompatibleDC(fontDevice
);
702 /* Swap fore and back colors so the bitmap has the right polarity */
703 tempColor
= GetBkColor(bitDevice
);
704 SetBkColor(bitDevice
, GetTextColor(bitDevice
));
705 SetTextColor(bitDevice
, tempColor
);
707 /* Place chars based on base line */
708 SetTextAlign(bitDevice
, TA_BASELINE
);
710 for (i
= 0; i
< (int)numChars
; i
++) {
713 int charWidth
, charHeight
, bmapWidth
, bmapHeight
, numBytes
, res
;
718 curChar
= (char)(i
+ firstChar
); /* [koolsmoky] explicit cast */
720 /* Find how high/wide this character is */
721 GetTextExtentPoint32(bitDevice
, &curChar
, 1, &size
);
723 /* Create the output bitmap */
725 charHeight
= size
.cy
;
726 bmapWidth
= ((charWidth
+ 31) / 32) * 32; /* Round up to the next multiple of 32 bits */
727 bmapHeight
= charHeight
;
728 bitObject
= CreateCompatibleBitmap(bitDevice
, bmapWidth
, bmapHeight
);
729 /*VERIFY(bitObject);*/
731 /* Assign the output bitmap to the device */
732 origBmap
= SelectObject(bitDevice
, bitObject
);
734 PatBlt(bitDevice
, 0, 0, bmapWidth
, bmapHeight
, BLACKNESS
);
736 /* Use our source font on the device */
737 SelectObject(bitDevice
, GetCurrentObject(fontDevice
, OBJ_FONT
));
739 /* Draw the character */
740 TextOut(bitDevice
, 0, metric
.tmAscent
, &curChar
, 1);
742 /* Unselect our bmap object */
743 SelectObject(bitDevice
, origBmap
);
745 /* Convert the display dependant representation to a 1 bit deep DIB */
746 numBytes
= (bmapWidth
* bmapHeight
) / 8;
747 bmap
= MALLOC(numBytes
);
748 dibInfo
->bmiHeader
.biWidth
= bmapWidth
;
749 dibInfo
->bmiHeader
.biHeight
= bmapHeight
;
750 res
= GetDIBits(bitDevice
, bitObject
, 0, bmapHeight
, bmap
,
751 dibInfo
, DIB_RGB_COLORS
);
753 /* Create the GL object */
754 glNewList(i
+ listBase
, GL_COMPILE
);
755 glBitmap(bmapWidth
, bmapHeight
, 0.0, metric
.tmDescent
,
756 charWidth
, 0.0, bmap
);
760 /* Destroy the bmap object */
761 DeleteObject(bitObject
);
763 /* Deallocate the bitmap data */
775 GLAPI BOOL GLAPIENTRY
776 wglUseFontBitmapsW (HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
)
781 GLAPI BOOL GLAPIENTRY
782 wglUseFontOutlinesA (HDC hdc
, DWORD first
, DWORD count
,
783 DWORD listBase
, FLOAT deviation
,
784 FLOAT extrusion
, int format
, LPGLYPHMETRICSFLOAT lpgmf
)
790 GLAPI BOOL GLAPIENTRY
791 wglUseFontOutlinesW (HDC hdc
, DWORD first
, DWORD count
,
792 DWORD listBase
, FLOAT deviation
,
793 FLOAT extrusion
, int format
, LPGLYPHMETRICSFLOAT lpgmf
)
800 GLAPI BOOL GLAPIENTRY
801 wglSwapLayerBuffers (HDC hdc
, UINT fuPlanes
)
803 if (ctx
&& WindowFromDC(hdc
) == hWND
) {
816 /* we should take an envvar for `fxMesaSelectCurrentBoard' */
817 return (fxMesaSelectCurrentBoard(0) < GR_SSTTYPE_Voodoo4
)
818 ? 2 /* only 16bit entries */
819 : sizeof(pix
) / sizeof(pix
[0]); /* full table */
823 wglChoosePixelFormat (HDC hdc
, const PIXELFORMATDESCRIPTOR
*ppfd
)
825 int i
, best
= -1, qt_valid_pix
;
826 PIXELFORMATDESCRIPTOR pfd
= *ppfd
;
828 qt_valid_pix
= pfd_tablen();
830 #if 1 || QUAKE2 || GORE
833 if ((pfd
.cColorBits
== 24) || (pfd
.cColorBits
== 32)) {
834 /* the first 2 entries are 16bit */
835 pfd
.cColorBits
= (qt_valid_pix
> 2) ? 32 : 16;
837 if (pfd
.cColorBits
== 32) {
839 } else if (pfd
.cColorBits
== 16) {
844 if (pfd
.nSize
!= sizeof(PIXELFORMATDESCRIPTOR
) || pfd
.nVersion
!= 1) {
849 for (i
= 0; i
< qt_valid_pix
; i
++) {
850 if (pfd
.cColorBits
> 0 && pix
[i
].pfd
.cColorBits
!= pfd
.cColorBits
)
853 if ((pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
)
854 && !(pix
[i
].pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
)) continue;
855 if ((pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
)
856 && !(pix
[i
].pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
)) continue;
857 if ((pfd
.dwFlags
& PFD_SUPPORT_GDI
)
858 && !(pix
[i
].pfd
.dwFlags
& PFD_SUPPORT_GDI
)) continue;
859 if ((pfd
.dwFlags
& PFD_SUPPORT_OPENGL
)
860 && !(pix
[i
].pfd
.dwFlags
& PFD_SUPPORT_OPENGL
)) continue;
861 if (!(pfd
.dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
)
862 && ((pfd
.dwFlags
& PFD_DOUBLEBUFFER
) !=
863 (pix
[i
].pfd
.dwFlags
& PFD_DOUBLEBUFFER
))) continue;
864 #if 1 /* Doom3 fails here! */
865 if (!(pfd
.dwFlags
& PFD_STEREO_DONTCARE
)
866 && ((pfd
.dwFlags
& PFD_STEREO
) !=
867 (pix
[i
].pfd
.dwFlags
& PFD_STEREO
))) continue;
870 if (pfd
.cDepthBits
> 0 && pix
[i
].pfd
.cDepthBits
== 0)
871 continue; /* need depth buffer */
873 if (pfd
.cAlphaBits
> 0 && pix
[i
].pfd
.cAlphaBits
== 0)
874 continue; /* need alpha buffer */
876 #if 0 /* regression bug? */
877 if (pfd
.cStencilBits
> 0 && pix
[i
].pfd
.cStencilBits
== 0)
878 continue; /* need stencil buffer */
881 if (pfd
.iPixelType
== pix
[i
].pfd
.iPixelType
) {
888 FILE *err
= fopen("MESA.LOG", "w");
890 fprintf(err
, "wglChoosePixelFormat failed\n");
891 fprintf(err
, "\tnSize = %d\n", ppfd
->nSize
);
892 fprintf(err
, "\tnVersion = %d\n", ppfd
->nVersion
);
893 fprintf(err
, "\tdwFlags = %lu\n", ppfd
->dwFlags
);
894 fprintf(err
, "\tiPixelType = %d\n", ppfd
->iPixelType
);
895 fprintf(err
, "\tcColorBits = %d\n", ppfd
->cColorBits
);
896 fprintf(err
, "\tcRedBits = %d\n", ppfd
->cRedBits
);
897 fprintf(err
, "\tcRedShift = %d\n", ppfd
->cRedShift
);
898 fprintf(err
, "\tcGreenBits = %d\n", ppfd
->cGreenBits
);
899 fprintf(err
, "\tcGreenShift = %d\n", ppfd
->cGreenShift
);
900 fprintf(err
, "\tcBlueBits = %d\n", ppfd
->cBlueBits
);
901 fprintf(err
, "\tcBlueShift = %d\n", ppfd
->cBlueShift
);
902 fprintf(err
, "\tcAlphaBits = %d\n", ppfd
->cAlphaBits
);
903 fprintf(err
, "\tcAlphaShift = %d\n", ppfd
->cAlphaShift
);
904 fprintf(err
, "\tcAccumBits = %d\n", ppfd
->cAccumBits
);
905 fprintf(err
, "\tcAccumRedBits = %d\n", ppfd
->cAccumRedBits
);
906 fprintf(err
, "\tcAccumGreenBits = %d\n", ppfd
->cAccumGreenBits
);
907 fprintf(err
, "\tcAccumBlueBits = %d\n", ppfd
->cAccumBlueBits
);
908 fprintf(err
, "\tcAccumAlphaBits = %d\n", ppfd
->cAccumAlphaBits
);
909 fprintf(err
, "\tcDepthBits = %d\n", ppfd
->cDepthBits
);
910 fprintf(err
, "\tcStencilBits = %d\n", ppfd
->cStencilBits
);
911 fprintf(err
, "\tcAuxBuffers = %d\n", ppfd
->cAuxBuffers
);
912 fprintf(err
, "\tiLayerType = %d\n", ppfd
->iLayerType
);
913 fprintf(err
, "\tbReserved = %d\n", ppfd
->bReserved
);
914 fprintf(err
, "\tdwLayerMask = %lu\n", ppfd
->dwLayerMask
);
915 fprintf(err
, "\tdwVisibleMask = %lu\n", ppfd
->dwVisibleMask
);
916 fprintf(err
, "\tdwDamageMask = %lu\n", ppfd
->dwDamageMask
);
928 ChoosePixelFormat (HDC hdc
, const PIXELFORMATDESCRIPTOR
*ppfd
)
931 return wglChoosePixelFormat(hdc
, ppfd
);
935 wglDescribePixelFormat (HDC hdc
, int iPixelFormat
, UINT nBytes
,
936 LPPIXELFORMATDESCRIPTOR ppfd
)
940 qt_valid_pix
= pfd_tablen();
942 if (iPixelFormat
< 1 || iPixelFormat
> qt_valid_pix
||
943 ((nBytes
!= sizeof(PIXELFORMATDESCRIPTOR
)) && (nBytes
!= 0))) {
949 *ppfd
= pix
[iPixelFormat
- 1].pfd
;
955 DescribePixelFormat (HDC hdc
, int iPixelFormat
, UINT nBytes
,
956 LPPIXELFORMATDESCRIPTOR ppfd
)
958 return wglDescribePixelFormat(hdc
, iPixelFormat
, nBytes
, ppfd
);
962 wglGetPixelFormat (HDC hdc
)
973 GetPixelFormat (HDC hdc
)
975 return wglGetPixelFormat(hdc
);
978 GLAPI BOOL GLAPIENTRY
979 wglSetPixelFormat (HDC hdc
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
983 qt_valid_pix
= pfd_tablen();
985 if (iPixelFormat
< 1 || iPixelFormat
> qt_valid_pix
) {
987 PIXELFORMATDESCRIPTOR my_pfd
;
988 if (!wglDescribePixelFormat(hdc
, iPixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &my_pfd
)) {
992 } else if (ppfd
->nSize
!= sizeof(PIXELFORMATDESCRIPTOR
)) {
997 curPFD
= iPixelFormat
;
1002 GLAPI BOOL GLAPIENTRY
1003 wglSwapBuffers (HDC hdc
)
1010 fxMesaSwapBuffers();
1015 GLAPI BOOL GLAPIENTRY
1016 SetPixelFormat (HDC hdc
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
*ppfd
)
1018 return wglSetPixelFormat(hdc
, iPixelFormat
, ppfd
);
1021 GLAPI BOOL GLAPIENTRY
1022 SwapBuffers(HDC hdc
)
1024 return wglSwapBuffers(hdc
);
1028 FixedFromDouble (double d
)
1034 pun
.l
= (long)(d
* 65536L);
1039 ** This was yanked from windows/gdi/wgl.c
1041 GLAPI BOOL GLAPIENTRY
1042 wglUseFontBitmapsA (HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
)
1053 font_list
= listBase
;
1055 mat
.eM11
= FixedFromDouble(1);
1056 mat
.eM12
= FixedFromDouble(0);
1057 mat
.eM21
= FixedFromDouble(0);
1058 mat
.eM22
= FixedFromDouble(-1);
1060 memset(&gm
, 0, sizeof(gm
));
1063 ** If we can't get the glyph outline, it may be because this is a fixed
1064 ** font. Try processing it that way.
1066 if (GetGlyphOutline(hdc
, first
, GGO_BITMAP
, &gm
, 0, NULL
, &mat
) == GDI_ERROR
) {
1067 return wglUseFontBitmaps_FX(hdc
, first
, count
, listBase
);
1071 ** Otherwise process all desired characters.
1073 for (i
= 0; i
< count
; i
++) {
1076 glNewList(font_list
+ i
, GL_COMPILE
);
1078 /* allocate space for the bitmap/outline */
1079 size
= GetGlyphOutline(hdc
, first
+ i
, GGO_BITMAP
, &gm
, 0, NULL
, &mat
);
1080 if (size
== GDI_ERROR
) {
1082 err
= GetLastError();
1087 hBits
= GlobalAlloc(GHND
, size
+ 1);
1088 lpBits
= GlobalLock(hBits
);
1090 err
= GetGlyphOutline(hdc
, /* handle to device context */
1091 first
+ i
, /* character to query */
1092 GGO_BITMAP
, /* format of data to return */
1093 &gm
, /* pointer to structure for metrics */
1094 size
, /* size of buffer for data */
1095 lpBits
, /* pointer to buffer for data */
1096 &mat
/* pointer to transformation */
1097 /* matrix structure */
1100 if (err
== GDI_ERROR
) {
1101 GlobalUnlock(hBits
);
1105 err
= GetLastError();
1110 glBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1111 -gm
.gmptGlyphOrigin
.x
,
1112 gm
.gmptGlyphOrigin
.y
,
1113 gm
.gmCellIncX
, gm
.gmCellIncY
,
1114 (const GLubyte
*)lpBits
);
1116 GlobalUnlock(hBits
);
1125 GLAPI BOOL GLAPIENTRY
1126 wglDescribeLayerPlane (HDC hdc
, int iPixelFormat
, int iLayerPlane
,
1127 UINT nBytes
, LPLAYERPLANEDESCRIPTOR ppfd
)
1133 GLAPI
int GLAPIENTRY
1134 wglGetLayerPaletteEntries (HDC hdc
, int iLayerPlane
, int iStart
,
1135 int cEntries
, COLORREF
*pcr
)
1141 GLAPI BOOL GLAPIENTRY
1142 wglRealizeLayerPalette (HDC hdc
, int iLayerPlane
, BOOL bRealize
)
1148 GLAPI
int GLAPIENTRY
1149 wglSetLayerPaletteEntries (HDC hdc
, int iLayerPlane
, int iStart
,
1150 int cEntries
, CONST COLORREF
*pcr
)
1157 /***************************************************************************
1158 * [dBorca] simplistic ICD implementation, based on ICD code by Gregor Anich
1161 typedef struct _icdTable
{
1164 } ICDTABLE
, *PICDTABLE
;
1166 #ifdef USE_MGL_NAMESPACE
1167 #define GL_FUNC(func) mgl##func
1169 #define GL_FUNC(func) gl##func
1172 static ICDTABLE icdTable
= { 336, {
1173 #define ICD_ENTRY(func) (PROC)GL_FUNC(func),
1174 #include "../icd/icdlist.h"
1179 GLAPI BOOL GLAPIENTRY
1180 DrvCopyContext (HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
1182 return wglCopyContext(hglrcSrc
, hglrcDst
, mask
);
1186 GLAPI HGLRC GLAPIENTRY
1187 DrvCreateContext (HDC hdc
)
1189 return wglCreateContext(hdc
);
1193 GLAPI BOOL GLAPIENTRY
1194 DrvDeleteContext (HGLRC hglrc
)
1196 return wglDeleteContext(hglrc
);
1200 GLAPI HGLRC GLAPIENTRY
1201 DrvCreateLayerContext (HDC hdc
, int iLayerPlane
)
1203 return wglCreateContext(hdc
);
1207 GLAPI PICDTABLE GLAPIENTRY
1208 DrvSetContext (HDC hdc
, HGLRC hglrc
, void *callback
)
1210 return wglMakeCurrent(hdc
, hglrc
) ? &icdTable
: NULL
;
1214 GLAPI BOOL GLAPIENTRY
1215 DrvReleaseContext (HGLRC hglrc
)
1221 GLAPI BOOL GLAPIENTRY
1222 DrvShareLists (HGLRC hglrc1
, HGLRC hglrc2
)
1224 return wglShareLists(hglrc1
, hglrc2
);
1228 GLAPI BOOL GLAPIENTRY
1229 DrvDescribeLayerPlane (HDC hdc
, int iPixelFormat
,
1230 int iLayerPlane
, UINT nBytes
,
1231 LPLAYERPLANEDESCRIPTOR plpd
)
1233 return wglDescribeLayerPlane(hdc
, iPixelFormat
, iLayerPlane
, nBytes
, plpd
);
1237 GLAPI
int GLAPIENTRY
1238 DrvSetLayerPaletteEntries (HDC hdc
, int iLayerPlane
,
1239 int iStart
, int cEntries
, CONST COLORREF
*pcr
)
1241 return wglSetLayerPaletteEntries(hdc
, iLayerPlane
, iStart
, cEntries
, pcr
);
1245 GLAPI
int GLAPIENTRY
1246 DrvGetLayerPaletteEntries (HDC hdc
, int iLayerPlane
,
1247 int iStart
, int cEntries
, COLORREF
*pcr
)
1249 return wglGetLayerPaletteEntries(hdc
, iLayerPlane
, iStart
, cEntries
, pcr
);
1253 GLAPI BOOL GLAPIENTRY
1254 DrvRealizeLayerPalette (HDC hdc
, int iLayerPlane
, BOOL bRealize
)
1256 return wglRealizeLayerPalette(hdc
, iLayerPlane
, bRealize
);
1260 GLAPI BOOL GLAPIENTRY
1261 DrvSwapLayerBuffers (HDC hdc
, UINT fuPlanes
)
1263 return wglSwapLayerBuffers(hdc
, fuPlanes
);
1266 GLAPI
int GLAPIENTRY
1267 DrvDescribePixelFormat (HDC hdc
, int iPixelFormat
, UINT nBytes
,
1268 LPPIXELFORMATDESCRIPTOR ppfd
)
1270 return wglDescribePixelFormat(hdc
, iPixelFormat
, nBytes
, ppfd
);
1274 GLAPI PROC GLAPIENTRY
1275 DrvGetProcAddress (LPCSTR lpszProc
)
1277 return wglGetProcAddress(lpszProc
);
1281 GLAPI BOOL GLAPIENTRY
1282 DrvSetPixelFormat (HDC hdc
, int iPixelFormat
)
1284 return wglSetPixelFormat(hdc
, iPixelFormat
, NULL
);
1288 GLAPI BOOL GLAPIENTRY
1289 DrvSwapBuffers (HDC hdc
)
1291 return wglSwapBuffers(hdc
);
1295 GLAPI BOOL GLAPIENTRY
1296 DrvValidateVersion (DWORD version
)
1303 #if (_MSC_VER >= 1200)
1304 #pragma warning( pop )