aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderbuffer.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2018-08-24 16:10:28 -0400
committerJosh Matthews <josh@joshmatthews.net>2018-09-10 16:31:30 -0400
commitbb8d9ba74c024a317fbbd49811541632404ef51c (patch)
treedd7e34c9665c5f4e5935d947e6de8129654887a4 /components/script/dom/webglrenderbuffer.rs
parent1b08dd523274b1fb346b413cb986cd47409f3aa7 (diff)
downloadservo-bb8d9ba74c024a317fbbd49811541632404ef51c.tar.gz
servo-bb8d9ba74c024a317fbbd49811541632404ef51c.zip
webgl: Ensure that depth and stencil attachments are rebound after messing with DEPTH_STENCIL attachments.
Diffstat (limited to 'components/script/dom/webglrenderbuffer.rs')
-rw-r--r--components/script/dom/webglrenderbuffer.rs44
1 files changed, 43 insertions, 1 deletions
diff --git a/components/script/dom/webglrenderbuffer.rs b/components/script/dom/webglrenderbuffer.rs
index f346407581f..7ee108ebdc5 100644
--- a/components/script/dom/webglrenderbuffer.rs
+++ b/components/script/dom/webglrenderbuffer.rs
@@ -4,12 +4,14 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLRenderbufferId, WebGLResult};
+use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as WebGl2Constants;
use dom::bindings::codegen::Bindings::WebGLRenderbufferBinding;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::{DomObject, reflect_dom_object};
-use dom::bindings::root::DomRoot;
+use dom::bindings::root::{DomRoot, Dom};
+use dom::webglframebuffer::WebGLFramebuffer;
use dom::webglobject::WebGLObject;
use dom::webglrenderingcontext::{WebGLRenderingContext, is_gles};
use dom_struct::dom_struct;
@@ -24,6 +26,8 @@ pub struct WebGLRenderbuffer {
size: Cell<Option<(i32, i32)>>,
internal_format: Cell<Option<u32>>,
is_initialized: Cell<bool>,
+ // Framebuffer that this texture is attached to.
+ attached_framebuffers: DomRefCell<Vec<Dom<WebGLFramebuffer>>>,
}
impl WebGLRenderbuffer {
@@ -36,6 +40,7 @@ impl WebGLRenderbuffer {
internal_format: Cell::new(None),
size: Cell::new(None),
is_initialized: Cell::new(false),
+ attached_framebuffers: Default::default(),
}
}
@@ -86,6 +91,29 @@ impl WebGLRenderbuffer {
pub fn delete(&self) {
if !self.is_deleted.get() {
self.is_deleted.set(true);
+
+ /*
+ 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.
+ - GLES 2.0, 4.4.3, "Attaching Renderbuffer Images to a Framebuffer"
+ */
+ let currently_bound_framebuffer =
+ self.upcast::<WebGLObject>()
+ .context()
+ .bound_framebuffer()
+ .map_or(0, |fb| fb.id().get());
+ let current_framebuffer =
+ self.attached_framebuffers
+ .borrow()
+ .iter()
+ .position(|fb| fb.id().get() == currently_bound_framebuffer);
+ if let Some(fb_index) = current_framebuffer {
+ self.attached_framebuffers.borrow()[fb_index].detach_renderbuffer(self);
+ self.attached_framebuffers.borrow_mut().remove(fb_index);
+ }
+
self.upcast::<WebGLObject>()
.context()
.send_command(WebGLCommand::DeleteRenderbuffer(self.id));
@@ -145,4 +173,18 @@ impl WebGLRenderbuffer {
Ok(())
}
+
+ pub fn attach(&self, framebuffer: &WebGLFramebuffer) {
+ self.attached_framebuffers.borrow_mut().push(Dom::from_ref(framebuffer));
+ }
+
+ pub fn unattach(&self, fb: &WebGLFramebuffer) {
+ let mut attached_framebuffers = self.attached_framebuffers.borrow_mut();
+ let idx = attached_framebuffers.iter().position(|attached| {
+ attached.id() == fb.id()
+ });
+ if let Some(idx) = idx {
+ attached_framebuffers.remove(idx);
+ }
+ }
}