Skip to content

Commit

Permalink
gui: refactor imgui integration
Browse files Browse the repository at this point in the history
  • Loading branch information
scribam committed Nov 4, 2024
1 parent 699db31 commit 4902aaf
Show file tree
Hide file tree
Showing 37 changed files with 778 additions and 2,076 deletions.
5 changes: 5 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ add_subdirectory(libfat16)
add_library(imgui STATIC imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_tables.cpp imgui/imgui_widgets.cpp imgui/misc/cpp/imgui_stdlib.cpp)
target_compile_definitions(imgui PRIVATE IMGUI_DISABLE_DEMO_WINDOWS)
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui"
"${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends"
"${CMAKE_CURRENT_SOURCE_DIR}/imgui_club/imgui_memory_editor/")

target_sources(imgui PRIVATE imgui/backends/imgui_impl_opengl3.cpp imgui/backends/imgui_impl_sdl2.cpp imgui/backends/imgui_impl_vulkan.cpp)
target_link_libraries(imgui PRIVATE sdl2 vulkan)

add_library(miniz STATIC miniz/miniz.c miniz/miniz.h)
target_include_directories(miniz PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/miniz")

Expand Down Expand Up @@ -236,6 +240,7 @@ add_library(CLI11 INTERFACE)
target_include_directories(CLI11 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/cli11")

add_library(vulkan INTERFACE)
target_compile_definitions(vulkan INTERFACE VK_NO_PROTOTYPES VULKAN_HPP_NO_CONSTRUCTORS VULKAN_HPP_NO_SPACESHIP_OPERATOR)
target_include_directories(vulkan INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include")
if(APPLE)
if(NOT EXISTS "${CMAKE_BINARY_DIR}/external/MoltenVK-macos.tar")
Expand Down
4 changes: 2 additions & 2 deletions vita3k/app/include/app/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
struct Config;
struct EmuEnvState;
struct SDL_Window;
struct ImGui_State;
struct GuiState;
class Root;

namespace app {
Expand All @@ -38,7 +38,7 @@ enum class AppRunType {
void init_paths(Root &root_paths);
bool init(EmuEnvState &state, Config &cfg, const Root &root_paths);
bool late_init(EmuEnvState &state);
void destroy(EmuEnvState &emuenv, ImGui_State *imgui);
void destroy(EmuEnvState &emuenv, GuiState &gui);
void update_viewport(EmuEnvState &state);
void switch_state(EmuEnvState &emuenv, const bool pause);
void error_dialog(const std::string &message, SDL_Window *window = nullptr);
Expand Down
64 changes: 60 additions & 4 deletions vita3k/app/src/app_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
#include <config/state.h>
#include <config/version.h>
#include <display/state.h>
#include <gui/imgui_impl_sdl_vulkan_texture.h>
#include <gui/state.h>
#include <emuenv/state.h>
#include <gui/imgui_impl_sdl.h>
#include <io/functions.h>
#include <kernel/state.h>
#include <ngs/state.h>
#include <renderer/state.h>
#include <renderer/vulkan/state.h>

#include <renderer/functions.h>
#include <util/fs.h>
Expand All @@ -45,6 +47,10 @@
#include <SDL_video.h>
#include <SDL_vulkan.h>

#include <imgui_impl_opengl3.h>
#include <imgui_impl_sdl2.h>
#include <imgui_impl_vulkan.h>

#ifdef _WIN32
#include <SDL_syswm.h>
#include <dwmapi.h>
Expand Down Expand Up @@ -262,11 +268,15 @@ bool init(EmuEnvState &state, Config &cfg, const Root &root_paths) {
#endif
LOG_INFO("User pref path: {}", state.pref_path);

// Setup Dear ImGui context
IMGUI_CHECKVERSION();
if (ImGui::GetCurrentContext() == NULL) {
ImGui::CreateContext();
}
ImGuiIO &io = ImGui::GetIO();
io.IniFilename = NULL;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.IniFilename = nullptr;

state.backend_renderer = renderer::Backend::Vulkan;

Expand Down Expand Up @@ -406,8 +416,54 @@ bool late_init(EmuEnvState &state) {
return true;
}

void destroy(EmuEnvState &emuenv, ImGui_State *imgui) {
ImGui_ImplSdl_Shutdown(imgui);
void destroy(EmuEnvState &emuenv, GuiState &gui) {
switch (emuenv.renderer->current_backend) {
case renderer::Backend::OpenGL:
gui.app_selector.sys_apps_icon.clear();
gui.app_selector.user_apps_icon.clear();
gui.users_avatar.clear();
gui.themes_preview.clear();
gui.theme_backgrounds.clear();
gui.theme_information_bar_notice.clear();
gui.notice_info_icon.clear();
gui.user_backgrounds.clear();
gui.trophy_np_com_id_list_icons.clear();
gui.trophy_list.clear();
gui.start_background = {};
gui.apps_background.clear();
gui.live_area_contents.clear();
gui.live_items.clear();
gui.manuals.clear();
gui.trophy_window_icon = {};
ImGui_ImplOpenGL3_Shutdown();
break;
case renderer::Backend::Vulkan:
gui.app_selector.sys_apps_icon.clear();
gui.app_selector.user_apps_icon.clear();
gui.users_avatar.clear();
gui.themes_preview.clear();
gui.theme_backgrounds.clear();
gui.theme_information_bar_notice.clear();
gui.notice_info_icon.clear();
gui.user_backgrounds.clear();
gui.trophy_np_com_id_list_icons.clear();
gui.trophy_list.clear();
gui.start_background = {};
gui.apps_background.clear();
gui.live_area_contents.clear();
gui.live_items.clear();
gui.manuals.clear();
gui.trophy_window_icon = {};
ImGui_ImplVulkan_Shutdown();
dynamic_cast<renderer::vulkan::VKState &>(*emuenv.renderer).device.destroy(imgui_descriptor_pool);
break;
default:
LOG_ERROR("Missing ImGui init for backend {}.", static_cast<int>(emuenv.renderer->current_backend));
break;
}

ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();

#ifdef USE_DISCORD
discordrpc::shutdown();
Expand Down
5 changes: 2 additions & 3 deletions vita3k/dialog/include/dialog/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
#pragma once

#include <dialog/types.h>

#include <gui/imgui_impl_sdl_state.h>
#include <io/vfs.h>

#include <lang/state.h>

enum DialogType {
Expand Down Expand Up @@ -64,7 +63,7 @@ struct SavedataState {
uint32_t button_id = SCE_SAVEDATA_DIALOG_BUTTON_ID_INVALID;

std::vector<vfs::FileBuffer> icon_buffer;
std::vector<ImTextureID> icon_texture;
std::vector<ImGui_Texture> icon_texture;

uint32_t mode;
uint32_t mode_to_display;
Expand Down
11 changes: 5 additions & 6 deletions vita3k/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ add_library(
gui
STATIC
include/gui/functions.h
include/gui/imgui_impl_sdl_gl3.h
include/gui/imgui_impl_sdl_gl3_texture.h
include/gui/imgui_impl_sdl_state.h
include/gui/imgui_impl_sdl_vulkan.h
include/gui/imgui_impl_sdl.h
include/gui/imgui_impl_sdl_vulkan_texture.h
include/gui/state.h
src/app_context_menu.cpp
src/archive_install_dialog.cpp
Expand All @@ -18,9 +17,9 @@ add_library(
src/gui.cpp
src/home_screen.cpp
src/ime.cpp
src/imgui_impl_sdl_gl3.cpp
src/imgui_impl_sdl_vulkan.cpp
src/imgui_impl_sdl.cpp
src/imgui_impl_sdl_gl3_texture.cpp
src/imgui_impl_sdl_texture.cpp
src/imgui_impl_sdl_vulkan_texture.cpp
src/information_bar.cpp
src/initial_setup.cpp
src/license_install_dialog.cpp
Expand Down
6 changes: 2 additions & 4 deletions vita3k/gui/include/gui/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void init_user_apps(GuiState &gui, EmuEnvState &emuenv);
bool init_user_background(GuiState &gui, EmuEnvState &emuenv, const std::string &background_path);
bool init_user_backgrounds(GuiState &gui, EmuEnvState &emuenv);
void init_user_management(GuiState &gui, EmuEnvState &emuenv);
bool init_user_start_background(GuiState &gui, const std::string &image_path);
bool init_user_start_background(GuiState &gui, EmuEnvState &emuenv, const std::string &image_path);
void load_and_update_compat_user_apps(GuiState &gui, EmuEnvState &emuenv);
void open_live_area(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
void open_manual(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path);
Expand All @@ -113,7 +113,7 @@ void update_time_app_used(GuiState &gui, EmuEnvState &emuenv, const std::string
void save_notice_list(EmuEnvState &emuenv);

void draw_begin(GuiState &gui, EmuEnvState &emuenv);
void draw_end(GuiState &gui);
void draw_end(GuiState &gui, EmuEnvState &emuenv);
void draw_vita_area(GuiState &gui, EmuEnvState &emuenv);
void draw_ui(GuiState &gui, EmuEnvState &emuenv);

Expand All @@ -130,6 +130,4 @@ void draw_trophies_unlocked(GuiState &gui, EmuEnvState &emuenv);
void draw_touchpad_cursor(EmuEnvState &emuenv);
void draw_perf_overlay(GuiState &gui, EmuEnvState &emuenv);

ImTextureID load_image(GuiState &gui, const uint8_t *data, const int size);

} // namespace gui
41 changes: 0 additions & 41 deletions vita3k/gui/include/gui/imgui_impl_sdl.h

This file was deleted.

48 changes: 0 additions & 48 deletions vita3k/gui/include/gui/imgui_impl_sdl_gl3.h

This file was deleted.

33 changes: 33 additions & 0 deletions vita3k/gui/include/gui/imgui_impl_sdl_gl3_texture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Vita3K emulator project
// Copyright (C) 2024 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#pragma once

#include <glutil/gl.h>
#include <gui/imgui_impl_sdl_state.h>

struct GLTextureData : ImguiTextureData
{
private:
GLuint texture = 0;

public:
GLTextureData(unsigned char *data, int width, int height);
~GLTextureData() override;

ImTextureID GetImTextureID() const override;
};
Loading

0 comments on commit 4902aaf

Please sign in to comment.