example-glue.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. void showExampleDialog(entry::AppI* _app)
  10. {
  11. char temp[1024];
  12. bx::snprintf(temp, BX_COUNTOF(temp), "Example: %s", _app->getName() );
  13. ImGui::SetNextWindowPos(
  14. ImVec2(10.0f, 50.0f)
  15. , ImGuiSetCond_FirstUseEver
  16. );
  17. ImGui::Begin(temp
  18. , NULL
  19. , ImVec2(256.0f, 200.0f)
  20. , ImGuiWindowFlags_AlwaysAutoResize
  21. );
  22. ImGui::TextWrapped("%s", _app->getDescription() );
  23. ImGui::Separator();
  24. {
  25. uint32_t num = entry::getNumApps();
  26. const char** items = (const char**)alloca(num*sizeof(void*) );
  27. uint32_t ii = 0;
  28. int32_t current = 0;
  29. for (entry::AppI* app = entry::getFirstApp(); NULL != app; app = app->getNext() )
  30. {
  31. if (app == _app)
  32. {
  33. current = ii;
  34. }
  35. items[ii++] = app->getName();
  36. }
  37. if (1 < num
  38. && ImGui::Combo("Example", &current, items, num) )
  39. {
  40. char command[1024];
  41. bx::snprintf(command, BX_COUNTOF(command), "app restart %s", items[current]);
  42. cmdExec(command);
  43. }
  44. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(3.0f, 3.0f) );
  45. if (ImGui::Button(ICON_FA_REPEAT " Restart" ) )
  46. {
  47. cmdExec("app restart");
  48. }
  49. ImGui::SameLine();
  50. if (ImGui::Button(ICON_KI_PREVIOUS " Prev") )
  51. {
  52. cmdExec("app restart prev");
  53. }
  54. ImGui::SameLine();
  55. if (ImGui::Button(ICON_KI_NEXT " Next") )
  56. {
  57. cmdExec("app restart next");
  58. }
  59. ImGui::SameLine();
  60. if (ImGui::Button(ICON_KI_EXIT " Exit") )
  61. {
  62. cmdExec("exit");
  63. }
  64. ImGui::PopStyleVar();
  65. }
  66. #if 0
  67. {
  68. bgfx::RendererType::Enum supportedRenderers[bgfx::RendererType::Count];
  69. uint8_t num = bgfx::getSupportedRenderers(BX_COUNTOF(supportedRenderers), supportedRenderers);
  70. const bgfx::Caps* caps = bgfx::getCaps();
  71. const char* items[bgfx::RendererType::Count];
  72. int32_t current = 0;
  73. for (uint8_t ii = 0; ii < num; ++ii)
  74. {
  75. items[ii] = bgfx::getRendererName(supportedRenderers[ii]);
  76. if (supportedRenderers[ii] == caps->rendererType)
  77. {
  78. current = ii;
  79. }
  80. }
  81. if (ImGui::Combo("Renderer", &current, items, num) )
  82. {
  83. cmdExec("app restart");
  84. }
  85. }
  86. #endif // 0
  87. const bgfx::Stats* stats = bgfx::getStats();
  88. ImGui::Text("CPU %0.3f"
  89. , double(stats->cpuTimeEnd-stats->cpuTimeBegin)/stats->cpuTimerFreq*1000.0
  90. );
  91. ImGui::Text("GPU %0.3f (latency: %d)"
  92. , double(stats->gpuTimeEnd-stats->gpuTimeBegin)/stats->gpuTimerFreq*1000.0
  93. , stats->maxGpuLatency
  94. );
  95. ImGui::End();
  96. }