| 1 | /* $Id: wgl.c,v 1.3 2000-03-02 23:09:21 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 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. | 
|---|
| 8 | * | 
|---|
| 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. | 
|---|
| 13 | * | 
|---|
| 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. | 
|---|
| 17 | * | 
|---|
| 18 | */ | 
|---|
| 19 |  | 
|---|
| 20 | /* | 
|---|
| 21 | * File name     : wgl.c | 
|---|
| 22 | * WGL stuff. Added by Oleg Letsinsky, ajl@ultersys.ru | 
|---|
| 23 | * Some things originated from the 3Dfx WGL functions | 
|---|
| 24 | */ | 
|---|
| 25 |  | 
|---|
| 26 | #if defined(WIN32) || defined(__WIN32OS2__) | 
|---|
| 27 |  | 
|---|
| 28 | #ifdef __cplusplus | 
|---|
| 29 | extern "C" { | 
|---|
| 30 | #endif | 
|---|
| 31 | #include <windows.h> | 
|---|
| 32 |  | 
|---|
| 33 | #ifdef __cplusplus | 
|---|
| 34 | } | 
|---|
| 35 | #endif | 
|---|
| 36 |  | 
|---|
| 37 | #include <stdio.h> | 
|---|
| 38 | #include <tchar.h> | 
|---|
| 39 | #include "gl.h" | 
|---|
| 40 | #include "types.h" | 
|---|
| 41 | #include "context.h" | 
|---|
| 42 | #include "wmesadef.h" | 
|---|
| 43 | #include "wmesa.h" | 
|---|
| 44 |  | 
|---|
| 45 | #define MAX_MESA_ATTRS  20 | 
|---|
| 46 |  | 
|---|
| 47 | struct __extensions__ | 
|---|
| 48 | { | 
|---|
| 49 | PROC        proc; | 
|---|
| 50 | char        *name; | 
|---|
| 51 | }; | 
|---|
| 52 |  | 
|---|
| 53 | struct __pixelformat__ | 
|---|
| 54 | { | 
|---|
| 55 | PIXELFORMATDESCRIPTOR       pfd; | 
|---|
| 56 | GLboolean doubleBuffered; | 
|---|
| 57 | }; | 
|---|
| 58 |  | 
|---|
| 59 | struct __extensions__   ext[] = { | 
|---|
| 60 |  | 
|---|
| 61 | #ifdef GL_EXT_polygon_offset | 
|---|
| 62 | { (PROC)glPolygonOffsetEXT,                  "glPolygonOffsetEXT"            }, | 
|---|
| 63 | #endif | 
|---|
| 64 | { (PROC)glBlendEquationEXT,                  "glBlendEquationEXT"            }, | 
|---|
| 65 | { (PROC)glBlendColorEXT,                     "glBlendColorExt"               }, | 
|---|
| 66 | { (PROC)glVertexPointerEXT,                  "glVertexPointerEXT"            }, | 
|---|
| 67 | { (PROC)glNormalPointerEXT,                  "glNormalPointerEXT"            }, | 
|---|
| 68 | { (PROC)glColorPointerEXT,                   "glColorPointerEXT"             }, | 
|---|
| 69 | { (PROC)glIndexPointerEXT,                   "glIndexPointerEXT"             }, | 
|---|
| 70 | { (PROC)glTexCoordPointerEXT,                "glTexCoordPointer"             }, | 
|---|
| 71 | { (PROC)glEdgeFlagPointerEXT,                "glEdgeFlagPointerEXT"          }, | 
|---|
| 72 | { (PROC)glGetPointervEXT,                    "glGetPointervEXT"              }, | 
|---|
| 73 | { (PROC)glArrayElementEXT,                   "glArrayElementEXT"             }, | 
|---|
| 74 | { (PROC)glDrawArraysEXT,                     "glDrawArrayEXT"                }, | 
|---|
| 75 | { (PROC)glAreTexturesResidentEXT,            "glAreTexturesResidentEXT"      }, | 
|---|
| 76 | { (PROC)glBindTextureEXT,                    "glBindTextureEXT"              }, | 
|---|
| 77 | { (PROC)glDeleteTexturesEXT,                 "glDeleteTexturesEXT"           }, | 
|---|
| 78 | { (PROC)glGenTexturesEXT,                    "glGenTexturesEXT"              }, | 
|---|
| 79 | { (PROC)glIsTextureEXT,                      "glIsTextureEXT"                }, | 
|---|
| 80 | { (PROC)glPrioritizeTexturesEXT,             "glPrioritizeTexturesEXT"       }, | 
|---|
| 81 | { (PROC)glCopyTexSubImage3DEXT,              "glCopyTexSubImage3DEXT"        }, | 
|---|
| 82 | { (PROC)glTexImage3DEXT,                     "glTexImage3DEXT"               }, | 
|---|
| 83 | { (PROC)glTexSubImage3DEXT,                  "glTexSubImage3DEXT"            }, | 
|---|
| 84 | { (PROC)glColorTableEXT,                     "glColorTableEXT"               }, | 
|---|
| 85 | { (PROC)glColorSubTableEXT,                  "glColorSubTableEXT"            }, | 
|---|
| 86 | { (PROC)glGetColorTableEXT,                  "glGetColorTableEXT"            }, | 
|---|
| 87 | { (PROC)glGetColorTableParameterfvEXT,       "glGetColorTableParameterfvEXT" }, | 
|---|
| 88 | { (PROC)glGetColorTableParameterivEXT,       "glGetColorTableParameterivEXT" }, | 
|---|
| 89 | { (PROC)glPointParameterfEXT,                "glPointParameterfEXT"          }, | 
|---|
| 90 | { (PROC)glPointParameterfvEXT,               "glPointParameterfvEXT"         }, | 
|---|
| 91 | { (PROC)glBlendFuncSeparateINGR,             "glBlendFuncSeparateINGR"       }, | 
|---|
| 92 | { (PROC)glLockArraysEXT,                     "glLockArraysEXT"               }, | 
|---|
| 93 | { (PROC)glUnlockArraysEXT,                   "glUnlockArraysEXT"             } | 
|---|
| 94 | }; | 
|---|
| 95 |  | 
|---|
| 96 | int qt_ext = sizeof(ext) / sizeof(ext[0]); | 
|---|
| 97 |  | 
|---|
| 98 | struct __pixelformat__  pix[] = | 
|---|
| 99 | { | 
|---|
| 100 | {   {       sizeof(PIXELFORMATDESCRIPTOR),  1, | 
|---|
| 101 | PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_GENERIC_FORMAT|PFD_DOUBLEBUFFER|PFD_SWAP_COPY, | 
|---|
| 102 | PFD_TYPE_RGBA, | 
|---|
| 103 | 24,     8,      0,      8,      8,      8,      16,     8,      24, | 
|---|
| 104 | 0,      0,      0,      0,      0,      16,     8,      0,      0,      0,      0,      0,      0 }, | 
|---|
| 105 | GL_TRUE | 
|---|
| 106 | }, | 
|---|
| 107 | {   {       sizeof(PIXELFORMATDESCRIPTOR),  1, | 
|---|
| 108 | PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_GENERIC_FORMAT, | 
|---|
| 109 | PFD_TYPE_RGBA, | 
|---|
| 110 | 24,     8,      0,      8,      8,      8,      16,     8,      24, | 
|---|
| 111 | 0,      0,      0,      0,      0,      16,     8,      0,      0,      0,      0,      0,      0 }, | 
|---|
| 112 | GL_FALSE | 
|---|
| 113 | }, | 
|---|
| 114 | }; | 
|---|
| 115 |  | 
|---|
| 116 | int                             qt_pix = sizeof(pix) / sizeof(pix[0]); | 
|---|
| 117 |  | 
|---|
| 118 | typedef struct { | 
|---|
| 119 | WMesaContext ctx; | 
|---|
| 120 | HDC hdc; | 
|---|
| 121 | } MesaWglCtx; | 
|---|
| 122 |  | 
|---|
| 123 | #define MESAWGL_CTX_MAX_COUNT 20 | 
|---|
| 124 |  | 
|---|
| 125 | static MesaWglCtx wgl_ctx[MESAWGL_CTX_MAX_COUNT]; | 
|---|
| 126 |  | 
|---|
| 127 | static unsigned ctx_count = 0; | 
|---|
| 128 | static unsigned ctx_current = -1; | 
|---|
| 129 | static unsigned curPFD = 0; | 
|---|
| 130 |  | 
|---|
| 131 | GLAPI BOOL GLWINAPI wglCopyContext(HGLRC hglrcSrc,HGLRC hglrcDst,UINT mask) | 
|---|
| 132 | { | 
|---|
| 133 | return(FALSE); | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | GLAPI HGLRC GLWINAPI wglCreateContext(HDC hdc) | 
|---|
| 137 | { | 
|---|
| 138 | HWND                hWnd; | 
|---|
| 139 | int i = 0; | 
|---|
| 140 | if(!(hWnd = WindowFromDC(hdc))) | 
|---|
| 141 | { | 
|---|
| 142 | SetLastError(0); | 
|---|
| 143 | return(NULL); | 
|---|
| 144 | } | 
|---|
| 145 | if (!ctx_count) | 
|---|
| 146 | { | 
|---|
| 147 | for(i=0;i<MESAWGL_CTX_MAX_COUNT;i++) | 
|---|
| 148 | { | 
|---|
| 149 | wgl_ctx[i].ctx = NULL; | 
|---|
| 150 | wgl_ctx[i].hdc = NULL; | 
|---|
| 151 | } | 
|---|
| 152 | } | 
|---|
| 153 | for( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ ) | 
|---|
| 154 | { | 
|---|
| 155 | if ( wgl_ctx[i].ctx == NULL ) | 
|---|
| 156 | { | 
|---|
| 157 | wgl_ctx[i].ctx = WMesaCreateContext( hWnd, NULL, GL_TRUE, | 
|---|
| 158 | pix[curPFD-1].doubleBuffered ); | 
|---|
| 159 | if (wgl_ctx[i].ctx == NULL) | 
|---|
| 160 | break; | 
|---|
| 161 | wgl_ctx[i].hdc = hdc; | 
|---|
| 162 | ctx_count++; | 
|---|
| 163 | return ((HGLRC)wgl_ctx[i].ctx); | 
|---|
| 164 | } | 
|---|
| 165 | } | 
|---|
| 166 | SetLastError(0); | 
|---|
| 167 | return(NULL); | 
|---|
| 168 | } | 
|---|
| 169 |  | 
|---|
| 170 | GLAPI BOOL GLWINAPI wglDeleteContext(HGLRC hglrc) | 
|---|
| 171 | { | 
|---|
| 172 | int i; | 
|---|
| 173 | for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ ) | 
|---|
| 174 | { | 
|---|
| 175 | if ( wgl_ctx[i].ctx == (PWMC) hglrc ) | 
|---|
| 176 | { | 
|---|
| 177 | WMesaMakeCurrent((PWMC) hglrc); | 
|---|
| 178 | WMesaDestroyContext(); | 
|---|
| 179 | wgl_ctx[i].ctx = NULL; | 
|---|
| 180 | wgl_ctx[i].hdc = NULL; | 
|---|
| 181 | ctx_count--; | 
|---|
| 182 | return(TRUE); | 
|---|
| 183 | } | 
|---|
| 184 | } | 
|---|
| 185 | SetLastError(0); | 
|---|
| 186 | return(FALSE); | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 | GLAPI HGLRC GLWINAPI wglCreateLayerContext(HDC hdc,int iLayerPlane) | 
|---|
| 190 | { | 
|---|
| 191 | SetLastError(0); | 
|---|
| 192 | return(NULL); | 
|---|
| 193 | } | 
|---|
| 194 |  | 
|---|
| 195 | GLAPI HGLRC GLWINAPI wglGetCurrentContext(VOID) | 
|---|
| 196 | { | 
|---|
| 197 | if (ctx_current < 0) | 
|---|
| 198 | return 0; | 
|---|
| 199 | else | 
|---|
| 200 | return (HGLRC) wgl_ctx[ctx_current].ctx; | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 | GLAPI HDC GLWINAPI wglGetCurrentDC(VOID) | 
|---|
| 204 | { | 
|---|
| 205 | if (ctx_current < 0) | 
|---|
| 206 | return 0; | 
|---|
| 207 | else | 
|---|
| 208 | return wgl_ctx[ctx_current].hdc; | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | GLAPI BOOL GLWINAPI wglMakeCurrent(HDC hdc,HGLRC hglrc) | 
|---|
| 212 | { | 
|---|
| 213 | int i; | 
|---|
| 214 |  | 
|---|
| 215 | /* new code suggested by Andy Sy */ | 
|---|
| 216 | if (!hdc || !hglrc) { | 
|---|
| 217 | WMesaMakeCurrent(NULL); | 
|---|
| 218 | ctx_current = -1; | 
|---|
| 219 | return TRUE; | 
|---|
| 220 | } | 
|---|
| 221 |  | 
|---|
| 222 | for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ ) | 
|---|
| 223 | { | 
|---|
| 224 | if ( wgl_ctx[i].ctx == (PWMC) hglrc ) | 
|---|
| 225 | { | 
|---|
| 226 | wgl_ctx[i].hdc = hdc; | 
|---|
| 227 | WMesaMakeCurrent( (WMesaContext) hglrc ); | 
|---|
| 228 | ctx_current = i; | 
|---|
| 229 | return TRUE; | 
|---|
| 230 | } | 
|---|
| 231 | } | 
|---|
| 232 | return FALSE; | 
|---|
| 233 | } | 
|---|
| 234 |  | 
|---|
| 235 | GLAPI BOOL GLWINAPI wglShareLists(HGLRC hglrc1,HGLRC hglrc2) | 
|---|
| 236 | { | 
|---|
| 237 | return(TRUE); | 
|---|
| 238 | } | 
|---|
| 239 |  | 
|---|
| 240 |  | 
|---|
| 241 | static FIXED FixedFromDouble(double d) | 
|---|
| 242 | { | 
|---|
| 243 | long l = (long) (d * 65536L); | 
|---|
| 244 | return *(FIXED *)&l; | 
|---|
| 245 | } | 
|---|
| 246 |  | 
|---|
| 247 |  | 
|---|
| 248 | GLAPI BOOL GLWINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, | 
|---|
| 249 | DWORD count, DWORD listBase) | 
|---|
| 250 | { | 
|---|
| 251 | int i; | 
|---|
| 252 | GLuint font_list; | 
|---|
| 253 | DWORD size; | 
|---|
| 254 | GLYPHMETRICS gm; | 
|---|
| 255 | HANDLE hBits; | 
|---|
| 256 | LPSTR lpBits; | 
|---|
| 257 | MAT2 mat; | 
|---|
| 258 |  | 
|---|
| 259 | if (first<0) | 
|---|
| 260 | return FALSE; | 
|---|
| 261 | if (count<0) | 
|---|
| 262 | return FALSE; | 
|---|
| 263 | if (listBase<0) | 
|---|
| 264 | return FALSE; | 
|---|
| 265 |  | 
|---|
| 266 | font_list = glGenLists( count ); | 
|---|
| 267 | if(font_list == 0) | 
|---|
| 268 | return FALSE; | 
|---|
| 269 |  | 
|---|
| 270 | mat.eM11 = FixedFromDouble(1); | 
|---|
| 271 | mat.eM12 = FixedFromDouble(0); | 
|---|
| 272 | mat.eM21 = FixedFromDouble(0); | 
|---|
| 273 | mat.eM22 = FixedFromDouble(1); | 
|---|
| 274 |  | 
|---|
| 275 | memset(&gm,0,sizeof(gm)); | 
|---|
| 276 |  | 
|---|
| 277 | for (i = 0; i < count; i++) | 
|---|
| 278 | { | 
|---|
| 279 | glNewList( font_list+i, GL_COMPILE ); | 
|---|
| 280 |  | 
|---|
| 281 | /* allocate space for the bitmap/outline */ | 
|---|
| 282 | size = GetGlyphOutline(hdc, first + i, GGO_BITMAP, &gm, 0, NULL, &mat); | 
|---|
| 283 | if (size == GDI_ERROR) | 
|---|
| 284 | { | 
|---|
| 285 | DWORD err; | 
|---|
| 286 | err = GetLastError(); | 
|---|
| 287 | return(FALSE); | 
|---|
| 288 | } | 
|---|
| 289 |  | 
|---|
| 290 | hBits  = GlobalAlloc(GHND, size); | 
|---|
| 291 | lpBits = (LPSTR)GlobalLock(hBits); | 
|---|
| 292 |  | 
|---|
| 293 | GetGlyphOutline(hdc,                      /* handle to device context*/ | 
|---|
| 294 | first + i,                      /* character to query*/ | 
|---|
| 295 | GGO_BITMAP,               /* format of data to return*/ | 
|---|
| 296 | &gm,              /* pointer to structure for metrics*/ | 
|---|
| 297 | size,                      /* size of buffer for data*/ | 
|---|
| 298 | lpBits,                 /* pointer to buffer for data*/ | 
|---|
| 299 | &mat                     /* pointer to transformation*/ | 
|---|
| 300 | /* matrix structure */ | 
|---|
| 301 | ); | 
|---|
| 302 | if (*lpBits == GDI_ERROR) | 
|---|
| 303 | { | 
|---|
| 304 | DWORD err; | 
|---|
| 305 | err = GetLastError(); | 
|---|
| 306 |  | 
|---|
| 307 | GlobalUnlock(hBits); | 
|---|
| 308 | GlobalFree(hBits); | 
|---|
| 309 |  | 
|---|
| 310 | return(FALSE); | 
|---|
| 311 | } | 
|---|
| 312 |  | 
|---|
| 313 | glBitmap(gm.gmBlackBoxX,gm.gmBlackBoxY, | 
|---|
| 314 | gm.gmptGlyphOrigin.x, | 
|---|
| 315 | gm.gmptGlyphOrigin.y, | 
|---|
| 316 | gm.gmCellIncX,gm.gmCellIncY, | 
|---|
| 317 | (const GLubyte * )lpBits); | 
|---|
| 318 |  | 
|---|
| 319 | GlobalUnlock(hBits); | 
|---|
| 320 | GlobalFree(hBits); | 
|---|
| 321 |  | 
|---|
| 322 | glEndList( ); | 
|---|
| 323 | } | 
|---|
| 324 |  | 
|---|
| 325 | return TRUE; | 
|---|
| 326 | } | 
|---|
| 327 |  | 
|---|
| 328 | GLAPI BOOL GLWINAPI wglUseFontBitmapsW(HDC hdc,DWORD first,DWORD count,DWORD listBase) | 
|---|
| 329 | { | 
|---|
| 330 | return FALSE; | 
|---|
| 331 | } | 
|---|
| 332 |  | 
|---|
| 333 | GLAPI BOOL GLWINAPI wglUseFontOutlinesA(HDC hdc,DWORD first,DWORD count, | 
|---|
| 334 | DWORD listBase,FLOAT deviation, | 
|---|
| 335 | FLOAT extrusion,int format, | 
|---|
| 336 | LPGLYPHMETRICSFLOAT lpgmf) | 
|---|
| 337 | { | 
|---|
| 338 | SetLastError(0); | 
|---|
| 339 | return(FALSE); | 
|---|
| 340 | } | 
|---|
| 341 |  | 
|---|
| 342 | GLAPI BOOL GLWINAPI wglUseFontOutlinesW(HDC hdc,DWORD first,DWORD count, | 
|---|
| 343 | DWORD listBase,FLOAT deviation, | 
|---|
| 344 | FLOAT extrusion,int format, | 
|---|
| 345 | LPGLYPHMETRICSFLOAT lpgmf) | 
|---|
| 346 | { | 
|---|
| 347 | SetLastError(0); | 
|---|
| 348 | return(FALSE); | 
|---|
| 349 | } | 
|---|
| 350 |  | 
|---|
| 351 | GLAPI BOOL GLWINAPI wglDescribeLayerPlane(HDC hdc,int iPixelFormat, | 
|---|
| 352 | int iLayerPlane,UINT nBytes, | 
|---|
| 353 | LAYERPLANEDESCRIPTOR *plpd) | 
|---|
| 354 | { | 
|---|
| 355 | SetLastError(0); | 
|---|
| 356 | return(FALSE); | 
|---|
| 357 | } | 
|---|
| 358 |  | 
|---|
| 359 | GLAPI int GLWINAPI wglSetLayerPaletteEntries(HDC hdc,int iLayerPlane, | 
|---|
| 360 | int iStart,int cEntries, | 
|---|
| 361 | CONST COLORREF *pcr) | 
|---|
| 362 | { | 
|---|
| 363 | SetLastError(0); | 
|---|
| 364 | return(0); | 
|---|
| 365 | } | 
|---|
| 366 |  | 
|---|
| 367 | GLAPI int GLWINAPI wglGetLayerPaletteEntries(HDC hdc,int iLayerPlane, | 
|---|
| 368 | int iStart,int cEntries, | 
|---|
| 369 | COLORREF *pcr) | 
|---|
| 370 | { | 
|---|
| 371 | SetLastError(0); | 
|---|
| 372 | return(0); | 
|---|
| 373 | } | 
|---|
| 374 |  | 
|---|
| 375 | GLAPI BOOL GLWINAPI wglRealizeLayerPalette(HDC hdc,int iLayerPlane,BOOL bRealize) | 
|---|
| 376 | { | 
|---|
| 377 | SetLastError(0); | 
|---|
| 378 | return(FALSE); | 
|---|
| 379 | } | 
|---|
| 380 |  | 
|---|
| 381 | GLAPI BOOL GLWINAPI wglSwapLayerBuffers(HDC hdc,UINT fuPlanes) | 
|---|
| 382 | { | 
|---|
| 383 | if( !hdc ) | 
|---|
| 384 | { | 
|---|
| 385 | WMesaSwapBuffers(); | 
|---|
| 386 | return(TRUE); | 
|---|
| 387 | } | 
|---|
| 388 | SetLastError(0); | 
|---|
| 389 | return(FALSE); | 
|---|
| 390 | } | 
|---|
| 391 |  | 
|---|
| 392 | GLAPI int GLWINAPI wglChoosePixelFormat(HDC hdc, | 
|---|
| 393 | CONST PIXELFORMATDESCRIPTOR *ppfd) | 
|---|
| 394 | { | 
|---|
| 395 | int         i,best = -1,bestdelta = 0x7FFFFFFF,delta,qt_valid_pix; | 
|---|
| 396 |  | 
|---|
| 397 | qt_valid_pix = qt_pix; | 
|---|
| 398 | //    if(ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR) || ppfd->nVersion != 1) | 
|---|
| 399 | if(ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR)) | 
|---|
| 400 | { | 
|---|
| 401 | SetLastError(0); | 
|---|
| 402 | return(0); | 
|---|
| 403 | } | 
|---|
| 404 | for(i = 0;i < qt_valid_pix;i++) | 
|---|
| 405 | { | 
|---|
| 406 | delta = 0; | 
|---|
| 407 | if( | 
|---|
| 408 | (ppfd->dwFlags & PFD_DRAW_TO_WINDOW) && | 
|---|
| 409 | !(pix[i].pfd.dwFlags & PFD_DRAW_TO_WINDOW)) | 
|---|
| 410 | continue; | 
|---|
| 411 | if( | 
|---|
| 412 | (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) && | 
|---|
| 413 | !(pix[i].pfd.dwFlags & PFD_DRAW_TO_BITMAP)) | 
|---|
| 414 | continue; | 
|---|
| 415 | if( | 
|---|
| 416 | (ppfd->dwFlags & PFD_SUPPORT_GDI) && | 
|---|
| 417 | !(pix[i].pfd.dwFlags & PFD_SUPPORT_GDI)) | 
|---|
| 418 | continue; | 
|---|
| 419 | if( | 
|---|
| 420 | (ppfd->dwFlags & PFD_SUPPORT_OPENGL) && | 
|---|
| 421 | !(pix[i].pfd.dwFlags & PFD_SUPPORT_OPENGL)) | 
|---|
| 422 | continue; | 
|---|
| 423 | if( | 
|---|
| 424 | !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && | 
|---|
| 425 | ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != (pix[i].pfd.dwFlags & PFD_DOUBLEBUFFER))) | 
|---|
| 426 | continue; | 
|---|
| 427 | if( | 
|---|
| 428 | !(ppfd->dwFlags & PFD_STEREO_DONTCARE) && | 
|---|
| 429 | ((ppfd->dwFlags & PFD_STEREO) != (pix[i].pfd.dwFlags & PFD_STEREO))) | 
|---|
| 430 | continue; | 
|---|
| 431 | if(ppfd->iPixelType != pix[i].pfd.iPixelType) | 
|---|
| 432 | delta++; | 
|---|
| 433 | if(delta < bestdelta) | 
|---|
| 434 | { | 
|---|
| 435 | best = i + 1; | 
|---|
| 436 | bestdelta = delta; | 
|---|
| 437 | if(bestdelta == 0) | 
|---|
| 438 | break; | 
|---|
| 439 | } | 
|---|
| 440 | } | 
|---|
| 441 | if(best == -1) | 
|---|
| 442 | { | 
|---|
| 443 | SetLastError(0); | 
|---|
| 444 | return(0); | 
|---|
| 445 | } | 
|---|
| 446 | return(best); | 
|---|
| 447 | } | 
|---|
| 448 |  | 
|---|
| 449 | GLAPI int GLWINAPI wglDescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes, | 
|---|
| 450 | LPPIXELFORMATDESCRIPTOR ppfd) | 
|---|
| 451 | { | 
|---|
| 452 | int         qt_valid_pix; | 
|---|
| 453 |  | 
|---|
| 454 | qt_valid_pix = qt_pix; | 
|---|
| 455 | if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || nBytes != sizeof(PIXELFORMATDESCRIPTOR)) | 
|---|
| 456 | { | 
|---|
| 457 | SetLastError(0); | 
|---|
| 458 | return(0); | 
|---|
| 459 | } | 
|---|
| 460 | *ppfd = pix[iPixelFormat - 1].pfd; | 
|---|
| 461 | return(qt_valid_pix); | 
|---|
| 462 | } | 
|---|
| 463 |  | 
|---|
| 464 | /* | 
|---|
| 465 | * GetProcAddress - return the address of an appropriate extension | 
|---|
| 466 | */ | 
|---|
| 467 | GLAPI PROC GLWINAPI wglGetProcAddress(LPCSTR lpszProc) | 
|---|
| 468 | { | 
|---|
| 469 | int i; | 
|---|
| 470 | for(i = 0;i < qt_ext;i++) | 
|---|
| 471 | if(!strcmp(lpszProc,ext[i].name)) | 
|---|
| 472 | return(ext[i].proc); | 
|---|
| 473 |  | 
|---|
| 474 | SetLastError(0); | 
|---|
| 475 | return(NULL); | 
|---|
| 476 | } | 
|---|
| 477 |  | 
|---|
| 478 | GLAPI int GLWINAPI wglGetPixelFormat(HDC hdc) | 
|---|
| 479 | { | 
|---|
| 480 | if(curPFD == 0) | 
|---|
| 481 | { | 
|---|
| 482 | SetLastError(0); | 
|---|
| 483 | return(0); | 
|---|
| 484 | } | 
|---|
| 485 | return(curPFD); | 
|---|
| 486 | } | 
|---|
| 487 |  | 
|---|
| 488 | GLAPI BOOL GLWINAPI wglSetPixelFormat(HDC hdc, int iPixelFormat, | 
|---|
| 489 | PIXELFORMATDESCRIPTOR *ppfd) | 
|---|
| 490 | { | 
|---|
| 491 | int         qt_valid_pix; | 
|---|
| 492 |  | 
|---|
| 493 | qt_valid_pix = qt_pix; | 
|---|
| 494 | #ifdef __WIN32OS2__ | 
|---|
| 495 | if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || (ppfd && ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR))) | 
|---|
| 496 | #else | 
|---|
| 497 | if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR)) | 
|---|
| 498 | #endif | 
|---|
| 499 | { | 
|---|
| 500 | SetLastError(0); | 
|---|
| 501 | return(FALSE); | 
|---|
| 502 | } | 
|---|
| 503 | curPFD = iPixelFormat; | 
|---|
| 504 | return(TRUE); | 
|---|
| 505 | } | 
|---|
| 506 |  | 
|---|
| 507 | GLAPI BOOL GLWINAPI wglSwapBuffers(HDC hdc) | 
|---|
| 508 | { | 
|---|
| 509 | if (ctx_current < 0) | 
|---|
| 510 | return FALSE; | 
|---|
| 511 |  | 
|---|
| 512 | if(wgl_ctx[ctx_current].ctx == NULL) { | 
|---|
| 513 | SetLastError(0); | 
|---|
| 514 | return(FALSE); | 
|---|
| 515 | } | 
|---|
| 516 | WMesaSwapBuffers(); | 
|---|
| 517 | return(TRUE); | 
|---|
| 518 | } | 
|---|
| 519 |  | 
|---|
| 520 | #endif                                 /* WIN32 or __WIN32OS2__            */ | 
|---|