debugdraw.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Copyright 2011-2025 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. */
  5. #ifndef DEBUGDRAW_H_HEADER_GUARD
  6. #define DEBUGDRAW_H_HEADER_GUARD
  7. #include <bx/allocator.h>
  8. #include <bx/bounds.h>
  9. #include <bgfx/bgfx.h>
  10. struct Axis
  11. {
  12. enum Enum
  13. {
  14. X,
  15. Y,
  16. Z,
  17. Count
  18. };
  19. };
  20. struct DdVertex
  21. {
  22. float x, y, z;
  23. };
  24. struct SpriteHandle { uint16_t idx; };
  25. inline bool isValid(SpriteHandle _handle) { return _handle.idx != UINT16_MAX; }
  26. struct GeometryHandle { uint16_t idx; };
  27. inline bool isValid(GeometryHandle _handle) { return _handle.idx != UINT16_MAX; }
  28. ///
  29. void ddInit(bx::AllocatorI* _allocator = NULL);
  30. ///
  31. void ddShutdown();
  32. ///
  33. SpriteHandle ddCreateSprite(uint16_t _width, uint16_t _height, const void* _data);
  34. ///
  35. void ddDestroy(SpriteHandle _handle);
  36. ///
  37. GeometryHandle ddCreateGeometry(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const void* _indices = NULL, bool _index32 = false);
  38. ///
  39. void ddDestroy(GeometryHandle _handle);
  40. ///
  41. struct DebugDrawEncoder
  42. {
  43. ///
  44. DebugDrawEncoder();
  45. ///
  46. ~DebugDrawEncoder();
  47. ///
  48. void begin(uint16_t _viewId, bool _depthTestLess = true, bgfx::Encoder* _encoder = NULL);
  49. ///
  50. void end();
  51. ///
  52. void push();
  53. ///
  54. void pop();
  55. ///
  56. void setDepthTestLess(bool _depthTestLess);
  57. ///
  58. void setState(bool _depthTest, bool _depthWrite, bool _clockwise);
  59. ///
  60. void setColor(uint32_t _abgr);
  61. ///
  62. void setLod(uint8_t _lod);
  63. ///
  64. void setWireframe(bool _wireframe);
  65. ///
  66. void setStipple(bool _stipple, float _scale = 1.0f, float _offset = 0.0f);
  67. ///
  68. void setSpin(float _spin);
  69. ///
  70. void setTransform(const void* _mtx);
  71. ///
  72. void setTranslate(float _x, float _y, float _z);
  73. ///
  74. void pushTransform(const void* _mtx);
  75. ///
  76. void popTransform();
  77. ///
  78. void moveTo(float _x, float _y, float _z = 0.0f);
  79. ///
  80. void moveTo(const bx::Vec3& _pos);
  81. ///
  82. void lineTo(float _x, float _y, float _z = 0.0f);
  83. ///
  84. void lineTo(const bx::Vec3& _pos);
  85. ///
  86. void close();
  87. ///
  88. void draw(const bx::Aabb& _aabb);
  89. ///
  90. void draw(const bx::Cylinder& _cylinder);
  91. ///
  92. void draw(const bx::Capsule& _capsule);
  93. ///
  94. void draw(const bx::Disk& _disk);
  95. ///
  96. void draw(const bx::Obb& _obb);
  97. ///
  98. void draw(const bx::Sphere& _sphere);
  99. ///
  100. void draw(const bx::Triangle& _triangle);
  101. ///
  102. void draw(const bx::Cone& _cone);
  103. ///
  104. void draw(GeometryHandle _handle);
  105. ///
  106. void drawLineList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
  107. ///
  108. void drawTriList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
  109. ///
  110. void drawFrustum(const void* _viewProj);
  111. ///
  112. void drawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees);
  113. ///
  114. void drawCircle(const bx::Vec3& _normal, const bx::Vec3& _center, float _radius, float _weight = 0.0f);
  115. ///
  116. void drawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight = 0.0f);
  117. ///
  118. void drawQuad(const bx::Vec3& _normal, const bx::Vec3& _center, float _size);
  119. ///
  120. void drawQuad(SpriteHandle _handle, const bx::Vec3& _normal, const bx::Vec3& _center, float _size);
  121. ///
  122. void drawQuad(bgfx::TextureHandle _handle, const bx::Vec3& _normal, const bx::Vec3& _center, float _size);
  123. ///
  124. void drawCone(const bx::Vec3& _from, const bx::Vec3& _to, float _radius);
  125. ///
  126. void drawCylinder(const bx::Vec3& _from, const bx::Vec3& _to, float _radius);
  127. ///
  128. void drawCapsule(const bx::Vec3& _from, const bx::Vec3& _to, float _radius);
  129. ///
  130. void drawAxis(float _x, float _y, float _z, float _len = 1.0f, Axis::Enum _highlight = Axis::Count, float _thickness = 0.0f);
  131. ///
  132. void drawGrid(const bx::Vec3& _normal, const bx::Vec3& _center, uint32_t _size = 20, float _step = 1.0f);
  133. ///
  134. void drawGrid(Axis::Enum _axis, const bx::Vec3& _center, uint32_t _size = 20, float _step = 1.0f);
  135. ///
  136. void drawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _highlight = Axis::Count);
  137. BX_ALIGN_DECL_CACHE_LINE(uint8_t) m_internal[50<<10];
  138. };
  139. ///
  140. class DebugDrawEncoderScopePush
  141. {
  142. public:
  143. ///
  144. DebugDrawEncoderScopePush(DebugDrawEncoder& _dde);
  145. ///
  146. ~DebugDrawEncoderScopePush();
  147. private:
  148. DebugDrawEncoder& m_dde;
  149. };
  150. #endif // DEBUGDRAW_H_HEADER_GUARD