example-glue.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #include <bx/timer.h>
  10. void showExampleDialog(entry::AppI* _app, const char* _errorText)
  11. {
  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. if (NULL != _errorText)
  26. {
  27. const int64_t now = bx::getHPCounter();
  28. const int64_t freq = bx::getHPFrequency();
  29. const float time = float(now%freq)/float(freq);
  30. bool blink = time > 0.5f;
  31. ImGui::PushStyleColor(ImGuiCol_Text
  32. , blink
  33. ? ImVec4(1.0, 0.0, 0.0, 1.0)
  34. : ImVec4(1.0, 1.0, 1.0, 1.0)
  35. );
  36. ImGui::TextWrapped("%s", _errorText);
  37. ImGui::Separator();
  38. ImGui::PopStyleColor();
  39. }
  40. {
  41. uint32_t num = entry::getNumApps();
  42. const char** items = (const char**)alloca(num*sizeof(void*) );
  43. uint32_t ii = 0;
  44. int32_t current = 0;
  45. for (entry::AppI* app = entry::getFirstApp(); NULL != app; app = app->getNext() )
  46. {
  47. if (app == _app)
  48. {
  49. current = ii;
  50. }
  51. items[ii++] = app->getName();
  52. }
  53. if (1 < num
  54. && ImGui::Combo("Example", &current, items, num) )
  55. {
  56. char command[1024];
  57. bx::snprintf(command, BX_COUNTOF(command), "app restart %s", items[current]);
  58. cmdExec(command);
  59. }
  60. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(3.0f, 3.0f) );
  61. if (ImGui::Button(ICON_FA_REPEAT " Restart" ) )
  62. {
  63. cmdExec("app restart");
  64. }
  65. ImGui::SameLine();
  66. if (ImGui::Button(ICON_KI_PREVIOUS " Prev") )
  67. {
  68. cmdExec("app restart prev");
  69. }
  70. ImGui::SameLine();
  71. if (ImGui::Button(ICON_KI_NEXT " Next") )
  72. {
  73. cmdExec("app restart next");
  74. }
  75. ImGui::SameLine();
  76. if (ImGui::Button(ICON_KI_EXIT " Exit") )
  77. {
  78. cmdExec("exit");
  79. }
  80. ImGui::PopStyleVar();
  81. }
  82. #if 0
  83. {
  84. bgfx::RendererType::Enum supportedRenderers[bgfx::RendererType::Count];
  85. uint8_t num = bgfx::getSupportedRenderers(BX_COUNTOF(supportedRenderers), supportedRenderers);
  86. const bgfx::Caps* caps = bgfx::getCaps();
  87. const char* items[bgfx::RendererType::Count];
  88. int32_t current = 0;
  89. for (uint8_t ii = 0; ii < num; ++ii)
  90. {
  91. items[ii] = bgfx::getRendererName(supportedRenderers[ii]);
  92. if (supportedRenderers[ii] == caps->rendererType)
  93. {
  94. current = ii;
  95. }
  96. }
  97. if (ImGui::Combo("Renderer", &current, items, num) )
  98. {
  99. cmdExec("app restart");
  100. }
  101. }
  102. #endif // 0
  103. const bgfx::Stats* stats = bgfx::getStats();
  104. ImGui::Text("CPU %0.3f"
  105. , double(stats->cpuTimeEnd-stats->cpuTimeBegin)/stats->cpuTimerFreq*1000.0
  106. );
  107. ImGui::Text("GPU %0.3f (latency: %d)"
  108. , double(stats->gpuTimeEnd-stats->gpuTimeBegin)/stats->gpuTimerFreq*1000.0
  109. , stats->maxGpuLatency
  110. );
  111. ImGui::End();
  112. }