unit-MeshPrimitive.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include <catch2/catch.hpp>
  2. #include <iostream>
  3. #include <gul/MeshPrimitive.h>
  4. SCENARIO("Stride Copy")
  5. {
  6. GIVEN("A vertex attribute with 3 items")
  7. {
  8. gul::VertexAttribute_v V = std::vector<uint32_t>( {1,2,3});
  9. WHEN("We do a strideCopy with a stride size of 2*sizeof(uint32_t)")
  10. {
  11. std::vector<uint32_t> D = {0,0,0,0,0,0};
  12. gul::VertexAttributeStrideCopy(D.data(), V, 2*sizeof(uint32_t));
  13. THEN("Every other value is copied")
  14. {
  15. REQUIRE( D[0] == 1);
  16. REQUIRE( D[1] == 0);
  17. REQUIRE( D[2] == 2);
  18. REQUIRE( D[3] == 0);
  19. REQUIRE( D[4] == 3);
  20. REQUIRE( D[5] == 0);
  21. }
  22. }
  23. }
  24. }
  25. SCENARIO("Copy Interleaved")
  26. {
  27. GIVEN("Two vertex attributes")
  28. {
  29. gul::VertexAttribute_v V1 = std::vector<glm::uvec2>( {{1,2}, {3,4}});
  30. gul::VertexAttribute_v V2 = std::vector<glm::uvec3>( {{5,6,7}, {8,9,10}});
  31. WHEN("We copyInterleaved with the two attributes")
  32. {
  33. std::vector<uint32_t> D(100);
  34. gul::VertexAttributeInterleaved(D.data(), {&V1,&V2});
  35. THEN("Every other value is copied")
  36. {
  37. REQUIRE( D[0] == 1); //V1[0].x
  38. REQUIRE( D[1] == 2); //V1[0].y
  39. REQUIRE( D[2] == 5); //V2[0].x
  40. REQUIRE( D[3] == 6); //V2[0].y
  41. REQUIRE( D[4] == 7); //V2[0].z
  42. REQUIRE( D[5] == 3); //V1[1].x
  43. REQUIRE( D[6] == 4); //V1[1].y
  44. REQUIRE( D[7] == 8); //V2[1].x
  45. REQUIRE( D[8] == 9); //V2[1].y
  46. REQUIRE( D[9] == 10);//V2[1].z
  47. }
  48. }
  49. }
  50. }
  51. SCENARIO("Copy Sequential")
  52. {
  53. GIVEN("Two vertex attributes")
  54. {
  55. gul::VertexAttribute_v V1 = std::vector<glm::uvec2>( {{1,2}, {3,4}});
  56. gul::VertexAttribute_v V2 = std::vector<glm::uvec3>( {{5,6,7}, {8,9,10}});
  57. WHEN("We copySequential with the two attributes")
  58. {
  59. std::vector<uint32_t> D(100);
  60. auto offsets = gul::VertexAttributeCopySequential(D.data(), {&V1,&V2});
  61. REQUIRE( offsets[0] == 0);
  62. REQUIRE( offsets[1] == sizeof(glm::uvec2)*2);
  63. THEN("Attribute vectors are copied as if they were appended")
  64. {
  65. REQUIRE( D[0] == 1); //V1[0].x
  66. REQUIRE( D[1] == 2); //V1[0].y
  67. REQUIRE( D[2] == 3); //V1[1].x
  68. REQUIRE( D[3] == 4); //V1[1].y
  69. REQUIRE( D[4] == 5); //V2[0].z
  70. REQUIRE( D[5] == 6); //V2[0].x
  71. REQUIRE( D[6] == 7); //V2[0].y
  72. REQUIRE( D[7] == 8); //V2[1].x
  73. REQUIRE( D[8] == 9); //V2[1].y
  74. REQUIRE( D[9] == 10);//V2[1].z
  75. }
  76. }
  77. }
  78. }
  79. SCENARIO("Copy Sequential with nullptr")
  80. {
  81. GIVEN("Two vertex attributes")
  82. {
  83. gul::VertexAttribute_v V1 = std::vector<glm::uvec2>( {{1,2}, {3,4}});
  84. gul::VertexAttribute_v V2 = std::vector<glm::uvec3>();
  85. gul::VertexAttribute_v V3 = std::vector<glm::uvec3>( {{5,6,7}, {8,9,10}});
  86. WHEN("We copySequential with the three attributes, and one of them has zero attributes")
  87. {
  88. std::vector<uint32_t> D(100);
  89. auto offsets = gul::VertexAttributeCopySequential(D.data(), {&V1, &V2, &V3});
  90. THEN("We get an offset vector of size 3")
  91. {
  92. REQUIRE( offsets.size() == 3);
  93. }
  94. REQUIRE( offsets[0] == 0);
  95. THEN("The vertex with zero attributes has an offset of zero")
  96. {
  97. REQUIRE( offsets[1] == 0);
  98. }
  99. REQUIRE( offsets[2] == sizeof(glm::uvec2)*2);
  100. THEN("Attribute vectors are copied as if they were appended")
  101. {
  102. REQUIRE( D[0] == 1); //V1[0].x
  103. REQUIRE( D[1] == 2); //V1[0].y
  104. REQUIRE( D[2] == 3); //V1[1].x
  105. REQUIRE( D[3] == 4); //V1[1].y
  106. REQUIRE( D[4] == 5); //V2[0].z
  107. REQUIRE( D[5] == 6); //V2[0].x
  108. REQUIRE( D[6] == 7); //V2[0].y
  109. REQUIRE( D[7] == 8); //V2[1].x
  110. REQUIRE( D[8] == 9); //V2[1].y
  111. REQUIRE( D[9] == 10);//V2[1].z
  112. }
  113. }
  114. }
  115. }
  116. SCENARIO("Load obj")
  117. {
  118. std::ifstream in(CMAKE_SOURCE_DIR "/test/data/test.obj");
  119. auto M = gul::ReadOBJ(in);
  120. REQUIRE(M.indexCount() == 3);
  121. }