MSAA_RPI_ExampleComponent.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <CommonSampleComponentBase.h>
  10. #include <AzCore/Component/EntityBus.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <Atom/Feature/ImGui/ImGuiUtils.h>
  13. #include <AzFramework/Input/Events/InputChannelEventListener.h>
  14. #include <Atom/Bootstrap/DefaultWindowBus.h>
  15. #include <Utils/ImGuiSidebar.h>
  16. #include <Utils/Utils.h>
  17. #include <ExampleComponentBus.h>
  18. namespace AtomSampleViewer
  19. {
  20. //!
  21. //! This component creates a simple scene that tests the MSAA pipeline. It can test both MSAA enabled and disabled with the same scene
  22. //!
  23. class MSAA_RPI_ExampleComponent final
  24. : public CommonSampleComponentBase
  25. , public AZ::Render::Bootstrap::DefaultWindowNotificationBus::Handler
  26. , public AZ::TickBus::Handler
  27. , public ExampleComponentRequestBus::Handler
  28. {
  29. public:
  30. AZ_COMPONENT(MSAA_RPI_ExampleComponent, "{2BDCA64E-7E5F-49EE-ACF5-65C79C40840D}", CommonSampleComponentBase);
  31. static void Reflect(AZ::ReflectContext* context);
  32. void Activate() override;
  33. void Deactivate() override;
  34. private:
  35. // DefaultWindowNotificationBus::Handler
  36. void DefaultWindowCreated() override;
  37. // AZ::TickBus::Handler
  38. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  39. // ExampleComponentRequestBus::Handler
  40. void ResetCamera() override;
  41. // helper functions
  42. void ChangeRenderPipeline();
  43. void ActivateIbl();
  44. void ActivateModel();
  45. void OnModelReady(AZ::Data::Instance<AZ::RPI::Model> model);
  46. AZ::Data::Asset<AZ::RPI::MaterialAsset> GetMaterialAsset();
  47. AZ::Data::Asset<AZ::RPI::ModelAsset> GetModelAsset();
  48. void DrawSidebar();
  49. bool DrawSidebarModeChooser(bool refresh);
  50. bool DrawSideBarModelChooser(bool refresh);
  51. // sample mesh
  52. int m_modelType = 0;
  53. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  54. AZ::Render::MeshFeatureProcessorInterface::ModelChangedEvent::Handler m_meshChangedHandler
  55. {
  56. [&](AZ::Data::Instance<AZ::RPI::Model> model)
  57. {
  58. OnModelReady(model);
  59. }
  60. };
  61. // original render pipeline when the sample was started
  62. AZ::RPI::RenderPipelinePtr m_originalPipeline;
  63. // sample render pipeline, can be MSAA 2x/4x/8x or non-MSAA
  64. AZ::RPI::RenderPipelinePtr m_samplePipeline;
  65. // number of MSAA samples in the pipeline, controlled by the user
  66. int m_numSamples = 1;
  67. // flag indicating if the current pipeline is a non-MSAA pipeline
  68. bool m_isNonMsaaPipeline = false;
  69. // other state
  70. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext;
  71. Utils::DefaultIBL m_defaultIbl;
  72. ImGuiSidebar m_imguiSidebar;
  73. AZ::Render::ImGuiActiveContextScope m_imguiScope;
  74. };
  75. } // namespace AtomSampleViewer