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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixel(Un)PackData with None #326

Merged
merged 1 commit into from
Nov 11, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading