aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglframebuffer.rs
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2016-10-30 19:02:35 -0700
committerEric Anholt <eric@anholt.net>2016-11-05 11:49:29 -0700
commit3277c5281cf7d4345d8c0eb11a8f451a5796eb3e (patch)
tree152f5b40e7f771521a5b849480f2324cac101060 /components/script/dom/webglframebuffer.rs
parentd77373654a4d168092fb51d1810236d4bf0b3b52 (diff)
downloadservo-3277c5281cf7d4345d8c0eb11a8f451a5796eb3e.tar.gz
servo-3277c5281cf7d4345d8c0eb11a8f451a5796eb3e.zip
webgl: Validate that framebuffer attachment sizes match.
This is required by the WebGL spec, and we need to figure out the FB size like this for validating ReadPixels.
Diffstat (limited to 'components/script/dom/webglframebuffer.rs')
-rw-r--r--components/script/dom/webglframebuffer.rs39
1 files changed, 35 insertions, 4 deletions
diff --git a/components/script/dom/webglframebuffer.rs b/components/script/dom/webglframebuffer.rs
index e271f1c7034..8586b09d5bf 100644
--- a/components/script/dom/webglframebuffer.rs
+++ b/components/script/dom/webglframebuffer.rs
@@ -111,10 +111,15 @@ impl WebGLFramebuffer {
}
fn update_status(&self) {
- let has_c = self.color.borrow().is_some();
- let has_z = self.depth.borrow().is_some();
- let has_s = self.stencil.borrow().is_some();
- let has_zs = self.depthstencil.borrow().is_some();
+ let c = self.color.borrow();
+ let z = self.depth.borrow();
+ let s = self.stencil.borrow();
+ let zs = self.depthstencil.borrow();
+ let has_c = c.is_some();
+ let has_z = z.is_some();
+ let has_s = s.is_some();
+ let has_zs = zs.is_some();
+ let attachments = [&*c, &*z, &*s, &*zs];
// From the WebGL spec, 6.6 ("Framebuffer Object Attachments"):
//
@@ -135,6 +140,32 @@ impl WebGLFramebuffer {
return;
}
+ let mut fb_size = None;
+ for attachment in &attachments {
+ // Get the size of this attachment.
+ let size = match **attachment {
+ Some(WebGLFramebufferAttachment::Renderbuffer(ref att_rb)) => {
+ att_rb.size()
+ }
+ Some(WebGLFramebufferAttachment::Texture { texture: ref att_tex, level } ) => {
+ let info = att_tex.image_info_at_face(0, level as u32);
+ Some((info.width() as i32, info.height() as i32))
+ }
+ None => None,
+ };
+
+ // Make sure that, if we've found any other attachment,
+ // that the size matches.
+ if size.is_some() {
+ if fb_size.is_some() && size != fb_size {
+ self.status.set(constants::FRAMEBUFFER_INCOMPLETE_DIMENSIONS);
+ return;
+ } else {
+ fb_size = size;
+ }
+ }
+ }
+
if has_c || has_z || has_zs || has_s {
self.status.set(constants::FRAMEBUFFER_COMPLETE);
} else {