Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
As requested apply the same changes made by rev 6958822 to the D3D9 b…
…ackend.

handle v-sync changed while the emulation is running.
thanks to neobrain for pointing the missing functionality.
  • Loading branch information
Tinob committed Apr 1, 2013
1 parent 49d809a commit a562c7c
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions Source/Plugins/Plugin_VideoDX9/Src/Render.cpp
Expand Up @@ -68,7 +68,7 @@ static u32 s_blendMode;
static u32 s_LastAA;
static bool IS_AMD;
static float m_fMaxPointSize;

static bool s_vsync;
static char *st;

static LPDIRECT3DSURFACE9 ScreenShootMEMSurface = NULL;
Expand Down Expand Up @@ -190,7 +190,8 @@ Renderer::Renderer()
D3D::dev->CreateOffscreenPlainSurface(s_backbuffer_width,s_backbuffer_height, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &ScreenShootMEMSurface, NULL );
D3D::SetRenderState(D3DRS_POINTSCALEENABLE,false);
m_fMaxPointSize = D3D::GetCaps().MaxPointSize;

// Handle VSync on/off
s_vsync = g_ActiveConfig.IsVSync();
}

Renderer::~Renderer()
Expand Down Expand Up @@ -452,7 +453,8 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
}
else if(type == PEEK_COLOR)
{
// TODO: Can't we directly StretchRect to System buf?
// We can't directly StretchRect to System buf because is not suported by all implementations
// this is the only safe path that works in most cases
hr = D3D::dev->StretchRect(pEFBSurf, &RectToLock, pBufferRT, NULL, D3DTEXF_NONE);
D3D::dev->GetRenderTargetData(pBufferRT, pSystemBuf);

Expand Down Expand Up @@ -1037,7 +1039,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons

DLCache::ProgressiveCleanup();
TextureCache::Cleanup();

// Flip/present backbuffer to frontbuffer here
D3D::Present();
// Enable configuration changes
UpdateActiveConfig();
TextureCache::OnConfigChanged(g_ActiveConfig);
Expand Down Expand Up @@ -1096,8 +1099,15 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
// New frame
stats.ResetFrame();

// Flip/present backbuffer to frontbuffer here
D3D::Present();
// Handle vsync changes during execution
if(s_vsync != g_ActiveConfig.IsVSync())
{
s_vsync = g_ActiveConfig.IsVSync();
TeardownDeviceObjects();
D3D::Reset();
// device objects lost, so recreate all of them
SetupDeviceObjects();
}
D3D::BeginFrame();
RestoreAPIState();

Expand All @@ -1113,14 +1123,16 @@ void Renderer::ApplyState(bool bUseDstAlpha)
{
if (bUseDstAlpha)
{
// TODO: WTF is this crap? We're enabling color writing regardless of the actual GPU state here...
// If we get here we are sure that we are using dst alpha pass. (bpmem.dstalpha.enable)
// Alpha write is enabled. (because bpmem.blendmode.alphaupdate && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24)
// We must disable blend because we want to write alpha value directly to the alpha channel without modifications.
D3D::ChangeRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
D3D::ChangeRenderState(D3DRS_ALPHABLENDENABLE, false);
if(bpmem.zmode.testenable && bpmem.zmode.updateenable)
{
//This is needed to draw to the correct pixels in multi-pass algorithms
//this avoid z-figthing and grants that you write to the same pixels
//affected by the last pass
// This is needed to draw to the correct pixels in multi-pass algorithms
// to avoid z-figthing and grants that you write to the same pixels
// affected by the last pass
D3D::ChangeRenderState(D3DRS_ZWRITEENABLE, false);
D3D::ChangeRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);
}
Expand Down

0 comments on commit a562c7c

Please sign in to comment.