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

Use PixelUnpackData in tex_image_{1,2,3}d #322

Merged
merged 3 commits into from
Nov 5, 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
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ pub trait HasContext: __private::Sealed {
border: i32,
format: u32,
ty: u32,
pixels: Option<&[u8]>,
pixels: PixelUnpackData,
);

unsafe fn compressed_tex_image_1d(
Expand All @@ -1094,7 +1094,7 @@ pub trait HasContext: __private::Sealed {
border: i32,
format: u32,
ty: u32,
pixels: Option<&[u8]>,
pixels: PixelUnpackData,
);

unsafe fn tex_image_2d_multisample(
Expand Down 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
21 changes: 15 additions & 6 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2435,7 +2435,7 @@ impl HasContext for Context {
border: i32,
format: u32,
ty: u32,
pixels: Option<&[u8]>,
pixels: PixelUnpackData,
) {
let gl = &self.raw;
gl.TexImage1D(
Expand All @@ -2446,7 +2446,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 Expand Up @@ -2482,7 +2485,7 @@ impl HasContext for Context {
border: i32,
format: u32,
ty: u32,
pixels: Option<&[u8]>,
pixels: PixelUnpackData,
) {
let gl = &self.raw;
gl.TexImage2D(
Expand All @@ -2494,7 +2497,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 Expand Up @@ -2553,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 @@ -2566,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
125 changes: 80 additions & 45 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3940,7 +3940,7 @@ impl HasContext for Context {
_border: i32,
_format: u32,
_ty: u32,
_pixels: Option<&[u8]>,
_pixels: PixelUnpackData,
) {
panic!("Tex image 1D is not supported");
}
Expand Down Expand Up @@ -3968,39 +3968,59 @@ impl HasContext for Context {
border: i32,
format: u32,
ty: u32,
pixels: Option<&[u8]>,
pixels: PixelUnpackData,
) {
let pixels = pixels.map(|bytes| texture_data_view(ty, bytes));
match self.raw {
RawRenderingContext::WebGl1(ref gl) => {
// TODO: Handle return value?
gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_array_buffer_view(
target,
level,
internal_format,
width,
height,
border,
format,
ty,
pixels.as_ref(),
)
.unwrap();
match pixels {
PixelUnpackData::BufferOffset(_offset) => panic!("Tex image 2D with offset is not supported"),
PixelUnpackData::Slice(data) => {
let 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,
internal_format,
width,
height,
border,
format,
ty,
Some(&data),
)
}
}
.unwrap(); // TODO: Handle return value?
}
RawRenderingContext::WebGl2(ref gl) => {
// TODO: Handle return value?
gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_array_buffer_view(
target,
level,
internal_format,
width,
height,
border,
format,
ty,
pixels.as_ref(),
)
.unwrap();
match pixels {
PixelUnpackData::BufferOffset(offset) => gl
.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_i32(
target,
level,
internal_format,
width,
height,
border,
format,
ty,
offset as i32,
),
PixelUnpackData::Slice(data) => {
let 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,
internal_format,
width,
height,
border,
format,
ty,
Some(&data),
)
}
}
.unwrap(); // TODO: Handle return value?
}
}
}
Expand Down Expand Up @@ -4064,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
Loading