1 extern crate khronos_egl as egl; 2 use egl::{EGL1_2, EGL1_4}; 3 use std::sync::Arc; 4 main()5fn main() { 6 let minimal_egl = 7 unsafe { Arc::new(egl::DynamicInstance::load().expect("unable to load libEGL.so.1")) }; 8 9 println!("EGL version is {}", minimal_egl.version()); 10 11 // Select the rendering API. 12 if let Some(egl1_2) = minimal_egl.upcast::<EGL1_2>() { 13 println!("selecting API"); 14 egl1_2 15 .bind_api(egl::OPENGL_API) 16 .expect("unable to select OpenGL API"); 17 } 18 19 // Setup Open GL. 20 gl::load_with(|name| minimal_egl.get_proc_address(name).unwrap() as *const std::ffi::c_void); 21 22 match minimal_egl.upcast::<EGL1_4>() { 23 Some(egl1_4) => foo_with_1_4(egl1_4), 24 None => foo_without_1_4(&minimal_egl), 25 } 26 } 27 foo_with_1_4<V: egl::api::EGL1_4>(_egl: &egl::Instance<V>)28fn foo_with_1_4<V: egl::api::EGL1_4>(_egl: &egl::Instance<V>) { 29 println!("with 1.4"); 30 // do something that requires at least EGL 1.4. 31 } 32 foo_without_1_4<V>(_egl: &egl::Instance<V>)33fn foo_without_1_4<V>(_egl: &egl::Instance<V>) { 34 println!("without 1.4"); 35 // do something without any specific EGL version (other that 1.0). 36 } 37