mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
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.
This commit is contained in:
parent
d77373654a
commit
3277c5281c
2 changed files with 36 additions and 5 deletions
|
@ -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 {
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue