2021-09-06 06:21:10 +00:00
|
|
|
// Dear ImGui: standalone example application for GLFW + OpenGL 3, using programmable pipeline
|
|
|
|
// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
|
|
|
|
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
|
|
|
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
|
|
|
|
2023-03-03 11:30:49 +00:00
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/msg.h>
|
|
|
|
|
2021-09-06 06:21:10 +00:00
|
|
|
#include "imgui.h"
|
|
|
|
#include "imgui_impl_glfw.h"
|
|
|
|
#include "imgui_impl_opengl3.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <thread>
|
2021-10-18 15:50:50 +00:00
|
|
|
#include <unistd.h>
|
2021-09-06 06:21:10 +00:00
|
|
|
#include "../overlay.h"
|
2022-04-07 08:28:48 +00:00
|
|
|
#include "notify.h"
|
2022-01-06 09:57:18 +00:00
|
|
|
#include "mangoapp.h"
|
2023-03-03 11:30:49 +00:00
|
|
|
#include "mangoapp_proto.h"
|
2022-01-05 05:12:21 +00:00
|
|
|
#include <GL/glew.h>
|
2021-09-06 06:21:10 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
2023-05-01 11:52:26 +00:00
|
|
|
#include "amdgpu.h"
|
2023-09-21 20:05:21 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
#include "implot.h"
|
|
|
|
#endif
|
2021-09-06 06:21:10 +00:00
|
|
|
|
2021-09-21 12:29:49 +00:00
|
|
|
#define GLFW_EXPOSE_NATIVE_X11
|
|
|
|
#include <GLFW/glfw3native.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
2022-03-14 18:49:20 +00:00
|
|
|
#include "nlohmann/json.hpp"
|
|
|
|
using json = nlohmann::json;
|
2022-04-07 08:28:48 +00:00
|
|
|
using namespace std;
|
2022-03-14 18:49:20 +00:00
|
|
|
|
2021-09-06 06:21:10 +00:00
|
|
|
static void glfw_error_callback(int error, const char* description)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
|
|
|
|
}
|
2022-03-13 11:17:38 +00:00
|
|
|
|
2021-09-06 06:21:10 +00:00
|
|
|
swapchain_stats sw_stats {};
|
2022-04-07 08:28:48 +00:00
|
|
|
overlay_params params {};
|
2021-09-06 06:21:10 +00:00
|
|
|
static ImVec2 window_size;
|
|
|
|
static uint32_t vendorID;
|
|
|
|
static std::string deviceName;
|
2022-01-05 05:12:41 +00:00
|
|
|
static notify_thread notifier;
|
2022-03-13 11:17:38 +00:00
|
|
|
static int msgid;
|
|
|
|
static bool mangoapp_paused = false;
|
2022-01-06 09:57:18 +00:00
|
|
|
std::mutex mangoapp_m;
|
|
|
|
std::condition_variable mangoapp_cv;
|
2021-12-13 13:38:50 +00:00
|
|
|
static uint8_t raw_msg[1024] = {0};
|
2023-05-29 03:37:03 +00:00
|
|
|
static uint32_t screenWidth, screenHeight;
|
2022-02-13 13:57:48 +00:00
|
|
|
|
2022-03-19 21:23:59 +00:00
|
|
|
static unsigned int get_prop(const char* propName){
|
2022-02-13 13:57:48 +00:00
|
|
|
Display *x11_display = glfwGetX11Display();
|
2023-11-07 19:55:06 +00:00
|
|
|
Atom gamescope_focused = XInternAtom(x11_display, propName, false);
|
2022-02-13 13:57:48 +00:00
|
|
|
auto scr = DefaultScreen(x11_display);
|
|
|
|
auto root = RootWindow(x11_display, scr);
|
|
|
|
Atom actual;
|
|
|
|
int format;
|
|
|
|
unsigned long n, left;
|
|
|
|
uint64_t *data;
|
|
|
|
int result = XGetWindowProperty(x11_display, root, gamescope_focused, 0L, 1L, false,
|
|
|
|
XA_CARDINAL, &actual, &format,
|
|
|
|
&n, &left, ( unsigned char** )&data);
|
|
|
|
|
|
|
|
if (result == Success && data != NULL){
|
|
|
|
bool *found = nullptr;
|
|
|
|
unsigned int i;
|
|
|
|
memcpy(&i, data, sizeof(unsigned int));
|
|
|
|
XFree((void *) data);
|
|
|
|
if ( found != nullptr )
|
|
|
|
{
|
|
|
|
*found = true;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
2023-11-07 19:55:06 +00:00
|
|
|
return -1;
|
2022-02-13 13:57:48 +00:00
|
|
|
}
|
2021-12-13 13:38:50 +00:00
|
|
|
|
2022-03-13 11:17:38 +00:00
|
|
|
static void ctrl_thread(){
|
2022-01-21 09:35:55 +00:00
|
|
|
while (1){
|
|
|
|
const struct mangoapp_ctrl_msgid1_v1 *mangoapp_ctrl_v1 = (const struct mangoapp_ctrl_msgid1_v1*) raw_msg;
|
2022-01-22 04:17:55 +00:00
|
|
|
memset(raw_msg, 0, sizeof(raw_msg));
|
2022-03-19 21:23:59 +00:00
|
|
|
msgrcv(msgid, (void *) raw_msg, sizeof(raw_msg), 2, 0);
|
2022-01-21 09:35:55 +00:00
|
|
|
switch (mangoapp_ctrl_v1->log_session) {
|
2022-03-13 11:17:38 +00:00
|
|
|
case 0:
|
|
|
|
// Keep as-is
|
|
|
|
break;
|
2022-01-21 09:35:55 +00:00
|
|
|
case 1:
|
2022-01-22 04:17:55 +00:00
|
|
|
if (!logger->is_active())
|
|
|
|
logger->start_logging();
|
|
|
|
break;
|
2022-01-21 09:35:55 +00:00
|
|
|
case 2:
|
2022-01-22 04:17:55 +00:00
|
|
|
if (logger->is_active())
|
|
|
|
logger->stop_logging();
|
|
|
|
break;
|
2022-01-21 09:35:55 +00:00
|
|
|
case 3:
|
|
|
|
logger->is_active() ? logger->stop_logging() : logger->start_logging();
|
2022-01-22 04:17:55 +00:00
|
|
|
break;
|
2022-01-21 09:35:55 +00:00
|
|
|
}
|
2023-03-07 17:19:23 +00:00
|
|
|
switch (mangoapp_ctrl_v1->reload_config) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
2023-07-07 04:23:12 +00:00
|
|
|
parse_overlay_config(¶ms, getenv("MANGOHUD_CONFIG"), false);
|
2023-03-07 17:19:23 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
case 3:
|
2023-07-07 04:23:12 +00:00
|
|
|
parse_overlay_config(¶ms, getenv("MANGOHUD_CONFIG"), false);
|
2023-03-07 17:19:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-02-01 01:27:45 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(mangoapp_m);
|
|
|
|
switch (mangoapp_ctrl_v1->no_display){
|
2022-03-13 11:17:38 +00:00
|
|
|
case 0:
|
|
|
|
// Keep as-is
|
|
|
|
break;
|
2022-02-01 01:27:45 +00:00
|
|
|
case 1:
|
2022-04-07 08:28:48 +00:00
|
|
|
params.no_display = 1;
|
2022-02-01 01:27:45 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2022-04-07 08:28:48 +00:00
|
|
|
params.no_display = 0;
|
2022-02-01 01:27:45 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2022-04-07 08:28:48 +00:00
|
|
|
params.no_display ? params.no_display = 0 : params.no_display = 1;
|
2022-02-01 01:27:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-01-21 09:35:55 +00:00
|
|
|
}
|
|
|
|
mangoapp_cv.notify_one();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-01 01:29:14 +00:00
|
|
|
bool new_frame = false;
|
|
|
|
|
2022-03-13 11:17:38 +00:00
|
|
|
static void gamescope_frametime(uint64_t app_frametime_ns, uint64_t latency_ns){
|
2023-12-01 06:06:21 +00:00
|
|
|
if (app_frametime_ns != uint64_t(-1))
|
|
|
|
{
|
|
|
|
float app_frametime_ms = app_frametime_ns / 1000000.f;
|
|
|
|
HUDElements.gamescope_debug_app.push_back(app_frametime_ms);
|
|
|
|
if (HUDElements.gamescope_debug_app.size() > 200)
|
|
|
|
HUDElements.gamescope_debug_app.erase(HUDElements.gamescope_debug_app.begin());
|
|
|
|
}
|
2022-02-15 09:19:02 +00:00
|
|
|
|
|
|
|
float latency_ms = latency_ns / 1000000.f;
|
2022-03-19 21:23:59 +00:00
|
|
|
if (latency_ns == uint64_t(-1))
|
2022-02-15 09:19:02 +00:00
|
|
|
latency_ms = -1;
|
2023-04-21 21:21:59 +00:00
|
|
|
HUDElements.gamescope_debug_latency.push_back(latency_ms);
|
|
|
|
if (HUDElements.gamescope_debug_latency.size() > 200)
|
|
|
|
HUDElements.gamescope_debug_latency.erase(HUDElements.gamescope_debug_latency.begin());
|
2022-02-15 09:19:02 +00:00
|
|
|
}
|
|
|
|
|
2022-03-13 11:17:38 +00:00
|
|
|
static void msg_read_thread(){
|
2022-02-15 09:19:02 +00:00
|
|
|
for (size_t i = 0; i < 200; i++){
|
2023-04-21 21:21:59 +00:00
|
|
|
HUDElements.gamescope_debug_app.push_back(0);
|
|
|
|
HUDElements.gamescope_debug_latency.push_back(0);
|
2022-02-15 09:19:02 +00:00
|
|
|
}
|
2023-11-14 09:43:01 +00:00
|
|
|
int key = ftok("mangoapp", 65);
|
2022-01-06 09:57:18 +00:00
|
|
|
msgid = msgget(key, 0666 | IPC_CREAT);
|
2022-07-07 22:07:02 +00:00
|
|
|
// uint32_t previous_pid = 0;
|
2021-12-13 13:38:50 +00:00
|
|
|
const struct mangoapp_msg_header *hdr = (const struct mangoapp_msg_header*) raw_msg;
|
|
|
|
const struct mangoapp_msg_v1 *mangoapp_v1 = (const struct mangoapp_msg_v1*) raw_msg;
|
2021-09-06 06:21:10 +00:00
|
|
|
while (1){
|
2021-12-13 13:38:50 +00:00
|
|
|
// make sure that the message recieved is compatible
|
|
|
|
// and that we're not trying to use variables that don't exist (yet)
|
2022-02-18 15:02:08 +00:00
|
|
|
size_t msg_size = msgrcv(msgid, (void *) raw_msg, sizeof(raw_msg), 1, 0) + sizeof(long);
|
2021-12-13 13:38:50 +00:00
|
|
|
if (hdr->version == 1){
|
2022-02-18 15:02:08 +00:00
|
|
|
if (msg_size > offsetof(struct mangoapp_msg_v1, visible_frametime_ns)){
|
2023-12-01 06:06:21 +00:00
|
|
|
bool should_new_frame = false;
|
|
|
|
if (mangoapp_v1->visible_frametime_ns != ~(0lu) && (!params.no_display || logger->is_active())) {
|
2023-02-07 11:09:10 +00:00
|
|
|
update_hud_info_with_frametime(sw_stats, params, vendorID, mangoapp_v1->visible_frametime_ns);
|
2023-12-01 06:06:21 +00:00
|
|
|
should_new_frame = true;
|
|
|
|
}
|
2023-02-07 11:09:10 +00:00
|
|
|
|
2022-02-18 15:02:08 +00:00
|
|
|
if (msg_size > offsetof(mangoapp_msg_v1, fsrUpscale)){
|
2023-04-21 21:21:59 +00:00
|
|
|
HUDElements.g_fsrUpscale = mangoapp_v1->fsrUpscale;
|
2022-04-07 08:28:48 +00:00
|
|
|
if (params.fsr_steam_sharpness < 0)
|
2023-04-21 21:21:59 +00:00
|
|
|
HUDElements.g_fsrSharpness = mangoapp_v1->fsrSharpness;
|
2022-03-20 07:00:11 +00:00
|
|
|
else
|
2023-04-21 21:21:59 +00:00
|
|
|
HUDElements.g_fsrSharpness = params.fsr_steam_sharpness - mangoapp_v1->fsrSharpness;
|
2022-02-09 04:33:08 +00:00
|
|
|
}
|
2022-03-19 21:23:59 +00:00
|
|
|
if (!HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_mangoapp_steam]){
|
|
|
|
steam_focused = get_prop("GAMESCOPE_FOCUSED_APP_GFX") == 769;
|
|
|
|
} else {
|
|
|
|
steam_focused = false;
|
|
|
|
}
|
2022-07-05 14:56:36 +00:00
|
|
|
// if (!steam_focused && mangoapp_v1->pid != previous_pid){
|
|
|
|
// string path = "/tmp/mangoapp/" + to_string(mangoapp_v1->pid) + ".json";
|
|
|
|
// ifstream i(path);
|
|
|
|
// if (i.fail()){
|
|
|
|
// sw_stats.engine = EngineTypes::GAMESCOPE;
|
|
|
|
// } else {
|
|
|
|
// json j;
|
|
|
|
// i >> j;
|
|
|
|
// sw_stats.engine = static_cast<EngineTypes> (j["engine"]);
|
|
|
|
// }
|
|
|
|
// previous_pid = mangoapp_v1->pid;
|
|
|
|
// }
|
2022-03-19 21:23:59 +00:00
|
|
|
if (msg_size > offsetof(mangoapp_msg_v1, latency_ns))
|
2022-02-15 09:19:02 +00:00
|
|
|
gamescope_frametime(mangoapp_v1->app_frametime_ns, mangoapp_v1->latency_ns);
|
2022-03-19 21:23:59 +00:00
|
|
|
|
2023-12-01 06:06:21 +00:00
|
|
|
if (should_new_frame)
|
2022-02-01 01:29:14 +00:00
|
|
|
{
|
2023-12-01 06:06:21 +00:00
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lk(mangoapp_m);
|
|
|
|
new_frame = true;
|
|
|
|
}
|
|
|
|
mangoapp_cv.notify_one();
|
|
|
|
screenWidth = mangoapp_v1->outputWidth;
|
|
|
|
screenHeight = mangoapp_v1->outputHeight;
|
2022-02-01 01:29:14 +00:00
|
|
|
}
|
2021-12-13 13:38:50 +00:00
|
|
|
}
|
2021-09-06 06:21:10 +00:00
|
|
|
} else {
|
2021-12-13 13:38:50 +00:00
|
|
|
printf("Unsupported mangoapp struct version: %i\n", hdr->version);
|
|
|
|
exit(1);
|
2021-09-06 06:21:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-04 06:56:56 +00:00
|
|
|
static const char *GamescopeOverlayProperty = "GAMESCOPE_EXTERNAL_OVERLAY";
|
2021-09-21 12:29:49 +00:00
|
|
|
|
2022-03-13 11:17:38 +00:00
|
|
|
static GLFWwindow* init(const char* glsl_version){
|
2023-11-14 09:10:26 +00:00
|
|
|
init_spdlog();
|
2022-09-05 11:50:04 +00:00
|
|
|
GLFWwindow *window = glfwCreateWindow(1280, 800, "mangoapp overlay window", NULL, NULL);
|
2022-01-06 09:57:18 +00:00
|
|
|
Display *x11_display = glfwGetX11Display();
|
|
|
|
Window x11_window = glfwGetX11Window(window);
|
|
|
|
if (x11_window && x11_display)
|
|
|
|
{
|
|
|
|
// Set atom for gamescope to render as an overlay.
|
|
|
|
Atom overlay_atom = XInternAtom (x11_display, GamescopeOverlayProperty, False);
|
|
|
|
uint32_t value = 1;
|
2022-06-09 14:50:49 +00:00
|
|
|
XChangeProperty(x11_display, x11_window, overlay_atom, XA_CARDINAL, 32, PropertyNewValue, (unsigned char *)&value, 1);
|
2022-01-06 09:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
glfwSwapInterval(1); // Enable vsync
|
|
|
|
ImGui::CreateContext();
|
2023-09-21 20:05:21 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
ImPlot::CreateContext();
|
|
|
|
#endif
|
2022-01-06 09:57:18 +00:00
|
|
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
2022-02-11 02:05:44 +00:00
|
|
|
io.IniFilename = NULL;
|
2022-01-06 09:57:18 +00:00
|
|
|
ImGui::StyleColorsDark();
|
|
|
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
|
|
ImGui_ImplOpenGL3_Init(glsl_version);
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2022-03-13 11:17:38 +00:00
|
|
|
static void shutdown(GLFWwindow* window){
|
2022-01-06 09:57:18 +00:00
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplGlfw_Shutdown();
|
|
|
|
ImGui::DestroyContext();
|
|
|
|
glfwDestroyWindow(window);
|
|
|
|
}
|
|
|
|
|
2023-11-07 19:55:06 +00:00
|
|
|
static void get_atom_info(){
|
|
|
|
HUDElements.hdr_status = get_prop("GAMESCOPE_COLOR_APP_WANTS_HDR_FEEDBACK");
|
|
|
|
HUDElements.refresh = get_prop("GAMESCOPE_DISPLAY_REFRESH_RATE_FEEDBACK");
|
|
|
|
}
|
|
|
|
|
2022-03-13 11:17:38 +00:00
|
|
|
static bool render(GLFWwindow* window) {
|
2023-06-10 20:42:42 +00:00
|
|
|
if (HUDElements.colors.update)
|
|
|
|
HUDElements.convert_colors(params);
|
|
|
|
|
2022-02-01 02:34:36 +00:00
|
|
|
ImVec2 last_window_size = window_size;
|
|
|
|
ImGui_ImplGlfw_NewFrame();
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui::NewFrame();
|
2022-04-07 08:28:48 +00:00
|
|
|
overlay_new_frame(params);
|
|
|
|
position_layer(sw_stats, params, window_size);
|
|
|
|
render_imgui(sw_stats, params, window_size, true);
|
2023-11-07 19:55:06 +00:00
|
|
|
get_atom_info();
|
2022-05-16 08:06:23 +00:00
|
|
|
overlay_end_frame();
|
2023-05-29 03:37:03 +00:00
|
|
|
if (screenWidth && screenHeight)
|
|
|
|
glfwSetWindowSize(window, screenWidth, screenHeight);
|
2022-02-01 02:34:36 +00:00
|
|
|
ImGui::EndFrame();
|
|
|
|
return last_window_size.x != window_size.x || last_window_size.y != window_size.y;
|
|
|
|
}
|
|
|
|
|
2021-09-06 06:21:10 +00:00
|
|
|
int main(int, char**)
|
2022-03-13 11:17:38 +00:00
|
|
|
{
|
2021-09-06 06:21:10 +00:00
|
|
|
// Setup window
|
|
|
|
glfwSetErrorCallback(glfw_error_callback);
|
|
|
|
if (!glfwInit())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
const char* glsl_version = "#version 130";
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
|
|
|
|
|
|
|
glfwWindowHint(GLFW_RESIZABLE, 1);
|
|
|
|
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, 1);
|
|
|
|
|
|
|
|
// Create window with graphics context
|
2022-03-19 21:23:59 +00:00
|
|
|
GLFWwindow* window = init(glsl_version);
|
2022-06-05 09:11:38 +00:00
|
|
|
|
|
|
|
Display *x11_display = glfwGetX11Display();
|
|
|
|
Window x11_window = glfwGetX11Window(window);
|
|
|
|
Atom overlay_atom = XInternAtom (x11_display, GamescopeOverlayProperty, False);
|
2021-09-06 06:21:10 +00:00
|
|
|
// Initialize OpenGL loader
|
2022-01-05 05:12:21 +00:00
|
|
|
|
2021-09-06 06:21:10 +00:00
|
|
|
bool err = glewInit() != GLEW_OK;
|
2022-01-05 05:12:21 +00:00
|
|
|
|
2021-09-06 06:21:10 +00:00
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup Platform/Renderer backends
|
2022-04-07 08:28:48 +00:00
|
|
|
int control_client = -1;
|
2023-07-07 04:23:12 +00:00
|
|
|
parse_overlay_config(¶ms, getenv("MANGOHUD_CONFIG"), false);
|
2022-07-28 20:05:58 +00:00
|
|
|
create_fonts(nullptr, params, sw_stats.font1, sw_stats.font_text);
|
2022-04-07 08:28:48 +00:00
|
|
|
HUDElements.convert_colors(params);
|
|
|
|
init_cpu_stats(params);
|
|
|
|
notifier.params = ¶ms;
|
2022-01-05 05:12:41 +00:00
|
|
|
start_notifier(notifier);
|
2022-04-07 08:28:48 +00:00
|
|
|
window_size = ImVec2(params.width, params.height);
|
|
|
|
deviceName = (char*)glGetString(GL_RENDERER);
|
2021-09-06 06:21:10 +00:00
|
|
|
sw_stats.deviceName = deviceName;
|
2023-07-24 20:27:20 +00:00
|
|
|
|
|
|
|
#define GLX_RENDERER_VENDOR_ID_MESA 0x8183
|
|
|
|
auto pfn_glXQueryCurrentRendererIntegerMESA = (Bool (*)(int, unsigned int*)) (glfwGetProcAddress("glXQueryCurrentRendererIntegerMESA"));
|
|
|
|
if (pfn_glXQueryCurrentRendererIntegerMESA) {
|
|
|
|
pfn_glXQueryCurrentRendererIntegerMESA(GLX_RENDERER_VENDOR_ID_MESA, &vendorID);
|
2021-09-06 06:21:10 +00:00
|
|
|
} else {
|
2023-07-24 20:27:20 +00:00
|
|
|
if (deviceName.find("Radeon") != std::string::npos
|
|
|
|
|| deviceName.find("AMD") != std::string::npos){
|
|
|
|
vendorID = 0x1002;
|
|
|
|
} else if (deviceName.find("Intel") != std::string::npos) {
|
|
|
|
vendorID = 0x8086;
|
|
|
|
} else {
|
|
|
|
vendorID = 0x10de;
|
|
|
|
}
|
2021-09-06 06:21:10 +00:00
|
|
|
}
|
2023-10-31 14:04:53 +00:00
|
|
|
|
|
|
|
HUDElements.vendorID = vendorID;
|
2022-04-07 08:28:48 +00:00
|
|
|
init_gpu_stats(vendorID, 0, params);
|
2021-09-06 06:21:10 +00:00
|
|
|
init_system_info();
|
2021-11-18 07:25:30 +00:00
|
|
|
sw_stats.engine = EngineTypes::GAMESCOPE;
|
2021-12-13 13:38:50 +00:00
|
|
|
std::thread(msg_read_thread).detach();
|
2022-01-21 09:35:55 +00:00
|
|
|
std::thread(ctrl_thread).detach();
|
2022-01-15 19:05:32 +00:00
|
|
|
if(!logger) logger = std::make_unique<Logger>(HUDElements.params);
|
2021-09-06 06:21:10 +00:00
|
|
|
// Main loop
|
2022-01-06 09:57:18 +00:00
|
|
|
while (!glfwWindowShouldClose(window)){
|
2022-04-07 08:28:48 +00:00
|
|
|
if (!params.no_display){
|
2022-01-06 09:57:18 +00:00
|
|
|
if (mangoapp_paused){
|
2022-03-13 11:17:38 +00:00
|
|
|
glfwRestoreWindow(window);
|
2022-06-05 09:11:38 +00:00
|
|
|
uint32_t value = 1;
|
|
|
|
XChangeProperty(x11_display, x11_window, overlay_atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&value, 1);
|
|
|
|
XSync(x11_display, 0);
|
2022-01-06 09:57:18 +00:00
|
|
|
mangoapp_paused = false;
|
2023-05-01 11:52:26 +00:00
|
|
|
{
|
|
|
|
amdgpu_run_thread = true;
|
|
|
|
amdgpu_c.notify_one();
|
|
|
|
}
|
2022-01-06 09:57:18 +00:00
|
|
|
}
|
2022-02-01 01:29:14 +00:00
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lk(mangoapp_m);
|
2022-04-07 08:28:48 +00:00
|
|
|
mangoapp_cv.wait(lk, []{return new_frame || params.no_display;});
|
2022-02-01 01:29:14 +00:00
|
|
|
new_frame = false;
|
|
|
|
}
|
2022-02-01 02:34:36 +00:00
|
|
|
|
2022-04-07 08:28:48 +00:00
|
|
|
check_keybinds(params, vendorID);
|
2022-01-06 09:57:18 +00:00
|
|
|
// Start the Dear ImGui frame
|
|
|
|
{
|
2022-02-01 02:34:36 +00:00
|
|
|
if (render(window)) {
|
|
|
|
// If we need to resize our window, give it another couple of rounds for the
|
|
|
|
// stupid display size stuff to propagate through ImGUI (using NDC and scaling
|
|
|
|
// in GL makes me a very unhappy boy.)
|
|
|
|
render(window);
|
|
|
|
render(window);
|
|
|
|
}
|
|
|
|
|
2022-04-07 08:28:48 +00:00
|
|
|
if (params.control >= 0) {
|
|
|
|
control_client_check(params.control, control_client, deviceName);
|
|
|
|
process_control_socket(control_client, params);
|
2022-01-20 00:24:01 +00:00
|
|
|
}
|
2022-01-06 09:57:18 +00:00
|
|
|
}
|
|
|
|
// Rendering
|
|
|
|
ImGui::Render();
|
2022-03-13 11:17:38 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glEnable(GL_BLEND);
|
2022-01-06 09:57:18 +00:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glClearColor(0, 0, 0, 0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
|
|
|
|
glfwSwapBuffers(window);
|
|
|
|
} else if (!mangoapp_paused) {
|
2022-03-13 11:17:38 +00:00
|
|
|
glfwIconifyWindow(window);
|
2022-06-05 09:11:38 +00:00
|
|
|
uint32_t value = 0;
|
|
|
|
XChangeProperty(x11_display, x11_window, overlay_atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&value, 1);
|
|
|
|
XSync(x11_display, 0);
|
2022-01-06 09:57:18 +00:00
|
|
|
mangoapp_paused = true;
|
2023-05-01 11:52:26 +00:00
|
|
|
{
|
|
|
|
amdgpu_run_thread = false;
|
|
|
|
amdgpu_c.notify_one();
|
|
|
|
}
|
2022-01-06 09:57:18 +00:00
|
|
|
std::unique_lock<std::mutex> lk(mangoapp_m);
|
2022-04-07 08:28:48 +00:00
|
|
|
mangoapp_cv.wait(lk, []{return !params.no_display;});
|
2021-09-06 06:21:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup
|
2022-03-13 11:17:38 +00:00
|
|
|
shutdown(window);
|
2021-09-06 06:21:10 +00:00
|
|
|
|
|
|
|
glfwTerminate();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|