summaryrefslogtreecommitdiffstats
path: root/platform/web/js
diff options
context:
space:
mode:
authorAdam Scott <ascott.ca@gmail.com>2024-08-29 09:50:18 -0400
committerAdam Scott <ascott.ca@gmail.com>2024-09-16 12:13:34 -0400
commita9b934b65754c93e557c9446e7c01af199bd6b40 (patch)
treebd692833c21aef532fcfd96a7d895d8df7052016 /platform/web/js
parent99a7a9ccd60fbe4030e067b3c36d54b67737446d (diff)
downloadredot-engine-a9b934b65754c93e557c9446e7c01af199bd6b40.tar.gz
Add `JavaScriptBridge` buffer methods
Diffstat (limited to 'platform/web/js')
-rw-r--r--platform/web/js/libs/library_godot_javascript_singleton.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/platform/web/js/libs/library_godot_javascript_singleton.js b/platform/web/js/libs/library_godot_javascript_singleton.js
index 6bb69bca95..3ff6abba60 100644
--- a/platform/web/js/libs/library_godot_javascript_singleton.js
+++ b/platform/web/js/libs/library_godot_javascript_singleton.js
@@ -127,6 +127,10 @@ const GodotJSWrapper = {
GodotRuntime.setHeapValue(p_exchange, id, 'i64');
return 24; // OBJECT
},
+
+ isBuffer: function (obj) {
+ return obj instanceof ArrayBuffer || ArrayBuffer.isView(obj);
+ },
},
godot_js_wrapper_interface_get__proxy: 'sync',
@@ -303,6 +307,34 @@ const GodotJSWrapper = {
return -1;
}
},
+
+ godot_js_wrapper_object_is_buffer__proxy: 'sync',
+ godot_js_wrapper_object_is_buffer__sig: 'ii',
+ godot_js_wrapper_object_is_buffer: function (p_id) {
+ const obj = GodotJSWrapper.get_proxied_value(p_id);
+ return GodotJSWrapper.isBuffer(obj)
+ ? 1
+ : 0;
+ },
+
+ godot_js_wrapper_object_transfer_buffer__proxy: 'sync',
+ godot_js_wrapper_object_transfer_buffer__sig: 'viiii',
+ godot_js_wrapper_object_transfer_buffer: function (p_id, p_byte_arr, p_byte_arr_write, p_callback) {
+ let obj = GodotJSWrapper.get_proxied_value(p_id);
+ if (!GodotJSWrapper.isBuffer(obj)) {
+ return;
+ }
+
+ if (ArrayBuffer.isView(obj) && !(obj instanceof Uint8Array)) {
+ obj = new Uint8Array(obj.buffer);
+ } else if (obj instanceof ArrayBuffer) {
+ obj = new Uint8Array(obj);
+ }
+
+ const resizePackedByteArrayAndOpenWrite = GodotRuntime.get_func(p_callback);
+ const bytesPtr = resizePackedByteArrayAndOpenWrite(p_byte_arr, p_byte_arr_write, obj.length);
+ HEAPU8.set(obj, bytesPtr);
+ },
};
autoAddDeps(GodotJSWrapper, '$GodotJSWrapper');