From b8f4020f38ca0d14bc0afb09677c62360a3c30a7 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Fri, 1 Nov 2024 19:00:16 +0100 Subject: [PATCH] Use PixelUnpackData for tex_image_3d Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- src/lib.rs | 2 +- src/native.rs | 7 +++++-- src/web_sys.rs | 47 +++++++++++++++++++++++++++++++---------------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0cd2514..f7bf75d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1130,7 +1130,7 @@ pub trait HasContext: __private::Sealed { border: i32, format: u32, ty: u32, - pixels: Option<&[u8]>, + pixels: PixelUnpackData, ); unsafe fn compressed_tex_image_3d( diff --git a/src/native.rs b/src/native.rs index dd487d9..1218af2 100644 --- a/src/native.rs +++ b/src/native.rs @@ -2559,7 +2559,7 @@ impl HasContext for Context { border: i32, format: u32, ty: u32, - pixels: Option<&[u8]>, + pixels: PixelUnpackData, ) { let gl = &self.raw; gl.TexImage3D( @@ -2572,7 +2572,10 @@ impl HasContext for Context { border, format, ty, - pixels.map(|p| p.as_ptr()).unwrap_or(std::ptr::null()) as *const std::ffi::c_void, + match pixels { + PixelUnpackData::BufferOffset(offset) => offset as *const std::ffi::c_void, + PixelUnpackData::Slice(data) => data.as_ptr() as *const std::ffi::c_void, + }, ); } diff --git a/src/web_sys.rs b/src/web_sys.rs index d8c138b..9e74283 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -4084,26 +4084,41 @@ impl HasContext for Context { border: i32, format: u32, ty: u32, - pixels: Option<&[u8]>, + pixels: PixelUnpackData, ) { match self.raw { RawRenderingContext::WebGl1(ref _gl) => panic!("3d textures are not supported"), RawRenderingContext::WebGl2(ref gl) => { - let pixels = pixels.map(|bytes| texture_data_view(ty, bytes)); - // TODO: Handle return value? - gl.tex_image_3d_with_opt_array_buffer_view( - target, - level, - internal_format, - width, - height, - depth, - border, - format, - ty, - pixels.as_ref(), - ) - .unwrap(); + match pixels { + PixelUnpackData::BufferOffset(offset) => gl.tex_image_3d_with_i32( + target, + level, + internal_format, + width, + height, + border, + depth, + format, + ty, + offset as i32, + ), + PixelUnpackData::Slice(data) => { + let data = texture_data_view(ty, data); + gl.tex_image_3d_with_opt_array_buffer_view( + target, + level, + internal_format, + width, + height, + border, + depth, + format, + ty, + Some(&data), + ) + } + } + .unwrap(); // TODO: Handle return value? } } }