debugdraw.cpp 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  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_offset = 0.0f;
  564. attrib.m_abgr = UINT32_MAX;
  565. attrib.m_stipple = false;
  566. attrib.m_wireframe = false;
  567. attrib.m_lod = 0;
  568. }
  569. void end()
  570. {
  571. BX_CHECK(0 == m_stack, "Invalid stack %d.", m_stack);
  572. flush();
  573. m_state = State::Count;
  574. }
  575. void push()
  576. {
  577. BX_CHECK(State::Count != m_state);
  578. ++m_stack;
  579. m_attrib[m_stack] = m_attrib[m_stack-1];
  580. }
  581. void pop()
  582. {
  583. BX_CHECK(State::Count != m_state);
  584. const Attrib& curr = m_attrib[m_stack];
  585. const Attrib& prev = m_attrib[m_stack-1];
  586. if (curr.m_stipple != prev.m_stipple
  587. || curr.m_state != prev.m_state)
  588. {
  589. flush();
  590. }
  591. --m_stack;
  592. }
  593. void setTransform(const void* _mtx)
  594. {
  595. BX_CHECK(State::Count != m_state);
  596. flush();
  597. if (NULL == _mtx)
  598. {
  599. m_mtx = 0;
  600. return;
  601. }
  602. bgfx::Transform transform;
  603. m_mtx = bgfx::allocTransform(&transform, 1);
  604. memcpy(transform.data, _mtx, 64);
  605. }
  606. void setTranslate(float _x, float _y, float _z)
  607. {
  608. float mtx[16];
  609. bx::mtxTranslate(mtx, _x, _y, _z);
  610. setTransform(mtx);
  611. }
  612. void setTranslate(const float* _pos)
  613. {
  614. setTranslate(_pos[0], _pos[1], _pos[2]);
  615. }
  616. void setState(bool _depthTest, bool _depthWrite, bool _clockwise)
  617. {
  618. flush();
  619. const uint64_t depthTest = m_depthTestLess
  620. ? BGFX_STATE_DEPTH_TEST_LESS
  621. : BGFX_STATE_DEPTH_TEST_GREATER
  622. ;
  623. uint64_t state = m_attrib[m_stack].m_state & ~(0
  624. | BGFX_STATE_DEPTH_TEST_MASK
  625. | BGFX_STATE_DEPTH_WRITE
  626. | BGFX_STATE_CULL_CW
  627. | BGFX_STATE_CULL_CCW
  628. );
  629. state |= _depthTest
  630. ? depthTest
  631. : 0
  632. ;
  633. state |= _depthWrite
  634. ? BGFX_STATE_DEPTH_WRITE
  635. : 0
  636. ;
  637. state |= _clockwise
  638. ? BGFX_STATE_CULL_CW
  639. : BGFX_STATE_CULL_CCW
  640. ;
  641. if (m_attrib[m_stack].m_state != state)
  642. {
  643. flush();
  644. }
  645. m_attrib[m_stack].m_state = state;
  646. }
  647. void setColor(uint32_t _abgr)
  648. {
  649. BX_CHECK(State::Count != m_state);
  650. m_attrib[m_stack].m_abgr = _abgr;
  651. }
  652. void setLod(uint8_t _lod)
  653. {
  654. BX_CHECK(State::Count != m_state);
  655. m_attrib[m_stack].m_lod = _lod;
  656. }
  657. void setWireframe(bool _wireframe)
  658. {
  659. BX_CHECK(State::Count != m_state);
  660. m_attrib[m_stack].m_wireframe = _wireframe;
  661. }
  662. void setStipple(bool _stipple, float _scale = 1.0f, float _offset = 0.0f)
  663. {
  664. BX_CHECK(State::Count != m_state);
  665. Attrib& attrib = m_attrib[m_stack];
  666. if (attrib.m_stipple != _stipple)
  667. {
  668. flush();
  669. }
  670. attrib.m_stipple = _stipple;
  671. attrib.m_offset = _offset;
  672. attrib.m_scale = _scale;
  673. }
  674. void moveTo(float _x, float _y, float _z = 0.0f)
  675. {
  676. BX_CHECK(State::Count != m_state);
  677. softFlush();
  678. m_state = State::MoveTo;
  679. DebugVertex& vertex = m_cache[m_pos];
  680. vertex.m_x = _x;
  681. vertex.m_y = _y;
  682. vertex.m_z = _z;
  683. Attrib& attrib = m_attrib[m_stack];
  684. vertex.m_abgr = attrib.m_abgr;
  685. vertex.m_len = attrib.m_offset;
  686. m_vertexPos = m_pos;
  687. }
  688. void moveTo(const void* _pos)
  689. {
  690. BX_CHECK(State::Count != m_state);
  691. const float* pos = (const float*)_pos;
  692. moveTo(pos[0], pos[1], pos[2]);
  693. }
  694. void moveTo(Axis::Enum _axis, float _x, float _y)
  695. {
  696. float pos[3];
  697. getPoint(pos, _axis, _x, _y);
  698. moveTo(pos);
  699. }
  700. void lineTo(float _x, float _y, float _z = 0.0f)
  701. {
  702. BX_CHECK(State::Count != m_state);
  703. if (State::None == m_state)
  704. {
  705. moveTo(_x, _y, _z);
  706. return;
  707. }
  708. if (m_pos+2 > uint16_t(BX_COUNTOF(m_cache) ) )
  709. {
  710. uint32_t pos = m_pos;
  711. uint32_t vertexPos = m_vertexPos;
  712. flush();
  713. memcpy(&m_cache[0], &m_cache[vertexPos], sizeof(DebugVertex) );
  714. if (vertexPos == pos)
  715. {
  716. m_pos = 1;
  717. }
  718. else
  719. {
  720. memcpy(&m_cache[1], &m_cache[pos - 1], sizeof(DebugVertex) );
  721. m_pos = 2;
  722. }
  723. m_state = State::LineTo;
  724. }
  725. else if (State::MoveTo == m_state)
  726. {
  727. ++m_pos;
  728. m_state = State::LineTo;
  729. }
  730. uint16_t prev = m_pos-1;
  731. uint16_t curr = m_pos++;
  732. DebugVertex& vertex = m_cache[curr];
  733. vertex.m_x = _x;
  734. vertex.m_y = _y;
  735. vertex.m_z = _z;
  736. Attrib& attrib = m_attrib[m_stack];
  737. vertex.m_abgr = attrib.m_abgr;
  738. vertex.m_len = attrib.m_offset;
  739. float tmp[3];
  740. bx::vec3Sub(tmp, &vertex.m_x, &m_cache[prev].m_x);
  741. float len = bx::vec3Length(tmp) * attrib.m_scale;
  742. vertex.m_len = m_cache[prev].m_len + len;
  743. m_indices[m_indexPos++] = prev;
  744. m_indices[m_indexPos++] = curr;
  745. }
  746. void lineTo(const void* _pos)
  747. {
  748. BX_CHECK(State::Count != m_state);
  749. const float* pos = (const float*)_pos;
  750. lineTo(pos[0], pos[1], pos[2]);
  751. }
  752. void lineTo(Axis::Enum _axis, float _x, float _y)
  753. {
  754. float pos[3];
  755. getPoint(pos, _axis, _x, _y);
  756. lineTo(pos);
  757. }
  758. void close()
  759. {
  760. BX_CHECK(State::Count != m_state);
  761. DebugVertex& vertex = m_cache[m_vertexPos];
  762. lineTo(vertex.m_x, vertex.m_y, vertex.m_z);
  763. m_state = State::None;
  764. }
  765. void draw(const Aabb& _aabb)
  766. {
  767. moveTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_min[2]);
  768. lineTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_min[2]);
  769. lineTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_min[2]);
  770. lineTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_min[2]);
  771. close();
  772. moveTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_max[2]);
  773. lineTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_max[2]);
  774. lineTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_max[2]);
  775. lineTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_max[2]);
  776. close();
  777. moveTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_min[2]);
  778. lineTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_max[2]);
  779. moveTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_min[2]);
  780. lineTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_max[2]);
  781. moveTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_min[2]);
  782. lineTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_max[2]);
  783. moveTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_min[2]);
  784. lineTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_max[2]);
  785. }
  786. void draw(const Cylinder& _cylinder, bool _capsule)
  787. {
  788. drawCylinder(_cylinder.m_pos, _cylinder.m_end, _cylinder.m_radius, _capsule);
  789. }
  790. void draw(const Disk& _disk)
  791. {
  792. drawCircle(_disk.m_normal, _disk.m_center, _disk.m_radius, 0.0f);
  793. }
  794. void draw(const Obb& _obb)
  795. {
  796. const Attrib& attrib = m_attrib[m_stack];
  797. if (attrib.m_wireframe)
  798. {
  799. setTransform(_obb.m_mtx);
  800. moveTo(-1.0f, -1.0f, -1.0f);
  801. lineTo( 1.0f, -1.0f, -1.0f);
  802. lineTo( 1.0f, 1.0f, -1.0f);
  803. lineTo(-1.0f, 1.0f, -1.0f);
  804. close();
  805. moveTo(-1.0f, 1.0f, 1.0f);
  806. lineTo( 1.0f, 1.0f, 1.0f);
  807. lineTo( 1.0f, -1.0f, 1.0f);
  808. lineTo(-1.0f, -1.0f, 1.0f);
  809. close();
  810. moveTo( 1.0f, -1.0f, -1.0f);
  811. lineTo( 1.0f, -1.0f, 1.0f);
  812. moveTo( 1.0f, 1.0f, -1.0f);
  813. lineTo( 1.0f, 1.0f, 1.0f);
  814. moveTo(-1.0f, 1.0f, -1.0f);
  815. lineTo(-1.0f, 1.0f, 1.0f);
  816. moveTo(-1.0f, -1.0f, -1.0f);
  817. lineTo(-1.0f, -1.0f, 1.0f);
  818. setTransform(NULL);
  819. }
  820. else
  821. {
  822. draw(Mesh::Cube, _obb.m_mtx, 1, false);
  823. }
  824. }
  825. void draw(const Sphere& _sphere)
  826. {
  827. const Attrib& attrib = m_attrib[m_stack];
  828. float mtx[16];
  829. bx::mtxSRT(mtx
  830. , _sphere.m_radius
  831. , _sphere.m_radius
  832. , _sphere.m_radius
  833. , 0.0f
  834. , 0.0f
  835. , 0.0f
  836. , _sphere.m_center[0]
  837. , _sphere.m_center[1]
  838. , _sphere.m_center[2]
  839. );
  840. uint8_t lod = attrib.m_lod > Mesh::SphereMaxLod
  841. ? uint8_t(Mesh::SphereMaxLod)
  842. : attrib.m_lod
  843. ;
  844. draw(Mesh::Enum(Mesh::Sphere0 + lod), mtx, 1, attrib.m_wireframe);
  845. }
  846. void drawFrustum(const float* _viewProj)
  847. {
  848. Plane planes[6];
  849. buildFrustumPlanes(planes, _viewProj);
  850. float points[24];
  851. intersectPlanes(&points[ 0], planes[0], planes[2], planes[4]);
  852. intersectPlanes(&points[ 3], planes[0], planes[3], planes[4]);
  853. intersectPlanes(&points[ 6], planes[0], planes[3], planes[5]);
  854. intersectPlanes(&points[ 9], planes[0], planes[2], planes[5]);
  855. intersectPlanes(&points[12], planes[1], planes[2], planes[4]);
  856. intersectPlanes(&points[15], planes[1], planes[3], planes[4]);
  857. intersectPlanes(&points[18], planes[1], planes[3], planes[5]);
  858. intersectPlanes(&points[21], planes[1], planes[2], planes[5]);
  859. moveTo(&points[ 0]);
  860. lineTo(&points[ 3]);
  861. lineTo(&points[ 6]);
  862. lineTo(&points[ 9]);
  863. close();
  864. moveTo(&points[12]);
  865. lineTo(&points[15]);
  866. lineTo(&points[18]);
  867. lineTo(&points[21]);
  868. close();
  869. moveTo(&points[ 0]);
  870. lineTo(&points[12]);
  871. moveTo(&points[ 3]);
  872. lineTo(&points[15]);
  873. moveTo(&points[ 6]);
  874. lineTo(&points[18]);
  875. moveTo(&points[ 9]);
  876. lineTo(&points[21]);
  877. }
  878. void drawFrustum(const void* _viewProj)
  879. {
  880. drawFrustum( (const float*)_viewProj);
  881. }
  882. void drawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees)
  883. {
  884. const Attrib& attrib = m_attrib[m_stack];
  885. const uint32_t num = getCircleLod(attrib.m_lod);
  886. const float step = bx::pi * 2.0f / num;
  887. _degrees = bx::fwrap(_degrees, 360.0f);
  888. float pos[3];
  889. getPoint(pos, _axis
  890. , bx::fsin(step * 0)*_radius
  891. , bx::fcos(step * 0)*_radius
  892. );
  893. moveTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  894. uint32_t n = uint32_t(num*_degrees/360.0f);
  895. for (uint32_t ii = 1; ii < n+1; ++ii)
  896. {
  897. getPoint(pos, _axis
  898. , bx::fsin(step * ii)*_radius
  899. , bx::fcos(step * ii)*_radius
  900. );
  901. lineTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  902. }
  903. moveTo(_x, _y, _z);
  904. getPoint(pos, _axis
  905. , bx::fsin(step * 0)*_radius
  906. , bx::fcos(step * 0)*_radius
  907. );
  908. lineTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  909. getPoint(pos, _axis
  910. , bx::fsin(step * n)*_radius
  911. , bx::fcos(step * n)*_radius
  912. );
  913. moveTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  914. lineTo(_x, _y, _z);
  915. }
  916. void drawCircle(const float* _normal, const float* _center, float _radius, float _weight)
  917. {
  918. const Attrib& attrib = m_attrib[m_stack];
  919. const uint32_t num = getCircleLod(attrib.m_lod);
  920. const float step = bx::pi * 2.0f / num;
  921. _weight = bx::fclamp(_weight, 0.0f, 2.0f);
  922. Plane plane = { { _normal[0], _normal[1], _normal[2] }, 0.0f };
  923. float udir[3];
  924. float vdir[3];
  925. calcPlaneUv(plane, udir, vdir);
  926. float pos[3];
  927. float tmp0[3];
  928. float tmp1[3];
  929. float xy0[2];
  930. float xy1[2];
  931. circle(xy0, 0.0f);
  932. squircle(xy1, 0.0f);
  933. bx::vec3Mul(pos, udir, bx::flerp(xy0[0], xy1[0], _weight)*_radius);
  934. bx::vec3Mul(tmp0, vdir, bx::flerp(xy0[1], xy1[1], _weight)*_radius);
  935. bx::vec3Add(tmp1, pos, tmp0);
  936. bx::vec3Add(pos, tmp1, _center);
  937. moveTo(pos);
  938. for (uint32_t ii = 1; ii < num; ++ii)
  939. {
  940. float angle = step * ii;
  941. circle(xy0, angle);
  942. squircle(xy1, angle);
  943. bx::vec3Mul(pos, udir, bx::flerp(xy0[0], xy1[0], _weight)*_radius);
  944. bx::vec3Mul(tmp0, vdir, bx::flerp(xy0[1], xy1[1], _weight)*_radius);
  945. bx::vec3Add(tmp1, pos, tmp0);
  946. bx::vec3Add(pos, tmp1, _center);
  947. lineTo(pos);
  948. }
  949. close();
  950. }
  951. void drawCircle(const void* _normal, const void* _center, float _radius, float _weight)
  952. {
  953. drawCircle( (const float*)_normal, (const float*)_center, _radius, _weight);
  954. }
  955. void drawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight)
  956. {
  957. const Attrib& attrib = m_attrib[m_stack];
  958. const uint32_t num = getCircleLod(attrib.m_lod);
  959. const float step = bx::pi * 2.0f / num;
  960. _weight = bx::fclamp(_weight, 0.0f, 2.0f);
  961. float xy0[2];
  962. float xy1[2];
  963. circle(xy0, 0.0f);
  964. squircle(xy1, 0.0f);
  965. float pos[3];
  966. getPoint(pos, _axis
  967. , bx::flerp(xy0[0], xy1[0], _weight)*_radius
  968. , bx::flerp(xy0[1], xy1[1], _weight)*_radius
  969. );
  970. moveTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  971. for (uint32_t ii = 1; ii < num; ++ii)
  972. {
  973. float angle = step * ii;
  974. circle(xy0, angle);
  975. squircle(xy1, angle);
  976. getPoint(pos, _axis
  977. , bx::flerp(xy0[0], xy1[0], _weight)*_radius
  978. , bx::flerp(xy0[1], xy1[1], _weight)*_radius
  979. );
  980. lineTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
  981. }
  982. close();
  983. }
  984. void drawCone(const float* _from, const float* _to, float _radius)
  985. {
  986. const Attrib& attrib = m_attrib[m_stack];
  987. float tmp0[3];
  988. bx::vec3Sub(tmp0, _from, _to);
  989. float normal[3];
  990. bx::vec3Norm(normal, tmp0);
  991. float mtx[2][16];
  992. bx::mtxFromNormal(mtx[0], normal, _radius, _from);
  993. memcpy(mtx[1], mtx[0], 64);
  994. mtx[1][12] = _to[0];
  995. mtx[1][13] = _to[1];
  996. mtx[1][14] = _to[2];
  997. uint8_t lod = attrib.m_lod > Mesh::ConeMaxLod
  998. ? uint8_t(Mesh::ConeMaxLod)
  999. : attrib.m_lod
  1000. ;
  1001. draw(Mesh::Enum(Mesh::Cone0 + lod), mtx[0], 2, attrib.m_wireframe);
  1002. }
  1003. void drawCone(const void* _from, const void* _to, float _radius)
  1004. {
  1005. drawCone( (const float*)_from, (const float*)_to, _radius);
  1006. }
  1007. void drawCylinder(const float* _from, const float* _to, float _radius, bool _capsule)
  1008. {
  1009. const Attrib& attrib = m_attrib[m_stack];
  1010. float tmp0[3];
  1011. bx::vec3Sub(tmp0, _from, _to);
  1012. float normal[3];
  1013. bx::vec3Norm(normal, tmp0);
  1014. float mtx[2][16];
  1015. bx::mtxFromNormal(mtx[0], normal, _radius, _from);
  1016. memcpy(mtx[1], mtx[0], 64);
  1017. mtx[1][12] = _to[0];
  1018. mtx[1][13] = _to[1];
  1019. mtx[1][14] = _to[2];
  1020. if (_capsule)
  1021. {
  1022. uint8_t lod = attrib.m_lod > Mesh::CapsuleMaxLod
  1023. ? uint8_t(Mesh::CapsuleMaxLod)
  1024. : attrib.m_lod
  1025. ;
  1026. draw(Mesh::Enum(Mesh::Capsule0 + lod), mtx[0], 2, attrib.m_wireframe);
  1027. Sphere sphere;
  1028. bx::vec3Move(sphere.m_center, _from);
  1029. sphere.m_radius = _radius;
  1030. draw(sphere);
  1031. bx::vec3Move(sphere.m_center, _to);
  1032. draw(sphere);
  1033. }
  1034. else
  1035. {
  1036. uint8_t lod = attrib.m_lod > Mesh::CylinderMaxLod
  1037. ? uint8_t(Mesh::CylinderMaxLod)
  1038. : attrib.m_lod
  1039. ;
  1040. draw(Mesh::Enum(Mesh::Cylinder0 + lod), mtx[0], 2, attrib.m_wireframe);
  1041. }
  1042. }
  1043. void drawCylinder(const void* _from, const void* _to, float _radius, bool _capsule)
  1044. {
  1045. drawCylinder( (const float*)_from, (const float*)_to, _radius, _capsule);
  1046. }
  1047. void drawAxis(float _x, float _y, float _z, float _len, Axis::Enum _highlight, float _thickness)
  1048. {
  1049. push();
  1050. if (_thickness > 0.0f)
  1051. {
  1052. float from[3] = { _x, _y, _z };
  1053. float mid[3];
  1054. float to[3];
  1055. setColor(Axis::X == _highlight ? 0xff00ffff : 0xff0000ff);
  1056. mid[0] = _x + _len - _thickness;
  1057. mid[1] = _y;
  1058. mid[2] = _z;
  1059. to[0] = _x + _len;
  1060. to[1] = _y;
  1061. to[2] = _z;
  1062. drawCylinder(from, mid, _thickness, false);
  1063. drawCone(mid, to, _thickness);
  1064. setColor(Axis::Y == _highlight ? 0xff00ffff : 0xff00ff00);
  1065. mid[0] = _x;
  1066. mid[1] = _y + _len - _thickness;
  1067. mid[2] = _z;
  1068. to[0] = _x;
  1069. to[1] = _y + _len;
  1070. to[2] = _z;
  1071. drawCylinder(from, mid, _thickness, false);
  1072. drawCone(mid, to, _thickness);
  1073. setColor(Axis::Z == _highlight ? 0xff00ffff : 0xffff0000);
  1074. mid[0] = _x;
  1075. mid[1] = _y;
  1076. mid[2] = _z + _len - _thickness;
  1077. to[0] = _x;
  1078. to[1] = _y;
  1079. to[2] = _z + _len;
  1080. drawCylinder(from, mid, _thickness, false);
  1081. drawCone(mid, to, _thickness);
  1082. }
  1083. else
  1084. {
  1085. setColor(Axis::X == _highlight ? 0xff00ffff : 0xff0000ff);
  1086. moveTo(_x, _y, _z);
  1087. lineTo(_x + _len, _y, _z);
  1088. setColor(Axis::Y == _highlight ? 0xff00ffff : 0xff00ff00);
  1089. moveTo(_x, _y, _z);
  1090. lineTo(_x, _y + _len, _z);
  1091. setColor(Axis::Z == _highlight ? 0xff00ffff : 0xffff0000);
  1092. moveTo(_x, _y, _z);
  1093. lineTo(_x, _y, _z + _len);
  1094. }
  1095. pop();
  1096. }
  1097. void drawGrid(const float* _normal, const float* _center, uint32_t _size, float _step)
  1098. {
  1099. float udir[3];
  1100. float vdir[3];
  1101. Plane plane = { { _normal[0], _normal[1], _normal[2] }, 0.0f };
  1102. calcPlaneUv(plane, udir, vdir);
  1103. bx::vec3Mul(udir, udir, _step);
  1104. bx::vec3Mul(vdir, vdir, _step);
  1105. const uint32_t num = (_size/2)*2+1;
  1106. const float halfExtent = float(_size/2);
  1107. float umin[3];
  1108. bx::vec3Mul(umin, udir, -halfExtent);
  1109. float umax[3];
  1110. bx::vec3Mul(umax, udir, halfExtent);
  1111. float vmin[3];
  1112. bx::vec3Mul(vmin, vdir, -halfExtent);
  1113. float vmax[3];
  1114. bx::vec3Mul(vmax, vdir, halfExtent);
  1115. float tmp[3];
  1116. float xs[3];
  1117. float xe[3];
  1118. bx::vec3Add(tmp, umin, vmin);
  1119. bx::vec3Add(xs, _center, tmp);
  1120. bx::vec3Add(tmp, umax, vmin);
  1121. bx::vec3Add(xe, _center, tmp);
  1122. float ys[3];
  1123. float ye[3];
  1124. bx::vec3Add(tmp, umin, vmin);
  1125. bx::vec3Add(ys, _center, tmp);
  1126. bx::vec3Add(tmp, umin, vmax);
  1127. bx::vec3Add(ye, _center, tmp);
  1128. for (uint32_t ii = 0; ii < num; ++ii)
  1129. {
  1130. moveTo(xs);
  1131. lineTo(xe);
  1132. bx::vec3Add(xs, xs, vdir);
  1133. bx::vec3Add(xe, xe, vdir);
  1134. moveTo(ys);
  1135. lineTo(ye);
  1136. bx::vec3Add(ys, ys, udir);
  1137. bx::vec3Add(ye, ye, udir);
  1138. }
  1139. }
  1140. void drawGrid(const void* _normal, const void* _center, uint32_t _size, float _step)
  1141. {
  1142. drawGrid( (const float*)_normal, (const float*)_center, _size, _step);
  1143. }
  1144. void drawGrid(Axis::Enum _axis, const float* _center, uint32_t _size, float _step)
  1145. {
  1146. push();
  1147. setTranslate(_center);
  1148. const uint32_t num = (_size/2)*2-1;
  1149. const float halfExtent = float(_size/2) * _step;
  1150. setColor(0xff606060);
  1151. float yy = -halfExtent + _step;
  1152. for (uint32_t ii = 0; ii < num; ++ii)
  1153. {
  1154. moveTo(_axis, -halfExtent, yy);
  1155. lineTo(_axis, halfExtent, yy);
  1156. moveTo(_axis, yy, -halfExtent);
  1157. lineTo(_axis, yy, halfExtent);
  1158. yy += _step;
  1159. }
  1160. setColor(0xff101010);
  1161. moveTo(_axis, -halfExtent, -halfExtent);
  1162. lineTo(_axis, -halfExtent, halfExtent);
  1163. lineTo(_axis, halfExtent, halfExtent);
  1164. lineTo(_axis, halfExtent, -halfExtent);
  1165. close();
  1166. moveTo(_axis, -halfExtent, 0.0f);
  1167. lineTo(_axis, halfExtent, 0.0f);
  1168. moveTo(_axis, 0.0f, -halfExtent);
  1169. lineTo(_axis, 0.0f, halfExtent);
  1170. pop();
  1171. }
  1172. void drawGrid(Axis::Enum _axis, const void* _center, uint32_t _size, float _step)
  1173. {
  1174. drawGrid(_axis, (const float*)_center, _size, _step);
  1175. }
  1176. void drawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _hightlight)
  1177. {
  1178. push();
  1179. setColor(Axis::X == _hightlight ? 0xff00ffff : 0xff0000ff);
  1180. drawCircle(Axis::X, _x, _y, _z, _radius, 0.0f);
  1181. setColor(Axis::Y == _hightlight ? 0xff00ffff : 0xff00ff00);
  1182. drawCircle(Axis::Y, _x, _y, _z, _radius, 0.0f);
  1183. setColor(Axis::Z == _hightlight ? 0xff00ffff : 0xffff0000);
  1184. drawCircle(Axis::Z, _x, _y, _z, _radius, 0.0f);
  1185. pop();
  1186. }
  1187. private:
  1188. struct Mesh
  1189. {
  1190. enum Enum
  1191. {
  1192. Sphere0,
  1193. Sphere1,
  1194. Sphere2,
  1195. Sphere3,
  1196. Cone0,
  1197. Cone1,
  1198. Cone2,
  1199. Cone3,
  1200. Cylinder0,
  1201. Cylinder1,
  1202. Cylinder2,
  1203. Cylinder3,
  1204. Capsule0,
  1205. Capsule1,
  1206. Capsule2,
  1207. Capsule3,
  1208. Cube,
  1209. Count,
  1210. SphereMaxLod = Sphere3 - Sphere0,
  1211. ConeMaxLod = Cone3 - Cone0,
  1212. CylinderMaxLod = Cylinder3 - Cylinder0,
  1213. CapsuleMaxLod = Capsule3 - Capsule0,
  1214. };
  1215. uint32_t m_startVertex;
  1216. uint32_t m_numVertices;
  1217. uint32_t m_startIndex[2];
  1218. uint32_t m_numIndices[2];
  1219. };
  1220. struct Program
  1221. {
  1222. enum Enum
  1223. {
  1224. Lines,
  1225. LinesStipple,
  1226. Fill,
  1227. FillLit,
  1228. Count
  1229. };
  1230. };
  1231. void draw(Mesh::Enum _mesh, const float* _mtx, uint16_t _num, bool _wireframe) const
  1232. {
  1233. const Mesh& mesh = m_mesh[_mesh];
  1234. const Attrib& attrib = m_attrib[m_stack];
  1235. if (0 != mesh.m_numIndices[_wireframe])
  1236. {
  1237. bgfx::setIndexBuffer(m_ibh
  1238. , mesh.m_startIndex[_wireframe]
  1239. , mesh.m_numIndices[_wireframe]
  1240. );
  1241. }
  1242. const float flip = 0 == (attrib.m_state & BGFX_STATE_CULL_CCW) ? 1.0f : -1.0f;
  1243. const uint8_t alpha = attrib.m_abgr>>24;
  1244. float params[4][4] =
  1245. {
  1246. { // lightDir
  1247. 0.0f * flip,
  1248. -1.0f * flip,
  1249. 0.0f * flip,
  1250. 3.0f, // shininess
  1251. },
  1252. { // skyColor
  1253. 1.0f,
  1254. 0.9f,
  1255. 0.8f,
  1256. 0.0f, // unused
  1257. },
  1258. { // groundColor.xyz0
  1259. 0.2f,
  1260. 0.22f,
  1261. 0.5f,
  1262. 0.0f, // unused
  1263. },
  1264. { // matColor
  1265. ( (attrib.m_abgr )&0xff)/255.0f,
  1266. ( (attrib.m_abgr>> 8)&0xff)/255.0f,
  1267. ( (attrib.m_abgr>>16)&0xff)/255.0f,
  1268. ( alpha )/255.0f,
  1269. },
  1270. };
  1271. bx::vec3Norm(params[0], params[0]);
  1272. bgfx::setUniform(u_params, params, 4);
  1273. bgfx::setTransform(_mtx, _num);
  1274. bgfx::setVertexBuffer(m_vbh, mesh.m_startVertex, mesh.m_numVertices);
  1275. bgfx::setState(0
  1276. | attrib.m_state
  1277. | (_wireframe ? BGFX_STATE_PT_LINES|BGFX_STATE_LINEAA|BGFX_STATE_BLEND_ALPHA
  1278. : (alpha < 0xff) ? BGFX_STATE_BLEND_ALPHA : 0)
  1279. );
  1280. bgfx::submit(m_viewId, m_program[_wireframe ? Program::Fill : Program::FillLit]);
  1281. }
  1282. void softFlush()
  1283. {
  1284. if (m_pos == uint16_t(BX_COUNTOF(m_cache) ) )
  1285. {
  1286. flush();
  1287. }
  1288. }
  1289. void flush()
  1290. {
  1291. if (0 != m_pos)
  1292. {
  1293. if (bgfx::checkAvailTransientBuffers(m_pos, DebugVertex::ms_decl, m_indexPos) )
  1294. {
  1295. bgfx::TransientVertexBuffer tvb;
  1296. bgfx::allocTransientVertexBuffer(&tvb, m_pos, DebugVertex::ms_decl);
  1297. memcpy(tvb.data, m_cache, m_pos * DebugVertex::ms_decl.m_stride);
  1298. bgfx::TransientIndexBuffer tib;
  1299. bgfx::allocTransientIndexBuffer(&tib, m_indexPos);
  1300. memcpy(tib.data, m_indices, m_indexPos * sizeof(uint16_t) );
  1301. const Attrib& attrib = m_attrib[m_stack];
  1302. bgfx::setVertexBuffer(&tvb);
  1303. bgfx::setIndexBuffer(&tib);
  1304. bgfx::setState(0
  1305. | BGFX_STATE_RGB_WRITE
  1306. | BGFX_STATE_PT_LINES
  1307. | attrib.m_state
  1308. | BGFX_STATE_LINEAA
  1309. | BGFX_STATE_BLEND_ALPHA
  1310. );
  1311. bgfx::setTransform(m_mtx);
  1312. bgfx::ProgramHandle program = m_program[attrib.m_stipple ? 1 : 0];
  1313. bgfx::submit(m_viewId, program);
  1314. }
  1315. m_state = State::None;
  1316. m_pos = 0;
  1317. m_indexPos = 0;
  1318. m_vertexPos = 0;
  1319. }
  1320. }
  1321. struct State
  1322. {
  1323. enum Enum
  1324. {
  1325. None,
  1326. MoveTo,
  1327. LineTo,
  1328. Count
  1329. };
  1330. };
  1331. static const uint32_t cacheSize = 1024;
  1332. static const uint32_t stackSize = 16;
  1333. BX_STATIC_ASSERT(cacheSize >= 3, "Cache must be at least 3 elements.");
  1334. DebugVertex m_cache[cacheSize+1];
  1335. uint32_t m_mtx;
  1336. uint16_t m_indices[cacheSize*2];
  1337. uint16_t m_pos;
  1338. uint16_t m_indexPos;
  1339. uint16_t m_vertexPos;
  1340. uint8_t m_viewId;
  1341. uint8_t m_stack;
  1342. bool m_depthTestLess;
  1343. struct Attrib
  1344. {
  1345. uint64_t m_state;
  1346. float m_offset;
  1347. float m_scale;
  1348. uint32_t m_abgr;
  1349. bool m_stipple;
  1350. bool m_wireframe;
  1351. uint8_t m_lod;
  1352. };
  1353. Attrib m_attrib[stackSize];
  1354. State::Enum m_state;
  1355. Mesh m_mesh[Mesh::Count];
  1356. bgfx::ProgramHandle m_program[Program::Count];
  1357. bgfx::UniformHandle u_params;
  1358. bgfx::VertexBufferHandle m_vbh;
  1359. bgfx::IndexBufferHandle m_ibh;
  1360. bx::AllocatorI* m_allocator;
  1361. };
  1362. static DebugDraw s_dd;
  1363. void ddInit(bool _depthTestLess, bx::AllocatorI* _allocator)
  1364. {
  1365. s_dd.init(_depthTestLess, _allocator);
  1366. }
  1367. void ddShutdown()
  1368. {
  1369. s_dd.shutdown();
  1370. }
  1371. void ddBegin(uint8_t _viewId)
  1372. {
  1373. s_dd.begin(_viewId);
  1374. }
  1375. void ddEnd()
  1376. {
  1377. s_dd.end();
  1378. }
  1379. void ddPush()
  1380. {
  1381. s_dd.push();
  1382. }
  1383. void ddPop()
  1384. {
  1385. s_dd.pop();
  1386. }
  1387. void ddSetState(bool _depthTest, bool _depthWrite, bool _clockwise)
  1388. {
  1389. s_dd.setState(_depthTest, _depthWrite, _clockwise);
  1390. }
  1391. void ddSetColor(uint32_t _abgr)
  1392. {
  1393. s_dd.setColor(_abgr);
  1394. }
  1395. void ddSetLod(uint8_t _lod)
  1396. {
  1397. s_dd.setLod(_lod);
  1398. }
  1399. void ddSetWireframe(bool _wireframe)
  1400. {
  1401. s_dd.setWireframe(_wireframe);
  1402. }
  1403. void ddSetStipple(bool _stipple, float _scale, float _offset)
  1404. {
  1405. s_dd.setStipple(_stipple, _scale, _offset);
  1406. }
  1407. void ddSetTransform(const void* _mtx)
  1408. {
  1409. s_dd.setTransform(_mtx);
  1410. }
  1411. void ddSetTranslate(float _x, float _y, float _z)
  1412. {
  1413. s_dd.setTranslate(_x, _y, _z);
  1414. }
  1415. void ddMoveTo(float _x, float _y, float _z)
  1416. {
  1417. s_dd.moveTo(_x, _y, _z);
  1418. }
  1419. void ddMoveTo(const void* _pos)
  1420. {
  1421. s_dd.moveTo(_pos);
  1422. }
  1423. void ddLineTo(float _x, float _y, float _z)
  1424. {
  1425. s_dd.lineTo(_x, _y, _z);
  1426. }
  1427. void ddLineTo(const void* _pos)
  1428. {
  1429. s_dd.lineTo(_pos);
  1430. }
  1431. void ddClose()
  1432. {
  1433. s_dd.close();
  1434. }
  1435. void ddDraw(const Aabb& _aabb)
  1436. {
  1437. s_dd.draw(_aabb);
  1438. }
  1439. void ddDraw(const Cylinder& _cylinder, bool _capsule)
  1440. {
  1441. s_dd.draw(_cylinder, _capsule);
  1442. }
  1443. void ddDraw(const Disk& _disk)
  1444. {
  1445. s_dd.draw(_disk);
  1446. }
  1447. void ddDraw(const Obb& _obb)
  1448. {
  1449. s_dd.draw(_obb);
  1450. }
  1451. void ddDraw(const Sphere& _sphere)
  1452. {
  1453. s_dd.draw(_sphere);
  1454. }
  1455. void ddDrawFrustum(const void* _viewProj)
  1456. {
  1457. s_dd.drawFrustum(_viewProj);
  1458. }
  1459. void ddDrawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees)
  1460. {
  1461. s_dd.drawArc(_axis, _x, _y, _z, _radius, _degrees);
  1462. }
  1463. void ddDrawCircle(const void* _normal, const void* _center, float _radius, float _weight)
  1464. {
  1465. s_dd.drawCircle(_normal, _center, _radius, _weight);
  1466. }
  1467. void ddDrawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight)
  1468. {
  1469. s_dd.drawCircle(_axis, _x, _y, _z, _radius, _weight);
  1470. }
  1471. void ddDrawCone(const void* _from, const void* _to, float _radius)
  1472. {
  1473. s_dd.drawCone(_from, _to, _radius);
  1474. }
  1475. void ddDrawCylinder(const void* _from, const void* _to, float _radius, bool _capsule)
  1476. {
  1477. if (_capsule)
  1478. {
  1479. s_dd.push();
  1480. s_dd.setLod(0);
  1481. s_dd.drawCylinder(_from, _to, _radius, true);
  1482. s_dd.pop();
  1483. }
  1484. else
  1485. {
  1486. s_dd.drawCylinder(_from, _to, _radius, false);
  1487. }
  1488. }
  1489. void ddDrawCapsule(const void* _from, const void* _to, float _radius)
  1490. {
  1491. s_dd.drawCylinder(_from, _to, _radius, true);
  1492. }
  1493. void ddDrawAxis(float _x, float _y, float _z, float _len, Axis::Enum _hightlight, float _thickness)
  1494. {
  1495. s_dd.drawAxis(_x, _y, _z, _len, _hightlight, _thickness);
  1496. }
  1497. void ddDrawGrid(const void* _normal, const void* _center, uint32_t _size, float _step)
  1498. {
  1499. s_dd.drawGrid(_normal, _center, _size, _step);
  1500. }
  1501. void ddDrawGrid(Axis::Enum _axis, const void* _center, uint32_t _size, float _step)
  1502. {
  1503. s_dd.drawGrid(_axis, _center, _size, _step);
  1504. }
  1505. void ddDrawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _hightlight)
  1506. {
  1507. s_dd.drawOrb(_x, _y, _z, _radius, _hightlight);
  1508. }