debugdraw.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #ifndef DEBUGDRAW_H_HEADER_GUARD
  6. #define DEBUGDRAW_H_HEADER_GUARD
  7. #include <bx/allocator.h>
  8. #include "../bounds.h"
  9. struct Axis
  10. {
  11. enum Enum
  12. {
  13. X,
  14. Y,
  15. Z,
  16. Count
  17. };
  18. };
  19. struct DdVertex
  20. {
  21. float x, y, z;
  22. };
  23. struct SpriteHandle { uint16_t idx; };
  24. inline bool isValid(SpriteHandle _handle) { return _handle.idx != UINT16_MAX; }
  25. struct GeometryHandle { uint16_t idx; };
  26. inline bool isValid(GeometryHandle _handle) { return _handle.idx != UINT16_MAX; }
  27. ///
  28. void ddInit(bool _depthTestLess = true, bx::AllocatorI* _allocator = NULL);
  29. ///
  30. void ddShutdown();
  31. ///
  32. SpriteHandle ddCreateSprite(uint16_t _width, uint16_t _height, const void* _data);
  33. ///
  34. void ddDestroy(SpriteHandle _handle);
  35. ///
  36. GeometryHandle ddCreateGeometry(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
  37. ///
  38. void ddDestroy(GeometryHandle _handle);
  39. struct DebugDrawEncoder
  40. {
  41. ///
  42. DebugDrawEncoder();
  43. ///
  44. ~DebugDrawEncoder();
  45. ///
  46. void begin(uint16_t _viewId, bgfx::Encoder* _encoder = NULL);
  47. ///
  48. void end();
  49. ///
  50. void push();
  51. ///
  52. void pop();
  53. ///
  54. void setState(bool _depthTest, bool _depthWrite, bool _clockwise);
  55. ///
  56. void setColor(uint32_t _abgr);
  57. ///
  58. void setLod(uint8_t _lod);
  59. ///
  60. void setWireframe(bool _wireframe);
  61. ///
  62. void setStipple(bool _stipple, float _scale = 1.0f, float _offset = 0.0f);
  63. ///
  64. void setSpin(float _spin);
  65. ///
  66. void setTransform(const void* _mtx);
  67. ///
  68. void setTranslate(float _x, float _y, float _z);
  69. ///
  70. void moveTo(float _x, float _y, float _z = 0.0f);
  71. ///
  72. void moveTo(const void* _pos);
  73. ///
  74. void lineTo(float _x, float _y, float _z = 0.0f);
  75. ///
  76. void lineTo(const void* _pos);
  77. ///
  78. void close();
  79. ///
  80. void draw(const Aabb& _aabb);
  81. ///
  82. void draw(const Cylinder& _cylinder);
  83. ///
  84. void draw(const Capsule& _capsule);
  85. ///
  86. void draw(const Disk& _disk);
  87. ///
  88. void draw(const Obb& _obb);
  89. ///
  90. void draw(const Sphere& _sphere);
  91. ///
  92. void draw(const Cone& _cone);
  93. ///
  94. void draw(GeometryHandle _handle);
  95. ///
  96. void drawLineList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
  97. ///
  98. void drawTriList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
  99. ///
  100. void drawFrustum(const void* _viewProj);
  101. ///
  102. void drawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees);
  103. ///
  104. void drawCircle(const void* _normal, const void* _center, float _radius, float _weight = 0.0f);
  105. ///
  106. void drawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight = 0.0f);
  107. ///
  108. void drawQuad(const float* _normal, const float* _center, float _size);
  109. ///
  110. void drawQuad(SpriteHandle _handle, const float* _normal, const float* _center, float _size);
  111. ///
  112. void drawQuad(bgfx::TextureHandle _handle, const float* _normal, const float* _center, float _size);
  113. ///
  114. void drawCone(const void* _from, const void* _to, float _radius);
  115. ///
  116. void drawCylinder(const void* _from, const void* _to, float _radius);
  117. ///
  118. void drawCapsule(const void* _from, const void* _to, float _radius);
  119. ///
  120. void drawAxis(float _x, float _y, float _z, float _len = 1.0f, Axis::Enum _highlight = Axis::Count, float _thickness = 0.0f);
  121. ///
  122. void drawGrid(const void* _normal, const void* _center, uint32_t _size = 20, float _step = 1.0f);
  123. ///
  124. void drawGrid(Axis::Enum _axis, const void* _center, uint32_t _size = 20, float _step = 1.0f);
  125. ///
  126. void drawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _highlight = Axis::Count);
  127. BX_ALIGN_DECL_CACHE_LINE(uint8_t) m_internal[50<<10];
  128. };
  129. ///
  130. void ddBegin(uint16_t _viewId, bgfx::Encoder* _encoder = NULL);
  131. ///
  132. void ddEnd();
  133. ///
  134. void ddPush();
  135. ///
  136. void ddPop();
  137. ///
  138. void ddSetState(bool _depthTest, bool _depthWrite, bool _clockwise);
  139. ///
  140. void ddSetColor(uint32_t _abgr);
  141. ///
  142. void ddSetLod(uint8_t _lod);
  143. ///
  144. void ddSetWireframe(bool _wireframe);
  145. ///
  146. void ddSetStipple(bool _stipple, float _scale = 1.0f, float _offset = 0.0f);
  147. ///
  148. void ddSetSpin(float _spin);
  149. ///
  150. void ddSetTransform(const void* _mtx);
  151. ///
  152. void ddSetTranslate(float _x, float _y, float _z);
  153. ///
  154. void ddMoveTo(float _x, float _y, float _z = 0.0f);
  155. ///
  156. void ddMoveTo(const void* _pos);
  157. ///
  158. void ddLineTo(float _x, float _y, float _z = 0.0f);
  159. ///
  160. void ddLineTo(const void* _pos);
  161. ///
  162. void ddClose();
  163. ///
  164. void ddDraw(const Aabb& _aabb);
  165. ///
  166. void ddDraw(const Cylinder& _cylinder);
  167. ///
  168. void ddDraw(const Capsule& _capsule);
  169. ///
  170. void ddDraw(const Disk& _disk);
  171. ///
  172. void ddDraw(const Obb& _obb);
  173. ///
  174. void ddDraw(const Sphere& _sphere);
  175. ///
  176. void ddDraw(const Cone& _cone);
  177. ///
  178. void ddDraw(GeometryHandle _handle);
  179. ///
  180. void ddDrawLineList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
  181. ///
  182. void ddDrawTriList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
  183. ///
  184. void ddDrawFrustum(const void* _viewProj);
  185. ///
  186. void ddDrawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees);
  187. ///
  188. void ddDrawCircle(const void* _normal, const void* _center, float _radius, float _weight = 0.0f);
  189. ///
  190. void ddDrawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight = 0.0f);
  191. ///
  192. void ddDrawQuad(const float* _normal, const float* _center, float _size);
  193. ///
  194. void ddDrawQuad(SpriteHandle _handle, const float* _normal, const float* _center, float _size);
  195. ///
  196. void ddDrawQuad(bgfx::TextureHandle _handle, const float* _normal, const float* _center, float _size);
  197. ///
  198. void ddDrawCone(const void* _from, const void* _to, float _radius);
  199. ///
  200. void ddDrawCylinder(const void* _from, const void* _to, float _radius);
  201. ///
  202. void ddDrawCapsule(const void* _from, const void* _to, float _radius);
  203. ///
  204. void ddDrawAxis(float _x, float _y, float _z, float _len = 1.0f, Axis::Enum _highlight = Axis::Count, float _thickness = 0.0f);
  205. ///
  206. void ddDrawGrid(const void* _normal, const void* _center, uint32_t _size = 20, float _step = 1.0f);
  207. ///
  208. void ddDrawGrid(Axis::Enum _axis, const void* _center, uint32_t _size = 20, float _step = 1.0f);
  209. ///
  210. void ddDrawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _highlight = Axis::Count);
  211. #endif // DEBUGDRAW_H_HEADER_GUARD