Hello!
I’m working on bringing Babylon Native to Apple Vision Pro. We are almost done with migrating the underlying rendering engine (bgfx). I’ve already started the integration to Babylon Native (here is the PR: feat: add visionOS support by okwasniewski · Pull Request #1384 · BabylonJS/BabylonNative · GitHub)
So the Playground app for iOS has an interesting pattern which I’m trying to understand. First, we pass an (MTKView*)view
that’s used for initialization of the graphics config, and then is the layer that receives the “2d rendering” inside of a window.
But we also have another MTKView
which is passed as a raw pointer called xrView
. Then this xrView
is passed down to initialize the NativeXr
plugin. Once the session changed callback is changed and called with isXrActive
as true, we trigger the isHidden
property to reveal the second MTKView.
As far as I understand the underlying MTKView is still rendering(?) which sounds like something that can lead to performance issues. - I might be wrong here.
When we render to the xrView
graphics config still “thinks” that we are rendering to the now covered MTKView
.
- (void)init:(MTKView*)view screenScale:(float)inScreenScale width:(int)inWidth height:(int)inHeight xrView:(void*)xrView
{
screenScale = inScreenScale;
float width = inWidth;
float height = inHeight;
// Init graphics config (passed down to BGFX) with the primary MTKView
Babylon::Graphics::Configuration graphicsConfig{};
graphicsConfig.Window = view;
graphicsConfig.Width = static_cast<size_t>(width);
graphicsConfig.Height = static_cast<size_t>(height);
device.emplace(graphicsConfig);
update.emplace(device->GetUpdate("update"));
device->StartRenderingCurrentFrame();
update->Start();
runtime.emplace();
runtime->Dispatch([xrView](Napi::Env env)
{
device->AddToJavaScript(env);
// [...]
Babylon::Plugins::NativeEngine::Initialize(env);
// Init nativeXr layer with second MTKView
nativeXr.emplace(Babylon::Plugins::NativeXr::Initialize(env));
nativeXr->UpdateWindow(xrView);
nativeXr->SetSessionStateChangedCallback([](bool isXrActive){ ::isXrActive = isXrActive; });
// [...]
});
// [...]
}
On visionOS we have a problem because there is no way to get two MTKView equivalents (layer renderers). So we have only one metal layer to draw into.
I’m trying to understand this design decision and whether it’s possible to initialize BabylonNative while having only one MTKView. In the case of visionOS rendering without the Xr plugin doesn’t make much sense.
Thanks for your help in advance.