diff --git a/stepmania/src/RageDisplay.cpp b/stepmania/src/RageDisplay.cpp index 8b5caa0060..493d48b8c7 100644 --- a/stepmania/src/RageDisplay.cpp +++ b/stepmania/src/RageDisplay.cpp @@ -150,23 +150,42 @@ RageDisplay::~RageDisplay() } - -//----------------------------------------------------------------------------- -// Name: SwitchDisplayMode() -// Desc: -//----------------------------------------------------------------------------- -bool RageDisplay::SwitchDisplayMode( - const bool bWindowed, const int iWidth, const int iHeight, const int iBPP, const int iFullScreenHz ) +HRESULT RageDisplay::SetMode() { - LOG->Trace( "RageDisplay::SwitchDisplayModes( %d, %d, %d, %d, %d )", bWindowed, iWidth, iHeight, iBPP, iFullScreenHz ); - - if( !bWindowed ) - SetCursor( NULL ); + HRESULT hr; + if( m_pd3dDevice == NULL ) + { + // device is not yet created. We need to create it + if( FAILED( hr = m_pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + m_hWnd, + D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, + &m_d3dpp, &m_pd3dDevice) ) ) + { + return hr; + } + LOG->Trace( + "Video card info:\n" + " - available texture mem is %u\n", + m_pd3dDevice->GetAvailableTextureMem() + ); + if( m_pVB == NULL ) + CreateVertexBuffer(); + } + else + { + // device is already created. Just reset it. + if( FAILED( hr = m_pd3dDevice->Reset( &m_d3dpp ) ) ) + return hr; + } + LOG->Trace( "Mode change was successful." ); + return S_OK; +} +D3DFORMAT RageDisplay::FindBackBufferType(bool bWindowed, int iBPP) +{ HRESULT hr; - // Find an pixel format for the back buffer. // If windowed, then dwBPP is ignored. Use whatever works. CArray arrayBackBufferFormats; // throw all possibilities in here @@ -215,13 +234,35 @@ bool RageDisplay::SwitchDisplayMode( LOG->Trace( "This will work." ); if( i == arrayBackBufferFormats.GetSize() ) // we didn't find an appropriate format + return D3DFMT_UNKNOWN; + return fmtBackBuffer; +} + + +//----------------------------------------------------------------------------- +// Name: SwitchDisplayMode() +// Desc: +//----------------------------------------------------------------------------- +bool RageDisplay::SwitchDisplayMode( + const bool bWindowed, const int iWidth, const int iHeight, const int iBPP, const int iFullScreenHz ) +{ + LOG->Trace( "RageDisplay::SwitchDisplayModes( %d, %d, %d, %d, %d )", bWindowed, iWidth, iHeight, iBPP, iFullScreenHz ); + + if( !bWindowed ) + SetCursor( NULL ); + + + HRESULT hr; + + // Find a pixel format for the back buffer. + D3DFORMAT fmtBackBuffer=FindBackBufferType( bWindowed, iBPP ); + if( fmtBackBuffer == D3DFMT_UNKNOWN ) { - LOG->Trace( hr, "failed to find an appropriate format for %d, %u, %u, %u.", bWindowed, iWidth, iHeight, iBPP ); + // we didn't find an appropriate format + LOG->Trace( "failed to find an appropriate format for %d, %u, %u, %u.", bWindowed, iWidth, iHeight, iBPP ); return false; } - - // Set up presentation parameters for the display ZeroMemory( &m_d3dpp, sizeof(m_d3dpp) ); @@ -252,37 +293,11 @@ bool RageDisplay::SwitchDisplayMode( ); - - if( m_pd3dDevice == NULL ) + if( FAILED( hr=SetMode() ) ) { - // device is not yet created. We need to create it - if( FAILED( hr = m_pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, - m_hWnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, - &m_d3dpp, &m_pd3dDevice) ) ) - { - LOG->Trace( hr, "failed to create device: %d, %u, %u, %u.", bWindowed, iWidth, iHeight, iBPP ); - return false; - } - LOG->Trace( - "Video card info:\n" - " - available texture mem is %u\n", - m_pd3dDevice->GetAvailableTextureMem() - ); - if( m_pVB == NULL ) - CreateVertexBuffer(); + LOG->Trace( hr, "failed to set device: %d, %u, %u, %u.", bWindowed, iWidth, iHeight, iBPP ); + return false; } - else - { - // device is already created. Just reset it. - if( FAILED( hr = m_pd3dDevice->Reset( &m_d3dpp ) ) ) - { - LOG->Trace( hr, "failed to reset device: %d, %u, %u, %u.", bWindowed, iWidth, iHeight, iBPP ); - return false; - } - } - - LOG->Trace( "Mode change was successful." ); // Clear the back buffer and present it so we don't show the gibberish that was // in video memory from the last app. @@ -290,7 +305,6 @@ bool RageDisplay::SwitchDisplayMode( EndFrame(); ShowFrame(); - return true; } diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index 4c5dc8d0d5..60b035dd26 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -97,6 +97,8 @@ public: private: int MaxRefresh(int iWidth, int iHeight, D3DFORMAT fmt) const; int GetBPP(D3DFORMAT fmt) const; + HRESULT SetMode(); + D3DFORMAT FindBackBufferType(bool bWindowed, int iBPP); D3DXMATRIX& GetTopMatrix() { return m_MatrixStack.ElementAt( m_MatrixStack.GetSize()-1 ); }; HWND m_hWnd;