/* * 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 * */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace AtomSampleViewer { //! Demonstrates queued uploads of data to the GPU while something is rendering. //! In effect this tests the AsyncUploadQueue class in the RHI back-end implementations. //! The expected output is a textured quad where the texture is frequently replaced and the //! position of the quad frequently changes. class CopyQueueComponent final : public BasicRHIComponent { public: AZ_COMPONENT(CopyQueueComponent, "{581AB2F2-C969-4572-9B40-4EE13D862C72}", AZ::Component); AZ_DISABLE_COPY(CopyQueueComponent); static void Reflect(AZ::ReflectContext* context); CopyQueueComponent(); ~CopyQueueComponent() override = default; protected: // AZ::Component void Activate() override; void Deactivate() override; // RHISystemNotificationBus::Handler void OnFramePrepare(AZ::RHI::FrameGraphBuilder& frameGraphBuilder) override; void UploadTextureAsAsset(const char* filePath, int index); /// Updates the content of the vertex position buffer to animated based on a time value void UpdateVertexPositions(float timeValue); /// Uploads the vertex position buffer to the GPU void UploadVertexBuffer(); AZ::RHI::ShaderInputImageIndex m_textureInputIndex; AZ::RHI::Ptr m_bufferPool; AZ::RHI::Ptr m_indexBuffer; AZ::RHI::Ptr m_positionBuffer; AZ::RHI::Ptr m_uvBuffer; AZ::RHI::ConstPtr m_pipelineState; AZ::Data::Instance m_shaderResourceGroup; AZ::RHI::ShaderInputConstantIndex m_objectMatrixConstantIndex; /// Tracks state used for 'animating' the textured quad to adjust its size and the texture in use. struct ProcessingState { static constexpr float ChangeDelay = 0.5f; static constexpr int TextureCount = 3; static constexpr float TickAmount = 0.005f; float m_time = 0.0f; float m_timeUntilChange = 0.0f; int m_changeCount = 0; }; ProcessingState m_processingState; struct BufferData { AZStd::array m_positions; AZStd::array m_uvs; AZStd::array m_indices; }; BufferData m_bufferData; AZ::RHI::DrawItem m_drawItem; AZStd::array m_streamBufferViews; static const int numberOfPaths = 3; const char* m_filePaths[numberOfPaths] = { "textures/streaming/streaming1.dds.streamingimage", "textures/streaming/streaming2.dds.streamingimage", "textures/streaming/streaming3.dds.streamingimage", }; AZStd::array, 3> m_images; }; } // namespace AtomSampleViewer #pragma once