shadowmaps_simple.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * Copyright 2013 Dario Manesku. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #include <string>
  6. #include <vector>
  7. #include <algorithm>
  8. #include "common.h"
  9. #include <bgfx.h>
  10. #include <bx/timer.h>
  11. #include <bx/readerwriter.h>
  12. #include "entry/entry.h"
  13. #include "fpumath.h"
  14. #define RENDER_PASS_0 0
  15. #define RENDER_PASS_1 1
  16. uint32_t packUint32(uint8_t _x, uint8_t _y, uint8_t _z, uint8_t _w)
  17. {
  18. union
  19. {
  20. uint32_t ui32;
  21. uint8_t arr[4];
  22. } un;
  23. un.arr[0] = _x;
  24. un.arr[1] = _y;
  25. un.arr[2] = _z;
  26. un.arr[3] = _w;
  27. return un.ui32;
  28. }
  29. uint32_t packF4u(float _x, float _y = 0.0f, float _z = 0.0f, float _w = 0.0f)
  30. {
  31. const uint8_t xx = uint8_t(_x*127.0f + 128.0f);
  32. const uint8_t yy = uint8_t(_y*127.0f + 128.0f);
  33. const uint8_t zz = uint8_t(_z*127.0f + 128.0f);
  34. const uint8_t ww = uint8_t(_w*127.0f + 128.0f);
  35. return packUint32(xx, yy, zz, ww);
  36. }
  37. struct PosNormalVertex
  38. {
  39. float m_x;
  40. float m_y;
  41. float m_z;
  42. uint32_t m_normal;
  43. };
  44. static const float s_texcoord = 5.0f;
  45. static const uint32_t s_numHPlaneVertices = 4;
  46. static PosNormalVertex s_hplaneVertices[s_numHPlaneVertices] =
  47. {
  48. { -1.0f, 0.0f, 1.0f, packF4u(0.0f, 1.0f, 0.0f) },
  49. { 1.0f, 0.0f, 1.0f, packF4u(0.0f, 1.0f, 0.0f) },
  50. { -1.0f, 0.0f, -1.0f, packF4u(0.0f, 1.0f, 0.0f) },
  51. { 1.0f, 0.0f, -1.0f, packF4u(0.0f, 1.0f, 0.0f) },
  52. };
  53. static const uint32_t s_numPlaneIndices = 6;
  54. static const uint16_t s_planeIndices[s_numPlaneIndices] =
  55. {
  56. 0, 1, 2,
  57. 1, 3, 2,
  58. };
  59. static const char* s_shaderPath = NULL;
  60. static bool s_flipV = false;
  61. static float s_texelHalf = 0.0f;
  62. static bgfx::RenderTargetHandle s_rtShadowMap;
  63. static bgfx::UniformHandle u_shadowMap;
  64. static void shaderFilePath(char* _out, const char* _name)
  65. {
  66. strcpy(_out, s_shaderPath);
  67. strcat(_out, _name);
  68. strcat(_out, ".bin");
  69. }
  70. long int fsize(FILE* _file)
  71. {
  72. long int pos = ftell(_file);
  73. fseek(_file, 0L, SEEK_END);
  74. long int size = ftell(_file);
  75. fseek(_file, pos, SEEK_SET);
  76. return size;
  77. }
  78. static const bgfx::Memory* load(const char* _filePath)
  79. {
  80. FILE* file = fopen(_filePath, "rb");
  81. if (NULL != file)
  82. {
  83. uint32_t size = (uint32_t)fsize(file);
  84. const bgfx::Memory* mem = bgfx::alloc(size+1);
  85. size_t ignore = fread(mem->data, 1, size, file);
  86. BX_UNUSED(ignore);
  87. fclose(file);
  88. mem->data[mem->size-1] = '\0';
  89. return mem;
  90. }
  91. return NULL;
  92. }
  93. static const bgfx::Memory* loadShader(const char* _name)
  94. {
  95. char filePath[512];
  96. shaderFilePath(filePath, _name);
  97. return load(filePath);
  98. }
  99. static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
  100. {
  101. const bgfx::Memory* mem;
  102. // Load vertex shader.
  103. mem = loadShader(_vsName);
  104. bgfx::VertexShaderHandle vsh = bgfx::createVertexShader(mem);
  105. // Load fragment shader.
  106. mem = loadShader(_fsName);
  107. bgfx::FragmentShaderHandle fsh = bgfx::createFragmentShader(mem);
  108. // Create program from shaders.
  109. bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh);
  110. // We can destroy vertex and fragment shader here since
  111. // their reference is kept inside bgfx after calling createProgram.
  112. // Vertex and fragment shader will be destroyed once program is
  113. // destroyed.
  114. bgfx::destroyVertexShader(vsh);
  115. bgfx::destroyFragmentShader(fsh);
  116. return program;
  117. }
  118. void mtxScaleRotateTranslate(float* _result
  119. , const float _scaleX
  120. , const float _scaleY
  121. , const float _scaleZ
  122. , const float _rotX
  123. , const float _rotY
  124. , const float _rotZ
  125. , const float _translateX
  126. , const float _translateY
  127. , const float _translateZ
  128. )
  129. {
  130. float mtxRotateTranslate[16];
  131. float mtxScale[16];
  132. mtxRotateXYZ(mtxRotateTranslate, _rotX, _rotY, _rotZ);
  133. mtxRotateTranslate[12] = _translateX;
  134. mtxRotateTranslate[13] = _translateY;
  135. mtxRotateTranslate[14] = _translateZ;
  136. memset(mtxScale, 0, sizeof(float)*16);
  137. mtxScale[0] = _scaleX;
  138. mtxScale[5] = _scaleY;
  139. mtxScale[10] = _scaleZ;
  140. mtxScale[15] = 1.0f;
  141. mtxMul(_result, mtxScale, mtxRotateTranslate);
  142. }
  143. struct Aabb
  144. {
  145. float m_min[3];
  146. float m_max[3];
  147. };
  148. struct Obb
  149. {
  150. float m_mtx[16];
  151. };
  152. struct Sphere
  153. {
  154. float m_center[3];
  155. float m_radius;
  156. };
  157. struct Primitive
  158. {
  159. uint32_t m_startIndex;
  160. uint32_t m_numIndices;
  161. uint32_t m_startVertex;
  162. uint32_t m_numVertices;
  163. Sphere m_sphere;
  164. Aabb m_aabb;
  165. Obb m_obb;
  166. };
  167. typedef std::vector<Primitive> PrimitiveArray;
  168. struct Group
  169. {
  170. Group()
  171. {
  172. reset();
  173. }
  174. void reset()
  175. {
  176. m_vbh.idx = bgfx::invalidHandle;
  177. m_ibh.idx = bgfx::invalidHandle;
  178. m_prims.clear();
  179. }
  180. bgfx::VertexBufferHandle m_vbh;
  181. bgfx::IndexBufferHandle m_ibh;
  182. Sphere m_sphere;
  183. Aabb m_aabb;
  184. Obb m_obb;
  185. PrimitiveArray m_prims;
  186. };
  187. ;
  188. struct Mesh
  189. {
  190. void load(const void* _vertices, uint32_t _numVertices, const bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices)
  191. {
  192. Group group;
  193. const bgfx::Memory* mem;
  194. uint32_t size;
  195. size = _numVertices*_decl.getStride();
  196. mem = bgfx::makeRef(_vertices, size);
  197. group.m_vbh = bgfx::createVertexBuffer(mem, _decl);
  198. size = _numIndices*2;
  199. mem = bgfx::makeRef(_indices, size);
  200. group.m_ibh = bgfx::createIndexBuffer(mem);
  201. //TODO:
  202. // group.m_sphere = ...
  203. // group.m_aabb = ...
  204. // group.m_obb = ...
  205. // group.m_prims = ...
  206. m_groups.push_back(group);
  207. }
  208. void load(const char* _filePath)
  209. {
  210. #define BGFX_CHUNK_MAGIC_VB BX_MAKEFOURCC('V', 'B', ' ', 0x0)
  211. #define BGFX_CHUNK_MAGIC_IB BX_MAKEFOURCC('I', 'B', ' ', 0x0)
  212. #define BGFX_CHUNK_MAGIC_PRI BX_MAKEFOURCC('P', 'R', 'I', 0x0)
  213. bx::CrtFileReader reader;
  214. reader.open(_filePath);
  215. Group group;
  216. uint32_t chunk;
  217. while (4 == bx::read(&reader, chunk) )
  218. {
  219. switch (chunk)
  220. {
  221. case BGFX_CHUNK_MAGIC_VB:
  222. {
  223. bx::read(&reader, group.m_sphere);
  224. bx::read(&reader, group.m_aabb);
  225. bx::read(&reader, group.m_obb);
  226. bx::read(&reader, m_decl);
  227. uint16_t stride = m_decl.getStride();
  228. uint16_t numVertices;
  229. bx::read(&reader, numVertices);
  230. const bgfx::Memory* mem = bgfx::alloc(numVertices*stride);
  231. bx::read(&reader, mem->data, mem->size);
  232. group.m_vbh = bgfx::createVertexBuffer(mem, m_decl);
  233. }
  234. break;
  235. case BGFX_CHUNK_MAGIC_IB:
  236. {
  237. uint32_t numIndices;
  238. bx::read(&reader, numIndices);
  239. const bgfx::Memory* mem = bgfx::alloc(numIndices*2);
  240. bx::read(&reader, mem->data, mem->size);
  241. group.m_ibh = bgfx::createIndexBuffer(mem);
  242. }
  243. break;
  244. case BGFX_CHUNK_MAGIC_PRI:
  245. {
  246. uint16_t len;
  247. bx::read(&reader, len);
  248. std::string material;
  249. material.resize(len);
  250. bx::read(&reader, const_cast<char*>(material.c_str() ), len);
  251. uint16_t num;
  252. bx::read(&reader, num);
  253. for (uint32_t ii = 0; ii < num; ++ii)
  254. {
  255. bx::read(&reader, len);
  256. std::string name;
  257. name.resize(len);
  258. bx::read(&reader, const_cast<char*>(name.c_str() ), len);
  259. Primitive prim;
  260. bx::read(&reader, prim.m_startIndex);
  261. bx::read(&reader, prim.m_numIndices);
  262. bx::read(&reader, prim.m_startVertex);
  263. bx::read(&reader, prim.m_numVertices);
  264. bx::read(&reader, prim.m_sphere);
  265. bx::read(&reader, prim.m_aabb);
  266. bx::read(&reader, prim.m_obb);
  267. group.m_prims.push_back(prim);
  268. }
  269. m_groups.push_back(group);
  270. group.reset();
  271. }
  272. break;
  273. default:
  274. DBG("%08x at %d", chunk, reader.seek() );
  275. break;
  276. }
  277. }
  278. reader.close();
  279. }
  280. void unload()
  281. {
  282. for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
  283. {
  284. const Group& group = *it;
  285. bgfx::destroyVertexBuffer(group.m_vbh);
  286. if (bgfx::isValid(group.m_ibh) )
  287. {
  288. bgfx::destroyIndexBuffer(group.m_ibh);
  289. }
  290. }
  291. m_groups.clear();
  292. }
  293. void submit(uint8_t _view, float* _mtx, bgfx::ProgramHandle _program)
  294. {
  295. for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
  296. {
  297. const Group& group = *it;
  298. // Set model matrix for rendering.
  299. bgfx::setTransform(_mtx);
  300. bgfx::setProgram(_program);
  301. bgfx::setIndexBuffer(group.m_ibh);
  302. bgfx::setVertexBuffer(group.m_vbh);
  303. // Set shadow map.
  304. bgfx::setTexture(4, u_shadowMap, s_rtShadowMap);
  305. // Set render states.
  306. bgfx::setState(0
  307. |BGFX_STATE_RGB_WRITE
  308. |BGFX_STATE_ALPHA_WRITE
  309. |BGFX_STATE_DEPTH_WRITE
  310. |BGFX_STATE_DEPTH_TEST_LESS
  311. |BGFX_STATE_CULL_CCW
  312. |BGFX_STATE_MSAA
  313. );
  314. // Submit primitive for rendering.
  315. bgfx::submit(_view);
  316. }
  317. }
  318. bgfx::VertexDecl m_decl;
  319. typedef std::vector<Group> GroupArray;
  320. GroupArray m_groups;
  321. };
  322. int _main_(int /*_argc*/, char** /*_argv*/)
  323. {
  324. uint32_t width = 1280;
  325. uint32_t height = 720;
  326. uint32_t debug = BGFX_DEBUG_TEXT;
  327. uint32_t reset = BGFX_RESET_VSYNC;
  328. bgfx::init();
  329. bgfx::reset(width, height, reset);
  330. // Enable debug text.
  331. bgfx::setDebug(debug);
  332. // Setup root path for binary shaders. Shader binaries are different
  333. // for each renderer.
  334. switch (bgfx::getRendererType() )
  335. {
  336. default:
  337. case bgfx::RendererType::Direct3D9:
  338. s_shaderPath = "shaders/dx9/";
  339. s_texelHalf = 0.5f;
  340. break;
  341. case bgfx::RendererType::Direct3D11:
  342. s_shaderPath = "shaders/dx11/";
  343. break;
  344. case bgfx::RendererType::OpenGL:
  345. s_shaderPath = "shaders/glsl/";
  346. s_flipV = true;
  347. break;
  348. case bgfx::RendererType::OpenGLES2:
  349. case bgfx::RendererType::OpenGLES3:
  350. s_shaderPath = "shaders/gles/";
  351. s_flipV = true;
  352. break;
  353. }
  354. // Uniforms.
  355. u_shadowMap = bgfx::createUniform("u_shadowMap", bgfx::UniformType::Uniform1iv);
  356. bgfx::UniformHandle u_lightPos = bgfx::createUniform("u_lightPos", bgfx::UniformType::Uniform4fv);
  357. bgfx::UniformHandle u_lightMtx = bgfx::createUniform("u_lightMtx", bgfx::UniformType::Uniform4x4fv);
  358. // Programs.
  359. bgfx::ProgramHandle progPackDepth = loadProgram("vs_smsimple_packdepth", "fs_smsimple_packdepth");
  360. bgfx::ProgramHandle progDraw = loadProgram("vs_smsimple_draw", "fs_smsimple_draw");
  361. // Vertex declarations.
  362. bgfx::VertexDecl PosNormalDecl;
  363. PosNormalDecl.begin();
  364. PosNormalDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
  365. PosNormalDecl.add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
  366. PosNormalDecl.end();
  367. // Meshes.
  368. Mesh bunnyMesh;
  369. Mesh cubeMesh;
  370. Mesh hollowcubeMesh;
  371. Mesh hplaneMesh;
  372. bunnyMesh.load("meshes/bunny.bin");
  373. cubeMesh.load("meshes/cube.bin");
  374. hollowcubeMesh.load("meshes/hollowcube.bin");
  375. hplaneMesh.load(s_hplaneVertices, s_numHPlaneVertices, PosNormalDecl, s_planeIndices, s_numPlaneIndices);
  376. // Render targets.
  377. uint16_t shadowMapSize = 512;
  378. s_rtShadowMap = bgfx::createRenderTarget(shadowMapSize, shadowMapSize, BGFX_RENDER_TARGET_COLOR_RGBA8 | BGFX_RENDER_TARGET_DEPTH_D16);
  379. // Set view and projection matrices.
  380. float view[16];
  381. float proj[16];
  382. const float eye[3] = { 0.0f, 30.0f, -60.0f };
  383. const float at[3] = { 0.0f, 5.0f, 0.0f };
  384. mtxLookAt(view, eye, at);
  385. const float aspect = float(int32_t(width) ) / float(int32_t(height) );
  386. mtxProj(proj, 60.0f, aspect, 0.1f, 1000.0f);
  387. // Time acumulators.
  388. float timeAccumulatorLight = 0.0f;
  389. float timeAccumulatorScene = 0.0f;
  390. entry::MouseState mouseState;
  391. while (!entry::processEvents(width, height, debug, reset, &mouseState) )
  392. {
  393. // Time.
  394. int64_t now = bx::getHPCounter();
  395. static int64_t last = now;
  396. const int64_t frameTime = now - last;
  397. last = now;
  398. const double freq = double(bx::getHPFrequency() );
  399. const double toMs = 1000.0/freq;
  400. const float deltaTime = float(frameTime/freq);
  401. // Update time accumulators.
  402. timeAccumulatorLight += deltaTime;
  403. timeAccumulatorScene += deltaTime;
  404. // Use debug font to print information about this example.
  405. bgfx::dbgTextClear();
  406. bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/15-shadowmaps-simple");
  407. bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Shadow maps example.");
  408. bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
  409. // Setup lights.
  410. float lightPos[4];
  411. lightPos[0] = -cos(timeAccumulatorLight);
  412. lightPos[1] = -1.0f;
  413. lightPos[2] = -sin(timeAccumulatorLight);
  414. lightPos[3] = 0.0f;
  415. bgfx::setUniform(u_lightPos, lightPos);
  416. // Setup instance matrices.
  417. float mtxFloor[16];
  418. mtxScaleRotateTranslate(mtxFloor
  419. , 30.0f //scaleX
  420. , 30.0f //scaleY
  421. , 30.0f //scaleZ
  422. , 0.0f //rotX
  423. , 0.0f //rotY
  424. , 0.0f //rotZ
  425. , 0.0f //translateX
  426. , 0.0f //translateY
  427. , 0.0f //translateZ
  428. );
  429. float mtxBunny[16];
  430. mtxScaleRotateTranslate(mtxBunny
  431. , 5.0f
  432. , 5.0f
  433. , 5.0f
  434. , 0.0f
  435. , float(M_PI) - timeAccumulatorScene
  436. , 0.0f
  437. , 15.0f
  438. , 5.0f
  439. , 0.0f
  440. );
  441. float mtxHollowcube[16];
  442. mtxScaleRotateTranslate(mtxHollowcube
  443. , 2.5f
  444. , 2.5f
  445. , 2.5f
  446. , 0.0f
  447. , 1.56f - timeAccumulatorScene
  448. , 0.0f
  449. , 0.0f
  450. , 10.0f
  451. , 0.0f
  452. );
  453. float mtxCube[16];
  454. mtxScaleRotateTranslate(mtxCube
  455. , 2.5f
  456. , 2.5f
  457. , 2.5f
  458. , 0.0f
  459. , 1.56f - timeAccumulatorScene
  460. , 0.0f
  461. , -15.0f
  462. , 5.0f
  463. , 0.0f
  464. );
  465. // Define matrices.
  466. float screenView[16];
  467. float screenProj[16];
  468. mtxIdentity(screenView);
  469. mtxOrtho(screenProj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f);
  470. float lightView[16];
  471. float lightProj[16];
  472. const float eye[3] =
  473. {
  474. -lightPos[0],
  475. -lightPos[1],
  476. -lightPos[2],
  477. };
  478. const float at[3] = { 0.0f, 0.0f, 0.0f };
  479. mtxLookAt(lightView, eye, at);
  480. const float area = 30.0f;
  481. mtxOrtho(lightProj, -area, area, -area, area, -100.0f, 100.0f);
  482. /**
  483. * RENDER_PASS_0 - Craft shadow map.
  484. * RENDER_PASS_1 - Draw scene.
  485. */
  486. bgfx::setViewRect(RENDER_PASS_0, 0, 0, shadowMapSize, shadowMapSize);
  487. bgfx::setViewRect(RENDER_PASS_1, 0, 0, width, height);
  488. bgfx::setViewTransform(RENDER_PASS_0, lightView, lightProj);
  489. bgfx::setViewTransform(RENDER_PASS_1, view, proj);
  490. bgfx::setViewRenderTarget(RENDER_PASS_0, s_rtShadowMap);
  491. // Clear backbuffer and shadowmap rendertarget at beginning.
  492. bgfx::setViewClearMask(0x3, BGFX_CLEAR_COLOR_BIT | BGFX_CLEAR_DEPTH_BIT, 0x303030ff, 1.0f, 0);
  493. bgfx::submitMask(0x3);
  494. // Render.
  495. { // Craft shadow map.
  496. hplaneMesh.submit(RENDER_PASS_0, mtxFloor, progPackDepth);
  497. bunnyMesh.submit(RENDER_PASS_0, mtxBunny, progPackDepth);
  498. hollowcubeMesh.submit(RENDER_PASS_0, mtxHollowcube, progPackDepth);
  499. cubeMesh.submit(RENDER_PASS_0, mtxCube, progPackDepth);
  500. }
  501. { // Draw Scene.
  502. float mtxShadow[16]; //lightviewProjCrop
  503. float lightMtx[16]; //modelLightviewProjCrop
  504. const float s = (s_flipV) ? 1.0f : -1.0f; //sign
  505. const float mtxCrop[16] =
  506. {
  507. 0.5f, 0.0f, 0.0f, 0.0f,
  508. 0.0f, s*0.5f, 0.0f, 0.0f,
  509. 0.0f, 0.0f, 0.5f, 0.0f,
  510. 0.5f, 0.5f, 0.5f, 1.0f,
  511. };
  512. float mtxTmp[16];
  513. mtxMul(mtxTmp, lightProj, mtxCrop);
  514. mtxMul(mtxShadow, lightView, mtxTmp);
  515. // Floor.
  516. mtxMul(lightMtx, mtxFloor, mtxShadow);
  517. bgfx::setUniform(u_lightMtx, lightMtx);
  518. hplaneMesh.submit(RENDER_PASS_1, mtxFloor, progDraw);
  519. // Bunny.
  520. mtxMul(lightMtx, mtxBunny, mtxShadow);
  521. bgfx::setUniform(u_lightMtx, lightMtx);
  522. bunnyMesh.submit(RENDER_PASS_1, mtxBunny, progDraw);
  523. // Hollow cube.
  524. mtxMul(lightMtx, mtxHollowcube, mtxShadow);
  525. bgfx::setUniform(u_lightMtx, lightMtx);
  526. hollowcubeMesh.submit(RENDER_PASS_1, mtxHollowcube, progDraw);
  527. // Cube.
  528. mtxMul(lightMtx, mtxCube, mtxShadow);
  529. bgfx::setUniform(u_lightMtx, lightMtx);
  530. cubeMesh.submit(RENDER_PASS_1, mtxCube, progDraw);
  531. }
  532. // Advance to next frame. Rendering thread will be kicked to
  533. // process submitted rendering primitives.
  534. bgfx::frame();
  535. }
  536. bunnyMesh.unload();
  537. cubeMesh.unload();
  538. hollowcubeMesh.unload();
  539. hplaneMesh.unload();
  540. bgfx::destroyProgram(progPackDepth);
  541. bgfx::destroyProgram(progDraw);
  542. bgfx::destroyRenderTarget(s_rtShadowMap);
  543. bgfx::destroyUniform(u_shadowMap);
  544. bgfx::destroyUniform(u_lightPos);
  545. bgfx::destroyUniform(u_lightMtx);
  546. // Shutdown bgfx.
  547. bgfx::shutdown();
  548. return 0;
  549. }