mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Add support for non-adaptive VSync (feature 7129)
This commit is contained in:
parent
83d15ef786
commit
be488649c3
16 changed files with 480 additions and 392 deletions
|
@ -14,7 +14,7 @@ namespace SDLUtil
|
|||
close(true);
|
||||
}
|
||||
|
||||
GraphicsWindowSDL2::GraphicsWindowSDL2(osg::GraphicsContext::Traits* traits)
|
||||
GraphicsWindowSDL2::GraphicsWindowSDL2(osg::GraphicsContext::Traits* traits, int vsync)
|
||||
: mWindow(nullptr)
|
||||
, mContext(nullptr)
|
||||
, mValid(false)
|
||||
|
@ -23,6 +23,13 @@ namespace SDLUtil
|
|||
{
|
||||
_traits = traits;
|
||||
|
||||
if (vsync == 2)
|
||||
mVSyncMode = VSyncMode::Adaptive;
|
||||
else if (vsync == 1)
|
||||
mVSyncMode = VSyncMode::Enabled;
|
||||
else
|
||||
mVSyncMode = VSyncMode::Disabled;
|
||||
|
||||
init();
|
||||
if (GraphicsWindowSDL2::valid())
|
||||
{
|
||||
|
@ -134,7 +141,7 @@ namespace SDLUtil
|
|||
openmw_gl4es_init(mWindow);
|
||||
#endif
|
||||
|
||||
setSwapInterval(_traits->vsync);
|
||||
setSwapInterval(mVSyncMode);
|
||||
|
||||
// Update traits with what we've actually been given
|
||||
// Use intermediate to avoid signed/unsigned mismatch
|
||||
|
@ -233,29 +240,41 @@ namespace SDLUtil
|
|||
}
|
||||
|
||||
void GraphicsWindowSDL2::setSyncToVBlank(bool on)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"setSyncToVBlank with bool argument is not supported. Use the VSyncMode argument instead.");
|
||||
}
|
||||
|
||||
void GraphicsWindowSDL2::setSyncToVBlank(VSyncMode mode)
|
||||
{
|
||||
SDL_Window* oldWin = SDL_GL_GetCurrentWindow();
|
||||
SDL_GLContext oldCtx = SDL_GL_GetCurrentContext();
|
||||
|
||||
SDL_GL_MakeCurrent(mWindow, mContext);
|
||||
|
||||
setSwapInterval(on);
|
||||
setSwapInterval(mode);
|
||||
|
||||
SDL_GL_MakeCurrent(oldWin, oldCtx);
|
||||
}
|
||||
|
||||
void GraphicsWindowSDL2::setSwapInterval(bool enable)
|
||||
void GraphicsWindowSDL2::setSwapInterval(VSyncMode mode)
|
||||
{
|
||||
if (enable)
|
||||
mVSyncMode = mode;
|
||||
|
||||
if (mode == VSyncMode::Adaptive)
|
||||
{
|
||||
if (SDL_GL_SetSwapInterval(-1) == -1)
|
||||
{
|
||||
OSG_NOTICE << "Adaptive vsync unsupported" << std::endl;
|
||||
if (SDL_GL_SetSwapInterval(1) == -1)
|
||||
{
|
||||
OSG_NOTICE << "Vertical synchronization unsupported, disabling" << std::endl;
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
}
|
||||
setSwapInterval(VSyncMode::Enabled);
|
||||
}
|
||||
}
|
||||
else if (mode == VSyncMode::Enabled)
|
||||
{
|
||||
if (SDL_GL_SetSwapInterval(1) == -1)
|
||||
{
|
||||
OSG_NOTICE << "Vertical synchronization unsupported, disabling" << std::endl;
|
||||
setSwapInterval(VSyncMode::Disabled);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue