shithub: cstory

Download patch

ref: 84df1a427b6a5e9ff95a3b537e39b2bef00710c0
parent: 4a6b04d306a449a993604b158f804af91cb042ca
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Nov 3 07:58:09 EST 2020

Explicitly disable vsync in OpenGL

It seems to be enabled by default (it was on my Raspberry Pi, anyway)

--- a/src/Backends/Rendering/Window/OpenGL3/GLFW3.cpp
+++ b/src/Backends/Rendering/Window/OpenGL3/GLFW3.cpp
@@ -59,6 +59,8 @@
 			if (GLAD_GL_VERSION_3_2)
 			{
 	#endif
+				glfwSwapInterval(0);	// Disable vsync
+
 				Backend_PostWindowCreation();
 
 				return true;
--- a/src/Backends/Rendering/Window/OpenGL3/SDL1.cpp
+++ b/src/Backends/Rendering/Window/OpenGL3/SDL1.cpp
@@ -13,6 +13,11 @@
 
 bool WindowBackend_OpenGL_CreateWindow(const char *window_title, size_t *screen_width, size_t *screen_height, bool fullscreen)
 {
+#ifdef SDL_GL_SWAP_CONTROL
+	if (SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0) < 0)	// Disable vsync
+		Backend_PrintError("Couldn't set OpenGL swap interval: %s", SDL_GetError());
+#endif
+
 	if (SDL_SetVideoMode(*screen_width, *screen_height, 0, SDL_RESIZABLE | SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)) != NULL)
 	{
 		SDL_WM_SetCaption(window_title, NULL);
--- a/src/Backends/Rendering/Window/OpenGL3/SDL2.cpp
+++ b/src/Backends/Rendering/Window/OpenGL3/SDL2.cpp
@@ -63,6 +63,8 @@
 					if (GLAD_GL_VERSION_3_2)
 					{
 			#endif
+						SDL_GL_SetSwapInterval(0);	// Disable vsync
+
 						Backend_PostWindowCreation();
 
 						return true;
--- a/src/Backends/Rendering/Window/Software/GLFW3.cpp
+++ b/src/Backends/Rendering/Window/Software/GLFW3.cpp
@@ -52,6 +52,8 @@
 	{
 		glfwMakeContextCurrent(window);
 
+		glfwSwapInterval(0);	// Disable vsync
+
 		glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
 
 		glEnable(GL_TEXTURE_2D);