example-glue.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "entry/cmd.h"
  8. #include <bx/string.h>
  9. bool showExampleDialog(entry::AppI* _app)
  10. {
  11. bool restart = false;
  12. char temp[1024];
  13. bx::snprintf(temp, BX_COUNTOF(temp), "Example: %s", _app->getName() );
  14. ImGui::SetNextWindowPos(
  15. ImVec2(10.0f, 50.0f)
  16. , ImGuiSetCond_FirstUseEver
  17. );
  18. ImGui::Begin(temp
  19. , NULL
  20. , ImVec2(256.0f, 200.0f)
  21. , ImGuiWindowFlags_AlwaysAutoResize
  22. );
  23. ImGui::TextWrapped("%s", _app->getDescription() );
  24. ImGui::Separator();
  25. {
  26. uint32_t num = entry::getNumApps();
  27. const char** items = (const char**)alloca(num*sizeof(void*) );
  28. uint32_t ii = 0;
  29. int32_t current = 0;
  30. for (entry::AppI* app = entry::getFirstApp(); NULL != app; app = app->getNext() )
  31. {
  32. if (app == _app)
  33. {
  34. current = ii;
  35. }
  36. items[ii++] = app->getName();
  37. }
  38. if (1 < num
  39. && ImGui::Combo("Example", &current, items, num) )
  40. {
  41. char command[1024];
  42. bx::snprintf(command, BX_COUNTOF(command), "app restart %s", items[current]);
  43. cmdExec(command);
  44. }
  45. }
  46. #if 0
  47. {
  48. bgfx::RendererType::Enum supportedRenderers[bgfx::RendererType::Count];
  49. uint8_t num = bgfx::getSupportedRenderers(BX_COUNTOF(supportedRenderers), supportedRenderers);
  50. const bgfx::Caps* caps = bgfx::getCaps();
  51. const char* items[bgfx::RendererType::Count];
  52. int32_t current = 0;
  53. for (uint8_t ii = 0; ii < num; ++ii)
  54. {
  55. items[ii] = bgfx::getRendererName(supportedRenderers[ii]);
  56. if (supportedRenderers[ii] == caps->rendererType)
  57. {
  58. current = ii;
  59. }
  60. }
  61. if (ImGui::Combo("Renderer", &current, items, num) )
  62. {
  63. restart = true;
  64. }
  65. }
  66. #endif // 0
  67. const bgfx::Stats* stats = bgfx::getStats();
  68. ImGui::Text("CPU %0.3f"
  69. , double(stats->cpuTimeEnd-stats->cpuTimeBegin)/stats->cpuTimerFreq*1000.0
  70. );
  71. ImGui::Text("GPU %0.3f (latency: %d)"
  72. , double(stats->gpuTimeEnd-stats->gpuTimeBegin)/stats->gpuTimerFreq*1000.0
  73. , stats->maxGpuLatency
  74. );
  75. ImGui::End();
  76. return restart;
  77. }