Minor patches to cleanup some compiler warnings in MSVC
[mesa.git] / src / mesa / drivers / glide / fxwgl.c
1 /* fxwgl.c - Microsoft wgl functions emulation for
2 * 3Dfx VooDoo/Mesa interface
3 */
4
5 /*
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * See the file fxapi.c for more informations about authors
21 *
22 */
23
24 #ifdef __WIN32__
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <windows.h>
31 #include "GL/gl.h"
32
33 #ifdef __cplusplus
34 }
35 #endif
36
37 #include <stdio.h>
38 #include "GL/fxmesa.h"
39 #include "fxdrv.h"
40
41 #define MAX_MESA_ATTRS 20
42
43 struct __extensions__
44 {
45 PROC proc;
46 char *name;
47 };
48
49 struct __pixelformat__
50 {
51 PIXELFORMATDESCRIPTOR pfd;
52 GLint mesaAttr[MAX_MESA_ATTRS];
53 };
54
55 WINGDIAPI void GLAPIENTRY gl3DfxSetPaletteEXT(GLuint *);
56
57 static struct __extensions__ ext[] = {
58
59 #ifdef GL_EXT_polygon_offset
60 { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" },
61 #endif
62 { (PROC)glBlendEquationEXT, "glBlendEquationEXT" },
63 { (PROC)glBlendColorEXT, "glBlendColorExt" },
64 { (PROC)glVertexPointerEXT, "glVertexPointerEXT" },
65 { (PROC)glNormalPointerEXT, "glNormalPointerEXT" },
66 { (PROC)glColorPointerEXT, "glColorPointerEXT" },
67 { (PROC)glIndexPointerEXT, "glIndexPointerEXT" },
68 { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" },
69 { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" },
70 { (PROC)glGetPointervEXT, "glGetPointervEXT" },
71 { (PROC)glArrayElementEXT, "glArrayElementEXT" },
72 { (PROC)glDrawArraysEXT, "glDrawArrayEXT" },
73 { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" },
74 { (PROC)glBindTextureEXT, "glBindTextureEXT" },
75 { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" },
76 { (PROC)glGenTexturesEXT, "glGenTexturesEXT" },
77 { (PROC)glIsTextureEXT, "glIsTextureEXT" },
78 { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" },
79 { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" },
80 { (PROC)glTexImage3DEXT, "glTexImage3DEXT" },
81 { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" },
82 { (PROC)gl3DfxSetPaletteEXT, "3DFX_set_global_palette" },
83 { (PROC)glColorTableEXT, "glColorTableEXT" },
84 { (PROC)glColorSubTableEXT, "glColorSubTableEXT" },
85 { (PROC)glGetColorTableEXT, "glGetColorTableEXT" },
86 { (PROC)glGetColorTableParameterfvEXT, "glGetColorTableParameterfvEXT" },
87 { (PROC)glGetColorTableParameterivEXT, "glGetColorTableParameterivEXT" },
88 { (PROC)glPointParameterfEXT, "glPointParameterfEXT" },
89 { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" },
90 { (PROC)glBlendFuncSeparateINGR, "glBlendFuncSeparateINGR" },
91 { (PROC)glActiveTextureARB, "glActiveTextureARB" },
92 { (PROC)glClientActiveTextureARB, "glClientActiveTextureARB" },
93 { (PROC)glMultiTexCoord1dARB, "glMultiTexCoord1dARB" },
94 { (PROC)glMultiTexCoord1dvARB, "glMultiTexCoord1dvARB" },
95 { (PROC)glMultiTexCoord1fARB, "glMultiTexCoord1fARB" },
96 { (PROC)glMultiTexCoord1fvARB, "glMultiTexCoord1fvARB" },
97 { (PROC)glMultiTexCoord1iARB, "glMultiTexCoord1iARB" },
98 { (PROC)glMultiTexCoord1ivARB, "glMultiTexCoord1ivARB" },
99 { (PROC)glMultiTexCoord1sARB, "glMultiTexCoord1sARB" },
100 { (PROC)glMultiTexCoord1svARB, "glMultiTexCoord1svARB" },
101 { (PROC)glMultiTexCoord2dARB, "glMultiTexCoord2dARB" },
102 { (PROC)glMultiTexCoord2dvARB, "glMultiTexCoord2dvARB" },
103 { (PROC)glMultiTexCoord2fARB, "glMultiTexCoord2fARB" },
104 { (PROC)glMultiTexCoord2fvARB, "glMultiTexCoord2fvARB" },
105 { (PROC)glMultiTexCoord2iARB, "glMultiTexCoord2iARB" },
106 { (PROC)glMultiTexCoord2ivARB, "glMultiTexCoord2ivARB" },
107 { (PROC)glMultiTexCoord2sARB, "glMultiTexCoord2sARB" },
108 { (PROC)glMultiTexCoord2svARB, "glMultiTexCoord2svARB" },
109 { (PROC)glMultiTexCoord3dARB, "glMultiTexCoord3dARB" },
110 { (PROC)glMultiTexCoord3dvARB, "glMultiTexCoord3dvARB" },
111 { (PROC)glMultiTexCoord3fARB, "glMultiTexCoord3fARB" },
112 { (PROC)glMultiTexCoord3fvARB, "glMultiTexCoord3fvARB" },
113 { (PROC)glMultiTexCoord3iARB, "glMultiTexCoord3iARB" },
114 { (PROC)glMultiTexCoord3ivARB, "glMultiTexCoord3ivARB" },
115 { (PROC)glMultiTexCoord3sARB, "glMultiTexCoord3sARB" },
116 { (PROC)glMultiTexCoord3svARB, "glMultiTexCoord3svARB" },
117 { (PROC)glMultiTexCoord4dARB, "glMultiTexCoord4dARB" },
118 { (PROC)glMultiTexCoord4dvARB, "glMultiTexCoord4dvARB" },
119 { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4fARB" },
120 { (PROC)glMultiTexCoord4fvARB, "glMultiTexCoord4fvARB" },
121 { (PROC)glMultiTexCoord4iARB, "glMultiTexCoord4iARB" },
122 { (PROC)glMultiTexCoord4ivARB, "glMultiTexCoord4ivARB" },
123 { (PROC)glMultiTexCoord4sARB, "glMultiTexCoord4sARB" },
124 { (PROC)glMultiTexCoord4svARB, "glMultiTexCoord4svARB" },
125 { (PROC)glLockArraysEXT, "glLockArraysEXT" },
126 { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }
127 };
128
129 static int qt_ext = sizeof(ext) / sizeof(ext[0]);
130
131 struct __pixelformat__ pix[] =
132 {
133 /* None */
134 {
135 {
136 sizeof(PIXELFORMATDESCRIPTOR), 1,
137 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|
138 PFD_DOUBLEBUFFER|PFD_SWAP_COPY,
139 PFD_TYPE_RGBA,
140 32,
141 8,0,8,8,8,16,0,24,
142 0,0,0,0,0,
143 0,
144 0,
145 0,
146 PFD_MAIN_PLANE,
147 0,0,0,0
148 },
149 {
150 FXMESA_DOUBLEBUFFER,
151 FXMESA_ALPHA_SIZE, 0,
152 FXMESA_DEPTH_SIZE, 0,
153 FXMESA_STENCIL_SIZE, 0,
154 FXMESA_ACCUM_SIZE, 0,
155 FXMESA_NONE
156 }
157 },
158
159 /* Alpha */
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,0,8,8,8,16,8,24,
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_DOUBLEBUFFER,
177 FXMESA_ALPHA_SIZE, 8,
178 FXMESA_DEPTH_SIZE, 0,
179 FXMESA_STENCIL_SIZE, 0,
180 FXMESA_ACCUM_SIZE, 0,
181 FXMESA_NONE
182 }
183 },
184
185 /* Depth */
186 {
187 {
188 sizeof(PIXELFORMATDESCRIPTOR), 1,
189 PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|
190 PFD_DOUBLEBUFFER|PFD_SWAP_COPY,
191 PFD_TYPE_RGBA,
192 32,
193 8,0,8,8,8,16,0,24,
194 0,0,0,0,0,
195 16,
196 0,
197 0,
198 PFD_MAIN_PLANE,
199 0,0,0,0
200 },
201 {
202 FXMESA_DOUBLEBUFFER,
203 FXMESA_ALPHA_SIZE, 0,
204 FXMESA_DEPTH_SIZE, 16,
205 FXMESA_STENCIL_SIZE, 0,
206 FXMESA_ACCUM_SIZE, 0,
207 FXMESA_NONE
208 }
209 }
210 };
211 static int qt_pix = sizeof(pix) / sizeof(pix[0]);
212
213 static fxMesaContext ctx = NULL;
214 static WNDPROC hWNDOldProc;
215 static int curPFD = 0;
216 static HDC hDC;
217 static HWND hWND;
218
219 static GLboolean haveDualHead;
220
221 /* For the in-window-rendering hack */
222
223 static GLboolean gdiWindowHack;
224 static GLboolean gdiWindowHackEna;
225 static void *dibSurfacePtr;
226 static BITMAPINFO *dibBMI;
227 static HBITMAP dibHBM;
228 static HWND dibWnd;
229
230 LONG GLAPIENTRY __wglMonitor(HWND hwnd,UINT message,UINT wParam,LONG lParam)
231
232 {
233 long ret; /* Now gives the resized window at the end to hWNDOldProc */
234
235 if(ctx && hwnd == hWND) {
236 switch(message) {
237 case WM_PAINT:
238 case WM_MOVE:
239 break;
240 case WM_DISPLAYCHANGE:
241 case WM_SIZE:
242 if (wParam != SIZE_MINIMIZED) {
243 static int moving = 0;
244 if (!moving) {
245 if(fxQueryHardware()!=GR_SSTTYPE_VOODOO) {
246 if(!grSstControl(GR_CONTROL_RESIZE)) {
247 moving = 1;
248 SetWindowPos(hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOZORDER);
249 moving = 0;
250 if(!grSstControl(GR_CONTROL_RESIZE)) {
251 /*MessageBox(0,_T("Error changing windowsize"),_T("fxMESA"),MB_OK);*/
252 PostMessage(hWND,WM_CLOSE,0,0);
253 }
254 }
255 }
256
257 /* Do the clipping in the glide library */
258 grClipWindow(0,0,grSstScreenWidth(),grSstScreenHeight());
259 /* And let the new size set in the context */
260 fxMesaUpdateScreenSize(ctx);
261 }
262 }
263 break;
264 case WM_ACTIVATE:
265 if((fxQueryHardware()==GR_SSTTYPE_VOODOO) &&
266 (!gdiWindowHack) &&
267 (!haveDualHead)) {
268 WORD fActive = LOWORD(wParam);
269 BOOL fMinimized = (BOOL) HIWORD(wParam);
270
271 if((fActive == WA_INACTIVE) || fMinimized)
272 grSstControl(GR_CONTROL_DEACTIVATE);
273 else
274 grSstControl(GR_CONTROL_ACTIVATE);
275 }
276 break;
277 case WM_SHOWWINDOW:
278 break;
279 case WM_SYSCHAR:
280 if(gdiWindowHackEna && (VK_RETURN == wParam)) {
281 if(gdiWindowHack) {
282 gdiWindowHack = GL_FALSE;
283 grSstControl(GR_CONTROL_ACTIVATE);
284 } else {
285 gdiWindowHack = GL_TRUE;
286 grSstControl(GR_CONTROL_DEACTIVATE);
287 }
288 }
289 break;
290 }
291 }
292
293 /* Finaly call the hWNDOldProc, which handles the resize witch the
294 now changed window sizes */
295 ret = CallWindowProc( hWNDOldProc, hwnd, message, wParam, lParam );
296
297 return(ret);
298 }
299
300 BOOL GLAPIENTRY wglCopyContext(HGLRC hglrcSrc,HGLRC hglrcDst,UINT mask)
301 {
302 return(FALSE);
303 }
304
305 HGLRC GLAPIENTRY wglCreateContext(HDC hdc)
306 {
307 HWND hWnd;
308 WNDPROC oldProc;
309 int error;
310
311 if(ctx) {
312 SetLastError(0);
313 return(NULL);
314 }
315
316 if(!(hWnd = WindowFromDC(hdc))) {
317 SetLastError(0);
318 return(NULL);
319 }
320
321 if(curPFD == 0) {
322 SetLastError(0);
323 return(NULL);
324 }
325
326 if((oldProc = (WNDPROC)GetWindowLong(hWnd,GWL_WNDPROC)) != __wglMonitor) {
327 hWNDOldProc = oldProc;
328 SetWindowLong(hWnd,GWL_WNDPROC,(LONG)__wglMonitor);
329 }
330
331 #ifndef FX_SILENT
332 freopen("MESA.LOG","w",stderr);
333 #endif
334
335 ShowWindow(hWnd, SW_SHOWNORMAL);
336 SetForegroundWindow(hWnd);
337 Sleep(100); /* an hack for win95 */
338
339 if(fxQueryHardware() == GR_SSTTYPE_VOODOO) {
340 RECT cliRect;
341
342 GetClientRect(hWnd,&cliRect);
343 error = !(ctx = fxMesaCreateBestContext((GLuint)hWnd,cliRect.right,cliRect.bottom,
344 pix[curPFD - 1].mesaAttr));
345
346 if(!error) {
347 /* create the DIB section for windowed rendering */
348 DWORD *p;
349
350 dibWnd = hWnd;
351
352 hDC = GetDC(dibWnd);
353
354 dibBMI = (BITMAPINFO*) MALLOC( sizeof(BITMAPINFO) + (256*sizeof(RGBQUAD)));
355
356 memset(dibBMI,0,sizeof(BITMAPINFO) + (256*sizeof(RGBQUAD)));
357
358 dibBMI->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
359 dibBMI->bmiHeader.biWidth = ctx->width;
360 dibBMI->bmiHeader.biHeight = -ctx->height;
361 dibBMI->bmiHeader.biPlanes = (short)1;
362 dibBMI->bmiHeader.biBitCount = (short)16;
363 dibBMI->bmiHeader.biCompression = BI_BITFIELDS;
364 dibBMI->bmiHeader.biSizeImage = 0;
365 dibBMI->bmiHeader.biXPelsPerMeter = 0;
366 dibBMI->bmiHeader.biYPelsPerMeter = 0;
367 dibBMI->bmiHeader.biClrUsed = 3;
368 dibBMI->bmiHeader.biClrImportant = 3;
369
370 p = (DWORD*)dibBMI->bmiColors;
371 p[0] = 0xF800;
372 p[1] = 0x07E0;
373 p[2] = 0x001F;
374
375 dibHBM = CreateDIBSection(hDC, dibBMI, DIB_RGB_COLORS, &dibSurfacePtr, NULL, 0);
376
377 ReleaseDC(dibWnd, hDC);
378
379 gdiWindowHackEna = (dibHBM != NULL ? GL_TRUE : GL_FALSE);
380
381 if (!getenv("MESA_WGL_FX") || !strcmp(getenv("MESA_WGL_FX"),"fullscreen"))
382 gdiWindowHack = GL_FALSE;
383 else {
384 gdiWindowHack = GL_TRUE;
385 grSstControl(GR_CONTROL_DEACTIVATE);
386 }
387 }
388 } else {
389 /* For the Voodoo Rush */
390
391 if(getenv("MESA_WGL_FX") && !strcmp(getenv("MESA_WGL_FX"),"fullscreen")) {
392 RECT cliRect;
393
394 GetClientRect(hWnd,&cliRect);
395 error = !(ctx = fxMesaCreateBestContext((GLuint)hWnd,cliRect.right,cliRect.bottom,
396 pix[curPFD - 1].mesaAttr));
397 } else
398 error = !(ctx = fxMesaCreateContext((GLuint)hWnd,GR_RESOLUTION_NONE,GR_REFRESH_75Hz,
399 pix[curPFD - 1].mesaAttr));
400 }
401
402 if(getenv("SST_DUALHEAD"))
403 haveDualHead=((atoi(getenv("SST_DUALHEAD"))==1) ? GL_TRUE:GL_FALSE);
404 else
405 haveDualHead=GL_FALSE;
406
407 if(error) {
408 SetLastError(0);
409 return(NULL);
410 }
411
412 hDC = hdc;
413 hWND = hWnd;
414
415 /* Required by the OpenGL Optimizer 1.1 (is it a Optimizer bug ?) */
416 wglMakeCurrent(hdc,(HGLRC)1);
417
418 return((HGLRC)1);
419 }
420
421 HGLRC GLAPIENTRY wglCreateLayerContext(HDC hdc,int iLayerPlane)
422 {
423 SetLastError(0);
424 return(NULL);
425 }
426
427 BOOL GLAPIENTRY wglDeleteContext(HGLRC hglrc)
428 {
429 if(ctx && hglrc == (HGLRC)1) {
430 if (gdiWindowHackEna) {
431 DeleteObject(dibHBM);
432 FREE(dibBMI);
433
434 dibSurfacePtr = NULL;
435 dibBMI = NULL;
436 dibHBM = NULL;
437 dibWnd = NULL;
438 }
439
440 fxMesaDestroyContext(ctx);
441
442 SetWindowLong(WindowFromDC(hDC),GWL_WNDPROC,(LONG)hWNDOldProc);
443
444 ctx = NULL;
445 hDC = 0;
446 return(TRUE);
447 }
448
449 SetLastError(0);
450
451 return(FALSE);
452 }
453
454 HGLRC GLAPIENTRY wglGetCurrentContext(VOID)
455 {
456 if(ctx)
457 return((HGLRC)1);
458
459 SetLastError(0);
460 return(NULL);
461 }
462
463 HDC GLAPIENTRY wglGetCurrentDC(VOID)
464 {
465 if(ctx)
466 return(hDC);
467
468 SetLastError(0);
469 return(NULL);
470 }
471
472 PROC GLAPIENTRY wglGetProcAddress(LPCSTR lpszProc)
473 {
474 int i;
475
476 /*fprintf(stderr,"fxMesa: looking for extension %s\n",lpszProc);
477 fflush(stderr);*/
478
479 for(i = 0;i < qt_ext;i++)
480 if(!strcmp(lpszProc,ext[i].name)) {
481 /*fprintf(stderr,"fxMesa: found extension %s\n",lpszProc);
482 fflush(stderr);*/
483
484 return(ext[i].proc);
485 }
486 SetLastError(0);
487 return(NULL);
488 }
489
490 BOOL GLAPIENTRY wglMakeCurrent(HDC hdc,HGLRC hglrc)
491 {
492 if((hdc==NULL) && (hglrc==NULL))
493 return(TRUE);
494
495 if(!ctx || hglrc != (HGLRC)1 || WindowFromDC(hdc) != hWND) {
496 SetLastError(0);
497 return(FALSE);
498 }
499
500 hDC = hdc;
501
502 fxMesaMakeCurrent(ctx);
503
504 return(TRUE);
505 }
506
507 BOOL GLAPIENTRY wglShareLists(HGLRC hglrc1,HGLRC hglrc2)
508 {
509 if(!ctx || hglrc1 != (HGLRC)1 || hglrc1 != hglrc2) {
510 SetLastError(0);
511 return(FALSE);
512 }
513
514 return(TRUE);
515 }
516
517 BOOL GLAPIENTRY wglUseFontBitmaps(HDC fontDevice, DWORD firstChar, DWORD numChars, DWORD listBase)
518 {
519 #define VERIFY(a) a
520
521 TEXTMETRIC metric;
522 BITMAPINFO *dibInfo;
523 HDC bitDevice;
524 COLORREF tempColor;
525 int i;
526
527 VERIFY(GetTextMetrics(fontDevice, &metric));
528
529 dibInfo = (BITMAPINFO *) calloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD), 1);
530 dibInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
531 dibInfo->bmiHeader.biPlanes = 1;
532 dibInfo->bmiHeader.biBitCount = 1;
533 dibInfo->bmiHeader.biCompression = BI_RGB;
534
535 bitDevice = CreateCompatibleDC(fontDevice);
536 // HDC bitDevice = CreateDC("DISPLAY", NULL, NULL, NULL);
537 // VERIFY(bitDevice);
538
539 // Swap fore and back colors so the bitmap has the right polarity
540 tempColor = GetBkColor(bitDevice);
541 SetBkColor(bitDevice, GetTextColor(bitDevice));
542 SetTextColor(bitDevice, tempColor);
543
544 // Place chars based on base line
545 VERIFY(SetTextAlign(bitDevice, TA_BASELINE) >= 0 ? 1 : 0);
546
547 for(i = 0; i < numChars; i++) {
548 SIZE size;
549 char curChar;
550 int charWidth,charHeight,bmapWidth,bmapHeight,numBytes,res;
551 HBITMAP bitObject;
552 HGDIOBJ origBmap;
553 unsigned char *bmap;
554
555 curChar = i + firstChar;
556
557 // Find how high/wide this character is
558 VERIFY(GetTextExtentPoint32(bitDevice, &curChar, 1, &size));
559
560 // Create the output bitmap
561 charWidth = size.cx;
562 charHeight = size.cy;
563 bmapWidth = ((charWidth + 31) / 32) * 32; // Round up to the next multiple of 32 bits
564 bmapHeight = charHeight;
565 bitObject = CreateCompatibleBitmap(bitDevice,
566 bmapWidth,
567 bmapHeight);
568 //VERIFY(bitObject);
569
570 // Assign the output bitmap to the device
571 origBmap = SelectObject(bitDevice, bitObject);
572 VERIFY(origBmap);
573
574 VERIFY( PatBlt( bitDevice, 0, 0, bmapWidth, bmapHeight,BLACKNESS ) );
575
576 // Use our source font on the device
577 VERIFY(SelectObject(bitDevice, GetCurrentObject(fontDevice,OBJ_FONT)));
578
579 // Draw the character
580 VERIFY(TextOut(bitDevice, 0, metric.tmAscent, &curChar, 1));
581
582 // Unselect our bmap object
583 VERIFY(SelectObject(bitDevice, origBmap));
584
585 // Convert the display dependant representation to a 1 bit deep DIB
586 numBytes = (bmapWidth * bmapHeight) / 8;
587 bmap = MALLOC(numBytes);
588 dibInfo->bmiHeader.biWidth = bmapWidth;
589 dibInfo->bmiHeader.biHeight = bmapHeight;
590 res = GetDIBits(bitDevice, bitObject, 0, bmapHeight, bmap,
591 dibInfo,
592 DIB_RGB_COLORS);
593 //VERIFY(res);
594
595 // Create the GL object
596 glNewList(i + listBase, GL_COMPILE);
597 glBitmap(bmapWidth, bmapHeight, 0.0, metric.tmDescent,
598 charWidth, 0.0,
599 bmap);
600 glEndList();
601 // CheckGL();
602
603 // Destroy the bmap object
604 DeleteObject(bitObject);
605
606 // Deallocate the bitmap data
607 FREE(bmap);
608 }
609
610 // Destroy the DC
611 VERIFY(DeleteDC(bitDevice));
612
613 FREE(dibInfo);
614
615 return TRUE;
616 #undef VERIFY
617 }
618
619 BOOL GLAPIENTRY wglUseFontBitmapsW(HDC hdc,DWORD first,DWORD count,DWORD listBase)
620 {
621 return(FALSE);
622 }
623
624 BOOL GLAPIENTRY wglUseFontOutlinesA(HDC hdc,DWORD first,DWORD count,
625 DWORD listBase,FLOAT deviation,
626 FLOAT extrusion,int format,
627 LPGLYPHMETRICSFLOAT lpgmf)
628 {
629 SetLastError(0);
630 return(FALSE);
631 }
632
633 BOOL GLAPIENTRY wglUseFontOutlinesW(HDC hdc,DWORD first,DWORD count,
634 DWORD listBase,FLOAT deviation,
635 FLOAT extrusion,int format,
636 LPGLYPHMETRICSFLOAT lpgmf)
637 {
638 SetLastError(0);
639 return(FALSE);
640 }
641
642
643 BOOL GLAPIENTRY wglSwapLayerBuffers(HDC hdc,UINT fuPlanes)
644 {
645 if(ctx && WindowFromDC(hdc) == hWND) {
646 fxMesaSwapBuffers();
647
648 return(TRUE);
649 }
650
651 SetLastError(0);
652 return(FALSE);
653 }
654
655 int GLAPIENTRY wglChoosePixelFormat(HDC hdc,
656 CONST PIXELFORMATDESCRIPTOR *ppfd)
657 {
658 int i,best=-1,qt_valid_pix;
659
660 qt_valid_pix = qt_pix;
661
662 if(ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR) || ppfd->nVersion != 1) {
663 SetLastError(0);
664 return(0);
665 }
666
667 for(i = 0;i < qt_valid_pix;i++) {
668 if((ppfd->dwFlags & PFD_DRAW_TO_WINDOW) && !(pix[i].pfd.dwFlags & PFD_DRAW_TO_WINDOW))
669 continue;
670 if((ppfd->dwFlags & PFD_DRAW_TO_BITMAP) && !(pix[i].pfd.dwFlags & PFD_DRAW_TO_BITMAP))
671 continue;
672 if((ppfd->dwFlags & PFD_SUPPORT_GDI) && !(pix[i].pfd.dwFlags & PFD_SUPPORT_GDI))
673 continue;
674 if((ppfd->dwFlags & PFD_SUPPORT_OPENGL) && !(pix[i].pfd.dwFlags & PFD_SUPPORT_OPENGL))
675 continue;
676 if(!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) &&
677 ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != (pix[i].pfd.dwFlags & PFD_DOUBLEBUFFER)))
678 continue;
679 if(!(ppfd->dwFlags & PFD_STEREO_DONTCARE) &&
680 ((ppfd->dwFlags & PFD_STEREO) != (pix[i].pfd.dwFlags & PFD_STEREO)))
681 continue;
682
683 if (ppfd->cDepthBits > 0 && pix[i].pfd.cDepthBits == 0)
684 continue; /* need depth buffer */
685
686 if (ppfd->cAlphaBits > 0 && pix[i].pfd.cAlphaBits == 0)
687 continue; /* need alpha buffer */
688
689 if(ppfd->iPixelType == pix[i].pfd.iPixelType) {
690 best = i + 1;
691 break;
692 }
693 }
694
695 if(best == -1) {
696 SetLastError(0);
697 return(0);
698 }
699
700 return(best);
701 }
702
703 int GLAPIENTRY ChoosePixelFormat(HDC hdc,
704 CONST PIXELFORMATDESCRIPTOR *ppfd)
705 {
706 return wglChoosePixelFormat(hdc,ppfd);
707 }
708
709 int GLAPIENTRY wglDescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes,
710 LPPIXELFORMATDESCRIPTOR ppfd)
711 {
712 int qt_valid_pix;
713
714 qt_valid_pix = qt_pix;
715
716 if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix ||
717 ((nBytes != sizeof(PIXELFORMATDESCRIPTOR)) && (nBytes != 0))) {
718 SetLastError(0);
719 return(0);
720 }
721
722 if(nBytes != 0)
723 *ppfd = pix[iPixelFormat - 1].pfd;
724
725 return(qt_valid_pix);
726 }
727
728 int GLAPIENTRY DescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes,
729 LPPIXELFORMATDESCRIPTOR ppfd)
730 {
731 return wglDescribePixelFormat(hdc,iPixelFormat,nBytes,ppfd);
732 }
733
734 int GLAPIENTRY wglGetPixelFormat(HDC hdc)
735 {
736 if(curPFD == 0) {
737 SetLastError(0);
738 return(0);
739 }
740
741 return(curPFD);
742 }
743
744 int GLAPIENTRY GetPixelFormat(HDC hdc)
745 {
746 return wglGetPixelFormat(hdc);
747 }
748
749 BOOL GLAPIENTRY wglSetPixelFormat(HDC hdc,int iPixelFormat,
750 CONST PIXELFORMATDESCRIPTOR *ppfd)
751 {
752 int qt_valid_pix;
753
754 qt_valid_pix = qt_pix;
755
756 if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR)) {
757 SetLastError(0);
758 return(FALSE);
759 }
760 curPFD = iPixelFormat;
761
762 return(TRUE);
763 }
764
765 BOOL GLAPIENTRY wglSwapBuffers(HDC hdc)
766 {
767 if(!ctx) {
768 SetLastError(0);
769 return(FALSE);
770 }
771
772 fxMesaSwapBuffers();
773
774 if(gdiWindowHack) {
775 GLuint width=ctx->width;
776 GLuint height=ctx->height;
777
778 HDC hdcScreen = GetDC(dibWnd);
779 HDC hdcDIBSection = CreateCompatibleDC(hdcScreen);
780 HBITMAP holdBitmap = (HBITMAP) SelectObject(hdcDIBSection, dibHBM);
781
782 grLfbReadRegion(GR_BUFFER_FRONTBUFFER, 0, 0,
783 width, height,
784 width * 2,
785 dibSurfacePtr);
786
787 /* Since the hardware is configured for GR_COLORFORMAT_ABGR the pixel data is
788 * going to come out as BGR 565, which is reverse of what we need for blitting
789 * to screen, so we need to convert it here pixel-by-pixel (ick). This loop would NOT
790 * be required if the color format was changed to GR_COLORFORMAT_ARGB, but I do
791 * not know the ramifications of that, so this will work until that is resolved.
792 *
793 * This routine CRIES out for MMX implementation, however since that's not
794 * guaranteed to be running on MMX enabled hardware so I'm not going to do
795 * that. I'm just going to try to make a reasonably efficient C
796 * version. -TAJ
797 *
798 * This routine drops frame rate by <1 fps on a 200Mhz MMX processor with a 640x480
799 * display. Obviously, it's performance hit will be higher on larger displays and
800 * less on smaller displays. To support the window-hack display this is probably fine.
801 */
802 {
803 unsigned long *pixel = dibSurfacePtr;
804 unsigned long count = (width * height) / 2;
805
806 while (count--)
807 {
808 *pixel++ = (*pixel & 0x07e007e0) /* greens */
809 | ((*pixel & 0xf800f800) >> 11) /* swap blues */
810 | ((*pixel & 0x001f001f) << 11) /* swap reds */
811 ;
812 }
813 }
814
815 BitBlt(hdcScreen, 0, 0,
816 width, height,
817 hdcDIBSection,
818 0, 0, SRCCOPY);
819
820 ReleaseDC(dibWnd, hdcScreen);
821 SelectObject(hdcDIBSection, holdBitmap);
822 DeleteDC(hdcDIBSection);
823 }
824
825 return(TRUE);
826 }
827
828 BOOL GLAPIENTRY SetPixelFormat(HDC hdc, int iPixelFormat,
829 CONST PIXELFORMATDESCRIPTOR *ppfd)
830 {
831 return wglSetPixelFormat(hdc,iPixelFormat,ppfd);
832 }
833
834 BOOL GLAPIENTRY SwapBuffers(HDC hdc)
835 {
836 return wglSwapBuffers(hdc);
837 }
838
839 #endif /* FX */