@onerjs/core 8.51.7 → 8.51.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Engines/abstractEngine.pure.js +11 -4
- package/Engines/abstractEngine.pure.js.map +1 -1
- package/Engines/engine.pure.d.ts +23 -0
- package/Engines/engine.pure.js +96 -1
- package/Engines/engine.pure.js.map +1 -1
- package/Engines/nativeEngine.pure.d.ts +4 -0
- package/Engines/nativeEngine.pure.js +6 -0
- package/Engines/nativeEngine.pure.js.map +1 -1
- package/Engines/thinNativeEngine.pure.d.ts +21 -0
- package/Engines/thinNativeEngine.pure.js +119 -4
- package/Engines/thinNativeEngine.pure.js.map +1 -1
- package/Engines/webgpuEngine.pure.d.ts +21 -0
- package/Engines/webgpuEngine.pure.js +46 -1
- package/Engines/webgpuEngine.pure.js.map +1 -1
- package/Materials/Textures/internalTexture.d.ts +11 -1
- package/Materials/Textures/internalTexture.js +16 -0
- package/Materials/Textures/internalTexture.js.map +1 -1
- package/Misc/tools.pure.js +1 -1
- package/Misc/tools.pure.js.map +1 -1
- package/SmartAssets/index.d.ts +2 -2
- package/SmartAssets/index.js +2 -1
- package/SmartAssets/index.js.map +1 -1
- package/SmartAssets/pure.d.ts +1 -1
- package/SmartAssets/pure.js +2 -1
- package/SmartAssets/pure.js.map +1 -1
- package/SmartAssets/smartAssetManager.js +9 -0
- package/SmartAssets/smartAssetManager.js.map +1 -1
- package/package.json +1 -1
|
@@ -1542,7 +1542,7 @@ export class ThinNativeEngine extends ThinEngine {
|
|
|
1542
1542
|
*/
|
|
1543
1543
|
wrapNativeTexture(texture, hasMipMaps = false, samplingMode = 3) {
|
|
1544
1544
|
const hardwareTexture = new NativeHardwareTexture(texture, this._engine);
|
|
1545
|
-
const internalTexture = new InternalTexture(this,
|
|
1545
|
+
const internalTexture = new InternalTexture(this, 15 /* InternalTextureSource.External */, true);
|
|
1546
1546
|
internalTexture._hardwareTexture = hardwareTexture;
|
|
1547
1547
|
internalTexture.baseWidth = this._engine.getTextureWidth(texture);
|
|
1548
1548
|
internalTexture.baseHeight = this._engine.getTextureHeight(texture);
|
|
@@ -1553,6 +1553,68 @@ export class ThinNativeEngine extends ThinEngine {
|
|
|
1553
1553
|
this.updateTextureSamplingMode(samplingMode, internalTexture);
|
|
1554
1554
|
return internalTexture;
|
|
1555
1555
|
}
|
|
1556
|
+
/**
|
|
1557
|
+
* Replaces the underlying native texture handle of a texture previously created via {@link wrapNativeTexture},
|
|
1558
|
+
* preserving the InternalTexture identity.
|
|
1559
|
+
*
|
|
1560
|
+
* Intended for the device-loss / device-restored flow (a DisableRendering / EnableRendering cycle from the host
|
|
1561
|
+
* application): when the host recreates its external resource on the new graphics device, it calls this method to
|
|
1562
|
+
* repoint Babylon's wrapper at the new handle without losing references held by materials, render-target wrappers,
|
|
1563
|
+
* particle systems, etc.
|
|
1564
|
+
*
|
|
1565
|
+
* The new handle must match the wrapped texture's recorded dimensions. To change dimensions, dispose the wrapped
|
|
1566
|
+
* texture and call {@link wrapNativeTexture} again. Sampling mode and mip-map flag are properties of the logical
|
|
1567
|
+
* wrapped texture and are re-applied to the new resource. Any render-target wrapper holding this texture as its
|
|
1568
|
+
* color attachment has its framebuffer rebuilt with the new handle.
|
|
1569
|
+
*
|
|
1570
|
+
* Throws if the target was not produced by {@link wrapNativeTexture}, if the new handle's dimensions don't match,
|
|
1571
|
+
* if the wrapped texture is part of a multi render-target, or if the wrapper has a depth/stencil texture (these
|
|
1572
|
+
* are not supported in this version; dispose and re-wrap).
|
|
1573
|
+
* @param internalTexture defines the wrapped InternalTexture to repoint
|
|
1574
|
+
* @param texture defines the new native texture handle to wrap
|
|
1575
|
+
*/
|
|
1576
|
+
updateWrappedNativeTexture(internalTexture, texture) {
|
|
1577
|
+
if (internalTexture.source !== 15 /* InternalTextureSource.External */) {
|
|
1578
|
+
throw new Error("updateWrappedNativeTexture: target InternalTexture was not produced by wrapNativeTexture.");
|
|
1579
|
+
}
|
|
1580
|
+
const newWidth = this._engine.getTextureWidth(texture);
|
|
1581
|
+
const newHeight = this._engine.getTextureHeight(texture);
|
|
1582
|
+
if (newWidth !== internalTexture.baseWidth || newHeight !== internalTexture.baseHeight) {
|
|
1583
|
+
throw new Error(`updateWrappedNativeTexture: new handle dimensions (${newWidth}x${newHeight}) must match the wrapped texture's dimensions (${internalTexture.baseWidth}x${internalTexture.baseHeight}).`);
|
|
1584
|
+
}
|
|
1585
|
+
// Pre-validate before mutating any state so a thrown precondition leaves the InternalTexture untouched.
|
|
1586
|
+
// Note: rtWrapper.texture only returns _textures[0]; walk every attachment to catch the multi-RT case where
|
|
1587
|
+
// the wrapped texture is at index > 0.
|
|
1588
|
+
for (const rtWrapper of this._renderTargetWrapperCache) {
|
|
1589
|
+
if (!rtWrapper.textures?.includes(internalTexture)) {
|
|
1590
|
+
continue;
|
|
1591
|
+
}
|
|
1592
|
+
if (rtWrapper.isMulti) {
|
|
1593
|
+
throw new Error("updateWrappedNativeTexture: wrapped texture is part of a multi render-target; not supported. Dispose and re-wrap.");
|
|
1594
|
+
}
|
|
1595
|
+
if (rtWrapper._depthStencilTexture) {
|
|
1596
|
+
// After a DisableRendering / EnableRendering cycle the bgfx framebuffer + the depth/stencil texture's
|
|
1597
|
+
// bgfx handle are both stale. Rebuilding the depth/stencil texture from the wrapper's stored settings
|
|
1598
|
+
// is feasible but non-trivial; v1 rejects and asks the caller to dispose + re-wrap.
|
|
1599
|
+
throw new Error("updateWrappedNativeTexture: wrapped texture's render-target wrapper has a depth/stencil texture; not supported. Dispose and re-wrap.");
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
internalTexture._hardwareTexture = new NativeHardwareTexture(texture, this._engine);
|
|
1603
|
+
internalTexture.isReady = true;
|
|
1604
|
+
this.updateTextureSamplingMode(internalTexture.samplingMode, internalTexture);
|
|
1605
|
+
// Rebuild the framebuffer of any render-target wrapper holding this wrapped texture as its color attachment.
|
|
1606
|
+
// After a DisableRendering / EnableRendering cycle the bgfx framebuffer handle is stale; the consumer-supplied
|
|
1607
|
+
// new texture is the moment we have a fresh handle to rebuild against.
|
|
1608
|
+
for (const rtWrapper of this._renderTargetWrapperCache) {
|
|
1609
|
+
if (rtWrapper.texture !== internalTexture) {
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1612
|
+
const nativeRTWrapper = rtWrapper;
|
|
1613
|
+
// NativeRenderTargetWrapper._framebuffer setter releases the old framebuffer before assigning,
|
|
1614
|
+
// so no manual _releaseFramebufferObjects call is needed (and would double-delete the handle).
|
|
1615
|
+
nativeRTWrapper._framebuffer = this._engine.createFrameBuffer(texture, rtWrapper.width, rtWrapper.height, rtWrapper._generateStencilBuffer, rtWrapper._generateDepthBuffer, rtWrapper.samples ?? 1);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1556
1618
|
_createDepthStencilTexture(size, options, rtWrapper) {
|
|
1557
1619
|
// TODO: handle other options?
|
|
1558
1620
|
const generateStencil = options.generateStencil || false;
|
|
@@ -1685,8 +1747,18 @@ export class ThinNativeEngine extends ThinEngine {
|
|
|
1685
1747
|
}
|
|
1686
1748
|
const nativeTexture = texture._hardwareTexture.underlyingResource;
|
|
1687
1749
|
const nativeTextureFormat = getNativeTextureFormat(format, type);
|
|
1750
|
+
// TODO(bgfx-msaa-mips): stopgap workaround for a bgfx bug -- D3D11/D3D12/Vulkan backends share one
|
|
1751
|
+
// texture descriptor between the MSAA render target and the non-MSAA resolve target, so requesting
|
|
1752
|
+
// both mips > 1 and samples > 1 makes the API (D3D11 E_INVALIDARG, Vulkan VUID-02257, ...) reject the
|
|
1753
|
+
// MSAA texture creation. Force hasMips = false here to keep the combo from reaching bgfx. The fix
|
|
1754
|
+
// belongs in bgfx (separate descs per target, like OpenGL/WebGL do with a non-mipped renderbuffer);
|
|
1755
|
+
// this guard should be removed once a fixed bgfx ships in a stable BabylonNative npm release. Tracked
|
|
1756
|
+
// in BabylonNative#1714. Cost: MSAA RTs on Native lose post-resolve auto-mipgen and diverge from
|
|
1757
|
+
// WebGL/WebGPU semantics -- texture.generateMipMaps stays true on the InternalTexture but the
|
|
1758
|
+
// underlying bgfx resource has 1 mip.
|
|
1759
|
+
const hasMips = samples > 1 ? false : generateMipMaps;
|
|
1688
1760
|
// REVIEW: We are always setting the renderTarget flag as we don't know whether the texture will be used as a render target.
|
|
1689
|
-
this._engine.initializeTexture(nativeTexture, width, height,
|
|
1761
|
+
this._engine.initializeTexture(nativeTexture, width, height, hasMips, nativeTextureFormat, true, useSRGBBuffer, samples);
|
|
1690
1762
|
this._setTextureSampling(nativeTexture, getNativeSamplingMode(samplingMode));
|
|
1691
1763
|
texture._useSRGBBuffer = useSRGBBuffer;
|
|
1692
1764
|
texture.baseWidth = width;
|
|
@@ -1730,8 +1802,51 @@ export class ThinNativeEngine extends ThinEngine {
|
|
|
1730
1802
|
return rtWrapper;
|
|
1731
1803
|
}
|
|
1732
1804
|
updateRenderTargetTextureSampleCount(rtWrapper, samples) {
|
|
1733
|
-
|
|
1734
|
-
|
|
1805
|
+
if (rtWrapper.samples === samples) {
|
|
1806
|
+
return samples;
|
|
1807
|
+
}
|
|
1808
|
+
const texture = rtWrapper.texture;
|
|
1809
|
+
if (!texture?._hardwareTexture) {
|
|
1810
|
+
return rtWrapper.samples;
|
|
1811
|
+
}
|
|
1812
|
+
// Wrapped (External-source) textures carry an opaque external handle with unknown format/type.
|
|
1813
|
+
// Recreating the underlying bgfx texture here would destroy the wrapped handle, breaking the
|
|
1814
|
+
// consumer's ownership contract, and getNativeTextureFormat would throw on format=-1 anyway.
|
|
1815
|
+
// Reject the request explicitly with a targeted error rather than failing deeper in the stack.
|
|
1816
|
+
if (texture.source === 15 /* InternalTextureSource.External */) {
|
|
1817
|
+
throw new Error("updateRenderTargetTextureSampleCount: changing MSAA samples is not supported on wrapped (External-source) textures. Dispose and re-wrap with the desired samples.");
|
|
1818
|
+
}
|
|
1819
|
+
const nativeRTWrapper = rtWrapper;
|
|
1820
|
+
const nativeTexture = texture._hardwareTexture.underlyingResource;
|
|
1821
|
+
// bgfx couples MSAA to the texture creation flags, so changing samples after the fact requires
|
|
1822
|
+
// recreating the underlying bgfx texture handle with the new MSAA flag. initializeTexture on the
|
|
1823
|
+
// Native side calls Graphics::Texture::Create2D, which disposes the existing bgfx handle and
|
|
1824
|
+
// allocates a fresh one. The Graphics::Texture / InternalTexture wrapper identity is preserved --
|
|
1825
|
+
// only the internal bgfx handle rotates. After the texture is reissued we also recreate the
|
|
1826
|
+
// framebuffer so its attachment list refers to the new handle.
|
|
1827
|
+
//
|
|
1828
|
+
// TODO(bgfx-msaa-mips): stopgap workaround for a bgfx bug. D3D11 forbids MipLevels > 1 on
|
|
1829
|
+
// multisampled textures (E_INVALIDARG on CreateTexture2D); D3D12/Vulkan have equivalent rules. bgfx's
|
|
1830
|
+
// D3D11 backend uses one D3D11_TEXTURE2D_DESC for both the MSAA render texture (m_rt2d) and the
|
|
1831
|
+
// non-MSAA sample target (m_texture2d) and doesn't reset desc.MipLevels between them -- so requesting
|
|
1832
|
+
// samples > 1 with hasMips = true crashes at m_rt2d creation. The trigger in practice is the glTF
|
|
1833
|
+
// transmission helper, which creates an `opaqueSceneTexture` RTT with generateMipmaps: true and
|
|
1834
|
+
// immediately sets samples = 4. WebGL2 sidesteps this with a separate non-mipped multisample
|
|
1835
|
+
// renderbuffer; bgfx D3D11 conflates the two-stage pattern. The proper fix lives in bgfx (per-backend
|
|
1836
|
+
// patches reset MipLevels=1 for the MSAA target). Tracked in BabylonNative#1714. Until that ships
|
|
1837
|
+
// through bgfx -> bgfx.cmake -> BabylonNative -> stable npm, force hasMips = false here so the bad
|
|
1838
|
+
// combo never reaches bgfx. Cost: MSAA RTs on Native lose post-resolve auto-mipgen and diverge from
|
|
1839
|
+
// WebGL/WebGPU semantics -- texture.generateMipMaps still reads true on the JS side, but the
|
|
1840
|
+
// underlying bgfx resource has 1 mip level. Remove this guard once a fixed bgfx is in stable BN npm.
|
|
1841
|
+
const hasMips = samples > 1 ? false : texture.generateMipMaps;
|
|
1842
|
+
const nativeTextureFormat = getNativeTextureFormat(texture.format, texture.type);
|
|
1843
|
+
this._engine.initializeTexture(nativeTexture, texture.baseWidth, texture.baseHeight, hasMips, nativeTextureFormat, /*renderTarget*/ true, texture._useSRGBBuffer, samples);
|
|
1844
|
+
// NativeRenderTargetWrapper._framebuffer setter releases the old framebuffer before assigning,
|
|
1845
|
+
// so no manual _releaseFramebufferObjects call is needed (and would double-delete the handle).
|
|
1846
|
+
nativeRTWrapper._framebuffer = this._engine.createFrameBuffer(nativeTexture, texture.baseWidth, texture.baseHeight, rtWrapper._generateStencilBuffer, rtWrapper._generateDepthBuffer, samples);
|
|
1847
|
+
rtWrapper._samples = samples;
|
|
1848
|
+
texture.samples = samples;
|
|
1849
|
+
return samples;
|
|
1735
1850
|
}
|
|
1736
1851
|
updateTextureSamplingMode(samplingMode, texture) {
|
|
1737
1852
|
if (texture._hardwareTexture) {
|