mangoconfig
This is mangohud compiled with emscripten to be run inside a browsermangoconfig
parent
3694e22d3b
commit
ea3cd9e67d
@ -0,0 +1,38 @@
|
|||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string> ls(const char* root, const char* prefix, LS_FLAGS flags)
|
||||||
|
{
|
||||||
|
std::vector<std::string> list;
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool file_exists(const std::string& path){
|
||||||
|
return "";
|
||||||
|
}
|
@ -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'
|
@ -0,0 +1,86 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en-us">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>WebGui Demo</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: arial;
|
||||||
|
margin: 0;
|
||||||
|
padding: none;
|
||||||
|
}
|
||||||
|
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
|
||||||
|
div.emscripten { text-align: center; }
|
||||||
|
div.emscripten_border { border: none; }
|
||||||
|
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
|
||||||
|
canvas.emscripten { border: 0px none; background-color: black; }
|
||||||
|
#canvas {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.background {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: -1; /* Position behind the canvas */
|
||||||
|
}
|
||||||
|
|
||||||
|
.emscripten_border {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1; /* Position in front of the background div */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div id="backgroundDiv" class="background" style="color: red;">asdf</div>
|
||||||
|
<div class="emscripten_border">
|
||||||
|
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type='text/javascript'>
|
||||||
|
var Module = {
|
||||||
|
preRun: [],
|
||||||
|
postRun: [],
|
||||||
|
print: (function() {})(),
|
||||||
|
printErr: function(text) {},
|
||||||
|
canvas: (function() {
|
||||||
|
var canvas = document.getElementById('canvas');
|
||||||
|
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
|
||||||
|
// application robust, you may want to override this behavior before shipping!
|
||||||
|
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
|
||||||
|
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
|
||||||
|
return canvas;
|
||||||
|
})(),
|
||||||
|
setStatus: function(text) {},
|
||||||
|
totalDependencies: 0,
|
||||||
|
monitorRunDependencies: function(left) {}
|
||||||
|
};
|
||||||
|
window.addEventListener('resize', js_resizeCanvas, false);
|
||||||
|
function js_resizeCanvas() {
|
||||||
|
document.getElementById('canvas').width = window.innerWidth;
|
||||||
|
document.getElementById('canvas').height = window.innerHeight;
|
||||||
|
}
|
||||||
|
function updateBackgroundSize() {
|
||||||
|
var canvas = document.getElementById('canvas');
|
||||||
|
var backgroundDiv = document.getElementById('backgroundDiv');
|
||||||
|
backgroundDiv.style.width = canvas.clientWidth + 'px';
|
||||||
|
backgroundDiv.style.height = canvas.clientHeight + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the background div size whenever the canvas size changes.
|
||||||
|
window.addEventListener('resize', updateBackgroundSize);
|
||||||
|
|
||||||
|
// Initial size update.
|
||||||
|
updateBackgroundSize();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<script async type="text/javascript" src="imgui.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,174 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#include <emscripten.h>
|
||||||
|
#include <emscripten/html5.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define GLFW_INCLUDE_ES3
|
||||||
|
#include <GLES3/gl3.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_glfw.h"
|
||||||
|
#include "imgui_impl_opengl3.h"
|
||||||
|
#include <iostream>
|
||||||
|
#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;
|
||||||
|
}
|
@ -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)
|
@ -0,0 +1 @@
|
|||||||
|
../../subprojects/imgui.wrap
|
@ -0,0 +1 @@
|
|||||||
|
../../
|
@ -0,0 +1,2 @@
|
|||||||
|
[wrap-file]
|
||||||
|
directory = mangohud
|
Loading…
Reference in New Issue