Skip to content

Commit 77c4f66

Browse files
bkaradzicCopilot
andcommitted
Add native cube render target support (re-enables 2 shadow-with-instances tests)
Render-to-cubemap on the native engine so ReflectionProbe and point-light cube shadow maps render instead of dereferencing the null WebGL context. - InitializeTexture: optional isCube param -> Texture::CreateCube. - CreateFrameBuffer: optional layer param so the color attachment targets a single cube face (bgfx::Attachment layer); the JS side creates one framebuffer per face and binds the matching one per face. Re-enables the "Shadows with instances in left/right handed system" validation tests that previously crashed/hung. Requires the paired Babylon.js change (native cube render target JS overrides); CI stays red until a babylonjs npm with that change is published and the dep bumped here. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b6ecf80 commit 77c4f66

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

Apps/Playground/Scripts/config.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,16 +1825,12 @@
18251825
"title": "Shadows with instances in left handed system",
18261826
"playgroundId": "#MSAHKR#79",
18271827
"renderCount": 10,
1828-
"excludeFromAutomaticTesting": true,
1829-
"reason": "Test crashes or hangs on Babylon Native",
18301828
"referenceImage": "shadowsinstancesleft.png"
18311829
},
18321830
{
18331831
"title": "Shadows with instances in right handed system",
18341832
"playgroundId": "#MSAHKR#13",
18351833
"renderCount": 10,
1836-
"excludeFromAutomaticTesting": true,
1837-
"reason": "Test crashes or hangs on Babylon Native",
18381834
"referenceImage": "shadowsinstancesright.png"
18391835
},
18401836
{

Plugins/NativeEngine/Source/NativeEngine.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,7 @@ namespace Babylon
13211321
const bool renderTarget = info[5].As<Napi::Boolean>();
13221322
const bool srgb = info[6].As<Napi::Boolean>();
13231323
const uint32_t samples = info[7].IsUndefined() ? 1 : info[7].As<Napi::Number>().Uint32Value();
1324+
const bool isCube = info.Length() > 8 && !info[8].IsUndefined() && info[8].As<Napi::Boolean>();
13241325

13251326
auto flags = BGFX_TEXTURE_NONE;
13261327
if (renderTarget)
@@ -1332,7 +1333,15 @@ namespace Babylon
13321333
flags |= BGFX_TEXTURE_SRGB;
13331334
}
13341335

1335-
texture->Create2D(width, height, hasMips, 1, format, flags);
1336+
if (isCube)
1337+
{
1338+
// Cube render target: width is the per-face size.
1339+
texture->CreateCube(width, hasMips, 1, format, flags);
1340+
}
1341+
else
1342+
{
1343+
texture->Create2D(width, height, hasMips, 1, format, flags);
1344+
}
13361345
}
13371346

13381347
void NativeEngine::LoadTexture(const Napi::CallbackInfo& info)
@@ -1820,6 +1829,8 @@ namespace Babylon
18201829
const bool generateStencilBuffer = info[3].As<Napi::Boolean>();
18211830
const bool generateDepth = info[4].As<Napi::Boolean>();
18221831
const uint32_t samples = info[5].IsUndefined() ? 1 : info[5].As<Napi::Number>().Uint32Value();
1832+
// Optional cube-face / array layer for the color attachment (single-face cube render targets).
1833+
const uint16_t layer = (info.Length() > 6 && !info[6].IsUndefined()) ? static_cast<uint16_t>(info[6].As<Napi::Number>().Uint32Value()) : 0;
18231834

18241835
std::array<bgfx::Attachment, 2> attachments{};
18251836
uint8_t numAttachments = 0;
@@ -1830,7 +1841,7 @@ namespace Babylon
18301841
// bgfx validation now asserts when trying to use BGFX_RESOLVE_AUTO_GEN_MIPS with a texture that doesn't have the BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN flag,
18311842
// but before it would just ignore the flag and not generate mips without any warning. This prevents validation assert, but rendering might be broken if autogen
18321843
// mips were expected. Basically this change preserves previous behavior.
1833-
attachments[numAttachments++].init(texture->Handle(), bgfx::Access::Write, 0, 1, 0
1844+
attachments[numAttachments++].init(texture->Handle(), bgfx::Access::Write, layer, 1, 0
18341845
, 0 != (caps->formats[texture->Format()] & BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN) ? BGFX_RESOLVE_AUTO_GEN_MIPS : BGFX_RESOLVE_NONE
18351846
);
18361847
}

0 commit comments

Comments
 (0)