Skip to content

Commit 4c79b1d

Browse files
committed
Merge branch 'external-texture-render-test' into partner-test-1652-1646
# Conflicts: # Apps/HeadlessScreenshotApp/Win32/App.cpp # Apps/PrecompiledShaderTest/Source/App.cpp # Apps/StyleTransferApp/Win32/App.cpp
2 parents 8a519b7 + ac6ba6e commit 4c79b1d

28 files changed

Lines changed: 1443 additions & 317 deletions

Apps/HeadlessScreenshotApp/Win32/App.cpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,35 +127,21 @@ int main()
127127
// Create a render target texture for the output.
128128
winrt::com_ptr<ID3D11Texture2D> outputTexture = CreateD3DRenderTargetTexture(d3dDevice.get());
129129

130-
std::promise<void> addToContext{};
131130
std::promise<void> startup{};
132131

133132
// Create an external texture for the render target texture and pass it to
134133
// the `startup` JavaScript function.
135-
loader.Dispatch([externalTexture = Babylon::Plugins::ExternalTexture{outputTexture.get()}, &addToContext, &startup](Napi::Env env) {
136-
auto jsPromise = externalTexture.AddToContextAsync(env);
137-
addToContext.set_value();
138-
139-
auto jsOnFulfilled = Napi::Function::New(env, [&startup](const Napi::CallbackInfo& info) {
140-
auto nativeTexture = info[0];
141-
info.Env().Global().Get("startup").As<Napi::Function>().Call(
142-
{
143-
nativeTexture,
144-
Napi::Value::From(info.Env(), WIDTH),
145-
Napi::Value::From(info.Env(), HEIGHT),
146-
});
147-
startup.set_value();
148-
});
149-
150-
jsPromise = jsPromise.Get("then").As<Napi::Function>().Call(jsPromise, {jsOnFulfilled}).As<Napi::Promise>();
151-
152-
CatchAndLogError(jsPromise);
134+
loader.Dispatch([externalTexture = Babylon::Plugins::ExternalTexture{outputTexture.get()}, &startup](Napi::Env env) {
135+
auto nativeTexture = externalTexture.CreateForJavaScript(env);
136+
env.Global().Get("startup").As<Napi::Function>().Call(
137+
{
138+
nativeTexture,
139+
Napi::Value::From(env, WIDTH),
140+
Napi::Value::From(env, HEIGHT),
141+
});
142+
startup.set_value();
153143
});
154144

155-
// Wait for `AddToContextAsync` to be called.
156-
addToContext.get_future().wait();
157-
158-
// Render a frame so that `AddToContextAsync` will complete.
159145
deviceUpdate.Finish();
160146
device.FinishRenderingCurrentFrame();
161147

Apps/PrecompiledShaderTest/Source/App.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,34 +135,21 @@ int RunApp(
135135
Babylon::ScriptLoader loader{runtime};
136136
loader.LoadScript("app:///index.js");
137137

138-
std::promise<void> addToContext{};
139138
std::promise<void> startup{};
140139

141140
// Create an external texture for the render target texture and pass it to
142141
// the `startup` JavaScript function.
143-
loader.Dispatch([externalTexture = std::move(externalTexture), &addToContext, &startup](Napi::Env env) {
144-
auto jsPromise = externalTexture.AddToContextAsync(env);
145-
addToContext.set_value();
146-
147-
auto jsOnFulfilled = Napi::Function::New(env, [&startup](const Napi::CallbackInfo& info) {
148-
auto nativeTexture = info[0];
149-
info.Env().Global().Get("startup").As<Napi::Function>().Call(
150-
{
151-
nativeTexture,
152-
Napi::Value::From(info.Env(), WIDTH),
153-
Napi::Value::From(info.Env(), HEIGHT),
154-
});
155-
startup.set_value();
156-
});
157-
158-
jsPromise = jsPromise.Get("then").As<Napi::Function>().Call(jsPromise, {jsOnFulfilled}).As<Napi::Promise>();
159-
CatchAndLogError(jsPromise);
142+
loader.Dispatch([externalTexture = std::move(externalTexture), &startup](Napi::Env env) {
143+
auto nativeTexture = externalTexture.CreateForJavaScript(env);
144+
env.Global().Get("startup").As<Napi::Function>().Call(
145+
{
146+
nativeTexture,
147+
Napi::Value::From(env, WIDTH),
148+
Napi::Value::From(env, HEIGHT),
149+
});
150+
startup.set_value();
160151
});
161152

162-
// Wait for `AddToContextAsync` to be called.
163-
addToContext.get_future().wait();
164-
165-
// Render a frame so that `AddToContextAsync` will complete.
166153
deviceUpdate.Finish();
167154
device.FinishRenderingCurrentFrame();
168155

Apps/StyleTransferApp/Win32/App.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -334,31 +334,21 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
334334
loader.LoadScript("app:///Scripts/babylonjs.loaders.js");
335335
loader.LoadScript("app:///Scripts/index.js");
336336

337-
std::promise<void> addToContext{};
338337
std::promise<void> startup{};
339338

340339
// Create an external texture for the render target texture and pass it to
341340
// the `startup` JavaScript function.
342-
loader.Dispatch([externalTexture = Babylon::Plugins::ExternalTexture{g_BabylonRenderTexture.get()}, &addToContext, &startup](Napi::Env env) {
343-
auto jsPromise = externalTexture.AddToContextAsync(env);
344-
addToContext.set_value();
345-
346-
jsPromise.Get("then").As<Napi::Function>().Call(jsPromise, {Napi::Function::New(env, [&startup](const Napi::CallbackInfo& info) {
347-
auto nativeTexture = info[0];
348-
info.Env().Global().Get("startup").As<Napi::Function>().Call(
349-
{
350-
nativeTexture,
351-
Napi::Value::From(info.Env(), WIDTH),
352-
Napi::Value::From(info.Env(), HEIGHT),
353-
});
354-
startup.set_value();
355-
})});
341+
loader.Dispatch([externalTexture = Babylon::Plugins::ExternalTexture{g_BabylonRenderTexture.get()}, &startup](Napi::Env env) {
342+
auto nativeTexture = externalTexture.CreateForJavaScript(env);
343+
env.Global().Get("startup").As<Napi::Function>().Call(
344+
{
345+
nativeTexture,
346+
Napi::Value::From(env, WIDTH),
347+
Napi::Value::From(env, HEIGHT),
348+
});
349+
startup.set_value();
356350
});
357351

358-
// Wait for `AddToContextAsync` to be called.
359-
addToContext.get_future().wait();
360-
361-
// Render a frame so that `AddToContextAsync` will complete.
362352
g_update->Finish();
363353
g_device->FinishRenderingCurrentFrame();
364354

Apps/UnitTests/CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ set(BABYLONJS_MATERIALS_ASSETS
1111
"../node_modules/babylonjs-materials/babylonjs.materials.js")
1212

1313
set(TEST_ASSETS
14+
"JavaScript/dist/tests.externalTexture.render.js"
1415
"JavaScript/dist/tests.javaScript.all.js"
1516
"JavaScript/dist/tests.shaderCache.basicScene.js")
1617

1718
set(SOURCES
1819
"Source/App.h"
1920
"Source/App.cpp"
2021
"Source/Tests.ExternalTexture.cpp"
22+
"Source/Tests.ExternalTexture.Render.cpp"
2123
"Source/Tests.JavaScript.cpp"
2224
"Source/Tests.ShaderCache.cpp"
2325
"Source/Tests.UniformPadding.cpp"
@@ -26,8 +28,7 @@ set(SOURCES
2628

2729
if(GRAPHICS_API STREQUAL "D3D11")
2830
set(SOURCES ${SOURCES}
29-
"Source/Tests.Device.${GRAPHICS_API}.cpp"
30-
"Source/Tests.ExternalTexture.${GRAPHICS_API}.cpp")
31+
"Source/Tests.Device.${GRAPHICS_API}.cpp")
3132
endif()
3233

3334
if(APPLE)
@@ -43,7 +44,11 @@ elseif(UNIX AND NOT ANDROID)
4344
set(SOURCES ${SOURCES} "Source/App.X11.cpp")
4445
set(ADDITIONAL_COMPILE_DEFINITIONS PRIVATE SKIP_EXTERNAL_TEXTURE_TESTS)
4546
elseif(WIN32)
46-
set(SOURCES ${SOURCES} "Source/App.Win32.cpp")
47+
set(SOURCES ${SOURCES}
48+
"Source/App.Win32.cpp"
49+
"Source/RenderDoc.h"
50+
"Source/RenderDoc.cpp")
51+
set(ADDITIONAL_COMPILE_DEFINITIONS ${ADDITIONAL_COMPILE_DEFINITIONS} PRIVATE HAS_RENDERDOC)
4752
endif()
4853

4954
add_executable(UnitTests ${BABYLONJS_ASSETS} ${BABYLONJS_MATERIALS_ASSETS} ${TEST_ASSETS} ${SOURCES})
@@ -65,6 +70,10 @@ target_link_libraries(UnitTests
6570

6671
target_compile_definitions(UnitTests PRIVATE ${ADDITIONAL_COMPILE_DEFINITIONS})
6772

73+
if(GRAPHICS_API STREQUAL "D3D12")
74+
target_compile_definitions(UnitTests PRIVATE SKIP_RENDER_TESTS)
75+
endif()
76+
6877
add_test(NAME UnitTests COMMAND UnitTests)
6978

7079
# See https://gitlab.kitware.com/cmake/cmake/-/issues/23543

0 commit comments

Comments
 (0)