Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress alignment padding from glReadPixels #58

Merged
merged 2 commits into from Nov 2, 2013
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

9 gl2.rs
@@ -928,16 +928,19 @@ pub fn read_pixels(x: GLint, y: GLint, width: GLsizei, height: GLsizei, format:
_ => fail!(~"unsupported pixel_type for read_pixels"),
};

let len = (width * height * colors * depth) as uint;
let mut pixels: ~[u8] = ~[];
pixels.reserve((width * height * colors * depth) as uint);
pixels.reserve(len);

do pixels.as_mut_buf |buf, _| {
unsafe {
glReadPixels(x, y, width, height, format, pixel_type, cast::transmute(buf));
// We don't want any alignment padding on pixel rows.
glPixelStorei(PACK_ALIGNMENT, 1);
glReadPixels(x, y, width, height, format, pixel_type, buf as *mut c_void);
}
}

unsafe { set_len(&mut pixels, (width * height * colors * depth) as uint); }
unsafe { set_len(&mut pixels, len); }

pixels
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.