Author: andreas Date: 2011-06-09 00:33:56 -0700 (Thu, 09 Jun 2011) New Revision: 2405 Modified: trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32D3D.c trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.c trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.h Log: Merging support files from cogvm branch. Modified: trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32D3D.c =================================================================== --- trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32D3D.c 2011-06-09 07:00:37 UTC (rev 2404) +++ trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32D3D.c 2011-06-09 07:33:56 UTC (rev 2405) @@ -6,7 +6,7 @@ * AUTHOR: Andreas Raab (ar) * ADDRESS: Walt Disney Imagineering, Glendale, CA * EMAIL: [hidden email] -* RCSID: $Id: sqWin32D3D.c,v 1.8 2002/09/05 19:30:45 andreasraab Exp $ +* RCSID: $Id$ * * NOTES: * @@ -36,7 +36,7 @@ #define forceFlush 1 /* Note: Print this stuff into a file in case we lock up*/ -# define DPRINTF(vLevel, args) if(vLevel <= verboseLevel) {\ +# define DPRINTF3D(vLevel, args) if(vLevel <= verboseLevel) {\ FILE *fp = fopen("Squeak3D.log", "at");\ if(fp) { fprintf args; if(forceFlush) fflush(fp); fclose(fp); }} @@ -59,7 +59,7 @@ extern int verboseLevel; #endif -#define ERROR_CHECK if(FAILED(hRes)) { DPRINTF(2, (fp, "Error (%x) in %s, line %d\n", hRes, __FILE__, __LINE__))} +#define ERROR_CHECK if(FAILED(hRes)) { DPRINTF3D(2, (fp, "Error (%x) in %s, line %d\n", hRes, __FILE__, __LINE__))} /*****************************************************************************/ /*****************************************************************************/ @@ -145,7 +145,7 @@ #define RELEASE(lp) if(lp) { lp->lpVtbl->Release(lp); lp = NULL; } d3dRenderer *d3dRendererFromHandle(int handle) { - DPRINTF(7, (fp, "Looking for renderer id: %d\n", handle)); + DPRINTF3D(7, (fp, "Looking for renderer id: %d\n", handle)); if(handle < 0 || handle >= MAX_RENDERER) return NULL; if(allRenderer[handle].fUsed) return allRenderer+handle; return NULL; @@ -169,26 +169,26 @@ DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); if(!FAILED(hRes)) return DD_OK; if(printWarnings) - DPRINTF(3,(fp,"WARNING: Failed to lock surface using DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT (errCode=%X)\n",hRes)); + DPRINTF3D(3,(fp,"WARNING: Failed to lock surface using DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT (errCode=%X)\n",hRes)); hRes = lpdd->lpVtbl-> Lock(lpdd, NULL, ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); if(!FAILED(hRes)) return DD_OK; if(printWarnings) - DPRINTF(3,(fp,"WARNING: Failed to lock surface using DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT (errCode=%X)\n",hRes)); + DPRINTF3D(3,(fp,"WARNING: Failed to lock surface using DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT (errCode=%X)\n",hRes)); hRes = lpdd->lpVtbl->Lock(lpdd, NULL, ddsd, DDLOCK_WAIT, NULL); if(!FAILED(hRes)) return DD_OK; if(printWarnings) - DPRINTF(3,(fp,"WARNING: Failed to lock surface using DDLOCK_WAIT (errCode=%X)\n",hRes)); + DPRINTF3D(3,(fp,"WARNING: Failed to lock surface using DDLOCK_WAIT (errCode=%X)\n",hRes)); /* Wait until the blt completed */ do { hRes = lpdd->lpVtbl->GetBltStatus(lpdd, DDGBS_ISBLTDONE); } while(hRes == DDERR_WASSTILLDRAWING); if(FAILED(hRes)) { - DPRINTF(3,(fp,"WARNING: Blt not completed on surface (errCode=%X)\n",hRes)); + DPRINTF3D(3,(fp,"WARNING: Blt not completed on surface (errCode=%X)\n",hRes)); } hRes = lpdd->lpVtbl->Lock(lpdd, NULL, ddsd, 0, NULL); if(!FAILED(hRes)) return DD_OK; - DPRINTF(1,(fp,"ERROR: Failed to lock surface using (errCode=%X)\n",hRes)); + DPRINTF3D(1,(fp,"ERROR: Failed to lock surface using (errCode=%X)\n",hRes)); return hRes; } @@ -202,7 +202,7 @@ desc.dwSize = sizeof(DDSURFACEDESC2); hRes = lpddSurface->lpVtbl->GetSurfaceDesc(lpddSurface, &desc); if(FAILED(hRes)) { - DPRINTF(1,(fp,"ERROR: Failed to obtain surface descriptor (d3dGetSurfaceFormat) (errCode=%X)\n",hRes)); + DPRINTF3D(1,(fp,"ERROR: Failed to obtain surface descriptor (d3dGetSurfaceFormat) (errCode=%X)\n",hRes)); return 0; } *width = desc.dwWidth; @@ -233,7 +233,7 @@ hRes = lpddSurface->lpVtbl->Unlock(lpddSurface, NULL); if(FAILED(hRes)) { - DPRINTF(1,(fp,"ERROR: Failed to unlock surface (d3dUnlockSurface) (errCode=%X)\n",hRes)); + DPRINTF3D(1,(fp,"ERROR: Failed to unlock surface (d3dUnlockSurface) (errCode=%X)\n",hRes)); return 0; } return 1; @@ -294,70 +294,70 @@ /* Check the triangle capabilities of this device */ triCaps = &lpDeviceDesc->dpcTriCaps; - DPRINTF(3,(fp, "\n#### Checking new device\n")); - DPRINTF(3,(fp, "Device name: %s\n", lpszDeviceName)); - DPRINTF(3,(fp, "Device description: %s\n", lpszDeviceDesc)); - DPRINTF(3,(fp, "Hardware accelerated: %s\n", fIsHardware ? "YES" : "NO")); - DPRINTF(3,(fp, "Available render depths: ")); - if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_1) DPRINTF(3,(fp, "1 ")); - if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_2) DPRINTF(3,(fp, "2 ")); - if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_4) DPRINTF(3,(fp, "4 ")); - if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_8) DPRINTF(3,(fp, "8 ")); - if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_16) DPRINTF(3,(fp, "16 ")); - if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_24) DPRINTF(3,(fp, "24 ")); - if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_32) DPRINTF(3,(fp, "32 ")); - DPRINTF(3,(fp, "\n")); + DPRINTF3D(3,(fp, "\n#### Checking new device\n")); + DPRINTF3D(3,(fp, "Device name: %s\n", lpszDeviceName)); + DPRINTF3D(3,(fp, "Device description: %s\n", lpszDeviceDesc)); + DPRINTF3D(3,(fp, "Hardware accelerated: %s\n", fIsHardware ? "YES" : "NO")); + DPRINTF3D(3,(fp, "Available render depths: ")); + if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_1) DPRINTF3D(3,(fp, "1 ")); + if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_2) DPRINTF3D(3,(fp, "2 ")); + if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_4) DPRINTF3D(3,(fp, "4 ")); + if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_8) DPRINTF3D(3,(fp, "8 ")); + if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_16) DPRINTF3D(3,(fp, "16 ")); + if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_24) DPRINTF3D(3,(fp, "24 ")); + if(lpDeviceDesc->dwDeviceRenderBitDepth & DDBD_32) DPRINTF3D(3,(fp, "32 ")); + DPRINTF3D(3,(fp, "\n")); - DPRINTF(3,(fp, "Available Z-buffer depths: ")); - if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_1) DPRINTF(3,(fp, "1 ")); - if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_2) DPRINTF(3,(fp, "2 ")); - if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_4) DPRINTF(3,(fp, "4 ")); - if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_8) DPRINTF(3,(fp, "8 ")); - if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_16) DPRINTF(3,(fp, "16 ")); - if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_24) DPRINTF(3,(fp, "24 ")); - if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_32) DPRINTF(3,(fp, "32 ")); - DPRINTF(3,(fp, "\n")); + DPRINTF3D(3,(fp, "Available Z-buffer depths: ")); + if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_1) DPRINTF3D(3,(fp, "1 ")); + if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_2) DPRINTF3D(3,(fp, "2 ")); + if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_4) DPRINTF3D(3,(fp, "4 ")); + if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_8) DPRINTF3D(3,(fp, "8 ")); + if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_16) DPRINTF3D(3,(fp, "16 ")); + if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_24) DPRINTF3D(3,(fp, "24 ")); + if(lpDeviceDesc->dwDeviceZBufferBitDepth & DDBD_32) DPRINTF3D(3,(fp, "32 ")); + DPRINTF3D(3,(fp, "\n")); - DPRINTF(3,(fp, "Z-buffer tests: ")); - if(triCaps->dwZCmpCaps & D3DPCMPCAPS_NEVER) DPRINTF(3,(fp, "NEVER ")); - if(triCaps->dwZCmpCaps & D3DPCMPCAPS_LESS) DPRINTF(3,(fp, "LESS ")); - if(triCaps->dwZCmpCaps & D3DPCMPCAPS_EQUAL) DPRINTF(3,(fp, "EQUAL ")); - if(triCaps->dwZCmpCaps & D3DPCMPCAPS_LESSEQUAL) DPRINTF(3,(fp, "LESSEQUAL ")); - if(triCaps->dwZCmpCaps & D3DPCMPCAPS_GREATER) DPRINTF(3,(fp, "GREATER ")); - if(triCaps->dwZCmpCaps & D3DPCMPCAPS_NOTEQUAL) DPRINTF(3,(fp, "NOTEQUAL ")); - if(triCaps->dwZCmpCaps & D3DPCMPCAPS_GREATEREQUAL) DPRINTF(3,(fp, "GREATEREQUAL ")); - if(triCaps->dwZCmpCaps & D3DPCMPCAPS_ALWAYS) DPRINTF(3,(fp, "ALWAYS ")); - DPRINTF(3,(fp, "\n")); + DPRINTF3D(3,(fp, "Z-buffer tests: ")); + if(triCaps->dwZCmpCaps & D3DPCMPCAPS_NEVER) DPRINTF3D(3,(fp, "NEVER ")); + if(triCaps->dwZCmpCaps & D3DPCMPCAPS_LESS) DPRINTF3D(3,(fp, "LESS ")); + if(triCaps->dwZCmpCaps & D3DPCMPCAPS_EQUAL) DPRINTF3D(3,(fp, "EQUAL ")); + if(triCaps->dwZCmpCaps & D3DPCMPCAPS_LESSEQUAL) DPRINTF3D(3,(fp, "LESSEQUAL ")); + if(triCaps->dwZCmpCaps & D3DPCMPCAPS_GREATER) DPRINTF3D(3,(fp, "GREATER ")); + if(triCaps->dwZCmpCaps & D3DPCMPCAPS_NOTEQUAL) DPRINTF3D(3,(fp, "NOTEQUAL ")); + if(triCaps->dwZCmpCaps & D3DPCMPCAPS_GREATEREQUAL) DPRINTF3D(3,(fp, "GREATEREQUAL ")); + if(triCaps->dwZCmpCaps & D3DPCMPCAPS_ALWAYS) DPRINTF3D(3,(fp, "ALWAYS ")); + DPRINTF3D(3,(fp, "\n")); - DPRINTF(3,(fp, "Gouraud shading (RGB): %s\n", + DPRINTF3D(3,(fp, "Gouraud shading (RGB): %s\n", (triCaps->dwShadeCaps & D3DPSHADECAPS_COLORGOURAUDRGB) ? "YES" : "NO")); - DPRINTF(3,(fp, "Texture perspective correction: %s\n", + DPRINTF3D(3,(fp, "Texture perspective correction: %s\n", (triCaps->dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) ? "YES" : "NO")); - DPRINTF(3,(fp, "Bilinear texture interpolation: %s\n", + DPRINTF3D(3,(fp, "Bilinear texture interpolation: %s\n", (triCaps->dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR) ? "YES" : "NO")); - DPRINTF(3, (fp, "Dithering: %s\n", + DPRINTF3D(3, (fp, "Dithering: %s\n", (triCaps->dwRasterCaps & D3DPRASTERCAPS_DITHER) ? "YES" : "NO")); - DPRINTF(3, (fp, "Range based fog: %s\n", + DPRINTF3D(3, (fp, "Range based fog: %s\n", (triCaps->dwRasterCaps & D3DPRASTERCAPS_FOGRANGE) ? "YES" : "NO")); - DPRINTF(3, (fp, "Pixel based fog: %s\n", + DPRINTF3D(3, (fp, "Pixel based fog: %s\n", (triCaps->dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) ? "YES" : "NO")); - DPRINTF(3, (fp, "Vertex based fog: %s\n", + DPRINTF3D(3, (fp, "Vertex based fog: %s\n", (triCaps->dwRasterCaps & D3DPRASTERCAPS_FOGVERTEX) ? "YES" : "NO")); - DPRINTF(3, (fp, "W-Buffering: %s\n", + DPRINTF3D(3, (fp, "W-Buffering: %s\n", (triCaps->dwRasterCaps & D3DPRASTERCAPS_WBUFFER) ? "YES" : "NO")); - DPRINTF(3, (fp, "W-based fog: %s\n", + DPRINTF3D(3, (fp, "W-based fog: %s\n", (triCaps->dwRasterCaps & D3DPRASTERCAPS_WFOG) ? "YES" : "NO")); - DPRINTF(3, (fp, "Z-based fog: %s\n", + DPRINTF3D(3, (fp, "Z-based fog: %s\n", (triCaps->dwRasterCaps & D3DPRASTERCAPS_ZFOG) ? "YES" : "NO")); - DPRINTF(3, (fp, "Flat fog: %s\n", + DPRINTF3D(3, (fp, "Flat fog: %s\n", (triCaps->dwShadeCaps & D3DPSHADECAPS_FOGFLAT) ? "YES" : "NO")); - DPRINTF(3, (fp, "Gouraud fog: %s\n", + DPRINTF3D(3, (fp, "Gouraud fog: %s\n", (triCaps->dwShadeCaps & D3DPSHADECAPS_FOGGOURAUD) ? "YES" : "NO")); - DPRINTF(3, (fp, "Phong fog: %s\n", + DPRINTF3D(3, (fp, "Phong fog: %s\n", (triCaps->dwShadeCaps & D3DPSHADECAPS_FOGPHONG) ? "YES" : "NO")); /* The device must support the current display depth */ @@ -420,9 +420,9 @@ { DDPIXELFORMAT* dest = (DDPIXELFORMAT*)lParam; - DPRINTF(3,(fp, "### New Z-Buffer format:\n")); - DPRINTF(3,(fp, "flags: %x\n", ddpf->dwFlags)); - DPRINTF(3,(fp, "depth: %d\n", ddpf->dwZBufferBitDepth)); + DPRINTF3D(3,(fp, "### New Z-Buffer format:\n")); + DPRINTF3D(3,(fp, "flags: %x\n", ddpf->dwFlags)); + DPRINTF3D(3,(fp, "depth: %d\n", ddpf->dwZBufferBitDepth)); if(ddpf->dwFlags != DDPF_ZBUFFER) D3DENUMRET_OK; /* not a z-buffer */ if(!dest->dwSize) { @@ -455,24 +455,24 @@ /* Check for a 8 bit palette indexed texture */ if(ddpf->dwFlags & DDPF_PALETTEINDEXED8) { - DPRINTF(3,(fp, "\nTexture: 8bit palette indexed\n")); + DPRINTF3D(3,(fp, "\nTexture: 8bit palette indexed\n")); CopyMemory(&renderer->ddpfTextureFormat08, ddpf, sizeof(*ddpf)); renderer->fTextureFound08 = TRUE; return DDENUMRET_OK; } /* Check for 16 bit textures */ if((ddpf->dwRGBBitCount == 16) && (ddpf->dwFlags & DDPF_RGB)) { - DPRINTF(3,(fp, "\nTexture: 16bit RGB\n")); - DPRINTF(3,(fp, "Red mask: %x\n", ddpf->dwRBitMask)); - DPRINTF(3,(fp, "Green mask: %x\n", ddpf->dwGBitMask)); - DPRINTF(3,(fp, "Blue mask: %x\n", ddpf->dwBBitMask)); - DPRINTF(3,(fp, "Alpha mask: %x\n", ddpf->dwRGBAlphaBitMask)); + DPRINTF3D(3,(fp, "\nTexture: 16bit RGB\n")); + DPRINTF3D(3,(fp, "Red mask: %x\n", ddpf->dwRBitMask)); + DPRINTF3D(3,(fp, "Green mask: %x\n", ddpf->dwGBitMask)); + DPRINTF3D(3,(fp, "Blue mask: %x\n", ddpf->dwBBitMask)); + DPRINTF3D(3,(fp, "Alpha mask: %x\n", ddpf->dwRGBAlphaBitMask)); if((ddpf->dwFlags & DDPF_ALPHAPIXELS) && ddpf->dwRBitMask == 0x0F00 && ddpf->dwGBitMask == 0x00F0 && ddpf->dwBBitMask == 0x000F && ddpf->dwRGBAlphaBitMask == 0xF000) { - DPRINTF(3,(fp, "[Note: Perfect 4x4x4x4 texture format]\n")); + DPRINTF3D(3,(fp, "[Note: Perfect 4x4x4x4 texture format]\n")); CopyMemory(&renderer->ddpfTextureFormat4x4x4x4, ddpf, sizeof(*ddpf)); renderer->fTextureFound4x4x4x4 = TRUE; return DDENUMRET_OK; @@ -482,23 +482,23 @@ ddpf->dwBBitMask == 0x001F) { if(ddpf->dwFlags & DDPF_ALPHAPIXELS) { if(ddpf->dwRGBAlphaBitMask == 0x8000) { - DPRINTF(3,(fp, "[Note: Perfect 1x5x5x5 texture format]\n")); + DPRINTF3D(3,(fp, "[Note: Perfect 1x5x5x5 texture format]\n")); CopyMemory(&renderer->ddpfTextureFormat1x5x5x5, ddpf, sizeof(*ddpf)); renderer->fTextureFound1x5x5x5 = TRUE; } } else { - DPRINTF(3,(fp, "[Note: Perfect 0x5x5x5 texture format]\n")); + DPRINTF3D(3,(fp, "[Note: Perfect 0x5x5x5 texture format]\n")); CopyMemory(&renderer->ddpfTextureFormat0x5x5x5, ddpf, sizeof(*ddpf)); renderer->fTextureFound0x5x5x5 = TRUE; } } else { if(ddpf->dwFlags & DDPF_ALPHAPIXELS) { - DPRINTF(3,(fp, "[Note: Lousy 1x5x5x5 texture format]\n")); + DPRINTF3D(3,(fp, "[Note: Lousy 1x5x5x5 texture format]\n")); if(renderer->fTextureFound1x5x5x5) return DDENUMRET_OK; CopyMemory(&renderer->ddpfTextureFormat1x5x5x5, ddpf, sizeof(*ddpf)); renderer->fTextureFound1x5x5x5 = TRUE; } else { - DPRINTF(3,(fp, "[Note: Lousy 0x5x5x5 texture format]\n")); + DPRINTF3D(3,(fp, "[Note: Lousy 0x5x5x5 texture format]\n")); if(renderer->fTextureFound0x5x5x5) return DDENUMRET_OK; CopyMemory(&renderer->ddpfTextureFormat0x5x5x5, ddpf, sizeof(*ddpf)); renderer->fTextureFound0x5x5x5 = TRUE; @@ -507,33 +507,33 @@ } /* Check for 32bit textures */ if( (ddpf->dwRGBBitCount == 32) && (ddpf->dwFlags & DDPF_RGB)) { - DPRINTF(3,(fp, "\nTexture: 32bit RGB\n")); - DPRINTF(3,(fp, "Red mask: %x\n", ddpf->dwRBitMask)); - DPRINTF(3,(fp, "Green mask: %x\n", ddpf->dwGBitMask)); - DPRINTF(3,(fp, "Blue mask: %x\n", ddpf->dwBBitMask)); - DPRINTF(3,(fp, "Alpha mask: %x\n", ddpf->dwRGBAlphaBitMask)); + DPRINTF3D(3,(fp, "\nTexture: 32bit RGB\n")); + DPRINTF3D(3,(fp, "Red mask: %x\n", ddpf->dwRBitMask)); + DPRINTF3D(3,(fp, "Green mask: %x\n", ddpf->dwGBitMask)); + DPRINTF3D(3,(fp, "Blue mask: %x\n", ddpf->dwBBitMask)); + DPRINTF3D(3,(fp, "Alpha mask: %x\n", ddpf->dwRGBAlphaBitMask)); if(ddpf->dwRBitMask == 0x00FF0000 && ddpf->dwGBitMask == 0x0000FF00 && ddpf->dwBBitMask == 0x000000FF) { if(ddpf->dwFlags & DDPF_ALPHAPIXELS) { if(ddpf->dwRGBAlphaBitMask == 0xFF000000) { - DPRINTF(3,(fp, "[Note: Perfect 8x8x8x8 texture format]\n")); + DPRINTF3D(3,(fp, "[Note: Perfect 8x8x8x8 texture format]\n")); CopyMemory(&renderer->ddpfTextureFormat8x8x8x8, ddpf, sizeof(*ddpf)); renderer->fTextureFound8x8x8x8 = TRUE; } } else { - DPRINTF(3,(fp, "[Note: Perfect 0x8x8x8 texture format]\n")); + DPRINTF3D(3,(fp, "[Note: Perfect 0x8x8x8 texture format]\n")); CopyMemory(&renderer->ddpfTextureFormat0x8x8x8, ddpf, sizeof(*ddpf)); renderer->fTextureFound0x8x8x8 = TRUE; } } else { if(ddpf->dwFlags & DDPF_ALPHAPIXELS) { - DPRINTF(3,(fp, "[Note: Lousy 8x8x8x8 texture format]\n")); + DPRINTF3D(3,(fp, "[Note: Lousy 8x8x8x8 texture format]\n")); if(renderer->fTextureFound8x8x8x8) return DDENUMRET_OK; CopyMemory(&renderer->ddpfTextureFormat8x8x8x8, ddpf, sizeof(*ddpf)); renderer->fTextureFound0x8x8x8 = TRUE; } else { - DPRINTF(3,(fp, "[Note: Lousy 0x8x8x8 texture format]\n")); + DPRINTF3D(3,(fp, "[Note: Lousy 0x8x8x8 texture format]\n")); if(renderer->fTextureFound0x5x5x5) return DDENUMRET_OK; CopyMemory(&renderer->ddpfTextureFormat0x8x8x8, ddpf, sizeof(*ddpf)); renderer->fTextureFound0x8x8x8 = TRUE; @@ -559,19 +559,19 @@ ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY; hRes = lpDD->lpVtbl->GetAvailableVidMem(lpDD, &ddsCaps, &dwTotal, &dwFree); ERROR_CHECK; - DPRINTF(3,(fp,"Video memory: %d (available total) %d (available free)\n", + DPRINTF3D(3,(fp,"Video memory: %d (available total) %d (available free)\n", dwTotal, dwFree)); dwTotal = dwFree = 0; ddsCaps.dwCaps = DDSCAPS_TEXTURE; hRes = lpDD->lpVtbl->GetAvailableVidMem(lpDD, &ddsCaps, &dwTotal, &dwFree); ERROR_CHECK; - DPRINTF(3,(fp,"Texture memory: %d (available total) %d (available free)\n", + DPRINTF3D(3,(fp,"Texture memory: %d (available total) %d (available free)\n", dwTotal, dwFree)); dwTotal = dwFree = 0; ddsCaps.dwCaps = DDSCAPS_ZBUFFER; hRes = lpDD->lpVtbl->GetAvailableVidMem(lpDD, &ddsCaps, &dwTotal, &dwFree); ERROR_CHECK; - DPRINTF(3,(fp,"Z-Buffer memory: %d (available total) %d (available free)\n", + DPRINTF3D(3,(fp,"Z-Buffer memory: %d (available total) %d (available free)\n", dwTotal, dwFree)); } @@ -582,9 +582,9 @@ int d3dInitializePrimary(void) { HRESULT hRes; - DPRINTF(5,(fp, "[Initializing primary surface]\n")); + DPRINTF3D(5,(fp, "[Initializing primary surface]\n")); if(!lpDD) { - DPRINTF(5,(fp, "[Creating DDraw object]\n")); + DPRINTF3D(5,(fp, "[Creating DDraw object]\n")); hRes = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, @@ -593,14 +593,14 @@ ERROR_CHECK; if(FAILED(hRes)) return 0; if(!lpDD) { - DPRINTF(1,(fp,"ERROR: Could not create IDirectDraw7\n")); + DPRINTF3D(1,(fp,"ERROR: Could not create IDirectDraw7\n")); return 0; } - DPRINTF(5,(fp, "[Initializing DDraw object]\n")); + DPRINTF3D(5,(fp, "[Initializing DDraw object]\n")); hRes = lpDD->lpVtbl->Initialize(lpDD, NULL); ERROR_CHECK; if(FAILED(hRes)) return 0; - DPRINTF(5,(fp, "[Setting cooperation level]\n")); + DPRINTF3D(5,(fp, "[Setting cooperation level]\n")); hRes = lpDD->lpVtbl-> SetCooperativeLevel(lpDD, *theSTWindow, DDSCL_NORMAL | DDSCL_FPUPRESERVE); @@ -609,12 +609,12 @@ } if(!lpD3D) { /* query for the direct3d object */ - DPRINTF(5,(fp, "[Querying for IDirect3D7]\n")); + DPRINTF3D(5,(fp, "[Querying for IDirect3D7]\n")); hRes = lpDD->lpVtbl->QueryInterface(lpDD,&IID_IDirect3D7, (LPVOID*)&lpD3D); ERROR_CHECK; if(FAILED(hRes)) return 0; if(!lpD3D) { - DPRINTF(1,(fp,"ERROR: Could not retrieve IDirect3D7\n")); + DPRINTF3D(1,(fp,"ERROR: Could not retrieve IDirect3D7\n")); return 0; } } @@ -626,12 +626,12 @@ ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - DPRINTF(5,(fp, "[Creating primary surface]\n")); + DPRINTF3D(5,(fp, "[Creating primary surface]\n")); hRes = lpDD->lpVtbl->CreateSurface( lpDD, &ddsd, &lpddPrimary, NULL ); ERROR_CHECK; if (FAILED(hRes)) return 0; if(!lpddPrimary) { - DPRINTF(1,(fp,"ERROR: Could not create primary surface\n")); + DPRINTF3D(1,(fp,"ERROR: Could not create primary surface\n")); return 0; } } @@ -643,12 +643,12 @@ * outside the visible region of the window. */ if(!lpddClipper) { - DPRINTF(5,(fp, "[Creating clipper]\n")); + DPRINTF3D(5,(fp, "[Creating clipper]\n")); hRes = lpDD->lpVtbl->CreateClipper(lpDD, 0UL, &lpddClipper, NULL); ERROR_CHECK; if(FAILED(hRes)) return 0; if(!lpddClipper) { - DPRINTF(1,(fp,"ERROR: Could not create clipper\n")); + DPRINTF3D(1,(fp,"ERROR: Could not create clipper\n")); return 0; } hRes = lpddClipper->lpVtbl->SetHWnd(lpddClipper, 0UL, *theSTWindow); @@ -685,18 +685,18 @@ displayDesc.dwSize = sizeof(displayDesc); hRes = lpDD->lpVtbl->GetDisplayMode(lpDD, &displayDesc); if(FAILED(hRes)) { - DPRINTF(1,(fp, "ERROR: Failed to get current display mode (errCode=%X)\n",hRes)); + DPRINTF3D(1,(fp, "ERROR: Failed to get current display mode (errCode=%X)\n",hRes)); goto cleanup; } - DPRINTF(3,(fp,"Current display width: %d\n",displayDesc.dwWidth)); - DPRINTF(3,(fp,"Current display height: %d\n",displayDesc.dwHeight)); - DPRINTF(3,(fp,"Current display depth: %d\n",displayDesc.ddpfPixelFormat.dwRGBBitCount)); + DPRINTF3D(3,(fp,"Current display width: %d\n",displayDesc.dwWidth)); + DPRINTF3D(3,(fp,"Current display height: %d\n",displayDesc.dwHeight)); + DPRINTF3D(3,(fp,"Current display depth: %d\n",displayDesc.ddpfPixelFormat.dwRGBBitCount)); /* Set the display depth bit */ switch(displayDesc.ddpfPixelFormat.dwRGBBitCount) { case 16: dwDisplayBitDepth = DDBD_16; break; case 32: dwDisplayBitDepth = DDBD_32; break; default: - DPRINTF(1,(fp, "ERROR: Display depth %d is not supported\n", + DPRINTF3D(1,(fp, "ERROR: Display depth %d is not supported\n", displayDesc.ddpfPixelFormat.dwRGBBitCount)); goto cleanup; /* we only deal with 16-32 bit */ }; @@ -715,7 +715,7 @@ return 0; } - DPRINTF(3, (fp, "### Using %s\n(%s)\n", + DPRINTF3D(3, (fp, "### Using %s\n(%s)\n", renderer->szDeviceName, renderer->szDeviceDesc)); /* enumerate z-buffer formats and find a nice one */ @@ -758,7 +758,7 @@ hRes = lpDD->lpVtbl->CreateSurface(lpDD, &ddsd, &lpdsZBuffer, NULL); if (FAILED(hRes)) { /* Scond try in system memory */ - DPRINTF(2,(fp,"WARNING: Failed to create VRAM z-buffer (errCode=%X)\n",hRes)); + DPRINTF3D(2,(fp,"WARNING: Failed to create VRAM z-buffer (errCode=%X)\n",hRes)); ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY; hRes = lpDD->lpVtbl->CreateSurface(lpDD, &ddsd, &lpdsZBuffer, NULL); } @@ -852,16 +852,16 @@ d3dRenderer *renderer; if(flags & ~SUPPORTED_FLAGS) { - DPRINTF(1, (fp, "ERROR: Unsupported flags requested( %d)\n", flags)); + DPRINTF3D(1, (fp, "ERROR: Unsupported flags requested( %d)\n", flags)); return -1; } - DPRINTF(3, (fp, "---- Initializing D3D ----\n")); + DPRINTF3D(3, (fp, "---- Initializing D3D ----\n")); for(i=0; i < MAX_RENDERER; i++) { if(allRenderer[i].fUsed == 0) break; } if(i >= MAX_RENDERER) { - DPRINTF(1, (fp, "ERROR: Maximum number of renderers (%d) exceeded\n", MAX_RENDERER)); + DPRINTF3D(1, (fp, "ERROR: Maximum number of renderers (%d) exceeded\n", MAX_RENDERER)); return -1; } index = i; @@ -886,7 +886,7 @@ if(!(*registerSurface)((int)renderer->lpdsTarget, &d3dTargetDispatch, &renderer->surfaceID)) { d3dReleaseRenderer(renderer); - DPRINTF(1,(fp,"ERROR: Failed to register rendering target\n")); + DPRINTF3D(1,(fp,"ERROR: Failed to register rendering target\n")); return -1; } /* all fine now */ @@ -1133,7 +1133,7 @@ if(w & (w-1)) return -1; /* not power of two */ if(h & (h-1)) return -1; /* not power of two */ - DPRINTF(5, (fp, "### Allocating new texture (w = %d, h = %d, d = %d)\n", w, h, d)); + DPRINTF3D(5, (fp, "### Allocating new texture (w = %d, h = %d, d = %d)\n", w, h, d)); /* fill in basic surface structure */ ZeroMemory( &ddsd, sizeof(DDSURFACEDESC2) ); @@ -1169,7 +1169,7 @@ /* register texture */ if(!(*registerSurface)((int)lpdsTexture, &d3dTextureDispatch, &surfaceID)) { RELEASE(lpdsTexture); - DPRINTF(1,(fp,"ERROR: Failed to register texture\n")); + DPRINTF3D(1,(fp,"ERROR: Failed to register texture\n")); return -1; } return surfaceID; @@ -1239,7 +1239,7 @@ LPDIRECTDRAWSURFACE7 lpdsTexture; /* Look if the surface was registered as D3D surface */ if(!(*findSurface)(handle, &d3dTextureDispatch, (int*) (&lpdsTexture))) { - DPRINTF(3, (fp, "WARNING: Texture (%d) not registered\n", handle)); + DPRINTF3D(3, (fp, "WARNING: Texture (%d) not registered\n", handle)); return -1; } return handle; @@ -1272,8 +1272,8 @@ if(!renderer) return 0; lpDevice = renderer->lpDevice; - DPRINTF(5, (fp, "### New Viewport\n")); - DPRINTF(5, (fp, "\tx: %d\n\ty: %d\n\tw: %d\n\th: %d\n", x, y, w, h)); + DPRINTF3D(5, (fp, "### New Viewport\n")); + DPRINTF3D(5, (fp, "\tx: %d\n\ty: %d\n\tw: %d\n\th: %d\n", x, y, w, h)); renderer->viewport[0] = x; renderer->viewport[1] = y; renderer->viewport[2] = w; @@ -1331,7 +1331,7 @@ lpdsTarget = renderer->lpdsTarget; if(renderer->fSceneStarted) { - DPRINTF(5,(fp,"Ending current scene\n")); + DPRINTF3D(5,(fp,"Ending current scene\n")); hRes = lpDevice->lpVtbl->EndScene(lpDevice); ERROR_CHECK; renderer->fSceneStarted = 0; @@ -1353,7 +1353,7 @@ lpDevice = renderer->lpDevice; if(renderer->fSceneStarted) { - DPRINTF(5,(fp,"Ending current scene\n")); + DPRINTF3D(5,(fp,"Ending current scene\n")); hRes = lpDevice->lpVtbl->EndScene(lpDevice); ERROR_CHECK; renderer->fSceneStarted = 0; @@ -1413,7 +1413,7 @@ if(!fClipperAttached) { hRes = lpddPrimary->lpVtbl->SetClipper(lpddPrimary, lpddClipper); if(FAILED(hRes)) { - DPRINTF(2,(fp,"WARNING: Failed to attach clipper (errCode=%X)\n",hRes)); + DPRINTF3D(2,(fp,"WARNING: Failed to attach clipper (errCode=%X)\n",hRes)); } else { fClipperAttached = 1; } @@ -1423,7 +1423,7 @@ if(fClipperAttached) { hRes = lpddPrimary->lpVtbl->SetClipper(lpddPrimary, NULL); if(FAILED(hRes)) { - DPRINTF(2,(fp,"WARNING: Failed to detach clipper (errCode=%X)\n",hRes)); + DPRINTF3D(2,(fp,"WARNING: Failed to detach clipper (errCode=%X)\n",hRes)); } else { fClipperAttached = 0; } @@ -1434,7 +1434,7 @@ (meaning there's lots of stuff to clip). Attach it. */ hRes = lpddPrimary->lpVtbl->SetClipper(lpddPrimary, lpddClipper); if(FAILED(hRes)) { - DPRINTF(2,(fp,"WARNING: Failed to attach clipper (errCode=%X)\n",hRes)); + DPRINTF3D(2,(fp,"WARNING: Failed to attach clipper (errCode=%X)\n",hRes)); } else { fClipperAttached = 1; } @@ -1489,7 +1489,7 @@ BltFast(lpddPrimary, dstRect.left, dstRect.top, lpddSurface, &dxRect, DDBLTFAST_WAIT | DDBLTFAST_NOCOLORKEY); if(FAILED(hRes)) { - DPRINTF(2,(fp,"WARNING: IDirectDrawSurface::BltFast() failed (errCode=%X)\n",hRes)); + DPRINTF3D(2,(fp,"WARNING: IDirectDrawSurface::BltFast() failed (errCode=%X)\n",hRes)); } } if(fClipperAttached || FAILED(hRes)) { @@ -1499,7 +1499,7 @@ Blt(lpddPrimary,&dstRect,lpddSurface, &dxRect, DDBLT_WAIT, NULL); } if(FAILED(hRes)) { - DPRINTF(1,(fp,"ERROR: Failed to blt to primary surface (errCode=%X)\n",hRes)); + DPRINTF3D(1,(fp,"ERROR: Failed to blt to primary surface (errCode=%X)\n",hRes)); return 0; } #if 0 @@ -1529,7 +1529,7 @@ if(!renderer) return 0; lpDevice = renderer->lpDevice; - DPRINTF(5, (fp, "### Installing new transformations\n")); + DPRINTF3D(5, (fp, "### Installing new transformations\n")); if(modelViewMatrix) { m = modelViewMatrix; d._11 = *m++; d._21 = *m++; d._31 = *m++; d._41 = *m++; @@ -1556,19 +1556,19 @@ SetTransform(lpDevice, D3DTRANSFORMSTATE_PROJECTION, &d); ERROR_CHECK; #if 0 - DPRINTF(1, (fp, "Projection matrix before:\n")); - DPRINTF(1, (fp, "\t%g\t%g\t%g\t%g\n", d._11, d._12,d._13,d._14)); - DPRINTF(1, (fp, "\t%g\t%g\t%g\t%g\n", d._21, d._22,d._23,d._24)); - DPRINTF(1, (fp, "\t%g\t%g\t%g\t%g\n", d._31, d._32,d._33,d._34)); - DPRINTF(1, (fp, "\t%g\t%g\t%g\t%g\n", d._41, d._42,d._43,d._44)); + DPRINTF3D(1, (fp, "Projection matrix before:\n")); + DPRINTF3D(1, (fp, "\t%g\t%g\t%g\t%g\n", d._11, d._12,d._13,d._14)); + DPRINTF3D(1, (fp, "\t%g\t%g\t%g\t%g\n", d._21, d._22,d._23,d._24)); + DPRINTF3D(1, (fp, "\t%g\t%g\t%g\t%g\n", d._31, d._32,d._33,d._34)); + DPRINTF3D(1, (fp, "\t%g\t%g\t%g\t%g\n", d._41, d._42,d._43,d._44)); hRes = lpDevice->lpVtbl-> GetTransform(lpDevice, D3DTRANSFORMSTATE_PROJECTION, &d); ERROR_CHECK; - DPRINTF(1, (fp, "Projection matrix after:\n")); - DPRINTF(1, (fp, "\t%g\t%g\t%g\t%g\n", d._11, d._12,d._13,d._14)); - DPRINTF(1, (fp, "\t%g\t%g\t%g\t%g\n", d._21, d._22,d._23,d._24)); - DPRINTF(1, (fp, "\t%g\t%g\t%g\t%g\n", d._31, d._32,d._33,d._34)); - DPRINTF(1, (fp, "\t%g\t%g\t%g\t%g\n", d._41, d._42,d._43,d._44)); + DPRINTF3D(1, (fp, "Projection matrix after:\n")); + DPRINTF3D(1, (fp, "\t%g\t%g\t%g\t%g\n", d._11, d._12,d._13,d._14)); + DPRINTF3D(1, (fp, "\t%g\t%g\t%g\t%g\n", d._21, d._22,d._23,d._24)); + DPRINTF3D(1, (fp, "\t%g\t%g\t%g\t%g\n", d._31, d._32,d._33,d._34)); + DPRINTF3D(1, (fp, "\t%g\t%g\t%g\t%g\n", d._41, d._42,d._43,d._44)); #endif return 1; } @@ -1581,7 +1581,7 @@ if(!renderer) return 0; lpDevice = renderer->lpDevice; - DPRINTF(5, (fp, "### Disabling all lights\n")); + DPRINTF3D(5, (fp, "### Disabling all lights\n")); for(i = 0; i <= renderer->maxLights; i++) { hRes = lpDevice->lpVtbl->LightEnable(lpDevice, i, FALSE); @@ -1601,27 +1601,27 @@ if(!renderer) return 0; lpDevice = renderer->lpDevice; - DPRINTF(5, (fp, "### New Material\n")); + DPRINTF3D(5, (fp, "### New Material\n")); if(!mat) { - DPRINTF(5, (fp, "\tOFF (material == nil)\n")); + DPRINTF3D(5, (fp, "\tOFF (material == nil)\n")); hRes = lpDevice->lpVtbl-> SetRenderState(lpDevice, D3DRENDERSTATE_LIGHTING, FALSE); ERROR_CHECK; return 1; } - DPRINTF(5, (fp, "\tambient : %g, %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tambient : %g, %g, %g, %g\n", mat->ambient[0], mat->ambient[1], mat->ambient[2], mat->ambient[3])); - DPRINTF(5, (fp, "\tdiffuse : %g, %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tdiffuse : %g, %g, %g, %g\n", mat->diffuse[0], mat->diffuse[1], mat->diffuse[2], mat->diffuse[3])); - DPRINTF(5, (fp, "\tspecular : %g, %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tspecular : %g, %g, %g, %g\n", mat->specular[0], mat->specular[1], mat->specular[2], mat->specular[3])); - DPRINTF(5, (fp, "\temission : %g, %g, %g, %g\n", + DPRINTF3D(5, (fp, "\temission : %g, %g, %g, %g\n", mat->emission[0], mat->emission[1], mat->emission[2], mat->emission[3])); - DPRINTF(5, (fp, "\tshininess: %g\n", mat->shininess)); + DPRINTF3D(5, (fp, "\tshininess: %g\n", mat->shininess)); hRes = lpDevice->lpVtbl-> SetRenderState(lpDevice, D3DRENDERSTATE_LIGHTING, TRUE); @@ -1661,10 +1661,10 @@ if(idx < 0) return 0; lpDevice = renderer->lpDevice; - DPRINTF(5, (fp, "### New Light (%d)\n", idx)); + DPRINTF3D(5, (fp, "### New Light (%d)\n", idx)); if(!light) { - DPRINTF(5, (fp, "\tDISABLED\n")); + DPRINTF3D(5, (fp, "\tDISABLED\n")); hRes = lpDevice->lpVtbl->LightEnable(lpDevice, idx, FALSE); ERROR_CHECK; return 1; @@ -1672,44 +1672,44 @@ if(idx > renderer->maxLights) renderer->maxLights = idx; - DPRINTF(5, (fp, "\tambient : %g, %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tambient : %g, %g, %g, %g\n", light->ambient[0], light->ambient[1], light->ambient[2], light->ambient[3])); - DPRINTF(5, (fp, "\tdiffuse : %g, %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tdiffuse : %g, %g, %g, %g\n", light->diffuse[0], light->diffuse[1], light->diffuse[2], light->diffuse[3])); - DPRINTF(5, (fp, "\tspecular : %g, %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tspecular : %g, %g, %g, %g\n", light->specular[0], light->specular[1], light->specular[2], light->specular[3])); - DPRINTF(5, (fp, "\tposition : %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tposition : %g, %g, %g\n", light->position[0], light->position[1], light->position[2])); - DPRINTF(5, (fp, "\tdirection : %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tdirection : %g, %g, %g\n", light->direction[0], light->direction[1], light->direction[2])); - DPRINTF(5, (fp, "\tattenuation : %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tattenuation : %g, %g, %g\n", light->attenuation[0], light->attenuation[1], light->attenuation[2])); - DPRINTF(5, (fp, "\tflags [%d]:", light->flags)); + DPRINTF3D(5, (fp, "\tflags [%d]:", light->flags)); if(light->flags & B3D_LIGHT_AMBIENT) - DPRINTF(5,(fp," B3D_LIGHT_AMBIENT")); + DPRINTF3D(5,(fp," B3D_LIGHT_AMBIENT")); if(light->flags & B3D_LIGHT_DIFFUSE) - DPRINTF(5,(fp," B3D_LIGHT_DIFFUSE")); + DPRINTF3D(5,(fp," B3D_LIGHT_DIFFUSE")); if(light->flags & B3D_LIGHT_SPECULAR) - DPRINTF(5,(fp," B3D_LIGHT_SPECULAR")); + DPRINTF3D(5,(fp," B3D_LIGHT_SPECULAR")); if(light->flags & B3D_LIGHT_POSITIONAL) - DPRINTF(5,(fp," B3D_LIGHT_POSITIONAL")); + DPRINTF3D(5,(fp," B3D_LIGHT_POSITIONAL")); if(light->flags & B3D_LIGHT_DIRECTIONAL) - DPRINTF(5,(fp," B3D_LIGHT_DIRECTIONAL")); + DPRINTF3D(5,(fp," B3D_LIGHT_DIRECTIONAL")); if(light->flags & B3D_LIGHT_ATTENUATED) - DPRINTF(5,(fp," B3D_LIGHT_ATTENUATED")); + DPRINTF3D(5,(fp," B3D_LIGHT_ATTENUATED")); if(light->flags & B3D_LIGHT_HAS_SPOT) - DPRINTF(5,(fp," B3D_LIGHT_HAS_SPOT")); - DPRINTF(5, (fp, "\n")); - DPRINTF(5, (fp, "\tspot exponent : %g\n", light->spotExponent)); + DPRINTF3D(5,(fp," B3D_LIGHT_HAS_SPOT")); + DPRINTF3D(5, (fp, "\n")); + DPRINTF3D(5, (fp, "\tspot exponent : %g\n", light->spotExponent)); - DPRINTF(5, (fp, "### Installing Light (%d)\n", idx)); + DPRINTF3D(5, (fp, "### Installing Light (%d)\n", idx)); memset(&d3dLight, 0, sizeof(d3dLight)); if(light->flags & B3D_LIGHT_AMBIENT) { - DPRINTF(5, (fp, "\tambient : %g, %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tambient : %g, %g, %g, %g\n", light->ambient[0], light->ambient[1], light->ambient[2], light->ambient[3])); d3dLight.dcvAmbient.r = light->ambient[0]; @@ -1717,11 +1717,11 @@ d3dLight.dcvAmbient.b = light->ambient[2]; d3dLight.dcvAmbient.a = light->ambient[3]; } else { - DPRINTF(5, (fp, "\tambient : OFF (0, 0, 0, 1)\n")); + DPRINTF3D(5, (fp, "\tambient : OFF (0, 0, 0, 1)\n")); } if(light->flags & B3D_LIGHT_DIFFUSE) { - DPRINTF(5, (fp, "\tdiffuse : %g, %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tdiffuse : %g, %g, %g, %g\n", light->diffuse[0], light->diffuse[1], light->diffuse[2], light->diffuse[3])); d3dLight.dcvDiffuse.r = light->diffuse[0]; @@ -1729,11 +1729,11 @@ d3dLight.dcvDiffuse.b = light->diffuse[2]; d3dLight.dcvDiffuse.a = light->diffuse[3]; } else { - DPRINTF(5, (fp, "\tdiffuse : OFF (0, 0, 0, 1)\n")); + DPRINTF3D(5, (fp, "\tdiffuse : OFF (0, 0, 0, 1)\n")); } if(light->flags & B3D_LIGHT_SPECULAR) { - DPRINTF(5, (fp, "\tspecular : %g, %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tspecular : %g, %g, %g, %g\n", light->specular[0], light->specular[1], light->specular[2], light->specular[3])); d3dLight.dcvSpecular.r = light->specular[0]; @@ -1741,11 +1741,11 @@ d3dLight.dcvSpecular.b = light->specular[2]; d3dLight.dcvSpecular.a = light->specular[3]; } else { - DPRINTF(5, (fp, "\tspecular : OFF (0, 0, 0, 1)\n")); + DPRINTF3D(5, (fp, "\tspecular : OFF (0, 0, 0, 1)\n")); } if(light->flags & B3D_LIGHT_POSITIONAL) { - DPRINTF(5, (fp, "\tposition : %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tposition : %g, %g, %g\n", light->position[0], light->position[1], light->position[2])); d3dLight.dltType = D3DLIGHT_POINT; d3dLight.dvPosition.x = light->position[0]; @@ -1753,7 +1753,7 @@ d3dLight.dvPosition.z = light->position[2]; } else { if(light->flags & B3D_LIGHT_DIRECTIONAL) { - DPRINTF(5, (fp, "\tdirection: %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tdirection: %g, %g, %g\n", light->direction[0], light->direction[1], light->direction[2])); d3dLight.dltType = D3DLIGHT_DIRECTIONAL; @@ -1764,21 +1764,21 @@ } if(light->flags & B3D_LIGHT_ATTENUATED) { - DPRINTF(5, (fp, "\tattenuation: %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tattenuation: %g, %g, %g\n", light->attenuation[0], light->attenuation[1], light->attenuation[2])); d3dLight.dvAttenuation0 = light->attenuation[0]; d3dLight.dvAttenuation1 = light->attenuation[1]; d3dLight.dvAttenuation2 = light->attenuation[2]; } else { - DPRINTF(5, (fp, "\tattenuation: OFF (1, 0, 0)\n")); + DPRINTF3D(5, (fp, "\tattenuation: OFF (1, 0, 0)\n")); d3dLight.dvAttenuation0 = 1.0; } if(light->flags & B3D_LIGHT_HAS_SPOT) { - DPRINTF(5, (fp, "\tspot exponent : %g\n", light->spotExponent)); - DPRINTF(5, (fp, "\tspot cutoff : ???\n")); - DPRINTF(5, (fp, "\tspot direction: %g, %g, %g\n", + DPRINTF3D(5, (fp, "\tspot exponent : %g\n", light->spotExponent)); + DPRINTF3D(5, (fp, "\tspot cutoff : ???\n")); + DPRINTF3D(5, (fp, "\tspot direction: %g, %g, %g\n", light->direction[0], light->direction[1], light->direction[2])); d3dLight.dltType = D3DLIGHT_SPOT; @@ -1788,8 +1788,8 @@ d3dLight.dvFalloff = light->spotExponent; d3dLight.dvPhi = (float) acos(light->spotMinCos); d3dLight.dvTheta = (float) acos(light->spotMaxCos); - DPRINTF(5, (fp, "\tdvPhi: %g\n", d3dLight.dvPhi)); - DPRINTF(5, (fp, "\tdvTheta: %g\n", d3dLight.dvTheta)); + DPRINTF3D(5, (fp, "\tdvPhi: %g\n", d3dLight.dvPhi)); + DPRINTF3D(5, (fp, "\tdvTheta: %g\n", d3dLight.dvTheta)); } d3dLight.dvRange = D3DLIGHT_RANGE_MAX; @@ -1919,20 +1919,20 @@ renderer->fSceneStarted = 1; } - DPRINTF(5, (fp,"### Primitive : %d\n", primType)); - DPRINTF(5, (fp,"\ttexHandle : %d\n", texHandle)); - DPRINTF(5, (fp,"\tcolor flags :")); - if(flags & B3D_VB_TRACK_AMBIENT) DPRINTF(5,(fp," B3D_VB_TRACK_AMBIENT")); - if(flags & B3D_VB_TRACK_DIFFUSE) DPRINTF(5,(fp," B3D_VB_TRACK_DIFFUSE")); - if(flags & B3D_VB_TRACK_SPECULAR) DPRINTF(5,(fp," B3D_VB_TRACK_SPECULAR")); - if(flags & B3D_VB_TRACK_EMISSION) DPRINTF(5,(fp," B3D_VB_TRACK_EMISSION")); - DPRINTF(5, (fp,"\n\tlight flags :")); - if(flags & B3D_VB_LOCAL_VIEWER) DPRINTF(5,(fp," B3D_VB_LOCAL_VIEWER")); - if(flags & B3D_VB_TWO_SIDED) DPRINTF(5,(fp," B3D_VB_TWO_SIDED")); - DPRINTF(5, (fp,"\n\tvertex flags:")); - if(flags & B3D_VB_HAS_NORMALS) DPRINTF(5,(fp," B3D_VB_HAS_NORMALS")); - if(flags & B3D_VB_HAS_TEXTURES) DPRINTF(5,(fp," B3D_VB_HAS_TEXTURES")); - DPRINTF(5, (fp, "\n")); + DPRINTF3D(5, (fp,"### Primitive : %d\n", primType)); + DPRINTF3D(5, (fp,"\ttexHandle : %d\n", texHandle)); + DPRINTF3D(5, (fp,"\tcolor flags :")); + if(flags & B3D_VB_TRACK_AMBIENT) DPRINTF3D(5,(fp," B3D_VB_TRACK_AMBIENT")); + if(flags & B3D_VB_TRACK_DIFFUSE) DPRINTF3D(5,(fp," B3D_VB_TRACK_DIFFUSE")); + if(flags & B3D_VB_TRACK_SPECULAR) DPRINTF3D(5,(fp," B3D_VB_TRACK_SPECULAR")); + if(flags & B3D_VB_TRACK_EMISSION) DPRINTF3D(5,(fp," B3D_VB_TRACK_EMISSION")); + DPRINTF3D(5, (fp,"\n\tlight flags :")); + if(flags & B3D_VB_LOCAL_VIEWER) DPRINTF3D(5,(fp," B3D_VB_LOCAL_VIEWER")); + if(flags & B3D_VB_TWO_SIDED) DPRINTF3D(5,(fp," B3D_VB_TWO_SIDED")); + DPRINTF3D(5, (fp,"\n\tvertex flags:")); + if(flags & B3D_VB_HAS_NORMALS) DPRINTF3D(5,(fp," B3D_VB_HAS_NORMALS")); + if(flags & B3D_VB_HAS_TEXTURES) DPRINTF3D(5,(fp," B3D_VB_HAS_TEXTURES")); + DPRINTF3D(5, (fp, "\n")); /* process VB flags */ tracking = FALSE; @@ -1981,7 +1981,7 @@ if(texHandle >= 0 && (flags & B3D_VB_HAS_TEXTURES)) { /* Look if the surface was registered as D3D surface */ if(!(*findSurface)(texHandle, &d3dTextureDispatch, (int*) (&lpdsTexture))) { - DPRINTF(4, (fp,"WARNING: Texture (%d) not registered\n", texHandle)); + DPRINTF3D(4, (fp,"WARNING: Texture (%d) not registered\n", texHandle)); lpdsTexture = NULL; } } else { @@ -2160,37 +2160,37 @@ hRes = CoInitialize(NULL); if(FAILED(hRes)) { - DPRINTF(1, (fp, "ERROR: Failed to CoInitialize\n")); + DPRINTF3D(1, (fp, "ERROR: Failed to CoInitialize\n")); return 0; } /* lookup the necessary things from interpreter */ theSTWindow = (HWND*) interpreterProxy->ioLoadFunctionFrom("stWindow",""); if(!theSTWindow) { - DPRINTF(1,(fp,"ERROR: Failed to look up stWindow\n")); + DPRINTF3D(1,(fp,"ERROR: Failed to look up stWindow\n")); return 0; } registerSurface = (fn_ioRegisterSurface) interpreterProxy->ioLoadFunctionFrom("ioRegisterSurface","SurfacePlugin"); if(!registerSurface) { - DPRINTF(1,(fp,"ERROR: Failed to look up ioRegisterSurface()\n")); + DPRINTF3D(1,(fp,"ERROR: Failed to look up ioRegisterSurface()\n")); return 0; } unregisterSurface = (fn_ioUnregisterSurface) interpreterProxy->ioLoadFunctionFrom("ioUnregisterSurface","SurfacePlugin"); if(!unregisterSurface) { - DPRINTF(1,(fp,"ERROR: Failed to look up ioUnregisterSurface()\n")); + DPRINTF3D(1,(fp,"ERROR: Failed to look up ioUnregisterSurface()\n")); return 0; } findSurface = (fn_ioFindSurface) interpreterProxy->ioLoadFunctionFrom("ioFindSurface","SurfacePlugin"); if(!findSurface) { - DPRINTF(1,(fp,"ERROR: Failed to look up ioFindSurface()\n")); + DPRINTF3D(1,(fp,"ERROR: Failed to look up ioFindSurface()\n")); return 0; } preMessageHook = (messageHook*) interpreterProxy->ioLoadFunctionFrom("preMessageHook",""); if(!preMessageHook) { - DPRINTF(1,(fp,"ERROR: Failed to look up preMessageHook()\n")); + DPRINTF3D(1,(fp,"ERROR: Failed to look up preMessageHook()\n")); return 0; } nextPreMessageHook = *preMessageHook; Modified: trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.c =================================================================== --- trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.c 2011-06-09 07:00:37 UTC (rev 2404) +++ trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.c 2011-06-09 07:33:56 UTC (rev 2405) @@ -1,12 +1,11 @@ /**************************************************************************** -* PROJECT: Squeak 3D accelerator * FILE: sqWin32OpenGL.c * CONTENT: Win32 specific bindings for OpenGL * * AUTHOR: Andreas Raab (ar) * ADDRESS: Walt Disney Imagineering, Glendale, CA * EMAIL: [hidden email] -* RCSID: $Id: sqWin32OpenGL.c,v 1.7 2002/09/05 19:30:45 andreasraab Exp $ +* RCSID: $Id$ * * NOTES: * @@ -30,11 +29,56 @@ #define PFD_SUPPORT_DIRECTDRAW 0x00002000 #endif +/* Constants for wgl ARB - not in usual headers. */ + +#define WGL_DRAW_TO_WINDOW_ARB 0x2001 +#define WGL_ACCELERATION_ARB 0x2003 +#define WGL_SUPPORT_OPENGL_ARB 0x2010 +#define WGL_DOUBLE_BUFFER_ARB 0x2011 +#define WGL_STEREO_ARB 0x2012 +#define WGL_PIXEL_TYPE_ARB 0x2013 +#define WGL_COLOR_BITS_ARB 0x2014 +#define WGL_RED_BITS_ARB 0x2015 +#define WGL_RED_SHIFT_ARB 0x2016 +#define WGL_GREEN_BITS_ARB 0x2017 +#define WGL_GREEN_SHIFT_ARB 0x2018 +#define WGL_BLUE_BITS_ARB 0x2019 +#define WGL_BLUE_SHIFT_ARB 0x201A +#define WGL_ALPHA_BITS_ARB 0x201B +#define WGL_ALPHA_SHIFT_ARB 0x201C +#define WGL_ACCUM_BITS_ARB 0x201D +#define WGL_ACCUM_RED_BITS_ARB 0x201E +#define WGL_ACCUM_GREEN_BITS_ARB 0x201F +#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 +#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 +#define WGL_DEPTH_BITS_ARB 0x2022 +#define WGL_STENCIL_BITS_ARB 0x2023 +#define WGL_AUX_BUFFERS_ARB 0x2024 +#define WGL_NO_ACCELERATION_ARB 0x2025 +#define WGL_GENERIC_ACCELERATION_ARB 0x2026 +#define WGL_FULL_ACCELERATION_ARB 0x2027 +#define WGL_SWAP_EXCHANGE_ARB 0x2028 +#define WGL_SWAP_COPY_ARB 0x2029 +#define WGL_SWAP_UNDEFINED_ARB 0x202A +#define WGL_TYPE_RGBA_ARB 0x202B +#define WGL_TYPE_COLORINDEX_ARB 0x202C +#define WGL_SAMPLE_BUFFERS_ARB 0x2041 +#define WGL_SAMPLES_ARB 0x2042 + +/* WGL function types */ +typedef int (__stdcall * PFN_WGLCHOOSEPIXELFORMAT) ( + HDC hdc, + const int *piAttribIList, + const FLOAT *pfAttribFList, + UINT nMaxFormats, int *piFormats, UINT *nNumFormats); + +typedef int (__stdcall * PFN_WGLSWAPINTERVALEXT) (int interval); + /* define forceFlush if we should fflush() before closing file */ #define forceFlush 1 /* Note: Print this stuff into a file in case we lock up*/ -# define DPRINTF(vLevel, args) if(vLevel <= verboseLevel) {\ +# define DPRINTF3D(vLevel, args) if(vLevel <= verboseLevel) {\ FILE *fp = fopen("Squeak3D.log", "at");\ if(fp) { fprintf args; if(forceFlush) fflush(fp); fclose(fp); }} @@ -131,54 +175,54 @@ static void printPFD(PIXELFORMATDESCRIPTOR *pfd, int lvl) { /* Print the pixel format for information purposes */ - DPRINTF(lvl,(fp,"flags (%d): ", pfd->dwFlags)); + DPRINTF3D(lvl,(fp,"flags (%d): ", pfd->dwFlags)); if(pfd->dwFlags & PFD_DRAW_TO_WINDOW) - DPRINTF(lvl, (fp, "PFD_DRAW_TO_WINDOW ")); + DPRINTF3D(lvl, (fp, "PFD_DRAW_TO_WINDOW ")); if(pfd->dwFlags & PFD_DRAW_TO_BITMAP) - DPRINTF(lvl, (fp, "PFD_DRAW_TO_BITMAP ")); + DPRINTF3D(lvl, (fp, "PFD_DRAW_TO_BITMAP ")); if(pfd->dwFlags & PFD_SUPPORT_GDI) - DPRINTF(lvl, (fp, "PFD_SUPPORT_GDI ")); + DPRINTF3D(lvl, (fp, "PFD_SUPPORT_GDI ")); if(pfd->dwFlags & PFD_SUPPORT_OPENGL) - DPRINTF(lvl, (fp, "PFD_SUPPORT_OPENGL ")); + DPRINTF3D(lvl, (fp, "PFD_SUPPORT_OPENGL ")); if(pfd->dwFlags & PFD_GENERIC_ACCELERATED) - DPRINTF(lvl, (fp, "PFD_GENERIC_ACCELERATED ")); + DPRINTF3D(lvl, (fp, "PFD_GENERIC_ACCELERATED ")); if(pfd->dwFlags & PFD_GENERIC_FORMAT) - DPRINTF(lvl, (fp, "PFD_GENERIC_FORMAT ")); + DPRINTF3D(lvl, (fp, "PFD_GENERIC_FORMAT ")); if(pfd->dwFlags & PFD_NEED_PALETTE) - DPRINTF(lvl, (fp, "PFD_NEED_PALETTE ")); + DPRINTF3D(lvl, (fp, "PFD_NEED_PALETTE ")); if(pfd->dwFlags & PFD_NEED_SYSTEM_PALETTE) - DPRINTF(lvl, (fp, "PFD_NEED_SYSTEM_PALETTE ")); + DPRINTF3D(lvl, (fp, "PFD_NEED_SYSTEM_PALETTE ")); if(pfd->dwFlags & PFD_DOUBLEBUFFER) - DPRINTF(lvl, (fp, "PFD_DOUBLEBUFFER ")); + DPRINTF3D(lvl, (fp, "PFD_DOUBLEBUFFER ")); if(pfd->dwFlags & PFD_SWAP_LAYER_BUFFERS) - DPRINTF(lvl, (fp, "PFD_SWAP_LAYER_BUFFERS ")); + DPRINTF3D(lvl, (fp, "PFD_SWAP_LAYER_BUFFERS ")); if(pfd->dwFlags & PFD_SWAP_COPY) - DPRINTF(lvl, (fp, "PFD_SWAP_COPY ")); + DPRINTF3D(lvl, (fp, "PFD_SWAP_COPY ")); if(pfd->dwFlags & PFD_SWAP_EXCHANGE) - DPRINTF(lvl, (fp, "PFD_SWAP_EXCHANGE ")); - DPRINTF(lvl,(fp,"\n")); + DPRINTF3D(lvl, (fp, "PFD_SWAP_EXCHANGE ")); + DPRINTF3D(lvl,(fp,"\n")); - DPRINTF(lvl,(fp,"pixelType = %s\n",(pfd->iPixelType == PFD_TYPE_RGBA ? "PFD_TYPE_RGBA" : "PFD_TYPE_COLORINDEX"))); - DPRINTF(lvl,(fp,"colorBits = %d\n",pfd->cColorBits)); - DPRINTF(lvl,(fp,"depthBits = %d\n",pfd->cDepthBits)); - DPRINTF(lvl,(fp,"stencilBits = %d\n",pfd->cStencilBits)); - DPRINTF(lvl,(fp,"accumBits = %d\n",pfd->cAccumBits)); - DPRINTF(lvl,(fp,"auxBuffers = %d\n",pfd->cAuxBuffers)); - DPRINTF(lvl,(fp,"layerType = %d\n",pfd->iLayerType)); + DPRINTF3D(lvl,(fp,"pixelType = %s\n",(pfd->iPixelType == PFD_TYPE_RGBA ? "PFD_TYPE_RGBA" : "PFD_TYPE_COLORINDEX"))); + DPRINTF3D(lvl,(fp,"colorBits = %d\n",pfd->cColorBits)); + DPRINTF3D(lvl,(fp,"depthBits = %d\n",pfd->cDepthBits)); + DPRINTF3D(lvl,(fp,"stencilBits = %d\n",pfd->cStencilBits)); + DPRINTF3D(lvl,(fp,"accumBits = %d\n",pfd->cAccumBits)); + DPRINTF3D(lvl,(fp,"auxBuffers = %d\n",pfd->cAuxBuffers)); + DPRINTF3D(lvl,(fp,"layerType = %d\n",pfd->iLayerType)); - DPRINTF(lvl,(fp,"redBits = %d\n",pfd->cRedBits)); - DPRINTF(lvl,(fp,"redShift = %d\n",pfd->cRedShift)); - DPRINTF(lvl,(fp,"greenBits = %d\n",pfd->cGreenBits)); - DPRINTF(lvl,(fp,"greenShift = %d\n",pfd->cGreenShift)); - DPRINTF(lvl,(fp,"blueBits = %d\n",pfd->cBlueBits)); - DPRINTF(lvl,(fp,"blueShift = %d\n",pfd->cBlueShift)); - DPRINTF(lvl,(fp,"alphaBits = %d\n",pfd->cAlphaBits)); - DPRINTF(lvl,(fp,"alphaShift = %d\n",pfd->cAlphaShift)); + DPRINTF3D(lvl,(fp,"redBits = %d\n",pfd->cRedBits)); + DPRINTF3D(lvl,(fp,"redShift = %d\n",pfd->cRedShift)); + DPRINTF3D(lvl,(fp,"greenBits = %d\n",pfd->cGreenBits)); + DPRINTF3D(lvl,(fp,"greenShift = %d\n",pfd->cGreenShift)); + DPRINTF3D(lvl,(fp,"blueBits = %d\n",pfd->cBlueBits)); + DPRINTF3D(lvl,(fp,"blueShift = %d\n",pfd->cBlueShift)); + DPRINTF3D(lvl,(fp,"alphaBits = %d\n",pfd->cAlphaBits)); + DPRINTF3D(lvl,(fp,"alphaShift = %d\n",pfd->cAlphaShift)); - DPRINTF(lvl,(fp,"accumRedBits = %d\n",pfd->cAccumRedBits)); - DPRINTF(lvl,(fp,"accumGreenBits = %d\n",pfd->cAccumGreenBits)); - DPRINTF(lvl,(fp,"accumBlueBits = %d\n",pfd->cAccumBlueBits)); - DPRINTF(lvl,(fp,"accumAlphaBits = %d\n",pfd->cAccumAlphaBits)); + DPRINTF3D(lvl,(fp,"accumRedBits = %d\n",pfd->cAccumRedBits)); + DPRINTF3D(lvl,(fp,"accumGreenBits = %d\n",pfd->cAccumGreenBits)); + DPRINTF3D(lvl,(fp,"accumBlueBits = %d\n",pfd->cAccumBlueBits)); + DPRINTF3D(lvl,(fp,"accumAlphaBits = %d\n",pfd->cAccumAlphaBits)); } int glDestroyRenderer(int handle) { @@ -196,241 +240,116 @@ return 1; } -#if 0 -int glDescribeRenderer(int index, int *desc, int descSize) { - PIXELFORMATDESCRIPTOR pfd, goodPFD; - HDC hDC; +/* Weak gl extension check - good enough for WGL_ARB_multisample */ +static int glExtensionExists(const char *extension) +{ + const char *glExtensions = (const char*)glGetString(GL_EXTENSIONS); + if (!glExtensions) + return 0; + return (strstr(glExtensions,extension) != NULL); +} - /* req. at least version 0 */ - if(descSize < B3D_PF_SIZE0) return 0; - if(!*theSTWindow) return 0; - hDC = GetDC(*theSTWindow); - if(!hDC) return 0; - pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); - pfd.nVersion = 1; - if(!DescribePixelFormat(hDC, index, sizeof(pfd), &pfd)) { - return 0; +/* Find a pixel format with antialiasing support. */ +static int findAAPixelFormat (HDC hdc) +{ + int pixelFormat; + BOOL bStatus; + UINT numFormats; + float fAttributes[] = {0,0}; + int iAttributes[] = { + WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, + WGL_SUPPORT_OPENGL_ARB, GL_TRUE, + WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, + WGL_COLOR_BITS_ARB, 24, + WGL_ALPHA_BITS_ARB, 8, + WGL_DEPTH_BITS_ARB, 12, + WGL_STENCIL_BITS_ARB, 8, + WGL_DOUBLE_BUFFER_ARB, GL_TRUE, + WGL_SAMPLE_BUFFERS_ARB, 1, + WGL_SAMPLES_ARB, 4, + 0, 0}; + + /* Find the extension routine. */ + PFN_WGLCHOOSEPIXELFORMAT wglChoosePixelFormatARB = + (PFN_WGLCHOOSEPIXELFORMAT) + wglGetProcAddress("wglChoosePixelFormatARB"); + + if (!wglChoosePixelFormatARB) { + DPRINTF3D(3, (fp, "Cannot find function wglChoosePixelFormatARB")); + return -1; } - desc[0] = B3D_PF_SIZE; - flags = 0; - if(pfd.dwFlags & PFD_DRAW_TO_WINDOW) flags |= B3D_PF_WINDOW_FLAG; - if(pfd.dwFlags & PFD_DRAW_TO_BITMAP) flags |= B3D_PF_BITMAP_FLAG; - if(pfd.dwFlags & PFD_SUPPORT_GDI) flags |= B3D_PF_NATIVE_GDI_FLAG; - if(pfd.dwFlags & PFD_SUPPORT_OPENGL) flags |= B3D_PF_NATIVE_API_FLAG; - if(pfd.dwFlags & PFD_GENERIC_ACCELERATED) flags |= B3D_PF_ACCELERATED_FLAG; - if((pfd.dwFlags & PFD_GENERIC_FORMAT) == 0) flags |= B3D_PF_ACCELERATED_FLAG; - if(pfd.dwFlags & PFD_DOUBLEBUFFER) flags |= B3D_PF_DOUBLEBUFFER_FLAG; - if(pfd.iPixelType == PFD_TYPE_RGBA) flags |= B3D_RGBA_FLAG; - else flags |= B3D_INDEXED_FLAG; + /* Make sure the basic extension is also supported. */ + if (!glExtensionExists("GL_ARB_multisample")) { + DPRINTF3D(3, (fp, "Cannot find extension GL_ARB_multisample")); + return -1; + } - desc[B3D_PF_FLAGS] = flags; - desc[B3D_PF_COLORBITS] = pfd.cColorBits; - desc[B3D_PF_DEPTHBITS] = pfd.cDepthBits; - desc[B3D_PF_STENCILBITS] = pfd.cStencilBits; - desc[B3D_PF_ACCUMBITS] = pfd.cAccumBits; - desc[B3D_PF_AUXBUFFERS] = pfd.cAuxBuffers; - desc[B3D_PF_LAYER] = pfd.iLayerType; + bStatus = wglChoosePixelFormatARB(hdc, iAttributes, + fAttributes, 1, &pixelFormat, &numFormats); + if ((bStatus == GL_TRUE) && (numFormats > 0)) + { + DPRINTF3D(3, (fp, "Found 4-sample pixel format %d", pixelFormat)); + return pixelFormat; + } - desc[B3D_PF_REDMASK] = ((1 << pfd.cRedBits) - 1) << pfd.cRedShift; - desc[B3D_PF_GREENMASK] = ((1 << pfd.cGreenBits) - 1) << pfd.cGreenShift; - desc[B3D_PF_BLUEMASK] = ((1 << pfd.cBlueBits) - 1) << pfd.cBlueShift; - desc[B3D_PF_ALPHAMASK] = ((1 << pfd.cAlphaBits) - 1) << pfd.cAlphaShift; - return 1; + /* That failed, try using 2 samples now instead of 4 */ + iAttributes[19] = 2; + bStatus = wglChoosePixelFormatARB(hdc, iAttributes, + fAttributes, 1, &pixelFormat, &numFormats); + if ((bStatus == GL_TRUE) && (numFormats > 0)) + { + DPRINTF3D(3, (fp, "Found 2-sample pixel format %d", pixelFormat)); + return pixelFormat; + } + + DPRINTF3D(3, (fp, "Cannot find a multisample pixel format.")); + return -1; } -int glCreateRendererPF(int *pfDesc, int descSize, int x, int y, int w, int h) -{ - PIXELFORMATDESCRIPTOR pfd; - int depth, i, goodIndex, max, index; - char *string; - glRenderer *renderer; +static int enableVSync(int value) { + PFN_WGLSWAPINTERVALEXT wglSwapIntervalEXT = + (PFN_WGLSWAPINTERVALEXT) wglGetProcAddress("wglSwapIntervalEXT"); - for(i=0; i < MAX_RENDERER; i++) { - if(allRenderer[i].used == 0) break; + if(!glExtensionExists("WGL_EXT_swap_control")){ + DPRINTF3D(3, (fp, "WGL_EXT_swap_control not found")); + return -1; } - if(i >= MAX_RENDERER) { - DPRINTF(1, (fp, "ERROR: Maximum number of renderers (%d) exceeded\n", MAX_RENDERER)); - return 0; + + if(!wglSwapIntervalEXT) { + DPRINTF3D(3, (fp, "wglSwapIntervalEXT not found")); + return -1; } - index = i; - renderer = allRenderer+index; - renderer->used = 0; - renderer->context = NULL; - renderer->hDC = NULL; - renderer->hWnd = NULL; + wglSwapIntervalEXT(value); + return value; +} - DPRINTF(3,(fp,"---- Initializing OpenGL ----\n\n")); +/* Create the renderer window and context; returns 0 on failure. */ +static int setupWindow(glRenderer * renderer, int x, int y, int w, int h) { renderer->hWnd = glCreateClientWindow(*theSTWindow, x, y, w, h); if(renderer->hWnd == NULL) { - DPRINTF(1, (fp, "Failed to create client window\n")); - goto FAILED; + DPRINTF3D(1, (fp, "Failed to create client window\n")); + return 0; } ShowWindow(renderer->hWnd, SW_SHOW); UpdateWindow(renderer->hWnd); renderer->hDC = GetDC(renderer->hWnd); if(!renderer->hDC) { - DPRINTF(1, (fp, "Failed to obtain client hdc\n")); - goto FAILED; + DPRINTF3D(1, (fp, "Failed to obtain client hdc\n")); + return 0; } - - /* Query the native depth so we can choose something appropriate */ - depth = GetDeviceCaps(renderer->hDC, BITSPIXEL); - max = DescribePixelFormat(renderer->hDC, 1, sizeof(pfd), &pfd); - pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); - pfd.nVersion = 1; - goodPFD.nSize = 0; - goodIndex = 0; - - for(i=1; i<= max; i++) { - DescribePixelFormat(renderer->hDC, i, sizeof(pfd), &pfd); - DPRINTF(3,(fp, "\n#### Checking pixel format %d:\n", i)); - printPFD(&pfd, 3); - if((pfd.dwFlags & PFD_DRAW_TO_WINDOW) == 0) - continue; /* can't draw to window */ - if((pfd.dwFlags & PFD_SUPPORT_OPENGL) == 0) - continue; /* can't use OpenGL */ - if((pfd.dwFlags & PFD_DOUBLEBUFFER) == 0) - continue; /* can't double buffer */ - if(pfd.iPixelType != PFD_TYPE_RGBA) - continue; /* not an RGBA format */ - if(pfd.cDepthBits < 16) - continue; /* no enough z-buffer */ - if(pfd.iLayerType != PFD_MAIN_PLANE) - continue; /* overlay/underlay */ -#ifdef TEA -#warning "**************************************************************" -#warning "**************************************************************" -#warning "**************************************************************" -#warning -#warning "TEA: Stencil buffer required" -#warning -#warning "**************************************************************" -#warning "**************************************************************" -#warning "**************************************************************" - if(pfd.cStencilBits < 8) - continue; /* need stencil bits */ -#endif - if((pfd.dwFlags & PFD_GENERIC_FORMAT) == 0) { - /* This indicates an accellerated driver */ - if(!allowHardware) continue; - DPRINTF(3,(fp,"===> This is an accelerated driver\n")); -#ifdef ENABLE_FORCED_PFD - if(forcedPFD > 0) { - if(--forcedPFD == 0) { - goodPFD = pfd; goodIndex = i; - break; - } - } -#endif - if(goodPFD.nSize == 0) { - goodPFD = pfd; goodIndex = i; - } else if(goodPFD.cColorBits == depth) { - goodPFD = pfd; goodIndex = i; - } - } else if(pfd.dwFlags & PFD_GENERIC_ACCELERATED) { - /* This indicates an accellerated mini-driver */ - if(!allowHardware) continue; - DPRINTF(3,(fp,"===> This is an accelerated mini-driver\n")); -#ifdef ENABLE_FORCED_PFD - if(forcedPFD > 0) { - if(--forcedPFD == 0) { - goodPFD = pfd; goodIndex = i; - break; - } - } -#endif - if(goodPFD.nSize == 0) { - goodPFD = pfd; goodIndex = i; - } else if(goodPFD.cColorBits == depth) { - goodPFD = pfd; goodIndex = i; - } - } - - if( (pfd.dwFlags & PFD_GENERIC_FORMAT) && - ((pfd.dwFlags & PFD_GENERIC_ACCELERATED) == 0)) { - /* this indicates a non-accellerated driver */ - if(!allowSoftware) continue; - if(goodPFD.nSize == 0) { - goodPFD = pfd; goodIndex = i; - } - } - } - if((goodPFD.nSize == 0) -#ifdef ENABLE_FORCED_PFD - || (forcedPFD > 0) -#endif - ) { - /* We didn't find an accellerated driver. */ - DPRINTF(3,(fp,"#### WARNING: No accelerated driver found; bailing out\n")); - goto FAILED; - } - - /* Now we have found the PFD to use. - Try setting the pixel format for the window */ - SetPixelFormat(renderer->hDC, goodIndex, &goodPFD); - /* Note: SetPixelFormat may fail if the pixel format has been set before. - Rather than failing here we do ignore the result of the above, - so that an old pixel format will be used in any case. */ - goodIndex = GetPixelFormat(renderer->hDC); - DescribePixelFormat(renderer->hDC, goodIndex, sizeof(pfd), &pfd); - - DPRINTF(3,(fp,"\n#### Selected pixel format (%d) ####\n",goodIndex)); - printPFD(&pfd, 3); - renderer->context = wglCreateContext(renderer->hDC); - if(!renderer->context) { - DPRINTF(1, (fp,"Failed to create opengl context\n")); - goto FAILED; - } - /* Make the context current */ - if(!wglMakeCurrent(renderer->hDC, renderer->context)) goto FAILED; - - /* print some information about the context */ - string = (char*) glGetString(GL_VENDOR); - DPRINTF(3,(fp, "\nOpenGL vendor: %s\n", string)); - string = (char*) glGetString(GL_RENDERER); - DPRINTF(3,(fp, "OpenGL renderer: %s\n", string)); - string = (char*) glGetString(GL_VERSION); - DPRINTF(3,(fp, "OpenGL version: %s\n", string)); - string = (char*) glGetString(GL_EXTENSIONS); - DPRINTF(3,(fp, "OpenGL extensions: %s\n", string)); - - renderer->used = 1; - renderer->bufferRect[0] = x; - renderer->bufferRect[1] = y; - renderer->bufferRect[2] = w; - renderer->bufferRect[3] = h; - - DPRINTF(3, (fp,"### Renderer created!\n")); - /* setup user context */ - glDisable(GL_LIGHTING); - glDisable(GL_COLOR_MATERIAL); - glDisable(GL_BLEND); - glDisable(GL_ALPHA_TEST); - glEnable(GL_DITHER); - glEnable(GL_DEPTH_TEST); - glEnable(GL_NORMALIZE); - glDepthFunc(GL_LEQUAL); - glClearDepth(1.0); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glShadeModel(GL_SMOOTH); - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, blackLight); - ERROR_CHECK; - return index; -FAILED: - /* do necessary cleanup */ - DPRINTF(1,(fp, "OpenGL initialization failed\n")); - if(renderer->context) wglDeleteContext(renderer->context); - if(renderer->hDC) ReleaseDC(renderer->hWnd, renderer->hDC); - if(renderer->hWnd) DestroyWindow(renderer->hWnd); - return -1; + return 1; } -#endif + #define SUPPORTED_FLAGS (\ B3D_HARDWARE_RENDERER \ | B3D_SOFTWARE_RENDERER \ - | B3D_STENCIL_BUFFER) + | B3D_STENCIL_BUFFER \ + | B3D_ANTIALIASING \ + | B3D_STEREO \ + | B3D_SYNCVBL \ +) int glCreateRendererFlags(int x, int y, int w, int h, int flags) { @@ -440,7 +359,7 @@ glRenderer *renderer; if(flags & ~SUPPORTED_FLAGS) { - DPRINTF(1, (fp, "ERROR: Unsupported flags requested( %d)\n", flags)); + DPRINTF3D(1, (fp, "ERROR: Unsupported flags requested( %d)\n", flags)); return -1; } @@ -448,29 +367,16 @@ if(allRenderer[i].used == 0) break; } if(i >= MAX_RENDERER) { - DPRINTF(1, (fp, "ERROR: Maximum number of renderers (%d) exceeded\n", MAX_RENDERER)); + DPRINTF3D(1, (fp, "ERROR: Maximum number of renderers (%d) exceeded\n", MAX_RENDERER)); return -1; } index = i; renderer = allRenderer+index; - renderer->used = 0; - renderer->context = NULL; - renderer->hDC = NULL; - renderer->hWnd = NULL; - - DPRINTF(3,(fp,"---- Initializing OpenGL ----\n\n")); - renderer->hWnd = glCreateClientWindow(*theSTWindow, x, y, w, h); - if(renderer->hWnd == NULL) { - DPRINTF(1, (fp, "Failed to create client window\n")); + memset(renderer, 0, sizeof(glRenderer)); + DPRINTF3D(3,(fp,"---- Initializing OpenGL ----\n\n")); + if (! setupWindow(renderer, x, y, w, h)) { goto FAILED; } - ShowWindow(renderer->hWnd, SW_SHOW); - UpdateWindow(renderer->hWnd); - renderer->hDC = GetDC(renderer->hWnd); - if(!renderer->hDC) { - DPRINTF(1, (fp, "Failed to obtain client hdc\n")); - goto FAILED; - } /* Query the native depth so we can choose something appropriate */ depth = GetDeviceCaps(renderer->hDC, BITSPIXEL); @@ -490,7 +396,7 @@ for(i=1; i<= max; i++) { DescribePixelFormat(renderer->hDC, i, sizeof(pfd), &pfd); - DPRINTF(3,(fp, "\n#### Checking pixel format %d:\n", i)); + DPRINTF3D(3,(fp, "\n#### Checking pixel format %d:\n", i)); printPFD(&pfd, 3); if((pfd.dwFlags & matchPFD.dwFlags) != matchPFD.dwFlags) @@ -509,10 +415,14 @@ if(pfd.cStencilBits == 0) continue; /* need stencil bits */ + if(flags & B3D_STEREO) + if(pfd.dwFlags & PFD_STEREO == 0) + continue; /* need stereo caps */ + if((pfd.dwFlags & PFD_GENERIC_FORMAT) == 0) { /* This indicates an accellerated driver */ if((flags & B3D_HARDWARE_RENDERER) == 0) continue; - DPRINTF(3,(fp,"===> This is an accelerated driver\n")); + DPRINTF3D(3,(fp,"===> This is an accelerated driver\n")); if(goodPFD.nSize == 0) { goodPFD = pfd; goodIndex = i; } else if(goodPFD.cColorBits == depth) { @@ -521,7 +431,7 @@ } else if(pfd.dwFlags & PFD_GENERIC_ACCELERATED) { /* This indicates an accellerated mini-driver */ if((flags & B3D_HARDWARE_RENDERER) == 0) continue; - DPRINTF(3,(fp,"===> This is an accelerated mini-driver\n")); + DPRINTF3D(3,(fp,"===> This is an accelerated mini-driver\n")); if(goodPFD.nSize == 0) { goodPFD = pfd; goodIndex = i; @@ -541,7 +451,7 @@ } if((goodPFD.nSize == 0)) { /* We didn't find an accellerated driver. */ - DPRINTF(3,(fp,"#### WARNING: No accelerated driver found; bailing out\n")); + DPRINTF3D(3,(fp,"#### WARNING: No accelerated driver found; bailing out\n")); goto FAILED; } @@ -554,25 +464,57 @@ goodIndex = GetPixelFormat(renderer->hDC); DescribePixelFormat(renderer->hDC, goodIndex, sizeof(pfd), &pfd); - DPRINTF(3,(fp,"\n#### Selected pixel format (%d) ####\n",goodIndex)); + DPRINTF3D(3,(fp,"\n#### Selected pixel format (%d) ####\n", goodIndex)); printPFD(&pfd, 3); renderer->context = wglCreateContext(renderer->hDC); if(!renderer->context) { - DPRINTF(1, (fp,"Failed to create opengl context\n")); + DPRINTF3D(1, (fp,"Failed to create opengl context\n")); goto FAILED; } /* Make the context current */ if(!wglMakeCurrent(renderer->hDC, renderer->context)) goto FAILED; + /* Now we have a context; check for antialiasing support. */ + if (flags & B3D_ANTIALIASING) { + int aaIndex = findAAPixelFormat (renderer->hDC); + if (aaIndex > 0) { + /* To set an AA pixel format, we have to start with a new window. */ + DescribePixelFormat(renderer->hDC, aaIndex, sizeof(pfd), &pfd); + /* Take down the old window */ + wglMakeCurrent(NULL, NULL); + wglDeleteContext(renderer->context); + ReleaseDC (renderer->hWnd, renderer->hDC); + DestroyWindow (renderer->hWnd); + renderer->hWnd = NULL; + renderer->hDC = NULL; + renderer->context = NULL; + + if (! setupWindow(renderer, x, y, w, h)) { + goto FAILED; + } + /* Set the new pixel format. */ + SetPixelFormat(renderer->hDC, aaIndex, &pfd); + goodIndex = GetPixelFormat(renderer->hDC); + DescribePixelFormat(renderer->hDC, goodIndex, sizeof(pfd), &pfd); + DPRINTF3D(3,(fp,"\n#### AA pixel format (%d) ####\n", goodIndex)); + printPFD(&pfd, 3); + renderer->context = wglCreateContext(renderer->hDC); + if (!wglMakeCurrent(renderer->hDC, renderer->context)) goto FAILED; + } + } + + /* Enable vsync if requested */ + if(flags & B3D_SYNCVBL) enableVSync(1); + /* print some information about the context */ string = (char*) glGetString(GL_VENDOR); - DPRINTF(3,(fp, "\nOpenGL vendor: %s\n", string)); + DPRINTF3D(3,(fp, "\nOpenGL vendor: %s\n", string)); string = (char*) glGetString(GL_RENDERER); - DPRINTF(3,(fp, "OpenGL renderer: %s\n", string)); + DPRINTF3D(3,(fp, "OpenGL renderer: %s\n", string)); string = (char*) glGetString(GL_VERSION); - DPRINTF(3,(fp, "OpenGL version: %s\n", string)); + DPRINTF3D(3,(fp, "OpenGL version: %s\n", string)); string = (char*) glGetString(GL_EXTENSIONS); - DPRINTF(3,(fp, "OpenGL extensions: %s\n", string)); + DPRINTF3D(3,(fp, "OpenGL extensions: %s\n", string)); renderer->used = 1; renderer->bufferRect[0] = x; @@ -580,7 +522,7 @@ renderer->bufferRect[2] = w; renderer->bufferRect[3] = h; - DPRINTF(3, (fp,"### Renderer created!\n")); + DPRINTF3D(3, (fp,"### Renderer created!\n")); /* setup user context */ glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); @@ -598,7 +540,7 @@ return index; FAILED: /* do necessary cleanup */ - DPRINTF(1,(fp, "OpenGL initialization failed\n")); + DPRINTF3D(1,(fp, "OpenGL initialization failed\n")); if(renderer->context) wglDeleteContext(renderer->context); if(renderer->hDC) ReleaseDC(renderer->hWnd, renderer->hDC); if(renderer->hWnd) DestroyWindow(renderer->hWnd); @@ -624,7 +566,7 @@ /*****************************************************************************/ glRenderer *glRendererFromHandle(int handle) { - DPRINTF(7, (fp, "Looking for renderer id: %d\n", handle)); + DPRINTF3D(7, (fp, "Looking for renderer id: %d\n", handle)); if(handle < 0 || handle >= MAX_RENDERER) return NULL; if(allRenderer[handle].used) return allRenderer+handle; return NULL; @@ -685,7 +627,7 @@ int i; theSTWindow = (HWND*) interpreterProxy->ioLoadFunctionFrom("stWindow",""); if(!theSTWindow) { - DPRINTF(1,(fp,"ERROR: Failed to look up stWindow\n")); + DPRINTF3D(1,(fp,"ERROR: Failed to look up stWindow\n")); return 0; } for(i = 0; i < MAX_RENDERER; i++) { @@ -704,17 +646,5 @@ return 1; } -#ifdef ENABLE_FORCED_PFD -int win32SetForcedPFD(void) { - int pfdIndex; - if(interpreterProxy->methodArgumentCount() != 1) - return interpreterProxy->primitiveFail(); - pfdIndex = interpreterProxy->stackIntegerValue(0); - if(interpreterProxy->failed()) return 0; - forcedPFD = pfdIndex; - interpreterProxy->pop(1); -} -#endif - #endif /* defined(B3DX_GL) */ Modified: trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.h =================================================================== --- trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.h 2011-06-09 07:00:37 UTC (rev 2404) +++ trunk/platforms/win32/plugins/B3DAcceleratorPlugin/sqWin32OpenGL.h 2011-06-09 07:33:56 UTC (rev 2405) @@ -13,6 +13,9 @@ HWND hWnd; HGLRC context; HDC hDC; + + void APIENTRY (*glDrawRangeElements) (GLenum, GLuint, GLuint, GLsizei, GLenum, const GLvoid*); + } glRenderer; #define GL_RENDERER_DEFINED 1 |
Free forum by Nabble | Edit this page |