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
46 #define GL_GLEXT_PROTOTYPES
54 #include "GL/fxmesa.h"
60 #define MAX_MESA_ATTRS 20
62 #if (_MSC_VER >= 1200)
63 #pragma warning( push )
64 #pragma warning( disable : 4273 )
73 struct __pixelformat__
75 PIXELFORMATDESCRIPTOR pfd
;
76 GLint mesaAttr
[MAX_MESA_ATTRS
];
79 WINGDIAPI
void GLAPIENTRY
gl3DfxSetPaletteEXT(GLuint
*);
80 static GLushort gammaTable
[3*256];
82 struct __pixelformat__ pix
[] = {
83 /* 16bit RGB565 single buffer with depth */
85 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
86 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
,
89 5, 0, 6, 5, 5, 11, 0, 0,
97 {FXMESA_COLORDEPTH
, 16,
99 FXMESA_DEPTH_SIZE
, 16,
100 FXMESA_STENCIL_SIZE
, 0,
101 FXMESA_ACCUM_SIZE
, 0,
105 /* 16bit RGB565 double buffer with depth */
107 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
108 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
|
109 PFD_DOUBLEBUFFER
| PFD_SWAP_COPY
,
112 5, 0, 6, 5, 5, 11, 0, 0,
120 {FXMESA_COLORDEPTH
, 16,
122 FXMESA_ALPHA_SIZE
, 0,
123 FXMESA_DEPTH_SIZE
, 16,
124 FXMESA_STENCIL_SIZE
, 0,
125 FXMESA_ACCUM_SIZE
, 0,
129 /* 16bit ARGB1555 single buffer with depth */
131 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
132 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
,
135 5, 0, 5, 5, 5, 10, 1, 15,
143 {FXMESA_COLORDEPTH
, 15,
144 FXMESA_ALPHA_SIZE
, 1,
145 FXMESA_DEPTH_SIZE
, 16,
146 FXMESA_STENCIL_SIZE
, 0,
147 FXMESA_ACCUM_SIZE
, 0,
151 /* 16bit ARGB1555 double buffer with depth */
153 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
154 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
|
155 PFD_DOUBLEBUFFER
| PFD_SWAP_COPY
,
158 5, 0, 5, 5, 5, 10, 1, 15,
166 {FXMESA_COLORDEPTH
, 15,
168 FXMESA_ALPHA_SIZE
, 1,
169 FXMESA_DEPTH_SIZE
, 16,
170 FXMESA_STENCIL_SIZE
, 0,
171 FXMESA_ACCUM_SIZE
, 0,
175 /* 32bit ARGB8888 single buffer with depth */
177 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
178 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
,
181 8, 0, 8, 8, 8, 16, 8, 24,
189 {FXMESA_COLORDEPTH
, 32,
190 FXMESA_ALPHA_SIZE
, 8,
191 FXMESA_DEPTH_SIZE
, 24,
192 FXMESA_STENCIL_SIZE
, 8,
193 FXMESA_ACCUM_SIZE
, 0,
197 /* 32bit ARGB8888 double buffer with depth */
199 {sizeof(PIXELFORMATDESCRIPTOR
), 1,
200 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
|
201 PFD_DOUBLEBUFFER
| PFD_SWAP_COPY
,
204 8, 0, 8, 8, 8, 16, 8, 24,
212 {FXMESA_COLORDEPTH
, 32,
214 FXMESA_ALPHA_SIZE
, 8,
215 FXMESA_DEPTH_SIZE
, 24,
216 FXMESA_STENCIL_SIZE
, 8,
217 FXMESA_ACCUM_SIZE
, 0,
222 static fxMesaContext ctx
= NULL
;
223 static WNDPROC hWNDOldProc
;
224 static int curPFD
= 0;
228 static GLboolean haveDualHead
;
230 /* For the in-window-rendering hack */
232 #ifndef GR_CONTROL_RESIZE
233 /* Apparently GR_CONTROL_RESIZE can be ignored. OK? */
234 #define GR_CONTROL_RESIZE -1
237 static GLboolean gdiWindowHack
;
238 static void *dibSurfacePtr
;
239 static BITMAPINFO
*dibBMI
;
240 static HBITMAP dibHBM
;
243 static int env_check (const char *var
, int val
)
245 const char *env
= getenv(var
);
246 return (env
&& (env
[0] == val
));
249 static LRESULT APIENTRY
250 __wglMonitor(HWND hwnd
, UINT message
, UINT wParam
, LONG lParam
)
252 long ret
; /* Now gives the resized window at the end to hWNDOldProc */
254 if (ctx
&& hwnd
== hWND
) {
259 case WM_DISPLAYCHANGE
:
262 if (wParam
!= SIZE_MINIMIZED
) {
263 static int moving
= 0;
265 if (!FX_grSstControl(GR_CONTROL_RESIZE
)) {
267 SetWindowPos(hwnd
, 0, 0, 0, 300, 300, SWP_NOMOVE
| SWP_NOZORDER
);
269 if (!FX_grSstControl(GR_CONTROL_RESIZE
)) {
270 /*MessageBox(0,_T("Error changing windowsize"),_T("fxMESA"),MB_OK); */
271 PostMessage(hWND
, WM_CLOSE
, 0, 0);
274 /* Do the clipping in the glide library */
275 grClipWindow(0, 0, FX_grSstScreenWidth(), FX_grSstScreenHeight());
276 /* And let the new size set in the context */
277 fxMesaUpdateScreenSize(ctx
);
292 /* Finaly call the hWNDOldProc, which handles the resize witch the
293 now changed window sizes */
294 ret
= CallWindowProc(hWNDOldProc
, hwnd
, message
, wParam
, lParam
);
299 static void wgl_error (long error
)
301 #define WGL_INVALID_PIXELFORMAT ERROR_INVALID_PIXEL_FORMAT
302 SetLastError(0xC0000000 /* error severity */
303 |0x00070000 /* error facility (who we are) */
307 GLAPI BOOL GLAPIENTRY
308 wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
313 GLAPI HGLRC GLAPIENTRY
314 wglCreateContext(HDC hdc
)
325 if (!(hWnd
= WindowFromDC(hdc
))) {
331 wgl_error(WGL_INVALID_PIXELFORMAT
);
335 if ((oldProc
= (WNDPROC
) GetWindowLong(hWnd
, GWL_WNDPROC
)) != __wglMonitor
) {
336 hWNDOldProc
= oldProc
;
337 SetWindowLong(hWnd
, GWL_WNDPROC
, (LONG
) __wglMonitor
);
340 /* always log when debugging, or if user demands */
341 if (TDFX_DEBUG
|| env_check("MESA_FX_INFO", 'r')) {
342 freopen("MESA.LOG", "w", stderr
);
347 ShowWindow(hWnd
, SW_SHOWNORMAL
);
348 SetForegroundWindow(hWnd
);
349 Sleep(100); /* a hack for win95 */
350 if (env_check("MESA_GLX_FX", 'w') && !(GetWindowLong (hWnd
, GWL_STYLE
) & WS_POPUP
)) {
351 /* [dBorca] Hack alert: unfinished business! */
352 error
= !(ctx
= fxMesaCreateContext((GLuint
) hWnd
, GR_RESOLUTION_NONE
, GR_REFRESH_NONE
, pix
[curPFD
- 1].mesaAttr
));
354 GetClientRect(hWnd
, &cliRect
);
355 error
= !(ctx
= fxMesaCreateBestContext((GLuint
) hWnd
, cliRect
.right
, cliRect
.bottom
, pix
[curPFD
- 1].mesaAttr
));
359 /*if (getenv("SST_DUALHEAD"))
361 ((atoi(getenv("SST_DUALHEAD")) == 1) ? GL_TRUE : GL_FALSE);
363 haveDualHead = GL_FALSE;*/
373 /* Required by the OpenGL Optimizer 1.1 (is it a Optimizer bug ?) */
374 wglMakeCurrent(hdc
, (HGLRC
) 1);
379 GLAPI HGLRC GLAPIENTRY
380 wglCreateLayerContext(HDC hdc
, int iLayerPlane
)
386 GLAPI BOOL GLAPIENTRY
387 wglDeleteContext(HGLRC hglrc
)
389 if (ctx
&& hglrc
== (HGLRC
) 1) {
391 fxMesaDestroyContext(ctx
);
393 SetWindowLong(WindowFromDC(hDC
), GWL_WNDPROC
, (LONG
) hWNDOldProc
);
405 GLAPI HGLRC GLAPIENTRY
406 wglGetCurrentContext(VOID
)
416 wglGetCurrentDC(VOID
)
425 GLAPI BOOL GLAPIENTRY
426 wglSwapIntervalEXT (int interval
)
433 } else if (interval
> 3) {
436 ctx
->swapInterval
= interval
;
441 wglGetSwapIntervalEXT (void)
443 return (ctx
== NULL
) ? -1 : ctx
->swapInterval
;
446 GLAPI BOOL GLAPIENTRY
447 wglGetDeviceGammaRamp3DFX (HDC hdc
, LPVOID arrays
)
449 /* gammaTable should be per-context */
450 memcpy(arrays
, gammaTable
, 3*256*sizeof(GLushort
));
454 GLAPI BOOL GLAPIENTRY
455 wglSetDeviceGammaRamp3DFX (HDC hdc
, LPVOID arrays
)
457 GLint i
, tableSize
, inc
, index
;
458 GLushort
*red
, *green
, *blue
;
459 FxU32 gammaTableR
[256], gammaTableG
[256], gammaTableB
[256];
461 /* gammaTable should be per-context */
462 memcpy(gammaTable
, arrays
, 3*256*sizeof(GLushort
));
464 tableSize
= FX_grGetInteger(GR_GAMMA_TABLE_ENTRIES
);
465 inc
= 256 / tableSize
;
466 red
= (GLushort
*)arrays
;
467 green
= (GLushort
*)arrays
+ 256;
468 blue
= (GLushort
*)arrays
+ 512;
469 for (i
= 0, index
= 0; i
< tableSize
; i
++, index
+= inc
) {
470 gammaTableR
[i
] = red
[index
] >> 8;
471 gammaTableG
[i
] = green
[index
] >> 8;
472 gammaTableB
[i
] = blue
[index
] >> 8;
475 grLoadGammaTable(tableSize
, gammaTableR
, gammaTableG
, gammaTableB
);
480 typedef void *HPBUFFERARB
;
482 /* WGL_ARB_pixel_format */
483 GLAPI BOOL GLAPIENTRY
484 wglGetPixelFormatAttribivARB (HDC hdc
,
488 const int *piAttributes
,
495 GLAPI BOOL GLAPIENTRY
496 wglGetPixelFormatAttribfvARB (HDC hdc
,
500 const int *piAttributes
,
507 GLAPI BOOL GLAPIENTRY
508 wglChoosePixelFormatARB (HDC hdc
,
509 const int *piAttribIList
,
510 const FLOAT
*pfAttribFList
,
519 /* WGL_ARB_render_texture */
520 GLAPI BOOL GLAPIENTRY
521 wglBindTexImageARB (HPBUFFERARB hPbuffer
, int iBuffer
)
527 GLAPI BOOL GLAPIENTRY
528 wglReleaseTexImageARB (HPBUFFERARB hPbuffer
, int iBuffer
)
534 GLAPI BOOL GLAPIENTRY
535 wglSetPbufferAttribARB (HPBUFFERARB hPbuffer
,
536 const int *piAttribList
)
542 /* WGL_ARB_pbuffer */
543 GLAPI HPBUFFERARB GLAPIENTRY
544 wglCreatePbufferARB (HDC hDC
,
548 const int *piAttribList
)
555 wglGetPbufferDCARB (HPBUFFERARB hPbuffer
)
562 wglReleasePbufferDCARB (HPBUFFERARB hPbuffer
, HDC hDC
)
568 GLAPI BOOL GLAPIENTRY
569 wglDestroyPbufferARB (HPBUFFERARB hPbuffer
)
575 GLAPI BOOL GLAPIENTRY
576 wglQueryPbufferARB (HPBUFFERARB hPbuffer
,
584 GLAPI
const char * GLAPIENTRY
585 wglGetExtensionsStringEXT (void)
587 return "WGL_3DFX_gamma_control "
588 "WGL_EXT_swap_control "
589 "WGL_EXT_extensions_string WGL_ARB_extensions_string"
590 /*WGL_ARB_pixel_format WGL_ARB_render_texture WGL_ARB_pbuffer*/;
593 GLAPI
const char * GLAPIENTRY
594 wglGetExtensionsStringARB (HDC hdc
)
596 return wglGetExtensionsStringEXT();
603 {"wglGetExtensionsStringARB", wglGetExtensionsStringARB
},
604 {"wglGetExtensionsStringEXT", wglGetExtensionsStringEXT
},
605 {"wglSwapIntervalEXT", wglSwapIntervalEXT
},
606 {"wglGetSwapIntervalEXT", wglGetSwapIntervalEXT
},
607 {"wglGetDeviceGammaRamp3DFX", wglGetDeviceGammaRamp3DFX
},
608 {"wglSetDeviceGammaRamp3DFX", wglSetDeviceGammaRamp3DFX
},
609 /* WGL_ARB_pixel_format */
610 {"wglGetPixelFormatAttribivARB", wglGetPixelFormatAttribivARB
},
611 {"wglGetPixelFormatAttribfvARB", wglGetPixelFormatAttribfvARB
},
612 {"wglChoosePixelFormatARB", wglChoosePixelFormatARB
},
613 /* WGL_ARB_render_texture */
614 {"wglBindTexImageARB", wglBindTexImageARB
},
615 {"wglReleaseTexImageARB", wglReleaseTexImageARB
},
616 {"wglSetPbufferAttribARB", wglSetPbufferAttribARB
},
617 /* WGL_ARB_pbuffer */
618 {"wglCreatePbufferARB", wglCreatePbufferARB
},
619 {"wglGetPbufferDCARB", wglGetPbufferDCARB
},
620 {"wglReleasePbufferDCARB", wglReleasePbufferDCARB
},
621 {"wglDestroyPbufferARB", wglDestroyPbufferARB
},
622 {"wglQueryPbufferARB", wglQueryPbufferARB
},
626 GLAPI PROC GLAPIENTRY
627 wglGetProcAddress(LPCSTR lpszProc
)
630 PROC p
= (PROC
) _glapi_get_proc_address((const char *) lpszProc
);
632 /* [dBorca] we can't do BlendColor */
633 if (p
&& strcmp(lpszProc
, "glBlendColor") && 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
) {
813 static int pfd_tablen (void)
815 /* we should take an envvar for `fxMesaSelectCurrentBoard' */
816 return (fxMesaSelectCurrentBoard(0) < GR_SSTTYPE_Voodoo4
)
817 ? 2 /* only 16bit entries */
818 : sizeof(pix
) / sizeof(pix
[0]); /* full table */
822 wglChoosePixelFormat(HDC hdc
, const PIXELFORMATDESCRIPTOR
* ppfd
)
824 int i
, best
= -1, qt_valid_pix
;
825 PIXELFORMATDESCRIPTOR pfd
= *ppfd
;
827 qt_valid_pix
= pfd_tablen();
829 #if 1 || QUAKE2 || GORE
832 if ((pfd
.cColorBits
== 24) || (pfd
.cColorBits
== 32)) {
833 /* the first 2 entries are 16bit */
834 pfd
.cColorBits
= (qt_valid_pix
> 2) ? 32 : 16;
836 if (pfd
.cColorBits
== 32) {
838 } else if (pfd
.cColorBits
== 16) {
843 if (pfd
.nSize
!= sizeof(PIXELFORMATDESCRIPTOR
) || pfd
.nVersion
!= 1) {
848 for (i
= 0; i
< qt_valid_pix
; i
++) {
849 if (pfd
.cColorBits
> 0 && pix
[i
].pfd
.cColorBits
!= pfd
.cColorBits
)
852 if ((pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
)
853 && !(pix
[i
].pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
)) continue;
854 if ((pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
)
855 && !(pix
[i
].pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
)) continue;
856 if ((pfd
.dwFlags
& PFD_SUPPORT_GDI
)
857 && !(pix
[i
].pfd
.dwFlags
& PFD_SUPPORT_GDI
)) continue;
858 if ((pfd
.dwFlags
& PFD_SUPPORT_OPENGL
)
859 && !(pix
[i
].pfd
.dwFlags
& PFD_SUPPORT_OPENGL
)) continue;
860 if (!(pfd
.dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
)
861 && ((pfd
.dwFlags
& PFD_DOUBLEBUFFER
) !=
862 (pix
[i
].pfd
.dwFlags
& PFD_DOUBLEBUFFER
))) continue;
863 if (!(pfd
.dwFlags
& PFD_STEREO_DONTCARE
)
864 && ((pfd
.dwFlags
& PFD_STEREO
) !=
865 (pix
[i
].pfd
.dwFlags
& PFD_STEREO
))) continue;
867 if (pfd
.cDepthBits
> 0 && pix
[i
].pfd
.cDepthBits
== 0)
868 continue; /* need depth buffer */
870 if (pfd
.cAlphaBits
> 0 && pix
[i
].pfd
.cAlphaBits
== 0)
871 continue; /* need alpha buffer */
873 #if 0 /* [dBorca] regression bug? */
874 if (pfd
.cStencilBits
> 0 && pix
[i
].pfd
.cStencilBits
== 0)
875 continue; /* need stencil buffer */
878 if (pfd
.iPixelType
== pix
[i
].pfd
.iPixelType
) {
885 FILE *err
= fopen("MESA.LOG", "w");
887 fprintf(err
, "wglChoosePixelFormat failed\n");
888 fprintf(err
, "\tnSize = %d\n", ppfd
->nSize
);
889 fprintf(err
, "\tnVersion = %d\n", ppfd
->nVersion
);
890 fprintf(err
, "\tdwFlags = %d\n", ppfd
->dwFlags
);
891 fprintf(err
, "\tiPixelType = %d\n", ppfd
->iPixelType
);
892 fprintf(err
, "\tcColorBits = %d\n", ppfd
->cColorBits
);
893 fprintf(err
, "\tcRedBits = %d\n", ppfd
->cRedBits
);
894 fprintf(err
, "\tcRedShift = %d\n", ppfd
->cRedShift
);
895 fprintf(err
, "\tcGreenBits = %d\n", ppfd
->cGreenBits
);
896 fprintf(err
, "\tcGreenShift = %d\n", ppfd
->cGreenShift
);
897 fprintf(err
, "\tcBlueBits = %d\n", ppfd
->cBlueBits
);
898 fprintf(err
, "\tcBlueShift = %d\n", ppfd
->cBlueShift
);
899 fprintf(err
, "\tcAlphaBits = %d\n", ppfd
->cAlphaBits
);
900 fprintf(err
, "\tcAlphaShift = %d\n", ppfd
->cAlphaShift
);
901 fprintf(err
, "\tcAccumBits = %d\n", ppfd
->cAccumBits
);
902 fprintf(err
, "\tcAccumRedBits = %d\n", ppfd
->cAccumRedBits
);
903 fprintf(err
, "\tcAccumGreenBits = %d\n", ppfd
->cAccumGreenBits
);
904 fprintf(err
, "\tcAccumBlueBits = %d\n", ppfd
->cAccumBlueBits
);
905 fprintf(err
, "\tcAccumAlphaBits = %d\n", ppfd
->cAccumAlphaBits
);
906 fprintf(err
, "\tcDepthBits = %d\n", ppfd
->cDepthBits
);
907 fprintf(err
, "\tcStencilBits = %d\n", ppfd
->cStencilBits
);
908 fprintf(err
, "\tcAuxBuffers = %d\n", ppfd
->cAuxBuffers
);
909 fprintf(err
, "\tiLayerType = %d\n", ppfd
->iLayerType
);
910 fprintf(err
, "\tbReserved = %d\n", ppfd
->bReserved
);
911 fprintf(err
, "\tdwLayerMask = %d\n", ppfd
->dwLayerMask
);
912 fprintf(err
, "\tdwVisibleMask = %d\n", ppfd
->dwVisibleMask
);
913 fprintf(err
, "\tdwDamageMask = %d\n", ppfd
->dwDamageMask
);
925 ChoosePixelFormat(HDC hdc
, const PIXELFORMATDESCRIPTOR
* ppfd
)
928 return wglChoosePixelFormat(hdc
, ppfd
);
932 wglDescribePixelFormat(HDC hdc
, int iPixelFormat
, UINT nBytes
,
933 LPPIXELFORMATDESCRIPTOR ppfd
)
937 qt_valid_pix
= pfd_tablen();
939 if (iPixelFormat
< 1 || iPixelFormat
> qt_valid_pix
||
940 ((nBytes
!= sizeof(PIXELFORMATDESCRIPTOR
)) && (nBytes
!= 0))) {
942 return (qt_valid_pix
);
946 *ppfd
= pix
[iPixelFormat
- 1].pfd
;
948 return (qt_valid_pix
);
952 DescribePixelFormat(HDC hdc
, int iPixelFormat
, UINT nBytes
,
953 LPPIXELFORMATDESCRIPTOR ppfd
)
955 return wglDescribePixelFormat(hdc
, iPixelFormat
, nBytes
, ppfd
);
959 wglGetPixelFormat(HDC hdc
)
970 GetPixelFormat(HDC hdc
)
972 return wglGetPixelFormat(hdc
);
975 GLAPI BOOL GLAPIENTRY
976 wglSetPixelFormat(HDC hdc
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
* ppfd
)
980 qt_valid_pix
= pfd_tablen();
982 if (iPixelFormat
< 1 || iPixelFormat
> qt_valid_pix
) {
984 PIXELFORMATDESCRIPTOR my_pfd
;
985 if (!wglDescribePixelFormat(hdc
, iPixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &my_pfd
)) {
989 } else if (ppfd
->nSize
!= sizeof(PIXELFORMATDESCRIPTOR
)) {
994 curPFD
= iPixelFormat
;
999 GLAPI BOOL GLAPIENTRY
1000 wglSwapBuffers(HDC hdc
)
1007 fxMesaSwapBuffers();
1012 GLAPI BOOL GLAPIENTRY
1013 SetPixelFormat(HDC hdc
, int iPixelFormat
, const PIXELFORMATDESCRIPTOR
* ppfd
)
1015 return wglSetPixelFormat(hdc
, iPixelFormat
, ppfd
);
1018 GLAPI BOOL GLAPIENTRY
1019 SwapBuffers(HDC hdc
)
1021 return wglSwapBuffers(hdc
);
1024 static FIXED
FixedFromDouble(double d
)
1026 long l
= (long) (d
* 65536L);
1027 return *(FIXED
*)&l
;
1031 ** This was yanked from windows/gdi/wgl.c
1033 GLAPI BOOL GLAPIENTRY
1034 wglUseFontBitmapsA(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
)
1052 font_list
= listBase
;
1054 mat
.eM11
= FixedFromDouble(1);
1055 mat
.eM12
= FixedFromDouble(0);
1056 mat
.eM21
= FixedFromDouble(0);
1057 mat
.eM22
= FixedFromDouble(-1);
1059 memset(&gm
,0,sizeof(gm
));
1062 ** If we can't get the glyph outline, it may be because this is a fixed
1063 ** font. Try processing it that way.
1065 if( GetGlyphOutline(hdc
, first
, GGO_BITMAP
, &gm
, 0, NULL
, &mat
)
1068 return wglUseFontBitmaps_FX( hdc
, first
, count
, listBase
);
1072 ** Otherwise process all desired characters.
1074 for (i
= 0; i
< count
; i
++)
1078 glNewList( font_list
+i
, GL_COMPILE
);
1080 /* allocate space for the bitmap/outline */
1081 size
= GetGlyphOutline(hdc
, first
+ i
, GGO_BITMAP
, &gm
, 0, NULL
, &mat
);
1082 if (size
== GDI_ERROR
)
1085 err
= GetLastError();
1090 hBits
= GlobalAlloc(GHND
, size
+1);
1091 lpBits
= GlobalLock(hBits
);
1093 err
= GetGlyphOutline(hdc
, /* handle to device context */
1094 first
+ i
, /* character to query */
1095 GGO_BITMAP
, /* format of data to return */
1096 &gm
, /* pointer to structure for metrics*/
1097 size
, /* size of buffer for data */
1098 lpBits
, /* pointer to buffer for data */
1099 &mat
/* pointer to transformation */
1100 /* matrix structure */
1103 if (err
== GDI_ERROR
)
1105 GlobalUnlock(hBits
);
1109 err
= GetLastError();
1114 glBitmap(gm
.gmBlackBoxX
,gm
.gmBlackBoxY
,
1115 -gm
.gmptGlyphOrigin
.x
,
1116 gm
.gmptGlyphOrigin
.y
,
1117 gm
.gmCellIncX
,gm
.gmCellIncY
,
1118 (const GLubyte
* )lpBits
);
1120 GlobalUnlock(hBits
);
1129 GLAPI BOOL GLAPIENTRY
1130 wglDescribeLayerPlane(HDC hdc
, int iPixelFormat
, int iLayerPlane
,
1131 UINT nBytes
, LPLAYERPLANEDESCRIPTOR ppfd
)
1137 GLAPI
int GLAPIENTRY
1138 wglGetLayerPaletteEntries(HDC hdc
, int iLayerPlane
, int iStart
,
1139 int cEntries
, COLORREF
*pcr
)
1145 GLAPI BOOL GLAPIENTRY
1146 wglRealizeLayerPalette(HDC hdc
,int iLayerPlane
,BOOL bRealize
)
1152 GLAPI
int GLAPIENTRY
1153 wglSetLayerPaletteEntries(HDC hdc
,int iLayerPlane
, int iStart
,
1154 int cEntries
, CONST COLORREF
*pcr
)
1160 #if (_MSC_VER >= 1200)
1161 #pragma warning( pop )