Skip to content

Commit

Permalink
Fix screen staying blank when video card is lost/resolution changes a…
Browse files Browse the repository at this point in the history
…fter api call optimization commit.
  • Loading branch information
xwidghet committed Jun 13, 2017
1 parent c217987 commit 4a566af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
40 changes: 25 additions & 15 deletions src/RageDisplay_D3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ D3DCAPS9 g_DeviceCaps;
D3DDISPLAYMODE g_DesktopMode;
D3DPRESENT_PARAMETERS g_d3dpp;
int g_ModelMatrixCnt=0;
DWORD lastFVF = 0;
DWORD g_lastFVF = 0;
static bool g_bSphereMapping[NUM_TextureUnit] = { false, false };

// Need default color and depth buffer to restore them after using render targets
Expand Down Expand Up @@ -566,6 +566,9 @@ RString RageDisplay_D3D::TryVideoMode( const VideoModeParams &_p, bool &bNewDevi
// Present once the window is created so we don't display a white frame while initializing
g_pd3dDevice->Present(0, 0, 0, 0);

// Ensure device is in a clean state when resolution changes occur
RecoverFromDeviceLoss();

return RString(); // mode change successful
}

Expand All @@ -576,6 +579,12 @@ void RageDisplay_D3D::ResolutionChanged()
RageDisplay::ResolutionChanged();
}

// Reset anything which doesn't survive device loss
void RageDisplay_D3D::RecoverFromDeviceLoss()
{
g_lastFVF = 0;
}

int RageDisplay_D3D::GetMaxTextureSize() const
{
return g_DeviceCaps.MaxTextureWidth;
Expand All @@ -588,6 +597,7 @@ bool RageDisplay_D3D::BeginFrame()
switch( g_pd3dDevice->TestCooperativeLevel() )
{
case D3DERR_DEVICELOST:
RecoverFromDeviceLoss();
return false;
case D3DERR_DEVICENOTRESET:
{
Expand Down Expand Up @@ -835,9 +845,9 @@ class RageCompiledGeometrySWD3D : public RageCompiledGeometry
g_pd3dDevice->SetTransform( D3DTS_TEXTURE0, (D3DMATRIX*)&m );
}

if ( lastFVF != D3DFVF_RageModelVertex )
if ( g_lastFVF != D3DFVF_RageModelVertex )
{
lastFVF = D3DFVF_RageModelVertex;
g_lastFVF = D3DFVF_RageModelVertex;
g_pd3dDevice->SetFVF( D3DFVF_RageModelVertex );
}

Expand Down Expand Up @@ -890,9 +900,9 @@ void RageDisplay_D3D::DrawQuadsInternal( const RageSpriteVertex v[], int iNumVer
vIndices[i*6+5] = i*4+0;
}

if ( lastFVF != D3DFVF_RageSpriteVertex )
if ( g_lastFVF != D3DFVF_RageSpriteVertex )
{
lastFVF = D3DFVF_RageSpriteVertex;
g_lastFVF = D3DFVF_RageSpriteVertex;
g_pd3dDevice->SetFVF( D3DFVF_RageSpriteVertex );
}

Expand Down Expand Up @@ -931,9 +941,9 @@ void RageDisplay_D3D::DrawQuadStripInternal( const RageSpriteVertex v[], int iNu
vIndices[i*6+5] = i*2+3;
}

if ( lastFVF != D3DFVF_RageSpriteVertex )
if ( g_lastFVF != D3DFVF_RageSpriteVertex )
{
lastFVF = D3DFVF_RageSpriteVertex;
g_lastFVF = D3DFVF_RageSpriteVertex;
g_pd3dDevice->SetFVF( D3DFVF_RageSpriteVertex );
}

Expand Down Expand Up @@ -978,9 +988,9 @@ void RageDisplay_D3D::DrawSymmetricQuadStripInternal( const RageSpriteVertex v[]
vIndices[i*12+11] = i*3+5;
}

if ( lastFVF != D3DFVF_RageSpriteVertex )
if ( g_lastFVF != D3DFVF_RageSpriteVertex )
{
lastFVF = D3DFVF_RageSpriteVertex;
g_lastFVF = D3DFVF_RageSpriteVertex;
g_pd3dDevice->SetFVF( D3DFVF_RageSpriteVertex );
}

Expand All @@ -999,9 +1009,9 @@ void RageDisplay_D3D::DrawSymmetricQuadStripInternal( const RageSpriteVertex v[]

void RageDisplay_D3D::DrawFanInternal( const RageSpriteVertex v[], int iNumVerts )
{
if ( lastFVF != D3DFVF_RageSpriteVertex )
if ( g_lastFVF != D3DFVF_RageSpriteVertex )
{
lastFVF = D3DFVF_RageSpriteVertex;
g_lastFVF = D3DFVF_RageSpriteVertex;
g_pd3dDevice->SetFVF( D3DFVF_RageSpriteVertex );
}

Expand All @@ -1016,9 +1026,9 @@ void RageDisplay_D3D::DrawFanInternal( const RageSpriteVertex v[], int iNumVerts

void RageDisplay_D3D::DrawStripInternal( const RageSpriteVertex v[], int iNumVerts )
{
if ( lastFVF != D3DFVF_RageSpriteVertex )
if ( g_lastFVF != D3DFVF_RageSpriteVertex )
{
lastFVF = D3DFVF_RageSpriteVertex;
g_lastFVF = D3DFVF_RageSpriteVertex;
g_pd3dDevice->SetFVF( D3DFVF_RageSpriteVertex );
}

Expand All @@ -1033,9 +1043,9 @@ void RageDisplay_D3D::DrawStripInternal( const RageSpriteVertex v[], int iNumVer

void RageDisplay_D3D::DrawTrianglesInternal( const RageSpriteVertex v[], int iNumVerts )
{
if ( lastFVF != D3DFVF_RageSpriteVertex )
if ( g_lastFVF != D3DFVF_RageSpriteVertex )
{
lastFVF = D3DFVF_RageSpriteVertex;
g_lastFVF = D3DFVF_RageSpriteVertex;
g_pd3dDevice->SetFVF( D3DFVF_RageSpriteVertex );
}

Expand Down
3 changes: 2 additions & 1 deletion src/RageDisplay_D3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ class RageDisplay_D3D: public RageDisplay

RString TryVideoMode( const VideoModeParams &p, bool &bNewDeviceOut );
RageSurface* CreateScreenshot();
RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf );
RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf );

void RecoverFromDeviceLoss();
void SendCurrentMatrices();
};

Expand Down

0 comments on commit 4a566af

Please sign in to comment.