"Integrations" (simple) API layer#1701
Draft
ryantrem wants to merge 62 commits into
Draft
Conversation
Add ShaderCache support
Add options to Playground::Initialize Update win32 playground to pass options from cmd options (parity with master AppContext)
bghgary
reviewed
May 21, 2026
ryantrem
commented
May 21, 2026
Comment on lines
+217
to
+219
| // TODO: Should be able to clear the Dirty flag, but bgfx::init is not doing everything that UpdateBgfxState is doing (at least on Apple platforms). | ||
| // See https://github.com/BabylonJS/ThePirateCove/issues/1657 | ||
| // m_state.Bgfx.Dirty = false; |
Member
Author
There was a problem hiding this comment.
We probably need to sort this out before merging.
Member
Author
There was a problem hiding this comment.
"Integrations" may not be the right name for this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces a new
Babylon::Integrationslayer that gives host apps a small, opinionatedRuntime+ViewAPI for embedding Babylon Native, and migrates every Playground host (Android, iOS, visionOS, macOS, UWP, Win32, X11) onto it. The goal is to make platform integration a job that takes tens — not hundreds — of lines of code, and to do that without leakingAppRuntime,Graphics::Device, plugin headers, polyfill plumbing, or threading rules into the host.Two layers ship together:
Integrations/Include/Shared/Babylon/Integrations/{Runtime,View,RuntimeOptions,LogLevel}.h) — cross-platform, single source of truth for the lifecycle, threading, suspend/resume, input forwarding, and XR window management.BabylonNative.java+ JNI (BabylonNativeIntegrations.cpp)BNRuntime/BNViewObj‑C classes (Swift-friendly via the bridging header)What's new
Integrationscore (Integrations/Source,Integrations/Include/Shared)Two value types with explicit ownership and a documented contract:
Babylon::Integrations::RuntimeOptions options{}; options.enableDebugger = true; options.log = [](LogLevel level, std::string_view msg) { /* … */ }; Babylon::Integrations::Runtime runtime{options}; runtime.LoadScript("app:///Scripts/babylon.max.js"); runtime.LoadScript("app:///Scripts/scene.js"); Babylon::Integrations::View view{runtime, nativeWindowHandle}; view.Resize(width, height, CoordinateUnits::Physical); // driven from the host's draw callback: view.RenderFrame();What the layer takes care of for you:
AppRuntime,JsRuntime, polyfills (Console, Window, XMLHttpRequest, WebSocket, URL, Canvas, TextDecoder, Performance, Scheduling), and non‑GPU plugins.Graphics::Device,NativeEngine,NativeInput,NativeCanvas,TestUtils, and (optionally)NativeXr/ShaderCacheare constructed lazily on the firstView::Resize. Subsequent View attaches just rebind the Device.LoadScript/Eval/RunOnJsThreadare safe to call before the firstViewattach; queued and flushed when the engine comes up.OnPointer*/OnMouse*accept eitherPhysicalorLogicalpixel units; the View handles DPR conversion.Runtime::SetXrWindowhands off a secondary surface for NativeXr.RuntimeOptions::logsink forconsole.{log,warn,error},Babylon::DebugTrace, and uncaught JS exceptions.Android facade
Integrations/Android/BabylonNative/(replaces the oldBabylonNativeJNI.cpp+Wrapper.java).com.babylonjs.integrations.BabylonNative— Java mirror of the C++ API:loadScript,eval,runOnJsThread,suspend,resume,attachView,setXrWindow. Includes aRuntime.Builder, aLogListenerinterface, and aSurfaceViewattach overload that wiresSurfaceHolder.Callbackfor you.Apple facade
Integrations/Apple/— Obj‑C wrappers (BNRuntime,BNView,BNViewDelegate) usable from Obj‑C and from Swift via the bridging header. Used by Playground iOS, macOS, and visionOS.BNRuntimeNative.hexposes the underlyingBabylon::Integrations::Runtime&for callers that need the C++ API.Host app migrations
Every Playground host now runs on top of the Integrations layer:
BabylonNativeJNI.cpp(~196 lines bespoke JNI) +Wrapper.javaBabylonNativeJava classLibNativeBridge.{h,mm}+ ad-hoc Swift glueBNRuntime/BNView, ~75-lineViewController.swiftViewController.mmdoing its own AppContext plumbingBNRuntime/BNViewtypes as iOSLibNativeBridge.{h,mm}+ custom App.swift threadingBNRuntime/BNView+ bridging headerAppContext+ manualUpdateSize/ mouse plumbingRuntime+ViewwithWM_POINTER→View::On*AppContext+ manual swap-chain plumbingRuntime+ViewfromIInspectableAppContext+ xcb event handlersRuntime+ViewwithView::OnMouse*Lifecycle contract
Resizeat least once with the surface's pixel dimensions before the firstRenderFrame— the Device is built on the first Resize.Viewconstructor throwsstd::runtime_erroron double-attach.~Runtimeisnoexcept(false)and throws if a View is still attached.~Viewclears the back-reference, so LIFO destruction works.RenderFrame,Resize,Suspend,Resume,LoadScript,Eval,RunOnJsThread, View construction/destruction.OnPointer*/OnMouse*/IsSuspended/IsXrActive/SetXrWindow.File scope
Closed open items
RunOnJsThreadnow has anafterScriptLoadparameterRuntime/Vieware regular movable value types.mdfrom the repo root