mirror of
https://github.com/servo/servo.git
synced 2025-07-30 18:50:36 +01:00
webgl: Detach RBs and textures from the bound FBO on deletion.
This is part of general GL behavior: when an object is deleted, look through the currently bound objects and detach the deleted object from them. Detaching an object from an FBO causes it to need to be re-checked for its status.
This commit is contained in:
parent
6c10d5ca75
commit
dba7d5eb51
3 changed files with 148 additions and 0 deletions
|
@ -231,6 +231,7 @@ impl WebGLFramebuffer {
|
|||
|
||||
_ => {
|
||||
*binding.borrow_mut() = None;
|
||||
self.update_status();
|
||||
None
|
||||
}
|
||||
};
|
||||
|
@ -245,6 +246,49 @@ impl WebGLFramebuffer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn detach_renderbuffer(&self, rb: &WebGLRenderbuffer) {
|
||||
let attachments = [&self.color,
|
||||
&self.depth,
|
||||
&self.stencil,
|
||||
&self.depthstencil];
|
||||
|
||||
for attachment in &attachments {
|
||||
let matched = {
|
||||
match *attachment.borrow() {
|
||||
Some(WebGLFramebufferAttachment::Renderbuffer(ref att_rb))
|
||||
if rb.id() == att_rb.id() => true,
|
||||
_ => false,
|
||||
}
|
||||
};
|
||||
|
||||
if matched {
|
||||
*attachment.borrow_mut() = None;
|
||||
self.update_status();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn detach_texture(&self, texture: &WebGLTexture) {
|
||||
let attachments = [&self.color,
|
||||
&self.depth,
|
||||
&self.stencil,
|
||||
&self.depthstencil];
|
||||
|
||||
for attachment in &attachments {
|
||||
let matched = {
|
||||
match *attachment.borrow() {
|
||||
Some(WebGLFramebufferAttachment::Texture(ref att_texture))
|
||||
if texture.id() == att_texture.id() => true,
|
||||
_ => false,
|
||||
}
|
||||
};
|
||||
|
||||
if matched {
|
||||
*attachment.borrow_mut() = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn target(&self) -> Option<u32> {
|
||||
self.target.get()
|
||||
}
|
||||
|
|
|
@ -1280,6 +1280,20 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
if let Some(renderbuffer) = renderbuffer {
|
||||
handle_object_deletion!(self, self.bound_renderbuffer, renderbuffer,
|
||||
Some(WebGLCommand::BindRenderbuffer(constants::RENDERBUFFER, None)));
|
||||
// From the GLES 2.0.25 spec, page 113:
|
||||
//
|
||||
// "If a renderbuffer object is deleted while its
|
||||
// image is attached to the currently bound
|
||||
// framebuffer, then it is as if
|
||||
// FramebufferRenderbuffer had been called, with a
|
||||
// renderbuffer of 0, for each attachment point to
|
||||
// which this image was attached in the currently
|
||||
// bound framebuffer."
|
||||
//
|
||||
if let Some(fb) = self.bound_framebuffer.get() {
|
||||
fb.detach_renderbuffer(renderbuffer);
|
||||
}
|
||||
|
||||
renderbuffer.delete()
|
||||
}
|
||||
}
|
||||
|
@ -1291,6 +1305,18 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
Some(WebGLCommand::BindTexture(constants::TEXTURE_2D, None)));
|
||||
handle_object_deletion!(self, self.bound_texture_cube_map, texture,
|
||||
Some(WebGLCommand::BindTexture(constants::TEXTURE_CUBE_MAP, None)));
|
||||
|
||||
// From the GLES 2.0.25 spec, page 113:
|
||||
//
|
||||
// "If a texture object is deleted while its image is
|
||||
// attached to the currently bound framebuffer, then
|
||||
// it is as if FramebufferTexture2D had been called,
|
||||
// with a texture of 0, for each attachment point to
|
||||
// which this image was attached in the currently
|
||||
// bound framebuffer."
|
||||
if let Some(fb) = self.bound_framebuffer.get() {
|
||||
fb.detach_texture(texture);
|
||||
}
|
||||
texture.delete()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue