From 34fd48f68d3c0e9ca60468ca4befb1a67d57fdf7 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 6 Apr 2021 12:46:33 +0200 Subject: [PATCH] [HTML5] Implement WebGL fallback. According to project settings and when WebGL2 is not available. This does nothing in current master, as we have no rendering yet! --- platform/javascript/godot_js.h | 1 + platform/javascript/js/libs/library_godot_display.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/platform/javascript/godot_js.h b/platform/javascript/godot_js.h index 4448a356702..8927a83cb38 100644 --- a/platform/javascript/godot_js.h +++ b/platform/javascript/godot_js.h @@ -71,6 +71,7 @@ extern int godot_js_display_fullscreen_exit(); extern void godot_js_display_compute_position(int p_x, int p_y, int32_t *r_x, int32_t *r_y); extern void godot_js_display_window_title_set(const char *p_text); extern void godot_js_display_window_icon_set(const uint8_t *p_ptr, int p_len); +extern int godot_js_display_has_webgl(int p_version); // Display clipboard extern int godot_js_display_clipboard_set(const char *p_text); diff --git a/platform/javascript/js/libs/library_godot_display.js b/platform/javascript/js/libs/library_godot_display.js index 00e6a016797..91cab5eacc1 100644 --- a/platform/javascript/js/libs/library_godot_display.js +++ b/platform/javascript/js/libs/library_godot_display.js @@ -719,6 +719,17 @@ const GodotDisplay = { GodotRuntime.setHeapValue(r_y, (y - rect.y) * rh, 'i32'); }, + godot_js_display_has_webgl__sig: 'ii', + godot_js_display_has_webgl: function (p_version) { + if (p_version !== 1 && p_version !== 2) { + return false; + } + try { + return !!document.createElement('canvas').getContext(p_version === 2 ? 'webgl2' : 'webgl'); + } catch (e) { /* Not available */ } + return false; + }, + /* * Canvas */