You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.7 KiB
C++
93 lines
3.7 KiB
C++
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
#include <Atom/RPI.Public/Image/DefaultStreamingImageController.h>
|
|
#include <Atom/RPI.Public/Image/StreamingImage.h>
|
|
|
|
#include <AtomCore/Instance/InstanceDatabase.h>
|
|
|
|
#include <AzCore/Serialization/SerializeContext.h>
|
|
|
|
namespace AZ
|
|
{
|
|
namespace RPI
|
|
{
|
|
Data::Instance<DefaultStreamingImageController> DefaultStreamingImageController::FindOrCreate(const Data::Asset<DefaultStreamingImageControllerAsset>& asset)
|
|
{
|
|
return azrtti_cast<DefaultStreamingImageController*>(
|
|
Data::InstanceDatabase<StreamingImageController>::Instance().FindOrCreate(
|
|
Data::InstanceId::CreateFromAssetId(asset.GetId()),
|
|
asset));
|
|
}
|
|
|
|
AZ::Data::Instance<DefaultStreamingImageController> DefaultStreamingImageController::CreateInternal(Data::AssetData* assetData)
|
|
{
|
|
DefaultStreamingImageControllerAsset* specificAsset = azrtti_cast<DefaultStreamingImageControllerAsset*>(assetData);
|
|
if (!specificAsset)
|
|
{
|
|
AZ_Error("DefaultStreamingImageController", false, "DefaultStreamingImageController instance requires a DefaultStreamingImageControllerAsset.");
|
|
return nullptr;
|
|
}
|
|
|
|
Data::Instance<DefaultStreamingImageController> instance = aznew DefaultStreamingImageController();
|
|
|
|
const RHI::ResultCode resultCode = instance->Init(*specificAsset);
|
|
if (resultCode == RHI::ResultCode::Success)
|
|
{
|
|
return instance;
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
RHI::ResultCode DefaultStreamingImageController::Init([[maybe_unused]] DefaultStreamingImageControllerAsset& imageControllerAsset)
|
|
{
|
|
return RHI::ResultCode::Success;
|
|
}
|
|
|
|
StreamingImageContextPtr DefaultStreamingImageController::CreateContextInternal()
|
|
{
|
|
StreamingImageContextPtr context = aznew StreamingImageContext();
|
|
m_recentlyAttachedContexts.emplace_back(context);
|
|
return context;
|
|
}
|
|
|
|
void DefaultStreamingImageController::UpdateInternal(size_t timestamp, const StreamingImageContextList& contexts)
|
|
{
|
|
AZ_UNUSED(timestamp);
|
|
AZ_UNUSED(contexts);
|
|
|
|
const uint32_t maxExpandsCount = 20;
|
|
uint32_t mipsExpandsPerUpdate = 0;
|
|
|
|
// [GFX TODO] [ATOM-551] Streaming image control of DefaultStreamingImageController
|
|
// For now we always stream in all the mips. Of course we need to make this smarter at some point.
|
|
if (!m_recentlyAttachedContexts.empty())
|
|
{
|
|
for (auto& context : m_recentlyAttachedContexts)
|
|
{
|
|
if (StreamingImage* image = context->TryGetImage())
|
|
{
|
|
QueueExpandToMipChainLevel(image, 0);
|
|
mipsExpandsPerUpdate++;
|
|
if (mipsExpandsPerUpdate >= maxExpandsCount)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
m_recentlyAttachedContexts.erase(m_recentlyAttachedContexts.begin(), m_recentlyAttachedContexts.begin() + mipsExpandsPerUpdate);
|
|
}
|
|
}
|
|
}
|
|
}
|