DOS and glide driver updates from Daniel Borca
[mesa.git] / src / mesa / drivers / glide / fxwgl.c
1 /* $Id: fxwgl.c,v 1.17 2003/08/19 15:52:53 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.0
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 /* Authors:
28 * David Bucciarelli
29 * Brian Paul
30 * Keith Whitwell
31 */
32
33 /* fxwgl.c - Microsoft wgl functions emulation for
34 * 3Dfx VooDoo/Mesa interface
35 */
36
37
38 #ifdef __WIN32__
39
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44
45 #include <windows.h>
46 #define GL_GLEXT_PROTOTYPES
47 #include "GL/gl.h"
48 #include "GL/glext.h"
49
50 #ifdef __cplusplus
51 }
52 #endif
53
54 #include <stdio.h>
55 #include "GL/fxmesa.h"
56 #include "glheader.h"
57 #include "fxdrv.h"
58 #include "glapi.h"
59
60 #define MAX_MESA_ATTRS 20
61
62 struct __extensions__
63 {
64 PROC proc;
65 char *name;
66 };
67
68 struct __pixelformat__
69 {
70 PIXELFORMATDESCRIPTOR pfd;
71 GLint mesaAttr[MAX_MESA_ATTRS];
72 };
73
74 WINGDIAPI void GLAPIENTRY gl3DfxSetPaletteEXT(GLuint *);
75
76 struct __pixelformat__ pix[] = {
77 #if 0
78 /* None */
79 {
80 {
81 sizeof(PIXELFORMATDESCRIPTOR), 1,
82 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
83 PFD_DOUBLEBUFFER | PFD_SWAP_COPY,
84 PFD_TYPE_RGBA,
85 16,
86 5, 11, 6, 5, 5, 0, 0, 0,
87 0, 0, 0, 0, 0,
88 0,
89 0,
90 0,
91 PFD_MAIN_PLANE,
92 0, 0, 0, 0}
93 ,
94 {
95 FXMESA_COLORDEPTH, 16,
96 FXMESA_DOUBLEBUFFER,
97 FXMESA_ALPHA_SIZE, 0,
98 FXMESA_DEPTH_SIZE, 0,
99 FXMESA_STENCIL_SIZE, 0,
100 FXMESA_ACCUM_SIZE, 0,
101 FXMESA_NONE}
102 }
103 ,
104
105 /* Alpha */
106 {
107 {
108 sizeof(PIXELFORMATDESCRIPTOR), 1,
109 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
110 PFD_DOUBLEBUFFER | PFD_SWAP_COPY,
111 PFD_TYPE_RGBA,
112 16,
113 5, 10, 5, 5, 5, 0, 1, 15,
114 0, 0, 0, 0, 0,
115 0,
116 0,
117 0,
118 PFD_MAIN_PLANE,
119 0, 0, 0, 0}
120 ,
121 {
122 FXMESA_COLORDEPTH, 15,
123 FXMESA_DOUBLEBUFFER,
124 FXMESA_ALPHA_SIZE, 1,
125 FXMESA_DEPTH_SIZE, 0,
126 FXMESA_STENCIL_SIZE, 0,
127 FXMESA_ACCUM_SIZE, 0,
128 FXMESA_NONE}
129 }
130 ,
131
132 /* Depth */
133 {
134 {
135 sizeof(PIXELFORMATDESCRIPTOR), 1,
136 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
137 PFD_DOUBLEBUFFER | PFD_SWAP_COPY,
138 PFD_TYPE_RGBA,
139 16,
140 5, 11, 6, 5, 5, 0, 0, 0,
141 0, 0, 0, 0, 0,
142 16,
143 0,
144 0,
145 PFD_MAIN_PLANE,
146 0, 0, 0, 0}
147 ,
148 {
149 FXMESA_COLORDEPTH, 16,
150 FXMESA_DOUBLEBUFFER,
151 FXMESA_ALPHA_SIZE, 0,
152 FXMESA_DEPTH_SIZE, 16,
153 FXMESA_STENCIL_SIZE, 0,
154 FXMESA_ACCUM_SIZE, 0,
155 FXMESA_NONE}
156 }
157 ,
158
159 /* None */
160 {
161 {
162 sizeof(PIXELFORMATDESCRIPTOR), 1,
163 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
164 PFD_DOUBLEBUFFER | PFD_SWAP_COPY,
165 PFD_TYPE_RGBA,
166 32,
167 8, 16, 8, 8, 8, 0, 0, 0,
168 0, 0, 0, 0, 0,
169 0,
170 0,
171 0,
172 PFD_MAIN_PLANE,
173 0, 0, 0, 0}
174 ,
175 {
176 FXMESA_COLORDEPTH, 32,
177 FXMESA_DOUBLEBUFFER,
178 FXMESA_ALPHA_SIZE, 0,
179 FXMESA_DEPTH_SIZE, 0,
180 FXMESA_STENCIL_SIZE, 0,
181 FXMESA_ACCUM_SIZE, 0,
182 FXMESA_NONE}
183 }
184 ,
185
186 /* Alpha */
187 {
188 {
189 sizeof(PIXELFORMATDESCRIPTOR), 1,
190 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
191 PFD_DOUBLEBUFFER | PFD_SWAP_COPY,
192 PFD_TYPE_RGBA,
193 32,
194 8, 16, 8, 8, 8, 0, 8, 24,
195 0, 0, 0, 0, 0,
196 0,
197 0,
198 0,
199 PFD_MAIN_PLANE,
200 0, 0, 0, 0}
201 ,
202 {
203 FXMESA_COLORDEPTH, 32,
204 FXMESA_DOUBLEBUFFER,
205 FXMESA_ALPHA_SIZE, 8,
206 FXMESA_DEPTH_SIZE, 0,
207 FXMESA_STENCIL_SIZE, 0,
208 FXMESA_ACCUM_SIZE, 0,
209 FXMESA_NONE}
210 }
211 ,
212
213 /* Depth */
214 {
215 {
216 sizeof(PIXELFORMATDESCRIPTOR), 1,
217 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
218 PFD_DOUBLEBUFFER | PFD_SWAP_COPY,
219 PFD_TYPE_RGBA,
220 32,
221 8, 16, 8, 8, 8, 0, 0, 0,
222 0, 0, 0, 0, 0,
223 16,
224 0,
225 0,
226 PFD_MAIN_PLANE,
227 0, 0, 0, 0}
228 ,
229 {
230 FXMESA_COLORDEPTH, 32,
231 FXMESA_DOUBLEBUFFER,
232 FXMESA_ALPHA_SIZE, 0,
233 FXMESA_DEPTH_SIZE, 16,
234 FXMESA_STENCIL_SIZE, 0,
235 FXMESA_ACCUM_SIZE, 0,
236 FXMESA_NONE}
237 }
238 #endif
239 /* 16bit RGB565 */
240 {
241 {sizeof(PIXELFORMATDESCRIPTOR), 1,
242 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
243 PFD_DOUBLEBUFFER | PFD_SWAP_COPY,
244 PFD_TYPE_RGBA,
245 16,
246 5, 11, 6, 5, 5, 0, 0, 0,
247 0, 0, 0, 0, 0,
248 16,
249 0,
250 0,
251 PFD_MAIN_PLANE,
252 0, 0, 0, 0}
253 ,
254 {FXMESA_COLORDEPTH, 16,
255 FXMESA_DOUBLEBUFFER,
256 FXMESA_ALPHA_SIZE, 0,
257 FXMESA_DEPTH_SIZE, 16,
258 FXMESA_STENCIL_SIZE, 0,
259 FXMESA_ACCUM_SIZE, 0,
260 FXMESA_NONE}
261 }
262 ,
263 /* 16bit ARGB1555 */
264 {
265 {sizeof(PIXELFORMATDESCRIPTOR), 1,
266 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
267 PFD_DOUBLEBUFFER | PFD_SWAP_COPY,
268 PFD_TYPE_RGBA,
269 16,
270 5, 10, 5, 5, 5, 0, 1, 15,
271 0, 0, 0, 0, 0,
272 16,
273 0,
274 0,
275 PFD_MAIN_PLANE,
276 0, 0, 0, 0}
277 ,
278 {FXMESA_COLORDEPTH, 15,
279 FXMESA_DOUBLEBUFFER,
280 FXMESA_ALPHA_SIZE, 1,
281 FXMESA_DEPTH_SIZE, 16,
282 FXMESA_STENCIL_SIZE, 0,
283 FXMESA_ACCUM_SIZE, 0,
284 FXMESA_NONE}
285 }
286 ,
287 /* 32bit ARGB8888 */
288 {
289 {sizeof(PIXELFORMATDESCRIPTOR), 1,
290 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
291 PFD_DOUBLEBUFFER | PFD_SWAP_COPY,
292 PFD_TYPE_RGBA,
293 32,
294 8, 16, 8, 8, 8, 0, 8, 24,
295 0, 0, 0, 0, 0,
296 24,
297 0,
298 0,
299 PFD_MAIN_PLANE,
300 0, 0, 0, 0}
301 ,
302 {FXMESA_COLORDEPTH, 32,
303 FXMESA_DOUBLEBUFFER,
304 FXMESA_ALPHA_SIZE, 8,
305 FXMESA_DEPTH_SIZE, 24,
306 FXMESA_STENCIL_SIZE, 0,
307 FXMESA_ACCUM_SIZE, 0,
308 FXMESA_NONE}
309 }
310 };
311 static int qt_pix = sizeof(pix) / sizeof(pix[0]);
312
313 static fxMesaContext ctx = NULL;
314 static WNDPROC hWNDOldProc;
315 static int curPFD = 0;
316 static HDC hDC;
317 static HWND hWND;
318
319 static GLboolean haveDualHead;
320
321 /* For the in-window-rendering hack */
322
323 #ifndef GR_CONTROL_RESIZE
324 /* Apparently GR_CONTROL_RESIZE can be ignored. OK? */
325 #define GR_CONTROL_RESIZE -1
326 #endif
327
328 static GLboolean gdiWindowHack;
329 static void *dibSurfacePtr;
330 static BITMAPINFO *dibBMI;
331 static HBITMAP dibHBM;
332 static HWND dibWnd;
333
334 LONG GLAPIENTRY
335 __wglMonitor(HWND hwnd, UINT message, UINT wParam, LONG lParam)
336 {
337 long ret; /* Now gives the resized window at the end to hWNDOldProc */
338
339 if (ctx && hwnd == hWND) {
340 switch (message) {
341 case WM_PAINT:
342 case WM_MOVE:
343 break;
344 case WM_DISPLAYCHANGE:
345 case WM_SIZE:
346 if (wParam != SIZE_MINIMIZED) {
347 static int moving = 0;
348 if (!moving) {
349 if (!FX_grSstControl(GR_CONTROL_RESIZE)) {
350 moving = 1;
351 SetWindowPos(hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE | SWP_NOZORDER);
352 moving = 0;
353 if (!FX_grSstControl(GR_CONTROL_RESIZE)) {
354 /*MessageBox(0,_T("Error changing windowsize"),_T("fxMESA"),MB_OK); */
355 PostMessage(hWND, WM_CLOSE, 0, 0);
356 }
357 }
358 /* Do the clipping in the glide library */
359 grClipWindow(0, 0, FX_grSstScreenWidth(), FX_grSstScreenHeight());
360 /* And let the new size set in the context */
361 fxMesaUpdateScreenSize(ctx);
362 }
363 }
364 break;
365 case WM_ACTIVATE:
366 break;
367 case WM_SHOWWINDOW:
368 break;
369 case WM_SYSKEYDOWN:
370 case WM_SYSCHAR:
371 break;
372 }
373 }
374
375 /* Finaly call the hWNDOldProc, which handles the resize witch the
376 now changed window sizes */
377 ret = CallWindowProc(hWNDOldProc, hwnd, message, wParam, lParam);
378
379 return (ret);
380 }
381
382 BOOL GLAPIENTRY
383 wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
384 {
385 return (FALSE);
386 }
387
388 HGLRC GLAPIENTRY
389 wglCreateContext(HDC hdc)
390 {
391 HWND hWnd;
392 WNDPROC oldProc;
393 int error;
394
395 if (ctx) {
396 SetLastError(0);
397 return (NULL);
398 }
399
400 if (!(hWnd = WindowFromDC(hdc))) {
401 SetLastError(0);
402 return (NULL);
403 }
404
405 if (curPFD == 0) {
406 SetLastError(0);
407 return (NULL);
408 }
409
410 if ((oldProc = (WNDPROC) GetWindowLong(hWnd, GWL_WNDPROC)) != __wglMonitor) {
411 hWNDOldProc = oldProc;
412 SetWindowLong(hWnd, GWL_WNDPROC, (LONG) __wglMonitor);
413 }
414
415 #ifndef FX_SILENT
416 freopen("MESA.LOG", "w", stderr);
417 #endif
418
419 {
420 RECT cliRect;
421 ShowWindow(hWnd, SW_SHOWNORMAL);
422 SetForegroundWindow(hWnd);
423 Sleep(100); /* a hack for win95 */
424 GetClientRect(hWnd, &cliRect);
425 error = !(ctx = fxMesaCreateBestContext((GLuint) hWnd, cliRect.right, cliRect.bottom, pix[curPFD - 1].mesaAttr));
426 }
427
428 if (getenv("SST_DUALHEAD"))
429 haveDualHead =
430 ((atoi(getenv("SST_DUALHEAD")) == 1) ? GL_TRUE : GL_FALSE);
431 else
432 haveDualHead = GL_FALSE;
433
434 if (error) {
435 SetLastError(0);
436 return (NULL);
437 }
438
439 hDC = hdc;
440 hWND = hWnd;
441
442 /* Required by the OpenGL Optimizer 1.1 (is it a Optimizer bug ?) */
443 wglMakeCurrent(hdc, (HGLRC) 1);
444
445 return ((HGLRC) 1);
446 }
447
448 HGLRC GLAPIENTRY
449 wglCreateLayerContext(HDC hdc, int iLayerPlane)
450 {
451 SetLastError(0);
452 return (NULL);
453 }
454
455 BOOL GLAPIENTRY
456 wglDeleteContext(HGLRC hglrc)
457 {
458 if (ctx && hglrc == (HGLRC) 1) {
459
460 fxMesaDestroyContext(ctx);
461
462 SetWindowLong(WindowFromDC(hDC), GWL_WNDPROC, (LONG) hWNDOldProc);
463
464 ctx = NULL;
465 hDC = 0;
466 return (TRUE);
467 }
468
469 SetLastError(0);
470
471 return (FALSE);
472 }
473
474 HGLRC GLAPIENTRY
475 wglGetCurrentContext(VOID)
476 {
477 if (ctx)
478 return ((HGLRC) 1);
479
480 SetLastError(0);
481 return (NULL);
482 }
483
484 HDC GLAPIENTRY
485 wglGetCurrentDC(VOID)
486 {
487 if (ctx)
488 return (hDC);
489
490 SetLastError(0);
491 return (NULL);
492 }
493
494 PROC GLAPIENTRY
495 wglGetProcAddress(LPCSTR lpszProc)
496 {
497 PROC p = (PROC) _glapi_get_proc_address((const char *) lpszProc);
498 if (p)
499 return p;
500
501 SetLastError(0);
502 return (NULL);
503 }
504
505 BOOL GLAPIENTRY
506 wglMakeCurrent(HDC hdc, HGLRC hglrc)
507 {
508 if ((hdc == NULL) && (hglrc == NULL))
509 return (TRUE);
510
511 if (!ctx || hglrc != (HGLRC) 1 || WindowFromDC(hdc) != hWND) {
512 SetLastError(0);
513 return (FALSE);
514 }
515
516 hDC = hdc;
517
518 fxMesaMakeCurrent(ctx);
519
520 return (TRUE);
521 }
522
523 BOOL GLAPIENTRY
524 wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
525 {
526 if (!ctx || hglrc1 != (HGLRC) 1 || hglrc1 != hglrc2) {
527 SetLastError(0);
528 return (FALSE);
529 }
530
531 return (TRUE);
532 }
533
534 BOOL GLAPIENTRY
535 wglUseFontBitmaps(HDC fontDevice, DWORD firstChar, DWORD numChars,
536 DWORD listBase)
537 {
538 #define VERIFY(a) a
539
540 TEXTMETRIC metric;
541 BITMAPINFO *dibInfo;
542 HDC bitDevice;
543 COLORREF tempColor;
544 int i;
545
546 VERIFY(GetTextMetrics(fontDevice, &metric));
547
548 dibInfo = (BITMAPINFO *) calloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD), 1);
549 dibInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
550 dibInfo->bmiHeader.biPlanes = 1;
551 dibInfo->bmiHeader.biBitCount = 1;
552 dibInfo->bmiHeader.biCompression = BI_RGB;
553
554 bitDevice = CreateCompatibleDC(fontDevice);
555 // HDC bitDevice = CreateDC("DISPLAY", NULL, NULL, NULL);
556 // VERIFY(bitDevice);
557
558 // Swap fore and back colors so the bitmap has the right polarity
559 tempColor = GetBkColor(bitDevice);
560 SetBkColor(bitDevice, GetTextColor(bitDevice));
561 SetTextColor(bitDevice, tempColor);
562
563 // Place chars based on base line
564 VERIFY(SetTextAlign(bitDevice, TA_BASELINE) >= 0 ? 1 : 0);
565
566 for (i = 0; i < (int)numChars; i++) {
567 SIZE size;
568 char curChar;
569 int charWidth, charHeight, bmapWidth, bmapHeight, numBytes, res;
570 HBITMAP bitObject;
571 HGDIOBJ origBmap;
572 unsigned char *bmap;
573
574 curChar = (char)(i + firstChar); // [koolsmoky] explicit cast
575
576 // Find how high/wide this character is
577 VERIFY(GetTextExtentPoint32(bitDevice, &curChar, 1, &size));
578
579 // Create the output bitmap
580 charWidth = size.cx;
581 charHeight = size.cy;
582 bmapWidth = ((charWidth + 31) / 32) * 32; // Round up to the next multiple of 32 bits
583 bmapHeight = charHeight;
584 bitObject = CreateCompatibleBitmap(bitDevice, bmapWidth, bmapHeight);
585 //VERIFY(bitObject);
586
587 // Assign the output bitmap to the device
588 origBmap = SelectObject(bitDevice, bitObject);
589 VERIFY(origBmap);
590
591 VERIFY(PatBlt(bitDevice, 0, 0, bmapWidth, bmapHeight, BLACKNESS));
592
593 // Use our source font on the device
594 VERIFY(SelectObject(bitDevice, GetCurrentObject(fontDevice, OBJ_FONT)));
595
596 // Draw the character
597 VERIFY(TextOut(bitDevice, 0, metric.tmAscent, &curChar, 1));
598
599 // Unselect our bmap object
600 VERIFY(SelectObject(bitDevice, origBmap));
601
602 // Convert the display dependant representation to a 1 bit deep DIB
603 numBytes = (bmapWidth * bmapHeight) / 8;
604 bmap = MALLOC(numBytes);
605 dibInfo->bmiHeader.biWidth = bmapWidth;
606 dibInfo->bmiHeader.biHeight = bmapHeight;
607 res = GetDIBits(bitDevice, bitObject, 0, bmapHeight, bmap,
608 dibInfo, DIB_RGB_COLORS);
609 //VERIFY(res);
610
611 // Create the GL object
612 glNewList(i + listBase, GL_COMPILE);
613 glBitmap(bmapWidth, bmapHeight, 0.0, metric.tmDescent,
614 charWidth, 0.0, bmap);
615 glEndList();
616 // CheckGL();
617
618 // Destroy the bmap object
619 DeleteObject(bitObject);
620
621 // Deallocate the bitmap data
622 FREE(bmap);
623 }
624
625 // Destroy the DC
626 VERIFY(DeleteDC(bitDevice));
627
628 FREE(dibInfo);
629
630 return TRUE;
631 #undef VERIFY
632 }
633
634 BOOL GLAPIENTRY
635 wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
636 {
637 return (FALSE);
638 }
639
640 BOOL GLAPIENTRY
641 wglUseFontOutlinesA(HDC hdc, DWORD first, DWORD count,
642 DWORD listBase, FLOAT deviation,
643 FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf)
644 {
645 SetLastError(0);
646 return (FALSE);
647 }
648
649 BOOL GLAPIENTRY
650 wglUseFontOutlinesW(HDC hdc, DWORD first, DWORD count,
651 DWORD listBase, FLOAT deviation,
652 FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf)
653 {
654 SetLastError(0);
655 return (FALSE);
656 }
657
658
659 BOOL GLAPIENTRY
660 wglSwapLayerBuffers(HDC hdc, UINT fuPlanes)
661 {
662 if (ctx && WindowFromDC(hdc) == hWND) {
663 fxMesaSwapBuffers();
664
665 return (TRUE);
666 }
667
668 SetLastError(0);
669 return (FALSE);
670 }
671
672 int GLAPIENTRY
673 wglChoosePixelFormat(HDC hdc, CONST PIXELFORMATDESCRIPTOR * ppfd)
674 {
675 int i, best = -1, qt_valid_pix;
676
677 qt_valid_pix = qt_pix;
678
679 if (ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR) || ppfd->nVersion != 1) {
680 SetLastError(0);
681 return (0);
682 }
683
684 for (i = 0; i < qt_valid_pix; i++) {
685 if (ppfd->cColorBits > 0 && pix[i].pfd.cColorBits != ppfd->cColorBits)
686 continue;
687
688 if ((ppfd->dwFlags & PFD_DRAW_TO_WINDOW)
689 && !(pix[i].pfd.dwFlags & PFD_DRAW_TO_WINDOW)) continue;
690 if ((ppfd->dwFlags & PFD_DRAW_TO_BITMAP)
691 && !(pix[i].pfd.dwFlags & PFD_DRAW_TO_BITMAP)) continue;
692 if ((ppfd->dwFlags & PFD_SUPPORT_GDI)
693 && !(pix[i].pfd.dwFlags & PFD_SUPPORT_GDI)) continue;
694 if ((ppfd->dwFlags & PFD_SUPPORT_OPENGL)
695 && !(pix[i].pfd.dwFlags & PFD_SUPPORT_OPENGL)) continue;
696 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE)
697 && ((ppfd->dwFlags & PFD_DOUBLEBUFFER) !=
698 (pix[i].pfd.dwFlags & PFD_DOUBLEBUFFER))) continue;
699 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE)
700 && ((ppfd->dwFlags & PFD_STEREO) !=
701 (pix[i].pfd.dwFlags & PFD_STEREO))) continue;
702
703 if (ppfd->cDepthBits > 0 && pix[i].pfd.cDepthBits == 0)
704 continue; /* need depth buffer */
705
706 if (ppfd->cAlphaBits > 0 && pix[i].pfd.cAlphaBits == 0)
707 continue; /* need alpha buffer */
708
709 if (ppfd->iPixelType == pix[i].pfd.iPixelType) {
710 best = i + 1;
711 break;
712 }
713 }
714
715 if (best == -1) {
716 SetLastError(0);
717 return (0);
718 }
719
720 return (best);
721 }
722
723 int GLAPIENTRY
724 ChoosePixelFormat(HDC hdc, CONST PIXELFORMATDESCRIPTOR * ppfd)
725 {
726 return wglChoosePixelFormat(hdc, ppfd);
727 }
728
729 int GLAPIENTRY
730 wglDescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes,
731 LPPIXELFORMATDESCRIPTOR ppfd)
732 {
733 int qt_valid_pix;
734
735 qt_valid_pix = qt_pix;
736
737 if (iPixelFormat < 1 || iPixelFormat > qt_valid_pix ||
738 ((nBytes != sizeof(PIXELFORMATDESCRIPTOR)) && (nBytes != 0))) {
739 SetLastError(0);
740 return (0);
741 }
742
743 if (nBytes != 0)
744 *ppfd = pix[iPixelFormat - 1].pfd;
745
746 return (qt_valid_pix);
747 }
748
749 int GLAPIENTRY
750 DescribePixelFormat(HDC hdc, int iPixelFormat, UINT nBytes,
751 LPPIXELFORMATDESCRIPTOR ppfd)
752 {
753 return wglDescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd);
754 }
755
756 int GLAPIENTRY
757 wglGetPixelFormat(HDC hdc)
758 {
759 if (curPFD == 0) {
760 SetLastError(0);
761 return (0);
762 }
763
764 return (curPFD);
765 }
766
767 int GLAPIENTRY
768 GetPixelFormat(HDC hdc)
769 {
770 return wglGetPixelFormat(hdc);
771 }
772
773 BOOL GLAPIENTRY
774 wglSetPixelFormat(HDC hdc, int iPixelFormat,
775 CONST PIXELFORMATDESCRIPTOR * ppfd)
776 {
777 int qt_valid_pix;
778
779 qt_valid_pix = qt_pix;
780
781 if (iPixelFormat < 1 || iPixelFormat > qt_valid_pix
782 || ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR)) {
783 SetLastError(0);
784 return (FALSE);
785 }
786 curPFD = iPixelFormat;
787
788 return (TRUE);
789 }
790
791 BOOL GLAPIENTRY
792 wglSwapBuffers(HDC hdc)
793 {
794 if (!ctx) {
795 SetLastError(0);
796 return (FALSE);
797 }
798
799 fxMesaSwapBuffers();
800
801 return (TRUE);
802 }
803
804 BOOL GLAPIENTRY
805 SetPixelFormat(HDC hdc, int iPixelFormat, CONST PIXELFORMATDESCRIPTOR * ppfd)
806 {
807 return wglSetPixelFormat(hdc, iPixelFormat, ppfd);
808 }
809
810 BOOL GLAPIENTRY
811 SwapBuffers(HDC hdc)
812 {
813 return wglSwapBuffers(hdc);
814 }
815
816 #endif /* FX */