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

Add support for glReadPixels. #44

Merged
merged 1 commit into from Jul 16, 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

Add support for glReadPixels.

  • Loading branch information
metajack committed Jul 16, 2013
commit 8a7d777474138cd15dc29c757b15e6f8bb3d22ab
29 gl2.rs
@@ -20,7 +20,7 @@ use std::str::{as_c_str, from_bytes};
use std::str::raw::from_c_str;
use std::sys::size_of;
use std::vec::from_elem;
use std::vec::raw::to_ptr;
use std::vec::raw::{set_len, to_ptr};

// Linking
#[nolink]
@@ -832,6 +832,31 @@ pub fn polygon_mode(face: GLenum, mode: GLenum) {
}
}

pub fn read_pixels(x: GLint, y: GLint, width: GLsizei, height: GLsizei, format: GLenum, pixel_type: GLenum) -> ~[u8] {
let colors = match format {
RGB => 3,
RGBA => 3,
_ => fail!(~"unsupported format for read_pixels"),
};
let depth = match pixel_type {
UNSIGNED_BYTE => 1,
_ => fail!(~"unsupported pixel_type for read_pixels"),
};

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

do pixels.as_mut_buf |buf, _| {
unsafe {
glReadPixels(x, y, width, height, format, pixel_type, cast::transmute(buf));
}
}

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

pixels
}

pub fn shader_source(shader: GLuint, strings: &[~[u8]]) {
unsafe {
let pointers = strings.map(|string| to_ptr(*string));
@@ -1248,7 +1273,7 @@ pub fn glPolygonOffset(factor: GLfloat, units: GLfloat);

pub fn glPolygonMode(face: GLenum, mode: GLenum);

pub fn glReadPixels(x: GLint, y: GLint, width: GLsizei, height: GLsizei, format: GLenum, _type: GLenum, pixels: *GLvoid);
pub fn glReadPixels(x: GLint, y: GLint, width: GLsizei, height: GLsizei, format: GLenum, _type: GLenum, pixels: *mut GLvoid);

// Unsupported on Mac:
// fn glReleaseShaderCompiler();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.