aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2016-01-18 23:07:31 +0100
committertomaka <pierre.krieger1708@gmail.com>2016-01-18 23:07:31 +0100
commit1113fa1c138e8aa06213d7e74e9ed4a971bd10b7 (patch)
tree55c918c4bb359bcb5bdd716e9cbcf00de0220c50 /tests
parent0297efb7411c9d45aacebd1e3f52601d7b4fa961 (diff)
parent2a66d1cffccd74db2dd52925da31860f9330f27e (diff)
downloadglutin-1113fa1c138e8aa06213d7e74e9ed4a971bd10b7.tar.gz
glutin-1113fa1c138e8aa06213d7e74e9ed4a971bd10b7.zip
Merge pull request #703 from FredrikNoren/master
Fix cocoa headless. Fixes #635
Diffstat (limited to 'tests')
-rw-r--r--tests/headless.rs53
1 files changed, 43 insertions, 10 deletions
diff --git a/tests/headless.rs b/tests/headless.rs
index fdbb6c2..c22be40 100644
--- a/tests/headless.rs
+++ b/tests/headless.rs
@@ -1,28 +1,61 @@
extern crate glutin;
extern crate libc;
+use glutin::*;
+use std::ptr;
mod gl {
+ pub use self::Gles2 as Gl;
include!(concat!(env!("OUT_DIR"), "/test_gl_bindings.rs"));
}
+use gl::types::*;
-#[cfg(feature = "headless")]
+
+#[cfg(target_os = "macos")]
#[test]
-fn main() {
- let window = glutin::HeadlessRendererBuilder::new(1024, 768).build().unwrap();
+fn test_headless() {
+ let width: i32 = 256;
+ let height: i32 = 256;
+ let window = glutin::HeadlessRendererBuilder::new(width as u32, height as u32).build().unwrap();
unsafe { window.make_current() };
- let gl = gl::Gl::load_with(|symbol| window.get_proc_address(symbol));
+ let gl = gl::Gl::load_with(|symbol| window.get_proc_address(symbol) as *const _);
unsafe {
+ 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());
+ gl.FramebufferTexture2D(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, texture, 0);
+ let status = gl.CheckFramebufferStatus(gl::FRAMEBUFFER);
+ if status != gl::FRAMEBUFFER_COMPLETE {
+ panic!("Error while creating the framebuffer");
+ }
+
gl.ClearColor(0.0, 1.0, 0.0, 1.0);
gl.Clear(gl::COLOR_BUFFER_BIT);
+ 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);
- let mut value: (u8, u8, u8, u8) = std::mem::uninitialized();
- gl.ReadPixels(0, 0, 1, 1, gl::RGBA, gl::UNSIGNED_BYTE, std::mem::transmute(&mut value));
-
- assert!(value == (0, 255, 0, 255) || value == (0, 64, 0, 255) ||
- value == (0, 64, 0, 255) || value == (0, 64, 0, 0),
- "value is: {:?}", value);
+ assert_eq!(values[4], 255);
+ assert_eq!(values[5], 0);
+ assert_eq!(values[6], 0);
+ assert_eq!(values[7], 255);
}
}