Repository navigation
Commit 2b4e16d
NativeEngine: MultiRenderTarget framebuffers + OIT alpha blend modes (#1754)
Paired engine PR: BabylonJS/Babylon.js#18568
## What
Foundational native support for `MultiRenderTarget` (MRT) and the
order-independent-transparency blend
modes, removing several "`engine._gl` is null" crash classes. It does
**not** by itself turn the
MRT/OIT/FrameGraph validation tests green — those need further work (see
Follow-ups).
## Changes
- **`Plugins/NativeEngine/Source/NativeEngine.cpp` / `.h`**
- `CreateFrameBuffer` and `CreateMultiFrameBuffer` now share a private
`CreateFrameBufferImpl(env, colorTextures, …)` helper that builds one
bgfx framebuffer with N color
attachments (+ an optional depth/stencil attachment), so a
`MultiRenderTarget` renders to all
targets at once (bgfx writes every attachment of the bound framebuffer —
no `drawBuffers` needed).
The two N-API methods are kept for protocol compatibility and only
differ in how they parse
`info[0]` (single nullable texture vs. array); the single-RT path is
just the 0-or-1-color case.
The shared helper validates the attachment count against
`caps->limits.maxFBAttachments` and keeps
the `"Stencil without depth…"` warning and the `isTextureValid` assert.
- Add alpha blend modes `ALPHA_ONEONE_ONEONE` (11) and
`ALPHA_LAYER_ACCUMULATE` (17) used by the
depth-peeling OIT renderer.
## Paired engine PR
Pairs with the Babylon.js change (`createMultipleRenderTarget` + MRT
helper overrides, `applyStates`
override, reverse-Z `clear`, alpha-mode mapping). That PR
feature-detects both `createMultiFrameBuffer`
and the two alpha constants, so it degrades gracefully on native
binaries that predate this PR.
## CI
The validation suite uses the published `babylonjs` npm, which doesn't
yet contain the paired JS, so
no new tests are enabled here and CI stays in the usual "pending dep
bump" state. Verified locally
against a `babylon.max.js` built from the paired branch, and the plugin
compiles clean
(`cmake --build build/win32 --target NativeEngine --config
RelWithDebInfo`).
## Follow-ups (separate work)
- OIT depth-peeling still faults inside the D3D11 driver on `submit`
(multi-output / SRV↔RTV
ping-pong); needs interactive GPU debugging (PIX / VS Graphics
Debugger).
- Native does not yet apply the blend **equation** (`MAX`) —
`setAlphaEquation` is a no-op — so OIT
blending would still be incorrect after the crash is fixed.
- 2D-array / cube color attachments for MRT are approximated as 2D (test
"MRT with different texture
types").
---
## Related PRs & landing order
- **Babylon.js (engine / TS):**
BabylonJS/Babylon.js#18568
- **BabylonNative (C++ engine):**
#1754
These two are co-dependent and land in this order:
1. **Babylon.js #18568 first** — it only adds native-engine TS
overrides, changes no WebGL behavior,
re-enables no validation tests on its own, and feature-detects this PR's
additions, so it can merge
independently.
2. A **`babylonjs` npm release** ships that TS change.
3. **BabylonNative #1754 last** — after bumping the bundled `babylonjs`
to that release. (This
foundational pair does not yet turn the MRT/OIT/FrameGraph tests green —
that is separate follow-up
work.)
---------
Co-authored-by: Branimir Karadzic <branimirkaradzic@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent fbc2c82 commit 2b4e16d
2 files changed
Lines changed: 63 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| |||
598 | 600 | | |
599 | 601 | | |
600 | 602 | | |
| 603 | + | |
| 604 | + | |
601 | 605 | | |
602 | 606 | | |
603 | 607 | | |
| |||
726 | 730 | | |
727 | 731 | | |
728 | 732 | | |
| 733 | + | |
729 | 734 | | |
730 | 735 | | |
731 | 736 | | |
| |||
1874 | 1879 | | |
1875 | 1880 | | |
1876 | 1881 | | |
1877 | | - | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
1878 | 1929 | | |
1879 | 1930 | | |
1880 | | - | |
| 1931 | + | |
1881 | 1932 | | |
1882 | | - | |
1883 | 1933 | | |
1884 | 1934 | | |
1885 | 1935 | | |
| |||
1894 | 1944 | | |
1895 | 1945 | | |
1896 | 1946 | | |
1897 | | - | |
| 1947 | + | |
1898 | 1948 | | |
1899 | 1949 | | |
1900 | 1950 | | |
| |||
1926 | 1976 | | |
1927 | 1977 | | |
1928 | 1978 | | |
1929 | | - | |
| 1979 | + | |
1930 | 1980 | | |
1931 | 1981 | | |
1932 | 1982 | | |
1933 | | - | |
| 1983 | + | |
1934 | 1984 | | |
1935 | 1985 | | |
1936 | 1986 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
35 | 40 | | |
36 | 41 | | |
37 | 42 | | |
| |||
114 | 119 | | |
115 | 120 | | |
116 | 121 | | |
| 122 | + | |
| 123 | + | |
117 | 124 | | |
118 | 125 | | |
119 | 126 | | |
| |||
0 commit comments