Improved tearing test.
Added support for arbitrary swap intervals, including negative ones if (GLX|WGL)_EXT_swap_control_tear is available.
This commit is contained in:
parent
8d4ba0aa83
commit
8503d53018
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include "getopt.h"
|
#include "getopt.h"
|
||||||
|
|
||||||
|
static GLboolean swap_tear;
|
||||||
static int swap_interval;
|
static int swap_interval;
|
||||||
static double frame_rate;
|
static double frame_rate;
|
||||||
|
|
||||||
@ -51,8 +52,10 @@ static void update_window_title(GLFWwindow* window)
|
|||||||
{
|
{
|
||||||
char title[256];
|
char title[256];
|
||||||
|
|
||||||
sprintf(title, "Tearing detector (interval %i, %0.1f Hz)",
|
sprintf(title, "Tearing detector (interval %i%s, %0.1f Hz)",
|
||||||
swap_interval, frame_rate);
|
swap_interval,
|
||||||
|
(swap_tear && swap_interval < 0) ? " (swap tear)" : "",
|
||||||
|
frame_rate);
|
||||||
|
|
||||||
glfwSetWindowTitle(window, title);
|
glfwSetWindowTitle(window, title);
|
||||||
}
|
}
|
||||||
@ -81,9 +84,28 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
|
|||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case GLFW_KEY_SPACE:
|
case GLFW_KEY_UP:
|
||||||
set_swap_interval(window, 1 - swap_interval);
|
{
|
||||||
|
if (swap_interval + 1 > swap_interval)
|
||||||
|
set_swap_interval(window, swap_interval + 1);
|
||||||
break;
|
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:
|
case GLFW_KEY_ESCAPE:
|
||||||
glfwSetWindowShouldClose(window, 1);
|
glfwSetWindowShouldClose(window, 1);
|
||||||
break;
|
break;
|
||||||
@ -152,6 +174,8 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
last_time = glfwGetTime();
|
last_time = glfwGetTime();
|
||||||
frame_rate = 0.0;
|
frame_rate = 0.0;
|
||||||
|
swap_tear = (glfwExtensionSupported("WGL_EXT_swap_control_tear") ||
|
||||||
|
glfwExtensionSupported("GLX_EXT_swap_control_tear"));
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwSetKeyCallback(window, key_callback);
|
glfwSetKeyCallback(window, key_callback);
|
||||||
|
Loading…
Reference in New Issue
Block a user