3
0

UvStreamTangentBitmask.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 <Atom/RPI.Public/Model/UvStreamTangentBitmask.h>
  9. #include <AzCore/Debug/Trace.h>
  10. namespace AZ
  11. {
  12. namespace RPI
  13. {
  14. uint32_t UvStreamTangentBitmask::GetFullTangentBitmask() const
  15. {
  16. return m_mask;
  17. }
  18. uint32_t UvStreamTangentBitmask::GetUvStreamCount() const
  19. {
  20. return m_mask >> (sizeof(m_mask) * CHAR_BIT - BitsForUvIndex);
  21. }
  22. uint32_t UvStreamTangentBitmask::GetTangentAtUv(uint32_t uvIndex) const
  23. {
  24. return (m_mask >> (BitsPerTangent * uvIndex)) & 0b1111u;
  25. }
  26. void UvStreamTangentBitmask::ApplyTangent(uint32_t tangentIndex)
  27. {
  28. uint32_t currentSlot = GetUvStreamCount();
  29. if (currentSlot >= MaxUvSlots)
  30. {
  31. AZ_Error("UV Stream", false, "Reaching the max of avaiblable stream slots.");
  32. return;
  33. }
  34. if (tangentIndex > UnassignedTangent)
  35. {
  36. AZ_Warning(
  37. "UV Stream", false,
  38. "Tangent index must use %d bits as defined in UvStreamTangentIndex::m_flag. Unassigned index will be applied.",
  39. BitsPerTangent);
  40. tangentIndex = UnassignedTangent;
  41. }
  42. uint32_t clearMask = 0b1111u << (BitsPerTangent * currentSlot);
  43. clearMask = ~clearMask;
  44. // Clear the writing bits in case
  45. m_mask &= clearMask;
  46. // Write the bits to the slot
  47. m_mask |= (tangentIndex << (BitsPerTangent * currentSlot));
  48. // Increase the index
  49. m_mask += (1u << (sizeof(m_mask) * CHAR_BIT - BitsForUvIndex));
  50. }
  51. void UvStreamTangentBitmask::Reset()
  52. {
  53. m_mask = 0;
  54. }
  55. }
  56. }