Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/fast/Fast3dGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,8 @@ class Fast3dGui : public Ship::Gui {
int16_t GetIntegerScaleFactor();

std::unordered_map<std::string, Ship::GuiTextureMetadata> mGuiTextures; ///< Cached GPU texture registry.

std::shared_ptr<Ship::Window> mWindow;
std::shared_ptr<Ship::Window> mBackendWindow;
};
} // namespace Fast
36 changes: 17 additions & 19 deletions src/fast/Fast3dGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ bool Fast3dGui::SupportsViewports() {
}

void Fast3dGui::HandleWindowEvents(Fast::WindowEvent event) {
auto window = Ship::Context::GetInstance()->GetWindow();
switch (window->GetWindowBackend()) {
switch (mWindow->GetWindowBackend()) {
case WindowBackend::FAST3D_SDL_OPENGL:
case WindowBackend::FAST3D_SDL_METAL:
ImGui_ImplSDL2_ProcessEvent(static_cast<const SDL_Event*>(event.Sdl.Event));
Expand All @@ -87,10 +86,11 @@ void Fast3dGui::HandleWindowEvents(Fast::WindowEvent event) {
}

void Fast3dGui::ImGuiWMInit() {
auto window = Ship::Context::GetInstance()->GetWindow();
mInterpreter = std::dynamic_pointer_cast<Fast3dWindow>(window)->GetInterpreterWeak();
mWindow = Ship::Context::GetInstance()->GetWindow();
if (auto fast3dWindow = std::dynamic_pointer_cast<Fast3dWindow>(mWindow))
mInterpreter = fast3dWindow->GetInterpreterWeak();

switch (window->GetWindowBackend()) {
switch (mWindow->GetWindowBackend()) {
case WindowBackend::FAST3D_SDL_OPENGL:
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "1");
if (Ship::Context::GetInstance()->GetConsoleVariables()->GetInteger(CVAR_ALLOW_BACKGROUND_INPUTS, 1)) {
Expand Down Expand Up @@ -121,8 +121,7 @@ void Fast3dGui::ImGuiWMInit() {
}

void Fast3dGui::ImGuiWMShutdown() {
auto window = Ship::Context::GetInstance()->GetWindow();
switch (window->GetWindowBackend()) {
switch (mWindow->GetWindowBackend()) {
#ifdef ENABLE_OPENGL
case WindowBackend::FAST3D_SDL_OPENGL:
ImGui_ImplSDL2_Shutdown();
Expand All @@ -141,11 +140,13 @@ void Fast3dGui::ImGuiWMShutdown() {
default:
break;
}

mWindow = nullptr;
}

void Fast3dGui::ImGuiBackendInit() {
auto window = Ship::Context::GetInstance()->GetWindow();
switch (window->GetWindowBackend()) {
mBackendWindow = Ship::Context::GetInstance()->GetWindow();
switch (mBackendWindow->GetWindowBackend()) {
#ifdef ENABLE_OPENGL
case WindowBackend::FAST3D_SDL_OPENGL:
#ifdef __APPLE__
Expand Down Expand Up @@ -178,8 +179,7 @@ void Fast3dGui::ImGuiBackendInit() {
}

void Fast3dGui::ImGuiBackendShutdown() {
auto window = Ship::Context::GetInstance()->GetWindow();
switch (window->GetWindowBackend()) {
switch (mBackendWindow->GetWindowBackend()) {
#ifdef ENABLE_OPENGL
case WindowBackend::FAST3D_SDL_OPENGL:
ImGui_ImplOpenGL3_Shutdown();
Expand All @@ -198,11 +198,12 @@ void Fast3dGui::ImGuiBackendShutdown() {
default:
break;
}

mBackendWindow = nullptr;
}

void Fast3dGui::ImGuiBackendNewFrame() {
auto window = Ship::Context::GetInstance()->GetWindow();
switch (window->GetWindowBackend()) {
switch (mBackendWindow->GetWindowBackend()) {
#ifdef ENABLE_OPENGL
case WindowBackend::FAST3D_SDL_OPENGL:
ImGui_ImplOpenGL3_NewFrame();
Expand All @@ -228,8 +229,7 @@ void Fast3dGui::ImGuiBackendNewFrame() {
}

void Fast3dGui::ImGuiWMNewFrame() {
auto window = Ship::Context::GetInstance()->GetWindow();
switch (window->GetWindowBackend()) {
switch (mWindow->GetWindowBackend()) {
case WindowBackend::FAST3D_SDL_OPENGL:
case WindowBackend::FAST3D_SDL_METAL:
ImGui_ImplSDL2_NewFrame();
Expand Down Expand Up @@ -257,8 +257,7 @@ void Fast3dGui::RefreshImGuiGamepads() {
}

void Fast3dGui::ImGuiRenderDrawData(ImDrawData* data) {
auto window = Ship::Context::GetInstance()->GetWindow();
switch (window->GetWindowBackend()) {
switch (mWindow->GetWindowBackend()) {
#ifdef ENABLE_OPENGL
case WindowBackend::FAST3D_SDL_OPENGL:
ImGui_ImplOpenGL3_RenderDrawData(data);
Expand Down Expand Up @@ -288,9 +287,8 @@ void Fast3dGui::DrawFloatingWindows() {
return;
}

auto window = Ship::Context::GetInstance()->GetWindow();
// OpenGL requires extra platform handling for the GL context
if (window->GetWindowBackend() == WindowBackend::FAST3D_SDL_OPENGL && mImpl.Opengl.Context != nullptr) {
if (mWindow->GetWindowBackend() == WindowBackend::FAST3D_SDL_OPENGL && mImpl.Opengl.Context != nullptr) {
// Backup window and context before calling RenderPlatformWindowsDefault
SDL_Window* backupCurrentWindow = SDL_GL_GetCurrentWindow();
SDL_GLContext backupCurrentContext = SDL_GL_GetCurrentContext();
Expand Down
4 changes: 3 additions & 1 deletion src/ship/debug/CrashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ static void ErrorHandler(int sig, siginfo_t* sigInfo, void* data) {
}

static void ShutdownHandler(int sig, siginfo_t* sigInfo, void* data) {
exit(1);
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
}

#elif _WIN32
Expand Down