diff --git a/components/script/dom/webglframebuffer.rs b/components/script/dom/webglframebuffer.rs index fa66d61429f..de659e6ebd3 100644 --- a/components/script/dom/webglframebuffer.rs +++ b/components/script/dom/webglframebuffer.rs @@ -25,6 +25,15 @@ enum WebGLFramebufferAttachment { Texture { texture: Dom, level: i32 }, } +impl WebGLFramebufferAttachment { + fn needs_initialization(&self) -> bool { + match *self { + WebGLFramebufferAttachment::Renderbuffer(_) => true, + WebGLFramebufferAttachment::Texture { .. } => false, + } + } +} + #[derive(Clone, JSTraceable, MallocSizeOf)] pub enum WebGLFramebufferAttachmentRoot { Renderbuffer(DomRoot), @@ -46,6 +55,7 @@ pub struct WebGLFramebuffer { depth: DomRefCell>, stencil: DomRefCell>, depthstencil: DomRefCell>, + is_initialized: Cell, } impl WebGLFramebuffer { @@ -61,6 +71,7 @@ impl WebGLFramebuffer { depth: DomRefCell::new(None), stencil: DomRefCell::new(None), depthstencil: DomRefCell::new(None), + is_initialized: Cell::new(false), } } @@ -205,12 +216,36 @@ impl WebGLFramebuffer { pub fn check_status_for_rendering(&self) -> u32 { let result = self.check_status(); - if result == constants::FRAMEBUFFER_COMPLETE { - if self.color.borrow().is_none() { - return constants::FRAMEBUFFER_INCOMPLETE_ATTACHMENT; - } + if result != constants::FRAMEBUFFER_COMPLETE { + return result; } - result + + if self.color.borrow().is_none() { + return constants::FRAMEBUFFER_INCOMPLETE_ATTACHMENT; + } + + if !self.is_initialized.get() { + let attachments = [ + (&self.color, constants::COLOR_BUFFER_BIT), + (&self.depth, constants::DEPTH_BUFFER_BIT), + (&self.stencil, constants::STENCIL_BUFFER_BIT), + (&self.depthstencil, constants::DEPTH_BUFFER_BIT | constants::STENCIL_BUFFER_BIT) + ]; + let mut clear_bits = 0; + for &(attachment, bits) in &attachments { + if attachment.borrow().as_ref().map_or(false, |att| att.needs_initialization()) { + clear_bits |= bits; + } + } + if clear_bits != 0 { + self.upcast::().context().send_command( + WebGLCommand::Clear(clear_bits) + ); + } + self.is_initialized.set(true); + } + + constants::FRAMEBUFFER_COMPLETE } pub fn renderbuffer(&self, attachment: u32, rb: Option<&WebGLRenderbuffer>) -> WebGLResult<()> { @@ -244,6 +279,7 @@ impl WebGLFramebuffer { ); self.update_status(); + self.is_initialized.set(false); Ok(()) } @@ -344,6 +380,7 @@ impl WebGLFramebuffer { ); self.update_status(); + self.is_initialized.set(false); Ok(()) } diff --git a/tests/wpt/webgl/meta/conformance/renderbuffers/framebuffer-object-attachment.html.ini b/tests/wpt/webgl/meta/conformance/renderbuffers/framebuffer-object-attachment.html.ini index 46af4d0a93b..06d68f8e7ed 100644 --- a/tests/wpt/webgl/meta/conformance/renderbuffers/framebuffer-object-attachment.html.ini +++ b/tests/wpt/webgl/meta/conformance/renderbuffers/framebuffer-object-attachment.html.ini @@ -1,43 +1,21 @@ [framebuffer-object-attachment.html] + [WebGL test #139: at (0, 0) expected: 0,255,0,255 was 255,0,0,255] + expected: fail + [WebGL test #522: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT was FRAMEBUFFER_UNSUPPORTED or FRAMEBUFFER_UNSUPPORTED] expected: FAIL - [WebGL test #483: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] - expected: FAIL - [WebGL test #537: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT was FRAMEBUFFER_UNSUPPORTED or FRAMEBUFFER_UNSUPPORTED] expected: FAIL - [WebGL test #476: at (0, 0) expected: 0,255,0,255 was 255,0,0,255] - expected: FAIL - - [WebGL test #491: at (0, 0) expected: 0,255,0,255 was 255,0,0,255] - expected: FAIL - - [WebGL test #478: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] - expected: FAIL - - [WebGL test #488: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] - expected: FAIL - - [WebGL test #481: at (0, 0) expected: 0,255,0,255 was 255,0,0,255] - expected: FAIL - - [WebGL test #486: at (0, 0) expected: 0,255,0,255 was 255,0,0,255] - expected: FAIL - [WebGL test #559: getError expected: INVALID_OPERATION. Was INVALID_FRAMEBUFFER_OPERATION : After CopyTexSubImage2D from missing attachment] expected: FAIL [WebGL test #555: getError expected: INVALID_OPERATION. Was INVALID_FRAMEBUFFER_OPERATION : After ReadPixels from missing attachment] expected: FAIL - [WebGL test #473: at (0, 0) expected: 0,255,0,255 was 0,0,0,0] - expected: FAIL - [WebGL test #519: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT was FRAMEBUFFER_UNSUPPORTED or FRAMEBUFFER_UNSUPPORTED] expected: FAIL [WebGL test #557: getError expected: INVALID_OPERATION. Was INVALID_FRAMEBUFFER_OPERATION : After CopyTexImage2D from missing attachment] expected: FAIL -