Skip to content

Use BabylonNative WindowT type#708

Draft
CedricGuillemet wants to merge 9 commits intoBabylonJS:masterfrom
CedricGuillemet:UpdateViewLayer
Draft

Use BabylonNative WindowT type#708
CedricGuillemet wants to merge 9 commits intoBabylonJS:masterfrom
CedricGuillemet:UpdateViewLayer

Conversation

@CedricGuillemet
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the React Native Babylon Native interop to pass a platform-specific graphics “window” handle (Babylon::Graphics::WindowT) into the shared graphics configuration, aligning iOS to pass the Metal layer instead of the MTKView.

Changes:

  • Change BabylonNative::UpdateView declaration to take Babylon::Graphics::WindowT instead of WindowType.
  • Update shared ReactNativeModule::UpdateView to store the passed WindowT directly (removing the iOS-only window.layer conversion).
  • Update iOS interop to call UpdateView with mtkView.layer.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
Modules/@babylonjs/react-native/shared/BabylonNative.h Changes the UpdateView API to accept Babylon::Graphics::WindowT.
Modules/@babylonjs/react-native/shared/BabylonNative.cpp Updates internal UpdateView to store the window handle directly, removing iOS conditional logic.
Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm Passes mtkView.layer into UpdateView on iOS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread Modules/@babylonjs/react-native/shared/BabylonNative.h Outdated
Comment thread Modules/@babylonjs/react-native/shared/BabylonNative.cpp
Comment thread Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm Outdated
@CedricGuillemet CedricGuillemet marked this pull request as draft March 19, 2026 09:06
CedricGuillemet and others added 7 commits April 14, 2026 15:31
wstring_convert<codecvt_utf8_utf16> is deprecated in C++17 and the
BabylonNative cmakeextensions build helper adds -Werror to all Clang
targets, turning this deprecation into a hard build error on
Xcode 26+ / Clang 20+.

Add -Wno-deprecated-declarations via add_compile_options for Clang/
AppleClang builds so the project compiles cleanly while all other
-Werror checks remain enforced.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- postinstall.js: add BABYLON_USE_SYSTEM_CMAKE=1 env variable that
  bypasses the npm-bundled cmake-runtime package and uses whatever
  cmake is found on PATH (Homebrew, system install, etc.)
- README: document the new BABYLON_USE_SYSTEM_CMAKE variable in the
  iOS CMake configuration section
- README: add BabylonReactNative 2.0.2 entry to the Platform Native
  Packages version table (requires Babylon.js 9.0.0, BabylonNative 887a044)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Include QuartzCore/CAMetalLayer.h explicitly so that CA::MetalLayer
is declared when BabylonNative.h is compiled. MTKView.h alone does
not guarantee the CA namespace is available in all build contexts
(e.g. the CI runner with Xcode 26).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
<QuartzCore/CAMetalLayer.h> only defines an Objective-C @interface, not
the C++ CA::MetalLayer class from Metal-cpp. BabylonNative.cpp is compiled
as a pure C++ translation unit, so including that header does not make the
CA:: namespace visible.

Replace the include with a C++ forward declaration:
  namespace CA { class MetalLayer; }

This is sufficient for the pointer type alias in the header.
The full definition is provided by the Metal-cpp headers that BabylonNative
itself brings in when the implementation files are compiled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
mtkView.layer returns CALayer* (ObjC), but UpdateView expects
CA::MetalLayer* (C++ Metal-cpp type). These are ABI-compatible since
MTKView always uses CAMetalLayer as its backing layer, but in ObjC++
we must bridge explicitly:

  1. Cast CALayer* -> CAMetalLayer* (safe ObjC downcast)
  2. __bridge void*               (ARC-safe ObjC -> C pointer)
  3. reinterpret_cast<WindowTypeUpdate>   (void* -> CA::MetalLayer*)

Also import <QuartzCore/CAMetalLayer.h> to declare CAMetalLayer in the
ObjC++ TU.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants