BsDrawHelper2D.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsDrawHelperTemplate.h"
  4. #include "CmModule.h"
  5. #include "CmColor.h"
  6. #include "CmAABox.h"
  7. namespace BansheeEngine
  8. {
  9. class BS_EXPORT DrawHelper2D : public DrawHelperTemplate<Vector2>, public Module<DrawHelper2D>
  10. {
  11. public:
  12. DrawHelper2D();
  13. /**
  14. * @brief Fills the mesh data with vertices representing a quad (2 triangles).
  15. *
  16. * @param area Area in which to draw the quad.
  17. * @param meshData Mesh data that will be populated.
  18. * @param vertexOffset Offset in number of vertices from the start of the buffer to start writing at.
  19. * @param indexOffset Offset in number of indices from the start of the buffer to start writing at.
  20. *
  21. * @note Provided MeshData must have some specific elements at least:
  22. * Vector2 VES_POSITION
  23. * 32bit index buffer
  24. * Enough space for 4 vertices and 6 indices
  25. */
  26. void quad(const RectF& area, const MeshDataPtr& meshData, UINT32 vertexOffset, UINT32 indexOffset);
  27. /**
  28. * @brief Fills the mesh data with vertices representing a per-pixel line.
  29. *
  30. * @param a Start point of the line.
  31. * @param b End point of the line.
  32. * @param color Color of the line.
  33. * @param meshData Mesh data that will be populated.
  34. * @param vertexOffset Offset in number of vertices from the start of the buffer to start writing at.
  35. * @param indexOffset Offset in number of indices from the start of the buffer to start writing at.
  36. *
  37. * @note Provided MeshData must have some specific elements at least:
  38. * Vector2 VES_POSITION
  39. * UINT32 VES_COLOR
  40. * 32bit index buffer
  41. * Enough space for 2 vertices and 2 indices
  42. */
  43. void line_Pixel(const Vector2& a, const Vector2& b, const Color& color, const MeshDataPtr& meshData, UINT32 vertexOffset, UINT32 indexOffset);
  44. /**
  45. * @brief Fills the mesh data with vertices representing an anti-aliased line of specific width. Antialiasing is done using alpha blending.
  46. *
  47. * @param a Start point of the line.
  48. * @param b End point of the line.
  49. * @param width Width of the line.
  50. * @param borderWidth Width of the anti-aliased border.
  51. * @param color Color of the line.
  52. * @param meshData Mesh data that will be populated by this method.
  53. * @param vertexOffset Offset in number of vertices from the start of the buffer to start writing at.
  54. * @param indexOffset Offset in number of indices from the start of the buffer to start writing at.
  55. *
  56. * @note Provided MeshData must have some specific elements at least:
  57. * Vector2 VES_POSITION
  58. * UINT32 VES_COLOR
  59. * 32bit index buffer
  60. * Enough space for 8 vertices and 30 indices
  61. */
  62. void line_AA(const Vector2& a, const Vector2& b, float width, float borderWidth, const Color& color, const MeshDataPtr& meshData, UINT32 vertexOffset, UINT32 indexOffset);
  63. /**
  64. * @brief Fills the mesh data with vertices representing per-pixel lines.
  65. *
  66. * @param linePoints A list of start and end points for the lines. Must be a multiple of 2.
  67. * @param color Color of the line.
  68. * @param meshData Mesh data that will be populated.
  69. * @param vertexOffset Offset in number of vertices from the start of the buffer to start writing at.
  70. * @param indexOffset Offset in number of indices from the start of the buffer to start writing at.
  71. *
  72. * @note Provided MeshData must have some specific elements at least:
  73. * Vector2 VES_POSITION
  74. * UINT32 VES_COLOR
  75. * 32bit index buffer
  76. * Enough space for (numLines * 2) vertices and (numLines * 2) indices
  77. */
  78. void lineList_Pixel(const Vector<Vector2>::type& linePoints, const Color& color, const MeshDataPtr& meshData, UINT32 vertexOffset, UINT32 indexOffset);
  79. /**
  80. * @brief Fills the mesh data with vertices representing anti-aliased lines of specific width. Antialiasing is done using alpha blending.
  81. *
  82. * @param linePoints A list of start and end points for the lines. Must be a multiple of 2.
  83. * @param width Width of the line.
  84. * @param borderWidth Width of the anti-aliased border.
  85. * @param color Color of the line.
  86. * @param meshData Mesh data that will be populated by this method.
  87. * @param vertexOffset Offset in number of vertices from the start of the buffer to start writing at.
  88. * @param indexOffset Offset in number of indices from the start of the buffer to start writing at.
  89. *
  90. * @note Provided MeshData must have some specific elements at least:
  91. * Vector2 VES_POSITION
  92. * UINT32 VES_COLOR
  93. * 32bit index buffer
  94. * Enough space for (numLines * 8) vertices and (numLines * 30) indices
  95. */
  96. void lineList_AA(const Vector<Vector2>::type& linePoints, float width, float borderWidth, const Color& color, const MeshDataPtr& meshData, UINT32 vertexOffset, UINT32 indexOffset);
  97. void drawQuad(const HCamera& camera, const RectF& area, const Color& color = Color::White, DebugDrawCoordType coordType = DebugDrawCoordType::Pixel, float timeout = 0.0f);
  98. void drawLine_Pixel(const HCamera& camera, const Vector2& a, const Vector2& b, const Color& color = Color::White,
  99. DebugDrawCoordType coordType = DebugDrawCoordType::Pixel, float timeout = 0.0f);
  100. void drawLine_AA(const HCamera& camera, const Vector2& a, const Vector2& b, float width, float borderWidth,
  101. const Color& color = Color::White, DebugDrawCoordType coordType = DebugDrawCoordType::Pixel, float timeout = 0.0f);
  102. void drawLineList_Pixel(const HCamera& camera, const Vector<Vector2>::type& linePoints, const Color& color = Color::White,
  103. DebugDrawCoordType coordType = DebugDrawCoordType::Pixel, float timeout = 0.0f);
  104. void drawLineList_AA(const HCamera& camera, const Vector<Vector2>::type& linePoints, float width, float borderWidth,
  105. const Color& color = Color::White, DebugDrawCoordType coordType = DebugDrawCoordType::Pixel, float timeout = 0.0f);
  106. private:
  107. DebugDraw2DClipSpaceMatInfo mMaterial2DClipSpace;
  108. VertexDataDescPtr mVertexDesc;
  109. RectF normalizedCoordToClipSpace(const RectF& area) const;
  110. Vector2 normalizedCoordToClipSpace(const Vector2& pos) const;
  111. protected:
  112. void line_AA(const Vector2& a, const Vector2& b, float width, float borderWidth, const Color& color, UINT8* outVertices, UINT8* outColors,
  113. UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset);
  114. void polygon_AA(const Vector<Vector2>::type& points, float borderWidth, const Color& color, UINT8* outVertices, UINT8* outColors,
  115. UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset);
  116. };
  117. }