StencilExampleComponent.h 2.1 KB

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