Skip to content

Commit ebf9d70

Browse files
MikhailGorobetsTheMostDiligent
authored andcommitted
Emscripten: Added html pages for tests
1 parent 1c0dade commit ebf9d70

5 files changed

Lines changed: 228 additions & 1 deletion

File tree

Tests/DiligentCoreAPITest/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
cmake_minimum_required (VERSION 3.17)
22

3+
if (PLATFORM_EMSCRIPTEN)
4+
set(CMAKE_EXECUTABLE_SUFFIX ".html")
5+
endif()
6+
37
project(DiligentCoreAPITest)
48

59
file(GLOB COMMON_SOURCE LIST_DIRECTORIES false src/* src/ObjectCreationFailure/*)
@@ -78,6 +82,13 @@ set_common_target_properties(DiligentCoreAPITest)
7882

7983
get_supported_backends(ENGINE_LIBRARIES)
8084

85+
if (PLATFORM_EMSCRIPTEN)
86+
set(RESOURCE_PATH "${PROJECT_SOURCE_DIR}/assets/")
87+
set(HTML_TEMPLATE_FILE ${PROJECT_SOURCE_DIR}/resources/emscripten_template.html)
88+
target_link_options(DiligentCoreAPITest PRIVATE "SHELL: -s SINGLE_FILE -s ALLOW_MEMORY_GROWTH=1 --preload-file '${RESOURCE_PATH}@'")
89+
target_link_options(DiligentCoreAPITest PRIVATE "SHELL: --shell-file '${HTML_TEMPLATE_FILE}'")
90+
endif()
91+
8192
target_link_libraries(DiligentCoreAPITest
8293
PRIVATE
8394
Diligent-BuildSettings
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<!doctype html>
2+
<html lang="en-us">
3+
<head>
4+
<meta charset="utf-8">
5+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@4.19.0/css/xterm.min.css" />
6+
<script src="https://cdn.jsdelivr.net/npm/xterm@4.19.0/lib/xterm.min.js"></script>
7+
<script src="https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.5.0/lib/xterm-addon-fit.min.js"></script>
8+
<title>DiligentCoreAPITest</title>
9+
<style>
10+
html::-webkit-scrollbar,
11+
body::-webkit-scrollbar,
12+
div::-webkit-scrollbar {
13+
display: none;
14+
width: 0;
15+
}
16+
17+
html,
18+
body {
19+
margin: 0;
20+
overflow: hidden;
21+
padding: 0;
22+
}
23+
24+
div#terminal {
25+
height: 100%;
26+
left: 0;
27+
position: absolute;
28+
top: 0;
29+
width: 100%;
30+
}
31+
32+
div#terminal div {
33+
height: 100%;
34+
}
35+
36+
.xterm-viewport,
37+
.xterm-screen {
38+
height: 100%;
39+
margin: 0;
40+
padding: 0;
41+
}
42+
43+
.terminal.xterm {
44+
padding: 8px;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
<div id="terminal"></div>
50+
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
51+
<script type='text/javascript'>
52+
var term = new Terminal({
53+
screenKeys: true,
54+
useStyle: true,
55+
cursorBlink: true,
56+
cursorStyle: 'bar',
57+
fullscreenWin: true,
58+
maximizeWin: true,
59+
screenReaderMode: true,
60+
theme: {
61+
foreground: 'white',
62+
background: '#2A2C34',
63+
cursor: 'help',
64+
lineHeight: 16,
65+
},
66+
});
67+
68+
var fitAddon = new FitAddon.FitAddon();
69+
term.open(document.getElementById('terminal'));
70+
term.loadAddon(fitAddon);
71+
term._initialized = true;
72+
terminal.focus();
73+
fitAddon.fit();
74+
75+
function terminal_write(text) {
76+
text = Array.prototype.slice.call(arguments).join(' ');
77+
term.writeln(text);
78+
};
79+
80+
var argv = [ "--mode=gl" ];
81+
var Module = {
82+
preRun: [],
83+
postRun: [],
84+
arguments: argv,
85+
print: terminal_write,
86+
printErr: terminal_write,
87+
canvas: (function () {
88+
var canvas = document.getElementById('canvas');
89+
canvas.addEventListener("webglcontextlost", function(e) { alert('FIXME: WebGL context lost, please reload the page'); e.preventDefault(); }, false);
90+
return canvas;
91+
})(),
92+
setStatus: function (text) {
93+
console.log("status: " + text);
94+
}
95+
};
96+
window.onerror = function () {
97+
console.log("onerror: " + event);
98+
};
99+
</script>
100+
{{{ SCRIPT }}}
101+
</body>
102+
</html>

Tests/DiligentCoreTest/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
cmake_minimum_required (VERSION 3.6)
22

3+
if (PLATFORM_EMSCRIPTEN)
4+
set(CMAKE_EXECUTABLE_SUFFIX ".html")
5+
endif()
6+
37
project(DiligentCoreTest)
48

59
file(GLOB_RECURSE SOURCE src/*.*)
@@ -19,6 +23,13 @@ endif()
1923
add_executable(DiligentCoreTest ${SOURCE} ${SHADERS})
2024
set_common_target_properties(DiligentCoreTest)
2125

26+
if (PLATFORM_EMSCRIPTEN)
27+
set(RESOURCE_PATH "${PROJECT_SOURCE_DIR}/assets/")
28+
set(HTML_TEMPLATE_FILE ${PROJECT_SOURCE_DIR}/resources/emscripten_template.html)
29+
target_link_options(DiligentCoreTest PRIVATE "SHELL: -s SINGLE_FILE -s ALLOW_MEMORY_GROWTH=1 --preload-file '${RESOURCE_PATH}@'")
30+
target_link_options(DiligentCoreTest PRIVATE "SHELL: --shell-file '${HTML_TEMPLATE_FILE}'")
31+
endif()
32+
2233
target_link_libraries(DiligentCoreTest
2334
PRIVATE
2435
gtest_main
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<!doctype html>
2+
<html lang="en-us">
3+
<head>
4+
<meta charset="utf-8">
5+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@4.19.0/css/xterm.min.css" />
6+
<script src="https://cdn.jsdelivr.net/npm/xterm@4.19.0/lib/xterm.min.js"></script>
7+
<script src="https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.5.0/lib/xterm-addon-fit.min.js"></script>
8+
<title>DiligentCoreTest</title>
9+
<style>
10+
html::-webkit-scrollbar,
11+
body::-webkit-scrollbar,
12+
div::-webkit-scrollbar {
13+
display: none;
14+
width: 0;
15+
}
16+
17+
html,
18+
body {
19+
margin: 0;
20+
overflow: hidden;
21+
padding: 0;
22+
}
23+
24+
div#terminal {
25+
height: 100%;
26+
left: 0;
27+
position: absolute;
28+
top: 0;
29+
width: 100%;
30+
}
31+
32+
div#terminal div {
33+
height: 100%;
34+
}
35+
36+
.xterm-viewport,
37+
.xterm-screen {
38+
height: 100%;
39+
margin: 0;
40+
padding: 0;
41+
}
42+
43+
.terminal.xterm {
44+
padding: 8px;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
<div id="terminal"></div>
50+
<script type='text/javascript'>
51+
var term = new Terminal({
52+
screenKeys: true,
53+
useStyle: true,
54+
cursorBlink: true,
55+
cursorStyle: 'bar',
56+
fullscreenWin: true,
57+
maximizeWin: true,
58+
screenReaderMode: true,
59+
theme: {
60+
foreground: 'white',
61+
background: '#2A2C34',
62+
cursor: 'help',
63+
lineHeight: 16,
64+
},
65+
});
66+
67+
var fitAddon = new FitAddon.FitAddon();
68+
term.open(document.getElementById('terminal'));
69+
term.loadAddon(fitAddon);
70+
term._initialized = true;
71+
terminal.focus();
72+
fitAddon.fit();
73+
74+
function terminal_write(text) {
75+
text = Array.prototype.slice.call(arguments).join(' ');
76+
term.writeln(text);
77+
};
78+
79+
var Module = {
80+
preRun: [],
81+
postRun: [],
82+
print: terminal_write,
83+
printErr: terminal_write,
84+
setStatus: function (text) {
85+
console.log("status: " + text);
86+
}
87+
};
88+
window.onerror = function () {
89+
console.log("onerror: " + event);
90+
};
91+
92+
window.onresize = function () {
93+
fitAddon.fit();
94+
};
95+
96+
</script>
97+
{{{ SCRIPT }}}
98+
</body>
99+
</html>

Tests/GPUTestFramework/src/GPUTestingEnvironment.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -886,7 +886,11 @@ GPUTestingEnvironment* GPUTestingEnvironment::Initialize(int argc, char** argv)
886886
}
887887
else if (strcmp(arg, "--mode=gl") == 0)
888888
{
889+
#if PLATFORM_EMSCRIPTEN || PLATFORM_ANDROID
890+
TestEnvCI.deviceType = RENDER_DEVICE_TYPE_GLES;
891+
#else
889892
TestEnvCI.deviceType = RENDER_DEVICE_TYPE_GL;
893+
#endif
890894
}
891895
else if (strcmp(arg, "--mode=mtl") == 0)
892896
{

0 commit comments

Comments
 (0)