MultiViewportSwapchainComponent.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AtomCore/Instance/InstanceId.h>
  10. #include <AzCore/Component/EntityBus.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <AzFramework/Windowing/WindowBus.h>
  13. #include <AzFramework/Windowing/NativeWindow.h>
  14. #include <Atom/RHI/Factory.h>
  15. #include <Atom/RHI/FrameScheduler.h>
  16. #include <RHI/BasicRHIComponent.h>
  17. namespace AtomSampleViewer
  18. {
  19. //! A simple multi-viewport example with multiple swapchains.
  20. //! This sample just renders 2 windows, each with their own viewport and swapchain.
  21. class MultiViewportSwapchainComponent final
  22. : public BasicRHIComponent
  23. , public AZ::TickBus::Handler
  24. , public AzFramework::WindowNotificationBus::Handler
  25. {
  26. public:
  27. static constexpr const char* ContentWarning = CommonPhotosensitiveWarning;
  28. static constexpr const char* ContentWarningTitle = CommonPhotosensitiveWarningTitle;
  29. AZ_COMPONENT(MultiViewportSwapchainComponent, "{45118741-F7DB-4EE0-9EBF-59B85D7F6194}", AZ::Component);
  30. AZ_DISABLE_COPY(MultiViewportSwapchainComponent);
  31. static void Reflect(AZ::ReflectContext* context);
  32. MultiViewportSwapchainComponent();
  33. ~MultiViewportSwapchainComponent() override = default;
  34. /// AZ::Component
  35. void Activate() override;
  36. void Deactivate() override;
  37. private:
  38. // RHISystemNotificationBus::Handler
  39. void OnFramePrepare(AZ::RHI::FrameGraphBuilder& frameGraphBuilder) override;
  40. /// TickBus::Handler
  41. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  42. // AzFramework::WindowNotificationBus::Handler
  43. void OnWindowClosed() override;
  44. // Create Scope for window
  45. void CreateScopeForWindow(AZStd::shared_ptr<AZ::RPI::WindowContext>& windowContext, const AZ::RHI::ScopeId& swapchainScope, uint32_t shift = 0);
  46. AZ::RHI::ClearValue SelectClearColor(uint32_t time, uint32_t shift = 0);
  47. void CreateClearColors();
  48. uint32_t m_timeInSeconds = 0;
  49. AZStd::unique_ptr<AzFramework::NativeWindow> m_nativeWindow2;
  50. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext2;
  51. static const uint32_t m_numberOfClearColors = 5;
  52. AZStd::vector<AZ::RHI::ClearValue> m_clearValues;
  53. };
  54. } // namespace AzRHISample