webgl: Remove knowledge of attached framebuffers from renderbuffers and textures.

This commit is contained in:
Josh Matthews 2018-09-10 16:27:58 -04:00
parent b8ee62e67b
commit 4edb7b194c
3 changed files with 11 additions and 74 deletions

View file

@ -274,7 +274,9 @@ impl WebGLFramebuffer {
let rb_id = match rb { let rb_id = match rb {
Some(rb) => { Some(rb) => {
rb.attach(self)?; if !rb.ever_bound() {
return Err(WebGLError::InvalidOperation);
}
*binding.borrow_mut() = Some(WebGLFramebufferAttachment::Renderbuffer(Dom::from_ref(rb))); *binding.borrow_mut() = Some(WebGLFramebufferAttachment::Renderbuffer(Dom::from_ref(rb)));
Some(rb.id()) Some(rb.id())
} }
@ -305,16 +307,7 @@ impl WebGLFramebuffer {
binding: &DomRefCell<Option<WebGLFramebufferAttachment>>, binding: &DomRefCell<Option<WebGLFramebufferAttachment>>,
attachment: u32, attachment: u32,
) { ) {
let attachment_obj = binding.borrow().as_ref().map(WebGLFramebufferAttachment::root);
match attachment_obj {
Some(WebGLFramebufferAttachmentRoot::Renderbuffer(ref rb)) =>
rb.unattach(self),
Some(WebGLFramebufferAttachmentRoot::Texture(ref texture)) =>
texture.unattach(self),
None => (),
}
*binding.borrow_mut() = None; *binding.borrow_mut() = None;
if INTERESTING_ATTACHMENT_POINTS.contains(&attachment) { if INTERESTING_ATTACHMENT_POINTS.contains(&attachment) {
self.reattach_depth_stencil(); self.reattach_depth_stencil();
} }
@ -429,7 +422,6 @@ impl WebGLFramebuffer {
_ => return Err(WebGLError::InvalidOperation), _ => return Err(WebGLError::InvalidOperation),
} }
texture.attach(self);
*binding.borrow_mut() = Some(WebGLFramebufferAttachment::Texture { *binding.borrow_mut() = Some(WebGLFramebufferAttachment::Texture {
texture: Dom::from_ref(texture), texture: Dom::from_ref(texture),
level: level } level: level }

View file

@ -4,14 +4,12 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLRenderbufferId, WebGLResult}; 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::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as WebGl2Constants;
use dom::bindings::codegen::Bindings::WebGLRenderbufferBinding; use dom::bindings::codegen::Bindings::WebGLRenderbufferBinding;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::reflector::{DomObject, reflect_dom_object};
use dom::bindings::root::{DomRoot, Dom}; use dom::bindings::root::DomRoot;
use dom::webglframebuffer::WebGLFramebuffer;
use dom::webglobject::WebGLObject; use dom::webglobject::WebGLObject;
use dom::webglrenderingcontext::{WebGLRenderingContext, is_gles}; use dom::webglrenderingcontext::{WebGLRenderingContext, is_gles};
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -26,8 +24,6 @@ pub struct WebGLRenderbuffer {
size: Cell<Option<(i32, i32)>>, size: Cell<Option<(i32, i32)>>,
internal_format: Cell<Option<u32>>, internal_format: Cell<Option<u32>>,
is_initialized: Cell<bool>, is_initialized: Cell<bool>,
// Framebuffer that this texture is attached to.
attached_framebuffers: DomRefCell<Vec<Dom<WebGLFramebuffer>>>,
} }
impl WebGLRenderbuffer { impl WebGLRenderbuffer {
@ -40,7 +36,6 @@ impl WebGLRenderbuffer {
internal_format: Cell::new(None), internal_format: Cell::new(None),
size: Cell::new(None), size: Cell::new(None),
is_initialized: Cell::new(false), is_initialized: Cell::new(false),
attached_framebuffers: Default::default(),
} }
} }
@ -102,16 +97,9 @@ impl WebGLRenderbuffer {
let currently_bound_framebuffer = let currently_bound_framebuffer =
self.upcast::<WebGLObject>() self.upcast::<WebGLObject>()
.context() .context()
.bound_framebuffer() .bound_framebuffer();
.map_or(0, |fb| fb.id().get()); if let Some(fb) = currently_bound_framebuffer {
let current_framebuffer = fb.detach_renderbuffer(self);
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>() self.upcast::<WebGLObject>()
@ -173,22 +161,4 @@ impl WebGLRenderbuffer {
Ok(()) Ok(())
} }
pub fn attach(&self, framebuffer: &WebGLFramebuffer) -> WebGLResult<()> {
if !self.ever_bound.get() {
return Err(WebGLError::InvalidOperation);
}
self.attached_framebuffers.borrow_mut().push(Dom::from_ref(framebuffer));
Ok(())
}
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);
}
}
} }

View file

@ -12,9 +12,8 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi
use dom::bindings::codegen::Bindings::WebGLTextureBinding; use dom::bindings::codegen::Bindings::WebGLTextureBinding;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::reflector::{DomObject, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::root::DomRoot;
use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType}; use dom::webgl_validations::types::{TexImageTarget, TexFormat, TexDataType};
use dom::webglframebuffer::WebGLFramebuffer;
use dom::webglobject::WebGLObject; use dom::webglobject::WebGLObject;
use dom::webglrenderingcontext::WebGLRenderingContext; use dom::webglrenderingcontext::WebGLRenderingContext;
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -49,8 +48,6 @@ pub struct WebGLTexture {
mag_filter: Cell<u32>, mag_filter: Cell<u32>,
/// True if this texture is used for the DOMToTexture feature. /// True if this texture is used for the DOMToTexture feature.
attached_to_dom: Cell<bool>, attached_to_dom: Cell<bool>,
// Framebuffer that this texture is attached to.
attached_framebuffers: DomRefCell<Vec<Dom<WebGLFramebuffer>>>,
} }
impl WebGLTexture { impl WebGLTexture {
@ -66,7 +63,6 @@ impl WebGLTexture {
mag_filter: Cell::new(constants::LINEAR), mag_filter: Cell::new(constants::LINEAR),
image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]),
attached_to_dom: Cell::new(false), attached_to_dom: Cell::new(false),
attached_framebuffers: Default::default(),
} }
} }
@ -201,16 +197,9 @@ impl WebGLTexture {
let currently_bound_framebuffer = let currently_bound_framebuffer =
self.upcast::<WebGLObject>() self.upcast::<WebGLObject>()
.context() .context()
.bound_framebuffer() .bound_framebuffer();
.map_or(0, |fb| fb.id().get()); if let Some(fb) = currently_bound_framebuffer {
let current_framebuffer = fb.detach_texture(self);
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_texture(self);
self.attached_framebuffers.borrow_mut().remove(fb_index);
} }
context.send_command(WebGLCommand::DeleteTexture(self.id)); context.send_command(WebGLCommand::DeleteTexture(self.id));
@ -425,20 +414,6 @@ impl WebGLTexture {
pub fn set_attached_to_dom(&self) { pub fn set_attached_to_dom(&self) {
self.attached_to_dom.set(true); self.attached_to_dom.set(true);
} }
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);
}
}
} }
impl Drop for WebGLTexture { impl Drop for WebGLTexture {