Skip to content

Commit

Permalink
Use PixelUnpackData for tex_image_3d
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Nov 1, 2024
1 parent dd9150b commit b8f4020
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
},
);
}

Expand Down
47 changes: 31 additions & 16 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
}
}
Expand Down

0 comments on commit b8f4020

Please sign in to comment.