mirror of
https://github.com/godotengine/godot.git
synced 2025-10-26 11:14:17 +00:00
Add JavaScriptBridge buffer methods
This commit is contained in:
parent
99a7a9ccd6
commit
a9b934b657
5 changed files with 81 additions and 0 deletions
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue