AtomViewportDisplayIconsSystemComponent.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/Component/Component.h>
  10. #include <AzToolsFramework/API/EditorViewportIconDisplayInterface.h>
  11. #include <Atom/RPI.Public/DynamicDraw/DynamicDrawInterface.h>
  12. #include <Atom/Bootstrap/BootstrapNotificationBus.h>
  13. #include <QImage>
  14. #include <QSize>
  15. #include <QString>
  16. namespace AZ
  17. {
  18. class TickRequests;
  19. namespace Render
  20. {
  21. class AtomViewportDisplayIconsSystemComponent
  22. : public AZ::Component
  23. , public AzToolsFramework::EditorViewportIconDisplayInterface
  24. , public AZ::Render::Bootstrap::NotificationBus::Handler
  25. , private Data::AssetBus::Handler
  26. {
  27. public:
  28. AZ_COMPONENT(AtomViewportDisplayIconsSystemComponent, "{AEC1D3E1-1D9A-437A-B4C6-CFAEE620C160}");
  29. static void Reflect(AZ::ReflectContext* context);
  30. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  31. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  32. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  33. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  34. protected:
  35. // AZ::Component overrides...
  36. void Activate() override;
  37. void Deactivate() override;
  38. // AzToolsFramework::EditorViewportIconDisplayInterface overrides...
  39. void DrawIcon(const DrawParameters& drawParameters) override;
  40. IconId GetOrLoadIconForPath(AZStd::string_view path) override;
  41. IconLoadStatus GetIconLoadStatus(IconId icon) override;
  42. // AZ::Render::Bootstrap::NotificationBus::Handler overrides...
  43. void OnBootstrapSceneReady(AZ::RPI::Scene* bootstrapScene) override;
  44. // Data::AssetBus::Handler overrides...
  45. void OnAssetReady(Data::Asset<Data::AssetData> asset) override;
  46. private:
  47. static constexpr const char* DrawContextShaderPath = "Shaders/TexturedIcon.azshader";
  48. static constexpr QSize MinimumRenderedSvgSize = QSize(128, 128);
  49. static constexpr QImage::Format QtImageFormat = QImage::Format_RGBA8888;
  50. QString FindAssetPath(const QString& path) const;
  51. QImage RenderSvgToImage(const QString& svgPath) const;
  52. AZ::Data::Instance<AZ::RPI::Image> ConvertToAtomImage(AZ::Uuid assetId, QImage image) const;
  53. Name m_drawContextName = Name("ViewportIconDisplay");
  54. bool m_shaderIndexesInitialized = false;
  55. RHI::ShaderInputNameIndex m_textureParameterIndex = "m_texture";
  56. RHI::ShaderInputNameIndex m_viewportSizeIndex = "m_viewportSize";
  57. struct IconData
  58. {
  59. AZStd::string m_path;
  60. AZ::Data::Instance<AZ::RPI::Image> m_image = nullptr;
  61. };
  62. AZStd::unordered_map<IconId, IconData> m_iconData;
  63. IconId m_currentId = 0;
  64. bool m_drawContextRegistered = false;
  65. };
  66. } // namespace Render
  67. } // namespace AZ