Skip to content

Commit

Permalink
Fixes the calling time frame of ImGui BeginFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenix3 committed Aug 27, 2024
1 parent ab9ff11 commit 4d9fa8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/graphic/Fast3D/gfx_pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4019,19 +4019,20 @@ GfxExecStack g_exec_stack = {};

void gfx_run(Gfx* commands, const std::unordered_map<Mtx*, MtxF>& mtx_replacements) {
gfx_sp_reset();
Ship::Context::GetInstance()->GetWindow()->GetGui()->DrawMenu();

// puts("New frame");
get_pixel_depth_pending.clear();
get_pixel_depth_cached.clear();

if (!gfx_wapi->start_frame()) {
dropped_frame = true;
Ship::Context::GetInstance()->GetWindow()->GetGui()->StartFrame();
Ship::Context::GetInstance()->GetWindow()->GetGui()->EndFrame();
return;
}
dropped_frame = false;

Ship::Context::GetInstance()->GetWindow()->GetGui()->DrawMenu();

current_mtx_replacements = &mtx_replacements;

gfx_rapi->update_framebuffer_parameters(0, gfx_current_window_dimensions.width,
Expand Down
9 changes: 3 additions & 6 deletions src/window/gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ void Gui::UnblockImGuiGamepadNavigation() {

void Gui::DrawMenu() {
Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Console")->Update();
ImGuiBackendNewFrame();
ImGuiWMNewFrame();
ImGui::NewFrame();

const std::shared_ptr<Window> wnd = Context::GetInstance()->GetWindow();
const std::shared_ptr<Config> conf = Context::GetInstance()->GetConfig();
Expand All @@ -324,7 +321,7 @@ void Gui::DrawMenu() {
ImGui::Begin("Main - Deck", nullptr, windowFlags);
ImGui::PopStyleVar(3);

windowPosBeforeMenuBar = ImGui::GetWindowPos();
mWindowPosBeforeMenuBar = ImGui::GetWindowPos();

const ImGuiID dockId = ImGui::GetID("main_dock");

Expand Down Expand Up @@ -549,8 +546,8 @@ void Gui::StartFrame() {
ImGui::PopStyleColor();

ImVec2 mainPos = ImGui::GetWindowPos();
mainPos.x -= windowPosBeforeMenuBar.x;
mainPos.y -= windowPosBeforeMenuBar.y;
mainPos.x -= mWindowPosBeforeMenuBar.x;
mainPos.y -= mWindowPosBeforeMenuBar.y;
ImVec2 size = ImGui::GetContentRegionAvail();
gfx_current_dimensions.width = (uint32_t)(size.x * gfx_current_dimensions.internal_mul);
gfx_current_dimensions.height = (uint32_t)(size.y * gfx_current_dimensions.internal_mul);
Expand Down
7 changes: 4 additions & 3 deletions src/window/gui/Gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ class Gui {
bool GetPadBtnTogglesMenu();
void SetPadBtnTogglesMenu();

void ImGuiBackendNewFrame();
void ImGuiWMNewFrame();

protected:
void ImGuiWMInit();
void ImGuiBackendInit();
void ImGuiBackendNewFrame();
void ImGuiWMNewFrame();
void ImGuiRenderDrawData(ImDrawData* data);
ImTextureID GetTextureById(int32_t id);
void ApplyResolutionChanges();
Expand All @@ -124,7 +125,7 @@ class Gui {
std::unordered_map<std::string, GuiTextureMetadata> mGuiTextures;
std::map<std::string, std::shared_ptr<GuiWindow>> mGuiWindows;
bool mPadBtnTogglesMenu = false;
ImVec2 windowPosBeforeMenuBar;
ImVec2 mWindowPosBeforeMenuBar;
};
} // namespace Ship

Expand Down

0 comments on commit 4d9fa8d

Please sign in to comment.