diff --git a/src/pse-sdl/sdl_interface.cpp b/src/pse-sdl/sdl_interface.cpp index 7e90f252f..e31a5009b 100644 --- a/src/pse-sdl/sdl_interface.cpp +++ b/src/pse-sdl/sdl_interface.cpp @@ -388,10 +388,12 @@ void SDLInterface::RenderDisplay() void SDLInterface::RenderImGui() { RenderMainMenuBar(); - RenderOSDMessages(); m_system->RenderUI(); + RenderOSDMessages(); + RenderFPS(); + ImGui::Render(); } @@ -512,6 +514,27 @@ void SDLInterface::RenderOSDMessages() } } +void SDLInterface::RenderFPS() +{ + // Position in the top-right corner of the screen. + ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - 2.0f, 2.0f), ImGuiCond_Always, ImVec2(1.0f, 0.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + ImGui::SetNextWindowSize(ImVec2(80.0f, 20.0f)); + + if (ImGui::Begin("FPS", nullptr, + ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav | + ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing | + ImGuiWindowFlags_NoBackground)) + { + ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "FPS: %.2f", m_fps); + } + ImGui::End(); + + ImGui::PopStyleVar(2); +} + void SDLInterface::DoLoadState(u32 index) { LoadState(GetSaveStateFilename(index)); @@ -538,6 +561,19 @@ void SDLInterface::Run() } m_system->RunFrame(); + + // update fps counter + { + m_fps_counter++; + const double time = m_fps_timer.GetTimeSeconds(); + if (time > 0.1) + { + m_fps = static_cast(m_fps_counter / time); + m_fps_counter = 0; + m_fps_timer.Reset(); + } + } + Render(); } } diff --git a/src/pse-sdl/sdl_interface.h b/src/pse-sdl/sdl_interface.h index cd6f6b240..da22cad5f 100644 --- a/src/pse-sdl/sdl_interface.h +++ b/src/pse-sdl/sdl_interface.h @@ -57,6 +57,7 @@ private: void RenderDisplay(); void RenderMainMenuBar(); void RenderOSDMessages(); + void RenderFPS(); SDL_Window* m_window = nullptr; SDL_GLContext m_gl_context = nullptr; @@ -76,4 +77,8 @@ private: std::mutex m_osd_messages_lock; std::shared_ptr m_controller; + + float m_fps = 0.0f; + u32 m_fps_counter = 0; + Timer m_fps_timer; }; diff --git a/src/pse/gpu.cpp b/src/pse/gpu.cpp index 7a8b4a79a..20e60ff7d 100644 --- a/src/pse/gpu.cpp +++ b/src/pse/gpu.cpp @@ -753,11 +753,7 @@ bool GPU::HandleCopyRectangleVRAMToVRAMCommand() return true; } -void GPU::UpdateDisplay() -{ - m_render_state.texture_changed = true; - m_system->IncrementFrameNumber(); -} +void GPU::UpdateDisplay() {} void GPU::ReadVRAM(u32 x, u32 y, u32 width, u32 height, void* buffer) {}