2
0

example-glue.cpp 3.0 KB

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