Skip to content

Commit

Permalink
Add dedicated draw method to fast3d window to encapsulate all drawing…
Browse files Browse the repository at this point in the history
… logic as a LUS default
  • Loading branch information
Archez committed Jan 10, 2025
1 parent 806ffb0 commit d8d235c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
23 changes: 23 additions & 0 deletions src/graphic/Fast3D/Fast3dWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ bool Fast3dWindow::IsFrameReady() {
return mWindowManagerApi->is_frame_ready();
}

bool Fast3dWindow::DrawAndRunGraphicsCommands(Gfx* commands, const std::unordered_map<Mtx*, MtxF>& mtxReplacements) {
std::shared_ptr<Window> wnd = Ship::Context::GetInstance()->GetWindow();

// Skip dropped frames
if (!wnd->IsFrameReady()) {
return false;
}

auto gui = wnd->GetGui();
// Setup of the backend frames and draw initial Window and GUI menus
gui->StartDraw();
// Setup game framebuffers to match available window space
gfx_start_frame();
// Execute the games gfx commands
gfx_run(commands, mtxReplacements);
// Renders the game frame buffer to the final window and finishes the GUI
gui->EndDraw();
// Finalize swap buffers
gfx_end_frame();

return true;
}

void Fast3dWindow::HandleEvents() {
mWindowManagerApi->handle_events();
}
Expand Down
3 changes: 3 additions & 0 deletions src/graphic/Fast3D/Fast3dWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "public/bridge/gfxbridge.h"
#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"

union Gfx;

namespace Fast {
class Fast3dWindow : public Ship::Window {
public:
Expand Down Expand Up @@ -48,6 +50,7 @@ class Fast3dWindow : public Ship::Window {
void SetTextureFilter(FilteringMode filteringMode);
void SetRendererUCode(UcodeHandlers ucode);
void EnableSRGBMode();
bool DrawAndRunGraphicsCommands(Gfx* commands, const std::unordered_map<Mtx*, MtxF>& mtxReplacements);

protected:
static bool KeyDown(int32_t scancode);
Expand Down
17 changes: 1 addition & 16 deletions src/window/gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,27 +710,12 @@ void Gui::CheckSaveCvars() {
}
}

void Gui::Draw() {
// Initialize the frame.
StartFrame();
// Draw the gui menus
DrawMenu();
// Draw the game framebuffer into ImGui
DrawGame();
// End the frame
EndFrame();
// Draw the ImGui floating windows.
DrawFloatingWindows();
// Check if the CVars need to be saved, and do it if so.
CheckSaveCvars();
}

void Gui::StartDraw() {
// Initialize the frame.
StartFrame();
// Draw the gui menus
DrawMenu();

// Calculate the available space the game can render to
CalculateGameViewport();
}

Expand Down
1 change: 0 additions & 1 deletion src/window/gui/Gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class Gui {
~Gui();

void Init(GuiWindowInitData windowImpl);
void Draw();
void StartDraw();
void EndDraw();
void HandleWindowEvents(WindowEvent event);
Expand Down

0 comments on commit d8d235c

Please sign in to comment.