mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Add support for WebGL2 framebuffer invalidation
Adds support for the `invalidateFramebuffer` and `invalideSubFramebuffer` WebGL2 calls. See: https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.4
This commit is contained in:
parent
d42835b238
commit
cc07d930c8
10 changed files with 127 additions and 148 deletions
|
@ -603,6 +603,51 @@ impl WebGL2RenderingContext {
|
|||
|
||||
self.base.send_command(msg(buffer, draw_buffer, array));
|
||||
}
|
||||
|
||||
fn valid_fb_attachment_values(&self, target: u32, attachments: &[u32]) -> bool {
|
||||
let fb_slot = match target {
|
||||
constants::FRAMEBUFFER | constants::DRAW_FRAMEBUFFER => {
|
||||
self.base.get_draw_framebuffer_slot()
|
||||
},
|
||||
constants::READ_FRAMEBUFFER => self.base.get_read_framebuffer_slot(),
|
||||
_ => {
|
||||
self.base.webgl_error(InvalidEnum);
|
||||
return false;
|
||||
},
|
||||
};
|
||||
|
||||
if let Some(fb) = fb_slot.get() {
|
||||
if fb.check_status() != constants::FRAMEBUFFER_COMPLETE {
|
||||
return false;
|
||||
}
|
||||
|
||||
for &attachment in attachments {
|
||||
match attachment {
|
||||
constants::DEPTH_ATTACHMENT |
|
||||
constants::STENCIL_ATTACHMENT |
|
||||
constants::DEPTH_STENCIL_ATTACHMENT => {},
|
||||
constants::COLOR_ATTACHMENT0..=constants::COLOR_ATTACHMENT15 => {
|
||||
let last_slot = constants::COLOR_ATTACHMENT0 +
|
||||
self.base.limits().max_color_attachments -
|
||||
1;
|
||||
if last_slot < attachment {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
_ => return false,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for &attachment in attachments {
|
||||
match attachment {
|
||||
constants::COLOR | constants::DEPTH | constants::STENCIL => {},
|
||||
_ => return false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
|
||||
|
@ -3497,6 +3542,45 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
|
|||
stencil,
|
||||
));
|
||||
}
|
||||
|
||||
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.4
|
||||
fn InvalidateFramebuffer(&self, target: u32, attachments: Vec<u32>) {
|
||||
if !self.valid_fb_attachment_values(target, &attachments) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.base
|
||||
.send_command(WebGLCommand::InvalidateFramebuffer(target, attachments))
|
||||
}
|
||||
|
||||
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.4
|
||||
fn InvalidateSubFramebuffer(
|
||||
&self,
|
||||
target: u32,
|
||||
attachments: Vec<u32>,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
) {
|
||||
if !self.valid_fb_attachment_values(target, &attachments) {
|
||||
return;
|
||||
}
|
||||
|
||||
if width < 0 || height < 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
self.base
|
||||
.send_command(WebGLCommand::InvalidateSubFramebuffer(
|
||||
target,
|
||||
attachments,
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl LayoutCanvasWebGLRenderingContextHelpers for LayoutDom<WebGL2RenderingContext> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue