Skip to content

Commit

Permalink
Use PixelUnpackData in tex_image_{1,2,3}d (#322)
Browse files Browse the repository at this point in the history
* Use PixelUnpackData in tex_image_2d

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Use PixelUnpackData in tex_image_1d

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Use PixelUnpackData for tex_image_3d

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
  • Loading branch information
sagudev authored Nov 5, 2024
1 parent 9474323 commit a0ba3b7
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 54 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,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 @@ -1139,7 +1139,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 @@ -1175,7 +1175,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 @@ -2465,7 +2465,7 @@ impl HasContext for Context {
border: i32,
format: u32,
ty: u32,
pixels: Option<&[u8]>,
pixels: PixelUnpackData,
) {
let gl = &self.raw;
gl.TexImage1D(
Expand All @@ -2476,7 +2476,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 @@ -2512,7 +2515,7 @@ impl HasContext for Context {
border: i32,
format: u32,
ty: u32,
pixels: Option<&[u8]>,
pixels: PixelUnpackData,
) {
let gl = &self.raw;
gl.TexImage2D(
Expand All @@ -2524,7 +2527,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 @@ -2583,7 +2589,7 @@ impl HasContext for Context {
border: i32,
format: u32,
ty: u32,
pixels: Option<&[u8]>,
pixels: PixelUnpackData,
) {
let gl = &self.raw;
gl.TexImage3D(
Expand All @@ -2596,7 +2602,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 @@ -3960,7 +3960,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 @@ -3988,39 +3988,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 @@ -4084,26 +4104,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 a0ba3b7

Please sign in to comment.