From 0ae762a7013f7191296d79dbe9e38f5f1afe095f Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 16 Feb 2021 12:19:17 +0100 Subject: [PATCH 1/3] RasterizerDummy now instances Image(s). Avoid crash on start-up, we will need to slowly re-implement the various methods with dummy objects so exporting works again like in 3.2 --- drivers/dummy/rasterizer_dummy.h | 35 ++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/dummy/rasterizer_dummy.h b/drivers/dummy/rasterizer_dummy.h index 082f2474767..a76520dcdb2 100644 --- a/drivers/dummy/rasterizer_dummy.h +++ b/drivers/dummy/rasterizer_dummy.h @@ -210,8 +210,22 @@ public: bool can_create_resources_async() const override { return false; } /* TEXTURE API */ - RID texture_allocate() override { return RID(); } - void texture_2d_initialize(RID p_texture, const Ref &p_image) override {} + struct DummyTexture { + Ref image; + }; + mutable RID_PtrOwner texture_owner; + + RID texture_allocate() override { + DummyTexture *texture = memnew(DummyTexture); + ERR_FAIL_COND_V(!texture, RID()); + return texture_owner.make_rid(texture); + } + void texture_2d_initialize(RID p_texture, const Ref &p_image) override { + DummyTexture *t = texture_owner.getornull(p_texture); + ERR_FAIL_COND(!t); + t->image = p_image->duplicate(); + } + void texture_2d_layered_initialize(RID p_texture, const Vector> &p_layers, RS::TextureLayeredType p_layered_type) override {} void texture_2d_update_immediate(RID p_texture, const Ref &p_image, int p_layer = 0) override {} void texture_2d_update(RID p_texture, const Ref &p_image, int p_layer = 0) override {} @@ -224,7 +238,12 @@ public: void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override {} void texture_3d_placeholder_initialize(RID p_texture) override {} - Ref texture_2d_get(RID p_texture) const override { return Ref(); } + Ref texture_2d_get(RID p_texture) const override { + DummyTexture *t = texture_owner.getornull(p_texture); + ERR_FAIL_COND_V(!t, Ref()); + return t->image; + } + Ref texture_2d_layer_get(RID p_texture, int p_layer) const override { return Ref(); } Vector> texture_3d_get(RID p_texture) const override { return Vector>(); } @@ -635,7 +654,15 @@ public: Rect2i render_target_get_sdf_rect(RID p_render_target) const override { return Rect2i(); } RS::InstanceType get_base_type(RID p_rid) const override { return RS::INSTANCE_NONE; } - bool free(RID p_rid) override { return true; } + bool free(RID p_rid) override { + if (texture_owner.owns(p_rid)) { + // delete the texture + DummyTexture *texture = texture_owner.getornull(p_rid); + texture_owner.free(p_rid); + memdelete(texture); + } + return true; + } bool has_os_feature(const String &p_feature) const override { return false; } From 1446cfd13dae0e2e938466eddd325d45e1a032b5 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 15 Feb 2021 16:40:44 +0100 Subject: [PATCH 2/3] [HTML5] Fix compilation issues in 4.0 More memory is needed, and a Workaround to avoid undefined symbol due to dead code elimination. --- platform/javascript/detect.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 06f88dc83f8..4297088c09f 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -92,9 +92,9 @@ def configure(env): if not env["threads_enabled"]: print("Threads must be enabled to build the editor. Please add the 'threads_enabled=yes' option") sys.exit(255) - if env["initial_memory"] < 32: - print("Editor build requires at least 32MiB of initial memory. Forcing it.") - env["initial_memory"] = 32 + if env["initial_memory"] < 64: + print("Editor build requires at least 64MiB of initial memory. Forcing it.") + env["initial_memory"] = 64 elif env["builtin_icu"]: env.Append(CCFLAGS=["-frtti"]) else: @@ -233,3 +233,11 @@ def configure(env): # Add code that allow exiting runtime. env.Append(LINKFLAGS=["-s", "EXIT_RUNTIME=1"]) + + # TODO remove once we have GLES support back (temporary fix undefined symbols due to dead code elimination). + env.Append( + LINKFLAGS=[ + "-s", + "EXPORTED_FUNCTIONS=['_main', '_emscripten_webgl_get_current_context', '_emscripten_webgl_commit_frame', '_emscripten_webgl_create_context']", + ] + ) From 26ec6ca576ec91fe3ae52bd647d7d1778ad4716c Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 15 Feb 2021 15:48:06 +0100 Subject: [PATCH 3/3] [HTML5] Implement get_processor_count. --- platform/javascript/godot_js.h | 1 + platform/javascript/js/libs/library_godot_os.js | 5 +++++ platform/javascript/os_javascript.cpp | 4 ++++ platform/javascript/os_javascript.h | 1 + 4 files changed, 11 insertions(+) diff --git a/platform/javascript/godot_js.h b/platform/javascript/godot_js.h index d2a2fbd6db4..f0da8b7ca39 100644 --- a/platform/javascript/godot_js.h +++ b/platform/javascript/godot_js.h @@ -49,6 +49,7 @@ extern int godot_js_os_fs_is_persistent(); extern void godot_js_os_fs_sync(void (*p_callback)()); extern int godot_js_os_execute(const char *p_json); extern void godot_js_os_shell_open(const char *p_uri); +extern int godot_js_os_hw_concurrency_get(); // Display extern int godot_js_display_screen_dpi_get(); diff --git a/platform/javascript/js/libs/library_godot_os.js b/platform/javascript/js/libs/library_godot_os.js index 9fde4a84e1a..3ffcd655b7e 100644 --- a/platform/javascript/js/libs/library_godot_os.js +++ b/platform/javascript/js/libs/library_godot_os.js @@ -282,6 +282,11 @@ const GodotOS = { godot_js_os_shell_open: function (p_uri) { window.open(GodotRuntime.parseString(p_uri), '_blank'); }, + + godot_js_os_hw_concurrency_get__sig: 'i', + godot_js_os_hw_concurrency_get: function () { + return navigator.hardwareConcurrency || 1; + }, }; autoAddDeps(GodotOS, '$GodotOS'); diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index b922b2ba918..0b1650076c1 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -129,6 +129,10 @@ int OS_JavaScript::get_process_id() const { ERR_FAIL_V_MSG(0, "OS::get_process_id() is not available on the HTML5 platform."); } +int OS_JavaScript::get_processor_count() const { + return godot_js_os_hw_concurrency_get(); +} + bool OS_JavaScript::_check_internal_feature_support(const String &p_feature) { if (p_feature == "HTML5" || p_feature == "web") { return true; diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 8db62d9d1cd..81bb9c5f3da 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -74,6 +74,7 @@ public: Error create_process(const String &p_path, const List &p_arguments, ProcessID *r_child_id = nullptr) override; Error kill(const ProcessID &p_pid) override; int get_process_id() const override; + int get_processor_count() const override; String get_executable_path() const override; Error shell_open(String p_uri) override;