mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 01:01:34 +00:00
Updating a couple examples
This commit is contained in:
@ -39,12 +39,25 @@ pub fn start() -> Result<(), JsValue> {
|
||||
|
||||
let buffer = context.create_buffer().ok_or("failed to create buffer")?;
|
||||
context.bind_buffer(WebGlRenderingContext::ARRAY_BUFFER, Some(&buffer));
|
||||
let vert_array = unsafe { js_sys::Float32Array::view(&vertices) };
|
||||
context.buffer_data_with_array_buffer_view(
|
||||
WebGlRenderingContext::ARRAY_BUFFER,
|
||||
&vert_array,
|
||||
WebGlRenderingContext::STATIC_DRAW,
|
||||
);
|
||||
|
||||
// Note that `Float32Array::view` is somewhat dangerous (hence the
|
||||
// `unsafe`!). This is creating a raw view into our module's
|
||||
// `WebAssembly.Memory` buffer, but if we allocate more pages for ourself
|
||||
// (aka do a memory allocation in Rust) it'll cause the buffer to change,
|
||||
// causing the `Float32Array` to be invalid.
|
||||
//
|
||||
// As a result, after `Float32Array::view` we have to be very careful not to
|
||||
// do any memory allocations before it's dropped.
|
||||
unsafe {
|
||||
let vert_array = js_sys::Float32Array::view(&vertices);
|
||||
|
||||
context.buffer_data_with_array_buffer_view(
|
||||
WebGlRenderingContext::ARRAY_BUFFER,
|
||||
&vert_array,
|
||||
WebGlRenderingContext::STATIC_DRAW,
|
||||
);
|
||||
}
|
||||
|
||||
context.vertex_attrib_pointer_with_i32(0, 3, WebGlRenderingContext::FLOAT, false, 0, 0);
|
||||
context.enable_vertex_attrib_array(0);
|
||||
|
||||
|
Reference in New Issue
Block a user