The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tests: Add uv to tangent lengths test

+113 -1
+2 -1
tests/CMakeLists.txt
··· 37 37 list(APPEND tests tests_comp_client_d3d12) 38 38 endif() 39 39 if(XRT_HAVE_VULKAN) 40 - list(APPEND tests tests_comp_client_vulkan) 40 + list(APPEND tests tests_comp_client_vulkan tests_uv_to_tangent) 41 41 endif() 42 42 if(XRT_HAVE_OPENGL 43 43 AND XRT_HAVE_OPENGL_GLX ··· 101 101 target_link_libraries( 102 102 tests_comp_client_vulkan PRIVATE comp_client comp_mock comp_util aux_vk 103 103 ) 104 + target_link_libraries(tests_uv_to_tangent PRIVATE comp_render) 104 105 endif() 105 106 106 107 if(_have_opengl_test)
+111
tests/tests_uv_to_tangent.cpp
··· 1 + // Copyright 2023, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Testing UV to tangent values. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + */ 8 + 9 + #include "catch/catch.hpp" 10 + 11 + #include "math/m_mathinclude.h" 12 + #include "render/render_interface.h" 13 + 14 + 15 + #define QUARTER_PI (M_PI / 4) 16 + #define SIXTH_PI (M_PI / 6) 17 + #define MARGIN (0.000001) 18 + 19 + static inline xrt_normalized_rect 20 + rect(float x, float y, float w, float h) 21 + { 22 + xrt_normalized_rect rect = {x, y, w, h}; 23 + return rect; 24 + } 25 + 26 + static inline void 27 + check(xrt_normalized_rect &result, xrt_normalized_rect &&truth) 28 + { 29 + REQUIRE_THAT(result.x, Catch::WithinAbs(truth.x, MARGIN)); 30 + REQUIRE_THAT(result.y, Catch::WithinAbs(truth.y, MARGIN)); 31 + REQUIRE_THAT(result.w, Catch::WithinAbs(truth.w, MARGIN)); 32 + REQUIRE_THAT(result.h, Catch::WithinAbs(truth.h, MARGIN)); 33 + } 34 + 35 + #define CAPUTER_FOV(FOV) CAPTURE(FOV.angle_up, FOV.angle_down, FOV.angle_left, FOV.angle_right); 36 + 37 + 38 + TEST_CASE("render_calc_uv_to_tangent_lengths_rect") 39 + { 40 + // Sanity check. 41 + REQUIRE_THAT(tan(QUARTER_PI), Catch::WithinAbs(1.0, MARGIN)); 42 + 43 + SECTION("45_degrees") 44 + { 45 + struct xrt_fov f45 = XRT_STRUCT_INIT; 46 + f45.angle_down = -QUARTER_PI; 47 + f45.angle_up = QUARTER_PI; 48 + f45.angle_left = -QUARTER_PI; 49 + f45.angle_right = QUARTER_PI; 50 + 51 + SECTION("normal") 52 + { 53 + CAPTURE(f45.angle_up, f45.angle_down, f45.angle_left, f45.angle_right); 54 + struct xrt_normalized_rect result; 55 + render_calc_uv_to_tangent_lengths_rect(&f45, &result); 56 + 57 + /* 58 + * We expect a fov of 45 degrees in all angles to have tangets 59 + * of 1 or -1. In order to transform uv [0 .. 1] to [-1 .. 1] 60 + * we need to have a width of 2 and a offset of -1. 61 + */ 62 + check(result, rect(-1, -1, 2, 2)); 63 + } 64 + 65 + SECTION("flipped_vertical") 66 + { 67 + f45.angle_down = -f45.angle_down; 68 + f45.angle_up = -f45.angle_up; 69 + 70 + CAPUTER_FOV(f45); 71 + struct xrt_normalized_rect result; 72 + render_calc_uv_to_tangent_lengths_rect(&f45, &result); 73 + 74 + // We expect the same values as normal but with y and h negated. 75 + check(result, rect(-1, 1, 2, -2)); 76 + } 77 + 78 + SECTION("flipped_horizontal") 79 + { 80 + f45.angle_left = -f45.angle_left; 81 + f45.angle_right = -f45.angle_right; 82 + 83 + CAPUTER_FOV(f45); 84 + struct xrt_normalized_rect result; 85 + render_calc_uv_to_tangent_lengths_rect(&f45, &result); 86 + 87 + // We expect the same values as normal but with x and w negated. 88 + check(result, rect(1, -1, -2, 2)); 89 + } 90 + } 91 + 92 + 93 + SECTION("30_degrees") 94 + { 95 + struct xrt_fov f30 = XRT_STRUCT_INIT; 96 + f30.angle_down = -SIXTH_PI; 97 + f30.angle_up = SIXTH_PI; 98 + f30.angle_left = -SIXTH_PI; 99 + f30.angle_right = SIXTH_PI; 100 + 101 + CAPUTER_FOV(f30); 102 + struct xrt_normalized_rect result; 103 + render_calc_uv_to_tangent_lengths_rect(&f30, &result); 104 + 105 + float t = tan(SIXTH_PI); 106 + float t2 = t * 2; 107 + 108 + // We expect the offset to be -tan(PI/6) and the lengths to be tan(PI/6) * 2. 109 + check(result, rect(-t, -t, t2, t2)); 110 + } 111 + }