Merge pull request #1387 from colobot/dev-fix-vsync
Remove vsync loop and improve vsync UIpyro-refactor
commit
7b237ce9ad
|
@ -549,6 +549,8 @@ bool CApplication::Create()
|
|||
|
||||
/* SDL initialization sequence */
|
||||
|
||||
// Creating the m_engine now because it holds the vsync flag
|
||||
m_engine = MakeUnique<Gfx::CEngine>(this, m_systemUtils);
|
||||
|
||||
Uint32 initFlags = SDL_INIT_VIDEO | SDL_INIT_TIMER;
|
||||
|
||||
|
@ -693,8 +695,6 @@ bool CApplication::Create()
|
|||
}
|
||||
|
||||
// Create the 3D engine
|
||||
m_engine = MakeUnique<Gfx::CEngine>(this, m_systemUtils);
|
||||
|
||||
m_engine->SetDevice(m_device.get());
|
||||
|
||||
if (! m_engine->Create() )
|
||||
|
@ -850,24 +850,9 @@ bool CApplication::CreateVideoSurface()
|
|||
int vsync = 0;
|
||||
if (GetConfigFile().GetIntProperty("Setup", "VSync", vsync))
|
||||
{
|
||||
while (SDL_GL_SetSwapInterval(vsync) == -1)
|
||||
{
|
||||
switch(vsync)
|
||||
{
|
||||
case -1: //failed with adaptive sync?
|
||||
GetLogger()->Warn("Adaptive sync not supported.\n");
|
||||
vsync = 1;
|
||||
break;
|
||||
case 1: //failed with VSync enabled?
|
||||
GetLogger()->Warn("Couldn't enable VSync.\n");
|
||||
vsync = 0;
|
||||
break;
|
||||
case 0: //failed with VSync disabled?
|
||||
GetLogger()->Warn("Couldn't disable VSync.\n");
|
||||
vsync = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_engine->SetVSync(vsync);
|
||||
TryToSetVSync();
|
||||
vsync = m_engine->GetVSync();
|
||||
GetConfigFile().SetIntProperty("Setup", "VSync", vsync);
|
||||
|
||||
GetLogger()->Info("Using Vsync: %s\n", (vsync == -1 ? "adaptive" : (vsync ? "true" : "false")));
|
||||
|
@ -876,6 +861,32 @@ bool CApplication::CreateVideoSurface()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CApplication::TryToSetVSync()
|
||||
{
|
||||
int vsync = m_engine->GetVSync();
|
||||
int result = SDL_GL_SetSwapInterval(vsync);
|
||||
if (result == -1)
|
||||
{
|
||||
switch (vsync)
|
||||
{
|
||||
case -1:
|
||||
GetLogger()->Warn("Adaptive sync not supported: %s\n", SDL_GetError());
|
||||
m_engine->SetVSync(1);
|
||||
TryToSetVSync();
|
||||
break;
|
||||
case 1:
|
||||
GetLogger()->Warn("Couldn't enable VSync: %s\n", SDL_GetError());
|
||||
m_engine->SetVSync(0);
|
||||
TryToSetVSync();
|
||||
break;
|
||||
case 0:
|
||||
GetLogger()->Warn("Couldn't disable VSync: %s\n", SDL_GetError());
|
||||
m_engine->SetVSync(SDL_GL_GetSwapInterval());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig)
|
||||
{
|
||||
m_deviceConfig = newConfig;
|
||||
|
@ -884,26 +895,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig)
|
|||
SDL_SetWindowSize(m_private->window, m_deviceConfig.size.x, m_deviceConfig.size.y);
|
||||
SDL_SetWindowFullscreen(m_private->window, m_deviceConfig.fullScreen ? SDL_WINDOW_FULLSCREEN : 0);
|
||||
|
||||
int vsync = m_engine->GetVSync();
|
||||
while (SDL_GL_SetSwapInterval(vsync) == -1)
|
||||
{
|
||||
switch(vsync)
|
||||
{
|
||||
case -1: //failed with adaptive sync?
|
||||
GetLogger()->Warn("Adaptive sync not supported.\n");
|
||||
vsync = 1;
|
||||
break;
|
||||
case 1: //failed with VSync enabled?
|
||||
GetLogger()->Warn("Couldn't enable VSync.\n");
|
||||
vsync = 0;
|
||||
break;
|
||||
case 0: //failed with VSync disabled?
|
||||
GetLogger()->Warn("Couldn't disable VSync.\n");
|
||||
vsync = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_engine->SetVSync(vsync);
|
||||
TryToSetVSync();
|
||||
|
||||
m_device->ConfigChanged(m_deviceConfig);
|
||||
|
||||
|
|
|
@ -288,6 +288,9 @@ public:
|
|||
protected:
|
||||
//! Creates the window's SDL_Surface
|
||||
bool CreateVideoSurface();
|
||||
//! Tries to set the SDL vsync state desired by the 3D engine
|
||||
//! The final state of SDL vsync is set in the 3D engine afterwards
|
||||
void TryToSetVSync();
|
||||
|
||||
//! Processes the captured SDL event to Event struct
|
||||
Event ProcessSystemEvent();
|
||||
|
|
|
@ -293,6 +293,7 @@ void CScreenSetupDisplay::UpdateApply()
|
|||
CWindow* pw;
|
||||
CButton* pb;
|
||||
CList* pl;
|
||||
CList* pvl;
|
||||
CCheck* pc;
|
||||
int sel2;
|
||||
bool bFull;
|
||||
|
@ -309,6 +310,22 @@ void CScreenSetupDisplay::UpdateApply()
|
|||
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_FULL));
|
||||
bFull = pc->TestState(STATE_CHECK);
|
||||
|
||||
pvl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_VSYNC));
|
||||
if (pvl == nullptr) return;
|
||||
|
||||
switch (m_engine->GetVSync())
|
||||
{
|
||||
case -1: //Adaptive?
|
||||
pvl->SetSelect(1);
|
||||
break;
|
||||
case 0: //Off?
|
||||
pvl->SetSelect(0);
|
||||
break;
|
||||
case 1: //On?
|
||||
pvl->SetSelect(2);
|
||||
break;
|
||||
}
|
||||
|
||||
if ( sel2 == m_setupSelMode &&
|
||||
bFull == m_setupFull )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue