From df8a003802c789bc6a289dddacec0589508fe2ec Mon Sep 17 00:00:00 2001
From: Alexander Gauggel <agauggel@uni-koblenz.de>
Date: Wed, 11 Aug 2021 17:35:56 +0200
Subject: [PATCH] [#106] Hack/Fixed event synchronization issue, which caused
 subtle mouse stutter, which was visible due to motion blur. Added comment
 with info, should be fixed properly later. Have fun Tobi =)

---
 projects/indirect_dispatch/src/App.cpp |  2 +-
 src/vkcv/Window.cpp                    | 15 ++++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/projects/indirect_dispatch/src/App.cpp b/projects/indirect_dispatch/src/App.cpp
index e8987aa0..4b372ae9 100644
--- a/projects/indirect_dispatch/src/App.cpp
+++ b/projects/indirect_dispatch/src/App.cpp
@@ -103,7 +103,7 @@ void App::run() {
 
 	float   objectVerticalSpeed         = 0.005;
 	float   motionBlurMinVelocity       = 0.001;
-	int     cameraShutterSpeedInverse   = 48;
+	int     cameraShutterSpeedInverse   = 30;
 
 	glm::mat4 mvpPrevious               = glm::mat4(1.f);
 	glm::mat4 viewProjectionPrevious    = m_cameraManager.getActiveCamera().getMVP();
diff --git a/src/vkcv/Window.cpp b/src/vkcv/Window.cpp
index aea00fb1..daf66ddb 100644
--- a/src/vkcv/Window.cpp
+++ b/src/vkcv/Window.cpp
@@ -80,12 +80,17 @@ namespace vkcv {
 			window->e_key.unlock();
 			window->e_char.unlock();
 			window->e_gamepad.unlock();
-    	}
+		}
+
+		glfwPollEvents();
+
+		// fixes subtle mouse stutter, which is made visible by motion blur
+		// FIXME: proper solution
+		// probably caused by main thread locking events before glfw callbacks are executed
+		std::this_thread::sleep_for(std::chrono::milliseconds(1));
 
-        glfwPollEvents();
-    	
-    	for (int gamepadIndex = GLFW_JOYSTICK_1; gamepadIndex <= GLFW_JOYSTICK_LAST; gamepadIndex++) {
-    		if (glfwJoystickPresent(gamepadIndex)) {
+		for (int gamepadIndex = GLFW_JOYSTICK_1; gamepadIndex <= GLFW_JOYSTICK_LAST; gamepadIndex++) {
+			if (glfwJoystickPresent(gamepadIndex)) {
 				onGamepadEvent(gamepadIndex);
 			}
 		}
-- 
GitLab