Browse Source

plots

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
d951cbe6ef

+ 3
- 0
.gitmodules View File

[submodule "third_party/imgui_sdl"] [submodule "third_party/imgui_sdl"]
path = third_party/imgui_sdl path = third_party/imgui_sdl
url = https://github.com/mortie/imgui_sdl url = https://github.com/mortie/imgui_sdl
[submodule "third_party/imgui-plot"]
path = third_party/imgui-plot
url = https://github.com/soulthreads/imgui-plot.git

+ 2
- 0
libswan/include/swan/PerfCounter.h View File



void render(); void render();


void countTotalTime(double secs) { total_time_.count(secs); }
void countFrameTime(double secs) { frame_time_.count(secs); } void countFrameTime(double secs) { frame_time_.count(secs); }
void countGameUpdate(double secs) { game_update_.count(secs); } void countGameUpdate(double secs) { game_update_.count(secs); }
void countGameTick(double secs) { game_tick_.count(secs); } void countGameTick(double secs) { game_tick_.count(secs); }
void countMemoryUsage(double bytes) { memory_usage_.count(bytes); } void countMemoryUsage(double bytes) { memory_usage_.count(bytes); }


private: private:
Counter<> total_time_;
Counter<> frame_time_; Counter<> frame_time_;
Counter<> game_update_; Counter<> game_update_;
Counter<> game_tick_; Counter<> game_tick_;

+ 36
- 4
libswan/src/PerfCounter.cc View File

#include "PerfCounter.h" #include "PerfCounter.h"


#include <imgui.h> #include <imgui.h>
#include <imgui_plot.h>


#include "util.h" #include "util.h"


if (!ImGui::Begin("Perf Stats")) if (!ImGui::Begin("Perf Stats"))
return; return;


ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
ImGui::Text("Hello World");

std::array<float, 64> buf; std::array<float, 64> buf;
ImGui::PlotConfig conf;

conf.values = { .ys = buf.data(), .count = 64 };
conf.scale = { 0, 1 / 60.0 };
conf.scale.min = 0;
conf.scale.max = 1 / 60.0;
conf.frame_size = { ImGui::GetWindowContentRegionWidth(), 20 },

total_time_.fill(buf);
ImGui::Text("Total Time");
ImGui::Plot("Total Time", conf);

render_present_.fill(buf);
ImGui::Text("Render Present");
ImGui::Plot("Render Present", conf);

frame_time_.fill(buf); frame_time_.fill(buf);
ImGui::PlotLines("Frame Time", buf.data(), 64);
ImGui::Text("Frame Times");
ImGui::Plot("Frame Times", conf);

game_update_.fill(buf);
ImGui::Text("Game Update");
ImGui::Plot("Game Update", conf);

game_draw_.fill(buf);
ImGui::Text("Game Draw");
ImGui::Plot("Game Draw", conf);

game_tick_.fill(buf);
ImGui::Text("Game Tick");
ImGui::Plot("Game Tick", conf);

game_updates_per_frame_.fill(buf);
conf.scale = { 0, 5 };
ImGui::Text("Game Updates Per Frame");
ImGui::Plot("Game Updates Per Frame", conf);
} }


} }

+ 4
- 2
src/main.cc View File

int fcount = 0; int fcount = 0;
int slow_frames = 0; int slow_frames = 0;
while (1) { while (1) {
RTClock total_frame_clock;
RTClock total_time_clock;


SDL_Event evt; SDL_Event evt;
while (SDL_PollEvent(&evt)) { while (SDL_PollEvent(&evt)) {
game.draw(); game.draw();
pcounter.countGameDraw(draw_clock.duration()); pcounter.countGameDraw(draw_clock.duration());


pcounter.countFrameTime(total_frame_clock.duration());
pcounter.countFrameTime(total_time_clock.duration());
pcounter.render(); pcounter.render();


// Render ImGUI // Render ImGUI
RTClock present_clock; RTClock present_clock;
SDL_RenderPresent(renderer.get()); SDL_RenderPresent(renderer.get());
pcounter.countRenderPresent(present_clock.duration()); pcounter.countRenderPresent(present_clock.duration());

pcounter.countTotalTime(total_time_clock.duration());
} }


exit: exit:

+ 3
- 2
third_party/CMakeLists.txt View File

${PROJECT_SOURCE_DIR}/third_party/imgui/imgui_draw.cpp ${PROJECT_SOURCE_DIR}/third_party/imgui/imgui_draw.cpp
${PROJECT_SOURCE_DIR}/third_party/imgui/imgui_widgets.cpp ${PROJECT_SOURCE_DIR}/third_party/imgui/imgui_widgets.cpp
${PROJECT_SOURCE_DIR}/third_party/imgui/imgui.cpp ${PROJECT_SOURCE_DIR}/third_party/imgui/imgui.cpp
${PROJECT_SOURCE_DIR}/third_party/imgui_sdl/imgui_sdl.cpp)
${PROJECT_SOURCE_DIR}/third_party/imgui_sdl/imgui_sdl.cpp
${PROJECT_SOURCE_DIR}/third_party/imgui-plot/src/imgui_plot.cpp)
set_target_properties(imgui PROPERTIES CXX_CLANG_TIDY "") set_target_properties(imgui PROPERTIES CXX_CLANG_TIDY "")
target_include_directories(imgui PUBLIC target_include_directories(imgui PUBLIC
${PROJECT_SOURCE_DIR}/third_party/imgui ${PROJECT_SOURCE_DIR}/third_party/imgui
${PROJECT_SOURCE_DIR}/third_party/imgui/examples
${PROJECT_SOURCE_DIR}/third_party/imgui-plot/include
${SDL2_INCLUDE_DIRS}) ${SDL2_INCLUDE_DIRS})


install(TARGETS imgui DESTINATION swan/third_party) install(TARGETS imgui DESTINATION swan/third_party)

+ 1
- 0
third_party/imgui-plot

Subproject commit ce5f24e56ed14771ce25c60f0d933d2ee77eb468

Loading…
Cancel
Save