debugdraw.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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(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 void* _indices = NULL, bool _index32 = false);
  37. ///
  38. void ddDestroy(GeometryHandle _handle);
  39. struct DebugDrawEncoder
  40. {
  41. ///
  42. DebugDrawEncoder();
  43. ///
  44. ~DebugDrawEncoder();
  45. ///
  46. void begin(uint16_t _viewId, bool _depthTestLess = true, bgfx::Encoder* _encoder = NULL);
  47. ///
  48. void end();
  49. ///
  50. void push();
  51. ///
  52. void pop();
  53. ///
  54. void setDepthTestLess(bool _depthTestLess);
  55. ///
  56. void setState(bool _depthTest, bool _depthWrite, bool _clockwise);
  57. ///
  58. void setColor(uint32_t _abgr);
  59. ///
  60. void setLod(uint8_t _lod);
  61. ///
  62. void setWireframe(bool _wireframe);
  63. ///
  64. void setStipple(bool _stipple, float _scale = 1.0f, float _offset = 0.0f);
  65. ///
  66. void setSpin(float _spin);
  67. ///
  68. void setTransform(const void* _mtx);
  69. ///
  70. void setTranslate(float _x, float _y, float _z);
  71. ///
  72. void pushTransform(const void* _mtx);
  73. ///
  74. void popTransform();
  75. ///
  76. void moveTo(float _x, float _y, float _z = 0.0f);
  77. ///
  78. void moveTo(const void* _pos);
  79. ///
  80. void lineTo(float _x, float _y, float _z = 0.0f);
  81. ///
  82. void lineTo(const void* _pos);
  83. ///
  84. void close();
  85. ///
  86. void draw(const Aabb& _aabb);
  87. ///
  88. void draw(const Cylinder& _cylinder);
  89. ///
  90. void draw(const Capsule& _capsule);
  91. ///
  92. void draw(const Disk& _disk);
  93. ///
  94. void draw(const Obb& _obb);
  95. ///
  96. void draw(const Sphere& _sphere);
  97. ///
  98. void draw(const Cone& _cone);
  99. ///
  100. void draw(GeometryHandle _handle);
  101. ///
  102. void drawLineList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
  103. ///
  104. void drawTriList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
  105. ///
  106. void drawFrustum(const void* _viewProj);
  107. ///
  108. void drawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees);
  109. ///
  110. void drawCircle(const void* _normal, const void* _center, float _radius, float _weight = 0.0f);
  111. ///
  112. void drawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight = 0.0f);
  113. ///
  114. void drawQuad(const float* _normal, const float* _center, float _size);
  115. ///
  116. void drawQuad(SpriteHandle _handle, const float* _normal, const float* _center, float _size);
  117. ///
  118. void drawQuad(bgfx::TextureHandle _handle, const float* _normal, const float* _center, float _size);
  119. ///
  120. void drawCone(const void* _from, const void* _to, float _radius);
  121. ///
  122. void drawCylinder(const void* _from, const void* _to, float _radius);
  123. ///
  124. void drawCapsule(const void* _from, const void* _to, float _radius);
  125. ///
  126. void drawAxis(float _x, float _y, float _z, float _len = 1.0f, Axis::Enum _highlight = Axis::Count, float _thickness = 0.0f);
  127. ///
  128. void drawGrid(const void* _normal, const void* _center, uint32_t _size = 20, float _step = 1.0f);
  129. ///
  130. void drawGrid(Axis::Enum _axis, const void* _center, uint32_t _size = 20, float _step = 1.0f);
  131. ///
  132. void drawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _highlight = Axis::Count);
  133. BX_ALIGN_DECL_CACHE_LINE(uint8_t) m_internal[50<<10];
  134. };
  135. #endif // DEBUGDRAW_H_HEADER_GUARD