mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add support for WebGL2 TexImage2D
Adds initial support for one of the WebGL2 `TexImage2D` call.
This commit is contained in:
parent
ce076a8382
commit
b298160ff2
72 changed files with 739 additions and 7 deletions
|
@ -2917,8 +2917,74 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
|
|||
}
|
||||
|
||||
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.6
|
||||
#[allow(unsafe_code)]
|
||||
fn TexImage2D__(
|
||||
&self,
|
||||
target: u32,
|
||||
level: i32,
|
||||
internalformat: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
border: i32,
|
||||
format: u32,
|
||||
type_: u32,
|
||||
source: ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement,
|
||||
) -> Fallible<()> {
|
||||
if self.bound_pixel_unpack_buffer.get().is_some() {
|
||||
return Ok(self.base.webgl_error(InvalidOperation));
|
||||
}
|
||||
|
||||
let validator = TexImage2DValidator::new(
|
||||
&self.base,
|
||||
target,
|
||||
level,
|
||||
internalformat as u32,
|
||||
width,
|
||||
height,
|
||||
border,
|
||||
format,
|
||||
type_,
|
||||
);
|
||||
|
||||
let TexImage2DValidatorResult {
|
||||
texture,
|
||||
target,
|
||||
width: _,
|
||||
height: _,
|
||||
level,
|
||||
border,
|
||||
internal_format,
|
||||
format,
|
||||
data_type,
|
||||
} = match validator.validate() {
|
||||
Ok(result) => result,
|
||||
Err(_) => return Ok(()),
|
||||
};
|
||||
|
||||
let unpacking_alignment = self.base.texture_unpacking_alignment();
|
||||
|
||||
let pixels = match self.base.get_image_pixels(source)? {
|
||||
Some(pixels) => pixels,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
self.base.tex_image_2d(
|
||||
&texture,
|
||||
target,
|
||||
data_type,
|
||||
internal_format,
|
||||
format,
|
||||
level,
|
||||
border,
|
||||
unpacking_alignment,
|
||||
pixels,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.6
|
||||
#[allow(unsafe_code)]
|
||||
fn TexImage2D___(
|
||||
&self,
|
||||
target: u32,
|
||||
level: i32,
|
||||
|
|
|
@ -638,7 +638,7 @@ impl WebGLRenderingContext {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_image_pixels(&self, source: TexImageSource) -> Fallible<Option<TexPixels>> {
|
||||
pub fn get_image_pixels(&self, source: TexImageSource) -> Fallible<Option<TexPixels>> {
|
||||
Ok(Some(match source {
|
||||
TexImageSource::ImageData(image_data) => TexPixels::new(
|
||||
image_data.to_shared_memory(),
|
||||
|
|
|
@ -508,10 +508,10 @@ interface mixin WebGL2RenderingContextOverloads
|
|||
//[Throws]
|
||||
//void texImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
|
||||
// GLint border, GLenum format, GLenum type, GLintptr pboOffset);
|
||||
//[Throws]
|
||||
//void texImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
|
||||
// GLint border, GLenum format, GLenum type,
|
||||
// TexImageSource source); // May throw DOMException
|
||||
[Throws]
|
||||
void texImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
|
||||
GLint border, GLenum format, GLenum type,
|
||||
TexImageSource source); // May throw DOMException
|
||||
[Throws]
|
||||
void texImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
|
||||
GLint border, GLenum format, GLenum type, /*[AllowShared]*/ ArrayBufferView srcData,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue