DynamicDrawExampleComponent.h 2.3 KB

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