rustwasm / wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript
https://rustwasm.github.io/docs/wasm-bindgen/
Apache License 2.0
7.74k stars 1.07k forks source link

Handing 'opaque' framebuffers in WebXR #2864

Open expenses opened 2 years ago

expenses commented 2 years ago

So the WebXR spec has these 'opaque' framebuffers that you're meant to bind in WebGL:

https://developer.mozilla.org/en-US/docs/Web/API/XRWebGLLayer/framebuffer

It turns out that what 'opaque' means in this context is that the .framebuffer property will just straight-up report itself as null, yet is still bindable with gl.bindFramebuffer. This means that the XrWebGlLayer.framebuffer getter is always going to be None.

We need to come up with a work-around for this.

expenses commented 2 years ago

I've been using the changes in https://github.com/rustwasm/wasm-bindgen/pull/2863 for a while now and changing it from -> Option<WebGlFramebuffer> to -> WebGlFramebuffer has worked fine. We need a good way to override the generated function signature though.

expenses commented 2 years ago

This is still a problem, but can easily be worked around with:

let base_layer: web_sys::XrWebGlLayer = ...;
let framebuffer: web_sys::WebGlFramebuffer = js_sys::Reflect::get(&base_layer, &"framebuffer".into()).unwrap().into();