GSdx: Cleanups to the vsync framelimiter linkage. Ensures that the vsync settings are preserved across plugin shutdown/init, and removes a lot of function parameter mess trying to pass a single parameter across some 6-8 classes and 4 nested function calls.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2099 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2009-10-31 01:06:23 +00:00
parent 5326ae7686
commit c274d4e43c
21 changed files with 82 additions and 66 deletions

View File

@ -69,11 +69,12 @@ bool GPURenderer::Create(HWND hWnd)
m_wnd.Show();
if(!m_dev->Create(&m_wnd, m_vsync))
if(!m_dev->Create(&m_wnd))
{
return false;
}
m_dev->SetVsync(m_vsync);
Reset();
return true;
@ -162,7 +163,7 @@ void GPURenderer::VSync()
GetClientRect(m_hWnd, r);
m_dev->Present(r.fit(m_aspectratio), 0, true);
m_dev->Present(r.fit(m_aspectratio), 0);
}
bool GPURenderer::MakeSnapshot(const string& path)

View File

@ -39,6 +39,7 @@ static GSRenderer* s_gs = NULL;
static void (*s_irq)() = NULL;
static uint8* s_basemem = NULL;
static int s_renderer = -1;
static bool s_framelimit = true;
EXPORT_C_(uint32) PS2EgetLibType()
{
@ -441,9 +442,12 @@ EXPORT_C GSsetFrameSkip(int frameskip)
s_gs->SetFrameSkip(frameskip);
}
EXPORT_C GSsetFrameLimit(int limit)
{
s_gs->SetFrameLimit(limit != 0);
s_framelimit = limit != 0;
if( s_gs )
s_gs->SetFrameLimit(s_framelimit);
}
#ifdef _WINDOWS

View File

@ -25,6 +25,7 @@
GSDevice::GSDevice()
: m_wnd(NULL)
, m_vsync(false)
, m_rbswapped(false)
, m_backbuffer(NULL)
, m_merge(NULL)
@ -51,10 +52,9 @@ GSDevice::~GSDevice()
delete m_1x1;
}
bool GSDevice::Create(GSWnd* wnd, bool vsync)
bool GSDevice::Create(GSWnd* wnd)
{
m_wnd = wnd;
m_vsync = vsync;
return true;
}
@ -82,7 +82,7 @@ bool GSDevice::Reset(int w, int h)
return m_wnd != NULL;
}
void GSDevice::Present(const GSVector4i& r, int shader, bool limit)
void GSDevice::Present(const GSVector4i& r, int shader)
{
GSVector4i cr = m_wnd->GetClientRect();
@ -106,7 +106,7 @@ void GSDevice::Present(const GSVector4i& r, int shader, bool limit)
StretchRect(m_current, m_backbuffer, GSVector4(r), s_shader[shader]);
}
Flip(limit);
Flip();
}
GSTexture* GSDevice::Fetch(int type, int w, int h, bool msaa, int format)

View File

@ -80,15 +80,16 @@ public:
enum {Windowed, Fullscreen, DontCare};
virtual bool Create(GSWnd* wnd, bool vsync);
virtual bool Create(GSWnd* wnd);
virtual bool Reset(int w, int h);
virtual bool IsLost(bool update = false) {return false;}
virtual void Present(const GSVector4i& r, int shader, bool limit);
virtual void Flip(bool limit) {}
virtual void Present(const GSVector4i& r, int shader);
virtual void Flip() {}
virtual void BeginScene() {}
virtual void DrawPrimitive() {};
virtual void EndScene();
virtual void SetVsync(bool enable) { m_vsync = enable; }
virtual void ClearRenderTarget(GSTexture* t, const GSVector4& c) {}
virtual void ClearRenderTarget(GSTexture* t, uint32 c) {}

View File

@ -38,9 +38,9 @@ GSDevice10::~GSDevice10()
{
}
bool GSDevice10::Create(GSWnd* wnd, bool vsync)
bool GSDevice10::Create(GSWnd* wnd)
{
if(!__super::Create(wnd, vsync))
if(!__super::Create(wnd))
{
return false;
}
@ -260,9 +260,9 @@ bool GSDevice10::Reset(int w, int h)
return true;
}
void GSDevice10::Flip(bool limit)
void GSDevice10::Flip()
{
m_swapchain->Present(m_vsync && limit ? 1 : 0, 0);
m_swapchain->Present(m_vsync, 0);
}
void GSDevice10::DrawPrimitive()

View File

@ -107,10 +107,10 @@ public:
GSDevice10();
virtual ~GSDevice10();
bool Create(GSWnd* wnd, bool vsync);
bool Create(GSWnd* wnd);
bool CreateTextureFX();
bool Reset(int w, int h);
void Flip(bool limit);
void Flip();
void DrawPrimitive();

View File

