-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native JS Float32Array binding to Vec<f32> #968
Comments
This came up in #965, the buffer creation could be improved but js_sys is missing the necessary 3-parameter typed array constructor. We should be able to do something like let vert_array = js_sys::Float32Array::new_with_offset_and_length(&memory_buffer, vertices.as_ptr() as u32, vertices.len() as u32); which creates a view of wasm memory without copying it. |
Thanks for the report! The first snippet here is using I've submitted #970 to bind more constructors to make it a bit moer ergonomic in this case. |
@alexcrichton Thank for this fast update! But I haven't spotted a f32 Array in your code commit. Is this up to come, or did I miss something here? |
Oops I left those out by accident! So many arrays to update... |
Thanks for doing this :) |
Hey, I tried the changes in my crate and change to the actual GitHub master branch. But was-bingen fails with the following message: Has anyone experienced the same? I would like to validate the code change from Alex and close this issue. Thanks, |
When you're using the git version of
|
Okay guys, I go it and the code is now the following: let vertices: [f32; 9] = [-0.7, -0.7, 0.0, 0.7, -0.7, 0.0, 0.0, 0.7, 0.0];
let memory_buffer = wasm_bindgen::memory().dyn_into::<WebAssembly::Memory>().unwrap().buffer();
let vert_array = js_sys::Float32Array::new_with_byte_offset(&memory_buffer, vertices.as_ptr() as u32); In my opinion we should make this even easier, like the following: let vert_array = js_sys::Float32Array::new_from_array(&vertices); What do you think? |
Hi alex, I think #811 is the other way around, but yes I'm with you. |
Hi,
first of all thank you for the great crate!
I actually deep dive into the WebGL2 bindings and in the documentation the following way to get Values to native Float32Array is mentioned:
I have the feeling, that the data is cloned twice here?
Additionally this syntax and conversion is really confusing, especially because JS is already handling a native f32.
Is there a way to improve?
If I can get some high level guidance, I would also try to implement it on my own.
Thanks,
Robert
The text was updated successfully, but these errors were encountered: