Skip to content

Commit

Permalink
Pixel(Un)PackData with None (#326)
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 authored Nov 11, 2024
1 parent 0e058af commit cf08bc4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 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
27 changes: 18 additions & 9 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,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 @@ -2507,7 +2508,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 @@ -2558,7 +2560,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 @@ -2633,7 +2636,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 @@ -3314,7 +3318,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 @@ -3343,7 +3348,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 @@ -3403,7 +3409,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 @@ -3436,7 +3443,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 @@ -4191,7 +4199,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
34 changes: 17 additions & 17 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 @@ -4123,7 +4123,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_3d_with_opt_array_buffer_view(
target,
level,
Expand All @@ -4134,7 +4134,7 @@ impl HasContext for Context {
depth,
format,
ty,
Some(&data),
data.as_ref(),
)
}
}
Expand Down Expand Up @@ -4918,9 +4918,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 @@ -4941,9 +4941,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 @@ -5063,8 +5063,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 @@ -5076,7 +5076,7 @@ impl HasContext for Context {
depth,
format,
ty,
Some(&slice),
data.as_ref(),
)
}
}
Expand Down Expand Up @@ -5735,8 +5735,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 @@ -5746,7 +5746,7 @@ impl HasContext for Context {
height,
format,
gltype,
Some(&data),
data.as_ref(),
)
.unwrap(),
RawRenderingContext::WebGl2(ref gl) => gl
Expand All @@ -5757,7 +5757,7 @@ impl HasContext for Context {
height,
format,
gltype,
Some(&data),
data.as_ref(),
)
.unwrap(),
}
Expand Down

0 comments on commit cf08bc4

Please sign in to comment.