2014-10-05 04:17:02 +11:00
|
|
|
extern crate glutin;
|
2014-10-12 05:38:52 +11:00
|
|
|
extern crate libc;
|
2016-01-08 16:03:54 +11:00
|
|
|
use glutin::*;
|
|
|
|
use std::ptr;
|
2014-10-12 05:38:52 +11:00
|
|
|
|
|
|
|
mod gl {
|
2016-01-19 04:45:55 +11:00
|
|
|
pub use self::Gles2 as Gl;
|
2014-12-24 18:09:16 +11:00
|
|
|
include!(concat!(env!("OUT_DIR"), "/test_gl_bindings.rs"));
|
2014-10-12 05:38:52 +11:00
|
|
|
}
|
2016-01-08 16:03:54 +11:00
|
|
|
use gl::types::*;
|
2014-10-05 04:17:02 +11:00
|
|
|
|
2016-01-10 05:32:48 +11:00
|
|
|
|
2016-01-10 06:31:56 +11:00
|
|
|
#[cfg(target_os = "macos")]
|
2014-10-05 04:17:02 +11:00
|
|
|
#[test]
|
2016-01-08 16:34:10 +11:00
|
|
|
fn test_headless() {
|
2016-01-08 16:35:51 +11:00
|
|
|
let width: i32 = 256;
|
|
|
|
let height: i32 = 256;
|
2016-01-08 16:03:54 +11:00
|
|
|
let window = glutin::HeadlessRendererBuilder::new(width as u32, height as u32).build().unwrap();
|
2014-10-05 04:17:02 +11:00
|
|
|
|
|
|
|
unsafe { window.make_current() };
|
|
|
|
|
2016-01-08 16:03:54 +11:00
|
|
|
let gl = gl::Gl::load_with(|symbol| window.get_proc_address(symbol) as *const _);
|
2014-10-12 05:38:52 +11:00
|
|
|
|
2014-11-06 01:22:21 +11:00
|
|
|
unsafe {
|
2016-01-08 16:03:54 +11:00
|
|
|
let mut framebuffer = 0;
|
|
|
|
let mut texture = 0;
|
|
|
|
gl.GenFramebuffers(1, &mut framebuffer);
|
|
|
|
gl.BindFramebuffer(gl::FRAMEBUFFER, framebuffer);
|
|
|
|
gl.GenTextures(1, &mut texture);
|
|
|
|
gl.BindTexture(gl::TEXTURE_2D, texture);
|
|
|
|
gl.TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as i32);
|
|
|
|
gl.TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32);
|
|
|
|
gl.TexImage2D(gl::TEXTURE_2D, 0, gl::RGBA as i32, width, height,
|
|
|
|
0, gl::RGBA, gl::UNSIGNED_BYTE, ptr::null());
|
2016-01-19 04:45:55 +11:00
|
|
|
gl.FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, texture, 0);
|
2016-01-08 16:03:54 +11:00
|
|
|
let status = gl.CheckFramebufferStatus(gl::FRAMEBUFFER);
|
|
|
|
if status != gl::FRAMEBUFFER_COMPLETE {
|
|
|
|
panic!("Error while creating the framebuffer");
|
|
|
|
}
|
|
|
|
|
2014-11-06 01:22:21 +11:00
|
|
|
gl.ClearColor(0.0, 1.0, 0.0, 1.0);
|
|
|
|
gl.Clear(gl::COLOR_BUFFER_BIT);
|
2016-01-08 16:03:54 +11:00
|
|
|
gl.Enable(gl::SCISSOR_TEST);
|
|
|
|
gl.Scissor(1, 0, 1, 1);
|
|
|
|
gl.ClearColor(1.0, 0.0, 0.0, 1.0);
|
|
|
|
gl.Clear(gl::COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
let mut values: Vec<u8> = vec![0;(width*height*4) as usize];
|
|
|
|
gl.ReadPixels(0, 0, width, height, gl::RGBA, gl::UNSIGNED_BYTE, values.as_mut_ptr() as *mut GLvoid);
|
|
|
|
|
|
|
|
assert_eq!(values[0], 0);
|
|
|
|
assert_eq!(values[1], 255);
|
|
|
|
assert_eq!(values[2], 0);
|
|
|
|
assert_eq!(values[3], 255);
|
2014-11-06 01:22:21 +11:00
|
|
|
|
2016-01-08 16:03:54 +11:00
|
|
|
assert_eq!(values[4], 255);
|
|
|
|
assert_eq!(values[5], 0);
|
|
|
|
assert_eq!(values[6], 0);
|
|
|
|
assert_eq!(values[7], 255);
|
2014-11-06 01:22:21 +11:00
|
|
|
}
|
2014-10-05 04:17:02 +11:00
|
|
|
}
|