[go: up one dir, main page]

egli/
lib.rs

1// Copyright 2016 The EGLI Developers
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8/*!
9# EGLI - Higher-level EGL Interface
10*/
11
12extern crate libc;
13#[macro_use]
14extern crate bitflags;
15
16pub mod egl;
17pub mod ffi;
18pub mod error;
19
20mod display;
21mod context;
22mod window_surface;
23mod config_filter;
24mod frame_buffer_config;
25mod version;
26
27pub use display::{Display, ContextClientVersion};
28pub use context::Context;
29pub use window_surface::Surface;
30pub use config_filter::ConfigFilterRef;
31pub use frame_buffer_config::FrameBufferConfigRef;
32pub use version::Version;
33
34use std::mem;
35
36/// `[EGL 1.5]` Get supported EGL client version.
37///
38/// Returns a version or release number.
39/// The EGL_VERSION string is laid out as follows:
40///
41/// `major_version.minor_version space vendor_specific_info`
42///
43/// Both the major and minor portions of the version number are numeric.
44/// Their values must match the major and minor values returned by `Display::initialize`.
45#[cfg(feature = "egl_1_5")]
46pub fn query_version() -> error::Result<&'static str> {
47    let cstr = egl::query_string(egl::EGL_NO_DISPLAY, egl::EGL_VERSION)?;
48    Ok(cstr.to_str()?)
49}
50
51/// `[EGL 1.0]` Get all supported client extensions.
52///
53/// Returns a space separated list of supported extensions.
54pub fn query_extensions() -> error::Result<&'static str> {
55    let cstr = egl::query_string(egl::EGL_NO_DISPLAY, egl::EGL_EXTENSIONS)?;
56    Ok(cstr.to_str()?)
57}
58
59#[repr(i32)]
60#[derive(Copy, Clone, Debug)]
61pub enum ColorBufferType {
62    Rgb = 0x308E,
63    Luminance = 0x308F,
64}
65
66impl ColorBufferType {
67    pub unsafe fn from_raw(value: egl::EGLint) -> ColorBufferType {
68        mem::transmute(value as i32)
69    }
70}
71
72#[repr(i32)]
73#[derive(Copy, Clone, Debug)]
74pub enum ConfigCaveat {
75    None = 0x3038,
76    Slow = 0x3050,
77    NonConformant = 0x3051,
78}
79
80impl ConfigCaveat {
81    pub unsafe fn from_raw(value: egl::EGLint) -> ConfigCaveat {
82        mem::transmute(value as i32)
83    }
84}
85
86#[repr(i32)]
87#[derive(Copy, Clone, Debug)]
88pub enum TransparentType {
89    None = 0x3038,
90    TransparentRgb = 0x3052,
91}
92
93impl TransparentType {
94    pub unsafe fn from_raw(value: egl::EGLint) -> TransparentType {
95        mem::transmute(value as i32)
96    }
97}
98
99bitflags! {
100    /// Renderable type mask bits.
101    pub struct RenderableType: i32 {
102        /// EGL_OPENGL_BIT
103        const OPENGL       = 0x0008;
104        /// EGL_OPENGL_ES_BIT
105        const OPENGL_ES    = 0x0001;
106        /// EGL_OPENGL_ES2_BIT
107        const OPENGL_ES2   = 0x0004;
108        /// EGL_OPENGL_ES3_BIT
109        const OPENGL_ES3   = 0x00000040;
110        /// EGL_OPENVG_BIT
111        const OPENVG       = 0x0002;
112    }
113}
114
115bitflags! {
116    /// Surface type mask bits.
117    pub struct SurfaceType: i32 {
118        /// EGL_PBUFFER_BIT
119        const PBUFFER                  = 0x0001;
120        /// EGL_PIXMAP_BIT
121        const PIXMAP                   = 0x0002;
122        /// EGL_WINDOW_BIT
123        const WINDOW                   = 0x0004;
124        /// EGL_VG_COLORSPACE_LINEAR_BIT
125        const VG_COLORSPACE_LINEAR     = 0x0020;
126        /// EGL_VG_ALPHA_FORMAT_PRE_BIT
127        const VG_ALPHA_FORMAT_PRE      = 0x0040;
128        /// EGL_MULTISAMPLE_RESOLVE_BOX_BIT
129        const MULTISAMPLE_RESOLVE_BOX  = 0x0200;
130        /// EGL_SWAP_BEHAVIOR_PRESERVED_BIT
131        const SWAP_BEHAVIOR_PRESERVED  = 0x0400;
132    }
133}