@ -38,9 +38,9 @@ GSDevice11::~GSDevice11()
{
}
bool GSDevice11::Create(GSWnd* wnd, bool vsync)
bool GSDevice11::Create(GSWnd* wnd)
{
if(!__super::Create(wnd, vsync))
if(!__super::Create(wnd))
{
return false;
}
@ -251,9 +251,9 @@ bool GSDevice11::Reset(int w, int h)
return true;
}
void GSDevice11::Flip(bool limit)
void GSDevice11::Flip()
{
m_swapchain->Present(m_vsync && limit ? 1 : 0, 0);
m_swapchain->Present(m_vsync, 0);
}
void GSDevice11::DrawPrimitive()

View File

@ -109,10 +109,10 @@ public:
GSDevice11();
virtual ~GSDevice11();
bool Create(GSWnd* wnd, bool vsync);
bool Create(GSWnd* wnd);
bool CreateTextureFX();
bool Reset(int w, int h);
void Flip(bool limit);
void Flip();
void DrawPrimitive();

View File

@ -33,9 +33,9 @@ GSDevice7::~GSDevice7()
{
}
bool GSDevice7::Create(GSWnd* wnd, bool vsync)
bool GSDevice7::Create(GSWnd* wnd)
{
if(!__super::Create(wnd, vsync))
if(!__super::Create(wnd))
{
return false;
}
@ -136,7 +136,7 @@ bool GSDevice7::Reset(int w, int h)
return true;
}
void GSDevice7::Present(const GSVector4i& r, int shader, bool limit)
void GSDevice7::Present(const GSVector4i& r, int shader)
{
HRESULT hr;
@ -177,7 +177,7 @@ void GSDevice7::Present(const GSVector4i& r, int shader, bool limit)
MapWindowPoints((HWND)m_wnd->GetHandle(), HWND_DESKTOP, (POINT*)&r2, 2);
if(m_vsync && limit)
if(m_vsync)
{
hr = m_dd->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
}

View File

@ -40,8 +40,8 @@ public:
GSDevice7();
virtual ~GSDevice7();
bool Create(GSWnd* wnd, bool vsync);
bool Create(GSWnd* wnd);
bool Reset(int w, int h);
bool IsLost(bool update) {return m_lost;}
void Present(const GSVector4i& r, int shader, bool limit);
void Present(const GSVector4i& r, int shader);
};

View File

@ -50,9 +50,9 @@ GSDevice9::~GSDevice9()
if(m_state.ps_cb) _aligned_free(m_state.ps_cb);
}
bool GSDevice9::Create(GSWnd* wnd, bool vsync)
bool GSDevice9::Create(GSWnd* wnd)
{
if(!__super::Create(wnd, vsync))
if(!__super::Create(wnd))
{
return false;
}
@ -377,7 +377,7 @@ bool GSDevice9::IsLost(bool update)
return m_lost;
}
void GSDevice9::Flip(bool limit)
void GSDevice9::Flip()
{
m_dev->EndScene();

View File

@ -141,10 +141,10 @@ public:
GSDevice9();
virtual ~GSDevice9();
bool Create(GSWnd* wnd, bool vsync);
bool Create(GSWnd* wnd);
bool Reset(int w, int h);
bool IsLost(bool update);
void Flip(bool limit);
void Flip();
void BeginScene();
void DrawPrimitive();

View File

@ -262,9 +262,9 @@ public:
GSDeviceDX() {};
virtual ~GSDeviceDX() {}
virtual bool Create(GSWnd* wnd, bool vsync)
virtual bool Create(GSWnd* wnd)
{
return __super::Create( wnd, vsync );
return __super::Create( wnd );
}
virtual bool Reset(int w, int h)
@ -272,8 +272,8 @@ public:
return __super::Reset( w, h );
}
//virtual void Present(const GSVector4i& r, int shader, bool limit);
//virtual void Flip(bool limit) {}
//virtual void Present(const GSVector4i& r, int shader);
//virtual void Flip() {}
virtual void SetupIA(const void* vertices, int count, int prim) = 0;
virtual void SetupVS(VSSelector sel, const VSConstantBuffer* cb) = 0;

View File

@ -22,9 +22,9 @@
#include "stdafx.h"
#include "GSDeviceNull.h"
bool GSDeviceNull::Create(GSWnd* wnd, bool vsync)
bool GSDeviceNull::Create(GSWnd* wnd)
{
if(!__super::Create(wnd, vsync))
if(!__super::Create(wnd))
{
return false;
}

View File

@ -35,6 +35,6 @@ private:
public:
GSDeviceNull() {}
bool Create(GSWnd* wnd, bool vsync);
bool Create(GSWnd* wnd);
bool Reset(int w, int h);
};

View File

