debugdraw.cpp 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914
  1. /*
  2. * Copyright 2011-2016 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #include <bgfx/bgfx.h>
  6. #include <bgfx/embedded_shader.h>
  7. #include "debugdraw.h"
  8. #include <bx/fpumath.h>
  9. #include <bx/radixsort.h>
  10. #include <bx/uint32_t.h>
  11. #include <bx/crtimpl.h>
  12. struct DebugVertex
  13. {
  14. float m_x;
  15. float m_y;
  16. float m_z;
  17. float m_len;
  18. uint32_t m_abgr;
  19. static void init()
  20. {
  21. ms_decl
  22. .begin()
  23. .add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
  24. .add(bgfx::Attrib::TexCoord0, 1, bgfx::AttribType::Float)
  25. .add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
  26. .end();
  27. }
  28. static bgfx::VertexDecl ms_decl;
  29. };
  30. bgfx::VertexDecl DebugVertex::ms_decl;
  31. struct DebugShapeVertex
  32. {
  33. float m_x;
  34. float m_y;
  35. float m_z;
  36. uint8_t m_indices[4];
  37. static void init()
  38. {
  39. ms_decl
  40. .begin()
  41. .add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
  42. .add(bgfx::Attrib::Indices, 4, bgfx::AttribType::Uint8)
  43. .end();
  44. }
  45. static bgfx::VertexDecl ms_decl;
  46. };
  47. bgfx::VertexDecl DebugShapeVertex::ms_decl;
  48. static DebugShapeVertex s_cubeVertices[8] =
  49. {
  50. {-1.0f, 1.0f, 1.0f, { 0, 0, 0, 0 } },
  51. { 1.0f, 1.0f, 1.0f, { 0, 0, 0, 0 } },
  52. {-1.0f, -1.0f, 1.0f, { 0, 0, 0, 0 } },
  53. { 1.0f, -1.0f, 1.0f, { 0, 0, 0, 0 } },
  54. {-1.0f, 1.0f, -1.0f, { 0, 0, 0, 0 } },
  55. { 1.0f, 1.0f, -1.0f, { 0, 0, 0, 0 } },
  56. {-1.0f, -1.0f, -1.0f, { 0, 0, 0, 0 } },
  57. { 1.0f, -1.0f, -1.0f, { 0, 0, 0, 0 } },
  58. };
  59. static const uint16_t s_cubeIndices[36] =
  60. {
  61. 0, 1, 2, // 0
  62. 1, 3, 2,
  63. 4, 6, 5, // 2
  64. 5, 6, 7,
  65. 0, 2, 4, // 4
  66. 4, 2, 6,
  67. 1, 5, 3, // 6
  68. 5, 7, 3,
  69. 0, 4, 1, // 8
  70. 4, 5, 1,
  71. 2, 3, 6, // 10
  72. 6, 3, 7,
  73. };
  74. static const uint8_t s_circleLod[] =
  75. {
  76. 37,
  77. 29,
  78. 23,
  79. 17,
  80. 11,
  81. };
  82. static uint8_t getCircleLod(uint8_t _lod)
  83. {
  84. _lod = _lod > BX_COUNTOF(s_circleLod)-1 ? BX_COUNTOF(s_circleLod)-1 : _lod;
  85. return s_circleLod[_lod];
  86. }
  87. static void circle(float* _out, float _angle)
  88. {
  89. float sa = bx::fsin(_angle);
  90. float ca = bx::fcos(_angle);
  91. _out[0] = sa;
  92. _out[1] = ca;
  93. }
  94. static void squircle(float* _out, float _angle)
  95. {
  96. float sa = bx::fsin(_angle);
  97. float ca = bx::fcos(_angle);
  98. _out[0] = bx::fsqrt(bx::fabsolute(sa) ) * bx::fsign(sa);
  99. _out[1] = bx::fsqrt(bx::fabsolute(ca) ) * bx::fsign(ca);
  100. }
  101. uint32_t genSphere(uint8_t _subdiv0, void* _pos0 = NULL, uint16_t _posStride0 = 0, void* _normals0 = NULL, uint16_t _normalStride0 = 0)
  102. {
  103. if (NULL != _pos0)
  104. {
  105. struct Gen
  106. {
  107. Gen(void* _pos, uint16_t _posStride, void* _normals, uint16_t _normalStride, uint8_t _subdiv)
  108. : m_pos( (uint8_t*)_pos)
  109. , m_normals( (uint8_t*)_normals)
  110. , m_posStride(_posStride)
  111. , m_normalStride(_normalStride)
  112. {
  113. static const float scale = 1.0f;
  114. static const float golden = 1.6180339887f;
  115. static const float len = bx::fsqrt(golden*golden + 1.0f);
  116. static const float ss = 1.0f/len * scale;
  117. static const float ll = ss*golden;
  118. static const float vv[12][4] =
  119. {
  120. { -ll, 0.0f, -ss, 0.0f },
  121. { ll, 0.0f, -ss, 0.0f },
  122. { ll, 0.0f, ss, 0.0f },
  123. { -ll, 0.0f, ss, 0.0f },
  124. { -ss, ll, 0.0f, 0.0f },
  125. { ss, ll, 0.0f, 0.0f },
  126. { ss, -ll, 0.0f, 0.0f },
  127. { -ss, -ll, 0.0f, 0.0f },
  128. { 0.0f, -ss, ll, 0.0f },
  129. { 0.0f, ss, ll, 0.0f },
  130. { 0.0f, ss, -ll, 0.0f },
  131. { 0.0f, -ss, -ll, 0.0f },
  132. };
  133. m_numVertices = 0;
  134. triangle(vv[ 0], vv[ 4], vv[ 3], scale, _subdiv);
  135. triangle(vv[ 0], vv[10], vv[ 4], scale, _subdiv);
  136. triangle(vv[ 4], vv[10], vv[ 5], scale, _subdiv);
  137. triangle(vv[ 5], vv[10], vv[ 1], scale, _subdiv);
  138. triangle(vv[ 5], vv[ 1], vv[ 2], scale, _subdiv);
  139. triangle(vv[ 5], vv[ 2], vv[ 9], scale, _subdiv);
  140. triangle(vv[ 5], vv[ 9], vv[ 4], scale, _subdiv);
  141. triangle(vv[ 3], vv[ 4], vv[ 9], scale, _subdiv);
  142. triangle(vv[ 0], vv[ 3], vv[ 7], scale, _subdiv);
  143. triangle(vv[ 0], vv[ 7], vv[11], scale, _subdiv);
  144. triangle(vv[11], vv[ 7], vv[ 6], scale, _subdiv);
  145. triangle(vv[11], vv[ 6], vv[ 1], scale, _subdiv);
  146. triangle(vv[ 1], vv[ 6], vv[ 2], scale, _subdiv);
  147. triangle(vv[ 2], vv[ 6], vv[ 8], scale, _subdiv);
  148. triangle(vv[ 8], vv[ 6], vv[ 7], scale, _subdiv);
  149. triangle(vv[ 8], vv[ 7], vv[ 3], scale, _subdiv);
  150. triangle(vv[ 0], vv[11], vv[10], scale, _subdiv);
  151. triangle(vv[ 1], vv[10], vv[11], scale, _subdiv);
  152. triangle(vv[ 2], vv[ 8], vv[ 9], scale, _subdiv);
  153. triangle(vv[ 3], vv[ 9], vv[ 8], scale, _subdiv);
  154. }
  155. void addVert(const float* _v)
  156. {
  157. float* verts = (float*)m_pos;
  158. verts[0] = _v[0];
  159. verts[1] = _v[1];
  160. verts[2] = _v[2];
  161. m_pos += m_posStride;
  162. if (NULL != m_normals)
  163. {
  164. float* normals = (float*)m_normals;
  165. bx::vec3Norm(normals, _v);
  166. m_normals += m_normalStride;
  167. }
  168. m_numVertices++;
  169. }
  170. void triangle(const float* _v0, const float* _v1, const float* _v2, float _scale, uint8_t _subdiv)
  171. {
  172. if (0 == _subdiv)
  173. {
  174. addVert(_v0);
  175. addVert(_v1);
  176. addVert(_v2);
  177. }
  178. else
  179. {
  180. float tmp0[4];
  181. float tmp1[4];
  182. float v01[4];
  183. bx::vec3Add(tmp0, _v0, _v1);
  184. bx::vec3Norm(tmp1, tmp0);
  185. bx::vec3Mul(v01, tmp1, _scale);
  186. float v12[4];
  187. bx::vec3Add(tmp0, _v1, _v2);
  188. bx::vec3Norm(tmp1, tmp0);
  189. bx::vec3Mul(v12, tmp1, _scale);
  190. float v20[4];
  191. bx::vec3Add(tmp0, _v2, _v0);
  192. bx::vec3Norm(tmp1, tmp0);
  193. bx::vec3Mul(v20, tmp1, _scale);
  194. --_subdiv;
  195. triangle(_v0, v01, v20, _scale, _subdiv);
  196. triangle(_v1, v12, v01, _scale, _subdiv);
  197. triangle(_v2, v20, v12, _scale, _subdiv);
  198. triangle(v01, v12, v20, _scale, _subdiv);
  199. }
  200. }
  201. uint8_t* m_pos;
  202. uint8_t* m_normals;
  203. uint16_t m_posStride;
  204. uint16_t m_normalStride;
  205. uint32_t m_numVertices;
  206. } gen(_pos0, _posStride0, _normals0, _normalStride0, _subdiv0);
  207. }
  208. uint32_t numVertices = 20*3*bx::uint32_max(1, (uint32_t)bx::fpow(4.0f, _subdiv0) );
  209. return numVertices;
  210. }
  211. void getPoint(float* _result, Axis::Enum _axis, float _x, float _y)
  212. {
  213. switch (_axis)
  214. {
  215. case Axis::X:
  216. _result[0] = 0.0f;
  217. _result[1] = _x;
  218. _result[2] = _y;
  219. break;
  220. case Axis::Y:
  221. _result[0] = _y;
  222. _result[1] = 0.0f;
  223. _result[2] = _x;
  224. break;
  225. default:
  226. _result[0] = _x;
  227. _result[1] = _y;
  228. _result[2] = 0.0f;
  229. break;
  230. }
  231. }
  232. #include "vs_debugdraw_lines.bin.h"
  233. #include "fs_debugdraw_lines.bin.h"
  234. #include "vs_debugdraw_lines_stipple.bin.h"
  235. #include "fs_debugdraw_lines_stipple.bin.h"
  236. #include "vs_debugdraw_fill.bin.h"
  237. #include "fs_debugdraw_fill.bin.h"
  238. #include "vs_debugdraw_fill_lit.bin.h"
  239. #include "fs_debugdraw_fill_lit.bin.h"
  240. static const bgfx::EmbeddedShader s_embeddedShaders[] =
  241. {
  242. BGFX_EMBEDDED_SHADER(vs_debugdraw_lines),
  243. BGFX_EMBEDDED_SHADER(fs_debugdraw_lines),
  244. BGFX_EMBEDDED_SHADER(vs_debugdraw_lines_stipple),
  245. BGFX_EMBEDDED_SHADER(fs_debugdraw_lines_stipple),
  246. BGFX_EMBEDDED_SHADER(vs_debugdraw_fill),
  247. BGFX_EMBEDDED_SHADER(fs_debugdraw_fill),
  248. BGFX_EMBEDDED_SHADER(vs_debugdraw_fill_lit),
  249. BGFX_EMBEDDED_SHADER(fs_debugdraw_fill_lit),
  250. BGFX_EMBEDDED_SHADER_END()
  251. };
  252. struct DebugDraw
  253. {
  254. DebugDraw()
  255. : m_depthTestLess(true)
  256. , m_state(State::Count)
  257. {
  258. }
  259. void init(bool _depthTestLess, bx::AllocatorI* _allocator)
  260. {
  261. m_allocator = _allocator;
  262. m_depthTestLess = _depthTestLess;
  263. #if BX_CONFIG_ALLOCATOR_CRT
  264. if (NULL == _allocator)
  265. {
  266. static bx::CrtAllocator allocator;
  267. m_allocator = &allocator;
  268. }
  269. #endif // BX_CONFIG_ALLOCATOR_CRT
  270. DebugVertex::init();
  271. DebugShapeVertex::init();
  272. bgfx::RendererType::Enum type = bgfx::getRendererType();
  273. m_program[Program::Lines] =
  274. bgfx::createProgram(
  275. bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_lines")
  276. , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_lines")
  277. , true
  278. );
  279. m_program[Program::LinesStipple] =
  280. bgfx::createProgram(
  281. bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_lines_stipple")
  282. , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_lines_stipple")
  283. , true
  284. );
  285. m_program[Program::Fill] =
  286. bgfx::createProgram(
  287. bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_fill")
  288. , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_fill")
  289. , true
  290. );
  291. m_program[Program::FillLit] =
  292. bgfx::createProgram(
  293. bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_fill_lit")
  294. , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_fill_lit")
  295. , true
  296. );
  297. u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4, 4);
  298. void* vertices[Mesh::Count] = {};
  299. uint16_t* indices[Mesh::Count] = {};
  300. uint16_t stride = DebugShapeVertex::ms_decl.getStride();
  301. uint32_t startVertex = 0;
  302. uint32_t startIndex = 0;
  303. for (uint32_t mesh = 0; mesh < 4; ++mesh)
  304. {
  305. Mesh::Enum id = Mesh::Enum(Mesh::Sphere0+mesh);
  306. const uint8_t tess = uint8_t(3-mesh);
  307. const uint32_t numVertices = genSphere(tess);
  308. const uint32_t numIndices = numVertices;
  309. vertices[id] = BX_ALLOC(m_allocator, numVertices*stride);
  310. memset(vertices[id], 0, numVertices*stride);
  311. genSphere(tess, vertices[id], stride);
  312. uint16_t* trilist = (uint16_t*)BX_ALLOC(m_allocator, numIndices*sizeof(uint16_t) );
  313. for (uint32_t ii = 0; ii < numIndices; ++ii)
  314. {
  315. trilist[ii] = uint16_t(ii);
  316. }
  317. uint32_t numLineListIndices = bgfx::topologyConvert(bgfx::TopologyConvert::TriListToLineList
  318. , NULL
  319. , 0
  320. , trilist
  321. , numIndices
  322. , false
  323. );
  324. indices[id] = (uint16_t*)BX_ALLOC(m_allocator, (numIndices + numLineListIndices)*sizeof(uint16_t) );
  325. uint16_t* indicesOut = indices[id];
  326. memcpy(indicesOut, trilist, numIndices*sizeof(uint16_t) );
  327. bgfx::topologyConvert(bgfx::TopologyConvert::TriListToLineList
  328. , &indicesOut[numIndices]
  329. , numLineListIndices*sizeof(uint16_t)
  330. , trilist
  331. , numIndices
  332. , false
  333. );
  334. m_mesh[id].m_startVertex = startVertex;
  335. m_mesh[id].m_numVertices = numVertices;
  336. m_mesh[id].m_startIndex[0] = startIndex;
  337. m_mesh[id].m_numIndices[0] = numIndices;
  338. m_mesh[id].m_startIndex[1] = startIndex+numIndices;
  339. m_mesh[id].m_numIndices[1] = numLineListIndices;
  340. startVertex += numVertices;
  341. startIndex += numIndices + numLineListIndices;
  342. BX_FREE(m_allocator, trilist);
  343. }
  344. for (uint32_t mesh = 0; mesh < 4; ++mesh)
  345. {
  346. Mesh::Enum id = Mesh::Enum(Mesh::Cone0+mesh);
  347. const uint32_t num = getCircleLod(uint8_t(mesh) );
  348. const float step = bx::pi * 2.0f / num;
  349. const uint32_t numVertices = num+1;
  350. const uint32_t numIndices = num*6;
  351. const uint32_t numLineListIndices = num*4;
  352. vertices[id] = BX_ALLOC(m_allocator, numVertices*stride);
  353. indices[id] = (uint16_t*)BX_ALLOC(m_allocator, (numIndices + numLineListIndices)*sizeof(uint16_t) );
  354. memset(indices[id], 0, (numIndices + numLineListIndices)*sizeof(uint16_t) );
  355. DebugShapeVertex* vertex = (DebugShapeVertex*)vertices[id];
  356. uint16_t* index = indices[id];
  357. vertex[num].m_x = 0.0f;
  358. vertex[num].m_y = 0.0f;
  359. vertex[num].m_z = 0.0f;
  360. vertex[num].m_indices[0] = 1;
  361. for (uint32_t ii = 0; ii < num; ++ii)
  362. {
  363. const float angle = step * ii;
  364. float xy[2];
  365. circle(xy, angle);
  366. vertex[ii].m_x = xy[1];
  367. vertex[ii].m_y = 0.0f;
  368. vertex[ii].m_z = xy[0];
  369. vertex[ii].m_indices[0] = 0;
  370. index[ii*3+0] = uint16_t(num);
  371. index[ii*3+1] = uint16_t( (ii+1)%num);
  372. index[ii*3+2] = uint16_t(ii);
  373. index[num*3+ii*3+0] = 0;
  374. index[num*3+ii*3+1] = uint16_t(ii);
  375. index[num*3+ii*3+2] = uint16_t( (ii+1)%num);
  376. index[numIndices+ii*2+0] = uint16_t(ii);
  377. index[numIndices+ii*2+1] = uint16_t(num);
  378. index[numIndices+num*2+ii*2+0] = uint16_t(ii);
  379. index[numIndices+num*2+ii*2+1] = uint16_t( (ii+1)%num);
  380. }
  381. m_mesh[id].m_startVertex = startVertex;
  382. m_mesh[id].m_numVertices = numVertices;
  383. m_mesh[id].m_startIndex[0] = startIndex;
  384. m_mesh[id].m_numIndices[0] = numIndices;
  385. m_mesh[id].m_startIndex[1] = startIndex+numIndices;
  386. m_mesh[id].m_numIndices[1] = numLineListIndices;
  387. startVertex += numVertices;
  388. startIndex += numIndices + numLineListIndices;
  389. }
  390. for (uint32_t mesh = 0; mesh < 4; ++mesh)
  391. {
  392. Mesh::Enum id = Mesh::Enum(Mesh::Cylinder0+mesh);
  393. const uint32_t num = getCircleLod(uint8_t(mesh) );
  394. const float step = bx::pi * 2.0f / num;
  395. const uint32_t numVertices = num*2;
  396. const uint32_t numIndices = num*12;
  397. const uint32_t numLineListIndices = num*6;
  398. vertices[id] = BX_ALLOC(m_allocator, numVertices*stride);
  399. indices[id] = (uint16_t*)BX_ALLOC(m_allocator, (numIndices + numLineListIndices)*sizeof(uint16_t) );
  400. memset(indices[id], 0, (numIndices + numLineListIndices)*sizeof(uint16_t) );
  401. DebugShapeVertex* vertex = (DebugShapeVertex*)vertices[id];
  402. uint16_t* index = indices[id];
  403. for (uint32_t ii = 0; ii < num; ++ii)
  404. {
  405. const float angle = step * ii;
  406. float xy[2];
  407. circle(xy, angle);
  408. vertex[ii].m_x = xy[1];
  409. vertex[ii].m_y = 0.0f;
  410. vertex[ii].m_z = xy[0];
  411. vertex[ii].m_indices[0] = 0;
  412. vertex[ii+num].m_x = xy[1];
  413. vertex[ii+num].m_y = 0.0f;
  414. vertex[ii+num].m_z = xy[0];
  415. vertex[ii+num].m_indices[0] = 1;
  416. index[ii*6+0] = uint16_t(ii+num);
  417. index[ii*6+1] = uint16_t( (ii+1)%num);
  418. index[ii*6+2] = uint16_t(ii);
  419. index[ii*6+3] = uint16_t(ii+num);
  420. index[ii*6+4] = uint16_t( (ii+1)%num+num);
  421. index[ii*6+5] = uint16_t( (ii+1)%num);
  422. index[num*6+ii*6+0] = uint16_t(0);
  423. index[num*6+ii*6+1] = uint16_t(ii);
  424. index[num*6+ii*6+2] = uint16_t( (ii+1)%num);
  425. index[num*6+ii*6+3] = uint16_t(num);
  426. index[num*6+ii*6+4] = uint16_t( (ii+1)%num+num);
  427. index[num*6+ii*6+5] = uint16_t(ii+num);
  428. index[numIndices+ii*2+0] = uint16_t(ii);
  429. index[numIndices+ii*2+1] = uint16_t(ii+num);
  430. index[numIndices+num*2+ii*2+0] = uint16_t(ii);
  431. index[numIndices+num*2+ii*2+1] = uint16_t( (ii+1)%num);
  432. index[numIndices+num*4+ii*2+0] = uint16_t(num + ii);
  433. index[numIndices+num*4+ii*2+1] = uint16_t(num + (ii+1)%num);
  434. }
  435. m_mesh[id].m_startVertex = startVertex;
  436. m_mesh[id].m_numVertices = numVertices;
  437. m_mesh[id].m_startIndex[0] = startIndex;
  438. m_mesh[id].m_numIndices[0] = numIndices;
  439. m_mesh[id].m_startIndex[1] = startIndex+numIndices;
  440. m_mesh[id].m_numIndices[1] = numLineListIndices;
  441. startVertex += numVertices;
  442. startIndex += numIndices + numLineListIndices;
  443. }
  444. for (uint32_t mesh = 0; mesh < 4; ++mesh)
  445. {
  446. Mesh::Enum id = Mesh::Enum(Mesh::Capsule0+mesh);
  447. const uint32_t num = getCircleLod(uint8_t(mesh) );
  448. const float step = bx::pi * 2.0f / num;
  449. const uint32_t numVertices = num*2;
  450. const uint32_t numIndices = num*6;
  451. const uint32_t numLineListIndices = num*6;
  452. vertices[id] = BX_ALLOC(m_allocator, numVertices*stride);
  453. indices[id] = (uint16_t*)BX_ALLOC(m_allocator, (numIndices + numLineListIndices)*sizeof(uint16_t) );
  454. memset(indices[id], 0, (numIndices + numLineListIndices)*sizeof(uint16_t) );
  455. DebugShapeVertex* vertex = (DebugShapeVertex*)vertices[id];
  456. uint16_t* index = indices[id];
  457. for (uint32_t ii = 0; ii < num; ++ii)
  458. {
  459. const float angle = step * ii;
  460. float xy[2];
  461. circle(xy, angle);
  462. vertex[ii].m_x = xy[1];
  463. vertex[ii].m_y = 0.0f;
  464. vertex[ii].m_z = xy[0];
  465. vertex[ii].m_indices[0] = 0;
  466. vertex[ii+num].m_x = xy[1];
  467. vertex[ii+num].m_y = 0.0f;
  468. vertex[ii+num].m_z = xy[0];
  469. vertex[ii+num].m_indices[0] = 1;
  470. index[ii*6+0] = uint16_t(ii+num);
  471. index[ii*6+1] = uint16_t( (ii+1)%num);
  472. index[ii*6+2] = uint16_t(ii);
  473. index[ii*6+3] = uint16_t(ii+num);
  474. index[ii*6+4] = uint16_t( (ii+1)%num+num);
  475. index[ii*6+5] = uint16_t( (ii+1)%num);
  476. // index[num*6+ii*6+0] = uint16_t(0);
  477. // index[num*6+ii*6+1] = uint16_t(ii);
  478. // index[num*6+ii*6+2] = uint16_t( (ii+1)%num);
  479. // index[num*6+ii*6+3] = uint16_t(num);
  480. // index[num*6+ii*6+4] = uint16_t( (ii+1)%num+num);
  481. // index[num*6+ii*6+5] = uint16_t(ii+num);
  482. index[numIndices+ii*2+0] = uint16_t(ii);
  483. index[numIndices+ii*2+1] = uint16_t(ii+num);
  484. index[numIndices+num*2+ii*2+0] = uint16_t(ii);
  485. index[numIndices+num*2+ii*2+1] = uint16_t( (ii+1)%num);
  486. index[numIndices+num*4+ii*2+0] = uint16_t(num + ii);
  487. index[numIndices+num*4+ii*2+1] = uint16_t(num + (ii+1)%num);
  488. }
  489. m_mesh[id].m_startVertex = startVertex;
  490. m_mesh[id].m_numVertices = numVertices;
  491. m_mesh[id].m_startIndex[0] = startIndex;
  492. m_mesh[id].m_numIndices[0] = numIndices;
  493. m_mesh[id].m_startIndex[1] = startIndex+numIndices;
  494. m_mesh[id].m_numIndices[1] = numLineListIndices;
  495. startVertex += numVertices;
  496. startIndex += numIndices + numLineListIndices;
  497. }
  498. m_mesh[Mesh::Cube].m_startVertex = startVertex;
  499. m_mesh[Mesh::Cube].m_numVertices = BX_COUNTOF(s_cubeVertices);
  500. m_mesh[Mesh::Cube].m_startIndex[0] = startIndex;
  501. m_mesh[Mesh::Cube].m_numIndices[0] = BX_COUNTOF(s_cubeIndices);
  502. m_mesh[Mesh::Cube].m_startIndex[1] = 0;
  503. m_mesh[Mesh::Cube].m_numIndices[1] = 0;
  504. startVertex += m_mesh[Mesh::Cube].m_numVertices;
  505. startIndex += m_mesh[Mesh::Cube].m_numIndices[0];
  506. const bgfx::Memory* vb = bgfx::alloc(startVertex*stride);
  507. const bgfx::Memory* ib = bgfx::alloc(startIndex*sizeof(uint16_t) );
  508. for (uint32_t mesh = Mesh::Sphere0; mesh < Mesh::Cube; ++mesh)
  509. {
  510. Mesh::Enum id = Mesh::Enum(mesh);
  511. memcpy(&vb->data[m_mesh[id].m_startVertex * stride]
  512. , vertices[id]
  513. , m_mesh[id].m_numVertices*stride
  514. );
  515. memcpy(&ib->data[m_mesh[id].m_startIndex[0] * sizeof(uint16_t)]
  516. , indices[id]
  517. , (m_mesh[id].m_numIndices[0]+m_mesh[id].m_numIndices[1])*sizeof(uint16_t)
  518. );
  519. BX_FREE(m_allocator, vertices[id]);
  520. BX_FREE(m_allocator, indices[id]);
  521. }
  522. memcpy(&vb->data[m_mesh[Mesh::Cube].m_startVertex * stride]
  523. , s_cubeVertices
  524. , sizeof(s_cubeVertices)
  525. );
  526. memcpy(&ib->data[m_mesh[Mesh::Cube].m_startIndex[0] * sizeof(uint16_t)]
  527. , s_cubeIndices
  528. , sizeof(s_cubeIndices)
  529. );
  530. m_vbh = bgfx::createVertexBuffer(vb, DebugShapeVertex::ms_decl);
  531. m_ibh = bgfx::createIndexBuffer(ib);
  532. m_mtx = 0;
  533. m_viewId = 0;
  534. m_pos = 0;
  535. m_indexPos = 0;
  536. m_vertexPos = 0;
  537. }
  538. void shutdown()
  539. {
  540. bgfx::destroyIndexBuffer(m_ibh);
  541. bgfx::destroyVertexBuffer(m_vbh);
  542. for (uint32_t ii = 0; ii < Program::Count; ++ii)
  543. {
  544. bgfx::destroyProgram(m_program[ii]);
  545. }
  546. bgfx::destroyUniform(u_params);
  547. }
  548. void begin(uint8_t _viewId)
  549. {
  550. BX_CHECK(State::Count == m_state);
  551. m_viewId = _viewId;
  552. m_mtx = 0;
  553. m_state = State::None;
  554. m_stack = 0;
  555. Attrib& attrib = m_attrib[0];
  556. attrib.m_state = 0
  557. | BGFX_STATE_RGB_WRITE
  558. | (m_depthTestLess ? BGFX_STATE_DEPTH_TEST_LESS : BGFX_STATE_DEPTH_TEST_GREATER)
  559. | BGFX_STATE_CULL_CW
  560. | BGFX_STATE_DEPTH_WRITE
  561. ;
  562. attrib.m_scale = 1.0f;
  563. attrib.m_spin = 0.0f;
  564. attrib.m_offset = 0.0f;
  565. attrib.m_abgr = UINT32_MAX;
  566. attrib.m_stipple = false;
  567. attrib.m_wireframe = false;
  568. attrib.m_lod = 0;
  569. }
  570. void end()
  571. {
  572. BX_CHECK(0 == m_stack, "Invalid stack %d.", m_stack);
  573. flush();
  574. m_state = State::Count;
  575. }
  576. void push()
  577. {
  578. BX_CHECK(State::Count != m_state);
  579. ++m_stack;
  580. m_attrib[m_stack] = m_attrib[m_stack-1];
  581. }
  582. void pop()
  583. {
  584. BX_CHECK(State::Count != m_state);
  585. const Attrib& curr = m_attrib[m_stack];
  586. const Attrib& prev = m_attrib[m_stack-1];
  587. if (curr.m_stipple != prev.m_stipple
  588. || curr.m_state != prev.m_state)
  589. {
  590. flush();
  591. }
  592. --m_stack;
  593. }
  594. void setTransform(const void* _mtx)
  595. {
  596. BX_CHECK(State::Count != m_state);
  597. flush();
  598. if (NULL == _mtx)
  599. {
  600. m_mtx = 0;
  601. return;
  602. }
  603. bgfx::Transform transform;
  604. m_mtx = bgfx::allocTransform(&transform, 1);
  605. memcpy(transform.data, _mtx, 64);
  606. }
  607. void setTranslate(float _x, float _y, float _z)
  608. {
  609. float mtx[16];
  610. bx::mtxTranslate(mtx, _x, _y, _z);
  611. setTransform(mtx);
  612. }
  613. void setTranslate(const float* _pos)
  614. {
  615. setTranslate(_pos[0], _pos[1], _pos[2]);
  616. }
  617. void setState(bool _depthTest, bool _depthWrite, bool _clockwise)
  618. {
  619. flush();
  620. const uint64_t depthTest = m_depthTestLess
  621. ? BGFX_STATE_DEPTH_TEST_LESS
  622. : BGFX_STATE_DEPTH_TEST_GREATER
  623. ;
  624. uint64_t state = m_attrib[m_stack].m_state & ~(0
  625. | BGFX_STATE_DEPTH_TEST_MASK
  626. | BGFX_STATE_DEPTH_WRITE
  627. | BGFX_STATE_CULL_CW
  628. | BGFX_STATE_CULL_CCW
  629. );
  630. state |= _depthTest
  631. ? depthTest
  632. : 0
  633. ;
  634. state |= _depthWrite
  635. ? BGFX_STATE_DEPTH_WRITE
  636. : 0
  637. ;
  638. state |= _clockwise
  639. ? BGFX_STATE_CULL_CW
  640. : BGFX_STATE_CULL_CCW
  641. ;
  642. if (m_attrib[m_stack].m_state != state)
  643. {
  644. flush();
  645. }
  646. m_attrib[m_stack].m_state = state;
  647. }
  648. void setColor(uint32_t _abgr)
  649. {
  650. BX_CHECK(State::Count != m_state);
  651. m_attrib[m_stack].m_abgr = _abgr;
  652. }
  653. void setLod(uint8_t _lod)
  654. {
  655. BX_CHECK(State::Count != m_state);
  656. m_attrib[m_stack].m_lod = _lod;
  657. }
  658. void setWireframe(bool _wireframe)
  659. {
  660. BX_CHECK(State::Count != m_state);
  661. m_attrib[m_stack].m_wireframe = _wireframe;
  662. }
  663. void setStipple(bool _stipple, float _scale = 1.0f, float _offset = 0.0f)
  664. {
  665. BX_CHECK(State::Count != m_state);
  666. Attrib& attrib = m_attrib[m_stack];
  667. if (attrib.m_stipple != _stipple)
  668. {
  669. flush();
  670. }
  671. attrib.m_stipple = _stipple;
  672. attrib.m_offset = _offset;
  673. attrib.m_scale = _scale;
  674. }
  675. void setSpin(float _spin)
  676. {
  677. Attrib& attrib = m_attrib[m_stack];
  678. attrib.m_spin = _spin;
  679. }
  680. void moveTo(float _x, float _y, float _z = 0.0f)
  681. {
  682. BX_CHECK(State::Count != m_state);
  683. softFlush();
  684. m_state = State::MoveTo;
  685. DebugVertex& vertex = m_cache[m_pos];
  686. vertex.m_x = _x;
  687. vertex.m_y = _y;
  688. vertex.m_z = _z;
  689. Attrib& attrib = m_attrib[m_stack];
  690. vertex.m_abgr = attrib.m_abgr;
  691. vertex.m_len = attrib.m_offset;
  692. m_vertexPos = m_pos;
  693. }
  694. void moveTo(const void* _pos)
  695. {
  696. BX_CHECK(State::Count != m_state);
  697. const float* pos = (const float*)_pos;
  698. moveTo(pos[0], pos[1], pos[2]);
  699. }
  700. void moveTo(Axis::Enum _axis, float _x, float _y)
  701. {
  702. float pos[3];
  703. getPoint(pos, _axis, _x, _y);
  704. moveTo(pos);
  705. }
  706. void lineTo(float _x, float _y, float _z = 0.0f)
  707. {
  708. BX_CHECK(State::Count != m_state);
  709. if (State::None == m_state)
  710. {
  711. moveTo(_x, _y, _z);
  712. return;
  713. }
  714. if (m_pos+2 > uint16_t(BX_COUNTOF(m_cache) ) )
  715. {
  716. uint32_t pos = m_pos;
  717. uint32_t vertexPos = m_vertexPos;
  718. flush();
  719. memcpy(&m_cache[0], &m_cache[vertexPos], sizeof(DebugVertex) );
  720. if (vertexPos == pos)
  721. {
  722. m_pos = 1;
  723. }
  724. else
  725. {
  726. memcpy(&m_cache[1], &m_cache[pos - 1], sizeof(DebugVertex) );
  727. m_pos = 2;
  728. }
  729. m_state = State::LineTo;
  730. }
  731. else if (State::MoveTo == m_state)
  732. {
  733. ++m_pos;
  734. m_state = State::LineTo;
  735. }
  736. uint16_t prev = m_pos-1;
  737. uint16_t curr = m_pos++;
  738. DebugVertex& vertex = m_cache[curr];
  739. vertex.m_x = _x;
  740. vertex.m_y = _y;
  741. vertex.m_z = _z;
  742. Attrib& attrib = m_attrib[m_stack];
  743. vertex.m_abgr = attrib.m_abgr;
  744. vertex.m_len = attrib.m_offset;
  745. float tmp[3];
  746. bx::vec3Sub(tmp, &vertex.m_x, &m_cache[prev].m_x);
  747. float len = bx::vec3Length(tmp) * attrib.m_scale;
  748. vertex.m_len = m_cache[prev].m_len + len;
  749. m_indices[m_indexPos++] = prev;
  750. m_indices[m_indexPos++] = curr;
  751. }
  752. void lineTo(const void* _pos)
  753. {
  754. BX_CHECK(State::Count != m_state);
  755. const float* pos = (const float*)_pos;
  756. lineTo(pos[0], pos[1], pos[2]);
  757. }
  758. void lineTo(Axis::Enum _axis, float _x, float _y)
  759. {
  760. float pos[3];
  761. getPoint(pos, _axis, _x, _y);
  762. lineTo(pos);
  763. }
  764. void close()
  765. {
  766. BX_CHECK(State::Count != m_state);
  767. DebugVertex& vertex = m_cache[m_vertexPos];
  768. lineTo(vertex.m_x, vertex.m_y, vertex.m_z);
  769. m_state = State::None;
  770. }
  771. void draw(const Aabb& _aabb)
  772. {
  773. moveTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_min[2]);
  774. lineTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_min[2]);
  775. lineTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_min[2]);
  776. lineTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_min[2]);
  777. close();
  778. moveTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_max[2]);
  779. lineTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_max[2]);
  780. lineTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_max[2]);
  781. lineTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_max[2]);
  782. close();
  783. moveTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_min[2]);
  784. lineTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_max[2]);
  785. moveTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_min[2]);
  786. lineTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_max[2]);
  787. moveTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_min[2]);
  788. lineTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_max[2]);
  789. moveTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_min[2]);
  790. lineTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_max[2]);
  791. }
  792. void draw(const Cylinder& _cylinder, bool _capsule)
  793. {
  794. drawCylinder(_cylinder.m_pos, _cylinder.m_end, _cylinder.m_radius, _capsule);
  795. }
  796. void draw(const Disk& _disk)
  797. {
  798. drawCircle(_disk.m_normal, _disk.m_center, _disk.m_radius, 0.0f);
  799. }
  800. void draw(const Obb& _obb)
  801. {
  802. const Attrib& attrib = m_attrib[m_stack];
  803. if (attrib.m_wireframe)
  804. {
  805. setTransform(_obb.m_mtx);
  806. moveTo(-1.0f, -1.0f, -1.0f);
  807. lineTo( 1.0f, -1.0f, -1.0f);
  808. lineTo( 1.0f, 1.0f, -1.0f);
  809. lineTo(-1.0f, 1.0f, -1.0f);
  810. close();
  811. moveTo(-1.0f, 1.0f, 1.0f);
  812. lineTo( 1.0f, 1.0f, 1.0f);
  813. lineTo( 1.0f, -1.0f, 1.0f);
  814. lineTo(-1.0f, -1.0f, 1.0f);
  815. close();
  816. moveTo( 1.0f, -1.0f, -1.0f);
  817. lineTo( 1.0f, -1.0f, 1.0f);
  818. moveTo( 1.0f, 1.0f, -1.0f);
  819. lineTo( 1.0f, 1.0f, 1.0f);
  820. moveTo(-1.0f, 1.0f, -1.0f);
  821. lineTo(-1.0f, 1.0f, 1.0f);
  822. moveTo(-1.0f, -1.0f, -1.0f);
  823. lineTo(-1.0f, -1.0f, 1.0f);
  824. setTransform(NULL);
  825. }
  826. else
  827. {
  828. draw(Mesh::Cube, _obb.m_mtx, 1, false);
  829. }
  830. }
  831. void draw(const Sphere& _sphere)
  832. {
  833. const Attrib& attrib = m_attrib[m_stack];
  834. float mtx[16];
  835. bx::mtxSRT(mtx
  836. , _sphere.m_radius
  837. , _sphere.m_radius
  838. , _sphere.m_radius
  839. , 0.0f
  840. , 0.0f
  841. , 0.0f
  842. , _sphere.m_center[0]
  843. , _sphere.m_center[1]
  844. , _sphere.m_center[2]
  845. );
  846. uint8_t lod = attrib.m_lod > Mesh::SphereMaxLod
  847. ? uint8_t(Mesh::SphereMaxLod)
  848. : attrib.m_lod
  849. ;
  850. draw(Mesh::Enum(Mesh::Sphere0 + lod), mtx, 1, attrib.m_wireframe);
  851. }
  852. void drawFrustum(const float* _viewProj)
  853. {
  854. Plane planes[6];
  855. buildFrustumPlanes(planes, _viewProj);
  856. float points[24];
  857. intersectPlanes(&points[ 0], planes[0], planes[2], planes[4]);
  858. intersectPlanes(&points[ 3], planes[0], planes[3], planes[4]);
  859. intersectPlanes(&points[ 6], planes[0], planes[3], planes[5]);
  860. intersectPlanes(&points[ 9], planes[0], planes[2], planes[5]);
  861. intersectPlanes(&points[12], planes[1], planes[2], planes[4]);
  862. intersectPlanes(&points[15], planes[1], planes[3], planes[4]);
  863. intersectPlanes(&points[18], planes[1], planes[3], planes[5]);
  864. intersectPlanes(&points[21], planes[1], planes[2], planes[5]);
  865. moveTo(&points[ 0]);
  866. lineTo(&points[ 3]);
  867. lineTo(&points[ 6]);
  868. lineTo(&points[ 9]);
  869. close();
  870. moveTo(&points[12]);
  871. lineTo(&points[15]);
  872. lineTo(&points[18]);
  873. lineTo(&points[21]);
  874. close();
  875. moveTo(&points[ 0]);
  876. lineTo(&points[12]);
  877. moveTo(&points[ 3]);
  878. lineTo(&points[15]);
  879. moveTo(&points[ 6]);
  880. lineTo(&points[18]);
  881. moveTo(&points[ 9]);
  882. lineTo(&points[21]);
  883. }
  884. void drawFrustum(const void* _viewProj)
  885. {
  886. drawFrustum( (const float*)_viewProj);
  887. }
  888. void drawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees)
  889. {
  890. const Attrib& attrib = m_attrib[m_stack];
  891. const uint32_t num = getCircleLod(attrib.m_lod);
  892. const float step = bx::pi * 2.0f / num;
  893. _degrees = bx::fwrap(_degrees, 360.0f);
  894. float pos[3];
  895. getPoint(pos, _axis
  896. , bx::fsin(step * 0)*_radius
  897. , bx::fcos(step * 0)*_radius
  898. );
  899. moveTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  900. uint32_t n = uint32_t(num*_degrees/360.0f);
  901. for (uint32_t ii = 1; ii < n+1; ++ii)
  902. {
  903. getPoint(pos, _axis
  904. , bx::fsin(step * ii)*_radius
  905. , bx::fcos(step * ii)*_radius
  906. );
  907. lineTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  908. }
  909. moveTo(_x, _y, _z);
  910. getPoint(pos, _axis
  911. , bx::fsin(step * 0)*_radius
  912. , bx::fcos(step * 0)*_radius
  913. );
  914. lineTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  915. getPoint(pos, _axis
  916. , bx::fsin(step * n)*_radius
  917. , bx::fcos(step * n)*_radius
  918. );
  919. moveTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  920. lineTo(_x, _y, _z);
  921. }
  922. void drawCircle(const float* _normal, const float* _center, float _radius, float _weight)
  923. {
  924. const Attrib& attrib = m_attrib[m_stack];
  925. const uint32_t num = getCircleLod(attrib.m_lod);
  926. const float step = bx::pi * 2.0f / num;
  927. _weight = bx::fclamp(_weight, 0.0f, 2.0f);
  928. float udir[3];
  929. float vdir[3];
  930. bx::vec3TangentFrame(_normal, udir, vdir, attrib.m_spin);
  931. float pos[3];
  932. float tmp0[3];
  933. float tmp1[3];
  934. float xy0[2];
  935. float xy1[2];
  936. circle(xy0, 0.0f);
  937. squircle(xy1, 0.0f);
  938. bx::vec3Mul(pos, udir, bx::flerp(xy0[0], xy1[0], _weight)*_radius);
  939. bx::vec3Mul(tmp0, vdir, bx::flerp(xy0[1], xy1[1], _weight)*_radius);
  940. bx::vec3Add(tmp1, pos, tmp0);
  941. bx::vec3Add(pos, tmp1, _center);
  942. moveTo(pos);
  943. for (uint32_t ii = 1; ii < num; ++ii)
  944. {
  945. float angle = step * ii;
  946. circle(xy0, angle);
  947. squircle(xy1, angle);
  948. bx::vec3Mul(pos, udir, bx::flerp(xy0[0], xy1[0], _weight)*_radius);
  949. bx::vec3Mul(tmp0, vdir, bx::flerp(xy0[1], xy1[1], _weight)*_radius);
  950. bx::vec3Add(tmp1, pos, tmp0);
  951. bx::vec3Add(pos, tmp1, _center);
  952. lineTo(pos);
  953. }
  954. close();
  955. }
  956. void drawCircle(const void* _normal, const void* _center, float _radius, float _weight)
  957. {
  958. drawCircle( (const float*)_normal, (const float*)_center, _radius, _weight);
  959. }
  960. void drawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight)
  961. {
  962. const Attrib& attrib = m_attrib[m_stack];
  963. const uint32_t num = getCircleLod(attrib.m_lod);
  964. const float step = bx::pi * 2.0f / num;
  965. _weight = bx::fclamp(_weight, 0.0f, 2.0f);
  966. float xy0[2];
  967. float xy1[2];
  968. circle(xy0, 0.0f);
  969. squircle(xy1, 0.0f);
  970. float pos[3];
  971. getPoint(pos, _axis
  972. , bx::flerp(xy0[0], xy1[0], _weight)*_radius
  973. , bx::flerp(xy0[1], xy1[1], _weight)*_radius
  974. );
  975. moveTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  976. for (uint32_t ii = 1; ii < num; ++ii)
  977. {
  978. float angle = step * ii;
  979. circle(xy0, angle);
  980. squircle(xy1, angle);
  981. getPoint(pos, _axis
  982. , bx::flerp(xy0[0], xy1[0], _weight)*_radius
  983. , bx::flerp(xy0[1], xy1[1], _weight)*_radius
  984. );
  985. lineTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  986. }
  987. close();
  988. }
  989. void drawQuad(const float* _normal, const float* _center, float _size)
  990. {
  991. const Attrib& attrib = m_attrib[m_stack];
  992. float udir[3];
  993. float vdir[3];
  994. bx::vec3TangentFrame(_normal, udir, vdir, attrib.m_spin);
  995. const float halfExtent = _size*0.5f;
  996. float umin[3];
  997. bx::vec3Mul(umin, udir, -halfExtent);
  998. float umax[3];
  999. bx::vec3Mul(umax, udir, halfExtent);
  1000. float vmin[3];
  1001. bx::vec3Mul(vmin, vdir, -halfExtent);
  1002. float vmax[3];
  1003. bx::vec3Mul(vmax, vdir, halfExtent);
  1004. float pt[3];
  1005. float tmp[3];
  1006. bx::vec3Add(tmp, umin, vmin);
  1007. bx::vec3Add(pt, _center, tmp);
  1008. moveTo(pt);
  1009. bx::vec3Add(tmp, umax, vmin);
  1010. bx::vec3Add(pt, _center, tmp);
  1011. lineTo(pt);
  1012. bx::vec3Add(tmp, umax, vmax);
  1013. bx::vec3Add(pt, _center, tmp);
  1014. lineTo(pt);
  1015. bx::vec3Add(tmp, umin, vmax);
  1016. bx::vec3Add(pt, _center, tmp);
  1017. lineTo(pt);
  1018. close();
  1019. }
  1020. void drawCone(const float* _from, const float* _to, float _radius)
  1021. {
  1022. const Attrib& attrib = m_attrib[m_stack];
  1023. float tmp0[3];
  1024. bx::vec3Sub(tmp0, _from, _to);
  1025. float normal[3];
  1026. bx::vec3Norm(normal, tmp0);
  1027. float mtx[2][16];
  1028. bx::mtxFromNormal(mtx[0], normal, _radius, _from, attrib.m_spin);
  1029. memcpy(mtx[1], mtx[0], 64);
  1030. mtx[1][12] = _to[0];
  1031. mtx[1][13] = _to[1];
  1032. mtx[1][14] = _to[2];
  1033. uint8_t lod = attrib.m_lod > Mesh::ConeMaxLod
  1034. ? uint8_t(Mesh::ConeMaxLod)
  1035. : attrib.m_lod
  1036. ;
  1037. draw(Mesh::Enum(Mesh::Cone0 + lod), mtx[0], 2, attrib.m_wireframe);
  1038. }
  1039. void drawCone(const void* _from, const void* _to, float _radius)
  1040. {
  1041. drawCone( (const float*)_from, (const float*)_to, _radius);
  1042. }
  1043. void drawCylinder(const float* _from, const float* _to, float _radius, bool _capsule)
  1044. {
  1045. const Attrib& attrib = m_attrib[m_stack];
  1046. float tmp0[3];
  1047. bx::vec3Sub(tmp0, _from, _to);
  1048. float normal[3];
  1049. bx::vec3Norm(normal, tmp0);
  1050. float mtx[2][16];
  1051. bx::mtxFromNormal(mtx[0], normal, _radius, _from, attrib.m_spin);
  1052. memcpy(mtx[1], mtx[0], 64);
  1053. mtx[1][12] = _to[0];
  1054. mtx[1][13] = _to[1];
  1055. mtx[1][14] = _to[2];
  1056. if (_capsule)
  1057. {
  1058. uint8_t lod = attrib.m_lod > Mesh::CapsuleMaxLod
  1059. ? uint8_t(Mesh::CapsuleMaxLod)
  1060. : attrib.m_lod
  1061. ;
  1062. draw(Mesh::Enum(Mesh::Capsule0 + lod), mtx[0], 2, attrib.m_wireframe);
  1063. Sphere sphere;
  1064. bx::vec3Move(sphere.m_center, _from);
  1065. sphere.m_radius = _radius;
  1066. draw(sphere);
  1067. bx::vec3Move(sphere.m_center, _to);
  1068. draw(sphere);
  1069. }
  1070. else
  1071. {
  1072. uint8_t lod = attrib.m_lod > Mesh::CylinderMaxLod
  1073. ? uint8_t(Mesh::CylinderMaxLod)
  1074. : attrib.m_lod
  1075. ;
  1076. draw(Mesh::Enum(Mesh::Cylinder0 + lod), mtx[0], 2, attrib.m_wireframe);
  1077. }
  1078. }
  1079. void drawCylinder(const void* _from, const void* _to, float _radius, bool _capsule)
  1080. {
  1081. drawCylinder( (const float*)_from, (const float*)_to, _radius, _capsule);
  1082. }
  1083. void drawAxis(float _x, float _y, float _z, float _len, Axis::Enum _highlight, float _thickness)
  1084. {
  1085. push();
  1086. if (_thickness > 0.0f)
  1087. {
  1088. float from[3] = { _x, _y, _z };
  1089. float mid[3];
  1090. float to[3];
  1091. setColor(Axis::X == _highlight ? 0xff00ffff : 0xff0000ff);
  1092. mid[0] = _x + _len - _thickness;
  1093. mid[1] = _y;
  1094. mid[2] = _z;
  1095. to[0] = _x + _len;
  1096. to[1] = _y;
  1097. to[2] = _z;
  1098. drawCylinder(from, mid, _thickness, false);
  1099. drawCone(mid, to, _thickness);
  1100. setColor(Axis::Y == _highlight ? 0xff00ffff : 0xff00ff00);
  1101. mid[0] = _x;
  1102. mid[1] = _y + _len - _thickness;
  1103. mid[2] = _z;
  1104. to[0] = _x;
  1105. to[1] = _y + _len;
  1106. to[2] = _z;
  1107. drawCylinder(from, mid, _thickness, false);
  1108. drawCone(mid, to, _thickness);
  1109. setColor(Axis::Z == _highlight ? 0xff00ffff : 0xffff0000);
  1110. mid[0] = _x;
  1111. mid[1] = _y;
  1112. mid[2] = _z + _len - _thickness;
  1113. to[0] = _x;
  1114. to[1] = _y;
  1115. to[2] = _z + _len;
  1116. drawCylinder(from, mid, _thickness, false);
  1117. drawCone(mid, to, _thickness);
  1118. }
  1119. else
  1120. {
  1121. setColor(Axis::X == _highlight ? 0xff00ffff : 0xff0000ff);
  1122. moveTo(_x, _y, _z);
  1123. lineTo(_x + _len, _y, _z);
  1124. setColor(Axis::Y == _highlight ? 0xff00ffff : 0xff00ff00);
  1125. moveTo(_x, _y, _z);
  1126. lineTo(_x, _y + _len, _z);
  1127. setColor(Axis::Z == _highlight ? 0xff00ffff : 0xffff0000);
  1128. moveTo(_x, _y, _z);
  1129. lineTo(_x, _y, _z + _len);
  1130. }
  1131. pop();
  1132. }
  1133. void drawGrid(const float* _normal, const float* _center, uint32_t _size, float _step)
  1134. {
  1135. const Attrib& attrib = m_attrib[m_stack];
  1136. float udir[3];
  1137. float vdir[3];
  1138. bx::vec3TangentFrame(_normal, udir, vdir, attrib.m_spin);
  1139. bx::vec3Mul(udir, udir, _step);
  1140. bx::vec3Mul(vdir, vdir, _step);
  1141. const uint32_t num = (_size/2)*2+1;
  1142. const float halfExtent = float(_size/2);
  1143. float umin[3];
  1144. bx::vec3Mul(umin, udir, -halfExtent);
  1145. float umax[3];
  1146. bx::vec3Mul(umax, udir, halfExtent);
  1147. float vmin[3];
  1148. bx::vec3Mul(vmin, vdir, -halfExtent);
  1149. float vmax[3];
  1150. bx::vec3Mul(vmax, vdir, halfExtent);
  1151. float tmp[3];
  1152. float xs[3];
  1153. float xe[3];
  1154. bx::vec3Add(tmp, umin, vmin);
  1155. bx::vec3Add(xs, _center, tmp);
  1156. bx::vec3Add(tmp, umax, vmin);
  1157. bx::vec3Add(xe, _center, tmp);
  1158. float ys[3];
  1159. float ye[3];
  1160. bx::vec3Add(tmp, umin, vmin);
  1161. bx::vec3Add(ys, _center, tmp);
  1162. bx::vec3Add(tmp, umin, vmax);
  1163. bx::vec3Add(ye, _center, tmp);
  1164. for (uint32_t ii = 0; ii < num; ++ii)
  1165. {
  1166. moveTo(xs);
  1167. lineTo(xe);
  1168. bx::vec3Add(xs, xs, vdir);
  1169. bx::vec3Add(xe, xe, vdir);
  1170. moveTo(ys);
  1171. lineTo(ye);
  1172. bx::vec3Add(ys, ys, udir);
  1173. bx::vec3Add(ye, ye, udir);
  1174. }
  1175. }
  1176. void drawGrid(const void* _normal, const void* _center, uint32_t _size, float _step)
  1177. {
  1178. drawGrid( (const float*)_normal, (const float*)_center, _size, _step);
  1179. }
  1180. void drawGrid(Axis::Enum _axis, const float* _center, uint32_t _size, float _step)
  1181. {
  1182. push();
  1183. setTranslate(_center);
  1184. const uint32_t num = (_size/2)*2-1;
  1185. const float halfExtent = float(_size/2) * _step;
  1186. setColor(0xff606060);
  1187. float yy = -halfExtent + _step;
  1188. for (uint32_t ii = 0; ii < num; ++ii)
  1189. {
  1190. moveTo(_axis, -halfExtent, yy);
  1191. lineTo(_axis, halfExtent, yy);
  1192. moveTo(_axis, yy, -halfExtent);
  1193. lineTo(_axis, yy, halfExtent);
  1194. yy += _step;
  1195. }
  1196. setColor(0xff101010);
  1197. moveTo(_axis, -halfExtent, -halfExtent);
  1198. lineTo(_axis, -halfExtent, halfExtent);
  1199. lineTo(_axis, halfExtent, halfExtent);
  1200. lineTo(_axis, halfExtent, -halfExtent);
  1201. close();
  1202. moveTo(_axis, -halfExtent, 0.0f);
  1203. lineTo(_axis, halfExtent, 0.0f);
  1204. moveTo(_axis, 0.0f, -halfExtent);
  1205. lineTo(_axis, 0.0f, halfExtent);
  1206. pop();
  1207. }
  1208. void drawGrid(Axis::Enum _axis, const void* _center, uint32_t _size, float _step)
  1209. {
  1210. drawGrid(_axis, (const float*)_center, _size, _step);
  1211. }
  1212. void drawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _hightlight)
  1213. {
  1214. push();
  1215. setColor(Axis::X == _hightlight ? 0xff00ffff : 0xff0000ff);
  1216. drawCircle(Axis::X, _x, _y, _z, _radius, 0.0f);
  1217. setColor(Axis::Y == _hightlight ? 0xff00ffff : 0xff00ff00);
  1218. drawCircle(Axis::Y, _x, _y, _z, _radius, 0.0f);
  1219. setColor(Axis::Z == _hightlight ? 0xff00ffff : 0xffff0000);
  1220. drawCircle(Axis::Z, _x, _y, _z, _radius, 0.0f);
  1221. pop();
  1222. }
  1223. private:
  1224. struct Mesh
  1225. {
  1226. enum Enum
  1227. {
  1228. Sphere0,
  1229. Sphere1,
  1230. Sphere2,
  1231. Sphere3,
  1232. Cone0,
  1233. Cone1,
  1234. Cone2,
  1235. Cone3,
  1236. Cylinder0,
  1237. Cylinder1,
  1238. Cylinder2,
  1239. Cylinder3,
  1240. Capsule0,
  1241. Capsule1,
  1242. Capsule2,
  1243. Capsule3,
  1244. Cube,
  1245. Count,
  1246. SphereMaxLod = Sphere3 - Sphere0,
  1247. ConeMaxLod = Cone3 - Cone0,
  1248. CylinderMaxLod = Cylinder3 - Cylinder0,
  1249. CapsuleMaxLod = Capsule3 - Capsule0,
  1250. };
  1251. uint32_t m_startVertex;
  1252. uint32_t m_numVertices;
  1253. uint32_t m_startIndex[2];
  1254. uint32_t m_numIndices[2];
  1255. };
  1256. struct Program
  1257. {
  1258. enum Enum
  1259. {
  1260. Lines,
  1261. LinesStipple,
  1262. Fill,
  1263. FillLit,
  1264. Count
  1265. };
  1266. };
  1267. void draw(Mesh::Enum _mesh, const float* _mtx, uint16_t _num, bool _wireframe) const
  1268. {
  1269. const Mesh& mesh = m_mesh[_mesh];
  1270. const Attrib& attrib = m_attrib[m_stack];
  1271. if (0 != mesh.m_numIndices[_wireframe])
  1272. {
  1273. bgfx::setIndexBuffer(m_ibh
  1274. , mesh.m_startIndex[_wireframe]
  1275. , mesh.m_numIndices[_wireframe]
  1276. );
  1277. }
  1278. const float flip = 0 == (attrib.m_state & BGFX_STATE_CULL_CCW) ? 1.0f : -1.0f;
  1279. const uint8_t alpha = attrib.m_abgr>>24;
  1280. float params[4][4] =
  1281. {
  1282. { // lightDir
  1283. 0.0f * flip,
  1284. -1.0f * flip,
  1285. 0.0f * flip,
  1286. 3.0f, // shininess
  1287. },
  1288. { // skyColor
  1289. 1.0f,
  1290. 0.9f,
  1291. 0.8f,
  1292. 0.0f, // unused
  1293. },
  1294. { // groundColor.xyz0
  1295. 0.2f,
  1296. 0.22f,
  1297. 0.5f,
  1298. 0.0f, // unused
  1299. },
  1300. { // matColor
  1301. ( (attrib.m_abgr )&0xff)/255.0f,
  1302. ( (attrib.m_abgr>> 8)&0xff)/255.0f,
  1303. ( (attrib.m_abgr>>16)&0xff)/255.0f,
  1304. ( alpha )/255.0f,
  1305. },
  1306. };
  1307. bx::vec3Norm(params[0], params[0]);
  1308. bgfx::setUniform(u_params, params, 4);
  1309. bgfx::setTransform(_mtx, _num);
  1310. bgfx::setVertexBuffer(m_vbh, mesh.m_startVertex, mesh.m_numVertices);
  1311. bgfx::setState(0
  1312. | attrib.m_state
  1313. | (_wireframe ? BGFX_STATE_PT_LINES|BGFX_STATE_LINEAA|BGFX_STATE_BLEND_ALPHA
  1314. : (alpha < 0xff) ? BGFX_STATE_BLEND_ALPHA : 0)
  1315. );
  1316. bgfx::submit(m_viewId, m_program[_wireframe ? Program::Fill : Program::FillLit]);
  1317. }
  1318. void softFlush()
  1319. {
  1320. if (m_pos == uint16_t(BX_COUNTOF(m_cache) ) )
  1321. {
  1322. flush();
  1323. }
  1324. }
  1325. void flush()
  1326. {
  1327. if (0 != m_pos)
  1328. {
  1329. if (bgfx::checkAvailTransientBuffers(m_pos, DebugVertex::ms_decl, m_indexPos) )
  1330. {
  1331. bgfx::TransientVertexBuffer tvb;
  1332. bgfx::allocTransientVertexBuffer(&tvb, m_pos, DebugVertex::ms_decl);
  1333. memcpy(tvb.data, m_cache, m_pos * DebugVertex::ms_decl.m_stride);
  1334. bgfx::TransientIndexBuffer tib;
  1335. bgfx::allocTransientIndexBuffer(&tib, m_indexPos);
  1336. memcpy(tib.data, m_indices, m_indexPos * sizeof(uint16_t) );
  1337. const Attrib& attrib = m_attrib[m_stack];
  1338. bgfx::setVertexBuffer(&tvb);
  1339. bgfx::setIndexBuffer(&tib);
  1340. bgfx::setState(0
  1341. | BGFX_STATE_RGB_WRITE
  1342. | BGFX_STATE_PT_LINES
  1343. | attrib.m_state
  1344. | BGFX_STATE_LINEAA
  1345. | BGFX_STATE_BLEND_ALPHA
  1346. );
  1347. bgfx::setTransform(m_mtx);
  1348. bgfx::ProgramHandle program = m_program[attrib.m_stipple ? 1 : 0];
  1349. bgfx::submit(m_viewId, program);
  1350. }
  1351. m_state = State::None;
  1352. m_pos = 0;
  1353. m_indexPos = 0;
  1354. m_vertexPos = 0;
  1355. }
  1356. }
  1357. struct State
  1358. {
  1359. enum Enum
  1360. {
  1361. None,
  1362. MoveTo,
  1363. LineTo,
  1364. Count
  1365. };
  1366. };
  1367. static const uint32_t cacheSize = 1024;
  1368. static const uint32_t stackSize = 16;
  1369. BX_STATIC_ASSERT(cacheSize >= 3, "Cache must be at least 3 elements.");
  1370. DebugVertex m_cache[cacheSize+1];
  1371. uint32_t m_mtx;
  1372. uint16_t m_indices[cacheSize*2];
  1373. uint16_t m_pos;
  1374. uint16_t m_indexPos;
  1375. uint16_t m_vertexPos;
  1376. uint8_t m_viewId;
  1377. uint8_t m_stack;
  1378. bool m_depthTestLess;
  1379. struct Attrib
  1380. {
  1381. uint64_t m_state;
  1382. float m_offset;
  1383. float m_scale;
  1384. float m_spin;
  1385. uint32_t m_abgr;
  1386. bool m_stipple;
  1387. bool m_wireframe;
  1388. uint8_t m_lod;
  1389. };
  1390. Attrib m_attrib[stackSize];
  1391. State::Enum m_state;
  1392. Mesh m_mesh[Mesh::Count];
  1393. bgfx::ProgramHandle m_program[Program::Count];
  1394. bgfx::UniformHandle u_params;
  1395. bgfx::VertexBufferHandle m_vbh;
  1396. bgfx::IndexBufferHandle m_ibh;
  1397. bx::AllocatorI* m_allocator;
  1398. };
  1399. static DebugDraw s_dd;
  1400. void ddInit(bool _depthTestLess, bx::AllocatorI* _allocator)
  1401. {
  1402. s_dd.init(_depthTestLess, _allocator);
  1403. }
  1404. void ddShutdown()
  1405. {
  1406. s_dd.shutdown();
  1407. }
  1408. void ddBegin(uint8_t _viewId)
  1409. {
  1410. s_dd.begin(_viewId);
  1411. }
  1412. void ddEnd()
  1413. {
  1414. s_dd.end();
  1415. }
  1416. void ddPush()
  1417. {
  1418. s_dd.push();
  1419. }
  1420. void ddPop()
  1421. {
  1422. s_dd.pop();
  1423. }
  1424. void ddSetState(bool _depthTest, bool _depthWrite, bool _clockwise)
  1425. {
  1426. s_dd.setState(_depthTest, _depthWrite, _clockwise);
  1427. }
  1428. void ddSetColor(uint32_t _abgr)
  1429. {
  1430. s_dd.setColor(_abgr);
  1431. }
  1432. void ddSetLod(uint8_t _lod)
  1433. {
  1434. s_dd.setLod(_lod);
  1435. }
  1436. void ddSetWireframe(bool _wireframe)
  1437. {
  1438. s_dd.setWireframe(_wireframe);
  1439. }
  1440. void ddSetStipple(bool _stipple, float _scale, float _offset)
  1441. {
  1442. s_dd.setStipple(_stipple, _scale, _offset);
  1443. }
  1444. void ddSetSpin(float _spin)
  1445. {
  1446. s_dd.setSpin(_spin);
  1447. }
  1448. void ddSetTransform(const void* _mtx)
  1449. {
  1450. s_dd.setTransform(_mtx);
  1451. }
  1452. void ddSetTranslate(float _x, float _y, float _z)
  1453. {
  1454. s_dd.setTranslate(_x, _y, _z);
  1455. }
  1456. void ddMoveTo(float _x, float _y, float _z)
  1457. {
  1458. s_dd.moveTo(_x, _y, _z);
  1459. }
  1460. void ddMoveTo(const void* _pos)
  1461. {
  1462. s_dd.moveTo(_pos);
  1463. }
  1464. void ddLineTo(float _x, float _y, float _z)
  1465. {
  1466. s_dd.lineTo(_x, _y, _z);
  1467. }
  1468. void ddLineTo(const void* _pos)
  1469. {
  1470. s_dd.lineTo(_pos);
  1471. }
  1472. void ddClose()
  1473. {
  1474. s_dd.close();
  1475. }
  1476. void ddDraw(const Aabb& _aabb)
  1477. {
  1478. s_dd.draw(_aabb);
  1479. }
  1480. void ddDraw(const Cylinder& _cylinder, bool _capsule)
  1481. {
  1482. s_dd.draw(_cylinder, _capsule);
  1483. }
  1484. void ddDraw(const Disk& _disk)
  1485. {
  1486. s_dd.draw(_disk);
  1487. }
  1488. void ddDraw(const Obb& _obb)
  1489. {
  1490. s_dd.draw(_obb);
  1491. }
  1492. void ddDraw(const Sphere& _sphere)
  1493. {
  1494. s_dd.draw(_sphere);
  1495. }
  1496. void ddDrawFrustum(const void* _viewProj)
  1497. {
  1498. s_dd.drawFrustum(_viewProj);
  1499. }
  1500. void ddDrawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees)
  1501. {
  1502. s_dd.drawArc(_axis, _x, _y, _z, _radius, _degrees);
  1503. }
  1504. void ddDrawCircle(const void* _normal, const void* _center, float _radius, float _weight)
  1505. {
  1506. s_dd.drawCircle(_normal, _center, _radius, _weight);
  1507. }
  1508. void ddDrawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight)
  1509. {
  1510. s_dd.drawCircle(_axis, _x, _y, _z, _radius, _weight);
  1511. }
  1512. void ddDrawQuad(const float* _normal, const float* _center, float _size)
  1513. {
  1514. s_dd.drawQuad(_normal, _center, _size);
  1515. }
  1516. void ddDrawCone(const void* _from, const void* _to, float _radius)
  1517. {
  1518. s_dd.drawCone(_from, _to, _radius);
  1519. }
  1520. void ddDrawCylinder(const void* _from, const void* _to, float _radius, bool _capsule)
  1521. {
  1522. if (_capsule)
  1523. {
  1524. s_dd.push();
  1525. s_dd.setLod(0);
  1526. s_dd.drawCylinder(_from, _to, _radius, true);
  1527. s_dd.pop();
  1528. }
  1529. else
  1530. {
  1531. s_dd.drawCylinder(_from, _to, _radius, false);
  1532. }
  1533. }
  1534. void ddDrawCapsule(const void* _from, const void* _to, float _radius)
  1535. {
  1536. s_dd.drawCylinder(_from, _to, _radius, true);
  1537. }
  1538. void ddDrawAxis(float _x, float _y, float _z, float _len, Axis::Enum _hightlight, float _thickness)
  1539. {
  1540. s_dd.drawAxis(_x, _y, _z, _len, _hightlight, _thickness);
  1541. }
  1542. void ddDrawGrid(const void* _normal, const void* _center, uint32_t _size, float _step)
  1543. {
  1544. s_dd.drawGrid(_normal, _center, _size, _step);
  1545. }
  1546. void ddDrawGrid(Axis::Enum _axis, const void* _center, uint32_t _size, float _step)
  1547. {
  1548. s_dd.drawGrid(_axis, _center, _size, _step);
  1549. }
  1550. void ddDrawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _hightlight)
  1551. {
  1552. s_dd.drawOrb(_x, _y, _z, _radius, _hightlight);
  1553. }