Skip to content

Commit

Permalink
Merge #220
Browse files Browse the repository at this point in the history
220: Add a `framebuffer_texture_multiview_ovr` function to the web-sys context r=grovesNL a=expenses

Required for multiview rendering. See also: gfx-rs/naga#1933 and rustwasm/wasm-bindgen#2903.

Registry link: https://www.khronos.org/registry/webgl/extensions/OVR_multiview2/
MDN link: https://developer.mozilla.org/en-US/docs/Web/API/OVR_multiview2

~~Blocked until a new wasm-bindgen release.~~

Co-authored-by: Ashley Ruglys <ashley.ruglys@gmail.com>
  • Loading branch information
bors[bot] and expenses authored Jul 15, 2022
2 parents f004530 + 91bc259 commit d88346c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ wasm-bindgen = "~0.2"
slotmap = "1"

[target.'cfg(target_arch = "wasm32")'.dependencies.web_sys]
version = "~0.3.37"
version = "~0.3.58"
package = "web-sys"
features = [
"Document",
Expand Down Expand Up @@ -93,6 +93,7 @@ features = [
"WebglDepthTexture",
"WebglDrawBuffers",
"WebglLoseContext",
"OvrMultiview2",
]

[workspace]
Expand Down
34 changes: 32 additions & 2 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct Extensions {
pub oes_texture_half_float: Option<web_sys::OesTextureHalfFloat>,
pub oes_texture_half_float_linear: Option<web_sys::OesTextureHalfFloatLinear>,
pub oes_vertex_array_object: Option<web_sys::OesVertexArrayObject>,
pub ovr_multiview2: Option<()>,
pub ovr_multiview2: Option<web_sys::OvrMultiview2>,
pub webgl_color_buffer_float: Option<web_sys::WebglColorBufferFloat>,
pub webgl_compressed_texture_astc: Option<web_sys::WebglCompressedTextureAstc>,
pub webgl_compressed_texture_etc: Option<web_sys::WebglCompressedTextureEtc>,
Expand Down Expand Up @@ -182,7 +182,7 @@ macro_rules! build_extensions {
&$context,
"OES_vertex_array_object",
),
ovr_multiview2: get_extension_no_object(&$context, "OVR_multiview2"),
ovr_multiview2: get_extension::<web_sys::OvrMultiview2>(&$context, "OVR_multiview2"),
webgl_color_buffer_float: get_extension::<web_sys::WebglColorBufferFloat>(
&$context,
"WEBGL_color_buffer_float",
Expand Down Expand Up @@ -707,6 +707,36 @@ impl Context {
}
}

pub unsafe fn framebuffer_texture_multiview_ovr(
&self,
target: u32,
attachment: u32,
texture: Option<<Self as HasContext>::Texture>,
level: i32,
base_view_index: i32,
num_views: i32,
) {
let textures = self.textures.borrow();
let raw_texture = texture.map(|t| textures.get_unchecked(t));
match self.raw {
RawRenderingContext::WebGl1(ref _gl) => {
panic!("OVR_multiview2 is not supported in WebGL1")
}
RawRenderingContext::WebGl2(ref _gl) => {
if let Some(ext) = &self.extensions.ovr_multiview2 {
ext.framebuffer_texture_multiview_ovr(
target,
attachment,
raw_texture,
level,
base_view_index,
num_views,
);
}
}
}
}

pub unsafe fn bind_external_framebuffer(&self, target: u32, framebuffer: &WebGlFramebuffer) {
match self.raw {
RawRenderingContext::WebGl1(ref gl) => gl.bind_framebuffer(target, Some(framebuffer)),
Expand Down

0 comments on commit d88346c

Please sign in to comment.