static ULONG d3d_release(d3d *d3dptr) { IDirect3D8 *d3d8 = (IDirect3D8 *)d3dptr->d3dobj; ULONG result = IDirect3D8_Release(d3d8); FreeLibrary(d3dptr->dllhandle); global_free(d3dptr); return result; }
ILvoid CheckFormatsDX8(IDirect3DDevice8 *Device) { D3DDISPLAYMODE DispMode; HRESULT hr; IDirect3D8 *TestD3D8; ILuint i; IDirect3DDevice8_GetDirect3D(Device, (IDirect3D8**)&TestD3D8); IDirect3DDevice8_GetDisplayMode(Device, &DispMode); for (i = 0; i < 6; i++) { hr = IDirect3D8_CheckDeviceFormat(TestD3D8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, DispMode.Format, 0, D3DRTYPE_TEXTURE, FormatsDX8[i]); FormatsDX8supported[i] = SUCCEEDED(hr); } IDirect3D8_Release(TestD3D8); FormatsDX8Checked = IL_TRUE; return; }
BOOL gldBuildPixelformatList_DX(void) { D3DDISPLAYMODE d3ddm; D3DFORMAT fmt[6]; IDirect3D8 *pD3D = NULL; HRESULT hr; int nSupportedFormats = 0; int i; DGL_pixelFormat *pPF; BYTE cColorBits, cRedBits, cGreenBits, cBlueBits, cAlphaBits; // char buf[128]; // char cat[8]; // Direct3D (SW or HW) // These are arranged so that 'best' pixelformat // is higher in the list (for ChoosePixelFormat). const D3DFORMAT DepthStencil[6] = { D3DFMT_D15S1, D3DFMT_D16, D3DFMT_D24X8, D3DFMT_D24X4S4, D3DFMT_D24S8, D3DFMT_D32, }; // Dump DX version ddlogMessage(GLDLOG_SYSTEM, "DirectX Version : 8.0\n"); // Release any existing pixelformat list if (glb.lpPF) { free(glb.lpPF); } glb.nPixelFormatCount = 0; glb.lpPF = NULL; // // Pixelformats for Direct3D (SW or HW) rendering // // Get a Direct3D 8.0 interface pD3D = dx8Globals.fnDirect3DCreate8(D3D_SDK_VERSION_DX8_SUPPORT_WIN95); if (!pD3D) { return FALSE; } // We will use the display mode format when finding compliant // rendertarget/depth-stencil surfaces. hr = IDirect3D8_GetAdapterDisplayMode(pD3D, glb.dwAdapter, &d3ddm); if (FAILED(hr)) { IDirect3D8_Release(pD3D); return FALSE; } // Run through the possible formats and detect supported formats for (i=0; i<6; i++) { hr = IDirect3D8_CheckDeviceFormat( pD3D, glb.dwAdapter, glb.dwDriver==GLDS_DRIVER_HAL ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, DepthStencil[i]); if (FAILED(hr)) // A failure here is not fatal. continue; // Verify that the depth format is compatible. hr = IDirect3D8_CheckDepthStencilMatch( pD3D, glb.dwAdapter, glb.dwDriver==GLDS_DRIVER_HAL ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, d3ddm.Format, d3ddm.Format, DepthStencil[i]); if (FAILED(hr)) // A failure here is not fatal, just means depth-stencil // format is not compatible with this display mode. continue; fmt[nSupportedFormats++] = DepthStencil[i]; } IDirect3D8_Release(pD3D); if (nSupportedFormats == 0) return FALSE; // Bail: no compliant pixelformats // Total count of pixelformats is: // (nSupportedFormats+1)*2 glb.lpPF = (DGL_pixelFormat *)calloc((nSupportedFormats)*2, sizeof(DGL_pixelFormat)); glb.nPixelFormatCount = (nSupportedFormats)*2; if (glb.lpPF == NULL) { glb.nPixelFormatCount = 0; return FALSE; } // Get a copy of pointer that we can alter pPF = glb.lpPF; // Cache colour bits from display format _BitsFromDisplayFormat(d3ddm.Format, &cColorBits, &cRedBits, &cGreenBits, &cBlueBits, &cAlphaBits); // // Add single-buffer formats // // Single-buffer, no depth-stencil buffer /* memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); pPF->pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag pPF->pfd.cColorBits = cColorBits; pPF->pfd.cRedBits = cRedBits; pPF->pfd.cGreenBits = cGreenBits; pPF->pfd.cBlueBits = cBlueBits; pPF->pfd.cAlphaBits = cAlphaBits; pPF->pfd.cDepthBits = 0; pPF->pfd.cStencilBits = 0; pPF->dwDriverData = D3DFMT_UNKNOWN; pPF++;*/ for (i=0; i<nSupportedFormats; i++, pPF++) { memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); pPF->pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag pPF->pfd.cColorBits = cColorBits; pPF->pfd.cRedBits = cRedBits; pPF->pfd.cGreenBits = cGreenBits; pPF->pfd.cBlueBits = cBlueBits; pPF->pfd.cAlphaBits = cAlphaBits; _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); pPF->dwDriverData = fmt[i]; } // // Add double-buffer formats // /* memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); pPF->pfd.cColorBits = cColorBits; pPF->pfd.cRedBits = cRedBits; pPF->pfd.cGreenBits = cGreenBits; pPF->pfd.cBlueBits = cBlueBits; pPF->pfd.cAlphaBits = cAlphaBits; pPF->pfd.cDepthBits = 0; pPF->pfd.cStencilBits = 0; pPF->dwDriverData = D3DFMT_UNKNOWN; pPF++;*/ for (i=0; i<nSupportedFormats; i++, pPF++) { memcpy(pPF, &pfTemplateHW, sizeof(DGL_pixelFormat)); pPF->pfd.cColorBits = cColorBits; pPF->pfd.cRedBits = cRedBits; pPF->pfd.cGreenBits = cGreenBits; pPF->pfd.cBlueBits = cBlueBits; pPF->pfd.cAlphaBits = cAlphaBits; _BitsFromDepthStencilFormat(fmt[i], &pPF->pfd.cDepthBits, &pPF->pfd.cStencilBits); pPF->dwDriverData = fmt[i]; } // Popup warning message if non RGB color mode { // This is a hack. KeithH HDC hdcDesktop = GetDC(NULL); DWORD dwDisplayBitDepth = GetDeviceCaps(hdcDesktop, BITSPIXEL); ReleaseDC(0, hdcDesktop); if (dwDisplayBitDepth <= 8) { ddlogPrintf(DDLOG_WARN, "Current Color Depth %d bpp is not supported", dwDisplayBitDepth); MessageBox(NULL, szColorDepthWarning, "GLDirect", MB_OK | MB_ICONWARNING); } } // Mark list as 'current' glb.bPixelformatsDirty = FALSE; return TRUE; }