WebGL2: support TexImage3D (#37718)

Add TexImage3D method to WebGL2RenderingContext

Testing: conformance2 should pass. Also it should get
http://webglsamples.org/WebGL2Samples/#texture_2d_array and
http://webglsamples.org/WebGL2Samples/#texture_3d running.
Fixes: #26511

Now Servo can run texture_2d_array and texture_3d samples!

![圖片](https://github.com/user-attachments/assets/41b87563-08b8-4db3-b503-12f3a61dbed7)

![圖片](https://github.com/user-attachments/assets/3c62a4de-35ea-488d-b2e5-00e3aed52090)

And it can now run three.js too!

![圖片](https://github.com/user-attachments/assets/d880aa92-a154-4895-aa06-b7919d1fc869)

---------

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>
This commit is contained in:
Ngo Iok Ui (Wu Yu Wei) 2025-07-09 23:22:03 +09:00 committed by GitHub
parent 4499fdeb2b
commit 34c31ee418
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 1341 additions and 980 deletions

View file

@ -1582,6 +1582,48 @@ impl WebGLImpl {
WebGLCommand::SetViewport(x, y, width, height) => unsafe {
gl.viewport(x, y, width, height)
},
WebGLCommand::TexImage3D {
target,
level,
internal_format,
size,
depth,
format,
data_type,
effective_data_type,
unpacking_alignment,
alpha_treatment,
y_axis_treatment,
pixel_format,
ref data,
} => {
let pixels = prepare_pixels(
internal_format,
data_type,
size,
unpacking_alignment,
alpha_treatment,
y_axis_treatment,
pixel_format,
Cow::Borrowed(data),
);
unsafe {
gl.pixel_store_i32(gl::UNPACK_ALIGNMENT, unpacking_alignment as i32);
gl.tex_image_3d(
target,
level as i32,
internal_format.as_gl_constant() as i32,
size.width as i32,
size.height as i32,
depth as i32,
0,
format.as_gl_constant(),
effective_data_type,
PixelUnpackData::Slice(Some(&pixels)),
);
}
},
WebGLCommand::TexImage2D {
target,
level,