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);