Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
611f403
glue: create one shared render factory per application
igagis Nov 19, 2026
2d95c18
test app: use context.factory() accessor instead of the removed facto…
igagis Nov 19, 2026
622b89a
test app: use context.fac() accessor (renamed from factory())
igagis Nov 19, 2026
594877b
format
igagis Nov 19, 2026
ad91cc9
Integrate the Vulkan renderer (#28)
igagis Nov 20, 2026
5ef0218
Refactor Xorg window hierarchy and fix Wayland EGL surface bind
igagis Nov 20, 2026
98de76e
Address PR review comments
igagis Nov 20, 2026
213d2a0
Address follow-up PR review comments
igagis Nov 20, 2026
4b09764
Update for surface_provider rename and vulkan_device public ctor
igagis Nov 20, 2026
7b975a0
Update for vulkan_device to device rename
igagis Nov 20, 2026
fd11282
Replace VU_CHECK macro with check_vk_result direct call
igagis Nov 20, 2026
3022707
Split opengl_window.hxx into separate OpenGL and GLES files; refactor…
igagis Nov 20, 2026
2c2fa80
Address review comments: rename native_window classes, use context* i…
igagis Nov 21, 2026
236d0f2
Remove addressed review comment
igagis Nov 21, 2026
4a4d169
Fix Vulkan Wayland crash: create dummy native_window for shared_gl_co…
igagis Nov 21, 2026
4704fa3
Address review: create vulkan::context before ruis::context, no stati…
igagis Nov 21, 2026
c1ab784
Address remaining review comments
igagis Nov 21, 2026
902915d
Remove remaining review comments, use #elif defined + #error for unkn…
igagis Nov 21, 2026
eab0cda
Use ctx() shorthand, std::move for shared_ref args
igagis Nov 21, 2026
13e03b4
Use context::swap_frame_buffers(), remove owner_context from Vulkan w…
igagis Nov 21, 2026
34a0a48
Point to Vulkan pick_present_mode() for vsync handling
igagis Nov 21, 2026
35eefda
Improve vsync comment in vulkan_window.hxx
igagis Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ if(LINUX)
ruisapp_declare_variant(opengles wayland)
ruisapp_declare_variant(opengl sdl)
ruisapp_declare_variant(opengles sdl)
ruisapp_declare_variant(vulkan xorg)
ruisapp_declare_variant(vulkan wayland)

# 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
Expand Down Expand Up @@ -283,6 +285,8 @@ if(LINUX)
${name}-opengles-wayland
${name}-opengl-sdl
${name}-opengles-sdl
${name}-vulkan-xorg
${name}-vulkan-wayland
)
elseif(ruisapp_build_opengl_variant AND ruisapp_build_opengles_variant)
myci_export(
Expand Down Expand Up @@ -333,6 +337,8 @@ if(LINUX)
ruisapp_declare_test_app(${renderer} ${backend})
endforeach()
endforeach()
ruisapp_declare_test_app(vulkan xorg)
ruisapp_declare_test_app(vulkan wayland)
else()
if(ruisapp_build_opengl_variant)
myci_declare_application(${name}-opengl-test
Expand Down
6 changes: 3 additions & 3 deletions src/ruisapp/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ ruisapp::window& application::make_window(window_parameters window_params)
// By choice, the VSYNC is enabled by default.
// This call will synchornize the is_vsync_enabled_v field of the native window
// with the actual VSYNC state of the newly created window.
win.gui.context.get().ren().ctx().set_vsync_enabled(true);
win.gui.ctx().ren().ctx().set_vsync_enabled(true);

if (!this->get_shared_style_provider()) {
// The platform does not support shared style_provider.

// The platform should support only one window which has just been created.
utki::assert(this->get_windows().size() == size_t(1));

auto& sp = win.gui.context.get().style();
auto& sp = win.gui.ctx().style();

if (this->mount_ruis_res_pack) {
// The platform doesn't have shared style provider, so we need to
Expand All @@ -165,7 +165,7 @@ const std::shared_ptr<ruis::style_provider>& application::get_default_style_prov

auto windows = this->get_windows();
if (!windows.empty()) {
return windows.front().get().gui.context.get().style_provider.to_shared_ptr();
return windows.front().get().gui.ctx().style_provider.to_shared_ptr();
}

// return nullptr because shared style provider is nullptr
Expand Down
10 changes: 6 additions & 4 deletions src/ruisapp/glue/android/application.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "application.hxx"

#include <ruis/render/opengles/context.hpp>
#include <ruis/render/opengles/factory.hpp>
#include <ruis/widget/widget.hpp>
#include <utki/views.hpp>

Expand Down Expand Up @@ -107,13 +108,14 @@ app_window& application_glue::make_window(ruisapp::window_parameters window_para
// status bar and the navigation bar.
ruis_native_window.get().set_fullscreen(fullscreen);

auto rendering_context = utki::make_shared<ruis::render::opengles::context>(ruis_native_window);
auto rendering_factory = utki::make_shared<ruis::render::opengles::factory>(ruis_native_window);
auto rendering_context = utki::make_shared<ruis::render::opengles::context>(ruis_native_window, rendering_factory);

auto common_render_objects = utki::make_shared<ruis::render::renderer::objects>(rendering_context);
auto common_shaders = rendering_context.get().make_shaders();
auto common_render_objects = utki::make_shared<ruis::render::renderer::objects>(rendering_factory.get());
auto common_shaders = rendering_factory.get().make_shaders();

auto ruis_resource_loader = utki::make_shared<ruis::resource_loader>(
rendering_context, //
rendering_factory, //
common_render_objects
);

Expand Down
9 changes: 5 additions & 4 deletions src/ruisapp/glue/ios/application.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ app_window& application_glue::make_window(ruisapp::window_parameters window_para
std::move(window_params)
);

auto rendering_context = utki::make_shared<ruis::render::opengles::context>(ruis_native_window);
auto rendering_factory = utki::make_shared<ruis::render::opengles::factory>(ruis_native_window);
auto rendering_context = utki::make_shared<ruis::render::opengles::context>(ruis_native_window, rendering_factory);

auto common_render_objects = utki::make_shared<ruis::render::renderer::objects>(rendering_context);
auto common_shaders = rendering_context.get().make_shaders();
auto common_render_objects = utki::make_shared<ruis::render::renderer::objects>(rendering_factory.get());
auto common_shaders = rendering_factory.get().make_shaders();

auto ruis_resource_loader = utki::make_shared<ruis::resource_loader>(
rendering_context, //
rendering_factory, //
common_render_objects
);

Expand Down
1 change: 1 addition & 0 deletions src/ruisapp/glue/ios/glue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdexcept>

#include <ruis/render/opengles/context.hpp>
#include <ruis/render/opengles/factory.hpp>

// include implementations
#include "application.cxx"
Expand Down
55 changes: 47 additions & 8 deletions src/ruisapp/glue/linux/wayland/application.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#elif defined(RUISAPP_RENDER_OPENGLES)
# include <ruis/render/opengles/context.hpp>

#elif defined(RUISAPP_RENDER_VULKAN)
# include <ruis/render/vulkan/context.hpp>
#else
# error "Unknown graphics API"
#endif
Expand Down Expand Up @@ -200,12 +202,49 @@ ruisapp::window& application_glue::make_window(ruisapp::window_parameters window
{
utki::logcat_debug("application_glue::make_window(): enter", '\n');

auto ruis_native_window = utki::make_shared<native_window>(
#ifdef RUISAPP_RENDER_VULKAN
auto ruis_native_window = utki::make_shared<native_window_type>(
this->display, //
window_params
);
#else
auto ruis_native_window = utki::make_shared<native_window_type>(
this->display, //
this->gl_version,
window_params,
&this->shared_gl_context_native_window.get()
);
#endif

// create the render context before the ruis::context so we can save a pointer
// to it without a static_cast later (needed for Vulkan swap_frame_buffers)
#ifdef RUISAPP_RENDER_VULKAN
auto render_context = [this](auto&& win_ref) -> utki::shared_ref<ruis::render::vulkan::context> {
auto wl_surf = win_ref.get().get_wl_surface();
auto wl_disp = win_ref.get().get_wl_display();
auto& vdev = this->device.get();
VkWaylandSurfaceCreateInfoKHR sci{};
sci.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
sci.display = wl_disp;
sci.surface = wl_surf;
VkSurfaceKHR vk_surf = VK_NULL_HANDLE;
vkCreateWaylandSurfaceKHR(vdev.get_instance(), &sci, nullptr, &vk_surf);
auto sp = utki::make_shared<const ruis::render::vulkan::surface>(vdev, vk_surf);
return utki::make_shared<ruis::render::vulkan::context>(win_ref, sp, this->render_factory);
}(ruis_native_window);
#elif defined(RUISAPP_RENDER_OPENGL)
auto render_context = utki::make_shared<ruis::render::opengl::context>(
ruis_native_window, //
this->render_factory
);
#elif defined(RUISAPP_RENDER_OPENGLES)
auto render_context = utki::make_shared<ruis::render::opengles::context>(
ruis_native_window, //
this->render_factory
);
#else
# error "Unknown graphics API"
#endif

auto ruis_context = utki::make_shared<ruis::context>(ruis::context::parameters{
.post_to_ui_thread_function =
Expand All @@ -214,13 +253,7 @@ ruisapp::window& application_glue::make_window(ruisapp::window_parameters window
},
.updater = this->updater,
.renderer = utki::make_shared<ruis::render::renderer>(
#ifdef RUISAPP_RENDER_OPENGL
utki::make_shared<ruis::render::opengl::context>(ruis_native_window),
#elif defined(RUISAPP_RENDER_OPENGLES)
utki::make_shared<ruis::render::opengles::context>(ruis_native_window),
#else
# error "Unknown graphics API"
#endif
std::move(render_context),
this->common_shaders,
this->common_render_objects
),
Expand Down Expand Up @@ -263,6 +296,7 @@ ruisapp::window& application_glue::make_window(ruisapp::window_parameters window

auto& ret_win = res.first->second.get();

#if defined(RUISAPP_RENDER_OPENGL) || defined(RUISAPP_RENDER_OPENGLES)
// EGL surface for the window is not created yet at this point.
// In Wayland the EGL surface is created asynchronously.
// Some further calls (e.g. set_vsync_enabled()) rely on the EGL surface to be created,
Expand All @@ -278,6 +312,11 @@ ruisapp::window& application_glue::make_window(ruisapp::window_parameters window
}

utki::assert(ret_win.ruis_native_window.get().is_egl_surface_created(), SL);
#elif defined(RUISAPP_RENDER_VULKAN)
// A roundtrip ensures the compositor has processed the toplevel and the
// surface is mapped, so the Vulkan surface created from it is valid.
wl_display_roundtrip(this->display.get().wayland_display.display);
#endif

return ret_win;
}
Expand Down
100 changes: 78 additions & 22 deletions src/ruisapp/glue/linux/wayland/application.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../../../window.hpp"
#include "../../unix_common.hxx"

#include "window.hxx"
#ifdef RUISAPP_RENDER_VULKAN
# include "vulkan_window.hxx"
using native_window_type = vulkan_native_window;
#else
# include "opengles_window.hxx"
using native_window_type = opengles_native_window;
#endif

namespace {
class app_window : public ruisapp::window
Expand All @@ -44,11 +50,11 @@ public:
bool activated = false;
} actual_state;

utki::shared_ref<native_window> ruis_native_window;
utki::shared_ref<native_window_type> ruis_native_window;

app_window(
utki::shared_ref<ruis::context> ruis_context, //
utki::shared_ref<native_window> ruis_native_window
utki::shared_ref<native_window_type> ruis_native_window
) :
ruisapp::window(std::move(ruis_context)),
ruis_native_window(std::move(ruis_native_window))
Expand Down Expand Up @@ -100,6 +106,21 @@ private:
} // namespace

namespace {
#ifdef RUISAPP_RENDER_VULKAN
const utki::shared_ref<ruis::render::vulkan::device> make_device()
{
std::vector<std::string> instance_extensions = {
VK_KHR_SURFACE_EXTENSION_NAME,
VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
};
std::vector<std::string> device_extensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
return utki::make_shared<ruis::render::vulkan::device>(
instance_extensions, //
device_extensions //
);
}
#endif

class application_glue : public utki::destructable
{
public:
Expand All @@ -126,16 +147,28 @@ public:
const utki::version_duplet gl_version;

// TODO: make windowless shared egl context
const utki::shared_ref<native_window> shared_gl_context_native_window;
const utki::shared_ref<ruis::render::context> resource_loader_ruis_rendering_context;
const utki::shared_ref<const ruis::render::context::shaders> common_shaders;
const utki::shared_ref<native_window_type> shared_gl_context_native_window;
#ifdef RUISAPP_RENDER_VULKAN
// The Vulkan device is shared between the factory (resource creation) and the windows (surface creation).
// Surface extensions are needed for creating Vulkan surfaces (one per window) for presenting frames.
const utki::shared_ref<ruis::render::vulkan::device> device;
#endif
// concrete factory type, #ifdef by renderer
#ifdef RUISAPP_RENDER_VULKAN
const utki::shared_ref<const ruis::render::vulkan::factory> render_factory;
#elif defined(RUISAPP_RENDER_OPENGL)
const utki::shared_ref<const ruis::render::opengl::factory> render_factory;
#elif defined(RUISAPP_RENDER_OPENGLES)
const utki::shared_ref<const ruis::render::opengles::factory> render_factory;
#endif
const utki::shared_ref<const ruis::render::factory::shaders> common_shaders;
const utki::shared_ref<const ruis::render::renderer::objects> common_render_objects;
const utki::shared_ref<ruis::resource_loader> ruis_resource_loader;
const utki::shared_ref<ruis::style_provider> ruis_style_provider;

private:
std::map<
native_window::window_id_type, //
native_window_type::window_id_type, //
utki::shared_ref<app_window> //
>
windows;
Expand All @@ -148,47 +181,70 @@ public:
return this->windows;
}

native_window::window_id_type get_shared_gl_context_window_id() const noexcept
native_window_type::window_id_type get_shared_gl_context_window_id() const noexcept
{
return this->shared_gl_context_native_window.get().get_id();
}

application_glue(const utki::version_duplet& gl_version) :
waitable(this->display.get().wayland_display),
gl_version(gl_version),
shared_gl_context_native_window( //
utki::make_shared<native_window>(
shared_gl_context_native_window(
// 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
#ifdef RUISAPP_RENDER_VULKAN
utki::make_shared<native_window_type>(
this->display, //
ruisapp::window_parameters{
.dims = {1, 1},
.title = {},
.fullscreen = false,
.taskbar = false
}
)
#else
utki::make_shared<native_window_type>(
this->display, //
this->gl_version,
ruisapp::window_parameters{
.dims = {1, 1},
.title = {},
.fullscreen = false
},
nullptr // no shared gl context
.fullscreen = false,
.taskbar = false
},
nullptr
)
#endif
),
resource_loader_ruis_rendering_context(
#ifdef RUISAPP_RENDER_OPENGL
utki::make_shared<ruis::render::opengl::context>(this->shared_gl_context_native_window)
#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)
utki::make_shared<ruis::render::vulkan::factory>(
utki::make_shared<ruis::render::vulkan::surface>(this->device.get(), VK_NULL_HANDLE)
)
#elif defined(RUISAPP_RENDER_OPENGL)
utki::make_shared<ruis::render::opengl::factory>(this->shared_gl_context_native_window)
#elif defined(RUISAPP_RENDER_OPENGLES)
utki::make_shared<ruis::render::opengles::context>(this->shared_gl_context_native_window)
utki::make_shared<ruis::render::opengles::factory>(this->shared_gl_context_native_window)
#else
# error "Unknown graphics API"
#endif
),
common_shaders( //
[&]() {
utki::assert(this->resource_loader_ruis_rendering_context.to_shared_ptr(), SL);
return this->resource_loader_ruis_rendering_context.get().make_shaders();
utki::assert(this->render_factory.to_shared_ptr(), SL);
return this->render_factory.get().make_shaders();
}()
),
common_render_objects( //
utki::make_shared<ruis::render::renderer::objects>(this->resource_loader_ruis_rendering_context)
utki::make_shared<ruis::render::renderer::objects>(this->render_factory.get())
),
ruis_resource_loader( //
utki::make_shared<ruis::resource_loader>(
this->resource_loader_ruis_rendering_context, //
this->render_factory, //
this->common_render_objects
)
),
Expand All @@ -200,7 +256,7 @@ public:
ruisapp::window& make_window(ruisapp::window_parameters window_params);
void destroy_window(app_window& w);

app_window* get_window(native_window::window_id_type id)
app_window* get_window(native_window_type::window_id_type id)
{
auto i = this->windows.find(id);
if (i == this->windows.end()) {
Expand Down
Loading
Loading