mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
webgl: Clear renderbuffers on first read/write operation.
This commit is contained in:
parent
944d1d1f29
commit
da3b0ef88f
2 changed files with 45 additions and 30 deletions
|
@ -25,6 +25,15 @@ enum WebGLFramebufferAttachment {
|
||||||
Texture { texture: Dom<WebGLTexture>, level: i32 },
|
Texture { texture: Dom<WebGLTexture>, level: i32 },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl WebGLFramebufferAttachment {
|
||||||
|
fn needs_initialization(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
WebGLFramebufferAttachment::Renderbuffer(_) => true,
|
||||||
|
WebGLFramebufferAttachment::Texture { .. } => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, JSTraceable, MallocSizeOf)]
|
#[derive(Clone, JSTraceable, MallocSizeOf)]
|
||||||
pub enum WebGLFramebufferAttachmentRoot {
|
pub enum WebGLFramebufferAttachmentRoot {
|
||||||
Renderbuffer(DomRoot<WebGLRenderbuffer>),
|
Renderbuffer(DomRoot<WebGLRenderbuffer>),
|
||||||
|
@ -46,6 +55,7 @@ pub struct WebGLFramebuffer {
|
||||||
depth: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
depth: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
||||||
stencil: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
stencil: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
||||||
depthstencil: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
depthstencil: DomRefCell<Option<WebGLFramebufferAttachment>>,
|
||||||
|
is_initialized: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebGLFramebuffer {
|
impl WebGLFramebuffer {
|
||||||
|
@ -61,6 +71,7 @@ impl WebGLFramebuffer {
|
||||||
depth: DomRefCell::new(None),
|
depth: DomRefCell::new(None),
|
||||||
stencil: DomRefCell::new(None),
|
stencil: DomRefCell::new(None),
|
||||||
depthstencil: 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 {
|
pub fn check_status_for_rendering(&self) -> u32 {
|
||||||
let result = self.check_status();
|
let result = self.check_status();
|
||||||
if result == constants::FRAMEBUFFER_COMPLETE {
|
if result != constants::FRAMEBUFFER_COMPLETE {
|
||||||
if self.color.borrow().is_none() {
|
return result;
|
||||||
return constants::FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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::<WebGLObject>().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<()> {
|
pub fn renderbuffer(&self, attachment: u32, rb: Option<&WebGLRenderbuffer>) -> WebGLResult<()> {
|
||||||
|
@ -244,6 +279,7 @@ impl WebGLFramebuffer {
|
||||||
);
|
);
|
||||||
|
|
||||||
self.update_status();
|
self.update_status();
|
||||||
|
self.is_initialized.set(false);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,6 +380,7 @@ impl WebGLFramebuffer {
|
||||||
);
|
);
|
||||||
|
|
||||||
self.update_status();
|
self.update_status();
|
||||||
|
self.is_initialized.set(false);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,43 +1,21 @@
|
||||||
[framebuffer-object-attachment.html]
|
[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]
|
[WebGL test #522: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT was FRAMEBUFFER_UNSUPPORTED or FRAMEBUFFER_UNSUPPORTED]
|
||||||
expected: FAIL
|
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]
|
[WebGL test #537: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT was FRAMEBUFFER_UNSUPPORTED or FRAMEBUFFER_UNSUPPORTED]
|
||||||
expected: FAIL
|
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]
|
[WebGL test #559: getError expected: INVALID_OPERATION. Was INVALID_FRAMEBUFFER_OPERATION : After CopyTexSubImage2D from missing attachment]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[WebGL test #555: getError expected: INVALID_OPERATION. Was INVALID_FRAMEBUFFER_OPERATION : After ReadPixels from missing attachment]
|
[WebGL test #555: getError expected: INVALID_OPERATION. Was INVALID_FRAMEBUFFER_OPERATION : After ReadPixels from missing attachment]
|
||||||
expected: FAIL
|
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]
|
[WebGL test #519: gl.checkFramebufferStatus(gl.FRAMEBUFFER) should be FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT was FRAMEBUFFER_UNSUPPORTED or FRAMEBUFFER_UNSUPPORTED]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[WebGL test #557: getError expected: INVALID_OPERATION. Was INVALID_FRAMEBUFFER_OPERATION : After CopyTexImage2D from missing attachment]
|
[WebGL test #557: getError expected: INVALID_OPERATION. Was INVALID_FRAMEBUFFER_OPERATION : After CopyTexImage2D from missing attachment]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue