Size.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/RHI.Reflect/Size.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/std/algorithm.h>
  11. #include <AzCore/std/hash.h>
  12. namespace AZ::RHI
  13. {
  14. void Size::Reflect(AZ::ReflectContext* context)
  15. {
  16. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  17. {
  18. serializeContext->Class<Size>()
  19. ->Version(1)
  20. ->Field("Width", &Size::m_width)
  21. ->Field("Height", &Size::m_height)
  22. ->Field("Depth", &Size::m_depth)
  23. ;
  24. }
  25. }
  26. Size::Size(uint32_t width, uint32_t height, uint32_t depth)
  27. : m_width{width}
  28. , m_height{height}
  29. , m_depth{depth}
  30. {}
  31. Size Size::GetReducedMip(uint32_t mipLevel) const
  32. {
  33. Size size;
  34. size.m_width = AZStd::max(m_width >> mipLevel, 1u);
  35. size.m_height = AZStd::max(m_height >> mipLevel, 1u);
  36. size.m_depth = AZStd::max(m_depth >> mipLevel, 1u);
  37. return size;
  38. }
  39. bool Size::operator == (const Size& rhs) const
  40. {
  41. return m_width == rhs.m_width && m_height == rhs.m_height && m_depth == rhs.m_depth;
  42. }
  43. bool Size::operator != (const Size& rhs) const
  44. {
  45. return m_width != rhs.m_width || m_height != rhs.m_height || m_depth != rhs.m_depth;
  46. }
  47. uint32_t& Size::operator [] (uint32_t idx)
  48. {
  49. uint32_t* ptr = &m_width;
  50. return *(ptr + idx);
  51. }
  52. uint32_t Size::operator [] (uint32_t idx) const
  53. {
  54. const uint32_t* ptr = &m_width;
  55. return *(ptr + idx);
  56. }
  57. }