From 426779d02f4f6811af2895a97f56fc21f7998357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo?= Date: Tue, 24 Dec 2024 00:39:25 -0300 Subject: [PATCH] Use SDL Window as the WindowHandle (Enables wayland support). (#520) --- CMakeLists.txt | 3 +++ lib/N64ModernRuntime | 2 +- lib/rt64 | 2 +- src/main/main.cpp | 24 +++++++++++------------- src/main/rt64_render_context.cpp | 7 ++----- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b900bc..d737837 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ if (WIN32) endif() set(RT64_STATIC TRUE) +set(RT64_SDL_WINDOW_VULKAN TRUE) add_subdirectory(${CMAKE_SOURCE_DIR}/lib/rt64 ${CMAKE_BINARY_DIR}/rt64) # set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}") @@ -247,6 +248,8 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux") find_package(SDL2 REQUIRED) find_package(X11 REQUIRED) + add_compile_definitions("RT64_SDL_WINDOW_VULKAN") + # Generate icon_bytes.c from the app icon PNG. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/icon_bytes.c ${CMAKE_CURRENT_BINARY_DIR}/icon_bytes.h COMMAND file_to_c ${CMAKE_SOURCE_DIR}/icons/512.png icon_bytes ${CMAKE_CURRENT_BINARY_DIR}/icon_bytes.c ${CMAKE_CURRENT_BINARY_DIR}/icon_bytes.h diff --git a/lib/N64ModernRuntime b/lib/N64ModernRuntime index d5c81d0..1361c48 160000 --- a/lib/N64ModernRuntime +++ b/lib/N64ModernRuntime @@ -1 +1 @@ -Subproject commit d5c81d0a6bf2e5f36747a095a7a060d7623bbf58 +Subproject commit 1361c48f59877f1bb8189a27bf38e1983fcbb738 diff --git a/lib/rt64 b/lib/rt64 index 67422c3..16f1708 160000 --- a/lib/rt64 +++ b/lib/rt64 @@ -1 +1 @@ -Subproject commit 67422c3b647058d3d38f2813a2abe79cf1638f13 +Subproject commit 16f1708da21048684838c22abb43b60b4ce19e2e diff --git a/src/main/main.cpp b/src/main/main.cpp index bf13a28..49cd8fa 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -55,14 +55,12 @@ ultramodern::gfx_callbacks_t::gfx_data_t create_gfx() { SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); -#if defined(__linux__) - SDL_SetHint(SDL_HINT_VIDEODRIVER, "x11"); -#endif - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) > 0) { exit_error("Failed to initialize SDL2: %s\n", SDL_GetError()); } + fprintf(stdout, "SDL Video Driver: %s\n", SDL_GetCurrentVideoDriver()); + return {}; } @@ -118,7 +116,13 @@ bool SetImageAsIcon(const char* filename, SDL_Window* window) SDL_Window* window; ultramodern::renderer::WindowHandle create_window(ultramodern::gfx_callbacks_t::gfx_data_t) { - window = SDL_CreateWindow("Zelda 64: Recompiled", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1600, 960, SDL_WINDOW_RESIZABLE ); + uint32_t flags = SDL_WINDOW_RESIZABLE; + +#if defined(RT64_SDL_WINDOW_VULKAN) + flags |= SDL_WINDOW_VULKAN; +#endif + + window = SDL_CreateWindow("Zelda 64: Recompiled", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1600, 960, flags); #if defined(__linux__) SetImageAsIcon("icons/512.png",window); if (ultramodern::renderer::get_graphics_config().wm_option == ultramodern::renderer::WindowMode::Fullscreen) { // TODO: Remove once RT64 gets native fullscreen support on Linux @@ -138,14 +142,8 @@ ultramodern::renderer::WindowHandle create_window(ultramodern::gfx_callbacks_t:: #if defined(_WIN32) return ultramodern::renderer::WindowHandle{ wmInfo.info.win.window, GetCurrentThreadId() }; -#elif defined(__ANDROID__) - static_assert(false && "Unimplemented"); -#elif defined(__linux__) - if (wmInfo.subsystem != SDL_SYSWM_X11) { - exit_error("Unsupported SDL2 video driver \"%s\". Only X11 is supported on Linux.\n", SDL_GetCurrentVideoDriver()); - } - - return ultramodern::renderer::WindowHandle{ wmInfo.info.x11.display, wmInfo.info.x11.window }; +#elif defined(__linux__) || defined(__ANDROID__) + return ultramodern::renderer::WindowHandle{ window }; #else static_assert(false && "Unimplemented"); #endif diff --git a/src/main/rt64_render_context.cpp b/src/main/rt64_render_context.cpp index e800d99..126ab70 100644 --- a/src/main/rt64_render_context.cpp +++ b/src/main/rt64_render_context.cpp @@ -200,11 +200,8 @@ zelda64::renderer::RT64Context::RT64Context(uint8_t* rdram, ultramodern::rendere RT64::Application::Core appCore{}; #if defined(_WIN32) appCore.window = window_handle.window; -#elif defined(__ANDROID__) - assert(false && "Unimplemented"); -#elif defined(__linux__) - appCore.window.display = window_handle.display; - appCore.window.window = window_handle.window; +#elif defined(__linux__) || defined(__ANDROID__) + appCore.window = window_handle; #elif defined(__APPLE__) appCore.window.window = window_handle.window; appCore.window.view = window_handle.view;