Simplify WebGLRenderingContext::get_image_data

This commit is contained in:
Anthony Ramine 2018-09-07 16:46:18 +02:00
parent f7630dad87
commit 4e9281dcbf

View file

@ -1191,16 +1191,16 @@ impl WebGLRenderingContext {
// can fail and that it is UB what happens in that case. // can fail and that it is UB what happens in that case.
// //
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#2.2 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#2.2
pub fn get_image_data(&self, mut width: u32, mut height: u32) -> Option<Vec<u8>> { pub fn get_image_data(&self, width: u32, height: u32) -> Option<Vec<u8>> {
handle_potential_webgl_error!(self, self.validate_framebuffer(), return None); handle_potential_webgl_error!(self, self.validate_framebuffer(), return None);
if let Some((fb_width, fb_height)) = self.get_current_framebuffer_size() { let (fb_width, fb_height) = handle_potential_webgl_error!(
width = cmp::min(width, fb_width as u32); self,
height = cmp::min(height, fb_height as u32); self.get_current_framebuffer_size().ok_or(InvalidOperation),
} else { return None
self.webgl_error(InvalidOperation); );
return None; let width = cmp::min(width, fb_width as u32);
} let height = cmp::min(height, fb_height as u32);
let (sender, receiver) = webgl_channel().unwrap(); let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::ReadPixels( self.send_command(WebGLCommand::ReadPixels(