webgl: Update FBO status when textures or RBs are reallocated.

FBO status is supposed to depend on the size of the attachments all
matching, so we need to re-check when it changes.  We don't ensure
matching yet, but this will prevent regressions when we do.
This commit is contained in:
Eric Anholt 2016-11-01 21:45:29 -07:00
parent 8e681dddc1
commit d77373654a
2 changed files with 45 additions and 8 deletions

View file

@ -254,7 +254,9 @@ impl WebGLFramebuffer {
Ok(()) Ok(())
} }
pub fn detach_renderbuffer(&self, rb: &WebGLRenderbuffer) { fn with_matching_renderbuffers<F>(&self, rb: &WebGLRenderbuffer, mut closure: F)
where F: FnMut(&DOMRefCell<Option<WebGLFramebufferAttachment>>)
{
let attachments = [&self.color, let attachments = [&self.color,
&self.depth, &self.depth,
&self.stencil, &self.stencil,
@ -270,13 +272,14 @@ impl WebGLFramebuffer {
}; };
if matched { if matched {
*attachment.borrow_mut() = None; closure(attachment);
self.update_status();
} }
} }
} }
pub fn detach_texture(&self, texture: &WebGLTexture) { fn with_matching_textures<F>(&self, texture: &WebGLTexture, mut closure: F)
where F: FnMut(&DOMRefCell<Option<WebGLFramebufferAttachment>>)
{
let attachments = [&self.color, let attachments = [&self.color,
&self.depth, &self.depth,
&self.stencil, &self.stencil,
@ -292,12 +295,37 @@ impl WebGLFramebuffer {
}; };
if matched { if matched {
*attachment.borrow_mut() = None; closure(attachment);
self.update_status();
} }
} }
} }
pub fn detach_renderbuffer(&self, rb: &WebGLRenderbuffer) {
self.with_matching_renderbuffers(rb, |att| {
*att.borrow_mut() = None;
self.update_status();
});
}
pub fn detach_texture(&self, texture: &WebGLTexture) {
self.with_matching_textures(texture, |att| {
*att.borrow_mut() = None;
self.update_status();
});
}
pub fn invalidate_renderbuffer(&self, rb: &WebGLRenderbuffer) {
self.with_matching_renderbuffers(rb, |_att| {
self.update_status();
});
}
pub fn invalidate_texture(&self, texture: &WebGLTexture) {
self.with_matching_textures(texture, |_att| {
self.update_status();
});
}
pub fn target(&self) -> Option<u32> { pub fn target(&self) -> Option<u32> {
self.target.get() self.target.get()
} }

View file

@ -465,7 +465,11 @@ impl WebGLRenderingContext {
self.ipc_renderer self.ipc_renderer
.send(CanvasMsg::WebGL(msg)) .send(CanvasMsg::WebGL(msg))
.unwrap() .unwrap();
if let Some(fb) = self.bound_framebuffer.get() {
fb.invalidate_texture(&*texture);
}
} }
fn tex_sub_image_2d(&self, fn tex_sub_image_2d(&self,
@ -2621,7 +2625,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
} }
match self.bound_renderbuffer.get() { match self.bound_renderbuffer.get() {
Some(rb) => handle_potential_webgl_error!(self, rb.storage(internal_format, width, height)), Some(rb) => {
handle_potential_webgl_error!(self, rb.storage(internal_format, width, height));
if let Some(fb) = self.bound_framebuffer.get() {
fb.invalidate_renderbuffer(&*rb);
}
}
None => self.webgl_error(InvalidOperation), None => self.webgl_error(InvalidOperation),
}; };