Skip to content
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

Add a framebuffer_texture_multiview_ovr function to the web-sys context #220

Merged
merged 6 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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