AuxGeomDrawQueue.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 <Atom/RPI.Public/AuxGeom/AuxGeomDraw.h>
  10. #include <AzCore/std/containers/vector.h>
  11. #include <AzCore/Memory/SystemAllocator.h>
  12. #include <AzCore/Math/Transform.h>
  13. #include <Atom/RPI.Public/Base.h>
  14. #include "AuxGeomBase.h"
  15. namespace AZ
  16. {
  17. namespace RPI
  18. {
  19. class Scene;
  20. class View;
  21. }
  22. namespace Render
  23. {
  24. /**
  25. * Class that stores up AuxGeom draw requests for one RPI scene.
  26. * This acts somewhat like a render proxy in that it stores data that is consumed by the feature processor.
  27. */
  28. class AuxGeomDrawQueue final
  29. : public RPI::AuxGeomDraw
  30. {
  31. public: // functions
  32. AZ_CLASS_ALLOCATOR(AuxGeomDrawQueue, AZ::SystemAllocator);
  33. AuxGeomDrawQueue() = default;
  34. ~AuxGeomDrawQueue() override = default;
  35. // RPI::AuxGeomDraw
  36. int32_t AddViewProjOverride(const AZ::Matrix4x4& viewProj) override;
  37. int32_t GetOrAdd2DViewProjOverride() override;
  38. void SetPointSize(float pointSize) override;
  39. float GetPointSize() override;
  40. // dynamic polygon draws
  41. void DrawPoints(const AuxGeomDynamicDrawArguments& args) override;
  42. void DrawLines(const AuxGeomDynamicDrawArguments& args) override;
  43. void DrawLines(const AuxGeomDynamicIndexedDrawArguments& args) override;
  44. void DrawPolylines(const AuxGeomDynamicDrawArguments& args, PolylineEnd end = PolylineEnd::Open) override;
  45. void DrawTriangles(const AuxGeomDynamicDrawArguments& args, FaceCullMode faceCull = FaceCullMode::None) override;
  46. void DrawTriangles(const AuxGeomDynamicIndexedDrawArguments& args, FaceCullMode faceCull = FaceCullMode::None) override;
  47. // Fixed shape draws
  48. void DrawQuad(float width, float height, const AZ::Matrix3x4& transform, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  49. void DrawSphere(const AZ::Vector3& center, float radius, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  50. void DrawSphere(const AZ::Vector3& center, const AZ::Vector3& direction, float radius, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  51. void DrawHemisphere(const AZ::Vector3& center, const AZ::Vector3& direction, float radius, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  52. void DrawDisk(const AZ::Vector3& center, const AZ::Vector3& direction, float radius, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  53. void DrawCone(const AZ::Vector3& center, const AZ::Vector3& direction, float radius, float height, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  54. void DrawCylinder(const AZ::Vector3& center, const AZ::Vector3& direction, float radius, float height, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  55. void DrawCylinderNoEnds(const AZ::Vector3& center, const AZ::Vector3& direction, float radius, float height, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  56. void DrawAabb(const AZ::Aabb& aabb, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  57. void DrawAabb(const AZ::Aabb& aabb, const AZ::Matrix3x4& transform, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  58. void DrawObb(const AZ::Obb& obb, const AZ::Vector3& position, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  59. void DrawObb(const AZ::Obb& obb, const AZ::Matrix3x4& transform, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  60. void DrawFrustum(const AZ::Frustum& frustum, const AZ::Color& color, bool drawNormals, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex) override;
  61. //! Switch clients of AuxGeom to using a different buffer and return the filled buffer for processing
  62. AuxGeomBufferData* Commit();
  63. private: // functions
  64. void DrawCylinderCommon(const AZ::Vector3& center, const AZ::Vector3& direction, float radius, float height, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex, bool drawEnds);
  65. void DrawSphereCommon(const AZ::Vector3& center, const AZ::Vector3& direction, float radius, const AZ::Color& color, DrawStyle style, DepthTest depthTest, DepthWrite depthWrite, FaceCullMode faceCull, int32_t viewProjOverrideIndex, bool isHemisphere);
  66. //! Clear the current buffers
  67. void ClearCurrentBufferData();
  68. bool ShouldBatchDraw(
  69. DynamicPrimitiveData& primBuffer,
  70. AuxGeomPrimitiveType primType,
  71. AuxGeomBlendMode blendMode,
  72. AuxGeomDepthReadType depthRead,
  73. AuxGeomDepthWriteType depthWrite,
  74. AuxGeomFaceCullMode faceCull,
  75. u8 width,
  76. int32_t viewProjOverrideIndex);
  77. void DrawPrimitiveCommon(
  78. AuxGeomPrimitiveType primitiveType,
  79. uint32_t verticesPerPrimitiveType,
  80. uint32_t vertexCount,
  81. const AZ::Vector3* points,
  82. AZStd::function<AZ::u32(uint32_t)> packedColorFunction,
  83. bool isOpaque,
  84. AuxGeomDepthReadType depthRead,
  85. AuxGeomDepthWriteType depthWrite,
  86. AuxGeomFaceCullMode faceCull,
  87. AZ::u8 width,
  88. int32_t viewProjOverrideIndex);
  89. void DrawPrimitiveWithSharedVerticesCommon(
  90. AuxGeomPrimitiveType primitiveType,
  91. uint32_t verticesPerPrimitiveType,
  92. uint32_t vertexCount,
  93. uint32_t indexCount,
  94. const AZ::Vector3* points,
  95. AZStd::function<AZ::u32(uint32_t)> packedColorFunction,
  96. AZStd::function<AuxGeomIndex(uint32_t)> indexFunction,
  97. bool isOpaque,
  98. AuxGeomDepthReadType depthRead,
  99. AuxGeomDepthWriteType depthWrite,
  100. AuxGeomFaceCullMode faceCull,
  101. AZ::u8 width,
  102. int32_t viewProjOverrideIndex);
  103. void AddShape(DrawStyle style, const ShapeBufferEntry& shape);
  104. void AddBox(DrawStyle style, BoxBufferEntry& box);
  105. private: // data
  106. // We just toggle back and forth between two buffers, one being filled while the other is being processed
  107. // by the FeatureProcessor.
  108. static const int NumBuffers = 2;
  109. AuxGeomBufferData m_buffers[NumBuffers];
  110. int m_currentBufferIndex = 0;
  111. float m_pointSize = 3.0f;
  112. AZStd::recursive_mutex m_buffersWriteLock;
  113. };
  114. } // namespace Render
  115. } // namespace AZ