From 0f5d8730b0bff6e07f3bce85451715a52ec4388e Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 20 Oct 2024 01:19:08 -0400 Subject: [PATCH] Media Layer + Launching Tweaks --- dependencies/LIEF/src | 2 +- launcher/src/bootstrap.cpp | 85 ++-- launcher/src/bootstrap.h | 3 +- launcher/src/mods.cpp | 15 +- launcher/src/patchelf.cpp | 83 +++- launcher/src/patchelf.h | 11 +- media-layer/CMakeLists.txt | 3 - media-layer/core/CMakeLists.txt | 4 +- media-layer/core/src/base.cpp | 11 +- media-layer/core/src/cursor.cpp | 108 ++++ media-layer/core/src/events.cpp | 275 +++++++++++ media-layer/core/src/media.cpp | 467 +----------------- media-layer/core/src/media.h | 25 + media-layer/core/src/util.cpp | 67 +++ media-layer/extras/CMakeLists.txt | 5 - media-layer/extras/src/SDL.c | 36 -- media-layer/gles/src/passthrough.cpp | 114 ++--- media-layer/include/EGL/egl.h | 12 - media-layer/include/GLES/gl.h | 118 ++--- media-layer/include/SDL/SDL.h | 18 +- media-layer/include/X11/Xlib.h | 5 - media-layer/include/media-layer/internal.h | 12 - media-layer/trampoline/CMakeLists.txt | 2 +- media-layer/trampoline/src/GLESv1_CM.cpp | 168 +++---- .../trampoline/src/media-layer-core.cpp | 12 +- mods/CMakeLists.txt | 1 + mods/include/mods/textures/textures.h | 2 +- mods/src/atlas/atlas.cpp | 12 +- mods/src/benchmark/benchmark.cpp | 2 +- mods/src/compat/compat-internal.h | 1 + mods/src/compat/compat.cpp | 17 +- mods/src/compat/sdl.cpp | 43 ++ mods/src/input/misc.cpp | 4 +- mods/src/misc/api.cpp | 2 +- mods/src/misc/graphics.cpp | 80 ++- mods/src/misc/ui.cpp | 16 +- mods/src/multidraw/buffer.cpp | 12 +- mods/src/multidraw/glue.cpp | 40 +- mods/src/screenshot/screenshot.cpp | 6 +- mods/src/server/server.cpp | 2 +- mods/src/shading/lighting.cpp | 68 +-- mods/src/shading/tesselator.cpp | 76 ++- mods/src/skin/loader.cpp | 8 +- mods/src/textures/textures.cpp | 22 +- mods/src/title-screen/splashes.cpp | 14 +- mods/src/title-screen/title-screen.cpp | 2 +- 46 files changed, 1047 insertions(+), 1044 deletions(-) create mode 100644 media-layer/core/src/cursor.cpp create mode 100644 media-layer/core/src/events.cpp create mode 100644 media-layer/core/src/media.h create mode 100644 media-layer/core/src/util.cpp delete mode 100644 media-layer/extras/CMakeLists.txt delete mode 100644 media-layer/extras/src/SDL.c delete mode 100644 media-layer/include/media-layer/internal.h create mode 100644 mods/src/compat/sdl.cpp diff --git a/dependencies/LIEF/src b/dependencies/LIEF/src index 16962f2f36..f4d68357cb 160000 --- a/dependencies/LIEF/src +++ b/dependencies/LIEF/src @@ -1 +1 @@ -Subproject commit 16962f2f36a51b2acefad9cec3622f6de5730aa3 +Subproject commit f4d68357cb51fc251555e69e2679f5bb11af75ea diff --git a/launcher/src/bootstrap.cpp b/launcher/src/bootstrap.cpp index 53e7e19735..6a4d1c9990 100644 --- a/launcher/src/bootstrap.cpp +++ b/launcher/src/bootstrap.cpp @@ -101,22 +101,57 @@ void bootstrap(const options_t &options) { } } - // Fix MCPI Dependencies - char new_mcpi_exe_path[] = MCPI_PATCHED_DIR "/XXXXXX"; - std::string linker; + // Configure Preloaded Objects + std::vector mcpi_ld_preload; { // Log - DEBUG("Patching ELF Dependencies..."); + DEBUG("Locating Mods..."); + + // ARM Components + mcpi_ld_preload = bootstrap_mods(binary_directory); + } + + // Configure Library Search Path + std::vector mcpi_ld_path; + { + // Log + DEBUG("Setting Linker Search Paths..."); + + // Library Search Path For ARM Components + { + // Add ARM Library Directory + mcpi_ld_path.push_back("lib/arm"); + + // Add ARM Sysroot Libraries (Ensure Priority) (Ignore On Actual ARM System) +#ifdef MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN + mcpi_ld_path.push_back("sysroot/lib"); + mcpi_ld_path.push_back("sysroot/lib/arm-linux-gnueabihf"); + mcpi_ld_path.push_back("sysroot/usr/lib"); + mcpi_ld_path.push_back("sysroot/usr/lib/arm-linux-gnueabihf"); +#endif + + // Fix Paths + for (std::string &path : mcpi_ld_path) { + path = binary_directory + '/' + path; + } + } + } + + // Fix MCPI Dependencies + char new_mcpi_exe_path[] = MCPI_PATCHED_DIR "/XXXXXX"; + { + // Log + DEBUG("Patching ELF..."); // Find Linker - linker = "/lib/ld-linux-armhf.so.3"; + std::string linker = "/lib/ld-linux-armhf.so.3"; #ifdef MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN // Use ARM Sysroot Linker linker = binary_directory + "/sysroot" + linker; #endif // Patch - patch_mcpi_elf_dependencies(game_binary.c_str(), new_mcpi_exe_path); + patch_mcpi_elf_dependencies(game_binary, new_mcpi_exe_path, linker, mcpi_ld_path, mcpi_ld_preload); // Verify if (!starts_with(new_mcpi_exe_path, MCPI_PATCHED_DIR)) { @@ -132,37 +167,6 @@ void bootstrap(const options_t &options) { set_and_print_env(_MCPI_VANILLA_ASSETS_PATH_ENV, assets_path.c_str()); } - // Configure Library Search Path - std::string mcpi_ld_path = ""; - { - // Log - DEBUG("Setting Linker Search Paths..."); - - // Library Search Path For ARM Components - { - // Add ARM Library Directory - mcpi_ld_path += binary_directory + "/lib/arm:"; - - // Add ARM Sysroot Libraries (Ensure Priority) (Ignore On Actual ARM System) -#ifdef MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN - mcpi_ld_path += binary_directory + "/sysroot/lib:"; - mcpi_ld_path += binary_directory + "/sysroot/lib/arm-linux-gnueabihf:"; - mcpi_ld_path += binary_directory + "/sysroot/usr/lib:"; - mcpi_ld_path += binary_directory + "/sysroot/usr/lib/arm-linux-gnueabihf:"; -#endif - } - } - - // Configure Preloaded Objects - std::string mcpi_ld_preload; - { - // Log - DEBUG("Locating Mods..."); - - // ARM Components - mcpi_ld_preload = bootstrap_mods(binary_directory); - } - // Start Game INFO("Starting Game..."); @@ -178,13 +182,6 @@ void bootstrap(const options_t &options) { args.push_back("0x40000"); // Arbitrary Value (Aligns To 4k And 16k Page Sizes) #endif - // Setup Linker - args.push_back(linker); - args.push_back("--library-path"); - args.push_back(mcpi_ld_path); - args.push_back("--preload"); - args.push_back(mcpi_ld_preload); - // Specify MCPI Binary args.push_back(new_mcpi_exe_path); diff --git a/launcher/src/bootstrap.h b/launcher/src/bootstrap.h index 452fa7847a..2982a51a94 100644 --- a/launcher/src/bootstrap.h +++ b/launcher/src/bootstrap.h @@ -1,9 +1,10 @@ #pragma once #include +#include #include "options/parser.h" void bootstrap(const options_t &options); void copy_sdk(const std::string &binary_directory, bool log_with_debug); -std::string bootstrap_mods(const std::string &binary_directory); +std::vector bootstrap_mods(const std::string &binary_directory); diff --git a/launcher/src/mods.cpp b/launcher/src/mods.cpp index ec44b019bd..b30eb0cc58 100644 --- a/launcher/src/mods.cpp +++ b/launcher/src/mods.cpp @@ -8,14 +8,14 @@ #include "bootstrap.h" // Get All Mods In Folder -static void load(std::string &ld_preload, const std::string &folder, int recursion_limit = 128); -static void handle_file(std::string &ld_preload, const std::string &file, const int recursion_limit) { +static void load(std::vector &ld_preload, const std::string &folder, int recursion_limit = 128); +static void handle_file(std::vector &ld_preload, const std::string &file, const int recursion_limit) { // Check Type struct stat file_stat = {}; lstat(file.c_str(), &file_stat); if (S_ISDIR(file_stat.st_mode)) { // Recurse Into Directory - load(ld_preload, std::string(file) + "/", recursion_limit - 1); + load(ld_preload, std::string(file) + '/', recursion_limit - 1); } else if (S_ISLNK(file_stat.st_mode)) { // Resolve Symlink char *resolved_file = realpath(file.c_str(), nullptr); @@ -27,7 +27,8 @@ static void handle_file(std::string &ld_preload, const std::string &file, const const int result = access(file.c_str(), R_OK); if (result == 0) { // Add To LD_PRELOAD - ld_preload += file + ":"; + DEBUG("Found Mod: %s", file.c_str()); + ld_preload.push_back(file); } else if (result == -1 && errno != 0) { // Fail WARN("Unable To Access: %s: %s", file.c_str(), strerror(errno)); @@ -35,7 +36,7 @@ static void handle_file(std::string &ld_preload, const std::string &file, const } } } -static void load(std::string &ld_preload, const std::string &folder, const int recursion_limit) { +static void load(std::vector &ld_preload, const std::string &folder, const int recursion_limit) { // Check Recursion if (recursion_limit <= 0) { ERR("Reached Recursion Limit While Loading Mods"); @@ -74,9 +75,9 @@ static void load(std::string &ld_preload, const std::string &folder, const int r // Bootstrap Mods #define SUBDIRECTORY_FOR_MODS "/mods/" -std::string bootstrap_mods(const std::string &binary_directory) { +std::vector bootstrap_mods(const std::string &binary_directory) { // Prepare - std::string preload = ""; + std::vector preload; // ~/.minecraft-pi/mods { diff --git a/launcher/src/patchelf.cpp b/launcher/src/patchelf.cpp index 60300ef45c..8ac235f741 100644 --- a/launcher/src/patchelf.cpp +++ b/launcher/src/patchelf.cpp @@ -1,5 +1,6 @@ #include #include +#include #include @@ -16,7 +17,7 @@ static void duplicate_mcpi_executable(char *new_path) { ensure_directory(MCPI_PATCHED_DIR); // Generate New File - int new_file_fd = mkstemp(new_path); + const int new_file_fd = mkstemp(new_path); if (new_file_fd == -1) { ERR("Unable To Create Temporary File: %s", strerror(errno)); } @@ -24,34 +25,72 @@ static void duplicate_mcpi_executable(char *new_path) { } // Fix MCPI Dependencies -static const char *libraries_to_remove[] = { - "libbcm_host.so", - "libX11.so.6", - "libEGL.so", - "libGLESv2.so", - "libSDL-1.2.so.0" +static std::vector needed_libraries = { + "libmedia-layer-core.so", + "libpng12.so.0", + "libstdc++.so.6", + "libm.so.6", + "libgcc_s.so.1", + "libc.so.6", + "libpthread.so.0" }; -static const char *libraries_to_add[] = { - "libmedia-layer-core.so" +static std::vector function_prefixes_to_patch = { + "SDL_", + "gl" }; -void patch_mcpi_elf_dependencies(const char *original_path, char *new_path) { +void patch_mcpi_elf_dependencies(const std::string &original_path, char *new_path, const std::string &interpreter, const std::vector &rpath, const std::vector &mods) { // Duplicate MCPI executable into /tmp so it can be modified. duplicate_mcpi_executable(new_path); - // Patch File - { - std::unique_ptr binary = LIEF::ELF::Parser::parse(original_path); - for (size_t i = 0; i < (sizeof (libraries_to_remove) / sizeof (const char *)); i++) { - binary->remove_library(libraries_to_remove[i]); - } - for (size_t i = 0; i < (sizeof (libraries_to_add) / sizeof (const char *)); i++) { - binary->add_library(libraries_to_add[i]); - } - LIEF::ELF::Builder builder{*binary}; - builder.build(); - builder.write(new_path); + // Load Binary + std::unique_ptr binary = LIEF::ELF::Parser::parse(original_path); + + // Set Interpreter + if (!interpreter.empty()) { + binary->interpreter(interpreter); } + // Remove Existing Needed Libraries + std::vector to_remove; + for (const LIEF::ELF::DynamicEntry &entry : binary->dynamic_entries()) { + const LIEF::ELF::DynamicEntryLibrary *library = dynamic_cast(&entry); + if (library) { + to_remove.push_back(library->name()); + } + } + for (const std::string &library : to_remove) { + binary->remove_library(library); + } + + // Setup RPath + binary->add(LIEF::ELF::DynamicEntryRpath(rpath)); + + // Add Libraries + std::vector all_libraries; + for (const std::vector &list : {mods, needed_libraries}) { + all_libraries.insert(all_libraries.end(), list.begin(), list.end()); + } + for (const std::string &library : all_libraries | std::views::reverse) { + binary->add_library(library); + } + + // Fix Symbol Names + for (LIEF::ELF::Symbol &symbol : binary->dynamic_symbols()) { + if (symbol.is_function()) { + for (const std::string &prefix : function_prefixes_to_patch) { + if (symbol.name().rfind(prefix, 0) == 0) { + symbol.name("media_" + symbol.name()); + break; + } + } + } + } + + // Write Binary + LIEF::ELF::Builder builder{*binary}; + builder.build(); + builder.write(new_path); + // Fix Permissions if (chmod(new_path, S_IRUSR | S_IXUSR) != 0) { ERR("Unable To Set File Permissions: %s: %s", new_path, strerror(errno)); diff --git a/launcher/src/patchelf.h b/launcher/src/patchelf.h index 4b2f1f62ad..55ee213c95 100644 --- a/launcher/src/patchelf.h +++ b/launcher/src/patchelf.h @@ -1,13 +1,8 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif +#include +#include #define MCPI_PATCHED_DIR "/tmp/.minecraft-pi-patched" -void patch_mcpi_elf_dependencies(const char *original_path, char *new_path); - -#ifdef __cplusplus -} -#endif +void patch_mcpi_elf_dependencies(const std::string &original_path, char *new_path, const std::string &interpreter, const std::vector &rpath, const std::vector &mods); diff --git a/media-layer/CMakeLists.txt b/media-layer/CMakeLists.txt index bdf9be1784..65ecf6f363 100644 --- a/media-layer/CMakeLists.txt +++ b/media-layer/CMakeLists.txt @@ -19,9 +19,6 @@ if(BUILD_ARM_COMPONENTS) ) endif() -# Add Extras -add_subdirectory(extras) - # Add Core if(BUILD_MEDIA_LAYER_CORE) add_subdirectory(gles) diff --git a/media-layer/core/CMakeLists.txt b/media-layer/core/CMakeLists.txt index 0f1a562747..79c7df4191 100644 --- a/media-layer/core/CMakeLists.txt +++ b/media-layer/core/CMakeLists.txt @@ -4,10 +4,12 @@ project(media-layer-core) set(CORE_SRC src/base.cpp src/media.cpp + src/cursor.cpp + src/util.cpp + src/events.cpp src/audio/api.cpp src/audio/engine.c src/audio/file.cpp - $ ) # Build diff --git a/media-layer/core/src/base.cpp b/media-layer/core/src/base.cpp index 009ee7b071..814e32d094 100644 --- a/media-layer/core/src/base.cpp +++ b/media-layer/core/src/base.cpp @@ -2,13 +2,14 @@ #include -#include #include #include +#include "media.h" + // SDL Is Replaced With GLFW -int SDL_Init(__attribute__((unused)) uint32_t flags) { +int media_SDL_Init(__attribute__((unused)) uint32_t flags) { return 0; } @@ -16,9 +17,9 @@ int SDL_Init(__attribute__((unused)) uint32_t flags) { static std::vector queue; -int SDL_PollEvent(SDL_Event *event) { +int media_SDL_PollEvent(SDL_Event *event) { // Handle External Events - _media_handle_SDL_PollEvent(); + _media_handle_media_SDL_PollEvent(); // Poll Event int ret; @@ -32,7 +33,7 @@ int SDL_PollEvent(SDL_Event *event) { return ret; } -int SDL_PushEvent(SDL_Event *event) { +int media_SDL_PushEvent(SDL_Event *event) { queue.push_back(*event); return 1; } diff --git a/media-layer/core/src/cursor.cpp b/media-layer/core/src/cursor.cpp new file mode 100644 index 0000000000..84d499ce3e --- /dev/null +++ b/media-layer/core/src/cursor.cpp @@ -0,0 +1,108 @@ +#include "media.h" + +// Enable/Disable Raw Mouse Motion +bool raw_mouse_motion_enabled = true; +void media_set_raw_mouse_motion_enabled(const int enabled) { + raw_mouse_motion_enabled = enabled; + if (glfw_window) { + glfwSetInputMode(glfw_window, GLFW_RAW_MOUSE_MOTION, GLFW_FALSE); + } + if (!raw_mouse_motion_enabled) { + WARN("Raw mouse motion has been DISABLED, this IS NOT recommended, and should only ever be used on systems that don't support or have broken raw mouse motion."); + } +} + +// Store Cursor State +static bool cursor_grabbed = false; +static bool cursor_visible = true; + +// Ignore Relative Cursor Motion +bool ignore_relative_motion = false; + +// Update GLFW Cursor State (Client Only) +void _media_update_cursor() { + if (glfw_window) { + // Get New State + const bool new_cursor_visible = is_interactable ? cursor_visible : true; + const bool new_cursor_grabbed = is_interactable ? cursor_grabbed : false; + + // Store Old Mode + const int old_mode = glfwGetInputMode(glfw_window, GLFW_CURSOR); + + // Handle Cursor Visibility + int new_mode; + if (!new_cursor_visible) { + if (new_cursor_grabbed) { + new_mode = GLFW_CURSOR_DISABLED; + } else { + new_mode = GLFW_CURSOR_HIDDEN; + } + } else { + new_mode = GLFW_CURSOR_NORMAL; + } + if (new_mode != old_mode) { + // Ignore Relative Cursor Motion When Locking + if (new_mode == GLFW_CURSOR_DISABLED && old_mode != GLFW_CURSOR_DISABLED) { + ignore_relative_motion = true; + } + + // Set New Mode + glfwSetInputMode(glfw_window, GLFW_CURSOR, new_mode); + + // Handle Cursor Lock/Unlock + if ((new_mode == GLFW_CURSOR_DISABLED && old_mode != GLFW_CURSOR_DISABLED) || (new_mode != GLFW_CURSOR_DISABLED && old_mode == GLFW_CURSOR_DISABLED)) { + // Use Raw Mouse Motion + if (raw_mouse_motion_enabled) { + glfwSetInputMode(glfw_window, GLFW_RAW_MOUSE_MOTION, new_mode == GLFW_CURSOR_DISABLED ? GLFW_TRUE : GLFW_FALSE); + } + + // Request Focus + glfwRequestWindowAttention(glfw_window); + } + + // Reset Mouse Position When Unlocking + if (new_mode != GLFW_CURSOR_DISABLED && old_mode == GLFW_CURSOR_DISABLED) { + double cursor_x; + double cursor_y; + glfwGetCursorPos(glfw_window, &cursor_x, &cursor_y); + _media_glfw_motion(glfw_window, cursor_x, cursor_y); + } + } + } +} + +// Fix SDL Cursor Visibility/Grabbing +SDL_GrabMode media_SDL_WM_GrabInput(const SDL_GrabMode mode) { + if (mode == SDL_GRAB_QUERY) { + // Query + return cursor_grabbed ? SDL_GRAB_ON : SDL_GRAB_OFF; + } else if (mode == SDL_GRAB_ON) { + // Store State + cursor_grabbed = true; + } else if (mode == SDL_GRAB_OFF) { + // Store State + cursor_grabbed = false; + } + // Update Cursor GLFW State (Client Only) + _media_update_cursor(); + // Return + return mode; +} + +// Stub SDL Cursor Visibility +int media_SDL_ShowCursor(const int toggle) { + if (toggle == SDL_QUERY) { + // Query + return cursor_visible ? SDL_ENABLE : SDL_DISABLE; + } else if (toggle == SDL_ENABLE) { + // Store State + cursor_visible = true; + } else if (toggle == SDL_DISABLE) { + // Store State + cursor_visible = false; + } + // Update Cursor GLFW State (Client Only) + _media_update_cursor(); + // Return + return toggle; +} \ No newline at end of file diff --git a/media-layer/core/src/events.cpp b/media-layer/core/src/events.cpp new file mode 100644 index 0000000000..67f6562b42 --- /dev/null +++ b/media-layer/core/src/events.cpp @@ -0,0 +1,275 @@ +#include "media.h" + +// Convert GLFW Key To SDL Key +static SDLKey glfw_key_to_sdl_key(const int key) { + switch (key) { + // Movement + case GLFW_KEY_W: + return SDLK_w; + case GLFW_KEY_A: + return SDLK_a; + case GLFW_KEY_S: + return SDLK_s; + case GLFW_KEY_D: + return SDLK_d; + case GLFW_KEY_SPACE: + return SDLK_SPACE; + case GLFW_KEY_LEFT_SHIFT: + return SDLK_LSHIFT; + case GLFW_KEY_RIGHT_SHIFT: + return SDLK_RSHIFT; + // Inventory + case GLFW_KEY_E: + return SDLK_e; + // Drop Item + case GLFW_KEY_Q: + return SDLK_q; + // Toolbar + case GLFW_KEY_1: + return SDLK_1; + case GLFW_KEY_2: + return SDLK_2; + case GLFW_KEY_3: + return SDLK_3; + case GLFW_KEY_4: + return SDLK_4; + case GLFW_KEY_5: + return SDLK_5; + case GLFW_KEY_6: + return SDLK_6; + case GLFW_KEY_7: + return SDLK_7; + case GLFW_KEY_8: + return SDLK_8; + case GLFW_KEY_9: + return SDLK_9; + case GLFW_KEY_0: + return SDLK_0; + // UI Control + case GLFW_KEY_ESCAPE: + return SDLK_ESCAPE; + case GLFW_KEY_UP: + return SDLK_UP; + case GLFW_KEY_DOWN: + return SDLK_DOWN; + case GLFW_KEY_LEFT: + return SDLK_LEFT; + case GLFW_KEY_RIGHT: + return SDLK_RIGHT; + case GLFW_KEY_TAB: + return SDLK_TAB; + case GLFW_KEY_ENTER: + return SDLK_RETURN; + case GLFW_KEY_BACKSPACE: + return SDLK_BACKSPACE; + case GLFW_KEY_DELETE: + return SDLK_DELETE; + // Fullscreen + case GLFW_KEY_F11: + return SDLK_F11; + // Screenshot + case GLFW_KEY_F2: + return SDLK_F2; + // Debug + case GLFW_KEY_F3: + return SDLK_F3; + // Hide GUI + case GLFW_KEY_F1: + return SDLK_F1; + // Third Person + case GLFW_KEY_F5: + return SDLK_F5; + // Chat + case GLFW_KEY_T: + return SDLK_t; + // Unknown + default: + return SDLK_UNKNOWN; + } +} + +// Convert GLFW Key Modifier To SDL Key Modifier +static SDLMod glfw_modifier_to_sdl_modifier(const int mods) { + int ret = KMOD_NONE; + // Control + if ((mods & GLFW_MOD_CONTROL) != 0) { + ret |= KMOD_CTRL; + } + // Shift + if ((mods & GLFW_MOD_SHIFT) != 0) { + ret |= KMOD_SHIFT; + } + // Alt + if ((mods & GLFW_MOD_ALT) != 0) { + ret |= KMOD_ALT; + } + // Return + return SDLMod(ret); +} + +// Pass Key Presses To SDL +static void glfw_key_raw(int key, int scancode, int action, int mods) { + SDL_Event event1; + bool up = action == GLFW_RELEASE; + event1.type = up ? SDL_KEYUP : SDL_KEYDOWN; + event1.key.state = up ? SDL_RELEASED : SDL_PRESSED; + event1.key.keysym.scancode = scancode; + event1.key.keysym.mod = glfw_modifier_to_sdl_modifier(mods); + event1.key.keysym.sym = glfw_key_to_sdl_key(key); + media_SDL_PushEvent(&event1); + // Allow MCPI To Access Original GLFW Keycode + SDL_Event event2; + event2.type = SDL_USEREVENT; + event2.user.code = USER_EVENT_REAL_KEY; + event2.user.data1 = event1.key.state; + event2.user.data2 = key; + media_SDL_PushEvent(&event2); +} +static void glfw_key(__attribute__((unused)) GLFWwindow *window, const int key, const int scancode, const int action, const int mods) { + if (is_interactable) { + glfw_key_raw(key, scancode, action, mods); + } +} + +// Pass Text To Minecraft +static void character_event(char c) { + if (!is_interactable) { + return; + } + // SDL_UserEvent Is Never Used In MCPI, So It Is Repurposed For Character Events + SDL_Event event; + event.type = SDL_USEREVENT; + event.user.code = USER_EVENT_CHARACTER; + event.user.data1 = (int) c; + media_SDL_PushEvent(&event); +} +static void codepoint_to_utf8(unsigned char *const buffer, const unsigned int code) { + // https://stackoverflow.com/a/42013433/16198887 + if (code <= 0x7f) { + buffer[0] = code; + } else if (code <= 0x7ff) { + buffer[0] = 0xc0 | (code >> 6); // 110xxxxx + buffer[1] = 0x80 | (code & 0x3f); // 10xxxxxx + } else if (code <= 0xffff) { + buffer[0] = 0xe0 | (code >> 12); // 1110xxxx + buffer[1] = 0x80 | ((code >> 6) & 0x3f); // 10xxxxxx + buffer[2] = 0x80 | (code & 0x3f); // 10xxxxxx + } else if (code <= 0x10ffff) { + buffer[0] = 0xf0 | (code >> 18); // 11110xxx + buffer[1] = 0x80 | ((code >> 12) & 0x3f); // 10xxxxxx + buffer[2] = 0x80 | ((code >> 6) & 0x3f); // 10xxxxxx + buffer[3] = 0x80 | (code & 0x3f); // 10xxxxxx + } +} +static void glfw_char(__attribute__((unused)) GLFWwindow *window, const unsigned int codepoint) { + // Convert + size_t str_size = 4 /* Maximum UTF-8 character size */ + 1 /* NULL-terminator */; + char str[str_size] = {}; + codepoint_to_utf8((unsigned char *) str, codepoint); + char *cp437_str = to_cp437(str); + // Send Event + for (int i = 0; cp437_str[i] != '\0'; i++) { + character_event(cp437_str[i]); + } + // Free + free(cp437_str); +} + +// Convert Screen Coordinates To Pixels +static void convert_to_pixels(GLFWwindow *window, double *xpos, double *ypos) { + // Skip If Cursor Is Grabbed + if (media_SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON && raw_mouse_motion_enabled) { + return; + } + // Get Window Size + int window_width; + int window_height; + glfwGetWindowSize(window, &window_width, &window_height); + // Get Framebuffer Size + int framebuffer_width; + int framebuffer_height; + glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height); + // Calculate Ratios + const double width_ratio = ((double) framebuffer_width) / ((double) window_width); + const double height_ratio = ((double) framebuffer_height) / ((double) window_height); + // Multiply + *xpos *= width_ratio; + *ypos *= height_ratio; +} + +// Last Mouse Location +static double last_mouse_x = 0; +static double last_mouse_y = 0; + +// Pass Mouse Movement To SDL +void _media_glfw_motion(__attribute__((unused)) GLFWwindow *window, double xpos, double ypos) { + convert_to_pixels(window, &xpos, &ypos); + if (is_interactable) { + SDL_Event event; + event.type = SDL_MOUSEMOTION; + event.motion.x = uint16_t(xpos); + event.motion.y = uint16_t(ypos); + event.motion.xrel = !ignore_relative_motion ? (xpos - last_mouse_x) : 0; + event.motion.yrel = !ignore_relative_motion ? (ypos - last_mouse_y) : 0; + media_SDL_PushEvent(&event); + } + ignore_relative_motion = false; + last_mouse_x = xpos; + last_mouse_y = ypos; +} + +// Create And Push SDL Mouse Click Event +static void click_event(int button, bool up) { + SDL_Event event; + event.type = up ? SDL_MOUSEBUTTONUP : SDL_MOUSEBUTTONDOWN; + event.button.x = uint16_t(last_mouse_x); + event.button.y = uint16_t(last_mouse_y); + event.button.state = up ? SDL_RELEASED : SDL_PRESSED; + event.button.button = button; + media_SDL_PushEvent(&event); +} + +// Pass Mouse Click To SDL +static void glfw_click_raw(const int button, const int action) { + const bool up = action == GLFW_RELEASE; + const int sdl_button = button == GLFW_MOUSE_BUTTON_RIGHT ? SDL_BUTTON_RIGHT : (button == GLFW_MOUSE_BUTTON_LEFT ? SDL_BUTTON_LEFT : SDL_BUTTON_MIDDLE); + click_event(sdl_button, up); +} +static void glfw_click(__attribute__((unused)) GLFWwindow *window, const int button, const int action, __attribute__((unused)) int mods) { + if (is_interactable) { + glfw_click_raw(button, action); + } +} + +// Pass Mouse Scroll To SDL +static void glfw_scroll(__attribute__((unused)) GLFWwindow *window, __attribute__((unused)) double xoffset, double yoffset) { + if (is_interactable && yoffset != 0) { + const int sdl_button = yoffset > 0 ? SDL_BUTTON_WHEELUP : SDL_BUTTON_WHEELDOWN; + click_event(sdl_button, false); + click_event(sdl_button, true); + } +} + +// Intercept SDL Events +void _media_handle_media_SDL_PollEvent() { + if (glfw_window) { + // Process GLFW Events + glfwPollEvents(); + // Close Window + if (glfwWindowShouldClose(glfw_window)) { + SDL_Event event; + event.type = SDL_QUIT; + media_SDL_PushEvent(&event); + glfwSetWindowShouldClose(glfw_window, GLFW_FALSE); + } + } +} + +// Register Event Listeners +void _media_register_event_listeners() { + glfwSetKeyCallback(glfw_window, glfw_key); + glfwSetCharCallback(glfw_window, glfw_char); + glfwSetCursorPosCallback(glfw_window, _media_glfw_motion); + glfwSetMouseButtonCallback(glfw_window, glfw_click); + glfwSetScrollCallback(glfw_window, glfw_scroll); +} \ No newline at end of file diff --git a/media-layer/core/src/media.cpp b/media-layer/core/src/media.cpp index 4b256ae6db..00b14902a0 100644 --- a/media-layer/core/src/media.cpp +++ b/media-layer/core/src/media.cpp @@ -1,309 +1,21 @@ #include #include -#include -#include - -#define GLFW_INCLUDE_NONE -#include - -#include -#include - +#include "media.h" #include "audio/engine.h" -// Allow Disabling Interaction -static void update_cursor(); -static int is_interactable = 1; -void media_set_interactable(const int toggle) { - if (bool(toggle) != is_interactable) { - is_interactable = toggle; - update_cursor(); - } -} - -// Store Cursor State -static bool cursor_grabbed = false; -static bool cursor_visible = true; - -// Track If Raw Mouse Motion Is Enabled -static bool raw_mouse_motion_enabled = true; - // Window -static GLFWwindow *glfw_window = nullptr; +GLFWwindow *glfw_window = nullptr; // Handle GLFW Error static void glfw_error(__attribute__((unused)) int error, const char *description) { WARN("GLFW Error: %s", description); } -// Convert GLFW Key To SDL Key -static SDLKey glfw_key_to_sdl_key(const int key) { - switch (key) { - // Movement - case GLFW_KEY_W: - return SDLK_w; - case GLFW_KEY_A: - return SDLK_a; - case GLFW_KEY_S: - return SDLK_s; - case GLFW_KEY_D: - return SDLK_d; - case GLFW_KEY_SPACE: - return SDLK_SPACE; - case GLFW_KEY_LEFT_SHIFT: - return SDLK_LSHIFT; - case GLFW_KEY_RIGHT_SHIFT: - return SDLK_RSHIFT; - // Inventory - case GLFW_KEY_E: - return SDLK_e; - // Drop Item - case GLFW_KEY_Q: - return SDLK_q; - // Toolbar - case GLFW_KEY_1: - return SDLK_1; - case GLFW_KEY_2: - return SDLK_2; - case GLFW_KEY_3: - return SDLK_3; - case GLFW_KEY_4: - return SDLK_4; - case GLFW_KEY_5: - return SDLK_5; - case GLFW_KEY_6: - return SDLK_6; - case GLFW_KEY_7: - return SDLK_7; - case GLFW_KEY_8: - return SDLK_8; - case GLFW_KEY_9: - return SDLK_9; - case GLFW_KEY_0: - return SDLK_0; - // UI Control - case GLFW_KEY_ESCAPE: - return SDLK_ESCAPE; - case GLFW_KEY_UP: - return SDLK_UP; - case GLFW_KEY_DOWN: - return SDLK_DOWN; - case GLFW_KEY_LEFT: - return SDLK_LEFT; - case GLFW_KEY_RIGHT: - return SDLK_RIGHT; - case GLFW_KEY_TAB: - return SDLK_TAB; - case GLFW_KEY_ENTER: - return SDLK_RETURN; - case GLFW_KEY_BACKSPACE: - return SDLK_BACKSPACE; - case GLFW_KEY_DELETE: - return SDLK_DELETE; - // Fullscreen - case GLFW_KEY_F11: - return SDLK_F11; - // Screenshot - case GLFW_KEY_F2: - return SDLK_F2; - // Debug - case GLFW_KEY_F3: - return SDLK_F3; - // Hide GUI - case GLFW_KEY_F1: - return SDLK_F1; - // Third Person - case GLFW_KEY_F5: - return SDLK_F5; - // Chat - case GLFW_KEY_T: - return SDLK_t; - // Unknown - default: - return SDLK_UNKNOWN; - } -} - -// Convert GLFW Key Modifier To SDL Key Modifier -static SDLMod glfw_modifier_to_sdl_modifier(const int mods) { - int ret = KMOD_NONE; - // Control - if ((mods & GLFW_MOD_CONTROL) != 0) { - ret |= KMOD_CTRL; - } - // Shift - if ((mods & GLFW_MOD_SHIFT) != 0) { - ret |= KMOD_SHIFT; - } - // Alt - if ((mods & GLFW_MOD_ALT) != 0) { - ret |= KMOD_ALT; - } - // Return - return SDLMod(ret); -} - -// Pass Key Presses To SDL -static void glfw_key_raw(int key, int scancode, int action, int mods) { - SDL_Event event1; - bool up = action == GLFW_RELEASE; - event1.type = up ? SDL_KEYUP : SDL_KEYDOWN; - event1.key.state = up ? SDL_RELEASED : SDL_PRESSED; - event1.key.keysym.scancode = scancode; - event1.key.keysym.mod = glfw_modifier_to_sdl_modifier(mods); - event1.key.keysym.sym = glfw_key_to_sdl_key(key); - SDL_PushEvent(&event1); - // Allow MCPI To Access Original GLFW Keycode - SDL_Event event2; - event2.type = SDL_USEREVENT; - event2.user.code = USER_EVENT_REAL_KEY; - event2.user.data1 = event1.key.state; - event2.user.data2 = key; - SDL_PushEvent(&event2); -} -static void glfw_key(__attribute__((unused)) GLFWwindow *window, const int key, const int scancode, const int action, const int mods) { - if (is_interactable) { - glfw_key_raw(key, scancode, action, mods); - } -} - -// Pass Text To Minecraft -static void character_event(char c) { - if (!is_interactable) { - return; - } - // SDL_UserEvent Is Never Used In MCPI, So It Is Repurposed For Character Events - SDL_Event event; - event.type = SDL_USEREVENT; - event.user.code = USER_EVENT_CHARACTER; - event.user.data1 = (int) c; - SDL_PushEvent(&event); -} -static void codepoint_to_utf8(unsigned char *const buffer, const unsigned int code) { - // https://stackoverflow.com/a/42013433/16198887 - if (code <= 0x7f) { - buffer[0] = code; - } else if (code <= 0x7ff) { - buffer[0] = 0xc0 | (code >> 6); // 110xxxxx - buffer[1] = 0x80 | (code & 0x3f); // 10xxxxxx - } else if (code <= 0xffff) { - buffer[0] = 0xe0 | (code >> 12); // 1110xxxx - buffer[1] = 0x80 | ((code >> 6) & 0x3f); // 10xxxxxx - buffer[2] = 0x80 | (code & 0x3f); // 10xxxxxx - } else if (code <= 0x10ffff) { - buffer[0] = 0xf0 | (code >> 18); // 11110xxx - buffer[1] = 0x80 | ((code >> 12) & 0x3f); // 10xxxxxx - buffer[2] = 0x80 | ((code >> 6) & 0x3f); // 10xxxxxx - buffer[3] = 0x80 | (code & 0x3f); // 10xxxxxx - } -} -static void glfw_char(__attribute__((unused)) GLFWwindow *window, const unsigned int codepoint) { - // Convert - size_t str_size = 4 /* Maximum UTF-8 character size */ + 1 /* NULL-terminator */; - char str[str_size] = {}; - codepoint_to_utf8((unsigned char *) str, codepoint); - char *cp437_str = to_cp437(str); - // Send Event - for (int i = 0; cp437_str[i] != '\0'; i++) { - character_event(cp437_str[i]); - } - // Free - free(cp437_str); -} - -// Last Mouse Location -static double last_mouse_x = 0; -static double last_mouse_y = 0; -// Ignore Relative Cursor Motion -static bool ignore_relative_motion = false; - -// Convert Screen Coordinates To Pixels -static void convert_to_pixels(GLFWwindow *window, double *xpos, double *ypos) { - // Skip If Cursor Is Grabbed - if (cursor_grabbed && raw_mouse_motion_enabled) { - return; - } - // Get Window Size - int window_width; - int window_height; - glfwGetWindowSize(window, &window_width, &window_height); - // Get Framebuffer Size - int framebuffer_width; - int framebuffer_height; - glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height); - // Calculate Ratios - const double width_ratio = ((double) framebuffer_width) / ((double) window_width); - const double height_ratio = ((double) framebuffer_height) / ((double) window_height); - // Multiply - *xpos *= width_ratio; - *ypos *= height_ratio; -} - -// Pass Mouse Movement To SDL -static void glfw_motion(__attribute__((unused)) GLFWwindow *window, double xpos, double ypos) { - convert_to_pixels(window, &xpos, &ypos); - if (is_interactable) { - SDL_Event event; - event.type = SDL_MOUSEMOTION; - event.motion.x = xpos; - event.motion.y = ypos; - event.motion.xrel = !ignore_relative_motion ? (xpos - last_mouse_x) : 0; - event.motion.yrel = !ignore_relative_motion ? (ypos - last_mouse_y) : 0; - SDL_PushEvent(&event); - } - ignore_relative_motion = false; - last_mouse_x = xpos; - last_mouse_y = ypos; -} - -// Create And Push SDL Mouse Click Event -static void click_event(int button, bool up) { - SDL_Event event; - event.type = up ? SDL_MOUSEBUTTONUP : SDL_MOUSEBUTTONDOWN; - event.button.x = last_mouse_x; - event.button.y = last_mouse_y; - event.button.state = up ? SDL_RELEASED : SDL_PRESSED; - event.button.button = button; - SDL_PushEvent(&event); -} - -// Pass Mouse Click To SDL -static void glfw_click_raw(const int button, const int action) { - const bool up = action == GLFW_RELEASE; - const int sdl_button = button == GLFW_MOUSE_BUTTON_RIGHT ? SDL_BUTTON_RIGHT : (button == GLFW_MOUSE_BUTTON_LEFT ? SDL_BUTTON_LEFT : SDL_BUTTON_MIDDLE); - click_event(sdl_button, up); -} -static void glfw_click(__attribute__((unused)) GLFWwindow *window, const int button, const int action, __attribute__((unused)) int mods) { - if (is_interactable) { - glfw_click_raw(button, action); - } -} - -// Pass Mouse Scroll To SDL -static void glfw_scroll(__attribute__((unused)) GLFWwindow *window, __attribute__((unused)) double xoffset, double yoffset) { - if (is_interactable && yoffset != 0) { - const int sdl_button = yoffset > 0 ? SDL_BUTTON_WHEELUP : SDL_BUTTON_WHEELDOWN; - click_event(sdl_button, false); - click_event(sdl_button, true); - } -} - -// Enable/Disable Raw Mouse Motion -void media_set_raw_mouse_motion_enabled(const int enabled) { - raw_mouse_motion_enabled = enabled; - if (glfw_window) { - glfwSetInputMode(glfw_window, GLFW_RAW_MOUSE_MOTION, GLFW_FALSE); - } - if (!raw_mouse_motion_enabled) { - WARN("Raw mouse motion has been DISABLED, this IS NOT recommended, and should only ever be used on systems that don't support or have broken raw mouse motion."); - } -} - // Disable V-Sync -static int disable_vsync = 0; +static bool disable_vsync = false; void media_disable_vsync() { - disable_vsync = 1; + disable_vsync = true; if (glfw_window) { glfwSwapInterval(0); } @@ -321,7 +33,7 @@ void media_force_egl() { // Init Media Layer #define GL_VERSION 0x1f02 typedef const char *(*glGetString_t)(unsigned int name); -void SDL_WM_SetCaption(const char *title, __attribute__((unused)) const char *icon) { +void media_SDL_WM_SetCaption(const char *title, __attribute__((unused)) const char *icon) { // Disable In Headless Mode if (reborn_is_headless()) { return; @@ -356,11 +68,7 @@ void SDL_WM_SetCaption(const char *title, __attribute__((unused)) const char *ic } // Event Handlers - glfwSetKeyCallback(glfw_window, glfw_key); - glfwSetCharCallback(glfw_window, glfw_char); - glfwSetCursorPosCallback(glfw_window, glfw_motion); - glfwSetMouseButtonCallback(glfw_window, glfw_click); - glfwSetScrollCallback(glfw_window, glfw_scroll); + _media_register_event_listeners(); // Make Window Context Current glfwMakeContextCurrent(glfw_window); @@ -373,7 +81,7 @@ void SDL_WM_SetCaption(const char *title, __attribute__((unused)) const char *ic _media_audio_init(); // Update State - update_cursor(); + _media_update_cursor(); if (disable_vsync) { media_disable_vsync(); } @@ -382,58 +90,6 @@ void SDL_WM_SetCaption(const char *title, __attribute__((unused)) const char *ic atexit(media_cleanup); } -void media_swap_buffers() { - if (glfw_window) { - glfwSwapBuffers(glfw_window); - } -} - -// Track Fullscreen -static bool is_fullscreen = false; -// Old Size And Position To Use When Exiting Fullscreen -static int old_width = -1; -static int old_height = -1; -static int old_x = -1; -static int old_y = -1; - -// Toggle Fullscreen -void media_toggle_fullscreen() { - if (glfw_window) { - if (is_fullscreen) { - glfwSetWindowMonitor(glfw_window, nullptr, old_x, old_y, old_width, old_height, GLFW_DONT_CARE); - - old_width = -1; - old_height = -1; - old_x = -1; - old_y = -1; - } else { - glfwGetWindowSize(glfw_window, &old_width, &old_height); - glfwGetWindowPos(glfw_window, &old_x, &old_y); - - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - const GLFWvidmode *mode = glfwGetVideoMode(monitor); - - glfwSetWindowMonitor(glfw_window, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE); - } - is_fullscreen = !is_fullscreen; - } -} - -// Intercept SDL Events -void _media_handle_SDL_PollEvent() { - if (glfw_window) { - // Process GLFW Events - glfwPollEvents(); - // Close Window - if (glfwWindowShouldClose(glfw_window)) { - SDL_Event event; - event.type = SDL_QUIT; - SDL_PushEvent(&event); - glfwSetWindowShouldClose(glfw_window, GLFW_FALSE); - } - } -} - // Cleanup Media Layer void media_cleanup() { if (glfw_window) { @@ -450,113 +106,4 @@ void media_cleanup() { // Mark As Stopped glfw_window = nullptr; } -} - -// Update GLFW Cursor State (Client Only) -static void update_cursor() { - if (glfw_window) { - // Get New State - const bool new_cursor_visible = is_interactable ? cursor_visible : true; - const bool new_cursor_grabbed = is_interactable ? cursor_grabbed : false; - - // Store Old Mode - const int old_mode = glfwGetInputMode(glfw_window, GLFW_CURSOR); - - // Handle Cursor Visibility - int new_mode; - if (!new_cursor_visible) { - if (new_cursor_grabbed) { - new_mode = GLFW_CURSOR_DISABLED; - } else { - new_mode = GLFW_CURSOR_HIDDEN; - } - } else { - new_mode = GLFW_CURSOR_NORMAL; - } - if (new_mode != old_mode) { - // Ignore Relative Cursor Motion When Locking - if (new_mode == GLFW_CURSOR_DISABLED && old_mode != GLFW_CURSOR_DISABLED) { - ignore_relative_motion = true; - } - - // Set New Mode - glfwSetInputMode(glfw_window, GLFW_CURSOR, new_mode); - - // Handle Cursor Lock/Unlock - if ((new_mode == GLFW_CURSOR_DISABLED && old_mode != GLFW_CURSOR_DISABLED) || (new_mode != GLFW_CURSOR_DISABLED && old_mode == GLFW_CURSOR_DISABLED)) { - // Use Raw Mouse Motion - if (raw_mouse_motion_enabled) { - glfwSetInputMode(glfw_window, GLFW_RAW_MOUSE_MOTION, new_mode == GLFW_CURSOR_DISABLED ? GLFW_TRUE : GLFW_FALSE); - } - - // Request Focus - if (!glfwGetWindowAttrib(glfw_window, GLFW_FOCUSED)) { - glfwRequestWindowAttention(glfw_window); - } - } - - // Reset Mouse Position When Unlocking - if (new_mode != GLFW_CURSOR_DISABLED && old_mode == GLFW_CURSOR_DISABLED) { - double cursor_x; - double cursor_y; - glfwGetCursorPos(glfw_window, &cursor_x, &cursor_y); - glfw_motion(glfw_window, cursor_x, cursor_y); - } - } - } -} - -// Fix SDL Cursor Visibility/Grabbing -SDL_GrabMode SDL_WM_GrabInput(const SDL_GrabMode mode) { - if (mode == SDL_GRAB_QUERY) { - // Query - return cursor_grabbed ? SDL_GRAB_ON : SDL_GRAB_OFF; - } else if (mode == SDL_GRAB_ON) { - // Store State - cursor_grabbed = true; - } else if (mode == SDL_GRAB_OFF) { - // Store State - cursor_grabbed = false; - } - // Update Cursor GLFW State (Client Only) - update_cursor(); - // Return - return mode; -} - -// Stub SDL Cursor Visibility -int SDL_ShowCursor(const int toggle) { - if (toggle == SDL_QUERY) { - // Query - return cursor_visible ? SDL_ENABLE : SDL_DISABLE; - } else if (toggle == SDL_ENABLE) { - // Store State - cursor_visible = true; - } else if (toggle == SDL_DISABLE) { - // Store State - cursor_visible = false; - } - // Update Cursor GLFW State (Client Only) - update_cursor(); - // Return - return toggle; -} - -// Get Framebuffer Size -void media_get_framebuffer_size(int *width, int *height) { - if (glfw_window) { - glfwGetFramebufferSize(glfw_window, width, height); - } else { - *width = DEFAULT_WIDTH; - *height = DEFAULT_HEIGHT; - } -} - -// Check OpenGL Extension -int media_has_extension(const char *name) { - if (glfw_window) { - return glfwExtensionSupported(name); - } else { - return 0; - } } \ No newline at end of file diff --git a/media-layer/core/src/media.h b/media-layer/core/src/media.h new file mode 100644 index 0000000000..34d09b207d --- /dev/null +++ b/media-layer/core/src/media.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +#define GLFW_INCLUDE_NONE +#include + +#include + +// Interactivity +__attribute__((visibility("internal"))) extern bool is_interactable; + +// Window +__attribute__((visibility("internal"))) extern GLFWwindow *glfw_window; + +// Cursor +__attribute__((visibility("internal"))) void _media_update_cursor(); +__attribute__((visibility("internal"))) extern bool ignore_relative_motion; +__attribute__((visibility("internal"))) extern bool raw_mouse_motion_enabled; + +// Events +__attribute__((visibility("internal"))) void _media_register_event_listeners(); +__attribute__((visibility("internal"))) void _media_handle_media_SDL_PollEvent(); +__attribute__((visibility("internal"))) void _media_glfw_motion(GLFWwindow *window, double xpos, double ypos); \ No newline at end of file diff --git a/media-layer/core/src/util.cpp b/media-layer/core/src/util.cpp new file mode 100644 index 0000000000..51064170ac --- /dev/null +++ b/media-layer/core/src/util.cpp @@ -0,0 +1,67 @@ +#include "media.h" + +// Allow Disabling Interaction +bool is_interactable = true; +void media_set_interactable(const int toggle) { + if (bool(toggle) != is_interactable) { + is_interactable = toggle; + _media_update_cursor(); + } +} + +// Get Framebuffer Size +void media_get_framebuffer_size(int *width, int *height) { + if (glfw_window) { + glfwGetFramebufferSize(glfw_window, width, height); + } else { + *width = DEFAULT_WIDTH; + *height = DEFAULT_HEIGHT; + } +} + +// Check OpenGL Extension +int media_has_extension(const char *name) { + if (glfw_window) { + return glfwExtensionSupported(name); + } else { + return 0; + } +} + +// Swap Buffers +void media_swap_buffers() { + if (glfw_window) { + glfwSwapBuffers(glfw_window); + } +} + +// Toggle Fullscreen +void media_toggle_fullscreen() { + // Track Fullscreen + static bool is_fullscreen = false; + // Old Size And Position To Use When Exiting Fullscreen + static int old_width = -1; + static int old_height = -1; + static int old_x = -1; + static int old_y = -1; + // Run + if (glfw_window) { + if (is_fullscreen) { + glfwSetWindowMonitor(glfw_window, nullptr, old_x, old_y, old_width, old_height, GLFW_DONT_CARE); + + old_width = -1; + old_height = -1; + old_x = -1; + old_y = -1; + } else { + glfwGetWindowSize(glfw_window, &old_width, &old_height); + glfwGetWindowPos(glfw_window, &old_x, &old_y); + + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode *mode = glfwGetVideoMode(monitor); + + glfwSetWindowMonitor(glfw_window, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE); + } + is_fullscreen = !is_fullscreen; + } +} \ No newline at end of file diff --git a/media-layer/extras/CMakeLists.txt b/media-layer/extras/CMakeLists.txt deleted file mode 100644 index 56acbdca52..0000000000 --- a/media-layer/extras/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -project(media-layer-extras) - -# Build -add_library(media-layer-extras OBJECT src/SDL.c) -target_link_libraries(media-layer-extras media-layer-headers reborn-util) diff --git a/media-layer/extras/src/SDL.c b/media-layer/extras/src/SDL.c deleted file mode 100644 index f80090f472..0000000000 --- a/media-layer/extras/src/SDL.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include - -#include -#include - -// SDL Stub -void *SDL_SetVideoMode(__attribute__((unused)) int width, __attribute__((unused)) int height, __attribute__((unused)) int bpp, __attribute__((unused)) uint32_t flags) { - // Return Value Is Only Used For A NULL-Check - return (void *) 1; -} - -static void x11_nop() { - // NOP -} -int SDL_GetWMInfo(SDL_SysWMinfo *info) { - // Return Fake Lock Functions Since XLib Isn't Directly Used - SDL_SysWMinfo ret; - ret.info.x11.lock_func = x11_nop; - ret.info.x11.unlock_func = x11_nop; - ret.info.x11.display = NULL; - ret.info.x11.window = 0; - ret.info.x11.wmwindow = ret.info.x11.window; - *info = ret; - return 1; -} - -// Quit -void SDL_Quit() { - // Cleanup Media Layer - media_cleanup(); - - // Exit - INFO("Stopped"); -} diff --git a/media-layer/gles/src/passthrough.cpp b/media-layer/gles/src/passthrough.cpp index 5cb9b2cfae..e680a953ae 100644 --- a/media-layer/gles/src/passthrough.cpp +++ b/media-layer/gles/src/passthrough.cpp @@ -17,230 +17,230 @@ static void *gl_dlsysm(__attribute__((unused)) void *handle, __attribute__((unus // Passthrough Functions GL_FUNC(glFogfv, void, (GLenum pname, const GLfloat *params)) -void glFogfv(const GLenum pname, const GLfloat *params) { +void media_glFogfv(const GLenum pname, const GLfloat *params) { real_glFogfv()(pname, params); } GL_FUNC(glVertexPointer, void, (GLint size, GLenum type, GLsizei stride, const void *pointer)) -void glVertexPointer(const GLint size, const GLenum type, const GLsizei stride, const void *pointer) { +void media_glVertexPointer(const GLint size, const GLenum type, const GLsizei stride, const void *pointer) { real_glVertexPointer()(size, type, stride, pointer); } GL_FUNC(glLineWidth, void, (GLfloat width)) -void glLineWidth(const GLfloat width) { +void media_glLineWidth(const GLfloat width) { real_glLineWidth()(width); } GL_FUNC(glBlendFunc, void, (GLenum sfactor, GLenum dfactor)) -void glBlendFunc(const GLenum sfactor, const GLenum dfactor) { +void media_glBlendFunc(const GLenum sfactor, const GLenum dfactor) { real_glBlendFunc()(sfactor, dfactor); } GL_FUNC(glDrawArrays, void, (GLenum mode, GLint first, GLsizei count)) -void glDrawArrays(const GLenum mode, const GLint first, const GLsizei count) { +void media_glDrawArrays(const GLenum mode, const GLint first, const GLsizei count) { real_glDrawArrays()(mode, first, count); } GL_FUNC(glMultiDrawArraysEXT, void, (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount)) -void glMultiDrawArrays(const GLenum mode, const GLint *first, const GLsizei *count, const GLsizei drawcount) { +void media_glMultiDrawArrays(const GLenum mode, const GLint *first, const GLsizei *count, const GLsizei drawcount) { real_glMultiDrawArraysEXT()(mode, first, count, drawcount); } GL_FUNC(glColor4f, void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)) -void glColor4f(const GLfloat red, const GLfloat green, const GLfloat blue, const GLfloat alpha) { +void media_glColor4f(const GLfloat red, const GLfloat green, const GLfloat blue, const GLfloat alpha) { real_glColor4f()(red, green, blue, alpha); } GL_FUNC(glClear, void, (GLbitfield mask)) -void glClear(const GLbitfield mask) { +void media_glClear(const GLbitfield mask) { real_glClear()(mask); } GL_FUNC(glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, GLenum usage)) -void glBufferData(const GLenum target, const GLsizeiptr size, const void *data, const GLenum usage) { +void media_glBufferData(const GLenum target, const GLsizeiptr size, const void *data, const GLenum usage) { real_glBufferData()(target, size, data, usage); } GL_FUNC(glBufferSubData, void, (GLenum target, GLintptr offset, GLsizeiptr size, const void *data)) -void glBufferSubData(const GLenum target, const GLintptr offset, const GLsizeiptr size, const void *data) { +void media_glBufferSubData(const GLenum target, const GLintptr offset, const GLsizeiptr size, const void *data) { real_glBufferSubData()(target, offset, size, data); } GL_FUNC(glFogi, void, (GLenum pname, GLint param)) -void glFogx(const GLenum pname, const GLfixed param) { +void media_glFogx(const GLenum pname, const GLfixed param) { real_glFogi()(pname, param); } GL_FUNC(glFogf, void, (GLenum pname, GLfloat param)) -void glFogf(const GLenum pname, const GLfloat param) { +void media_glFogf(const GLenum pname, const GLfloat param) { real_glFogf()(pname, param); } GL_FUNC(glMatrixMode, void, (GLenum mode)) -void glMatrixMode(const GLenum mode) { +void media_glMatrixMode(const GLenum mode) { real_glMatrixMode()(mode); } GL_FUNC(glColorPointer, void, (GLint size, GLenum type, GLsizei stride, const void *pointer)) -void glColorPointer(const GLint size, const GLenum type, const GLsizei stride, const void *pointer) { +void media_glColorPointer(const GLint size, const GLenum type, const GLsizei stride, const void *pointer) { real_glColorPointer()(size, type, stride, pointer); } GL_FUNC(glScissor, void, (GLint x, GLint y, GLsizei width, GLsizei height)) -void glScissor(const GLint x, const GLint y, const GLsizei width, const GLsizei height) { +void media_glScissor(const GLint x, const GLint y, const GLsizei width, const GLsizei height) { real_glScissor()(x, y, width, height); } GL_FUNC(glTexParameteri, void, (GLenum target, GLenum pname, GLint param)) -void glTexParameteri(const GLenum target, const GLenum pname, const GLint param) { +void media_glTexParameteri(const GLenum target, const GLenum pname, const GLint param) { real_glTexParameteri()(target, pname, param); } GL_FUNC(glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)) -void glTexImage2D(const GLenum target, const GLint level, const GLint internalformat, const GLsizei width, const GLsizei height, const GLint border, const GLenum format, const GLenum type, const void *pixels) { +void media_glTexImage2D(const GLenum target, const GLint level, const GLint internalformat, const GLsizei width, const GLsizei height, const GLint border, const GLenum format, const GLenum type, const void *pixels) { real_glTexImage2D()(target, level, internalformat, width, height, border, format, type, pixels); } GL_FUNC(glEnable, void, (GLenum cap)) -void glEnable(const GLenum cap) { +void media_glEnable(const GLenum cap) { real_glEnable()(cap); } GL_FUNC(glEnableClientState, void, (GLenum array)) -void glEnableClientState(const GLenum array) { +void media_glEnableClientState(const GLenum array) { real_glEnableClientState()(array); } GL_FUNC(glPolygonOffset, void, (GLfloat factor, GLfloat units)) -void glPolygonOffset(const GLfloat factor, const GLfloat units) { +void media_glPolygonOffset(const GLfloat factor, const GLfloat units) { real_glPolygonOffset()(factor, units); } GL_FUNC(glDisableClientState, void, (GLenum array)) -void glDisableClientState(const GLenum array) { +void media_glDisableClientState(const GLenum array) { real_glDisableClientState()(array); } GL_FUNC(glDepthRange, void, (GLclampd near, GLclampd far)) -void glDepthRangef(const GLclampf near, const GLclampf far) { +void media_glDepthRangef(const GLclampf near, const GLclampf far) { real_glDepthRange()(near, far); } GL_FUNC(glDepthFunc, void, (GLenum func)) -void glDepthFunc(const GLenum func) { +void media_glDepthFunc(const GLenum func) { real_glDepthFunc()(func); } GL_FUNC(glBindBuffer, void, (GLenum target, GLuint buffer)) -void glBindBuffer(const GLenum target, const GLuint buffer) { +void media_glBindBuffer(const GLenum target, const GLuint buffer) { real_glBindBuffer()(target, buffer); } GL_FUNC(glClearColor, void, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)) -void glClearColor(const GLclampf red, const GLclampf green, const GLclampf blue, const GLclampf alpha) { +void media_glClearColor(const GLclampf red, const GLclampf green, const GLclampf blue, const GLclampf alpha) { real_glClearColor()(red, green, blue, alpha); } GL_FUNC(glPopMatrix, void, ()) -void glPopMatrix() { +void media_glPopMatrix() { real_glPopMatrix()(); } GL_FUNC(glLoadIdentity, void, ()) -void glLoadIdentity() { +void media_glLoadIdentity() { real_glLoadIdentity()(); } GL_FUNC(glScalef, void, (GLfloat x, GLfloat y, GLfloat z)) -void glScalef(const GLfloat x, const GLfloat y, const GLfloat z) { +void media_glScalef(const GLfloat x, const GLfloat y, const GLfloat z) { real_glScalef()(x, y, z); } GL_FUNC(glPushMatrix, void, ()) -void glPushMatrix() { +void media_glPushMatrix() { real_glPushMatrix()(); } GL_FUNC(glDepthMask, void, (GLboolean flag)) -void glDepthMask(const GLboolean flag) { +void media_glDepthMask(const GLboolean flag) { real_glDepthMask()(flag); } GL_FUNC(glHint, void, (GLenum target, GLenum mode)) -void glHint(const GLenum target, const GLenum mode) { +void media_glHint(const GLenum target, const GLenum mode) { real_glHint()(target, mode); } GL_FUNC(glMultMatrixf, void, (const GLfloat *m)) -void glMultMatrixf(const GLfloat *m) { +void media_glMultMatrixf(const GLfloat *m) { real_glMultMatrixf()(m); } GL_FUNC(glTexCoordPointer, void, (GLint size, GLenum type, GLsizei stride, const void *pointer)) -void glTexCoordPointer(const GLint size, const GLenum type, const GLsizei stride, const void *pointer) { +void media_glTexCoordPointer(const GLint size, const GLenum type, const GLsizei stride, const void *pointer) { real_glTexCoordPointer()(size, type, stride, pointer); } GL_FUNC(glDeleteBuffers, void, (GLsizei n, const GLuint *buffers)) -void glDeleteBuffers(const GLsizei n, const GLuint *buffers) { +void media_glDeleteBuffers(const GLsizei n, const GLuint *buffers) { real_glDeleteBuffers()(n, buffers); } GL_FUNC(glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)) -void glColorMask(const GLboolean red, const GLboolean green, const GLboolean blue, const GLboolean alpha) { +void media_glColorMask(const GLboolean red, const GLboolean green, const GLboolean blue, const GLboolean alpha) { real_glColorMask()(red, green, blue, alpha); } GL_FUNC(glTexSubImage2D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)) -void glTexSubImage2D(const GLenum target, const GLint level, const GLint xoffset, const GLint yoffset, const GLsizei width, const GLsizei height, const GLenum format, const GLenum type, const void *pixels) { +void media_glTexSubImage2D(const GLenum target, const GLint level, const GLint xoffset, const GLint yoffset, const GLsizei width, const GLsizei height, const GLenum format, const GLenum type, const void *pixels) { real_glTexSubImage2D()(target, level, xoffset, yoffset, width, height, format, type, pixels); } GL_FUNC(glGenTextures, void, (GLsizei n, GLuint *textures)) -void glGenTextures(const GLsizei n, GLuint *textures) { +void media_glGenTextures(const GLsizei n, GLuint *textures) { real_glGenTextures()(n, textures); } GL_FUNC(glDeleteTextures, void, (GLsizei n, const GLuint *textures)) -void glDeleteTextures(const GLsizei n, const GLuint *textures) { +void media_glDeleteTextures(const GLsizei n, const GLuint *textures) { real_glDeleteTextures()(n, textures); } GL_FUNC(glAlphaFunc, void, (GLenum func, GLclampf ref)) -void glAlphaFunc(const GLenum func, const GLclampf ref) { +void media_glAlphaFunc(const GLenum func, const GLclampf ref) { real_glAlphaFunc()(func, ref); } GL_FUNC(glGetFloatv, void, (GLenum pname, GLfloat *params)) -void glGetFloatv(const GLenum pname, GLfloat *params) { +void media_glGetFloatv(const GLenum pname, GLfloat *params) { real_glGetFloatv()(pname, params); } GL_FUNC(glBindTexture, void, (GLenum target, GLuint texture)) -void glBindTexture(const GLenum target, const GLuint texture) { +void media_glBindTexture(const GLenum target, const GLuint texture) { real_glBindTexture()(target, texture); } GL_FUNC(glTranslatef, void, (GLfloat x, GLfloat y, GLfloat z)) -void glTranslatef(const GLfloat x, const GLfloat y, const GLfloat z) { +void media_glTranslatef(const GLfloat x, const GLfloat y, const GLfloat z) { real_glTranslatef()(x, y, z); } GL_FUNC(glShadeModel, void, (GLenum mode)) -void glShadeModel(const GLenum mode) { +void media_glShadeModel(const GLenum mode) { real_glShadeModel()(mode); } GL_FUNC(glOrtho, void, (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)) -void glOrthof(const GLfloat left, const GLfloat right, const GLfloat bottom, const GLfloat top, const GLfloat near, const GLfloat far) { +void media_glOrthof(const GLfloat left, const GLfloat right, const GLfloat bottom, const GLfloat top, const GLfloat near, const GLfloat far) { real_glOrtho()(left, right, bottom, top, near, far); } GL_FUNC(glDisable, void, (GLenum cap)) -void glDisable(const GLenum cap) { +void media_glDisable(const GLenum cap) { real_glDisable()(cap); } GL_FUNC(glCullFace, void, (GLenum mode)) -void glCullFace(const GLenum mode) { +void media_glCullFace(const GLenum mode) { real_glCullFace()(mode); } GL_FUNC(glRotatef, void, (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)) -void glRotatef(const GLfloat angle, const GLfloat x, const GLfloat y, const GLfloat z) { +void media_glRotatef(const GLfloat angle, const GLfloat x, const GLfloat y, const GLfloat z) { real_glRotatef()(angle, x, y, z); } GL_FUNC(glViewport, void, (GLint x, GLint y, GLsizei width, GLsizei height)) -void glViewport(const GLint x, const GLint y, const GLsizei width, const GLsizei height) { +void media_glViewport(const GLint x, const GLint y, const GLsizei width, const GLsizei height) { real_glViewport()(x, y, width, height); } GL_FUNC(glNormal3f, void, (GLfloat nx, GLfloat ny, GLfloat nz)) -void glNormal3f(const GLfloat nx, const GLfloat ny, const GLfloat nz) { +void media_glNormal3f(const GLfloat nx, const GLfloat ny, const GLfloat nz) { real_glNormal3f()(nx, ny, nz); } GL_FUNC(glIsEnabled, GLboolean, (GLenum cap)) -GLboolean glIsEnabled(const GLenum cap) { +GLboolean media_glIsEnabled(const GLenum cap) { return real_glIsEnabled()(cap); } GL_FUNC(glGetIntegerv, void, (GLenum pname, GLint *data)) -void glGetIntegerv(const GLenum pname, GLint *data) { +void media_glGetIntegerv(const GLenum pname, GLint *data) { real_glGetIntegerv()(pname, data); } GL_FUNC(glReadPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data)) -void glReadPixels(const GLint x, const GLint y, const GLsizei width, const GLsizei height, const GLenum format, const GLenum type, void *data) { +void media_glReadPixels(const GLint x, const GLint y, const GLsizei width, const GLsizei height, const GLenum format, const GLenum type, void *data) { real_glReadPixels()(x, y, width, height, format, type, data); } GL_FUNC(glGenBuffers, void, (GLsizei n, GLuint *buffers)) -void glGenBuffers(const GLsizei n, GLuint *buffers) { +void media_glGenBuffers(const GLsizei n, GLuint *buffers) { real_glGenBuffers()(n, buffers); } GL_FUNC(glNormalPointer, void, (GLenum type, GLsizei stride, const void *pointer)) -void glNormalPointer(const GLenum type, const GLsizei stride, const void *pointer) { +void media_glNormalPointer(const GLenum type, const GLsizei stride, const void *pointer) { real_glNormalPointer()(type, stride, pointer); } GL_FUNC(glLightfv, void, (GLenum light, GLenum pname, const GLfloat *params)) -void glLightfv(const GLenum light, const GLenum pname, const GLfloat *params) { +void media_glLightfv(const GLenum light, const GLenum pname, const GLfloat *params) { real_glLightfv()(light, pname, params); } GL_FUNC(glColorMaterial, void, (GLenum face, GLenum mode)) -void glColorMaterial(const GLenum face, const GLenum mode) { +void media_glColorMaterial(const GLenum face, const GLenum mode) { real_glColorMaterial()(face, mode); } GL_FUNC(glLightModelfv, void, (GLenum pname, const GLfloat *params)) -void glLightModelfv(const GLenum pname, const GLfloat *params) { +void media_glLightModelfv(const GLenum pname, const GLfloat *params) { real_glLightModelfv()(pname, params); } \ No newline at end of file diff --git a/media-layer/include/EGL/egl.h b/media-layer/include/EGL/egl.h index 4df000f203..7e71129031 100644 --- a/media-layer/include/EGL/egl.h +++ b/media-layer/include/EGL/egl.h @@ -23,18 +23,6 @@ typedef XID EGLNativeWindowType; typedef EGLNativeWindowType NativeWindowType; typedef EGLNativeDisplayType NativeDisplayType; -EGLDisplay eglGetDisplay(NativeDisplayType native_display); -EGLBoolean eglInitialize(EGLDisplay display, EGLint *major, EGLint *minor); -EGLBoolean eglChooseConfig(EGLDisplay display, EGLint const *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); -EGLBoolean eglBindAPI(EGLenum api); -EGLContext eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, EGLint const *attrib_list); -EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, NativeWindowType native_window, EGLint const *attrib_list); -EGLBoolean eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context); -EGLBoolean eglDestroySurface(EGLDisplay display, EGLSurface surface); -EGLBoolean eglDestroyContext(EGLDisplay display, EGLContext context); -EGLBoolean eglTerminate(EGLDisplay display); -EGLBoolean eglSwapBuffers(EGLDisplay display, EGLSurface surface); - #ifdef __cplusplus } #endif diff --git a/media-layer/include/GLES/gl.h b/media-layer/include/GLES/gl.h index 7228e4a010..3d6657dcce 100644 --- a/media-layer/include/GLES/gl.h +++ b/media-layer/include/GLES/gl.h @@ -116,65 +116,65 @@ typedef unsigned int GLenum; typedef char GLchar; typedef void GLvoid; -void glFogfv(GLenum pname, const GLfloat *params); -void glVertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer); -void glLineWidth(GLfloat width); -void glBlendFunc(GLenum sfactor, GLenum dfactor); -void glDrawArrays(GLenum mode, GLint first, GLsizei count); -void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); -void glClear(GLbitfield mask); -void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage); -void glFogx(GLenum pname, GLfixed param); -void glFogf(GLenum pname, GLfloat param); -void glMatrixMode(GLenum mode); -void glColorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer); -void glScissor(GLint x, GLint y, GLsizei width, GLsizei height); -void glTexParameteri(GLenum target, GLenum pname, GLint param); -void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); -void glEnable(GLenum cap); -void glEnableClientState(GLenum array); -void glPolygonOffset(GLfloat factor, GLfloat units); -void glDisableClientState(GLenum array); -void glDepthRangef(GLclampf near, GLclampf far); -void glDepthFunc(GLenum func); -void glBindBuffer(GLenum target, GLuint buffer); -void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); -void glPopMatrix(); -void glLoadIdentity(); -void glScalef(GLfloat x, GLfloat y, GLfloat z); -void glPushMatrix(); -void glDepthMask(GLboolean flag); -void glHint(GLenum target, GLenum mode); -void glMultMatrixf(const GLfloat *m); -void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer); -void glDeleteBuffers(GLsizei n, const GLuint *buffers); -void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); -void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); -void glGenTextures(GLsizei n, GLuint *textures); -void glDeleteTextures(GLsizei n, const GLuint *textures); -void glAlphaFunc(GLenum func, GLclampf ref); -void glGetFloatv(GLenum pname, GLfloat *params); -void glBindTexture(GLenum target, GLuint texture); -void glTranslatef(GLfloat x, GLfloat y, GLfloat z); -void glShadeModel(GLenum mode); -void glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far); -void glDisable(GLenum cap); -void glCullFace(GLenum mode); -void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); -void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); -void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz); -GLboolean glIsEnabled(GLenum cap); -void glGetIntegerv(GLenum pname, GLint *data); -void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data); -void glGenBuffers(GLsizei n, GLuint *buffers); -GLenum glGetError(); -void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data); -void glPixelStorei(GLenum pname, GLint param); -void glMultiDrawArrays(GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); -void glNormalPointer(GLenum type, GLsizei stride, const void *pointer); -void glLightfv(GLenum light, GLenum pname, const GLfloat *params); -void glColorMaterial(GLenum face, GLenum mode); -void glLightModelfv(GLenum pname, const GLfloat *params); +void media_glFogfv(GLenum pname, const GLfloat *params); +void media_glVertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer); +void media_glLineWidth(GLfloat width); +void media_glBlendFunc(GLenum sfactor, GLenum dfactor); +void media_glDrawArrays(GLenum mode, GLint first, GLsizei count); +void media_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +void media_glClear(GLbitfield mask); +void media_glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage); +void media_glFogx(GLenum pname, GLfixed param); +void media_glFogf(GLenum pname, GLfloat param); +void media_glMatrixMode(GLenum mode); +void media_glColorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer); +void media_glScissor(GLint x, GLint y, GLsizei width, GLsizei height); +void media_glTexParameteri(GLenum target, GLenum pname, GLint param); +void media_glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); +void media_glEnable(GLenum cap); +void media_glEnableClientState(GLenum array); +void media_glPolygonOffset(GLfloat factor, GLfloat units); +void media_glDisableClientState(GLenum array); +void media_glDepthRangef(GLclampf near, GLclampf far); +void media_glDepthFunc(GLenum func); +void media_glBindBuffer(GLenum target, GLuint buffer); +void media_glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +void media_glPopMatrix(); +void media_glLoadIdentity(); +void media_glScalef(GLfloat x, GLfloat y, GLfloat z); +void media_glPushMatrix(); +void media_glDepthMask(GLboolean flag); +void media_glHint(GLenum target, GLenum mode); +void media_glMultMatrixf(const GLfloat *m); +void media_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer); +void media_glDeleteBuffers(GLsizei n, const GLuint *buffers); +void media_glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +void media_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); +void media_glGenTextures(GLsizei n, GLuint *textures); +void media_glDeleteTextures(GLsizei n, const GLuint *textures); +void media_glAlphaFunc(GLenum func, GLclampf ref); +void media_glGetFloatv(GLenum pname, GLfloat *params); +void media_glBindTexture(GLenum target, GLuint texture); +void media_glTranslatef(GLfloat x, GLfloat y, GLfloat z); +void media_glShadeModel(GLenum mode); +void media_glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far); +void media_glDisable(GLenum cap); +void media_glCullFace(GLenum mode); +void media_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +void media_glViewport(GLint x, GLint y, GLsizei width, GLsizei height); +void media_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz); +GLboolean media_glIsEnabled(GLenum cap); +void media_glGetIntegerv(GLenum pname, GLint *data); +void media_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data); +void media_glGenBuffers(GLsizei n, GLuint *buffers); +GLenum media_glGetError(); +void media_glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data); +void media_glPixelStorei(GLenum pname, GLint param); +void media_glMultiDrawArrays(GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +void media_glNormalPointer(GLenum type, GLsizei stride, const void *pointer); +void media_glLightfv(GLenum light, GLenum pname, const GLfloat *params); +void media_glColorMaterial(GLenum face, GLenum mode); +void media_glLightModelfv(GLenum pname, const GLfloat *params); #ifdef __cplusplus } diff --git a/media-layer/include/SDL/SDL.h b/media-layer/include/SDL/SDL.h index 38ccbd1d25..4cd12b1fa9 100644 --- a/media-layer/include/SDL/SDL.h +++ b/media-layer/include/SDL/SDL.h @@ -11,10 +11,10 @@ extern "C" { #include "SDL_syswm.h" #include "SDL_version.h" -int SDL_Init(uint32_t flags); -int SDL_PollEvent(SDL_Event *event); -int SDL_PushEvent(SDL_Event *event); -void SDL_WM_SetCaption(const char *title, const char *icon); +int media_SDL_Init(uint32_t flags); +int media_SDL_PollEvent(SDL_Event *event); +int media_SDL_PushEvent(SDL_Event *event); +void media_SDL_WM_SetCaption(const char *title, const char *icon); typedef enum { SDL_GRAB_QUERY = -1, @@ -22,17 +22,13 @@ typedef enum { SDL_GRAB_ON = 1, SDL_GRAB_FULLSCREEN } SDL_GrabMode; -SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode); +SDL_GrabMode media_SDL_WM_GrabInput(SDL_GrabMode mode); -#define SDL_QUERY -1 +#define SDL_QUERY (-1) #define SDL_IGNORE 0 #define SDL_DISABLE 0 #define SDL_ENABLE 1 -int SDL_ShowCursor(int toggle); - -void *SDL_SetVideoMode(int width, int height, int bpp, uint32_t flags); -int SDL_GetWMInfo(SDL_SysWMinfo *info); -void SDL_Quit(); +int media_SDL_ShowCursor(int toggle); #ifdef __cplusplus } diff --git a/media-layer/include/X11/Xlib.h b/media-layer/include/X11/Xlib.h index 64a651c5ee..77e7da7837 100644 --- a/media-layer/include/X11/Xlib.h +++ b/media-layer/include/X11/Xlib.h @@ -4,8 +4,6 @@ extern "C" { #endif -#include - typedef unsigned long XID; typedef struct { @@ -32,9 +30,6 @@ typedef struct { void *screen; } XWindowAttributes; -int XTranslateCoordinates(void *display, XID src_w, XID dest_w, int src_x, int src_y, int *dest_x_return, int *dest_y_return, XID *child_return); -int XGetWindowAttributes(void *display, XID w, XWindowAttributes *window_attributes_return); - #ifdef __cplusplus } #endif diff --git a/media-layer/include/media-layer/internal.h b/media-layer/include/media-layer/internal.h deleted file mode 100644 index 562520eb73..0000000000 --- a/media-layer/include/media-layer/internal.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -// Internal Methods -__attribute__((visibility("internal"))) void _media_handle_SDL_PollEvent(); - -#ifdef __cplusplus -} -#endif diff --git a/media-layer/trampoline/CMakeLists.txt b/media-layer/trampoline/CMakeLists.txt index 1f4307e606..0a33a77429 100644 --- a/media-layer/trampoline/CMakeLists.txt +++ b/media-layer/trampoline/CMakeLists.txt @@ -13,7 +13,7 @@ if(BUILD_NATIVE_COMPONENTS) install(TARGETS media-layer-trampoline DESTINATION "${MCPI_LIB_DIR}") elseif(BUILD_ARM_COMPONENTS) # Guest Component - add_library(media-layer-core SHARED src/guest/guest.cpp ${MEDIA_LAYER_TRAMPOLINE_SRC} $) + add_library(media-layer-core SHARED src/guest/guest.cpp ${MEDIA_LAYER_TRAMPOLINE_SRC}) target_link_libraries(media-layer-core PUBLIC media-layer-headers PRIVATE reborn-util PRIVATE trampoline-headers PRIVATE rt) target_compile_definitions(media-layer-core PRIVATE -DMEDIA_LAYER_TRAMPOLINE_GUEST) # Install diff --git a/media-layer/trampoline/src/GLESv1_CM.cpp b/media-layer/trampoline/src/GLESv1_CM.cpp index 5722e51a40..89f0961297 100644 --- a/media-layer/trampoline/src/GLESv1_CM.cpp +++ b/media-layer/trampoline/src/GLESv1_CM.cpp @@ -10,7 +10,7 @@ static int get_glFogfv_params_length(const GLenum pname) { return pname == GL_FOG_COLOR ? 4 : 1; } #endif -CALL(11, glFogfv, void, (GLenum pname, const GLfloat *params)) +CALL(11, media_glFogfv, void, (GLenum pname, const GLfloat *params)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, pname, copy_array(get_glFogfv_params_length(pname), params)); #else @@ -30,10 +30,10 @@ struct gl_array_details_t { }; #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST struct { - gl_array_details_t glVertexPointer; - gl_array_details_t glColorPointer; - gl_array_details_t glTexCoordPointer; - gl_array_details_t glNormalPointer; + gl_array_details_t media_glVertexPointer; + gl_array_details_t media_glColorPointer; + gl_array_details_t media_glTexCoordPointer; + gl_array_details_t media_glNormalPointer; } gl_array_details; #endif struct gl_state_t { @@ -67,9 +67,9 @@ struct gl_state_t { void send_array_to_driver(const GLenum array) { const bool state = get_array_enabled(array); if (state) { - glEnableClientState(array); + media_glEnableClientState(array); } else { - glDisableClientState(array); + media_glDisableClientState(array); } } void send_to_driver() { @@ -77,8 +77,8 @@ struct gl_state_t { send_array_to_driver(GL_COLOR_ARRAY); send_array_to_driver(GL_TEXTURE_COORD_ARRAY); send_array_to_driver(GL_NORMAL_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, bound_array_buffer); - glBindTexture(GL_TEXTURE_2D, bound_texture); + media_glBindBuffer(GL_ARRAY_BUFFER, bound_array_buffer); + media_glBindTexture(GL_TEXTURE_2D, bound_texture); } #endif }; @@ -102,16 +102,16 @@ static gl_state_t gl_state; #else #define CALL_GL_POINTER(unique_id, name) \ CALL(unique_id, name, unused, ()) \ - glBindBuffer(GL_ARRAY_BUFFER, args.next()); \ + media_glBindBuffer(GL_ARRAY_BUFFER, args.next()); \ gl_array_details_t state = args.next(); \ func(state.size, state.type, state.stride, (const void *) uintptr_t(state.pointer)); \ return 0; \ } #endif -CALL_GL_POINTER(12, glVertexPointer) +CALL_GL_POINTER(12, media_glVertexPointer) -CALL(13, glLineWidth, void, (GLfloat width)) +CALL(13, media_glLineWidth, void, (GLfloat width)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, width); #else @@ -120,7 +120,7 @@ CALL(13, glLineWidth, void, (GLfloat width)) #endif } -CALL(14, glBlendFunc, void, (GLenum sfactor, GLenum dfactor)) +CALL(14, media_glBlendFunc, void, (GLenum sfactor, GLenum dfactor)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, sfactor, dfactor); #else @@ -131,7 +131,7 @@ CALL(14, glBlendFunc, void, (GLenum sfactor, GLenum dfactor)) #endif } -CALL(15, glDrawArrays, void, (GLenum mode, GLint first, GLsizei count)) +CALL(15, media_glDrawArrays, void, (GLenum mode, GLint first, GLsizei count)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, gl_state, mode, first, count); #else @@ -145,7 +145,7 @@ CALL(15, glDrawArrays, void, (GLenum mode, GLint first, GLsizei count)) #endif } -CALL(70, glMultiDrawArrays, void, (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount)) +CALL(70, media_glMultiDrawArrays, void, (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, gl_state, mode, copy_array(drawcount, first), copy_array(drawcount, count)); #else @@ -160,7 +160,7 @@ CALL(70, glMultiDrawArrays, void, (GLenum mode, const GLint *first, const GLsize #endif } -CALL(16, glColor4f, void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)) +CALL(16, media_glColor4f, void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, red, green, blue, alpha); #else @@ -173,7 +173,7 @@ CALL(16, glColor4f, void, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alp #endif } -CALL(17, glClear, void, (GLbitfield mask)) +CALL(17, media_glClear, void, (GLbitfield mask)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, mask); #else @@ -182,11 +182,11 @@ CALL(17, glClear, void, (GLbitfield mask)) #endif } -CALL(18, glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, GLenum usage)) +CALL(18, media_glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, GLenum usage)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, gl_state.bound_array_buffer, target, int32_t(size), copy_array(size, (unsigned char *) data), usage); #else - glBindBuffer(GL_ARRAY_BUFFER, args.next()); + media_glBindBuffer(GL_ARRAY_BUFFER, args.next()); GLenum target = args.next(); int32_t size = args.next(); const unsigned char *data = args.next_arr(); @@ -196,7 +196,7 @@ CALL(18, glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, #endif } -CALL(19, glFogx, void, (GLenum pname, GLfixed param)) +CALL(19, media_glFogx, void, (GLenum pname, GLfixed param)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, pname, param); #else @@ -207,7 +207,7 @@ CALL(19, glFogx, void, (GLenum pname, GLfixed param)) #endif } -CALL(20, glFogf, void, (GLenum pname, GLfloat param)) +CALL(20, media_glFogf, void, (GLenum pname, GLfloat param)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, pname, param); #else @@ -218,7 +218,7 @@ CALL(20, glFogf, void, (GLenum pname, GLfloat param)) #endif } -CALL(21, glMatrixMode, void, (GLenum mode)) +CALL(21, media_glMatrixMode, void, (GLenum mode)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, mode); #else @@ -227,9 +227,9 @@ CALL(21, glMatrixMode, void, (GLenum mode)) #endif } -CALL_GL_POINTER(22, glColorPointer) +CALL_GL_POINTER(22, media_glColorPointer) -CALL(23, glScissor, void, (GLint x, GLint y, GLsizei width, GLsizei height)) +CALL(23, media_glScissor, void, (GLint x, GLint y, GLsizei width, GLsizei height)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, x, y, width, height); #else @@ -242,11 +242,11 @@ CALL(23, glScissor, void, (GLint x, GLint y, GLsizei width, GLsizei height)) #endif } -CALL(24, glTexParameteri, void, (GLenum target, GLenum pname, GLint param)) +CALL(24, media_glTexParameteri, void, (GLenum target, GLenum pname, GLint param)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, gl_state.bound_texture, target, pname, param); #else - glBindTexture(GL_TEXTURE_2D, args.next()); + media_glBindTexture(GL_TEXTURE_2D, args.next()); GLenum target = args.next(); GLenum pname = args.next(); GLint param = args.next(); @@ -282,7 +282,7 @@ static int get_texture_size(const GLsizei width, const GLsizei height, const GLe { // Handle Alignment int alignment; - glGetIntegerv(is_upload ? GL_UNPACK_ALIGNMENT : GL_PACK_ALIGNMENT, &alignment); + media_glGetIntegerv(is_upload ? GL_UNPACK_ALIGNMENT : GL_PACK_ALIGNMENT, &alignment); // Round line_size = ALIGN_UP(line_size, alignment); } @@ -290,11 +290,11 @@ static int get_texture_size(const GLsizei width, const GLsizei height, const GLe return line_size * height; } -CALL(25, glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)) +CALL(25, media_glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, gl_state.bound_texture, target, level, internalformat, width, height, border, format, type, copy_array(get_texture_size(width, height, format, type, true), (const unsigned char *) pixels)); #else - glBindTexture(GL_TEXTURE_2D, args.next()); + media_glBindTexture(GL_TEXTURE_2D, args.next()); GLenum target = args.next(); GLint level = args.next(); GLint internalformat = args.next(); @@ -309,7 +309,7 @@ CALL(25, glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, #endif } -CALL(26, glEnable, void, (GLenum cap)) +CALL(26, media_glEnable, void, (GLenum cap)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, cap); #else @@ -319,12 +319,12 @@ CALL(26, glEnable, void, (GLenum cap)) } #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST -void glEnableClientState(const GLenum array) { +void media_glEnableClientState(const GLenum array) { gl_state.get_array_enabled(array) = true; } #endif -CALL(28, glPolygonOffset, void, (GLfloat factor, GLfloat units)) +CALL(28, media_glPolygonOffset, void, (GLfloat factor, GLfloat units)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, factor, units); #else @@ -335,33 +335,33 @@ CALL(28, glPolygonOffset, void, (GLfloat factor, GLfloat units)) #endif } -CALL_GL_POINTER(41, glTexCoordPointer) +CALL_GL_POINTER(41, media_glTexCoordPointer) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST -void glDisableClientState(const GLenum array) { +void media_glDisableClientState(const GLenum array) { gl_state.get_array_enabled(array) = false; switch (array) { case GL_VERTEX_ARRAY: { - gl_array_details.glVertexPointer.size = -1; + gl_array_details.media_glVertexPointer.size = -1; break; } case GL_COLOR_ARRAY: { - gl_array_details.glColorPointer.size = -1; + gl_array_details.media_glColorPointer.size = -1; break; } case GL_TEXTURE_COORD_ARRAY: { - gl_array_details.glTexCoordPointer.size = -1; + gl_array_details.media_glTexCoordPointer.size = -1; break; } case GL_NORMAL_ARRAY: { - gl_array_details.glNormalPointer.size = -1; + gl_array_details.media_glNormalPointer.size = -1; break; } } } #endif -CALL(30, glDepthRangef, void, (GLclampf near, GLclampf far)) +CALL(30, media_glDepthRangef, void, (GLclampf near, GLclampf far)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, near, far); #else @@ -372,7 +372,7 @@ CALL(30, glDepthRangef, void, (GLclampf near, GLclampf far)) #endif } -CALL(31, glDepthFunc, void, (GLenum func)) +CALL(31, media_glDepthFunc, void, (GLenum func)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, func); #else @@ -382,20 +382,20 @@ CALL(31, glDepthFunc, void, (GLenum func)) } #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST -void glBindBuffer(const GLenum target, const GLuint buffer) { +void media_glBindBuffer(const GLenum target, const GLuint buffer) { if (target == GL_ARRAY_BUFFER) { gl_state.bound_array_buffer = buffer; } else { ERR("Unsupported Buffer Binding: %u", target); } - gl_array_details.glVertexPointer.size = -1; - gl_array_details.glColorPointer.size = -1; - gl_array_details.glTexCoordPointer.size = -1; - gl_array_details.glNormalPointer.size = -1; + gl_array_details.media_glVertexPointer.size = -1; + gl_array_details.media_glColorPointer.size = -1; + gl_array_details.media_glTexCoordPointer.size = -1; + gl_array_details.media_glNormalPointer.size = -1; } #endif -CALL(33, glClearColor, void, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)) +CALL(33, media_glClearColor, void, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, red, green, blue, alpha); #else @@ -408,7 +408,7 @@ CALL(33, glClearColor, void, (GLclampf red, GLclampf green, GLclampf blue, GLcla #endif } -CALL(34, glPopMatrix, void, ()) +CALL(34, media_glPopMatrix, void, ()) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true); #else @@ -417,7 +417,7 @@ CALL(34, glPopMatrix, void, ()) #endif } -CALL(35, glLoadIdentity, void, ()) +CALL(35, media_glLoadIdentity, void, ()) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true); #else @@ -426,7 +426,7 @@ CALL(35, glLoadIdentity, void, ()) #endif } -CALL(36, glScalef, void, (GLfloat x, GLfloat y, GLfloat z)) +CALL(36, media_glScalef, void, (GLfloat x, GLfloat y, GLfloat z)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, x, y, z); #else @@ -438,7 +438,7 @@ CALL(36, glScalef, void, (GLfloat x, GLfloat y, GLfloat z)) #endif } -CALL(37, glPushMatrix, void, ()) +CALL(37, media_glPushMatrix, void, ()) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true); #else @@ -447,7 +447,7 @@ CALL(37, glPushMatrix, void, ()) #endif } -CALL(38, glDepthMask, void, (GLboolean flag)) +CALL(38, media_glDepthMask, void, (GLboolean flag)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, flag); #else @@ -456,7 +456,7 @@ CALL(38, glDepthMask, void, (GLboolean flag)) #endif } -CALL(39, glHint, void, (GLenum target, GLenum mode)) +CALL(39, media_glHint, void, (GLenum target, GLenum mode)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, target, mode); #else @@ -472,7 +472,7 @@ static int get_glMultMatrixf_size() { return 16; } #endif -CALL(40, glMultMatrixf, void, (const GLfloat *m)) +CALL(40, media_glMultMatrixf, void, (const GLfloat *m)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, copy_array(get_glMultMatrixf_size(), m)); #else @@ -481,7 +481,7 @@ CALL(40, glMultMatrixf, void, (const GLfloat *m)) #endif } -CALL(42, glDeleteBuffers, void, (GLsizei n, const GLuint *buffers)) +CALL(42, media_glDeleteBuffers, void, (GLsizei n, const GLuint *buffers)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, copy_array(n, buffers)); #else @@ -492,7 +492,7 @@ CALL(42, glDeleteBuffers, void, (GLsizei n, const GLuint *buffers)) #endif } -CALL(43, glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)) +CALL(43, media_glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, red, green, blue, alpha); #else @@ -505,11 +505,11 @@ CALL(43, glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLb #endif } -CALL(44, glTexSubImage2D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)) +CALL(44, media_glTexSubImage2D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, gl_state.bound_texture, target, level, xoffset, yoffset, width, height, format, type, copy_array(get_texture_size(width, height, format, type, true), (const unsigned char *) pixels)); #else - glBindTexture(GL_TEXTURE_2D, args.next()); + media_glBindTexture(GL_TEXTURE_2D, args.next()); GLenum target = args.next(); GLint level = args.next(); GLint xoffset = args.next(); @@ -524,7 +524,7 @@ CALL(44, glTexSubImage2D, void, (GLenum target, GLint level, GLint xoffset, GLin #endif } -CALL(45, glGenTextures, void, (GLsizei n, GLuint *textures)) +CALL(45, media_glGenTextures, void, (GLsizei n, GLuint *textures)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(false, n, uint32_t(textures)); #else @@ -537,7 +537,7 @@ CALL(45, glGenTextures, void, (GLsizei n, GLuint *textures)) #endif } -CALL(46, glDeleteTextures, void, (GLsizei n, const GLuint *textures)) +CALL(46, media_glDeleteTextures, void, (GLsizei n, const GLuint *textures)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, copy_array(n, textures)); #else @@ -548,7 +548,7 @@ CALL(46, glDeleteTextures, void, (GLsizei n, const GLuint *textures)) #endif } -CALL(47, glAlphaFunc, void, (GLenum func, GLclampf ref)) +CALL(47, media_glAlphaFunc, void, (GLenum func, GLclampf ref)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, func, ref); #else @@ -570,12 +570,12 @@ static int get_glGetFloatv_params_size(GLenum pname) { return 2; } default: { - ERR("Unsupported glGetFloatv Property: %u", pname); + ERR("Unsupported media_glGetFloatv Property: %u", pname); } } } #endif -CALL(48, glGetFloatv, void, (GLenum pname, GLfloat *params)) +CALL(48, media_glGetFloatv, void, (GLenum pname, GLfloat *params)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(false, pname, uint32_t(params)); #else @@ -590,7 +590,7 @@ CALL(48, glGetFloatv, void, (GLenum pname, GLfloat *params)) } #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST -void glBindTexture(const GLenum target, const GLuint texture) { +void media_glBindTexture(const GLenum target, const GLuint texture) { if (target == GL_TEXTURE_2D) { gl_state.bound_texture = texture; } else { @@ -599,7 +599,7 @@ void glBindTexture(const GLenum target, const GLuint texture) { } #endif -CALL(50, glTranslatef, void, (GLfloat x, GLfloat y, GLfloat z)) +CALL(50, media_glTranslatef, void, (GLfloat x, GLfloat y, GLfloat z)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, x, y, z); #else @@ -611,7 +611,7 @@ CALL(50, glTranslatef, void, (GLfloat x, GLfloat y, GLfloat z)) #endif } -CALL(51, glShadeModel, void, (GLenum mode)) +CALL(51, media_glShadeModel, void, (GLenum mode)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, mode); #else @@ -620,7 +620,7 @@ CALL(51, glShadeModel, void, (GLenum mode)) #endif } -CALL(52, glOrthof, void, (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far)) +CALL(52, media_glOrthof, void, (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, left, right, bottom, top, near, far); #else @@ -635,7 +635,7 @@ CALL(52, glOrthof, void, (GLfloat left, GLfloat right, GLfloat bottom, GLfloat t #endif } -CALL(53, glDisable, void, (GLenum cap)) +CALL(53, media_glDisable, void, (GLenum cap)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, cap); #else @@ -644,7 +644,7 @@ CALL(53, glDisable, void, (GLenum cap)) #endif } -CALL(54, glCullFace, void, (GLenum mode)) +CALL(54, media_glCullFace, void, (GLenum mode)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, mode); #else @@ -653,7 +653,7 @@ CALL(54, glCullFace, void, (GLenum mode)) #endif } -CALL(55, glRotatef, void, (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)) +CALL(55, media_glRotatef, void, (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, angle, x, y, z); #else @@ -666,7 +666,7 @@ CALL(55, glRotatef, void, (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)) #endif } -CALL(56, glViewport, void, (GLint x, GLint y, GLsizei width, GLsizei height)) +CALL(56, media_glViewport, void, (GLint x, GLint y, GLsizei width, GLsizei height)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, x, y, width, height); #else @@ -679,7 +679,7 @@ CALL(56, glViewport, void, (GLint x, GLint y, GLsizei width, GLsizei height)) #endif } -CALL(57, glNormal3f, void, (GLfloat nx, GLfloat ny, GLfloat nz)) +CALL(57, media_glNormal3f, void, (GLfloat nx, GLfloat ny, GLfloat nz)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, nx, ny, nz); #else @@ -691,7 +691,7 @@ CALL(57, glNormal3f, void, (GLfloat nx, GLfloat ny, GLfloat nz)) #endif } -CALL(58, glIsEnabled, GLboolean, (GLenum cap)) +CALL(58, media_glIsEnabled, GLboolean, (GLenum cap)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST return trampoline(false, cap); #else @@ -711,12 +711,12 @@ static int get_glGetIntegerv_params_size(GLenum pname) { return 4; } default: { - ERR("Unsupported glGetIntegerv Property: %u", pname); + ERR("Unsupported media_glGetIntegerv Property: %u", pname); } } } #endif -CALL(61, glGetIntegerv, void, (GLenum pname, GLint *params)) +CALL(61, media_glGetIntegerv, void, (GLenum pname, GLint *params)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST if (pname == GL_TEXTURE_BINDING_2D) { params[0] = gl_state.bound_texture; @@ -734,7 +734,7 @@ CALL(61, glGetIntegerv, void, (GLenum pname, GLint *params)) #endif } -CALL(65, glReadPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data)) +CALL(65, media_glReadPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(false, x, y, width, height, format, type, uint32_t(data)); #else @@ -753,7 +753,7 @@ CALL(65, glReadPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, G #endif } -CALL(67, glGenBuffers, void, (GLsizei n, GLuint *buffers)) +CALL(67, media_glGenBuffers, void, (GLsizei n, GLuint *buffers)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(false, n, uint32_t(buffers)); #else @@ -766,11 +766,11 @@ CALL(67, glGenBuffers, void, (GLsizei n, GLuint *buffers)) #endif } -CALL(69, glBufferSubData, void, (GLenum target, GLintptr offset, GLsizeiptr size, const void *data)) +CALL(69, media_glBufferSubData, void, (GLenum target, GLintptr offset, GLsizeiptr size, const void *data)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, gl_state.bound_array_buffer, target, int32_t(offset), int32_t(size), copy_array(size, (unsigned char *) data)); #else - glBindBuffer(GL_ARRAY_BUFFER, args.next()); + media_glBindBuffer(GL_ARRAY_BUFFER, args.next()); GLenum target = args.next(); int32_t offset = args.next(); int32_t size = args.next(); @@ -780,9 +780,9 @@ CALL(69, glBufferSubData, void, (GLenum target, GLintptr offset, GLsizeiptr size #endif } -CALL(72, glNormalPointer, void, (GLenum type, GLsizei stride, const void *pointer)) +CALL(72, media_glNormalPointer, void, (GLenum type, GLsizei stride, const void *pointer)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST - gl_array_details_t &state = gl_array_details.glNormalPointer; + gl_array_details_t &state = gl_array_details.media_glNormalPointer; if (state.size == -1 || state.type != type || state.stride != stride || state.pointer != uint32_t(pointer)) { state.size = 0; state.type = type; @@ -791,14 +791,14 @@ CALL(72, glNormalPointer, void, (GLenum type, GLsizei stride, const void *pointe trampoline(true, gl_state.bound_array_buffer, state); } #else - glBindBuffer(GL_ARRAY_BUFFER, args.next()); + media_glBindBuffer(GL_ARRAY_BUFFER, args.next()); gl_array_details_t state = args.next(); func(state.type, state.stride, (const void *) uintptr_t(state.pointer)); return 0; #endif } -CALL(73, glLightfv, void, (GLenum light, GLenum pname, const GLfloat *params)) +CALL(73, media_glLightfv, void, (GLenum light, GLenum pname, const GLfloat *params)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, light, pname, copy_array(4, params)); #else @@ -810,7 +810,7 @@ CALL(73, glLightfv, void, (GLenum light, GLenum pname, const GLfloat *params)) #endif } -CALL(74, glColorMaterial, void, (GLenum face, GLenum mode)) +CALL(74, media_glColorMaterial, void, (GLenum face, GLenum mode)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, face, mode); #else @@ -821,7 +821,7 @@ CALL(74, glColorMaterial, void, (GLenum face, GLenum mode)) #endif } -CALL(75, glLightModelfv, void, (GLenum pname, const GLfloat *params)) +CALL(75, media_glLightModelfv, void, (GLenum pname, const GLfloat *params)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, pname, copy_array(4, params)); #else diff --git a/media-layer/trampoline/src/media-layer-core.cpp b/media-layer/trampoline/src/media-layer-core.cpp index 6836a0c552..fa9b3134a7 100644 --- a/media-layer/trampoline/src/media-layer-core.cpp +++ b/media-layer/trampoline/src/media-layer-core.cpp @@ -11,7 +11,7 @@ // SDL Functions -CALL(0, SDL_Init, int, (uint32_t flags)) +CALL(0, media_SDL_Init, int, (uint32_t flags)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST return trampoline(false, flags); #else @@ -20,7 +20,7 @@ CALL(0, SDL_Init, int, (uint32_t flags)) #endif } -CALL(1, SDL_PollEvent, int, (SDL_Event *event)) +CALL(1, media_SDL_PollEvent, int, (SDL_Event *event)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST return trampoline(false, uint32_t(event)); #else @@ -31,7 +31,7 @@ CALL(1, SDL_PollEvent, int, (SDL_Event *event)) #endif } -CALL(2, SDL_PushEvent, int, (SDL_Event *event)) +CALL(2, media_SDL_PushEvent, int, (SDL_Event *event)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST return trampoline(false, *event); #else @@ -40,7 +40,7 @@ CALL(2, SDL_PushEvent, int, (SDL_Event *event)) #endif } -CALL(3, SDL_WM_SetCaption, void, (const char *title, const char *icon)) +CALL(3, media_SDL_WM_SetCaption, void, (const char *title, const char *icon)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST trampoline(true, copy_array(title), copy_array(icon)); #else @@ -60,7 +60,7 @@ CALL(4, media_toggle_fullscreen, void, ()) #endif } -CALL(5, SDL_WM_GrabInput, SDL_GrabMode, (SDL_GrabMode mode)) +CALL(5, media_SDL_WM_GrabInput, SDL_GrabMode, (SDL_GrabMode mode)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST return (SDL_GrabMode) trampoline(false, mode); #else @@ -68,7 +68,7 @@ CALL(5, SDL_WM_GrabInput, SDL_GrabMode, (SDL_GrabMode mode)) #endif } -CALL(6, SDL_ShowCursor, int, (int32_t toggle)) +CALL(6, media_SDL_ShowCursor, int, (int32_t toggle)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST return trampoline(false, toggle); #else diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt index 9198636584..19341defa6 100644 --- a/mods/CMakeLists.txt +++ b/mods/CMakeLists.txt @@ -7,6 +7,7 @@ set(SRC src/compat/egl.cpp src/compat/x11.cpp src/compat/bcm_host.cpp + src/compat/sdl.cpp # readdir src/readdir/readdir.cpp # feature diff --git a/mods/include/mods/textures/textures.h b/mods/include/mods/textures/textures.h index ae24a4d4f8..777c38a6b6 100644 --- a/mods/include/mods/textures/textures.h +++ b/mods/include/mods/textures/textures.h @@ -3,5 +3,5 @@ #include extern "C" { -void glTexSubImage2D_with_scaling(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLsizei normal_texture_width, GLsizei normal_texture_height, GLenum format, GLenum type, const void *pixels); +void media_glTexSubImage2D_with_scaling(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLsizei normal_texture_width, GLsizei normal_texture_height, GLenum format, GLenum type, const void *pixels); } \ No newline at end of file diff --git a/mods/src/atlas/atlas.cpp b/mods/src/atlas/atlas.cpp index 0cd2bf35e1..7ca46d4371 100644 --- a/mods/src/atlas/atlas.cpp +++ b/mods/src/atlas/atlas.cpp @@ -24,15 +24,15 @@ static void ItemRenderer_renderGuiItemCorrect_injection_one(ItemRenderer_renderG } // Fix Toolbar Rendering - const GLboolean depth_test_was_enabled = glIsEnabled(GL_DEPTH_TEST); - glDisable(GL_DEPTH_TEST); + const GLboolean depth_test_was_enabled = media_glIsEnabled(GL_DEPTH_TEST); + media_glDisable(GL_DEPTH_TEST); // Call Original Method original(font, textures, use_carried ? &carried_item_instance : item_instance, param_1, param_2); // Revert GL State Changes if (depth_test_was_enabled) { - glEnable(GL_DEPTH_TEST); + media_glEnable(GL_DEPTH_TEST); } } @@ -98,10 +98,10 @@ static void ItemRenderer_renderGuiItem_two_injection_two(ItemRenderer_renderGuiI original(font, textures, item_instance, x, y, w, h, param_5); } static void ItemRenderer_renderGuiItemCorrect_injection_two(ItemRenderer_renderGuiItemCorrect_t original, Font *font, Textures *textures, const ItemInstance *item_instance, __attribute__((unused)) int x, __attribute__((unused)) int y) { - glPushMatrix(); - glTranslatef(target_x, target_y, 0); + media_glPushMatrix(); + media_glTranslatef(target_x, target_y, 0); original(font, textures, item_instance, 0, 0); - glPopMatrix();; + media_glPopMatrix();; } // Init diff --git a/mods/src/benchmark/benchmark.cpp b/mods/src/benchmark/benchmark.cpp index 9c1686bf4a..e1c80cdedf 100644 --- a/mods/src/benchmark/benchmark.cpp +++ b/mods/src/benchmark/benchmark.cpp @@ -126,7 +126,7 @@ static void Minecraft_update_injection(Minecraft *minecraft) { event.motion.y = 0; event.motion.xrel = (rotation_diff > INT16_MAX) ? INT16_MAX : int16_t(rotation_diff); event.motion.yrel = 0; - SDL_PushEvent(&event); + media_SDL_PushEvent(&event); // Reset Rotation Timer rotation_so_far += event.motion.xrel; } diff --git a/mods/src/compat/compat-internal.h b/mods/src/compat/compat-internal.h index 11107b23e2..488851240c 100644 --- a/mods/src/compat/compat-internal.h +++ b/mods/src/compat/compat-internal.h @@ -3,3 +3,4 @@ __attribute__((visibility("internal"))) void _patch_egl_calls(); __attribute__((visibility("internal"))) void _patch_x11_calls(); __attribute__((visibility("internal"))) void _patch_bcm_host_calls(); +__attribute__((visibility("internal"))) void _patch_sdl_calls(); diff --git a/mods/src/compat/compat.cpp b/mods/src/compat/compat.cpp index ac372078c8..513928911b 100644 --- a/mods/src/compat/compat.cpp +++ b/mods/src/compat/compat.cpp @@ -16,29 +16,29 @@ #include // Custom Title -HOOK(SDL_WM_SetCaption, void, (__attribute__((unused)) const char *title, const char *icon)) { - real_SDL_WM_SetCaption()(MCPI_APP_TITLE, icon); +HOOK(media_SDL_WM_SetCaption, void, (__attribute__((unused)) const char *title, const char *icon)) { + real_media_SDL_WM_SetCaption()(MCPI_APP_TITLE, icon); } // Mouse Cursor Is Always Invisible In Vanilla MCPI // Because In Vanilla MCPI, The GPU Overlay Covered The Normal Mouse Cursor -HOOK(SDL_ShowCursor, int, (int toggle)) { - return real_SDL_ShowCursor()(toggle == SDL_QUERY ? SDL_QUERY : SDL_DISABLE); +HOOK(media_SDL_ShowCursor, int, (int toggle)) { + return real_media_SDL_ShowCursor()(toggle == SDL_QUERY ? SDL_QUERY : SDL_DISABLE); } // Intercept SDL Events -HOOK(SDL_PollEvent, int, (SDL_Event *event)) { +HOOK(media_SDL_PollEvent, int, (SDL_Event *event)) { // In Server Mode, Exit Requests Are Handled In src/server/server.cpp // Check If Exit Is Requested if (!reborn_is_server() && compat_check_exit_requested()) { // Send SDL_QUIT SDL_Event new_event; new_event.type = SDL_QUIT; - SDL_PushEvent(&new_event); + media_SDL_PushEvent(&new_event); } // Poll Events - int ret = real_SDL_PollEvent()(event); + int ret = real_media_SDL_PollEvent()(event); // Handle Events if (ret == 1 && event != nullptr) { @@ -73,7 +73,7 @@ HOOK(SDL_PollEvent, int, (SDL_Event *event)) { } if (handled) { // Event Was Handled - return SDL_PollEvent(event); + return media_SDL_PollEvent(event); } } @@ -99,6 +99,7 @@ void init_compat() { _patch_egl_calls(); _patch_x11_calls(); _patch_bcm_host_calls(); + _patch_sdl_calls(); } // Store Exit Requests diff --git a/mods/src/compat/sdl.cpp b/mods/src/compat/sdl.cpp new file mode 100644 index 0000000000..82f240cc69 --- /dev/null +++ b/mods/src/compat/sdl.cpp @@ -0,0 +1,43 @@ +#include + +#include +#include +#include "compat-internal.h" + +// SDL Stub +static void *SDL_SetVideoMode_injection(__attribute__((unused)) int width, __attribute__((unused)) int height, __attribute__((unused)) int bpp, __attribute__((unused)) uint32_t flags) { + // Return Value Is Only Used For A NULL-Check + return (void *) 1; +} + +// Window Information +static void x11_nop() { + // NOP +} +static int SDL_GetWMInfo_injection(SDL_SysWMinfo *info) { + // Return Fake Lock Functions Since XLib Isn't Directly Used + SDL_SysWMinfo ret; + ret.info.x11.lock_func = x11_nop; + ret.info.x11.unlock_func = x11_nop; + ret.info.x11.display = NULL; + ret.info.x11.window = 0; + ret.info.x11.wmwindow = ret.info.x11.window; + *info = ret; + return 1; +} + +// Quit +static void SDL_Quit_injection() { + // Cleanup Media Layer + media_cleanup(); + // Exit + INFO("Stopped"); +} + +// Patch SDL Calls +void _patch_sdl_calls() { + // Disable SDL Calls + overwrite_call((void *) 0xe020, (void *) SDL_SetVideoMode_injection); + overwrite_call((void *) 0x13284, (void *) SDL_GetWMInfo_injection); + overwrite_call((void *) 0x12410, (void *) SDL_Quit_injection); +} diff --git a/mods/src/input/misc.cpp b/mods/src/input/misc.cpp index 1d8274625f..34ef4c5447 100644 --- a/mods/src/input/misc.cpp +++ b/mods/src/input/misc.cpp @@ -49,7 +49,7 @@ static bool InBedScreen_handleBackEvent_injection(InBedScreen *screen, const boo // Block UI Interaction When Mouse Is Locked static bool Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection(Minecraft *minecraft) { const bool is_in_game = minecraft->screen == nullptr || minecraft->screen->vtable == (Screen_vtable *) Touch_IngameBlockSelectionScreen_vtable_base; - if (!enable_misc || (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF && is_in_game)) { + if (!enable_misc || (media_SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF && is_in_game)) { // Call Original Method return creative_is_restricted() && minecraft->isCreativeMode(); } else { @@ -60,7 +60,7 @@ static bool Gui_tickItemDrop_Minecraft_isCreativeMode_call_injection(Minecraft * // Block UI Interaction When Mouse Is Locked static void Gui_handleClick_injection(Gui_handleClick_t original, Gui *gui, const int32_t param_2, const int32_t param_3, const int32_t param_4) { - if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { + if (media_SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { // Call Original Method original(gui, param_2, param_3, param_4); } diff --git a/mods/src/misc/api.cpp b/mods/src/misc/api.cpp index ebf82c8683..28621366da 100644 --- a/mods/src/misc/api.cpp +++ b/mods/src/misc/api.cpp @@ -112,7 +112,7 @@ void misc_run_on_key_press(const std::function &func) { // Render Fancy Background void misc_render_background(int color, const Minecraft *minecraft, const int x, const int y, const int width, const int height) { // https://github.com/ReMinecraftPE/mcpe/blob/f0d65eaecec1b3fe9c2f2b251e114a890c54ab77/source/client/gui/components/RolledSelectionList.cpp#L169-L179 - glColor4f(1, 1, 1, 1); + media_glColor4f(1, 1, 1, 1); minecraft->textures->loadAndBindTexture("gui/background.png"); Tesselator *t = &Tesselator::instance; t->begin(7); diff --git a/mods/src/misc/graphics.cpp b/mods/src/misc/graphics.cpp index 95bef6a3a7..358ff5c068 100644 --- a/mods/src/misc/graphics.cpp +++ b/mods/src/misc/graphics.cpp @@ -1,5 +1,4 @@ #include -#include #include #include @@ -15,14 +14,14 @@ // Properly Generate Buffers static void anGenBuffers_injection(__attribute__((unused)) Common_anGenBuffers_t original, const int32_t count, uint32_t *buffers) { if (!reborn_is_headless()) { - glGenBuffers(count, buffers); + media_glGenBuffers(count, buffers); } } // Custom Outline Color static void LevelRenderer_render_AABB_glColor4f_injection(__attribute__((unused)) GLfloat red, __attribute__((unused)) GLfloat green, __attribute__((unused)) GLfloat blue, __attribute__((unused)) GLfloat alpha) { // Set Color - glColor4f(0, 0, 0, 0.4); + media_glColor4f(0, 0, 0, 0.4); // Find Line Width const char *custom_line_width = getenv(MCPI_BLOCK_OUTLINE_WIDTH_ENV); @@ -36,14 +35,14 @@ static void LevelRenderer_render_AABB_glColor4f_injection(__attribute__((unused) } // Clamp Line Width float range[2]; - glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, range); + media_glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, range); if (range[1] < line_width) { line_width = range[1]; } else if (range[0] > line_width) { line_width = range[0]; } // Set Line Width - glLineWidth(line_width); + media_glLineWidth(line_width); } // Java Light Ramp @@ -101,10 +100,10 @@ static void render_fire(EntityRenderer *self, Entity *entity, const float x, flo const int texture = Tile::fire->texture; const int xt = (texture & 0xf) << 4; const int yt = texture & 0xf0; - glPushMatrix(); - glTranslatef(x, y, z); + media_glPushMatrix(); + media_glTranslatef(x, y, z); const float s = entity->hitbox_width * 1.4f; - glScalef(s, s, s); + media_glScalef(s, s, s); self->bindTexture("terrain.png"); Tesselator &t = Tesselator::instance; float r = 0.5f; @@ -115,9 +114,9 @@ static void render_fire(EntityRenderer *self, Entity *entity, const float x, flo // Handle Front-Facing player_rot_y -= 180.f; } - glRotatef(-player_rot_y, 0, 1, 0); - glTranslatef(0, 0, -0.3f + float(int(h)) * 0.02f); - glColor4f(1, 1, 1, 1); + media_glRotatef(-player_rot_y, 0, 1, 0); + media_glTranslatef(0, 0, -0.3f + float(int(h)) * 0.02f); + media_glColor4f(1, 1, 1, 1); float zo = 0; int ss = 0; t.begin(7); @@ -152,7 +151,7 @@ static void render_fire(EntityRenderer *self, Entity *entity, const float x, flo ss++; } t.draw(); - glPopMatrix(); + media_glPopMatrix(); } // Entity Shadows @@ -182,9 +181,6 @@ static void render_shadow_tile(Tile *tile, const float x, const float y, const f t.vertexUV(x1, y0, z1, u1, v1); t.vertexUV(x1, y0, z0, u1, v0); } -static const __cxxabiv1::__class_type_info *get_type_info(void *vtable) { - return *(((__cxxabiv1::__class_type_info **) Cow_vtable_base) - 1);; -} static void render_shadow(const EntityRenderer *self, Entity *entity, const float x, const float y, const float z, const float a) { // Calculate Power float pow = 0; @@ -196,14 +192,14 @@ static void render_shadow(const EntityRenderer *self, Entity *entity, const floa return; } // Render - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + media_glEnable(GL_BLEND); + media_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Textures *textures = EntityRenderer::entityRenderDispatcher->textures; textures->loadAndBindTexture("misc/shadow.png"); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + media_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + media_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); Level *level = EntityRenderer::entityRenderDispatcher->level; - glDepthMask(false); + media_glDepthMask(false); float r = self->shadow_radius; if (entity->isMob()) { Mob *mob = (Mob *) entity; @@ -242,9 +238,9 @@ static void render_shadow(const EntityRenderer *self, Entity *entity, const floa } } tt.draw(); - glColor4f(1, 1, 1, 1); - glDisable(GL_BLEND); - glDepthMask(true); + media_glColor4f(1, 1, 1, 1); + media_glDisable(GL_BLEND); + media_glDepthMask(true); } static void EntityRenderDispatcher_assign_injection(EntityRenderDispatcher_assign_t original, EntityRenderDispatcher *self, const uchar entity_id, EntityRenderer *renderer) { // Modify Shadow Size @@ -286,11 +282,11 @@ static void EntityRenderDispatcher_render_EntityRenderer_render_injection(Entity } // Render Fire if (should_render_fire) { - const bool was_lighting_enabled = glIsEnabled(GL_LIGHTING); - glDisable(GL_LIGHTING); + const bool was_lighting_enabled = media_glIsEnabled(GL_LIGHTING); + media_glDisable(GL_LIGHTING); render_fire(self, entity, x, y, z); if (was_lighting_enabled) { - glEnable(GL_LIGHTING); + media_glEnable(GL_LIGHTING); } } } @@ -302,14 +298,14 @@ static void GameRenderer_render_glColorMask_injection(const bool red, const bool game_render_anaglyph_color_mask[1] = green; game_render_anaglyph_color_mask[2] = blue; game_render_anaglyph_color_mask[3] = alpha; - glColorMask(red, green, blue, alpha); + media_glColorMask(red, green, blue, alpha); } static int GameRenderer_render_LevelRenderer_render_injection(LevelRenderer *self, Mob *mob, int param_1, float delta) { - glColorMask(false, false, false, false); + media_glColorMask(false, false, false, false); const int water_chunks = self->render(mob, param_1, delta); - glColorMask(true, true, true, true); + media_glColorMask(true, true, true, true); if (self->minecraft->options.anaglyph_3d) { - glColorMask(game_render_anaglyph_color_mask[0], game_render_anaglyph_color_mask[1], game_render_anaglyph_color_mask[2], game_render_anaglyph_color_mask[3]); + media_glColorMask(game_render_anaglyph_color_mask[0], game_render_anaglyph_color_mask[1], game_render_anaglyph_color_mask[2], game_render_anaglyph_color_mask[3]); } if (water_chunks > 0) { LevelRenderer_renderSameAsLast(self, delta); @@ -405,10 +401,10 @@ static ContainerMenu *ContainerMenu_destructor_injection(ContainerMenu_destructo static bool disable_hand_positioning = false; static void ItemInHandRenderer_renderItem_glTranslatef_injection(const float x, const float y, const float z) { if (disable_hand_positioning) { - glPopMatrix(); - glPushMatrix(); + media_glPopMatrix(); + media_glPushMatrix(); } else { - glTranslatef(x, y, z); + media_glTranslatef(x, y, z); } } static void ItemRenderer_render_injection(ItemRenderer_render_t original, ItemRenderer *self, Entity *entity, const float x, const float y, const float z, const float a, const float b) { @@ -422,7 +418,7 @@ static void ItemRenderer_render_injection(ItemRenderer_render_t original, ItemRe } else { // 3D Item self->random.setSeed(187); - glPushMatrix(); + media_glPushMatrix(); // Count int count; @@ -439,14 +435,14 @@ static void ItemRenderer_render_injection(ItemRenderer_render_t original, ItemRe // Bob const float age = float(item_entity->age) + b; const float bob = (Mth::sin((age / 10.0f) + item_entity->bob_offset) * 0.1f) + 0.1f; - glTranslatef(x, y + bob, z); + media_glTranslatef(x, y + bob, z); // Scale - glScalef(0.5f, 0.5f, 0.5f); + media_glScalef(0.5f, 0.5f, 0.5f); // Spin const float spin = ((age / 20.0f) + item_entity->bob_offset) * float(180.0f / M_PI); - glRotatef(spin, 0, 1, 0); + media_glRotatef(spin, 0, 1, 0); // Position constexpr float xo = 0.5f; @@ -454,29 +450,29 @@ static void ItemRenderer_render_injection(ItemRenderer_render_t original, ItemRe constexpr float width = 1 / 16.0f; constexpr float margin = 0.35f / 16.0f; constexpr float zo = width + margin; - glTranslatef(-xo, -yo, -((zo * float(count)) / 2)); + media_glTranslatef(-xo, -yo, -((zo * float(count)) / 2)); // Draw disable_hand_positioning = true; for (int i = 0; i < count; i++) { - glTranslatef(0, 0, zo); + media_glTranslatef(0, 0, zo); EntityRenderer::entityRenderDispatcher->item_renderer->renderItem(nullptr, &item); } disable_hand_positioning = false; // Finish - glPopMatrix(); + media_glPopMatrix(); } } // Vignette static void Gui_renderProgressIndicator_injection(Gui_renderProgressIndicator_t original, Gui *self, const bool is_touch, int width, int height, float a) { // Render - glEnable(GL_BLEND); + media_glEnable(GL_BLEND); self->minecraft->textures->blur = true; self->renderVignette(self->minecraft->player->getBrightness(a), width, height); self->minecraft->textures->blur = false; - glDisable(GL_BLEND); + media_glDisable(GL_BLEND); // Call Original Method original(self, is_touch, width, height, a); } diff --git a/mods/src/misc/ui.cpp b/mods/src/misc/ui.cpp index df08d6183a..73653f9f50 100644 --- a/mods/src/misc/ui.cpp +++ b/mods/src/misc/ui.cpp @@ -77,7 +77,7 @@ static void Gui_renderChatMessages_injection(Gui_renderChatMessages_t original, // Render Selected Item Text if (render_selected_item_text && !disable_fading) { // Fix GL Mode - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + media_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Calculate Selected Item Text Scale const Minecraft *minecraft = gui->minecraft; const int32_t screen_width = minecraft->screen_width; @@ -113,20 +113,20 @@ static void Inventory_selectSlot_injection(Inventory_selectSlot_t original, Inve // Translucent Toolbar static void Gui_renderToolBar_injection(Gui_renderToolBar_t original, Gui *gui, const float param_1, const int32_t param_2, const int32_t param_3) { // Call Original Method - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + media_glEnable(GL_BLEND); + media_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); original(gui, param_1, param_2, param_3); - glDisable(GL_BLEND); + media_glDisable(GL_BLEND); } static void Gui_renderToolBar_glColor4f_injection(const GLfloat red, const GLfloat green, const GLfloat blue, __attribute__((unused)) GLfloat alpha) { // Fix Alpha - glColor4f(red, green, blue, 1.0f); + media_glColor4f(red, green, blue, 1.0f); } // Fix Screen Rendering When GUI is Hidden static void Screen_render_injection(Screen_render_t original, Screen *screen, const int32_t param_1, const int32_t param_2, const float param_3) { // Fix - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + media_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Call Original Method original(screen, param_1, param_2, param_3); } @@ -150,9 +150,9 @@ static void GameRenderer_render_injection(GameRenderer_render_t original, GameRe original(game_renderer, param_1); // Check If Cursor Should Render - if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { + if (media_SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { // Fix GL Mode - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + media_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Get X And Y float x = Mouse::getX() * Gui::InvGuiScale; float y = Mouse::getY() * Gui::InvGuiScale; diff --git a/mods/src/multidraw/buffer.cpp b/mods/src/multidraw/buffer.cpp index e483c170d3..1eeadb7dee 100644 --- a/mods/src/multidraw/buffer.cpp +++ b/mods/src/multidraw/buffer.cpp @@ -8,15 +8,15 @@ Buffer::Buffer(const ssize_t size) { client_side_data = new unsigned char[size]; // Server-Side Data server_side_data = 0; - glGenBuffers(1, &server_side_data); - glBindBuffer(GL_ARRAY_BUFFER, server_side_data); - glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_DYNAMIC_DRAW); + media_glGenBuffers(1, &server_side_data); + media_glBindBuffer(GL_ARRAY_BUFFER, server_side_data); + media_glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_DYNAMIC_DRAW); } Buffer::~Buffer() { // Client-Side Data delete[] client_side_data; // Server-Side Data - glDeleteBuffers(1, &server_side_data); + media_glDeleteBuffers(1, &server_side_data); } // Upload Data @@ -24,6 +24,6 @@ void Buffer::upload(const intptr_t offset, const ssize_t size, const void *data) // Client-Side Data memcpy(client_side_data + offset, data, size); // Server-Side Data - glBindBuffer(GL_ARRAY_BUFFER, server_side_data); - glBufferSubData(GL_ARRAY_BUFFER, offset, size, data); + media_glBindBuffer(GL_ARRAY_BUFFER, server_side_data); + media_glBufferSubData(GL_ARRAY_BUFFER, offset, size, data); } diff --git a/mods/src/multidraw/glue.cpp b/mods/src/multidraw/glue.cpp index 733eba7888..3d0255d2e6 100644 --- a/mods/src/multidraw/glue.cpp +++ b/mods/src/multidraw/glue.cpp @@ -22,30 +22,30 @@ static void setup_multidraw(const int chunks, GLuint *buffers) { buffers[i] = i + MULTIDRAW_BASE; } } -HOOK(glDeleteBuffers, void, (GLsizei n, const GLuint *buffers)) { +HOOK(media_glDeleteBuffers, void, (GLsizei n, const GLuint *buffers)) { if (buffers[0] >= MULTIDRAW_BASE) { delete storage; } else { - real_glDeleteBuffers()(n, buffers); + real_media_glDeleteBuffers()(n, buffers); } } // Setup Fake OpenGL Buffers static int current_chunk = -1; -HOOK(glBindBuffer, void, (const GLenum target, GLuint buffer)) { +HOOK(media_glBindBuffer, void, (const GLenum target, GLuint buffer)) { if (target == GL_ARRAY_BUFFER && buffer >= MULTIDRAW_BASE && storage != nullptr) { current_chunk = int(buffer - MULTIDRAW_BASE); buffer = storage->buffer->server_side_data; } else { current_chunk = -1; } - real_glBindBuffer()(target, buffer); + real_media_glBindBuffer()(target, buffer); } -HOOK(glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, GLenum usage)) { +HOOK(media_glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, GLenum usage)) { if (target == GL_ARRAY_BUFFER && current_chunk >= 0 && storage != nullptr) { storage->upload(current_chunk, size, data); } else { - real_glBufferData()(target, size, data, usage); + real_media_glBufferData()(target, size, data, usage); } } @@ -68,31 +68,31 @@ static void multidraw_renderSameAsLast(const LevelRenderer *self, const float b) const float x = camera->old_x + ((camera->x - camera->old_x) * b); const float y = camera->old_y + ((camera->y - camera->old_y) * b); const float z = camera->old_z + ((camera->z - camera->old_z) * b); - glPushMatrix(); - glTranslatef(-x, -y, -z); + media_glPushMatrix(); + media_glTranslatef(-x, -y, -z); // Setup OpenGL - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, storage->buffer->server_side_data); - glVertexPointer(3, GL_FLOAT, multidraw_vertex_size, (void *) 0); - glTexCoordPointer(2, GL_FLOAT, multidraw_vertex_size, (void *) 0xc); - glColorPointer(4, GL_UNSIGNED_BYTE, multidraw_vertex_size, (void *) 0x14); + media_glEnableClientState(GL_VERTEX_ARRAY); + media_glEnableClientState(GL_COLOR_ARRAY); + media_glEnableClientState(GL_TEXTURE_COORD_ARRAY); + media_glBindBuffer(GL_ARRAY_BUFFER, storage->buffer->server_side_data); + media_glVertexPointer(3, GL_FLOAT, multidraw_vertex_size, (void *) 0); + media_glTexCoordPointer(2, GL_FLOAT, multidraw_vertex_size, (void *) 0xc); + media_glColorPointer(4, GL_UNSIGNED_BYTE, multidraw_vertex_size, (void *) 0x14); // Draw if (supports_multidraw()) { - glMultiDrawArrays(GL_TRIANGLES, multidraw_firsts, multidraw_counts, multidraw_total); + media_glMultiDrawArrays(GL_TRIANGLES, multidraw_firsts, multidraw_counts, multidraw_total); } else { for (int i = 0; i < multidraw_total; i++) { - glDrawArrays(GL_TRIANGLES, multidraw_firsts[i], multidraw_counts[i]); + media_glDrawArrays(GL_TRIANGLES, multidraw_firsts[i], multidraw_counts[i]); } } // Cleanup - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glPopMatrix(); + media_glDisableClientState(GL_COLOR_ARRAY); + media_glDisableClientState(GL_TEXTURE_COORD_ARRAY); + media_glPopMatrix(); } static int LevelRenderer_renderChunks_injection(__attribute__((unused)) LevelRenderer_renderChunks_t original, LevelRenderer *self, const int start, const int end, const int a, const float b) { // Batch diff --git a/mods/src/screenshot/screenshot.cpp b/mods/src/screenshot/screenshot.cpp index d45c694c76..18524f747c 100644 --- a/mods/src/screenshot/screenshot.cpp +++ b/mods/src/screenshot/screenshot.cpp @@ -66,7 +66,7 @@ void screenshot_take(Gui *gui) { // Get Image Size GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); + media_glGetIntegerv(GL_VIEWPORT, viewport); const int x = viewport[0]; const int y = viewport[1]; const int width = viewport[2]; @@ -77,7 +77,7 @@ void screenshot_take(Gui *gui) { { // Handle Alignment int alignment; - glGetIntegerv(GL_PACK_ALIGNMENT, &alignment); + media_glGetIntegerv(GL_PACK_ALIGNMENT, &alignment); // Round line_size = ALIGN_UP(line_size, alignment); } @@ -86,7 +86,7 @@ void screenshot_take(Gui *gui) { // Read Pixels unsigned char *pixels = (unsigned char *) malloc(size); ALLOC_CHECK(pixels); - glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + media_glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // Save Image if (save_png(file.c_str(), pixels, line_size, width, height)) { diff --git a/mods/src/server/server.cpp b/mods/src/server/server.cpp index af182b7aa3..624aa293a6 100644 --- a/mods/src/server/server.cpp +++ b/mods/src/server/server.cpp @@ -247,7 +247,7 @@ static void handle_server_stop(Minecraft *minecraft) { // Stop Game SDL_Event event; event.type = SDL_QUIT; - SDL_PushEvent(&event); + media_SDL_PushEvent(&event); } } diff --git a/mods/src/shading/lighting.cpp b/mods/src/shading/lighting.cpp index ecff315de9..bcfc92205b 100644 --- a/mods/src/shading/lighting.cpp +++ b/mods/src/shading/lighting.cpp @@ -14,32 +14,32 @@ static float *get_buffer(const float a, const float b, const float c, const floa return buffer; } static void lighting_turn_on() { - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_LIGHT1); - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + media_glEnable(GL_LIGHTING); + media_glEnable(GL_LIGHT0); + media_glEnable(GL_LIGHT1); + media_glEnable(GL_COLOR_MATERIAL); + media_glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); constexpr float a = 0.4f; constexpr float d = 0.6f; constexpr float s = 0.0f; Vec3 l = Vec3(0.2f, 1.0f, -0.7f).normalized(); - glLightfv(GL_LIGHT0, GL_POSITION, get_buffer(l.x, l.y, l.z, 0)); - glLightfv(GL_LIGHT0, GL_DIFFUSE, get_buffer(d, d, d, 1)); - glLightfv(GL_LIGHT0, GL_AMBIENT, get_buffer(0, 0, 0, 1)); - glLightfv(GL_LIGHT0, GL_SPECULAR, get_buffer(s, s, s, 1.0f)); + media_glLightfv(GL_LIGHT0, GL_POSITION, get_buffer(l.x, l.y, l.z, 0)); + media_glLightfv(GL_LIGHT0, GL_DIFFUSE, get_buffer(d, d, d, 1)); + media_glLightfv(GL_LIGHT0, GL_AMBIENT, get_buffer(0, 0, 0, 1)); + media_glLightfv(GL_LIGHT0, GL_SPECULAR, get_buffer(s, s, s, 1.0f)); l = Vec3(-0.2f, 1.0f, 0.7f).normalized(); - glLightfv(GL_LIGHT1, GL_POSITION, get_buffer(l.x, l.y, l.z, 0)); - glLightfv(GL_LIGHT1, GL_DIFFUSE, get_buffer(d, d, d, 1)); - glLightfv(GL_LIGHT1, GL_AMBIENT, get_buffer(0, 0, 0, 1)); - glLightfv(GL_LIGHT1, GL_SPECULAR, get_buffer(s, s, s, 1.0f)); - glShadeModel(GL_FLAT); - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, get_buffer(a, a, a, 1)); + media_glLightfv(GL_LIGHT1, GL_POSITION, get_buffer(l.x, l.y, l.z, 0)); + media_glLightfv(GL_LIGHT1, GL_DIFFUSE, get_buffer(d, d, d, 1)); + media_glLightfv(GL_LIGHT1, GL_AMBIENT, get_buffer(0, 0, 0, 1)); + media_glLightfv(GL_LIGHT1, GL_SPECULAR, get_buffer(s, s, s, 1.0f)); + media_glShadeModel(GL_FLAT); + media_glLightModelfv(GL_LIGHT_MODEL_AMBIENT, get_buffer(a, a, a, 1)); } static void lighting_turn_off() { - glDisable(GL_LIGHTING); - glDisable(GL_LIGHT0); - glDisable(GL_LIGHT1); - glDisable(GL_COLOR_MATERIAL); + media_glDisable(GL_LIGHTING); + media_glDisable(GL_LIGHT0); + media_glDisable(GL_LIGHT1); + media_glDisable(GL_COLOR_MATERIAL); } // Entity Rendering @@ -52,48 +52,48 @@ static void LevelRenderer_renderEntities_injection(LevelRenderer_renderEntities_ // Held Items static void ItemInHandRenderer_render_glPopMatrix_injection() { lighting_turn_on(); - glPopMatrix(); - glEnable(GL_RESCALE_NORMAL); + media_glPopMatrix(); + media_glEnable(GL_RESCALE_NORMAL); } static void ItemInHandRenderer_render_injection(ItemInHandRenderer_render_t original, ItemInHandRenderer *self, float a) { original(self, a); lighting_turn_off(); - glDisable(GL_RESCALE_NORMAL); + media_glDisable(GL_RESCALE_NORMAL); } // GL_RESCALE_NORMAL static void enable_rescale_normal() { - glPushMatrix(); - glEnable(GL_RESCALE_NORMAL); + media_glPushMatrix(); + media_glEnable(GL_RESCALE_NORMAL); } static void disable_rescale_normal() { - glPopMatrix(); - glDisable(GL_RESCALE_NORMAL); + media_glPopMatrix(); + media_glDisable(GL_RESCALE_NORMAL); } template static void EntityRenderer_render_injection(const std::function &original, Self *self, Entity *entity, float x, float y, float z, float rot, float a) { - glEnable(GL_RESCALE_NORMAL); + media_glEnable(GL_RESCALE_NORMAL); original(self, entity, x, y, z, rot, a); - glDisable(GL_RESCALE_NORMAL); + media_glDisable(GL_RESCALE_NORMAL); } // Fix Falling Tile Rendering static void FallingTileRenderer_render_TileRenderer_renderBlock_injection(TileRenderer *self, Tile *tile, LevelSource *level, int x, int y, int z) { - glDisable(GL_LIGHTING); + media_glDisable(GL_LIGHTING); self->renderBlock(tile, level, x, y, z); - glEnable(GL_LIGHTING); + media_glEnable(GL_LIGHTING); } static void TntRenderer_render_TileRenderer_renderTile_injection(TileRenderer *self, Tile *tile, int data) { - glDisable(GL_LIGHTING); + media_glDisable(GL_LIGHTING); self->renderTile(tile, data); - glEnable(GL_LIGHTING); + media_glEnable(GL_LIGHTING); } // Fix Names static void MobRenderer_renderNameTag_injection(MobRenderer_renderNameTag_t original, MobRenderer *self, Mob *mob, const std::string &name, const float x, const float y, const float z, const int param_1) { - glDisable(GL_LIGHTING); + media_glDisable(GL_LIGHTING); original(self, mob, name, x, y, z, param_1); - glEnable(GL_LIGHTING); + media_glEnable(GL_LIGHTING); } // Armor Screen diff --git a/mods/src/shading/tesselator.cpp b/mods/src/shading/tesselator.cpp index 42367a5361..84307dd529 100644 --- a/mods/src/shading/tesselator.cpp +++ b/mods/src/shading/tesselator.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include @@ -77,8 +76,8 @@ static RenderChunk Tesselator_end_injection(Tesselator *self, const bool use_giv out.vertices = CustomTesselator::instance.vertex_count; if (out.vertices > 0) { out.buffer = use_given_buffer ? buffer : get_next_buffer(); - glBindBuffer(GL_ARRAY_BUFFER, out.buffer); - glBufferData(GL_ARRAY_BUFFER, out.vertices * sizeof(CustomVertex), CustomTesselator::instance.vertices, GL_STATIC_DRAW); + media_glBindBuffer(GL_ARRAY_BUFFER, out.buffer); + media_glBufferData(GL_ARRAY_BUFFER, out.vertices * sizeof(CustomVertex), CustomTesselator::instance.vertices, GL_STATIC_DRAW); } // Finish self->clear(); @@ -97,36 +96,36 @@ static void Tesselator_draw_injection(Tesselator *self) { const int vertices = CustomTesselator::instance.vertex_count; if (vertices > 0) { const GLuint buffer = get_next_buffer(); - glBindBuffer(GL_ARRAY_BUFFER, buffer); - glBufferData(GL_ARRAY_BUFFER, vertices * sizeof(CustomVertex), CustomTesselator::instance.vertices, GL_STATIC_DRAW); + media_glBindBuffer(GL_ARRAY_BUFFER, buffer); + media_glBufferData(GL_ARRAY_BUFFER, vertices * sizeof(CustomVertex), CustomTesselator::instance.vertices, GL_STATIC_DRAW); if (self->has_texture) { - glTexCoordPointer(2, GL_FLOAT, sizeof(CustomVertex), (void *) offsetof(CustomVertex, uv)); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + media_glTexCoordPointer(2, GL_FLOAT, sizeof(CustomVertex), (void *) offsetof(CustomVertex, uv)); + media_glEnableClientState(GL_TEXTURE_COORD_ARRAY); } if (self->has_color) { - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(CustomVertex), (void *) offsetof(CustomVertex, color)); - glEnableClientState(GL_COLOR_ARRAY); + media_glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(CustomVertex), (void *) offsetof(CustomVertex, color)); + media_glEnableClientState(GL_COLOR_ARRAY); } if (CustomTesselator::instance.normal) { - glNormalPointer(GL_BYTE, sizeof(CustomVertex), (void *) offsetof(CustomVertex, normal)); - glEnableClientState(GL_NORMAL_ARRAY); + media_glNormalPointer(GL_BYTE, sizeof(CustomVertex), (void *) offsetof(CustomVertex, normal)); + media_glEnableClientState(GL_NORMAL_ARRAY); } - glVertexPointer(3, GL_FLOAT, sizeof(CustomVertex), (void *) offsetof(CustomVertex, pos)); - glEnableClientState(GL_VERTEX_ARRAY); + media_glVertexPointer(3, GL_FLOAT, sizeof(CustomVertex), (void *) offsetof(CustomVertex, pos)); + media_glEnableClientState(GL_VERTEX_ARRAY); int mode = self->mode; if (mode == GL_QUADS) { mode = GL_TRIANGLES; } - glDrawArrays(mode, 0, vertices); - glDisableClientState(GL_VERTEX_ARRAY); + media_glDrawArrays(mode, 0, vertices); + media_glDisableClientState(GL_VERTEX_ARRAY); if (self->has_texture) { - glDisableClientState(GL_TEXTURE_COORD_ARRAY); + media_glDisableClientState(GL_TEXTURE_COORD_ARRAY); } if (self->has_color) { - glDisableClientState(GL_COLOR_ARRAY); + media_glDisableClientState(GL_COLOR_ARRAY); } if (CustomTesselator::instance.normal) { - glDisableClientState(GL_NORMAL_ARRAY); + media_glDisableClientState(GL_NORMAL_ARRAY); } } // Finish @@ -135,17 +134,17 @@ static void Tesselator_draw_injection(Tesselator *self) { } static void drawArrayVT_injection(const int buffer, const int vertices, int vertex_size, const uint mode) { vertex_size = sizeof(CustomVertex); - glBindBuffer(GL_ARRAY_BUFFER, buffer); - glTexCoordPointer(2, GL_FLOAT, vertex_size, (void *) offsetof(CustomVertex, uv)); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(3, GL_FLOAT, vertex_size, (void *) offsetof(CustomVertex, pos)); - glEnableClientState(GL_VERTEX_ARRAY); - glNormalPointer(GL_BYTE, sizeof(CustomVertex), (void *) offsetof(CustomVertex, normal)); - glEnableClientState(GL_NORMAL_ARRAY); - glDrawArrays(mode, 0, vertices); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); + media_glBindBuffer(GL_ARRAY_BUFFER, buffer); + media_glTexCoordPointer(2, GL_FLOAT, vertex_size, (void *) offsetof(CustomVertex, uv)); + media_glEnableClientState(GL_TEXTURE_COORD_ARRAY); + media_glVertexPointer(3, GL_FLOAT, vertex_size, (void *) offsetof(CustomVertex, pos)); + media_glEnableClientState(GL_VERTEX_ARRAY); + media_glNormalPointer(GL_BYTE, sizeof(CustomVertex), (void *) offsetof(CustomVertex, normal)); + media_glEnableClientState(GL_NORMAL_ARRAY); + media_glDrawArrays(mode, 0, vertices); + media_glDisableClientState(GL_VERTEX_ARRAY); + media_glDisableClientState(GL_TEXTURE_COORD_ARRAY); + media_glDisableClientState(GL_NORMAL_ARRAY); } // Add Vertex @@ -190,21 +189,6 @@ static void Tesselator_normal_injection(__attribute__((unused)) Tesselator *self CustomTesselator::instance.normal = xx | (yy << 8) | (zz << 16); } -static void explore(const __cxxabiv1::__class_type_info *info) { - INFO("Test: %s", info->name()); - const __cxxabiv1::__si_class_type_info *a = dynamic_cast(info); - if (a) { - explore(a->__base_type); - } else { - const __cxxabiv1::__vmi_class_type_info *b = dynamic_cast(info); - if (b) { - for (unsigned int i = 0; i < b->__base_count; i++) { - explore(b->__base_info[i].__base_type); - } - } - } -} - // Init void _init_custom_tesselator() { multidraw_vertex_size = sizeof(CustomVertex); @@ -216,8 +200,4 @@ void _init_custom_tesselator() { overwrite_call((void *) Tesselator_vertex->backup, (void *) Tesselator_vertex_injection, true); overwrite_call((void *) Tesselator_normal->backup, (void *) Tesselator_normal_injection, true); overwrite_call((void *) Common_drawArrayVT->backup, (void *) drawArrayVT_injection, true); - - const std::type_info *info = *(((std::type_info **) Cow_vtable_base) - 1); - const __cxxabiv1::__si_class_type_info *info2 = dynamic_cast(info); - explore(info2); } \ No newline at end of file diff --git a/mods/src/skin/loader.cpp b/mods/src/skin/loader.cpp index 1415ee43a2..311208bb3a 100644 --- a/mods/src/skin/loader.cpp +++ b/mods/src/skin/loader.cpp @@ -42,10 +42,10 @@ static void load_pending_skins(__attribute__((unused)) Minecraft *minecraft) { // Load Texture GLint last_texture; - glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); - glBindTexture(GL_TEXTURE_2D, skin.texture_id); - glTexSubImage2D_with_scaling(GL_TEXTURE_2D, 0, 0, 0, width, height, SKIN_WIDTH, SKIN_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, img); - glBindTexture(GL_TEXTURE_2D, last_texture); + media_glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); + media_glBindTexture(GL_TEXTURE_2D, skin.texture_id); + media_glTexSubImage2D_with_scaling(GL_TEXTURE_2D, 0, 0, 0, width, height, SKIN_WIDTH, SKIN_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, img); + media_glBindTexture(GL_TEXTURE_2D, last_texture); // Free stbi_image_free(img); diff --git a/mods/src/textures/textures.cpp b/mods/src/textures/textures.cpp index f1fbc75b67..77d21f274d 100644 --- a/mods/src/textures/textures.cpp +++ b/mods/src/textures/textures.cpp @@ -34,18 +34,18 @@ static std::vector &get_texture_data() { static std::vector data; return data; } -HOOK(glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)) { +HOOK(media_glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)) { // Store texture_data data = {}; - glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint *) &data.id); + media_glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint *) &data.id); data.width = width; data.height = height; get_texture_data().push_back(data); // Call Original Method - real_glTexImage2D()(target, level, internalformat, width, height, border, format, type, pixels); + real_media_glTexImage2D()(target, level, internalformat, width, height, border, format, type, pixels); } -HOOK(glDeleteTextures, void, (GLsizei n, const GLuint *textures)) { +HOOK(media_glDeleteTextures, void, (GLsizei n, const GLuint *textures)) { // Remove Old Data for (int i = 0; i < n; i++) { const GLuint id = textures[i]; @@ -61,7 +61,7 @@ HOOK(glDeleteTextures, void, (GLsizei n, const GLuint *textures)) { } // Call Original Method - real_glDeleteTextures()(n, textures); + real_media_glDeleteTextures()(n, textures); } static void get_texture_size(const GLuint id, GLsizei *width, GLsizei *height) { // Iterate @@ -88,7 +88,7 @@ static int get_line_size(const int width) { { // Handle Alignment int alignment; - glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); + media_glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); // Round line_size = ALIGN_UP(line_size, alignment); } @@ -123,10 +123,10 @@ static void *scale_texture(const unsigned char *src, const GLsizei old_width, co } // Scale Animated Textures -void glTexSubImage2D_with_scaling(const GLenum target, const GLint level, const GLint xoffset, const GLint yoffset, const GLsizei width, const GLsizei height, const GLsizei normal_texture_width, const GLsizei normal_texture_height, const GLenum format, const GLenum type, const void *pixels) { +void media_glTexSubImage2D_with_scaling(const GLenum target, const GLint level, const GLint xoffset, const GLint yoffset, const GLsizei width, const GLsizei height, const GLsizei normal_texture_width, const GLsizei normal_texture_height, const GLenum format, const GLenum type, const void *pixels) { // Get Current Texture Size GLint current_texture; - glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture); + media_glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture); GLsizei texture_width; GLsizei texture_height; get_texture_size(current_texture, &texture_width, &texture_height); @@ -138,7 +138,7 @@ void glTexSubImage2D_with_scaling(const GLenum target, const GLint level, const // Only Scale If Needed if (width_factor == 1.0f && height_factor == 1.0f) { // No Scaling - glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); + media_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); } else { // Check if (format != GL_RGBA || type != GL_UNSIGNED_BYTE) { @@ -154,14 +154,14 @@ void glTexSubImage2D_with_scaling(const GLenum target, const GLint level, const // Call Original Method const GLint new_xoffset = xoffset * width_factor; const GLint new_yoffset = yoffset * height_factor; - glTexSubImage2D(target, level, new_xoffset, new_yoffset, new_width, new_height, format, type, new_pixels); + media_glTexSubImage2D(target, level, new_xoffset, new_yoffset, new_width, new_height, format, type, new_pixels); // Free free(new_pixels); } } static void Textures_tick_glTexSubImage2D_injection(const GLenum target, const GLint level, const GLint xoffset, const GLint yoffset, const GLsizei width, const GLsizei height, const GLenum format, const GLenum type, const void *pixels) { - glTexSubImage2D_with_scaling(target, level, xoffset, yoffset, width, height, 256, 256, format, type, pixels); + media_glTexSubImage2D_with_scaling(target, level, xoffset, yoffset, width, height, 256, 256, format, type, pixels); } // Load Textures diff --git a/mods/src/title-screen/splashes.cpp b/mods/src/title-screen/splashes.cpp index 9f82465e9a..19ae38beaf 100644 --- a/mods/src/title-screen/splashes.cpp +++ b/mods/src/title-screen/splashes.cpp @@ -107,24 +107,24 @@ static bool draw_splash(StartMenuScreen *screen, const float y_factor, const boo splash_width *= multiplier; } // Position - glPushMatrix(); - glTranslatef(x, y, 0.0f); + media_glPushMatrix(); + media_glTranslatef(x, y, 0.0f); // Rotate - glRotatef(SplashLine::angle, 0.0f, 0.0f, 1.0f); + media_glRotatef(SplashLine::angle, 0.0f, 0.0f, 1.0f); // Oscillate const float timeMS = float(Common::getTimeMs() % 1000) / 1000.0f; const float oscillation = (scale / SplashLine::max_scale) * 0.1f; scale = scale - Mth::abs(oscillation * Mth::sin(2.0f * float(M_PI) * timeMS)); // Scale - glTranslatef(splash_width / 2.0f, 0, 0); - glScalef(scale, scale, 1); - glTranslatef(-text_width / 2.0f, 0, 0); + media_glTranslatef(splash_width / 2.0f, 0, 0); + media_glScalef(scale, scale, 1); + media_glTranslatef(-text_width / 2.0f, 0, 0); // Render float y_offset = float(-line_height) / 2.0f; y_offset += 1; // Make It Look Vertically Centered screen->drawString(screen->font, current_splash, 0, y_offset, 0xffff00); // Finish - glPopMatrix(); + media_glPopMatrix(); return true; } static void StartMenuScreen_render_injection(StartMenuScreen_render_t original, StartMenuScreen *screen, const int mouse_x, const int mouse_y, const float param_1) { diff --git a/mods/src/title-screen/title-screen.cpp b/mods/src/title-screen/title-screen.cpp index 26fc5fc092..bc01fa75c7 100644 --- a/mods/src/title-screen/title-screen.cpp +++ b/mods/src/title-screen/title-screen.cpp @@ -110,7 +110,7 @@ static void StartMenuScreen_render_Screen_renderBackground_injection(StartMenuSc constexpr int w = modern_title_width / 2; constexpr int h = modern_title_height; Tesselator& t = Tesselator::instance; - glColor4f(1, 1, 1, 1); + media_glColor4f(1, 1, 1, 1); t.begin(7); t.vertexUV(x - w, y + h, self->z, 0, 1); t.vertexUV(x + w, y + h, self->z, 1, 1);