example-glue.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 2011-2017 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #include "imgui/imgui.h"
  6. #include "entry/entry.h"
  7. bool showExampleDialog(entry::AppI* _app)
  8. {
  9. bool restart = false;
  10. char temp[1024];
  11. bx::snprintf(temp, BX_COUNTOF(temp), "Example: %s", _app->getName() );
  12. ImGui::Begin(temp
  13. , NULL
  14. , ImVec2(256.0f, 200.0f)
  15. , ImGuiWindowFlags_AlwaysAutoResize
  16. );
  17. ImGui::TextWrapped("%s", _app->getDescription() );
  18. ImGui::Separator();
  19. {
  20. uint32_t num = entry::getNumApps();
  21. const char** items = (const char**)alloca(num*sizeof(void*) );
  22. uint32_t ii = 0;
  23. int32_t current = 0;
  24. for (entry::AppI* app = entry::getFirstApp(); NULL != app; app = app->getNext() )
  25. {
  26. if (app == _app)
  27. {
  28. current = ii;
  29. }
  30. items[ii++] = app->getName();
  31. }
  32. if (1 < num
  33. && ImGui::Combo("Example", &current, items, num) )
  34. {
  35. entry::setRestartArgs(items[current]);
  36. restart = true;
  37. }
  38. }
  39. #if 0
  40. {
  41. bgfx::RendererType::Enum supportedRenderers[bgfx::RendererType::Count];
  42. uint8_t num = bgfx::getSupportedRenderers(BX_COUNTOF(supportedRenderers), supportedRenderers);
  43. const bgfx::Caps* caps = bgfx::getCaps();
  44. const char* items[bgfx::RendererType::Count];
  45. int32_t current = 0;
  46. for (uint8_t ii = 0; ii < num; ++ii)
  47. {
  48. items[ii] = bgfx::getRendererName(supportedRenderers[ii]);
  49. if (supportedRenderers[ii] == caps->rendererType)
  50. {
  51. current = ii;
  52. }
  53. }
  54. if (ImGui::Combo("Renderer", &current, items, num) )
  55. {
  56. restart = true;
  57. }
  58. }
  59. #endif // 0
  60. const bgfx::Stats* stats = bgfx::getStats();
  61. ImGui::Text("CPU %0.3f"
  62. , double(stats->cpuTimeEnd-stats->cpuTimeBegin)/stats->cpuTimerFreq*1000.0
  63. );
  64. ImGui::Text("GPU %0.3f (latency: %d)"
  65. , double(stats->gpuTimeEnd-stats->gpuTimeBegin)/stats->gpuTimerFreq*1000.0
  66. , stats->maxGpuLatency
  67. );
  68. ImGui::End();
  69. return restart;
  70. }