Programmatically change vsync?

I primarily use Lib.application.window's members to change things in the window that I want to change while the game is running, such as screen size and fullscreen mode. It is standard to include an options menu with such options, as well as a vsync option, but I cannot find it.

Can vsync be an option we can toggle on the fly, without needing to relaunch the game with different lime.app.WindowConfig options, or is there a way to use lime’s config capabilities without a game restart?

I have not researched this extensively, but in SDL (which we use), I think we may need to initialize the renderer and context for GL again if we change this, or maybe even a new window. It might be worth looking into

I don’t think you need to create a new window.

In SDL, when you use SDL_CreateRenderer, it obviously accesses a pointer to a window. So if you had, for example, a reference to both the window and renderer on the lime backend, you could have something along the lines of:


namespace lime
{
    namespace app
    {
		
		class Application
		{
			//Whatever public and private accessors
			
			public:
				void SetRenderer();
			
			private:
				SDL_Window* window;
				SDL_Renderer* renderer;
		};
		
		Application::SetRenderer()
		{
			//tell the lime application to refresh the entire window when it
			//attempts to render, because we're about to destroy the renderer.
			_doRefresh = true;
			
			SDL_DestroyRenderer(renderer);
			//Recreate renderer with new render settings.
			renderer = SDL_CreateRenderer(window, 0, SDL_RENDERER_PRESENTVSYNC);
			
			//it's now okay to start rendering again
			_doRefresh = false;
		}
		
	}
}

I haven’t tested this exact code with a raw copy of SDL, but the idea is that _doRefresh is supposed to prevent drawing to the window while you’re creating a new SDL_Renderer to prevent the application from crashing. So right at the top of the render call to the window, if (_doRefresh) return; should, in theory, prevent crashes and allow for the renderer to be recreated without closing and reopening the window.

I’m not sure how it would work with OpenGL, because I’ve not used that directly.