IndexAttribute.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2019.08.13
  7. #pragma once
  8. #include <cstddef>
  9. #include <cstdint>
  10. // The IndexAttribute class represents an array of triples of indices into a
  11. // vertex array for an indexed triangle mesh. For now, the source must be
  12. // either uint16_t or uint32_t.
  13. namespace WwiseGTE
  14. {
  15. struct IndexAttribute
  16. {
  17. // Construction.
  18. inline IndexAttribute(void* inSource = nullptr, size_t inSize = 0)
  19. :
  20. source(inSource),
  21. size(inSize)
  22. {
  23. }
  24. // Triangle access.
  25. inline void SetTriangle(uint32_t t, uint32_t v0, uint32_t v1, uint32_t v2)
  26. {
  27. if (size == sizeof(uint32_t))
  28. {
  29. uint32_t* index = reinterpret_cast<uint32_t*>(source) + 3 * t;
  30. index[0] = v0;
  31. index[1] = v1;
  32. index[2] = v2;
  33. return;
  34. }
  35. if (size == sizeof(uint16_t))
  36. {
  37. uint16_t* index = reinterpret_cast<uint16_t*>(source) + 3 * t;
  38. index[0] = static_cast<uint16_t>(v0);
  39. index[1] = static_cast<uint16_t>(v1);
  40. index[2] = static_cast<uint16_t>(v2);
  41. return;
  42. }
  43. // Unsupported type.
  44. }
  45. inline void GetTriangle(uint32_t t, uint32_t& v0, uint32_t& v1, uint32_t& v2) const
  46. {
  47. if (size == sizeof(uint32_t))
  48. {
  49. uint32_t* index = reinterpret_cast<uint32_t*>(source) + 3 * t;
  50. v0 = index[0];
  51. v1 = index[1];
  52. v2 = index[2];
  53. return;
  54. }
  55. if (size == sizeof(uint16_t))
  56. {
  57. uint16_t* index = reinterpret_cast<uint16_t*>(source) + 3 * t;
  58. v0 = static_cast<uint32_t>(index[0]);
  59. v1 = static_cast<uint32_t>(index[1]);
  60. v2 = static_cast<uint32_t>(index[2]);
  61. return;
  62. }
  63. // Unsupported type.
  64. v0 = 0;
  65. v1 = 0;
  66. v2 = 0;
  67. }
  68. // The source pointer must be 4-byte aligned, which is guaranteed on
  69. // 32-bit and 64-bit architectures. The size is the number of bytes
  70. // per index.
  71. void* source;
  72. size_t size;
  73. };
  74. }