mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 02:38:52 -05:00
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"
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user