Expand description
This crate provides a binding for the Khronos EGL 1.5 API. It was originally a fork of the egl crate, which is left unmaintained.
§Usage
You can access the EGL API using an Instance
object defined by either statically linking with libEGL.so.1
at compile time,
or dynamically loading the EGL library at runtime.
§Static linking
You must enable static linking using the static
feature in your Cargo.toml
:
khronos-egl = { version = ..., features = ["static"] }
This will add a dependency to the pkg-config
crate,
necessary to find the EGL library at compile time.
Here is a simple example showing how to use this library to create an EGL context when static linking is enabled.
extern crate khronos_egl as egl;
fn main() -> Result<(), egl::Error> {
// Create an EGL API instance.
// The `egl::Static` API implementation is only available when the `static` feature is enabled.
let egl = egl::Instance::new(egl::Static);
let wayland_display = wayland_client::Display::connect_to_env().expect("unable to connect to the wayland server");
let display = unsafe { egl.get_display(wayland_display.get_display_ptr() as *mut std::ffi::c_void) }.unwrap();
egl.initialize(display)?;
let attributes = [
egl::RED_SIZE, 8,
egl::GREEN_SIZE, 8,
egl::BLUE_SIZE, 8,
egl::NONE
];
let config = egl.choose_first_config(display, &attributes)?.expect("unable to find an appropriate ELG configuration");
let context_attributes = [
egl::CONTEXT_MAJOR_VERSION, 4,
egl::CONTEXT_MINOR_VERSION, 0,
egl::CONTEXT_OPENGL_PROFILE_MASK, egl::CONTEXT_OPENGL_CORE_PROFILE_BIT,
egl::NONE
];
egl.create_context(display, config, None, &context_attributes);
Ok(())
}
The creation of a Display
instance is not detailed here since it depends on your display server.
It is created using the get_display
function with a pointer to the display server connection handle.
For instance, if you are using the wayland-client crate,
you can get this pointer using the Display::get_display_ptr
method.
§Static API Instance
It may be bothering in some applications to pass the Instance
to every fonction that needs to call the EGL API.
One workaround would be to define a static Instance
,
which should be possible to define at compile time using static linking.
However this is not yet supported by the stable rustc
compiler.
With the nightly compiler,
you can combine the nightly
and static
features so that this crate
can provide a static Instance
, called API
that can then be accessed everywhere.
use egl::API as egl;
§Dynamic Linking
Dynamic linking allows your application to accept multiple versions of EGL and be more flexible.
You must enable dynamic linking using the dynamic
feature in your Cargo.toml
:
khronos-egl = { version = ..., features = ["dynamic"] }
This will add a dependency to the libloading
crate,
necessary to find the EGL library at runtime.
You can then load the EGL API into a Instance<Dynamic<libloading::Library>>
as follows:
let lib = unsafe { libloading::Library::new("libEGL.so.1") }.expect("unable to find libEGL.so.1");
let egl = unsafe { egl::DynamicInstance::<egl::EGL1_4>::load_required_from(lib) }.expect("unable to load libEGL.so.1");
Here, egl::EGL1_4
is used to specify what is the minimum required version of EGL that must be provided by libEGL.so.1
.
This will return a DynamicInstance<egl::EGL1_4>
, however in that case where libEGL.so.1
provides a more recent version of EGL,
you can still upcast ths instance to provide version specific features:
match egl.upcast::<egl::EGL1_5>() {
Some(egl1_5) => {
// do something with EGL 1.5
}
None => {
// do something with EGL 1.4 instead.
}
};
§Troubleshooting
§Static Linking with OpenGL ES
When using OpenGL ES with khronos-egl
with the static
feature,
it is necessary to place a dummy extern at the top of your application which links libEGL first, then GLESv1/2.
This is because libEGL provides symbols required by GLESv1/2.
Here’s how to work around this:
#[link(name = "EGL")]
#[link(name = "GLESv2")]
extern {}
Modules§
Structs§
Enums§
Constants§
- ALPHA_
FORMAT - ALPHA_
FORMAT_ NONPRE - ALPHA_
FORMAT_ PRE - ALPHA_
MASK_ SIZE - ALPHA_
SIZE - ATTRIB_
NONE - BACK_
BUFFER - BAD_
ACCESS - BAD_
ALLOC - BAD_
ATTRIBUTE - BAD_
CONFIG - BAD_
CONTEXT - BAD_
CURRENT_ SURFACE - BAD_
DISPLAY - BAD_
MATCH - BAD_
NATIVE_ PIXMAP - BAD_
NATIVE_ WINDOW - BAD_
PARAMETER - BAD_
SURFACE - BIND_
TO_ TEXTURE_ RGB - BIND_
TO_ TEXTURE_ RGBA - BLUE_
SIZE - BUFFER_
DESTROYED - BUFFER_
PRESERVED - BUFFER_
SIZE - CLIENT_
APIS - CL_
EVENT_ HANDLE - COLORSPACE
- COLORSPACE_
LINEAR - COLORSPACE_
sRGB - COLOR_
BUFFER_ TYPE - CONDITION_
SATISFIED - CONFIG_
CAVEAT - CONFIG_
ID - CONFORMANT
- CONTEXT_
CLIENT_ TYPE - CONTEXT_
CLIENT_ VERSION - CONTEXT_
LOST - CONTEXT_
MAJOR_ VERSION - CONTEXT_
MINOR_ VERSION - CONTEXT_
OPENGL_ COMPATIBILITY_ PROFILE_ BIT - CONTEXT_
OPENGL_ CORE_ PROFILE_ BIT - CONTEXT_
OPENGL_ DEBUG - CONTEXT_
OPENGL_ FORWARD_ COMPATIBLE - CONTEXT_
OPENGL_ PROFILE_ MASK - CONTEXT_
OPENGL_ RESET_ NOTIFICATION_ STRATEGY - CONTEXT_
OPENGL_ ROBUST_ ACCESS - CORE_
NATIVE_ ENGINE - DEFAULT_
DISPLAY - DEPTH_
SIZE - DISPLAY_
SCALING - DONT_
CARE - DRAW
- EXTENSIONS
- FALSE
- FOREVER
- GL_
COLORSPACE - GL_
COLORSPACE_ LINEAR - GL_
COLORSPACE_ SRGB - GL_
RENDERBUFFER - GL_
TEXTURE_ 2D - GL_
TEXTURE_ 3D - GL_
TEXTURE_ CUBE_ MAP_ NEGATIVE_ X - GL_
TEXTURE_ CUBE_ MAP_ NEGATIVE_ Y - GL_
TEXTURE_ CUBE_ MAP_ NEGATIVE_ Z - GL_
TEXTURE_ CUBE_ MAP_ POSITIVE_ X - GL_
TEXTURE_ CUBE_ MAP_ POSITIVE_ Y - GL_
TEXTURE_ CUBE_ MAP_ POSITIVE_ Z - GL_
TEXTURE_ LEVEL - GL_
TEXTURE_ ZOFFSET - GREEN_
SIZE - HEIGHT
- HORIZONTAL_
RESOLUTION - IMAGE_
PRESERVED - LARGEST_
PBUFFER - LATEST
- Latest available EGL version.
- LEVEL
- LOSE_
CONTEXT_ ON_ RESET - LUMINANCE_
BUFFER - LUMINANCE_
SIZE - MATCH_
NATIVE_ PIXMAP - MAX_
PBUFFER_ HEIGHT - MAX_
PBUFFER_ PIXELS - MAX_
PBUFFER_ WIDTH - MAX_
SWAP_ INTERVAL - MIN_
SWAP_ INTERVAL - MIPMAP_
LEVEL - MIPMAP_
TEXTURE - MULTISAMPLE_
RESOLVE - MULTISAMPLE_
RESOLVE_ BOX - MULTISAMPLE_
RESOLVE_ BOX_ BIT - MULTISAMPLE_
RESOLVE_ DEFAULT - NATIVE_
RENDERABLE - NATIVE_
VISUAL_ ID - NATIVE_
VISUAL_ TYPE - NONE
- NON_
CONFORMANT_ CONFIG - NOT_
INITIALIZED - NO_
CONTEXT - NO_
DISPLAY - NO_
IMAGE - NO_
RESET_ NOTIFICATION - NO_
SURFACE - NO_SYNC
- NO_
TEXTURE - OPENGL_
API - OPENGL_
BIT - OPENGL_
ES2_ BIT - OPENGL_
ES3_ BIT - OPENGL_
ES_ API - OPENGL_
ES_ BIT - OPENVG_
API - OPENVG_
BIT - OPENVG_
IMAGE - PBUFFER_
BIT - PIXEL_
ASPECT_ RATIO - PIXMAP_
BIT - READ
- RED_
SIZE - RENDERABLE_
TYPE - RENDER_
BUFFER - RGB_
BUFFER - SAMPLES
- SAMPLE_
BUFFERS - SIGNALED
- SINGLE_
BUFFER - SLOW_
CONFIG - STENCIL_
SIZE - SUCCESS
- SURFACE_
TYPE - SWAP_
BEHAVIOR - SWAP_
BEHAVIOR_ PRESERVED_ BIT - SYNC_
CL_ EVENT - SYNC_
CL_ EVENT_ COMPLETE - SYNC_
CONDITION - SYNC_
FENCE - SYNC_
FLUSH_ COMMANDS_ BIT - SYNC_
PRIOR_ COMMANDS_ COMPLETE - SYNC_
STATUS - SYNC_
TYPE - TEXTURE_
2D - TEXTURE_
FORMAT - TEXTURE_
RGB - TEXTURE_
RGBA - TEXTURE_
TARGET - TIMEOUT_
EXPIRED - TRANSPARENT_
BLUE_ VALUE - TRANSPARENT_
GREEN_ VALUE - TRANSPARENT_
RED_ VALUE - TRANSPARENT_
RGB - TRANSPARENT_
TYPE - TRUE
- UNKNOWN
- UNSIGNALED
- VENDOR
- VERSION
- VERTICAL_
RESOLUTION - VG_
ALPHA_ FORMAT - VG_
ALPHA_ FORMAT_ NONPRE - VG_
ALPHA_ FORMAT_ PRE - VG_
ALPHA_ FORMAT_ PRE_ BIT - VG_
COLORSPACE - VG_
COLORSPACE_ LINEAR - VG_
COLORSPACE_ LINEAR_ BIT - VG_
COLORSPACE_ sRGB - WIDTH
- WINDOW_
BIT