From 8503d53018993630c8f8e637e6857cd6ff019c17 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Jan 2015 00:41:27 +0100 Subject: [PATCH] Improved tearing test. Added support for arbitrary swap intervals, including negative ones if (GLX|WGL)_EXT_swap_control_tear is available. --- tests/tearing.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/tearing.c b/tests/tearing.c index f93acbec..ce098d68 100644 --- a/tests/tearing.c +++ b/tests/tearing.c @@ -36,6 +36,7 @@ #include "getopt.h" +static GLboolean swap_tear; static int swap_interval; static double frame_rate; @@ -51,8 +52,10 @@ static void update_window_title(GLFWwindow* window) { char title[256]; - sprintf(title, "Tearing detector (interval %i, %0.1f Hz)", - swap_interval, frame_rate); + sprintf(title, "Tearing detector (interval %i%s, %0.1f Hz)", + swap_interval, + (swap_tear && swap_interval < 0) ? " (swap tear)" : "", + frame_rate); glfwSetWindowTitle(window, title); } @@ -81,9 +84,28 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, switch (key) { - case GLFW_KEY_SPACE: - set_swap_interval(window, 1 - swap_interval); + case GLFW_KEY_UP: + { + if (swap_interval + 1 > swap_interval) + set_swap_interval(window, swap_interval + 1); break; + } + + case GLFW_KEY_DOWN: + { + if (swap_tear) + { + if (swap_interval - 1 < swap_interval) + set_swap_interval(window, swap_interval - 1); + } + else + { + if (swap_interval - 1 >= 0) + set_swap_interval(window, swap_interval - 1); + } + break; + } + case GLFW_KEY_ESCAPE: glfwSetWindowShouldClose(window, 1); break; @@ -152,6 +174,8 @@ int main(int argc, char** argv) last_time = glfwGetTime(); frame_rate = 0.0; + swap_tear = (glfwExtensionSupported("WGL_EXT_swap_control_tear") || + glfwExtensionSupported("GLX_EXT_swap_control_tear")); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetKeyCallback(window, key_callback);