/* * 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. * */ #pragma once #include #include #include #include #include #include #include namespace AZ { namespace RPI { class ImageMipChainAsset; class StreamingImageAsset; class MaterialAsset; } namespace Render { //! Helper class used by DecalTextureArrayFeatureProcessor. //! Given a set of images (all with the same dimensions and format), it can pack them together into a single textureArray that can be sent to the GPU. class DecalTextureArray : public Data::AssetBus::MultiHandler { public: int AddMaterial(const AZ::Data::AssetId materialAssetId); void RemoveMaterial(const int index); size_t NumMaterials() const; AZ::Data::AssetId GetMaterialAssetId(const int index) const; void Pack(); const Data::Instance& GetPackedTexture() const; static bool IsValidDecalMaterial(const RPI::MaterialAsset& materialAsset); private: struct MaterialData { AZ::Data::AssetId m_materialAssetId; // We will clear this to nullptr as soon as it is packed in order to release the memory. Note that we might need to reload it in order to repack it. AZ::Data::Asset m_materialAssetData; }; void OnAssetReady(Data::Asset asset) override; int FindMaterial(const AZ::Data::AssetId materialAssetId) const; // packs the contents of the source images into a texture array readable by the GPU and returns it AZ::Data::Asset BuildPackedMipChainAsset(const size_t numTexturesToCreate); RHI::ImageDescriptor CreatePackedImageDescriptor(const uint16_t arraySize, const uint16_t mipLevels) const; uint16_t GetNumMipLevels() const; RHI::Size GetImageDimensions() const; RHI::Format GetFormat() const; RHI::ImageSubresourceLayout GetLayout(int mip) const; AZStd::array_view GetRawImageData(int arrayLevel, int mip) const; bool AreAllAssetsReady() const; bool IsAssetReady(const MaterialData& materialData) const; void ClearAssets(); void ClearAsset(MaterialData& materialData); void QueueAssetLoads(); void QueueAssetLoad(MaterialData& materialData); bool NeedsPacking() const; IndexableList m_materials; Data::Instance m_textureArrayPacked; AZStd::unordered_set m_assetsCurrentlyLoading; }; } // namespace Render } // namespace AZ