Browse Source

libobs-opengl: Disable v-sync when drawing on linux

Prevents glXSwapBuffers from stalling.  It would have to stall and wait
for the next frame for each and every single additional swap chain.
jp9000 9 years ago
parent
commit
9cded466dc
1 changed files with 28 additions and 0 deletions
  1. 28 0
      libobs-opengl/gl-x11.c

+ 28 - 0
libobs-opengl/gl-x11.c

@@ -561,12 +561,40 @@ extern void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
 	}
 	}
 }
 }
 
 
+enum swap_type {
+	SWAP_TYPE_NORMAL,
+	SWAP_TYPE_EXT,
+	SWAP_TYPE_MESA,
+	SWAP_TYPE_SGI,
+};
+
 extern void device_present(gs_device_t *device)
 extern void device_present(gs_device_t *device)
 {
 {
+	static bool initialized = false;
+	static enum swap_type swap_type = SWAP_TYPE_NORMAL;
+
 	Display *display = device->plat->display;
 	Display *display = device->plat->display;
 	XID window = device->cur_swap->wi->window;
 	XID window = device->cur_swap->wi->window;
 
 
+	if (!initialized) {
+		if (GLAD_GLX_EXT_swap_control)
+			swap_type = SWAP_TYPE_EXT;
+		else if (GLAD_GLX_MESA_swap_control)
+			swap_type = SWAP_TYPE_MESA;
+		else if (GLAD_GLX_SGI_swap_control)
+			swap_type = SWAP_TYPE_SGI;
+
+		initialized = true;
+	}
+
 	/* TODO: Handle XCB events. */
 	/* TODO: Handle XCB events. */
 
 
+	switch (swap_type) {
+	case SWAP_TYPE_EXT:    glXSwapIntervalEXT(display, window, 0); break;
+	case SWAP_TYPE_MESA:   glXSwapIntervalMESA(0); break;
+	case SWAP_TYPE_SGI:    glXSwapIntervalSGI(0); break;
+	case SWAP_TYPE_NORMAL:;
+	}
+
 	glXSwapBuffers(display, window);
 	glXSwapBuffers(display, window);
 }
 }