StencilExampleComponent.h 2.2 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 <RHI/BasicRHIComponent.h>
  10. #include <AzCore/Math/Vector3.h>
  11. #include <Atom/RHI/BufferPool.h>
  12. #include <Atom/RHI/Device.h>
  13. #include <Atom/RHI/DrawItem.h>
  14. #include <Atom/RHI/ImagePool.h>
  15. #include <Atom/RHI/PipelineState.h>
  16. namespace AtomSampleViewer
  17. {
  18. /*
  19. * Testing different Stencil Comparison Function
  20. * First render all color triangles with stencil set to 1
  21. * Then render white triangles with different functions
  22. * From top left to bottom right :
  23. * Never, Less, Equal, LessEqual, Greater, NotEqual, GreaterEqual, Always
  24. */
  25. class StencilExampleComponent final
  26. : public BasicRHIComponent
  27. {
  28. public:
  29. AZ_COMPONENT(StencilExampleComponent, "{30979B47-9B6C-49D5-BA4D-A88452247D9F}", AZ::Component);
  30. AZ_DISABLE_COPY(StencilExampleComponent);
  31. static void Reflect(AZ::ReflectContext* context);
  32. StencilExampleComponent();
  33. ~StencilExampleComponent() override = default;
  34. protected:
  35. // AZ::Component
  36. void Activate() override;
  37. void Deactivate() override;
  38. // Triangles setting
  39. void SetTriangleVertices(int startIndex, VertexPosition* vertexData, AZ::Vector3 center, float offset);
  40. AZ::RHI::Ptr<AZ::RHI::BufferPool> m_inputAssemblyBufferPool;
  41. AZ::RHI::Ptr<AZ::RHI::Buffer> m_inputAssemblyBuffer;
  42. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_pipelineStateBasePass;
  43. AZStd::array<AZ::RHI::ConstPtr<AZ::RHI::PipelineState>, 8> m_pipelineStateStencil;
  44. static const size_t s_numberOfVertices = 48;
  45. struct BufferData
  46. {
  47. AZStd::array<VertexPosition, s_numberOfVertices> m_positions;
  48. AZStd::array<VertexColor, s_numberOfVertices> m_colors;
  49. AZStd::array<uint16_t, s_numberOfVertices> m_indices;
  50. };
  51. AZStd::array<AZ::RHI::StreamBufferView, 2> m_streamBufferViews;
  52. AZ::RHI::DrawItem m_drawItem;
  53. AZ::RHI::AttachmentId m_depthStencilID;
  54. AZ::RHI::ClearValue m_depthClearValue;
  55. };
  56. }