DecalContainer.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #pragma once
  9. #include <AzCore/std/containers/vector.h>
  10. #include <AzCore/Math/Quaternion.h>
  11. #include <Atom/Feature/Decals/DecalFeatureProcessorInterface.h>
  12. namespace AtomSampleViewer
  13. {
  14. //! Helper class used by the AtomSampleViewer examples.
  15. //! Stores a list of decals and will automatically release them upon destruction of the container.
  16. class DecalContainer
  17. {
  18. public:
  19. DecalContainer(AZ::Render::DecalFeatureProcessorInterface* fp, const AZ::Vector3 position);
  20. DecalContainer(const DecalContainer&) = delete;
  21. DecalContainer& operator=(const DecalContainer&) = delete;
  22. ~DecalContainer();
  23. void SetNumDecalsActive(int numDecals);
  24. int GetMaxDecals() const { return aznumeric_cast<int>(m_decals.size()); }
  25. int GetNumDecalsActive() const { return m_numDecalsActive; }
  26. void CloneFrom(const DecalContainer& containerToClone);
  27. private:
  28. void SetupDecals();
  29. void SetupNewDecal(const AZ::Vector3 position, const AZ::Vector3 halfSize, const char* const decalMaterialName);
  30. void AcquireDecal(int i);
  31. void ReleaseDecal(int i);
  32. struct Decal
  33. {
  34. AZ::Vector3 m_position;
  35. AZ::Vector3 m_halfSize;
  36. AZ::Quaternion m_quaternion;
  37. const char* m_materialName = nullptr;
  38. AZ::Render::DecalFeatureProcessorInterface::DecalHandle m_decalHandle;
  39. };
  40. AZStd::vector<Decal> m_decals;
  41. AZ::Render::DecalFeatureProcessorInterface* m_decalFeatureProcessor = nullptr;
  42. int m_numDecalsActive = 0;
  43. AZ::Vector3 m_position;
  44. };
  45. } // namespace AtomSampleViewer