From 5af44ba3ea47e336232ea3a33c2f1bcc09060159 Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Wed, 25 Nov 2026 19:47:31 +0200 Subject: [PATCH 1/3] glue: add Vulkan renderer variant for Windows (VK_KHR_win32_surface) Adds a Vulkan build variant of the Windows platform glue, mirroring the existing Linux (xorg/wayland) Vulkan glue: - window: new constructor that does not create a WGL context (the Vulkan device owns the swapchain); expose the HWND - application: create the Vulkan instance (VK_KHR_SURFACE, VK_KHR_WIN32_SURFACE), physical device and logical device (VK_KHR_SWAPCHAIN); create a VK_KHR_win32_surface from the window handle in make_window() and construct the Vulkan render context - build: ruisapp-vulkan CMake variant and test app on Windows, ruisapp-vulkan rule in the makefile --- build/cmake/CMakeLists.txt | 66 +++++++++++++++++++----- src/makefile | 3 ++ src/ruisapp/glue/windows/application.cxx | 56 +++++++++++++++++--- src/ruisapp/glue/windows/application.hxx | 38 +++++++++++++- src/ruisapp/glue/windows/glue.cxx | 10 +++- src/ruisapp/glue/windows/window.cxx | 41 ++++++++++++--- src/ruisapp/glue/windows/window.hxx | 19 +++++++ 7 files changed, 205 insertions(+), 28 deletions(-) diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index 0f19d2ec..5335525c 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -44,8 +44,16 @@ else() set(ruisapp_build_opengl_variant True) set(ruisapp_build_opengles_variant True) + # The Vulkan variant is built on Windows (VK_KHR_win32_surface). + # On other platforms in this branch the platform glue does not support Vulkan yet. + set(ruisapp_build_vulkan_variant False) + if(WIN32) + set(ruisapp_build_vulkan_variant True) + endif() + set(ruisapp_opengl_install_include_directory ../../src/${name}) set(ruisapp_opengles_install_include_directory) # opengl variant is also built and will install the headers + set(ruisapp_vulkan_install_include_directory) # opengl variant is also built and will install the headers endif() # ==================== @@ -271,6 +279,27 @@ else() target_compile_options(${name}-opengles PRIVATE -Wno-deprecated-declarations) endif() endif() + + if(ruisapp_build_vulkan_variant) + myci_declare_library(${name}-vulkan + SOURCES + ${srcs} + PUBLIC_INCLUDE_DIRECTORIES + ../../src + INSTALL_INCLUDE_DIRECTORIES + ${ruisapp_vulkan_install_include_directory} + PREPROCESSOR_DEFINITIONS + "RUISAPP_RENDER_VULKAN" + DEPENDENCIES + nitki + ruis + ruis-render-vulkan + opros + setka + tml + NO_EXPORT + ) + endif() endif() # ==================== @@ -288,21 +317,20 @@ if(LINUX) ${name}-vulkan-xorg ${name}-vulkan-wayland ) -elseif(ruisapp_build_opengl_variant AND ruisapp_build_opengles_variant) - myci_export( - TARGETS - ${name}-opengl - ${name}-opengles - ) -elseif(ruisapp_build_opengl_variant) - myci_export( - TARGETS - ${name}-opengl - ) -elseif(ruisapp_build_opengles_variant) +else() + set(ruisapp_export_targets) + if(ruisapp_build_opengl_variant) + list(APPEND ruisapp_export_targets ${name}-opengl) + endif() + if(ruisapp_build_opengles_variant) + list(APPEND ruisapp_export_targets ${name}-opengles) + endif() + if(ruisapp_build_vulkan_variant) + list(APPEND ruisapp_export_targets ${name}-vulkan) + endif() myci_export( TARGETS - ${name}-opengles + ${ruisapp_export_targets} ) endif() @@ -378,4 +406,16 @@ else() ) endif() endif() + + if(ruisapp_build_vulkan_variant) + myci_declare_application(${name}-vulkan-test + GUI + SOURCES + ${app_srcs} + RESOURCE_DIRECTORY + ../../tests/app/res + DEPENDENCIES + ruisapp::${name}-vulkan + ) + endif() endif() diff --git a/src/makefile b/src/makefile index 5b385302..65eedd7f 100644 --- a/src/makefile +++ b/src/makefile @@ -151,6 +151,9 @@ ifeq ($(os), linux) $(eval $(call ruisapp_rules,opengles,sdl)) +else ifeq ($(os), windows) + $(eval $(call ruisapp_rules,opengl,)) + $(eval $(call ruisapp_rules,vulkan,)) else $(eval $(call ruisapp_rules,opengl,)) endif diff --git a/src/ruisapp/glue/windows/application.cxx b/src/ruisapp/glue/windows/application.cxx index fca24d20..a62101c2 100644 --- a/src/ruisapp/glue/windows/application.cxx +++ b/src/ruisapp/glue/windows/application.cxx @@ -103,25 +103,43 @@ application_glue::application_glue(const utki::version_duplet& gl_version) : gl_version(gl_version), shared_gl_context_native_window(utki::make_shared( this->display, +#ifdef RUISAPP_RENDER_VULKAN + ruisapp::window_parameters{ + .dims = {1, 1}, + .fullscreen = false +}, + nullptr // no shared gl context +#else this->gl_version, ruisapp::window_parameters{ .dims = {1, 1}, .fullscreen = false }, nullptr // no shared gl context +#endif )), +#ifdef RUISAPP_RENDER_VULKAN + device(make_device()), +#endif render_factory([&]() { +#ifdef RUISAPP_RENDER_VULKAN + // Vulkan has no "current context" — a null surface is sufficient for the factory (resource creation) + return utki::make_shared( + utki::make_shared(this->device.get(), VK_NULL_HANDLE) + ); +#else utki::logcat_debug("application_glue::application_glue(): creating shared gl context", '\n'); -#ifdef RUISAPP_RENDER_OPENGL +# ifdef RUISAPP_RENDER_OPENGL using factory_type = ruis::render::opengl::factory; -#elif defined(RUISAPP_RENDER_OPENGLES) +# elif defined(RUISAPP_RENDER_OPENGLES) using factory_type = ruis::render::opengles::factory; -#else -# error "Unknown graphics API" -#endif +# else +# error "Unknown graphics API" +# endif auto c = utki::make_shared(this->shared_gl_context_native_window); utki::logcat_debug("application_glue::application_glue(): shared gl context created", '\n'); return c; +#endif }()), common_shaders(this->render_factory.get().make_shaders()), common_render_objects(utki::make_shared(this->render_factory.get())), @@ -180,12 +198,17 @@ app_window* application_glue::get_window(native_window::window_id_type id) ruisapp::window& application_glue::make_window(ruisapp::window_parameters window_params) { +#ifdef RUISAPP_RENDER_VULKAN + auto ruis_native_window = + utki::make_shared(this->display, window_params, &this->shared_gl_context_native_window.get()); +#else auto ruis_native_window = utki::make_shared( this->display, this->gl_version, window_params, &this->shared_gl_context_native_window.get() ); +#endif auto ruis_context = utki::make_shared(ruis::context::parameters{ .post_to_ui_thread_function = @@ -194,7 +217,28 @@ ruisapp::window& application_glue::make_window(ruisapp::window_parameters window }, .updater = this->updater, .renderer = utki::make_shared( -#ifdef RUISAPP_RENDER_OPENGL +#ifdef RUISAPP_RENDER_VULKAN + utki::make_shared( + ruis_native_window, + [&]() { + // Create a VK_KHR_win32_surface from the window handle. The surface is owned + // by the surface provider (destroyed together with the render context). + VkWin32SurfaceCreateInfoKHR sci{}; + sci.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; + sci.hinstance = GetModuleHandle(nullptr); + sci.hwnd = ruis_native_window.get().get_hwnd(); + VkSurfaceKHR vk_surface = VK_NULL_HANDLE; + vkCreateWin32SurfaceKHR( + this->device.get().get_instance(), // + &sci, + nullptr, + &vk_surface + ); + return utki::make_shared(this->device.get(), vk_surface); + }(), + this->render_factory + ), +#elif defined(RUISAPP_RENDER_OPENGL) utki::make_shared(ruis_native_window, this->render_factory), #elif defined(RUISAPP_RENDER_OPENGLES) utki::make_shared(ruis_native_window, this->render_factory), diff --git a/src/ruisapp/glue/windows/application.hxx b/src/ruisapp/glue/windows/application.hxx index 8da8a90d..47b7e52d 100644 --- a/src/ruisapp/glue/windows/application.hxx +++ b/src/ruisapp/glue/windows/application.hxx @@ -24,9 +24,17 @@ along with this program. If not, see . #include #include #include +#include #include "../../application.hpp" +#ifdef RUISAPP_RENDER_VULKAN +# include +# include +# include +# include +#endif + #include "display.hxx" #include "window.hxx" @@ -68,6 +76,21 @@ public: } // namespace namespace { +#ifdef RUISAPP_RENDER_VULKAN +// The Vulkan device (instance, physical device, logical device and graphics queue) is shared +// across the render factory and all the windows, the same way it is done by the other +// ruisapp glue implementations that support Vulkan (e.g. Wayland and X11). +const utki::shared_ref make_device() +{ + std::vector instance_extensions = {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME}; + std::vector device_extensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + return utki::make_shared( + instance_extensions, // + device_extensions // + ); +} +#endif + class application_glue : public utki::destructable { const utki::version_duplet gl_version; @@ -75,7 +98,20 @@ class application_glue : public utki::destructable utki::shared_ref display = utki::make_shared(); const utki::shared_ref shared_gl_context_native_window; - const utki::shared_ref render_factory; +#ifdef RUISAPP_RENDER_VULKAN + // The Vulkan device is shared between the factory (resource creation) and the windows (surface creation). + const utki::shared_ref device; +#endif + // concrete factory type, #ifdef by renderer +#ifdef RUISAPP_RENDER_VULKAN + const utki::shared_ref render_factory; +#elif defined(RUISAPP_RENDER_OPENGL) + const utki::shared_ref render_factory; +#elif defined(RUISAPP_RENDER_OPENGLES) + const utki::shared_ref render_factory; +#else +# error "Unknown graphics API" +#endif const utki::shared_ref common_shaders; const utki::shared_ref common_render_objects; const utki::shared_ref ruis_resource_loader; diff --git a/src/ruisapp/glue/windows/glue.cxx b/src/ruisapp/glue/windows/glue.cxx index 16793eff..9cedd602 100644 --- a/src/ruisapp/glue/windows/glue.cxx +++ b/src/ruisapp/glue/windows/glue.cxx @@ -27,7 +27,15 @@ along with this program. If not, see . #include #include -#ifdef RUISAPP_RENDER_OPENGL +#ifdef RUISAPP_RENDER_VULKAN +# include +# include + +# include +# include +# include +# include +#elif defined(RUISAPP_RENDER_OPENGL) # include # include #elif defined(RUISAPP_RENDER_OPENGLES) diff --git a/src/ruisapp/glue/windows/window.cxx b/src/ruisapp/glue/windows/window.cxx index 89f9cb66..3e1e59d5 100644 --- a/src/ruisapp/glue/windows/window.cxx +++ b/src/ruisapp/glue/windows/window.cxx @@ -323,6 +323,26 @@ native_window::opengl_context_wrapper::~opengl_context_wrapper() } #endif +#ifdef RUISAPP_RENDER_VULKAN +native_window::native_window( + utki::shared_ref display, + const ruisapp::window_parameters& window_params, + native_window* shared_gl_context_native_window +) : + display(std::move(display)), + window( + shared_gl_context_native_window ? this->display.get().regular_window_class + : this->display.get().dummy_window_class, // + window_params, + shared_gl_context_native_window != nullptr + ), + device_context(this->window) +{ + // No rendering context is created here: the Vulkan renderer creates a + // VkSurfaceKHR from the window handle (see application.cxx) and presentation + // is handled by the Vulkan render context (vkQueuePresentKHR). +} +#else native_window::native_window( utki::shared_ref display, const utki::version_duplet& gl_version, @@ -337,7 +357,7 @@ native_window::native_window( shared_gl_context_native_window != nullptr ), device_context(this->window), -#ifdef RUISAPP_RENDER_OPENGL +# ifdef RUISAPP_RENDER_OPENGL opengl_context( this->display, this->device_context, // @@ -345,7 +365,7 @@ native_window::native_window( gl_version, shared_gl_context_native_window ? shared_gl_context_native_window->opengl_context.context : NULL ) -#elif defined(RUISAPP_RENDER_OPENGLES) +# elif defined(RUISAPP_RENDER_OPENGLES) egl_config( this->display.get().egl_display, // gl_version, @@ -362,9 +382,9 @@ native_window::native_window( this->egl_config, shared_gl_context_native_window ? shared_gl_context_native_window->egl_context.context : EGL_NO_CONTEXT ) -#endif +# endif { -#ifdef RUISAPP_RENDER_OPENGL +# ifdef RUISAPP_RENDER_OPENGL if (wglGetCurrentContext() == NULL) { auto res = wglMakeCurrent( this->device_context.context, // @@ -379,12 +399,16 @@ native_window::native_window( throw std::runtime_error("GLEW initialization failed"); } } -#endif +# endif } +#endif void native_window::bind_rendering_context() { -#ifdef RUISAPP_RENDER_OPENGL +#ifdef RUISAPP_RENDER_VULKAN + // For Vulkan, there's no concept of binding a rendering context. + // The Vulkan context is thread-safe and doesn't need to be made current. +#elif defined(RUISAPP_RENDER_OPENGL) auto res = wglMakeCurrent( this->device_context.context, // this->opengl_context.context @@ -409,7 +433,10 @@ void native_window::bind_rendering_context() void native_window::swap_frame_buffers() { -#ifdef RUISAPP_RENDER_OPENGL +#ifdef RUISAPP_RENDER_VULKAN + // Not used by the Vulkan renderer: presentation is handled by the Vulkan + // render context itself (vkQueuePresentKHR). +#elif defined(RUISAPP_RENDER_OPENGL) SwapBuffers(this->device_context.context); #elif defined(RUISAPP_RENDER_OPENGLES) this->egl_surface.swap_frame_buffers(); diff --git a/src/ruisapp/glue/windows/window.hxx b/src/ruisapp/glue/windows/window.hxx index 6908b7c0..657c25c8 100644 --- a/src/ruisapp/glue/windows/window.hxx +++ b/src/ruisapp/glue/windows/window.hxx @@ -112,12 +112,31 @@ public: return this->window.handle; } + /** + * @brief The native window handle. + * Used by the Vulkan renderer to create a VK_KHR_win32_surface for presenting frames. + */ + HWND get_hwnd() const noexcept + { + return this->window.handle; + } + +#ifdef RUISAPP_RENDER_VULKAN + // The Vulkan renderer does not create any GL context, so the constructor + // does not take a GL version. + native_window( + utki::shared_ref display, + const ruisapp::window_parameters& window_params, + native_window* shared_gl_context_native_window + ); +#else native_window( utki::shared_ref display, const utki::version_duplet& gl_version, const ruisapp::window_parameters& window_params, native_window* shared_gl_context_native_window ); +#endif void bind_rendering_context() override; From ed5322dc06ac2df29d5a9937a4e678aaa464083c Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Wed, 25 Nov 2026 22:29:08 +0200 Subject: [PATCH 2/3] address review comments - cmake: drop the name variable, use PROJECT_NAME in place - cmake: explicit WIN32 and EMSCRIPTEN branches; FATAL_ERROR on unknown OS - windows: rename make_device() to make_vulkan_device() - windows: explain the 1x1 hidden window in a comment (same as wayland) - makefile: do not build the vulkan variant (the mingw CI has no vulkan headers; the CMake/vcpkg build is the one that provides it) --- build/cmake/CMakeLists.txt | 107 ++++++++++++----------- src/makefile | 3 - src/ruisapp/glue/windows/application.cxx | 4 +- src/ruisapp/glue/windows/application.hxx | 2 +- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index 5335525c..3743a8fa 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.30) -set(name ruisapp) -project(${name}) +project(ruisapp) # !!! find_package must go after project() declaration !!! # Otherwise VCPKG does not set the CMAKE_PREFIX_PATH to find packages. @@ -10,27 +9,27 @@ find_package(myci CONFIG REQUIRED) set(srcs) myci_add_source_files(srcs DIRECTORY - ../../src/${name} + ../../src/${PROJECT_NAME} RECURSIVE ) if(IOS) enable_language(OBJCXX) - list(APPEND srcs ../../src/${name}/glue/ios/glue.mm) + list(APPEND srcs ../../src/${PROJECT_NAME}/glue/ios/glue.mm) set(ruisapp_build_opengl_variant False) set(ruisapp_build_opengles_variant True) set(ruisapp_opengl_install_include_directory) # opengl variant will not be built, no headers to install - set(ruisapp_opengles_install_include_directory ../../src/${name}) + set(ruisapp_opengles_install_include_directory ../../src/${PROJECT_NAME}) elseif(APPLE) enable_language(OBJCXX) - list(APPEND srcs ../../src/${name}/glue/macos/glue.mm) + list(APPEND srcs ../../src/${PROJECT_NAME}/glue/macos/glue.mm) set(ruisapp_build_opengl_variant True) set(ruisapp_build_opengles_variant False) - set(ruisapp_opengl_install_include_directory ../../src/${name}) + set(ruisapp_opengl_install_include_directory ../../src/${PROJECT_NAME}) set(ruisapp_opengles_install_include_directory) # opengles variant will not be built, no headers to install elseif(LINUX) set(ruisapp_build_opengl_variant True) @@ -40,20 +39,22 @@ elseif(LINUX) # the headers are installed by the opengl-xorg variant, see below. set(ruisapp_opengl_install_include_directory) set(ruisapp_opengles_install_include_directory) -else() +elseif(WIN32) set(ruisapp_build_opengl_variant True) set(ruisapp_build_opengles_variant True) + set(ruisapp_build_vulkan_variant True) # VK_KHR_win32_surface - # The Vulkan variant is built on Windows (VK_KHR_win32_surface). - # On other platforms in this branch the platform glue does not support Vulkan yet. - set(ruisapp_build_vulkan_variant False) - if(WIN32) - set(ruisapp_build_vulkan_variant True) - endif() - - set(ruisapp_opengl_install_include_directory ../../src/${name}) + set(ruisapp_opengl_install_include_directory ../../src/${PROJECT_NAME}) set(ruisapp_opengles_install_include_directory) # opengl variant is also built and will install the headers set(ruisapp_vulkan_install_include_directory) # opengl variant is also built and will install the headers +elseif(EMSCRIPTEN) + set(ruisapp_build_opengl_variant True) + set(ruisapp_build_opengles_variant True) + + set(ruisapp_opengl_install_include_directory ../../src/${PROJECT_NAME}) + set(ruisapp_opengles_install_include_directory) # opengl variant is also built and will install the headers +else() + message(FATAL_ERROR "Unknown OS") endif() # ==================== @@ -141,10 +142,10 @@ if(LINUX) set(install_include_directories) if(arg_INSTALL_HEADERS) - set(install_include_directories ../../src/${name}) + set(install_include_directories ../../src/${PROJECT_NAME}) endif() - myci_declare_library(${name}-${renderer}-${backend} + myci_declare_library(${PROJECT_NAME}-${renderer}-${backend} SOURCES ${srcs} PUBLIC_INCLUDE_DIRECTORIES @@ -171,7 +172,7 @@ if(LINUX) if(backend STREQUAL "wayland") # the generated xdg-shell client protocol source is added after the library # declaration, so that it is not picked up by the format targets - target_sources(${name}-${renderer}-${backend} + target_sources(${PROJECT_NAME}-${renderer}-${backend} PRIVATE ${wayland_xdg_shell_protocol_source} ) @@ -190,14 +191,14 @@ if(LINUX) # Compatibility aliases: for now ruisapp-opengl / ruisapp-opengles refer to the xorg variants. # Note: the namespaced alias refers to the plain (non-namespaced) target, the same # convention that myci_declare_library() uses for the ${PROJECT_NAME}:: alias. - add_library(${name}-opengl ALIAS ${name}-opengl-xorg) - add_library(${PROJECT_NAME}::${name}-opengl ALIAS ${name}-opengl-xorg) - add_library(${name}-opengles ALIAS ${name}-opengles-xorg) - add_library(${PROJECT_NAME}::${name}-opengles ALIAS ${name}-opengles-xorg) + add_library(${PROJECT_NAME}-opengl ALIAS ${PROJECT_NAME}-opengl-xorg) + add_library(${PROJECT_NAME}::${PROJECT_NAME}-opengl ALIAS ${PROJECT_NAME}-opengl-xorg) + add_library(${PROJECT_NAME}-opengles ALIAS ${PROJECT_NAME}-opengles-xorg) + add_library(${PROJECT_NAME}::${PROJECT_NAME}-opengles ALIAS ${PROJECT_NAME}-opengles-xorg) else() if(ruisapp_build_opengl_variant) - myci_declare_library(${name}-opengl + myci_declare_library(${PROJECT_NAME}-opengl SOURCES ${srcs} PUBLIC_INCLUDE_DIRECTORIES @@ -221,7 +222,7 @@ else() if(APPLE) # link to Cocoa framework - target_link_libraries(${name}-opengl + target_link_libraries(${PROJECT_NAME}-opengl PRIVATE # Link the Cocoa framework directly using the -framework flag string. # The quotes are important so CMake passes it as a single linker argument. @@ -229,15 +230,15 @@ else() ) # TODO: Define the GL_SILENCE_DEPRECATION macro to silence OpenGL deprecation warnings on Apple platforms. Need to move to Metal eventually. - target_compile_definitions(${name}-opengl PRIVATE GL_SILENCE_DEPRECATION) + target_compile_definitions(${PROJECT_NAME}-opengl PRIVATE GL_SILENCE_DEPRECATION) # TODO: some stuff (e.g. NSOpenGLContext) is deprecated on MacOS, so suppress the warnings for now. Need to use new APIs eventually. - target_compile_options(${name}-opengl PRIVATE -Wno-deprecated-declarations) + target_compile_options(${PROJECT_NAME}-opengl PRIVATE -Wno-deprecated-declarations) endif() endif() if(ruisapp_build_opengles_variant) - myci_declare_library(${name}-opengles + myci_declare_library(${PROJECT_NAME}-opengles SOURCES ${srcs} PUBLIC_INCLUDE_DIRECTORIES @@ -263,7 +264,7 @@ else() ) if(IOS) - target_link_libraries(${name}-opengles + target_link_libraries(${PROJECT_NAME}-opengles PRIVATE # Link the iOS frameworks directly using the -framework flag string. # The quotes are important so CMake passes it as a single linker argument. @@ -273,15 +274,15 @@ else() ) # TODO: Define the GLES_SILENCE_DEPRECATION macro to silence OpenGL ES deprecation warnings on Apple platforms. Need to move to Metal eventually. - target_compile_definitions(${name}-opengles PRIVATE GLES_SILENCE_DEPRECATION) + target_compile_definitions(${PROJECT_NAME}-opengles PRIVATE GLES_SILENCE_DEPRECATION) # TODO: some stuff (e.g. UI_USER_INTERFACE_IDIOM) is deprecated on iOS, so suppress the warnings for now. Need to use new APIs eventually. - target_compile_options(${name}-opengles PRIVATE -Wno-deprecated-declarations) + target_compile_options(${PROJECT_NAME}-opengles PRIVATE -Wno-deprecated-declarations) endif() endif() if(ruisapp_build_vulkan_variant) - myci_declare_library(${name}-vulkan + myci_declare_library(${PROJECT_NAME}-vulkan SOURCES ${srcs} PUBLIC_INCLUDE_DIRECTORIES @@ -308,25 +309,25 @@ endif() if(LINUX) myci_export( TARGETS - ${name}-opengl-xorg - ${name}-opengles-xorg - ${name}-opengl-wayland - ${name}-opengles-wayland - ${name}-opengl-sdl - ${name}-opengles-sdl - ${name}-vulkan-xorg - ${name}-vulkan-wayland + ${PROJECT_NAME}-opengl-xorg + ${PROJECT_NAME}-opengles-xorg + ${PROJECT_NAME}-opengl-wayland + ${PROJECT_NAME}-opengles-wayland + ${PROJECT_NAME}-opengl-sdl + ${PROJECT_NAME}-opengles-sdl + ${PROJECT_NAME}-vulkan-xorg + ${PROJECT_NAME}-vulkan-wayland ) else() set(ruisapp_export_targets) if(ruisapp_build_opengl_variant) - list(APPEND ruisapp_export_targets ${name}-opengl) + list(APPEND ruisapp_export_targets ${PROJECT_NAME}-opengl) endif() if(ruisapp_build_opengles_variant) - list(APPEND ruisapp_export_targets ${name}-opengles) + list(APPEND ruisapp_export_targets ${PROJECT_NAME}-opengles) endif() if(ruisapp_build_vulkan_variant) - list(APPEND ruisapp_export_targets ${name}-vulkan) + list(APPEND ruisapp_export_targets ${PROJECT_NAME}-vulkan) endif() myci_export( TARGETS @@ -345,7 +346,7 @@ myci_add_source_files(app_srcs ) # Declare a GUI test app for the given ruisapp-- library variant. function(ruisapp_declare_test_app renderer backend) - set(test_app_name "${name}-${renderer}-${backend}-test") + set(test_app_name "${PROJECT_NAME}-${renderer}-${backend}-test") myci_declare_application(${test_app_name} GUI SOURCES @@ -353,7 +354,7 @@ function(ruisapp_declare_test_app renderer backend) RESOURCE_DIRECTORY ../../tests/app/res DEPENDENCIES - ${PROJECT_NAME}::${name}-${renderer}-${backend} + ${PROJECT_NAME}::${PROJECT_NAME}-${renderer}-${backend} ) endfunction() @@ -369,7 +370,7 @@ if(LINUX) ruisapp_declare_test_app(vulkan wayland) else() if(ruisapp_build_opengl_variant) - myci_declare_application(${name}-opengl-test + myci_declare_application(${PROJECT_NAME}-opengl-test GUI SOURCES ${app_srcs} @@ -380,14 +381,14 @@ else() ) if(APPLE) - set_target_properties(${name}-opengl-test PROPERTIES + set_target_properties(${PROJECT_NAME}-opengl-test PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "io.github.cppfw.ruisapp-opengl-test" ) endif() endif() if(ruisapp_build_opengles_variant) - myci_declare_application(${name}-opengles-test + myci_declare_application(${PROJECT_NAME}-opengles-test GUI SOURCES ${app_srcs} @@ -398,9 +399,9 @@ else() ) if(APPLE) - set_target_properties(${name}-opengles-test PROPERTIES - MACOSX_BUNDLE_GUI_IDENTIFIER "io.github.cppfw.${name}-opengles-test" - XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "io.github.cppfw.${name}-opengles-test" + set_target_properties(${PROJECT_NAME}-opengles-test PROPERTIES + MACOSX_BUNDLE_GUI_IDENTIFIER "io.github.cppfw.${PROJECT_NAME}-opengles-test" + XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "io.github.cppfw.${PROJECT_NAME}-opengles-test" XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "948FQ58W9M" XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Automatic" ) @@ -408,14 +409,14 @@ else() endif() if(ruisapp_build_vulkan_variant) - myci_declare_application(${name}-vulkan-test + myci_declare_application(${PROJECT_NAME}-vulkan-test GUI SOURCES ${app_srcs} RESOURCE_DIRECTORY ../../tests/app/res DEPENDENCIES - ruisapp::${name}-vulkan + ruisapp::${PROJECT_NAME}-vulkan ) endif() endif() diff --git a/src/makefile b/src/makefile index 65eedd7f..5b385302 100644 --- a/src/makefile +++ b/src/makefile @@ -151,9 +151,6 @@ ifeq ($(os), linux) $(eval $(call ruisapp_rules,opengles,sdl)) -else ifeq ($(os), windows) - $(eval $(call ruisapp_rules,opengl,)) - $(eval $(call ruisapp_rules,vulkan,)) else $(eval $(call ruisapp_rules,opengl,)) endif diff --git a/src/ruisapp/glue/windows/application.cxx b/src/ruisapp/glue/windows/application.cxx index a62101c2..b6733a73 100644 --- a/src/ruisapp/glue/windows/application.cxx +++ b/src/ruisapp/glue/windows/application.cxx @@ -104,6 +104,8 @@ application_glue::application_glue(const utki::version_duplet& gl_version) : shared_gl_context_native_window(utki::make_shared( this->display, #ifdef RUISAPP_RENDER_VULKAN + // Create a 1x1 hidden window; for Vulkan it is not used by the factory, + // but the member is a shared_ref which cannot be null (same as the wayland glue). ruisapp::window_parameters{ .dims = {1, 1}, .fullscreen = false @@ -119,7 +121,7 @@ application_glue::application_glue(const utki::version_duplet& gl_version) : #endif )), #ifdef RUISAPP_RENDER_VULKAN - device(make_device()), + device(make_vulkan_device()), #endif render_factory([&]() { #ifdef RUISAPP_RENDER_VULKAN diff --git a/src/ruisapp/glue/windows/application.hxx b/src/ruisapp/glue/windows/application.hxx index 47b7e52d..9a049c35 100644 --- a/src/ruisapp/glue/windows/application.hxx +++ b/src/ruisapp/glue/windows/application.hxx @@ -80,7 +80,7 @@ namespace { // The Vulkan device (instance, physical device, logical device and graphics queue) is shared // across the render factory and all the windows, the same way it is done by the other // ruisapp glue implementations that support Vulkan (e.g. Wayland and X11). -const utki::shared_ref make_device() +const utki::shared_ref make_vulkan_device() { std::vector instance_extensions = {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME}; std::vector device_extensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; From 1b8f4ed8d371fe9b39093040c0bb0ddc134de60b Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Wed, 25 Nov 2026 23:36:23 +0200 Subject: [PATCH 3/3] windows: remove the shared gl context window in the Vulkan variant The Vulkan renderer does not use a shared GL context, so the shared_gl_context_native_window member and the 1x1 dummy window it required are dropped from the Vulkan build. The native_window constructor no longer takes the shared context pointer. --- src/ruisapp/glue/windows/application.cxx | 15 +++------------ src/ruisapp/glue/windows/application.hxx | 2 ++ src/ruisapp/glue/windows/window.cxx | 8 +++----- src/ruisapp/glue/windows/window.hxx | 8 ++------ 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/ruisapp/glue/windows/application.cxx b/src/ruisapp/glue/windows/application.cxx index b6733a73..4d7f3720 100644 --- a/src/ruisapp/glue/windows/application.cxx +++ b/src/ruisapp/glue/windows/application.cxx @@ -101,25 +101,17 @@ ruisapp::application::directories get_application_directories(std::string_view a application_glue::application_glue(const utki::version_duplet& gl_version) : gl_version(gl_version), +#ifndef RUISAPP_RENDER_VULKAN shared_gl_context_native_window(utki::make_shared( this->display, -#ifdef RUISAPP_RENDER_VULKAN - // Create a 1x1 hidden window; for Vulkan it is not used by the factory, - // but the member is a shared_ref which cannot be null (same as the wayland glue). - ruisapp::window_parameters{ - .dims = {1, 1}, - .fullscreen = false -}, - nullptr // no shared gl context -#else this->gl_version, ruisapp::window_parameters{ .dims = {1, 1}, .fullscreen = false }, nullptr // no shared gl context -#endif )), +#endif #ifdef RUISAPP_RENDER_VULKAN device(make_vulkan_device()), #endif @@ -201,8 +193,7 @@ app_window* application_glue::get_window(native_window::window_id_type id) ruisapp::window& application_glue::make_window(ruisapp::window_parameters window_params) { #ifdef RUISAPP_RENDER_VULKAN - auto ruis_native_window = - utki::make_shared(this->display, window_params, &this->shared_gl_context_native_window.get()); + auto ruis_native_window = utki::make_shared(this->display, window_params); #else auto ruis_native_window = utki::make_shared( this->display, diff --git a/src/ruisapp/glue/windows/application.hxx b/src/ruisapp/glue/windows/application.hxx index 9a049c35..9f55ca18 100644 --- a/src/ruisapp/glue/windows/application.hxx +++ b/src/ruisapp/glue/windows/application.hxx @@ -97,7 +97,9 @@ class application_glue : public utki::destructable utki::shared_ref display = utki::make_shared(); +#ifndef RUISAPP_RENDER_VULKAN const utki::shared_ref shared_gl_context_native_window; +#endif #ifdef RUISAPP_RENDER_VULKAN // The Vulkan device is shared between the factory (resource creation) and the windows (surface creation). const utki::shared_ref device; diff --git a/src/ruisapp/glue/windows/window.cxx b/src/ruisapp/glue/windows/window.cxx index 3e1e59d5..5f52e9a7 100644 --- a/src/ruisapp/glue/windows/window.cxx +++ b/src/ruisapp/glue/windows/window.cxx @@ -326,15 +326,13 @@ native_window::opengl_context_wrapper::~opengl_context_wrapper() #ifdef RUISAPP_RENDER_VULKAN native_window::native_window( utki::shared_ref display, - const ruisapp::window_parameters& window_params, - native_window* shared_gl_context_native_window + const ruisapp::window_parameters& window_params ) : display(std::move(display)), window( - shared_gl_context_native_window ? this->display.get().regular_window_class - : this->display.get().dummy_window_class, // + this->display.get().regular_window_class, // window_params, - shared_gl_context_native_window != nullptr + true // visible ), device_context(this->window) { diff --git a/src/ruisapp/glue/windows/window.hxx b/src/ruisapp/glue/windows/window.hxx index 657c25c8..e49f7d4c 100644 --- a/src/ruisapp/glue/windows/window.hxx +++ b/src/ruisapp/glue/windows/window.hxx @@ -123,12 +123,8 @@ public: #ifdef RUISAPP_RENDER_VULKAN // The Vulkan renderer does not create any GL context, so the constructor - // does not take a GL version. - native_window( - utki::shared_ref display, - const ruisapp::window_parameters& window_params, - native_window* shared_gl_context_native_window - ); + // does not take a GL version or a shared GL context window. + native_window(utki::shared_ref display, const ruisapp::window_parameters& window_params); #else native_window( utki::shared_ref display,