DynamicDrawExampleComponent.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/TickBus.h>
  11. #include <Atom/RPI.Public/Buffer/Buffer.h>
  12. #include <Atom/RPI.Public/DynamicDraw/DynamicDrawContext.h>
  13. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  14. #include <Atom/RHI/StreamBufferView.h>
  15. #include <Atom/RHI/IndexBufferView.h>
  16. #include <Atom/RHI/PipelineState.h>
  17. #include <Atom/RHI/DrawList.h>
  18. #include <Utils/ImGuiSidebar.h>
  19. namespace AtomSampleViewer
  20. {
  21. //! Provides a basic example for how to use DynamicDrawInterface and DynamicDrawContext
  22. class DynamicDrawExampleComponent final
  23. : public CommonSampleComponentBase
  24. , public AZ::TickBus::Handler
  25. {
  26. public:
  27. AZ_COMPONENT(DynamicDrawExampleComponent, "{0BA35CA5-31A4-422B-A269-E138EDD0BB5F}", CommonSampleComponentBase);
  28. static void Reflect(AZ::ReflectContext* context);
  29. DynamicDrawExampleComponent();
  30. ~DynamicDrawExampleComponent() override = default;
  31. // AZ::Component overrides ...
  32. void Activate() override;
  33. void Deactivate() override;
  34. // AZ::TickBus::Handler overrides ...
  35. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  36. private:
  37. struct ExampleVertex
  38. {
  39. ExampleVertex(float position[3], float color[4])
  40. {
  41. memcpy(m_position, position, sizeof(float)*3);
  42. memcpy(m_color, color, sizeof(float)*4);
  43. }
  44. float m_position[3];
  45. float m_color[4];
  46. };
  47. AZ::RHI::Ptr<AZ::RPI::DynamicDrawContext> m_dynamicDraw;
  48. AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_contextSrg;
  49. // Two dynamic draw for same pass to test sorting
  50. AZ::RHI::Ptr<AZ::RPI::DynamicDrawContext> m_dynamicDraw1ForPass;
  51. AZ::RHI::Ptr<AZ::RPI::DynamicDrawContext> m_dynamicDraw2ForPass;
  52. ImGuiSidebar m_imguiSidebar;
  53. bool m_showCullModeNull = true;
  54. bool m_showCullModeFront = true;
  55. bool m_showCullModeBack = true;
  56. bool m_showAlphaBlend = true;
  57. bool m_showAlphaAdditive = true;
  58. bool m_showLineList = true;
  59. bool m_showPerDrawViewport = true;
  60. bool m_showSorting = true;
  61. // CommonSampleComponentBase overrides...
  62. void OnAllAssetsReadyActivate() override;
  63. };
  64. } // namespace AtomSampleViewer