Merge pull request #68292 from Faless/web/4.x_editor_fixes
[Web] Fix shutdown, force WebGL2, fix editor run args.
This commit is contained in:
commit
13f1d80960
4 changed files with 34 additions and 36 deletions
|
@ -57,8 +57,11 @@ Error EditorRun::run(const String &p_scene, const String &p_write_movie) {
|
||||||
args.push_back(resource_path.replace(" ", "%20"));
|
args.push_back(resource_path.replace(" ", "%20"));
|
||||||
}
|
}
|
||||||
|
|
||||||
args.push_back("--remote-debug");
|
const String debug_uri = EditorDebuggerNode::get_singleton()->get_server_uri();
|
||||||
args.push_back(EditorDebuggerNode::get_singleton()->get_server_uri());
|
if (debug_uri.size()) {
|
||||||
|
args.push_back("--remote-debug");
|
||||||
|
args.push_back(debug_uri);
|
||||||
|
}
|
||||||
|
|
||||||
args.push_back("--editor-pid");
|
args.push_back("--editor-pid");
|
||||||
args.push_back(itos(OS::get_singleton()->get_process_id()));
|
args.push_back(itos(OS::get_singleton()->get_process_id()));
|
||||||
|
|
|
@ -758,10 +758,8 @@ DisplayServerWeb::DisplayServerWeb(const String &p_rendering_driver, WindowMode
|
||||||
godot_js_os_request_quit_cb(request_quit_callback);
|
godot_js_os_request_quit_cb(request_quit_callback);
|
||||||
|
|
||||||
#ifdef GLES3_ENABLED
|
#ifdef GLES3_ENABLED
|
||||||
// TODO "vulkan" defaults to webgl2 for now.
|
bool webgl2_inited = false;
|
||||||
bool wants_webgl2 = p_rendering_driver == "opengl3" || p_rendering_driver == "vulkan";
|
if (godot_js_display_has_webgl(2)) {
|
||||||
bool webgl2_init_failed = wants_webgl2 && !godot_js_display_has_webgl(2);
|
|
||||||
if (wants_webgl2 && !webgl2_init_failed) {
|
|
||||||
EmscriptenWebGLContextAttributes attributes;
|
EmscriptenWebGLContextAttributes attributes;
|
||||||
emscripten_webgl_init_context_attributes(&attributes);
|
emscripten_webgl_init_context_attributes(&attributes);
|
||||||
attributes.alpha = OS::get_singleton()->is_layered_allowed();
|
attributes.alpha = OS::get_singleton()->is_layered_allowed();
|
||||||
|
@ -770,20 +768,17 @@ DisplayServerWeb::DisplayServerWeb(const String &p_rendering_driver, WindowMode
|
||||||
attributes.explicitSwapControl = true;
|
attributes.explicitSwapControl = true;
|
||||||
|
|
||||||
webgl_ctx = emscripten_webgl_create_context(canvas_id, &attributes);
|
webgl_ctx = emscripten_webgl_create_context(canvas_id, &attributes);
|
||||||
if (emscripten_webgl_make_context_current(webgl_ctx) != EMSCRIPTEN_RESULT_SUCCESS) {
|
webgl2_inited = webgl_ctx && emscripten_webgl_make_context_current(webgl_ctx) == EMSCRIPTEN_RESULT_SUCCESS;
|
||||||
webgl2_init_failed = true;
|
|
||||||
} else {
|
|
||||||
if (!emscripten_webgl_enable_extension(webgl_ctx, "OVR_multiview2")) {
|
|
||||||
// @todo Should we log this?
|
|
||||||
}
|
|
||||||
RasterizerGLES3::make_current();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (webgl2_init_failed) {
|
if (webgl2_inited) {
|
||||||
|
if (!emscripten_webgl_enable_extension(webgl_ctx, "OVR_multiview2")) {
|
||||||
|
print_verbose("Failed to enable WebXR extension.");
|
||||||
|
}
|
||||||
|
RasterizerGLES3::make_current();
|
||||||
|
|
||||||
|
} else {
|
||||||
OS::get_singleton()->alert("Your browser does not seem to support WebGL2. Please update your browser version.",
|
OS::get_singleton()->alert("Your browser does not seem to support WebGL2. Please update your browser version.",
|
||||||
"Unable to initialize video driver");
|
"Unable to initialize video driver");
|
||||||
}
|
|
||||||
if (!wants_webgl2 || webgl2_init_failed) {
|
|
||||||
RasterizerDummy::make_current();
|
RasterizerDummy::make_current();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -275,7 +275,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
|
||||||
'print': this.onPrint,
|
'print': this.onPrint,
|
||||||
'printErr': this.onPrintError,
|
'printErr': this.onPrintError,
|
||||||
'thisProgram': this.executable,
|
'thisProgram': this.executable,
|
||||||
'noExitRuntime': true,
|
'noExitRuntime': false,
|
||||||
'dynamicLibraries': [`${loadPath}.side.wasm`],
|
'dynamicLibraries': [`${loadPath}.side.wasm`],
|
||||||
'instantiateWasm': function (imports, onSuccess) {
|
'instantiateWasm': function (imports, onSuccess) {
|
||||||
function done(result) {
|
function done(result) {
|
||||||
|
|
|
@ -41,30 +41,25 @@
|
||||||
|
|
||||||
static OS_Web *os = nullptr;
|
static OS_Web *os = nullptr;
|
||||||
static uint64_t target_ticks = 0;
|
static uint64_t target_ticks = 0;
|
||||||
|
static bool main_started = false;
|
||||||
|
static bool shutdown_complete = false;
|
||||||
|
|
||||||
void exit_callback() {
|
void exit_callback() {
|
||||||
emscripten_cancel_main_loop(); // After this, we can exit!
|
if (!shutdown_complete) {
|
||||||
Main::cleanup();
|
return; // Still waiting.
|
||||||
|
}
|
||||||
|
if (main_started) {
|
||||||
|
Main::cleanup();
|
||||||
|
main_started = false;
|
||||||
|
}
|
||||||
int exit_code = OS_Web::get_singleton()->get_exit_code();
|
int exit_code = OS_Web::get_singleton()->get_exit_code();
|
||||||
memdelete(os);
|
memdelete(os);
|
||||||
os = nullptr;
|
os = nullptr;
|
||||||
emscripten_force_exit(exit_code); // No matter that we call cancel_main_loop, regular "exit" will not work, forcing.
|
emscripten_force_exit(exit_code); // Exit runtime.
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup_after_sync() {
|
void cleanup_after_sync() {
|
||||||
emscripten_set_main_loop(exit_callback, -1, false);
|
shutdown_complete = true;
|
||||||
}
|
|
||||||
|
|
||||||
void early_cleanup() {
|
|
||||||
emscripten_cancel_main_loop(); // After this, we can exit!
|
|
||||||
int exit_code = OS_Web::get_singleton()->get_exit_code();
|
|
||||||
memdelete(os);
|
|
||||||
os = nullptr;
|
|
||||||
emscripten_force_exit(exit_code); // No matter that we call cancel_main_loop, regular "exit" will not work, forcing.
|
|
||||||
}
|
|
||||||
|
|
||||||
void early_cleanup_sync() {
|
|
||||||
emscripten_set_main_loop(early_cleanup, -1, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_loop_callback() {
|
void main_loop_callback() {
|
||||||
|
@ -87,7 +82,8 @@ void main_loop_callback() {
|
||||||
target_ticks += (uint64_t)(1000000 / max_fps);
|
target_ticks += (uint64_t)(1000000 / max_fps);
|
||||||
}
|
}
|
||||||
if (os->main_loop_iterate()) {
|
if (os->main_loop_iterate()) {
|
||||||
emscripten_cancel_main_loop(); // Cancel current loop and wait for cleanup_after_sync.
|
emscripten_cancel_main_loop(); // Cancel current loop and set the cleanup one.
|
||||||
|
emscripten_set_main_loop(exit_callback, -1, false);
|
||||||
godot_js_os_finish_async(cleanup_after_sync);
|
godot_js_os_finish_async(cleanup_after_sync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,10 +105,14 @@ extern EMSCRIPTEN_KEEPALIVE int godot_web_main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
os->set_exit_code(exit_code);
|
os->set_exit_code(exit_code);
|
||||||
// Will only exit after sync.
|
// Will only exit after sync.
|
||||||
godot_js_os_finish_async(early_cleanup_sync);
|
emscripten_set_main_loop(exit_callback, -1, false);
|
||||||
|
godot_js_os_finish_async(cleanup_after_sync);
|
||||||
return exit_code;
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os->set_exit_code(0);
|
||||||
|
main_started = true;
|
||||||
|
|
||||||
// Ease up compatibility.
|
// Ease up compatibility.
|
||||||
ResourceLoader::set_abort_on_missing_resources(false);
|
ResourceLoader::set_abort_on_missing_resources(false);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue