mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Add love.window.get/setVSync, to allow changing the vsync setting without recreating the window.
This commit is contained in:
@@ -159,6 +159,9 @@ public:
|
|||||||
virtual bool setIcon(love::image::ImageData *imgd) = 0;
|
virtual bool setIcon(love::image::ImageData *imgd) = 0;
|
||||||
virtual love::image::ImageData *getIcon() = 0;
|
virtual love::image::ImageData *getIcon() = 0;
|
||||||
|
|
||||||
|
virtual void setVSync(int vsync) = 0;
|
||||||
|
virtual int getVSync() const = 0;
|
||||||
|
|
||||||
virtual void setDisplaySleepEnabled(bool enable) = 0;
|
virtual void setDisplaySleepEnabled(bool enable) = 0;
|
||||||
virtual bool isDisplaySleepEnabled() const = 0;
|
virtual bool isDisplaySleepEnabled() const = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -512,12 +512,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
|
|||||||
|
|
||||||
SDL_RaiseWindow(window);
|
SDL_RaiseWindow(window);
|
||||||
|
|
||||||
SDL_GL_SetSwapInterval(f.vsync);
|
setVSync(f.vsync);
|
||||||
|
|
||||||
// Check if adaptive vsync was requested but not supported, and fall back
|
|
||||||
// to regular vsync if so.
|
|
||||||
if (f.vsync == -1 && SDL_GL_GetSwapInterval() != -1)
|
|
||||||
SDL_GL_SetSwapInterval(1);
|
|
||||||
|
|
||||||
updateSettings(f, false);
|
updateSettings(f, false);
|
||||||
|
|
||||||
@@ -608,7 +603,7 @@ void Window::updateSettings(const WindowSettings &newsettings, bool updateGraphi
|
|||||||
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &samples);
|
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &samples);
|
||||||
|
|
||||||
settings.msaa = (buffers > 0 ? samples : 0);
|
settings.msaa = (buffers > 0 ? samples : 0);
|
||||||
settings.vsync = SDL_GL_GetSwapInterval();
|
settings.vsync = getVSync();
|
||||||
|
|
||||||
settings.stencil = newsettings.stencil;
|
settings.stencil = newsettings.stencil;
|
||||||
settings.depth = newsettings.depth;
|
settings.depth = newsettings.depth;
|
||||||
@@ -915,6 +910,24 @@ love::image::ImageData *Window::getIcon()
|
|||||||
return icon.get();
|
return icon.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::setVSync(int vsync)
|
||||||
|
{
|
||||||
|
if (context == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SDL_GL_SetSwapInterval(vsync);
|
||||||
|
|
||||||
|
// Check if adaptive vsync was requested but not supported, and fall back
|
||||||
|
// to regular vsync if so.
|
||||||
|
if (vsync == -1 && SDL_GL_GetSwapInterval() != -1)
|
||||||
|
SDL_GL_SetSwapInterval(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Window::getVSync() const
|
||||||
|
{
|
||||||
|
return context != nullptr ? SDL_GL_GetSwapInterval() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Window::setDisplaySleepEnabled(bool enable)
|
void Window::setDisplaySleepEnabled(bool enable)
|
||||||
{
|
{
|
||||||
if (enable)
|
if (enable)
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ public:
|
|||||||
bool setIcon(love::image::ImageData *imgd) override;
|
bool setIcon(love::image::ImageData *imgd) override;
|
||||||
love::image::ImageData *getIcon() override;
|
love::image::ImageData *getIcon() override;
|
||||||
|
|
||||||
|
void setVSync(int vsync) override;
|
||||||
|
int getVSync() const override;
|
||||||
|
|
||||||
void setDisplaySleepEnabled(bool enable) override;
|
void setDisplaySleepEnabled(bool enable) override;
|
||||||
bool isDisplaySleepEnabled() const override;
|
bool isDisplaySleepEnabled() const override;
|
||||||
|
|
||||||
|
|||||||
@@ -381,6 +381,23 @@ int w_getIcon(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_setVSync(lua_State *L)
|
||||||
|
{
|
||||||
|
int vsync = 0;
|
||||||
|
if (lua_type(L, 1) == LUA_TBOOLEAN)
|
||||||
|
vsync = lua_toboolean(L, 1);
|
||||||
|
else
|
||||||
|
vsync = (int)luaL_checkinteger(L, 1);
|
||||||
|
instance()->setVSync(vsync);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_getVSync(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, instance()->getVSync());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int w_setDisplaySleepEnabled(lua_State *L)
|
int w_setDisplaySleepEnabled(lua_State *L)
|
||||||
{
|
{
|
||||||
instance()->setDisplaySleepEnabled(luax_checkboolean(L, 1));
|
instance()->setDisplaySleepEnabled(luax_checkboolean(L, 1));
|
||||||
@@ -592,6 +609,8 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getPosition", w_getPosition },
|
{ "getPosition", w_getPosition },
|
||||||
{ "setIcon", w_setIcon },
|
{ "setIcon", w_setIcon },
|
||||||
{ "getIcon", w_getIcon },
|
{ "getIcon", w_getIcon },
|
||||||
|
{ "setVSync", w_setVSync },
|
||||||
|
{ "getVSync", w_getVSync },
|
||||||
{ "setDisplaySleepEnabled", w_setDisplaySleepEnabled },
|
{ "setDisplaySleepEnabled", w_setDisplaySleepEnabled },
|
||||||
{ "isDisplaySleepEnabled", w_isDisplaySleepEnabled },
|
{ "isDisplaySleepEnabled", w_isDisplaySleepEnabled },
|
||||||
{ "setTitle", w_setTitle },
|
{ "setTitle", w_setTitle },
|
||||||
|
|||||||
Reference in New Issue
Block a user