@ -66,9 +66,9 @@ void GSDeviceOGL::OnCgError(CGcontext ctx, CGerror err)
printf("%s\n", cgGetLastListing(ctx)); // ?
}
bool GSDeviceOGL::Create(GSWnd* wnd, bool vsync)
bool GSDeviceOGL::Create(GSWnd* wnd)
{
if(!__super::Create(wnd, vsync))
if(!__super::Create(wnd))
{
return false;
}
@ -115,15 +115,6 @@ bool GSDeviceOGL::Create(GSWnd* wnd, bool vsync)
return false;
}
#ifdef _WINDOWS
if(WGLEW_EXT_swap_control)
{
wglSwapIntervalEXT(vsync ? 1 : 0);
}
#endif
const char* vendor = (const char*)glGetString(GL_VENDOR);
const char* renderer = (const char*)glGetString(GL_RENDERER);
const char* version = (const char*)glGetString(GL_VERSION);
@ -155,6 +146,20 @@ bool GSDeviceOGL::Create(GSWnd* wnd, bool vsync)
return true;
}
void GSDeviceOGL::SetVsync(bool enable)
{
__super::SetVsync(enable);
#ifdef _WINDOWS
if(WGLEW_EXT_swap_control)
{
wglSwapIntervalEXT(m_vsync ? 1 : 0);
}
#endif
}
bool GSDeviceOGL::Reset(int w, int h)
{
if(!__super::Reset(w, h))
@ -185,16 +190,16 @@ bool GSDeviceOGL::Reset(int w, int h)
return true;
}
void GSDeviceOGL::Present(const GSVector4i& r, int shader, bool limit)
void GSDeviceOGL::Present(const GSVector4i& r, int shader)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0); CheckError();
// TODO: m_current => backbuffer
Flip(limit);
Flip();
}
void GSDeviceOGL::Flip(bool limit)
void GSDeviceOGL::Flip()
{
#ifdef _WINDOWS

View File

@ -109,10 +109,11 @@ public:
GSDeviceOGL();
virtual ~GSDeviceOGL();
bool Create(GSWnd* wnd, bool vsync);
bool Create(GSWnd* wnd);
bool Reset(int w, int h);
void Present(const GSVector4i& r, int shader, bool limit);
void Flip(bool limit);
void Present(const GSVector4i& r, int shader);
void Flip();
void SetVsync(bool enable);
void DrawPrimitive();

View File

@ -77,12 +77,13 @@ bool GSRenderer::CreateDevice(GSDevice* dev)
ASSERT(dev);
ASSERT(!m_dev);
if(!dev->Create(&m_wnd, m_vsync))
if(!dev->Create(&m_wnd))
{
return false;
}
m_dev = dev;
m_dev->SetVsync( m_vsync && m_framelimit );
return true;
}
@ -271,6 +272,12 @@ bool GSRenderer::Merge(int field)
return true;
}
void GSRenderer::SetFrameLimit(bool limit)
{
m_framelimit = limit;
if( m_dev ) m_dev->SetVsync(m_vsync && m_framelimit);
}
void GSRenderer::VSync(int field)
{
GSPerfMonAutoTimer pmat(m_perfmon);
@ -343,7 +350,7 @@ void GSRenderer::VSync(int field)
// present
m_dev->Present(m_wnd.GetClientRect().fit(m_aspectratio), m_shader, m_framelimit);
m_dev->Present(m_wnd.GetClientRect().fit(m_aspectratio), m_shader);
// snapshot

View File

@ -46,6 +46,7 @@ protected:
bool m_nativeres;
bool m_aa1;
bool m_blur;
bool m_framelimit;
uint8* m_tex_buff;
@ -94,6 +95,8 @@ public:
return m_upscale_multiplier;
}
void SetFrameLimit(bool limit);
// TODO : Implement proper locking here *if needed* (not sure yet if it is) --air
uint8* GetTextureBufferLock() { return m_tex_buff; }
void ReleaseTextureBufferLock() { }

View File

@ -33,7 +33,6 @@ GSState::GSState()
, m_vprim(1)
, m_version(5)
, m_frameskip(0)
, m_framelimit(true)
, m_vkf(NULL)
{
m_sssize = 0;
@ -1617,6 +1616,7 @@ int GSState::Defrost(const GSFreezeData* fd)
if(version > m_version)
{
fprintf(stderr, "GSdx: Savestate version is incompatible. Load aborted.\n" );
return -1;
}
@ -1776,11 +1776,6 @@ void GSState::SetFrameSkip(int skip)
}
}
void GSState::SetFrameLimit(bool limit)
{
m_framelimit = limit;
}
// GSTransferBuffer
GSState::GSTransferBuffer::GSTransferBuffer()

View File

@ -249,7 +249,6 @@ public:
void GetLastTag(uint32* tag) {*tag = m_path3hack; m_path3hack = 0;}
virtual void SetGameCRC(uint32 crc, int options);
void SetFrameSkip(int skip);
void SetFrameLimit(bool limit);
void SetRegsMem(uint8* basemem);
void SetIrqCallback(void (*irq)());
void SetMultithreaded(bool isMT=true);