[][src]Crate khronos_egl

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 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 = 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 = libloading::Library::new("libEGL.so").expect("unable to find libEGL.so");
let egl = unsafe { egl::DynamicInstance::<egl::EGL1_4>::load_required_from(lib).expect("unable to load libEGL.so") };

Here, egl::EGL1_4 is used to specify what is the minimum required version of EGL that must be provided by libEGL.so. This will return a DynamicInstance<egl::EGL1_4>, however in that case where libEGL.so 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

api

Structs

ClientBuffer
Config
Context
Display
Image
Instance

EGL API instance.

Surface
Sync

Enums

Error

EGL errors.

Version

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

Traits

Api

EGL API provider.

Downcast
Upcast

Functions

check_attrib_list
check_int_list

Type Definitions

Attrib
Boolean
EGLClientBuffer
EGLConfig
EGLContext
EGLDisplay
EGLImage
EGLSurface
EGLSync
Enum
Int
NativeDisplayType
NativePixmapType
NativeWindowType
Time