Repository navigation
Add Metal variant (macOS + iOS) - #47
igagis-bot wants to merge 11 commits into
Conversation
Add a Metal variant of the ruisapp glue layer for macOS and iOS: - macOS: MetalView/CAMetalLayer-based window, Cocoa glue, key-code mapping - iOS: UIKit/CAMetalLayer-based window - CMake: build the Metal variant library (with the corresponding glue sources) for the current platform, plus the ruisapp-metal-test application. Depends on ruis with the native_window::get_native_metal_layer() method and on ruis-render-metal (Metal renderer).
Replace the native_window::get_native_metal_layer() virtual with the surface approach (mirroring the Vulkan renderer): the glue creates a ruis::render::metal::surface holding the window's CAMetalLayer and the shared device, and passes it to the Metal context, which keeps it alive for its own lifetime.
The surface now holds a shared_ref to the window (ruis-render-metal PR #3), so the glue passes its window reference to the surface constructor.
The context now takes the CAMetalLayer by reference, so the glue passes it directly instead of creating a surface provider.
The content view is layer-backed, so AppKit keeps the CAMetalLayer's geometry in sync with the view's bounds. resize() set layer.frame to a screen-coordinate rect, which fought that sync and mispositioned the rendered content (it appeared shifted up by the title-bar height, easing into place at launch). Let AppKit own the layer geometry; only set contentsScale, which AppKit does not derive for the drawable.
|
why separate glue and application created for metal, is it too different from opengl one? can't it be done using #ifdef interlieved in same glue and application? |
|
The split is per-variant because each variant owns a different rendering surface, which is inherent to the backend:
The The So: yes, it can be done with Let me know which direction you'd like and I'll do it. |
|
make two window implementations opengl_window and metal_window, everything else merge into same files |
… separate
Per review feedback, instead of a fully separate glue tree for the metal
variant, the shared glue files (application, glue, cocoa) are now a single
copy that selects the rendering backend via #ifdef RUISAPP_RENDER_METAL.
Only the window implementations are kept as separate per-backend files:
opengl_window.{hxx,cxx} - the opengl / opengles window (and its GL context
wrapper on macos)
metal_window.{hxx,cxx} - the metal window (owns the CAMetalLayer)
This removes the duplicated application/glue/cocoa/key_code code that
differed between the two backends by only a handful of lines.
macos:
- macos/window.{hxx,cxx} -> macos/opengl_window.{hxx,cxx}
- macos/metal/window.{hxx,cxx} -> macos/metal_window.{hxx,cxx}
- macos/metal/{application,glue,cocoa,key_code.map}.* removed (merged)
ios:
- ios/window.{hxx,cxx} -> ios/opengl_window.{hxx,cxx}
- ios/metal/window.{hxx,cxx} -> ios/metal_window.{hxx,cxx}
- ios/metal/{application,glue}.* removed (merged)
build/cmake: the metal variant now reuses the shared glue directory instead
of a per-variant /metal subdirectory.
|
Done — pushed as There are now two window implementations (
The redundant per-variant |
LICENSE file and all other sources (the license check compares each file's header against the LICENSE file).
|
Note on CI: the The other failures (lint, msys2, sanitizer, macosx) were a license-header year mismatch in the renamed |
…w obj-c code to satisfy the lint job.
metal_window.cxx) to satisfy the lint job.
| #ifdef RUISAPP_RENDER_METAL | ||
| # include <ruis/render/metal/context.hpp> | ||
| # include <ruis/render/metal/factory.hpp> | ||
| #else |
There was a problem hiding this comment.
should be elif OPENGL
else
error unknown rendering api
| utki::logcat_debug("application_glue::application_glue(): metal render factory created", '\n'); | ||
| return c; | ||
| }()), | ||
| #else |
There was a problem hiding this comment.
should be elif defined OPENGL else error unsknown rendering api
| #ifdef RUISAPP_RENDER_METAL | ||
| #include <ruis/render/metal/context.hpp> | ||
| #include <ruis/render/metal/factory.hpp> | ||
| #else |
There was a problem hiding this comment.
should be elif defined OPENGLES else error unknown rendering api
| #include "window.cxx" | ||
| #ifdef RUISAPP_RENDER_METAL | ||
| #include "metal_window.cxx" | ||
| #else |
| #include "window.hxx" | ||
| #ifdef RUISAPP_RENDER_METAL | ||
| # include "metal_window.hxx" | ||
| #else |
| { | ||
| const utki::version_duplet gl_version; | ||
|
|
||
| #ifndef RUISAPP_RENDER_METAL |
There was a problem hiding this comment.
convert to positive condition, ifdef OPENGL
|
|
||
| #ifdef RUISAPP_RENDER_METAL | ||
| #include <ruis/render/metal/context.hpp> | ||
| #else |
| #include "window.cxx" | ||
| #ifdef RUISAPP_RENDER_METAL | ||
| #include "metal_window.cxx" | ||
| #else |
| @end | ||
|
|
||
| namespace { | ||
| class native_window : public ruis::render::native_window |
There was a problem hiding this comment.
don't opengl_window and metal_window share something? would it make sense to make base cocoa_window : public ruis::native_window and derive metal and opengl windows from the cocoa window?
iOS touch coordinate offset:
- Convert touch locations (view coords, points) to GUI coordinates by
scaling to pixels and subtracting the viewport origin (content_rect.p).
Previously the status-bar height was not subtracted, so taps landed
below the actual touch position; most noticeable with Metal, whose
viewport is offset by the status-bar height (the GLES viewport starts
at the top of the screen).
iOS fullscreen:
- Add a custom Info.plist template (ios_info.plist.in) declaring an empty
UILaunchScreen dict. Without a launch screen iOS runs the app in a
scaled compatibility mode (320x480pt) instead of natively filling the
whole screen, like the Android backend does.
- The template uses Xcode build-setting vars ($(EXECUTABLE_NAME),
$(PRODUCT_BUNDLE_IDENTIFIER), $(PRODUCT_NAME)) because custom
MACOSX_BUNDLE_INFO_PLIST templates do not get ${APPLE_GUI_*} subst.
iOS deprecations / Metal layer:
- Replace deprecated UI_USER_INTERFACE_IDIOM() with
[[UIDevice currentDevice] userInterfaceIdiom]; silence statusBarFrame
and mainScreen deprecations with pragmas.
- Use the CAMetalLayer created via the +layerClass override instead of
assigning a new layer to the readonly UIView.layer.
Review feedback - rendering API conditionals:
- Restructure "#ifdef RUISAPP_RENDER_METAL / #else" into
"#ifdef METAL / #elif defined(OPENGL|OPENGLES) / #else #error
"Unknown graphics API"", matching the other glue backends.
- Convert the "#ifndef RUISAPP_RENDER_METAL" shared-GL-context member to
the positive condition "#ifdef RUISAPP_RENDER_OPENGL".
Summary
Add a Metal variant of the ruisapp glue layer for macOS and iOS:
CAMetalLayer-based window (MetalView/CocoaWindow), Cocoa glue, key-code mappingCAMetalLayer-based windowRUISAPP_RENDER_METALdefine, and theruisapp-metal-testapplicationCAMetalLayerby reference to the Metal context (the one held by the native_window) — nonative_window-specific method is needed (mirrors the Vulkan renderer's surface approach)Depends on ruis PR #211 (register the renderer in the monorepo build) and on the Metal renderer PR (cppfw/ruis-render-metal PR #3).