Skip to content

Commit

Permalink
webgl: Validate that framebuffer attachment sizes match.
Browse files Browse the repository at this point in the history
This is required by the WebGL spec, and we need to figure out the FB
size like this for validating ReadPixels.
  • Loading branch information
anholt committed Nov 5, 2016
1 parent d773736 commit 3277c52
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
39 changes: 35 additions & 4 deletions components/script/dom/webglframebuffer.rs
Expand Up @@ -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"):
//
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webgltexture.rs
Expand Up @@ -332,7 +332,7 @@ impl WebGLTexture {
self.image_info_at_face(face_index, level)
}

fn image_info_at_face(&self, face: u8, level: u32) -> ImageInfo {
pub fn image_info_at_face(&self, face: u8, level: u32) -> ImageInfo {
let pos = (level * self.face_count.get() as u32) + face as u32;
self.image_info_array.borrow()[pos as usize]
}
Expand Down

0 comments on commit 3277c52

Please sign in to comment.