|
@@ -1,17 +1,7 @@
|
|
|
-/**
|
|
|
|
|
- * Unit tests for mouse coordinate system conversions
|
|
|
|
|
- *
|
|
|
|
|
- * Tests verify that coordinate conversions between different systems
|
|
|
|
|
- * (GLFW/Wayland → OpenGL → Normalized → CEF) work correctly.
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
-#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
|
|
|
|
-#include "../../../External/json/tests/thirdparty/doctest/doctest.h"
|
|
|
|
|
|
|
+#include <catch2/catch_test_macros.hpp>
|
|
|
#include <glm/glm.hpp>
|
|
#include <glm/glm.hpp>
|
|
|
#include <cmath>
|
|
#include <cmath>
|
|
|
|
|
|
|
|
-namespace WallpaperEngine::Input::Drivers::Test {
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Test GLFW to OpenGL coordinate conversion
|
|
* Test GLFW to OpenGL coordinate conversion
|
|
|
* GLFW: Y=0 at top, Y=height at bottom
|
|
* GLFW: Y=0 at top, Y=height at bottom
|
|
@@ -19,17 +9,17 @@ namespace WallpaperEngine::Input::Drivers::Test {
|
|
|
*/
|
|
*/
|
|
|
TEST_CASE("GLFW to OpenGL coordinate conversion") {
|
|
TEST_CASE("GLFW to OpenGL coordinate conversion") {
|
|
|
const int framebufferHeight = 1080;
|
|
const int framebufferHeight = 1080;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at top of screen (GLFW: Y=0)
|
|
// Mouse at top of screen (GLFW: Y=0)
|
|
|
double glfwY = 0.0;
|
|
double glfwY = 0.0;
|
|
|
double openglY = static_cast<double>(framebufferHeight) - glfwY;
|
|
double openglY = static_cast<double>(framebufferHeight) - glfwY;
|
|
|
CHECK(openglY == 1080.0); // Should be at top in OpenGL (Y=height)
|
|
CHECK(openglY == 1080.0); // Should be at top in OpenGL (Y=height)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at bottom of screen (GLFW: Y=height)
|
|
// Mouse at bottom of screen (GLFW: Y=height)
|
|
|
glfwY = 1080.0;
|
|
glfwY = 1080.0;
|
|
|
openglY = static_cast<double>(framebufferHeight) - glfwY;
|
|
openglY = static_cast<double>(framebufferHeight) - glfwY;
|
|
|
CHECK(openglY == 0.0); // Should be at bottom in OpenGL (Y=0)
|
|
CHECK(openglY == 0.0); // Should be at bottom in OpenGL (Y=0)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at middle of screen
|
|
// Mouse at middle of screen
|
|
|
glfwY = 540.0;
|
|
glfwY = 540.0;
|
|
|
openglY = static_cast<double>(framebufferHeight) - glfwY;
|
|
openglY = static_cast<double>(framebufferHeight) - glfwY;
|
|
@@ -43,17 +33,17 @@ TEST_CASE("GLFW to OpenGL coordinate conversion") {
|
|
|
*/
|
|
*/
|
|
|
TEST_CASE("Wayland to OpenGL coordinate conversion") {
|
|
TEST_CASE("Wayland to OpenGL coordinate conversion") {
|
|
|
const double viewportHeight = 1080.0;
|
|
const double viewportHeight = 1080.0;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at top of screen (Wayland: Y=0)
|
|
// Mouse at top of screen (Wayland: Y=0)
|
|
|
double waylandY = 0.0;
|
|
double waylandY = 0.0;
|
|
|
double openglY = viewportHeight - waylandY;
|
|
double openglY = viewportHeight - waylandY;
|
|
|
CHECK(openglY == 1080.0); // Should be at top in OpenGL
|
|
CHECK(openglY == 1080.0); // Should be at top in OpenGL
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at bottom of screen (Wayland: Y=height)
|
|
// Mouse at bottom of screen (Wayland: Y=height)
|
|
|
waylandY = 1080.0;
|
|
waylandY = 1080.0;
|
|
|
openglY = viewportHeight - waylandY;
|
|
openglY = viewportHeight - waylandY;
|
|
|
CHECK(openglY == 0.0); // Should be at bottom in OpenGL
|
|
CHECK(openglY == 0.0); // Should be at bottom in OpenGL
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at middle of screen
|
|
// Mouse at middle of screen
|
|
|
waylandY = 540.0;
|
|
waylandY = 540.0;
|
|
|
openglY = viewportHeight - waylandY;
|
|
openglY = viewportHeight - waylandY;
|
|
@@ -68,17 +58,17 @@ TEST_CASE("Wayland to OpenGL coordinate conversion") {
|
|
|
TEST_CASE("OpenGL to normalized coordinate conversion") {
|
|
TEST_CASE("OpenGL to normalized coordinate conversion") {
|
|
|
const int viewportY = 0;
|
|
const int viewportY = 0;
|
|
|
const int viewportHeight = 1080;
|
|
const int viewportHeight = 1080;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at top in OpenGL (Y=height)
|
|
// Mouse at top in OpenGL (Y=height)
|
|
|
double openglY = 1080.0;
|
|
double openglY = 1080.0;
|
|
|
double normalizedY = glm::clamp((openglY - viewportY) / static_cast<double>(viewportHeight), 0.0, 1.0);
|
|
double normalizedY = glm::clamp((openglY - viewportY) / static_cast<double>(viewportHeight), 0.0, 1.0);
|
|
|
CHECK(normalizedY == 1.0); // Should be 1.0 (top)
|
|
CHECK(normalizedY == 1.0); // Should be 1.0 (top)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at bottom in OpenGL (Y=0)
|
|
// Mouse at bottom in OpenGL (Y=0)
|
|
|
openglY = 0.0;
|
|
openglY = 0.0;
|
|
|
normalizedY = glm::clamp((openglY - viewportY) / static_cast<double>(viewportHeight), 0.0, 1.0);
|
|
normalizedY = glm::clamp((openglY - viewportY) / static_cast<double>(viewportHeight), 0.0, 1.0);
|
|
|
CHECK(normalizedY == 0.0); // Should be 0.0 (bottom)
|
|
CHECK(normalizedY == 0.0); // Should be 0.0 (bottom)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at middle
|
|
// Mouse at middle
|
|
|
openglY = 540.0;
|
|
openglY = 540.0;
|
|
|
normalizedY = glm::clamp((openglY - viewportY) / static_cast<double>(viewportHeight), 0.0, 1.0);
|
|
normalizedY = glm::clamp((openglY - viewportY) / static_cast<double>(viewportHeight), 0.0, 1.0);
|
|
@@ -93,19 +83,19 @@ TEST_CASE("OpenGL to normalized coordinate conversion") {
|
|
|
TEST_CASE("OpenGL to CEF coordinate conversion") {
|
|
TEST_CASE("OpenGL to CEF coordinate conversion") {
|
|
|
const int viewportHeight = 1080;
|
|
const int viewportHeight = 1080;
|
|
|
const int viewportY = 0;
|
|
const int viewportY = 0;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at top in OpenGL (Y=height)
|
|
// Mouse at top in OpenGL (Y=height)
|
|
|
double openglY = 1080.0;
|
|
double openglY = 1080.0;
|
|
|
int clampedY = std::clamp(static_cast<int>(openglY - viewportY), 0, viewportHeight);
|
|
int clampedY = std::clamp(static_cast<int>(openglY - viewportY), 0, viewportHeight);
|
|
|
int cefY = viewportHeight - clampedY;
|
|
int cefY = viewportHeight - clampedY;
|
|
|
CHECK(cefY == 0); // Should be 0 (top in CEF)
|
|
CHECK(cefY == 0); // Should be 0 (top in CEF)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at bottom in OpenGL (Y=0)
|
|
// Mouse at bottom in OpenGL (Y=0)
|
|
|
openglY = 0.0;
|
|
openglY = 0.0;
|
|
|
clampedY = std::clamp(static_cast<int>(openglY - viewportY), 0, viewportHeight);
|
|
clampedY = std::clamp(static_cast<int>(openglY - viewportY), 0, viewportHeight);
|
|
|
cefY = viewportHeight - clampedY;
|
|
cefY = viewportHeight - clampedY;
|
|
|
CHECK(cefY == 1080); // Should be height (bottom in CEF)
|
|
CHECK(cefY == 1080); // Should be height (bottom in CEF)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at middle
|
|
// Mouse at middle
|
|
|
openglY = 540.0;
|
|
openglY = 540.0;
|
|
|
clampedY = std::clamp(static_cast<int>(openglY - viewportY), 0, viewportHeight);
|
|
clampedY = std::clamp(static_cast<int>(openglY - viewportY), 0, viewportHeight);
|
|
@@ -121,13 +111,13 @@ TEST_CASE("Complete coordinate flow: GLFW to normalized") {
|
|
|
const int framebufferHeight = 1080;
|
|
const int framebufferHeight = 1080;
|
|
|
const int viewportY = 0;
|
|
const int viewportY = 0;
|
|
|
const int viewportHeight = 1080;
|
|
const int viewportHeight = 1080;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at top of screen
|
|
// Mouse at top of screen
|
|
|
double glfwY = 0.0;
|
|
double glfwY = 0.0;
|
|
|
double openglY = static_cast<double>(framebufferHeight) - glfwY; // Convert to OpenGL
|
|
double openglY = static_cast<double>(framebufferHeight) - glfwY; // Convert to OpenGL
|
|
|
double normalizedY = glm::clamp((openglY - viewportY) / static_cast<double>(viewportHeight), 0.0, 1.0);
|
|
double normalizedY = glm::clamp((openglY - viewportY) / static_cast<double>(viewportHeight), 0.0, 1.0);
|
|
|
CHECK(normalizedY == 1.0); // Top should normalize to 1.0
|
|
CHECK(normalizedY == 1.0); // Top should normalize to 1.0
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Mouse at bottom of screen
|
|
// Mouse at bottom of screen
|
|
|
glfwY = 1080.0;
|
|
glfwY = 1080.0;
|
|
|
openglY = static_cast<double>(framebufferHeight) - glfwY;
|
|
openglY = static_cast<double>(framebufferHeight) - glfwY;
|
|
@@ -147,7 +137,7 @@ TEST_CASE("Coordinate conversion with different viewport sizes") {
|
|
|
double openglY = static_cast<double>(height) - glfwY;
|
|
double openglY = static_cast<double>(height) - glfwY;
|
|
|
CHECK(openglY == 1080.0);
|
|
CHECK(openglY == 1080.0);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Test with 2560x1440 viewport
|
|
// Test with 2560x1440 viewport
|
|
|
{
|
|
{
|
|
|
const int height = 1440;
|
|
const int height = 1440;
|
|
@@ -155,7 +145,7 @@ TEST_CASE("Coordinate conversion with different viewport sizes") {
|
|
|
double openglY = static_cast<double>(height) - glfwY;
|
|
double openglY = static_cast<double>(height) - glfwY;
|
|
|
CHECK(openglY == 1440.0);
|
|
CHECK(openglY == 1440.0);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Test with 800x600 viewport
|
|
// Test with 800x600 viewport
|
|
|
{
|
|
{
|
|
|
const int height = 600;
|
|
const int height = 600;
|
|
@@ -163,7 +153,4 @@ TEST_CASE("Coordinate conversion with different viewport sizes") {
|
|
|
double openglY = static_cast<double>(height) - glfwY;
|
|
double openglY = static_cast<double>(height) - glfwY;
|
|
|
CHECK(openglY == 600.0);
|
|
CHECK(openglY == 600.0);
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-} // namespace WallpaperEngine::Input::Drivers::Test
|
|
|
|
|
-
|
|
|
|
|
|
|
+}
|