Files
o3de/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAssetHandler.cpp
T
Tommy Walton f1d9e7ae28 Skybox hot reloading - fix black screen when running the editor for the first time with a clean cache (#5529)
* Add a default fallback image when a StreamingImageAsset fails to load

Signed-off-by: Tommy Walton <waltont@amazon.com>

* Don't release a missing/invalid texture reference in the skybox component. Hold on to the reference so that it can hot-reload

Signed-off-by: Tommy Walton <waltont@amazon.com>

* Don't release a missing/invalid texture reference in the ibl component. Hold on to the reference so that it can hot-reload

Signed-off-by: Tommy Walton <waltont@amazon.com>

* Use a different fallback image depending on the status of the asset. Including a setting to use a friendly image that is less obnoxious for anything that might have been missed in a release build

Signed-off-by: Tommy Walton <waltont@amazon.com>

* Adding the stubbed in fallback textures

Signed-off-by: Tommy Walton <waltont@amazon.com>

* Updated the seedlist for the RPI to include the fallback images. It only needs the default and the missing asset images, since the AP doesn't run in release builds, the asset status will always be unknown, not processing or failed to process, so if an asset is not bundled, it is just missing.

Signed-off-by: Tommy Walton <waltont@amazon.com>

* Switched to GetAssetIdByPath and removed some tabs

Signed-off-by: Tommy Walton <waltont@amazon.com>
2021-11-11 12:55:06 -08:00

98 lines
4.4 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <Atom/RPI.Reflect/Image/StreamingImageAssetHandler.h>
#include <AzCore/Settings/SettingsRegistry.h>
#include <AzFramework/Asset/AssetSystemBus.h>
namespace AZ
{
namespace RPI
{
Data::AssetHandler::LoadResult StreamingImageAssetHandler::LoadAssetData(
const Data::Asset<Data::AssetData>& asset,
AZStd::shared_ptr<Data::AssetDataStream> stream,
const Data::AssetFilterCB& assetLoadFilterCB)
{
AZ_UNUSED(assetLoadFilterCB);
StreamingImageAsset* assetData = asset.GetAs<StreamingImageAsset>();
AZ_Assert(assetData, "Asset is of the wrong type.");
AZ_Assert(m_serializeContext, "Unable to retrieve serialize context.");
Data::AssetHandler::LoadResult loadResult = Data::AssetHandler::LoadResult::Error;
if (assetData)
{
loadResult = Utils::LoadObjectFromStreamInPlace<StreamingImageAsset>(*stream, *assetData, m_serializeContext) ?
Data::AssetHandler::LoadResult::LoadComplete :
Data::AssetHandler::LoadResult::Error;
if (loadResult == Data::AssetHandler::LoadResult::LoadComplete)
{
// ImageMipChainAsset has some internal variables need to initialized after it was loaded.
StreamingImageAsset* assetData2 = asset.GetAs<StreamingImageAsset>();
assetData2->m_tailMipChain.Init();
}
}
return loadResult;
}
Data::AssetId StreamingImageAssetHandler::AssetMissingInCatalog(const Data::Asset<Data::AssetData>& asset)
{
// Find out if the asset is missing completely, or just still processing
// and escalate the asset to the top of the list
AzFramework::AssetSystem::AssetStatus missingAssetStatus;
AzFramework::AssetSystemRequestBus::BroadcastResult(
missingAssetStatus, &AzFramework::AssetSystem::AssetSystemRequests::GetAssetStatusById, asset.GetId().m_guid);
// Determine which fallback image to use
const char* relativePath = "textures/defaults/defaultfallback.png.streamingimage";
bool useDebugFallbackImages = true;
if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
{
settingsRegistry->GetObject(useDebugFallbackImages, "/O3DE/Atom/RPI/UseDebugFallbackImages");
}
if (useDebugFallbackImages)
{
switch (missingAssetStatus)
{
case AzFramework::AssetSystem::AssetStatus::AssetStatus_Queued:
case AzFramework::AssetSystem::AssetStatus::AssetStatus_Compiling:
relativePath = "textures/defaults/processing.png.streamingimage";
break;
case AzFramework::AssetSystem::AssetStatus::AssetStatus_Failed:
relativePath = "textures/defaults/processingfailed.png.streamingimage";
break;
case AzFramework::AssetSystem::AssetStatus::AssetStatus_Missing:
case AzFramework::AssetSystem::AssetStatus::AssetStatus_Unknown:
case AzFramework::AssetSystem::AssetStatus::AssetStatus_Compiled:
relativePath = "textures/defaults/missing.png.streamingimage";
break;
}
}
// Make sure the fallback image has been processed
AzFramework::AssetSystem::AssetStatus status = AzFramework::AssetSystem::AssetStatus_Unknown;
AzFramework::AssetSystemRequestBus::BroadcastResult(
status, &AzFramework::AssetSystemRequestBus::Events::CompileAssetSync, relativePath);
// Return the asset id of the fallback image
Data::AssetId assetId{};
bool autoRegisterIfNotFound = false;
Data::AssetCatalogRequestBus::BroadcastResult(
assetId, &Data::AssetCatalogRequestBus::Events::GetAssetIdByPath, relativePath,
azrtti_typeid<AZ::RPI::StreamingImageAsset>(), autoRegisterIfNotFound);
return assetId;
}
} // namespace RPI
} // namespace AZ