#include #include #include #include #include #include #ifdef DEBUG #include #endif #include #include #include #include #define GLFW_INCLUDE_NONE #include #include "types.h" #include "defer.hpp" #include "mem.h" #include "str.h" #include "rntuple.h" #include "window.h" #include "app_state.h" // @Platform #include "platform_linux.h" namespace chr = std::chrono; #include "mem.cpp" #include "str.cpp" #include "rntuple.cpp" #include "render.cpp" #include "mainloop.cpp" using namespace ROOT::Experimental; internal b8 init_imgui(GLFWwindow* window) { IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void) io; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; ImGui::StyleColorsDark(); ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init("#version 400"); return true; } internal void glfw_error_callback(i32 error, const char *description) { fprintf(stderr, "GLFW error %d: %s\n", error, description); } internal GLFWwindow* init_glfw(i32 desired_win_width, i32 desired_win_height) { glfwSetErrorCallback(glfw_error_callback); glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); glfwWindowHint(GLFW_DEPTH_BITS, 32); #ifndef NDEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true); #endif GLFWwindow *window = glfwCreateWindow( desired_win_width, desired_win_height, "RNTuple Viewer", nullptr, nullptr ); glfwMakeContextCurrent(window); //glfwSetFramebufferSizeCallback(window, resize_keep_ratio); return window; } internal void app_cleanup(App_State &app) { os_stop_file_watch(app); os_unmap_file(app.inspected_fmem, app.inspected_file_size); if (app.inspected_file) fclose(app.inspected_file); app.inspected_file = nullptr; } int main(int argc, char **argv) { if (argc > 1 && argv[1][0] == '-') { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } // Collect arguments const char *ntpl_name = argc > 1 ? argv[1] : nullptr; const char *fname = argc > 2 ? argv[2] : nullptr; // Allocate program memory Arena *arena = arena_alloc(); if (!arena) { fprintf(stderr, "Failed to allocate memory\n"); return 1; } defer { arena_release(arena); }; // Init imgui and GLFW GLFWwindow *window = init_glfw(800, 600); if (!window) { fprintf(stderr, "Failed to init GLFW\n"); return 1; } defer { glfwTerminate(); }; if (!init_imgui(window)) { fprintf(stderr, "Failed to init Imgui\n"); return 1; } App_State app {}; defer { app_cleanup(app); }; // Open and map the file if (fname) { os_open_and_map_file(fname, app); // Watch file for changes (to adapt the displayed file size - otherwise // we may try to access invalid memory when the file gets shrunk) os_start_file_watch(fname, app); } app.ntpl_name = ntpl_name; app.rntinfo = get_rntuple_info(arena, fname, ntpl_name); // Start main loop run_main_loop(window, arena, app); return 0; }