mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 05:21:31 +11:00
Detect OSMesa errors
This commit is contained in:
parent
37bdb997ce
commit
9b39d99f6e
|
@ -1,5 +1,5 @@
|
||||||
use HeadlessRendererBuilder;
|
use HeadlessRendererBuilder;
|
||||||
use CreationError;
|
use {CreationError, OsError};
|
||||||
use libc;
|
use libc;
|
||||||
use std::{mem, ptr};
|
use std::{mem, ptr};
|
||||||
use super::ffi;
|
use super::ffi;
|
||||||
|
@ -18,16 +18,23 @@ impl HeadlessContext {
|
||||||
height: builder.dimensions.1,
|
height: builder.dimensions.1,
|
||||||
buffer: Vec::from_elem(builder.dimensions.0 * builder.dimensions.1, unsafe { mem::uninitialized() }),
|
buffer: Vec::from_elem(builder.dimensions.0 * builder.dimensions.1, unsafe { mem::uninitialized() }),
|
||||||
context: unsafe {
|
context: unsafe {
|
||||||
// TODO: check errors
|
let ctxt = ffi::OSMesaCreateContext(0x1908, ptr::null());
|
||||||
ffi::OSMesaCreateContext(0x1908, ptr::null())
|
if ctxt.is_null() {
|
||||||
|
return Err(OsError("OSMesaCreateContext failed".to_string()));
|
||||||
|
}
|
||||||
|
ctxt
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn make_current(&self) {
|
pub unsafe fn make_current(&self) {
|
||||||
ffi::OSMesaMakeCurrent(self.context,
|
let ret = ffi::OSMesaMakeCurrent(self.context,
|
||||||
self.buffer.as_ptr() as *mut libc::c_void,
|
self.buffer.as_ptr() as *mut libc::c_void,
|
||||||
0x1401, self.width as libc::c_int, self.height as libc::c_int);
|
0x1401, self.width as libc::c_int, self.height as libc::c_int);
|
||||||
|
|
||||||
|
if ret == 0 {
|
||||||
|
panic!("OSMesaMakeCurrent failed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_proc_address(&self, addr: &str) -> *const () {
|
pub fn get_proc_address(&self, addr: &str) -> *const () {
|
||||||
|
|
|
@ -32,6 +32,7 @@ fn main() {
|
||||||
gl.ReadPixels(0, 0, 1, 1, gl::RGBA, gl::UNSIGNED_BYTE, std::mem::transmute(&mut value));
|
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) ||
|
assert!(value == (0, 255, 0, 255) || value == (0, 64, 0, 255) ||
|
||||||
value == (0, 64, 0, 255) || value == (0, 64, 0, 0));
|
value == (0, 64, 0, 255) || value == (0, 64, 0, 0),
|
||||||
|
"value is: {}", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue