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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web] add tex_image_* fns for VideoFrame #227

Merged
merged 1 commit into from
Sep 20, 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.
Jump to
Jump to file
Failed to load files.
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.58"
version = "~0.3.60"
package = "web-sys"
features = [
"Document",
Expand All @@ -48,6 +48,7 @@ features = [
"HtmlImageElement",
"HtmlVideoElement",
"ImageBitmap",
"VideoFrame",
"WebGlActiveInfo",
"WebGlBuffer",
"WebGlFramebuffer",
Expand Down
152 changes: 152 additions & 0 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use web_sys::{
WebGlUniformLocation, WebGlVertexArrayObject,
};

#[cfg(web_sys_unstable_apis)]
use web_sys::VideoFrame;

#[derive(Debug)]
enum RawRenderingContext {
WebGl1(WebGlRenderingContext),
Expand Down Expand Up @@ -303,6 +306,8 @@ impl Context {
// - image_bitmap
// - html_canvas
// - html_image
// - html_video
// - video_frame

pub unsafe fn tex_image_2d_with_image_bitmap(
&self,
Expand Down Expand Up @@ -452,6 +457,44 @@ impl Context {
}
}

#[cfg(web_sys_unstable_apis)]
pub unsafe fn tex_image_2d_with_video_frame(
&self,
target: u32,
level: i32,
internal_format: i32,
format: u32,
ty: u32,
video_frame: &VideoFrame,
) {
match self.raw {
RawRenderingContext::WebGl1(ref gl) => {
// TODO: Handle return value?
gl.tex_image_2d_with_u32_and_u32_and_video_frame(
target,
level,
internal_format,
format,
ty,
video_frame,
)
.unwrap();
}
RawRenderingContext::WebGl2(ref gl) => {
// TODO: Handle return value?
gl.tex_image_2d_with_u32_and_u32_and_video_frame(
target,
level,
internal_format,
format,
ty,
video_frame,
)
.unwrap();
}
}
}

pub unsafe fn tex_sub_image_2d_with_image_bitmap(
&self,
target: u32,
Expand Down Expand Up @@ -530,6 +573,45 @@ impl Context {
}
}

#[cfg(web_sys_unstable_apis)]
pub unsafe fn tex_sub_image_2d_with_video_frame(
&self,
target: u32,
level: i32,
x_offset: i32,
y_offset: i32,
format: u32,
ty: u32,
video_frame: &VideoFrame,
) {
match self.raw {
RawRenderingContext::WebGl1(ref gl) => {
gl.tex_sub_image_2d_with_u32_and_u32_and_video_frame(
target,
level,
x_offset,
y_offset,
format,
ty,
video_frame,
)
.unwrap(); // TODO: Handle return value?
}
RawRenderingContext::WebGl2(ref gl) => {
gl.tex_sub_image_2d_with_u32_and_u32_and_video_frame(
target,
level,
x_offset,
y_offset,
format,
ty,
video_frame,
)
.unwrap(); // TODO: Handle return value?
}
}
}

pub unsafe fn tex_image_3d_with_image_bitmap(
&self,
target: u32,
Expand Down Expand Up @@ -629,6 +711,40 @@ impl Context {
}
}

#[cfg(web_sys_unstable_apis)]
pub unsafe fn tex_image_3d_with_video_frame(
&self,
target: u32,
level: i32,
internal_format: i32,
width: i32,
height: i32,
depth: i32,
border: i32,
format: u32,
ty: u32,
video_frame: &VideoFrame,
) {
match self.raw {
RawRenderingContext::WebGl1(_) => panic!("3D images not supported"),
RawRenderingContext::WebGl2(ref gl) => {
gl.tex_image_3d_with_video_frame(
target,
level,
internal_format,
width,
height,
depth,
border,
format,
ty,
video_frame,
)
.unwrap(); // TODO: Handle return value?
}
}
}

pub unsafe fn tex_sub_image_3d_with_image_bitmap(
&self,
target: u32,
Expand Down Expand Up @@ -707,6 +823,42 @@ impl Context {
}
}

#[cfg(web_sys_unstable_apis)]
pub unsafe fn tex_sub_image_3d_with_video_frame(
&self,
target: u32,
level: i32,
x_offset: i32,
y_offset: i32,
z_offset: i32,
width: i32,
height: i32,
depth: i32,
format: u32,
ty: u32,
video_frame: &VideoFrame,
) {
match self.raw {
RawRenderingContext::WebGl1(_) => panic!("3D images not supported"),
RawRenderingContext::WebGl2(ref gl) => {
gl.tex_sub_image_3d_with_video_frame(
target,
level,
x_offset,
y_offset,
z_offset,
width,
height,
depth,
format,
ty,
video_frame,
)
.unwrap(); // TODO: Handle return value?
}
}
}

pub unsafe fn framebuffer_texture_multiview_ovr(
&self,
target: u32,
Expand Down