//Get a supported back buffer format bool WINDOW::GetBackBufferFormat( D3DFORMAT requestedFormat, D3DFORMAT & resultFormat, D3DFORMAT frontBufferFormat, LPDIRECT3D8 d3d, bool windowed) { //See if the requested back buffer format is supported HRESULT hr; hr=d3d->CheckDeviceType( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frontBufferFormat, requestedFormat, windowed); if(SUCCEEDED(hr)) { LOG::Instance()->OutputSuccess("Chosen back buffer format is available in %s mode", windowed ? "windowed" : "fullscreen"); resultFormat=requestedFormat; return true; } //If failed, try A8R8G8B8, X8R8G8B8, R5G6B5 D3DFORMAT testFormats[3]={D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_R5G6B5}; char * testStrings[3]={"D3DFMT_A8R8G8B8", "D3DFMT_X8R8G8B8", "D3DFMT_R5G6B5"}; for(int i=0; i<3; ++i) { D3DFORMAT currentTestFormat=testFormats[i]; if(FAILED(hr)) { hr=d3d->CheckDeviceType( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frontBufferFormat, currentTestFormat, windowed); if(SUCCEEDED(hr)) { LOG::Instance()->OutputMisc("%s will be used instead of chosen back buffer format in %s mode", testStrings[i], windowed ? "windowed" : "fullscreen"); resultFormat=testFormats[i]; return true; } } } //If still failed, no color formats supported LOG::Instance()->OutputError("No suitable back buffer formats supported in %s mode", windowed ? "windowed" : "fullscreen"); return false; }
D3DFORMAT FindBackBufferType(bool bWindowed, int iBPP) { HRESULT hr; // If windowed, then bpp is ignored. Use whatever works. vector<D3DFORMAT> vBackBufferFormats; // throw all possibilities in here /* When windowed, add all formats; otherwise add only formats that match dwBPP. */ if( iBPP == 16 || bWindowed ) { vBackBufferFormats.push_back( D3DFMT_R5G6B5 ); vBackBufferFormats.push_back( D3DFMT_X1R5G5B5 ); vBackBufferFormats.push_back( D3DFMT_A1R5G5B5 ); } if( iBPP == 32 || bWindowed ) { #if !defined(XBOX) vBackBufferFormats.push_back( D3DFMT_R8G8B8 ); #endif vBackBufferFormats.push_back( D3DFMT_X8R8G8B8 ); vBackBufferFormats.push_back( D3DFMT_A8R8G8B8 ); } if( !bWindowed && iBPP != 16 && iBPP != 32 ) { GraphicsWindow::Shutdown(); RageException::Throw( "Invalid BPP '%i' specified", iBPP ); } // Test each back buffer format until we find something that works. for( unsigned i=0; i < vBackBufferFormats.size(); i++ ) { D3DFORMAT fmtBackBuffer = vBackBufferFormats[i]; D3DFORMAT fmtDisplay; if( bWindowed ) fmtDisplay = g_DesktopMode.Format; else // Fullscreen fmtDisplay = vBackBufferFormats[i]; LOG->Trace( "Testing format: display %d, back buffer %d, windowed %d...", fmtDisplay, fmtBackBuffer, bWindowed ); hr = g_pd3d->CheckDeviceType( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, fmtDisplay, fmtBackBuffer, bWindowed ); if( FAILED(hr) ) continue; // skip // done searching LOG->Trace( "This will work." ); return fmtBackBuffer; } LOG->Trace( "Couldn't find an appropriate back buffer format." ); return D3DFMT_UNKNOWN; }