SkinnedMeshShaderOptionsCache.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <Atom/Feature/SkinnedMesh/SkinnedMeshShaderOptions.h>
  10. #include <Atom/RPI.Reflect/Shader/ShaderOptionGroup.h>
  11. #include <AtomCore/Instance/Instance.h>
  12. #include <AzCore/EBus/Event.h>
  13. namespace AZ
  14. {
  15. namespace RPI
  16. {
  17. class Shader;
  18. }
  19. namespace Render
  20. {
  21. class CachedSkinnedMeshShaderOptions;
  22. //! Notifies listeners that the skinned mesh shader has reloaded and the shader options need to be updated
  23. class SkinnedMeshShaderOptionNotifications
  24. : public AZ::EBusTraits
  25. {
  26. public:
  27. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
  28. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  29. using BusIdType = CachedSkinnedMeshShaderOptions*;
  30. using MutexType = AZStd::mutex;
  31. virtual void OnShaderReinitialized(const CachedSkinnedMeshShaderOptions* cachedShaderOptions) = 0;
  32. };
  33. using SkinnedMeshShaderOptionNotificationBus = AZ::EBus<SkinnedMeshShaderOptionNotifications>;
  34. //! This class caches the indices of the skinned mesh shader options and uses them to more optimally create a ShaderOptionGroup
  35. class CachedSkinnedMeshShaderOptions
  36. {
  37. public:
  38. void SetShader(Data::Instance<RPI::Shader> shader);
  39. void ConnectToShaderReinitializedEvent(SkinnedMeshShaderOptionNotificationBus::Handler& shaderReinitializedEventHandler);
  40. RPI::ShaderOptionGroup CreateShaderOptionGroup(const SkinnedMeshShaderOptions& shaderOptions) const;
  41. private:
  42. Data::Instance<RPI::Shader> m_shader;
  43. RPI::ShaderOptionIndex m_skinningMethodOptionIndex;
  44. RPI::ShaderOptionValue m_skinningMethodLinearSkinningValue;
  45. RPI::ShaderOptionValue m_skinningMethodDualQuaternionValue;
  46. RPI::ShaderOptionIndex m_applyMorphTargetOptionIndex;
  47. RPI::ShaderOptionValue m_applyMorphTargetFalseValue;
  48. RPI::ShaderOptionValue m_applyMorphTargetTrueValue;
  49. };
  50. } // namespace Render
  51. } // namespace AZ