WhiteBoxRenderDataTest.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "WhiteBoxTestFixtures.h"
  9. #include <AzCore/UnitTest/TestTypes.h>
  10. #include <AzTest/AzTest.h>
  11. #include <vector>
  12. namespace UnitTest
  13. {
  14. using namespace WhiteBox;
  15. FaceTestData NonDegenerateFaceList = {
  16. {// Tri 0: non-degenerate
  17. AZ::Vector3{0.0f, 1.0f, 0.0f}, AZ::Vector3{1.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f},
  18. // Tri 1: non-degenerate
  19. AZ::Vector3{1.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 1.0f, 0.0f},
  20. // Tri 2: non-degenerate
  21. AZ::Vector3{0.0f, 0.0f, 1.0f}, AZ::Vector3{0.0f, 1.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f},
  22. // Tri 3: non-degenerate
  23. AZ::Vector3{0.0f, 1.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 1.0f}},
  24. 0};
  25. FaceTestData DegenerateFaceList = {
  26. {// Tri 0: degenerate
  27. AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{1.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f},
  28. // Tri 1: degenerate
  29. AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f},
  30. // Tri 2: degenerate
  31. AZ::Vector3{0.0f, 0.0f, 1.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f},
  32. // Tri 3: degenerate
  33. AZ::Vector3{0.0f, 0.0f, 1.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 1.0f}},
  34. 4};
  35. FaceTestData DegenerateAndNonDegenerateFaceList = {
  36. {// Tri 0: degenerate
  37. AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{1.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f},
  38. // Tri 1: non-degenerate
  39. AZ::Vector3{0.0f, 1.0f, 0.0f}, AZ::Vector3{1.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f},
  40. // Tri 2: degenerate
  41. AZ::Vector3{0.0f, 0.0f, 1.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f},
  42. // Tri 3: non-degenerate
  43. AZ::Vector3{1.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 1.0f, 0.0f},
  44. // Tri 4: non-degenerate
  45. AZ::Vector3{0.0f, 0.0f, 1.0f}, AZ::Vector3{0.0f, 1.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f},
  46. // Tri 5: non-degenerate
  47. AZ::Vector3{0.0f, 1.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 1.0f},
  48. // Tri 6: degenerate
  49. AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f}, AZ::Vector3{0.0f, 0.0f, 0.0f}},
  50. 3};
  51. TEST_P(WhiteBoxVertexDataTestFixture, BuildCulledTriangleList)
  52. {
  53. // given the raw positional data
  54. const FaceTestData& faceData = GetParam();
  55. // expect the vertex data to be composed of only triangle primitives
  56. // (we cannot proceed any further with the test if this isn't the case)
  57. ASSERT_EQ(faceData.m_positions.size() % 3, 0);
  58. // given an input list of valid and/or degenerate triangles
  59. const WhiteBoxFaces inVertexData = ConstructFaceData(faceData);
  60. // build the output list of visible triangles from the input list
  61. const WhiteBoxFaces outVertexData = BuildCulledWhiteBoxFaces(inVertexData);
  62. const size_t numInTriangles = inVertexData.size();
  63. const size_t numOutTriangles = outVertexData.size();
  64. // expect the number of triangles in the input list to always be at least as
  65. // as the the number of culled triangles in the output list
  66. EXPECT_GE(numInTriangles, numOutTriangles);
  67. // expect the number of triangles culled from the input list to equal that
  68. // of the expected number of triangles to be culled
  69. EXPECT_EQ(numOutTriangles, numInTriangles - faceData.m_numCulledFaces);
  70. }
  71. INSTANTIATE_TEST_CASE_P(
  72. NonDegenerateFaceList, WhiteBoxVertexDataTestFixture, ::testing::Values(NonDegenerateFaceList));
  73. INSTANTIATE_TEST_CASE_P(DegenerateFaceList, WhiteBoxVertexDataTestFixture, ::testing::Values(DegenerateFaceList));
  74. INSTANTIATE_TEST_CASE_P(
  75. DegenerateAndNonDegenerateFaceList, WhiteBoxVertexDataTestFixture,
  76. ::testing::Values(DegenerateAndNonDegenerateFaceList));
  77. } // namespace UnitTest