Additional preview renderer checks

Preventing multiple preview renderers from being created with multiple catalog loaded notifications
Purging material preview images reaching a maximum number of stored images
Purging material previews if entity gets destroyed

Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
Guthrie Adams
2021-10-18 18:21:50 -05:00
parent c8dc309b32
commit 5b8a37a75b
5 changed files with 51 additions and 10 deletions
@@ -11,6 +11,7 @@
#include <AtomLyIntegration/CommonFeatures/Material/EditorMaterialSystemComponentRequestBus.h>
#include <AzCore/Asset/AssetCommon.h>
#include <AzCore/Component/Component.h>
#include <AzCore/Component/EntityBus.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
#include <AzToolsFramework/Viewport/ActionBus.h>
@@ -24,6 +25,7 @@ namespace AZ
//! System component that manages launching and maintaining connections with the material editor.
class EditorMaterialSystemComponent final
: public AZ::Component
, public AZ::EntitySystemBus::Handler
, public EditorMaterialSystemComponentNotificationBus::Handler
, public EditorMaterialSystemComponentRequestBus::Handler
, public AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler
@@ -54,9 +56,12 @@ namespace AZ
QPixmap GetRenderedMaterialPreview(
const AZ::EntityId& entityId, const AZ::Render::MaterialAssignmentId& materialAssignmentId) const override;
// AZ::EntitySystemBus::Handler overrides...
void OnEntityDestroyed(const AZ::EntityId& entityId) override;
//! EditorMaterialSystemComponentNotificationBus::Handler overrides...
void OnRenderMaterialPreviewComplete(
const AZ::EntityId& entityId, const AZ::Render::MaterialAssignmentId& materialAssignmentId, const QPixmap& pixmap)override;
const AZ::EntityId& entityId, const AZ::Render::MaterialAssignmentId& materialAssignmentId, const QPixmap& pixmap) override;
//! AssetBrowserInteractionNotificationBus::Handler overrides...
AzToolsFramework::AssetBrowser::SourceFileDetails GetSourceFileDetails(const char* fullSourceFileName) override;
@@ -68,9 +73,13 @@ namespace AZ
// AztoolsFramework::EditorEvents::Bus::Handler overrides...
void NotifyRegisterViews() override;
void PurgePreviews();
QAction* m_openMaterialEditorAction = nullptr;
AZStd::unique_ptr<MaterialBrowserInteractions> m_materialBrowserInteractions;
AZStd::unordered_map<AZ::EntityId, AZStd::unordered_map<AZ::Render::MaterialAssignmentId, QPixmap>> m_materialPreviews;
static constexpr const size_t m_materialPreviewLimit = 100;
static constexpr const int m_materialPreviewResolution = 128;
};
} // namespace Render
} // namespace AZ