diff --git a/.gitignore b/.gitignore index 8e63a955..31130a6d 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,15 @@ subprojects/imgui-*/ subprojects/spdlog-*/ subprojects/nlohmann_json-*/ subprojects/implot-*/ +mangoconfig/subprojects/packagecache/ +mangoconfig/subprojects/Vulkan-Headers-*/ +mangoconfig/subprojects/imgui-*/ +mangoconfig/subprojects/spdlog-*/ +mangoconfig/subprojects/nlohmann_json-*/ +mangoconfig/subprojects/implot-*/ +mangoconfig/subprojects/nlohmann_json.wrap +mangoconfig/subprojects/spdlog.wrap +mangoconfig/subprojects/vulkan-headers.wrap #GNU Global Metadata **/GPATH diff --git a/mangoconfig/emscripten.cpp b/mangoconfig/emscripten.cpp new file mode 100644 index 00000000..a85087da --- /dev/null +++ b/mangoconfig/emscripten.cpp @@ -0,0 +1,38 @@ +#include +#include + +std::string get_data_dir() +{ + return std::string(); +} + +std::string get_config_dir() +{ + return std::string(); +} + +std::string get_exe_path() +{ + return std::string(); +} + +std::string get_wine_exe_name(bool keep_ext) +{ + return std::string(); +} + +enum LS_FLAGS +{ + LS_DIRS = 0x01, + LS_FILES = 0x02, +}; + +std::vector ls(const char* root, const char* prefix, LS_FLAGS flags) +{ + std::vector list; + return list; +} + +bool file_exists(const std::string& path){ + return ""; +} \ No newline at end of file diff --git a/mangoconfig/emscripten.cross b/mangoconfig/emscripten.cross new file mode 100644 index 00000000..aac3435d --- /dev/null +++ b/mangoconfig/emscripten.cross @@ -0,0 +1,15 @@ +[binaries] +c = '/usr/lib/emscripten/emcc' +cpp = '/usr/lib/emscripten/em++' +ar = '/usr/lib/emscripten/emar' +strip = '/usr/lib/emscripten/emstrip' +pkgconfig = ['/usr/lib/emscripten/emconfigure', 'pkg-config'] + +[properties] +needs_exe_wrapper = true + +[host_machine] +system = 'emscripten' +cpu_family = 'wasm32' +cpu = 'wasm32' +endian = 'little' \ No newline at end of file diff --git a/mangoconfig/imgui.html b/mangoconfig/imgui.html new file mode 100644 index 00000000..c755103c --- /dev/null +++ b/mangoconfig/imgui.html @@ -0,0 +1,86 @@ + + + + + + WebGui Demo + + + + +
+
asdf
+
+ +
+
+ + + + + diff --git a/mangoconfig/main.cpp b/mangoconfig/main.cpp new file mode 100644 index 00000000..5c142eab --- /dev/null +++ b/mangoconfig/main.cpp @@ -0,0 +1,174 @@ +#include + +#ifdef __EMSCRIPTEN__ +#include +#include +#endif + +#define GLFW_INCLUDE_ES3 +#include +#include + +#include "imgui.h" +#include "imgui_impl_glfw.h" +#include "imgui_impl_opengl3.h" +#include +#include "hud_elements.h" +#include "overlay.h" +#include "font_default.h" + +GLFWwindow* g_window; +ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); +bool show_demo_window = true; +bool show_another_window = false; +int g_width; +int g_height; +swapchain_stats sw_stats {}; +overlay_params params {}; +static ImVec2 window_size; +static uint32_t vendorID; +static std::string deviceName; +static int msgid; +static bool mangoapp_paused = false; + +// Function used by c++ to get the size of the html canvas +EM_JS(int, canvas_get_width, (), { + return Module.canvas.width; +}); + +// Function used by c++ to get the size of the html canvas +EM_JS(int, canvas_get_height, (), { + return Module.canvas.height; +}); + +// Function called by javascript +EM_JS(void, resizeCanvas, (), { + js_resizeCanvas(); +}); + +void on_size_changed() +{ + glfwSetWindowSize(g_window, g_width, g_height); + + ImGui::SetCurrentContext(ImGui::GetCurrentContext()); +} + +void loop() +{ + int width = canvas_get_width(); + int height = canvas_get_height(); + + if (width != g_width || height != g_height) + { + g_width = width; + g_height = height; + on_size_changed(); + } + + glfwPollEvents(); + + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + update_hud_info(sw_stats, params, vendorID); + overlay_new_frame(params); + position_layer(sw_stats, params, window_size); + render_imgui(sw_stats, params, window_size, true); + overlay_end_frame(); + ImGui::Render(); + + int display_w, display_h; + glfwMakeContextCurrent(g_window); + glfwGetFramebufferSize(g_window, &display_w, &display_h); + glViewport(0, 0, display_w, display_h); + EmscriptenWebGLContextAttributes attrs; + emscripten_webgl_init_context_attributes(&attrs); + attrs.alpha = EM_TRUE; + glEnable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glClearColor(0, 0, 0, 0.8); + glClear(GL_COLOR_BUFFER_BIT); + + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + glfwMakeContextCurrent(g_window); +} + +int init_gl() +{ + if( !glfwInit() ) + { + fprintf( stderr, "Failed to initialize GLFW\n" ); + return 1; + } + + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); + glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, 1); + + // Open a window and create its OpenGL context + int canvasWidth = g_width; + int canvasHeight = g_height; + g_window = glfwCreateWindow(canvasWidth, canvasHeight, "WebGui Demo", NULL, NULL); + if( g_window == NULL ) + { + fprintf( stderr, "Failed to open GLFW window.\n" ); + glfwTerminate(); + return -1; + } + glfwMakeContextCurrent(g_window); // Initialize GLEW + + return 0; +} + + +int init_imgui() +{ + // Setup Dear ImGui binding + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGui_ImplGlfw_InitForOpenGL(g_window, true); + ImGui_ImplOpenGL3_Init(); + + // Setup style + // ImGui::StyleColorsDark(); + + ImGuiIO& io = ImGui::GetIO(); + create_fonts(nullptr, params, sw_stats.font1, sw_stats.font_text); + parse_overlay_config(¶ms, "MANGOHUD_CONFIG", false); + HUDElements.convert_colors(params); + sw_stats.engine = EngineTypes::VULKAN; + resizeCanvas(); + + return 0; +} + + +int init() +{ + init_gl(); + init_imgui(); + return 0; +} + + +void quit() +{ + glfwTerminate(); +} + + +extern "C" int main(int argc, char** argv) +{ + g_width = canvas_get_width(); + g_height = canvas_get_height(); + if (init() != 0) return 1; + + #ifdef __EMSCRIPTEN__ + emscripten_set_main_loop(loop, 0, 1); + #endif + + quit(); + + return 0; +} diff --git a/mangoconfig/meson.build b/mangoconfig/meson.build new file mode 100644 index 00000000..46ae145e --- /dev/null +++ b/mangoconfig/meson.build @@ -0,0 +1,69 @@ +project('imgui_project', 'cpp', + default_options : ['cpp_std=c++17']) + +imgui_options = [ + 'default_library=static', + 'werror=false', + # use 'auto_features=disabled' once available: https://github.com/mesonbuild/meson/issues/5320 + 'dx9=disabled', + 'dx10=disabled', + 'dx11=disabled', + 'dx12=disabled', + 'metal=disabled', + 'opengl=enabled', + 'vulkan=disabled', + 'glfw=enabled', + 'sdl2=disabled', + 'osx=disabled', + 'win=disabled', + 'allegro5=disabled', + 'webgpu=disabled' +] + +mangohud_options = [ + 'with_nvml=disabled', + 'with_xnvctrl=disabled', + 'with_dbus=disabled', + 'with_spdlog=disabled' +] + +dearimgui_sp = subproject('imgui', default_options: imgui_options) +dearimgui_dep = dearimgui_sp.get_variable('imgui_dep') +glfw_dep = dependency('glfw3') +mangohud_sp = subproject('mangohud', default_options: mangohud_options) +# spdlog_dep = mangohud_sp.get_variable('spdlog_dep') +mangohud_static = mangohud_sp.get_variable('mangohud_static_lib') + +sources = [ + 'main.cpp', + 'emscripten.cpp' +] + +cxx_flags = [ + '-O2', + '-s', 'USE_WEBGL2=1', + '-s', 'USE_GLFW=3', + '-s', 'FULL_ES3=1', + '-s', 'WASM=1', + '--preload-file data', + '--source-map', + '-s', 'ASSERTIONS=1', + '-s', 'TOTAL_MEMORY=512MB', + '-s', 'USE_PTHREADS=1', +] + +libs = ['-lGL'] +spdlog_dep = mangohud_sp.get_variable('spdlog_dep') + +executable('imgui', sources, + dependencies : [], # add deps if any + c_args : cxx_flags, + objects: mangohud_static.extract_all_objects(), + # link_with: mangohud_static, + include_directories: mangohud_sp.get_variable('inc_common'), + link_args : libs, + native: false, + dependencies: [dearimgui_dep, glfw_dep]) + + +configure_file(input: 'imgui.html', output: 'imgui.html', copy: true) \ No newline at end of file diff --git a/mangoconfig/subprojects/imgui.wrap b/mangoconfig/subprojects/imgui.wrap new file mode 120000 index 00000000..ff389a85 --- /dev/null +++ b/mangoconfig/subprojects/imgui.wrap @@ -0,0 +1 @@ +../../subprojects/imgui.wrap \ No newline at end of file diff --git a/mangoconfig/subprojects/mangohud b/mangoconfig/subprojects/mangohud new file mode 120000 index 00000000..6581736d --- /dev/null +++ b/mangoconfig/subprojects/mangohud @@ -0,0 +1 @@ +../../ \ No newline at end of file diff --git a/mangoconfig/subprojects/mangohud.wrap b/mangoconfig/subprojects/mangohud.wrap new file mode 100644 index 00000000..243e1f03 --- /dev/null +++ b/mangoconfig/subprojects/mangohud.wrap @@ -0,0 +1,2 @@ +[wrap-file] +directory = mangohud