summaryrefslogtreecommitdiffstats
path: root/third_party/rust/khronos-egl/examples/load-minimal.rs
blob: 409376d6787d6f285a9e1b68b76d3508b076cae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
extern crate gl;
extern crate khronos_egl as egl;
extern crate libloading;

use std::sync::Arc;
use egl::{
	EGL1_2,
	EGL1_4
};

fn main() {
	let minimal_egl = unsafe { Arc::new(egl::DynamicInstance::load().expect("unable to load libEGL.so.1")) };

	println!("EGL version is {}", minimal_egl.version());

	// Select the rendering API.
	if let Some(egl1_2) = minimal_egl.upcast::<EGL1_2>() {
		println!("selecting API");
		 egl1_2.bind_api(egl::OPENGL_API).expect("unable to select OpenGL API");
	}

	// Setup Open GL.
	gl::load_with(|name| minimal_egl.get_proc_address(name).unwrap() as *const std::ffi::c_void);

	match minimal_egl.upcast::<EGL1_4>() {
		Some(egl1_4) => {
			foo_with_1_4(egl1_4)
		},
		None => {
			foo_without_1_4(&minimal_egl)
		}
	}
}

fn foo_with_1_4<V: egl::api::EGL1_4>(_egl: &egl::Instance<V>) {
	println!("with 1.4");
	// do something that requires at least EGL 1.4.
}

fn foo_without_1_4<V>(_egl: &egl::Instance<V>) {
	println!("without 1.4");
	// do something without any specific EGL version (other that 1.0).
}