MultiViewportSwapchainComponent.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. AZ_COMPONENT(MultiViewportSwapchainComponent, "{45118741-F7DB-4EE0-9EBF-59B85D7F6194}", AZ::Component);
  28. AZ_DISABLE_COPY(MultiViewportSwapchainComponent);
  29. static void Reflect(AZ::ReflectContext* context);
  30. MultiViewportSwapchainComponent();
  31. ~MultiViewportSwapchainComponent() override = default;
  32. /// AZ::Component
  33. void Activate() override;
  34. void Deactivate() override;
  35. private:
  36. // RHISystemNotificationBus::Handler
  37. void OnFramePrepare(AZ::RHI::FrameGraphBuilder& frameGraphBuilder) override;
  38. /// TickBus::Handler
  39. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  40. // AzFramework::WindowNotificationBus::Handler
  41. void OnWindowClosed() override;
  42. // Create Scope for window
  43. void CreateScopeForWindow(AZStd::shared_ptr<AZ::RPI::WindowContext>& windowContext, const AZ::RHI::ScopeId& swapchainScope, uint32_t shift = 0);
  44. AZ::RHI::ClearValue SelectClearColor(uint32_t time, uint32_t shift = 0);
  45. void CreateClearColors();
  46. uint32_t m_timeInSeconds = 0;
  47. AZStd::unique_ptr<AzFramework::NativeWindow> m_nativeWindow2;
  48. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext2;
  49. static const uint32_t m_numberOfClearColors = 5;
  50. AZStd::vector<AZ::RHI::ClearValue> m_clearValues;
  51. };
  52. } // namespace AzRHISample