Skip to content

Commit

Permalink
Pixel(Un)PackData with None
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
  • Loading branch information
sagudev committed Oct 26, 2024
1 parent fe002d3 commit 1378d85
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ pub struct DebugMessageLogEntry {

pub enum PixelPackData<'a> {
BufferOffset(u32),
Slice(&'a mut [u8]),
Slice(Option<&'a mut [u8]>),
}

pub enum PixelUnpackData<'a> {
BufferOffset(u32),
Slice(&'a [u8]),
Slice(Option<&'a [u8]>),
}

pub enum CompressedPixelUnpackData<'a> {
Expand Down
21 changes: 14 additions & 7 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ impl HasContext for Context {
ty,
match pixels {
PixelPackData::BufferOffset(offset) => offset as *mut std::ffi::c_void,
PixelPackData::Slice(data) => data.as_mut_ptr() as *mut std::ffi::c_void,
PixelPackData::Slice(Some(data)) => data.as_mut_ptr() as *mut std::ffi::c_void,
PixelPackData::Slice(None) => ptr::null_mut(),
},
);
}
Expand Down Expand Up @@ -2526,7 +2527,8 @@ impl HasContext for Context {
ty,
match pixels {
PixelUnpackData::BufferOffset(offset) => offset as *const std::ffi::c_void,
PixelUnpackData::Slice(data) => data.as_ptr() as *const std::ffi::c_void,
PixelUnpackData::Slice(Some(data)) => data.as_ptr() as *const std::ffi::c_void,
PixelUnpackData::Slice(None) => ptr::null(),
},
);
}
Expand Down Expand Up @@ -3279,7 +3281,8 @@ impl HasContext for Context {
ty,
match pixels {
PixelUnpackData::BufferOffset(offset) => offset as *const std::ffi::c_void,
PixelUnpackData::Slice(data) => data.as_ptr() as *const std::ffi::c_void,
PixelUnpackData::Slice(Some(data)) => data.as_ptr() as *const std::ffi::c_void,
PixelUnpackData::Slice(None) => ptr::null(),
},
);
}
Expand Down Expand Up @@ -3308,7 +3311,8 @@ impl HasContext for Context {
ty,
match pixels {
PixelUnpackData::BufferOffset(offset) => offset as *const std::ffi::c_void,
PixelUnpackData::Slice(data) => data.as_ptr() as *const std::ffi::c_void,
PixelUnpackData::Slice(Some(data)) => data.as_ptr() as *const std::ffi::c_void,
PixelUnpackData::Slice(None) => ptr::null(),
},
);
}
Expand Down Expand Up @@ -3368,7 +3372,8 @@ impl HasContext for Context {
ty,
match pixels {
PixelUnpackData::BufferOffset(offset) => offset as *const std::ffi::c_void,
PixelUnpackData::Slice(data) => data.as_ptr() as *const std::ffi::c_void,
PixelUnpackData::Slice(Some(data)) => data.as_ptr() as *const std::ffi::c_void,
PixelUnpackData::Slice(None) => ptr::null(),
},
);
}
Expand Down Expand Up @@ -3401,7 +3406,8 @@ impl HasContext for Context {
ty,
match pixels {
PixelUnpackData::BufferOffset(offset) => offset as *const std::ffi::c_void,
PixelUnpackData::Slice(data) => data.as_ptr() as *const std::ffi::c_void,
PixelUnpackData::Slice(Some(data)) => data.as_ptr() as *const std::ffi::c_void,
PixelUnpackData::Slice(None) => ptr::null(),
},
);
}
Expand Down Expand Up @@ -4156,7 +4162,8 @@ impl HasContext for Context {
gltype,
match pixels {
PixelPackData::BufferOffset(offset) => offset as *mut std::ffi::c_void,
PixelPackData::Slice(data) => data.as_mut_ptr() as *mut std::ffi::c_void,
PixelPackData::Slice(Some(data)) => data.as_mut_ptr() as *mut std::ffi::c_void,
PixelPackData::Slice(None) => ptr::null_mut(),
},
);
}
Expand Down
30 changes: 15 additions & 15 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3995,7 +3995,7 @@ impl HasContext for Context {
match pixels {
PixelUnpackData::BufferOffset(_offset) => panic!("Tex image 2D with offset is not supported"),
PixelUnpackData::Slice(data) => {
let data = texture_data_view(ty, data);
let data = data.map(|data| texture_data_view(ty, data));
gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_array_buffer_view(
target,
level,
Expand All @@ -4005,7 +4005,7 @@ impl HasContext for Context {
border,
format,
ty,
Some(&data),
data.as_ref(),
)
}
}
Expand All @@ -4026,7 +4026,7 @@ impl HasContext for Context {
offset as i32,
),
PixelUnpackData::Slice(data) => {
let data = texture_data_view(ty, data);
let data = data.map(|data| texture_data_view(ty, data));
gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_array_buffer_view(
target,
level,
Expand All @@ -4036,7 +4036,7 @@ impl HasContext for Context {
border,
format,
ty,
Some(&data),
data.as_ref(),
)
}
}
Expand Down Expand Up @@ -4903,9 +4903,9 @@ impl HasContext for Context {
panic!("Sub image 2D pixel buffer offset is not supported");
}
PixelUnpackData::Slice(data) => {
let data = texture_data_view(ty, data);
let data = data.map(|data| texture_data_view(ty, data));
gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_array_buffer_view(
target, level, x_offset, y_offset, width, height, format, ty, Some(&data),
target, level, x_offset, y_offset, width, height, format, ty, data.as_ref(),
)
}
}
Expand All @@ -4926,9 +4926,9 @@ impl HasContext for Context {
offset as i32,
),
PixelUnpackData::Slice(data) => {
let data = texture_data_view(ty, data);
let data = data.map(|data| texture_data_view(ty, data));
gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_array_buffer_view(
target, level, x_offset, y_offset, width, height, format, ty, Some(&data),
target, level, x_offset, y_offset, width, height, format, ty, data.as_ref()
)
}
}
Expand Down Expand Up @@ -5048,8 +5048,8 @@ impl HasContext for Context {
ty,
offset as i32,
),
PixelUnpackData::Slice(slice) => {
let slice = texture_data_view(ty, slice);
PixelUnpackData::Slice(data) => {
let data = data.map(|data| texture_data_view(ty, data));
gl.tex_sub_image_3d_with_opt_array_buffer_view(
target,
level,
Expand All @@ -5061,7 +5061,7 @@ impl HasContext for Context {
depth,
format,
ty,
Some(&slice),
data.as_ref(),
)
}
}
Expand Down Expand Up @@ -5720,8 +5720,8 @@ impl HasContext for Context {
.read_pixels_with_i32(x, y, width, height, format, gltype, offset as i32)
.unwrap(),
},
PixelPackData::Slice(bytes) => {
let data = texture_data_view(gltype, bytes);
PixelPackData::Slice(data) => {
let data = data.map(|data| texture_data_view(gltype, data));
match self.raw {
RawRenderingContext::WebGl1(ref gl) => gl
.read_pixels_with_opt_array_buffer_view(
Expand All @@ -5731,7 +5731,7 @@ impl HasContext for Context {
height,
format,
gltype,
Some(&data),
data.as_ref(),
)
.unwrap(),
RawRenderingContext::WebGl2(ref gl) => gl
Expand All @@ -5742,7 +5742,7 @@ impl HasContext for Context {
height,
format,
gltype,
Some(&data),
data.as_ref(),
)
.unwrap(),
}
Expand Down

0 comments on commit 1378d85

Please sign in to comment.