From a3d25b316f7b25474c637881e67e67c07f6c2ba7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20M=C3=BCller?= <thomas94@gmx.net>
Date: Wed, 19 Oct 2022 08:10:25 +0200
Subject: [PATCH] Add VSync toggle to the GUI

---
 include/neural-graphics-primitives/testbed.h | 2 ++
 src/testbed.cu                               | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/include/neural-graphics-primitives/testbed.h b/include/neural-graphics-primitives/testbed.h
index b52f000..7f69802 100644
--- a/include/neural-graphics-primitives/testbed.h
+++ b/include/neural-graphics-primitives/testbed.h
@@ -810,6 +810,8 @@ public:
 	std::chrono::time_point<std::chrono::steady_clock> m_training_start_time_point;
 	Eigen::Array4f m_background_color = {0.0f, 0.0f, 0.0f, 1.0f};
 
+	bool m_vsync = false;
+
 	// Visualization of neuron activations
 	int m_visualized_dimension = -1;
 	int m_visualized_layer = 0;
diff --git a/src/testbed.cu b/src/testbed.cu
index eb48fcf..c2664fa 100644
--- a/src/testbed.cu
+++ b/src/testbed.cu
@@ -649,6 +649,9 @@ void Testbed::imgui() {
 		}
 
 		ImGui::Checkbox("Dynamic resolution", &m_dynamic_res);
+		if (ImGui::Checkbox("VSync", &m_vsync)) {
+			glfwSwapInterval(m_vsync ? 1 : 0);
+		}
 		ImGui::SliderFloat("Target FPS", &m_dynamic_res_target_fps, 2.0f, 144.0f, "%.01f", ImGuiSliderFlags_Logarithmic | ImGuiSliderFlags_NoRoundToFormat);
 		ImGui::SliderInt("Max spp", &m_max_spp, 0, 1024, "%d", ImGuiSliderFlags_Logarithmic | ImGuiSliderFlags_NoRoundToFormat);
 
-- 
GitLab