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
@@ -185,7 +185,7 @@ namespace AZ
materialAssignmentId);
previewRenderer->AddCaptureRequest(
{ 128,
{ m_materialPreviewResolution,
AZStd::make_shared<AZ::LyIntegration::SharedPreviewContent>(
previewRenderer->GetScene(), previewRenderer->GetView(), previewRenderer->GetEntityContextId(),
AZ::RPI::AssetUtils::GetAssetIdForProductPath(DefaultModelPath), materialAssetId,
@@ -220,11 +220,17 @@ namespace AZ
return QPixmap();
}
void EditorMaterialSystemComponent::OnEntityDestroyed(const AZ::EntityId& entityId)
{
m_materialPreviews.erase(entityId);
}
void EditorMaterialSystemComponent::OnRenderMaterialPreviewComplete(
[[maybe_unused]] const AZ::EntityId& entityId,
[[maybe_unused]] const AZ::Render::MaterialAssignmentId& materialAssignmentId,
[[maybe_unused]] const QPixmap& pixmap)
{
PurgePreviews();
m_materialPreviews[entityId][materialAssignmentId] = pixmap;
}
@@ -281,5 +287,22 @@ namespace AZ
}
return AzToolsFramework::AssetBrowser::SourceFileDetails();
}
void EditorMaterialSystemComponent::PurgePreviews()
{
size_t materialPreviewCount = 0;
for (const auto& [entityId, previews] : m_materialPreviews)
{
for (const auto& [assignmentId, images] : previews)
{
materialPreviewCount += previews.size();
}
}
if (materialPreviewCount > m_materialPreviewLimit)
{
m_materialPreviews.clear();
}
}
} // namespace Render
} // namespace AZ