Skip to content

Commit ff3eba0

Browse files
committed
Only run AddToContextAsyncAndUpdateWithLayerIndex test in D3D11
1 parent 982314c commit ff3eba0

10 files changed

Lines changed: 89 additions & 79 deletions

Apps/UnitTests/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ set(SOURCES
2121
"Source/Tests.NativeEngine.cpp"
2222
"Source/Tests.ExternalTexture.cpp"
2323
"Source/Utils.h"
24-
"Source/Utils_${GRAPHICS_API}.${BABYLON_NATIVE_PLATFORM_IMPL_EXT}")
24+
"Source/Utils.${GRAPHICS_API}.${BABYLON_NATIVE_PLATFORM_IMPL_EXT}")
25+
26+
if(GRAPHICS_API STREQUAL "D3D11")
27+
set(SOURCES ${SOURCES} "Source/Tests.ExternalTexture.D3D11.cpp")
28+
endif()
2529

2630
if(APPLE)
27-
set(SOURCES ${SOURCES} "Source/App_Apple.mm")
31+
set(SOURCES ${SOURCES} "Source/App.Apple.mm")
2832
if(BABYLON_NATIVE_TESTS_USE_NOOP_METAL_DEVICE)
2933
set(ADDITIONAL_COMPILE_DEFINITIONS
3034
PRIVATE USE_NOOP_METAL_DEVICE
@@ -33,10 +37,10 @@ if(APPLE)
3337
find_library(JAVASCRIPTCORE_LIBRARY JavaScriptCore)
3438
set(ADDITIONAL_LIBRARIES PRIVATE ${JAVASCRIPTCORE_LIBRARY})
3539
elseif(UNIX AND NOT ANDROID)
36-
set(SOURCES ${SOURCES} "Source/App_X11.cpp")
40+
set(SOURCES ${SOURCES} "Source/App.X11.cpp")
3741
set(ADDITIONAL_COMPILE_DEFINITIONS PRIVATE SKIP_EXTERNAL_TEXTURE_TESTS)
3842
elseif(WIN32)
39-
set(SOURCES ${SOURCES} "Source/App_Win32.cpp")
43+
set(SOURCES ${SOURCES} "Source/App.Win32.cpp")
4044
endif()
4145

4246
add_executable(UnitTests ${BABYLONJS_ASSETS} ${BABYLONJS_MATERIALS_ASSETS} ${TEST_ASSETS} ${SOURCES})
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <Babylon/AppRuntime.h>
4+
#include <Babylon/Graphics/Device.h>
5+
#include <Babylon/Polyfills/Console.h>
6+
#include <Babylon/Polyfills/Window.h>
7+
#include <Babylon/Plugins/NativeEngine.h>
8+
#include <Babylon/Plugins/ExternalTexture.h>
9+
10+
#include "Utils.h"
11+
12+
extern Babylon::Graphics::Configuration g_deviceConfig;
13+
14+
TEST(ExternalTexture, AddToContextAsyncAndUpdateWithLayerIndex)
15+
{
16+
#ifdef SKIP_EXTERNAL_TEXTURE_TESTS
17+
GTEST_SKIP();
18+
#else
19+
Babylon::Graphics::Device device{g_deviceConfig};
20+
Babylon::Graphics::DeviceUpdate update{device.GetUpdate("update")};
21+
22+
device.StartRenderingCurrentFrame();
23+
update.Start();
24+
25+
auto nativeTexture = CreateTestTexture(device.GetPlatformInfo().Device, 256, 256, 3);
26+
27+
Babylon::Plugins::ExternalTexture externalTexture{nativeTexture};
28+
29+
std::promise<void> addToContext{};
30+
std::promise<void> promiseResolved{};
31+
32+
Babylon::AppRuntime runtime{};
33+
runtime.Dispatch([&device, &addToContext, &promiseResolved, externalTexture](Napi::Env env) {
34+
device.AddToJavaScript(env);
35+
36+
Babylon::Polyfills::Console::Initialize(env, [](const char* message, auto) {
37+
std::cout << message << std::endl;
38+
});
39+
40+
Babylon::Polyfills::Window::Initialize(env);
41+
42+
Babylon::Plugins::NativeEngine::Initialize(env);
43+
44+
// Test with explicit layer index 1
45+
auto jsPromise = externalTexture.AddToContextAsync(env, 1);
46+
addToContext.set_value();
47+
48+
auto jsOnFulfilled = Napi::Function::New(env, [&promiseResolved](const Napi::CallbackInfo& info) {
49+
promiseResolved.set_value();
50+
});
51+
52+
auto jsOnRejected = Napi::Function::New(env, [&promiseResolved](const Napi::CallbackInfo& info) {
53+
promiseResolved.set_exception(std::make_exception_ptr(info[0].As<Napi::Error>()));
54+
});
55+
56+
jsPromise.Get("then").As<Napi::Function>().Call(jsPromise, {jsOnFulfilled, jsOnRejected});
57+
});
58+
59+
// Wait for AddToContextAsync to be called.
60+
addToContext.get_future().wait();
61+
62+
// Render a frame so that AddToContextAsync will complete.
63+
update.Finish();
64+
device.FinishRenderingCurrentFrame();
65+
66+
// Wait for promise to resolve.
67+
promiseResolved.get_future().wait();
68+
69+
// Start a new frame.
70+
device.StartRenderingCurrentFrame();
71+
update.Start();
72+
73+
// Update the external texture to a new texture with explicit layer index 2.
74+
externalTexture.Update(nativeTexture, std::nullopt, 2);
75+
76+
DestroyTestTexture(nativeTexture);
77+
78+
update.Finish();
79+
device.FinishRenderingCurrentFrame();
80+
#endif
81+
}

Apps/UnitTests/Source/Tests.ExternalTexture.cpp

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@
66
#include <Babylon/Polyfills/Window.h>
77
#include <Babylon/Plugins/NativeEngine.h>
88
#include <Babylon/Plugins/ExternalTexture.h>
9-
#include <Babylon/ScriptLoader.h>
10-
#include <Babylon/ShaderCache.h>
119

1210
#include "Utils.h"
1311

14-
#include <chrono>
15-
#include <future>
16-
#include <iostream>
17-
1812
extern Babylon::Graphics::Configuration g_deviceConfig;
1913

2014
TEST(ExternalTexture, Construction)
@@ -107,72 +101,3 @@ TEST(ExternalTexture, AddToContextAsyncAndUpdate)
107101
device.FinishRenderingCurrentFrame();
108102
#endif
109103
}
110-
111-
TEST(ExternalTexture, AddToContextAsyncAndUpdateWithLayerIndex)
112-
{
113-
#ifdef SKIP_EXTERNAL_TEXTURE_TESTS
114-
GTEST_SKIP();
115-
#else
116-
Babylon::Graphics::Device device{g_deviceConfig};
117-
Babylon::Graphics::DeviceUpdate update{device.GetUpdate("update")};
118-
119-
device.StartRenderingCurrentFrame();
120-
update.Start();
121-
122-
auto nativeTexture = CreateTestTexture(device.GetPlatformInfo().Device, 256, 256, 3);
123-
124-
Babylon::Plugins::ExternalTexture externalTexture{nativeTexture};
125-
126-
std::promise<void> addToContext{};
127-
std::promise<void> promiseResolved{};
128-
129-
Babylon::AppRuntime runtime{};
130-
runtime.Dispatch([&device, &addToContext, &promiseResolved, externalTexture](Napi::Env env) {
131-
device.AddToJavaScript(env);
132-
133-
Babylon::Polyfills::Console::Initialize(env, [](const char* message, auto) {
134-
std::cout << message << std::endl;
135-
});
136-
137-
Babylon::Polyfills::Window::Initialize(env);
138-
139-
Babylon::Plugins::NativeEngine::Initialize(env);
140-
141-
// Test with explicit layer index 1
142-
auto jsPromise = externalTexture.AddToContextAsync(env, 1);
143-
addToContext.set_value();
144-
145-
auto jsOnFulfilled = Napi::Function::New(env, [&promiseResolved](const Napi::CallbackInfo& info) {
146-
promiseResolved.set_value();
147-
});
148-
149-
auto jsOnRejected = Napi::Function::New(env, [&promiseResolved](const Napi::CallbackInfo& info) {
150-
promiseResolved.set_exception(std::make_exception_ptr(info[0].As<Napi::Error>()));
151-
});
152-
153-
jsPromise.Get("then").As<Napi::Function>().Call(jsPromise, {jsOnFulfilled, jsOnRejected});
154-
});
155-
156-
// Wait for AddToContextAsync to be called.
157-
addToContext.get_future().wait();
158-
159-
// Render a frame so that AddToContextAsync will complete.
160-
update.Finish();
161-
device.FinishRenderingCurrentFrame();
162-
163-
// Wait for promise to resolve.
164-
promiseResolved.get_future().wait();
165-
166-
// Start a new frame.
167-
device.StartRenderingCurrentFrame();
168-
update.Start();
169-
170-
// Update the external texture to a new texture with explicit layer index 2.
171-
externalTexture.Update(nativeTexture, std::nullopt, 2);
172-
173-
DestroyTestTexture(nativeTexture);
174-
175-
update.Finish();
176-
device.FinishRenderingCurrentFrame();
177-
#endif
178-
}

0 commit comments

Comments
 (0)