#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate shared_library;
extern crate libc;
#[cfg(target_os = "windows")]
extern crate winapi;
#[cfg(target_os = "windows")]
extern crate kernel32;
#[cfg(target_os = "windows")]
extern crate shell32;
#[cfg(target_os = "windows")]
extern crate gdi32;
#[cfg(target_os = "windows")]
extern crate user32;
#[cfg(target_os = "windows")]
extern crate dwmapi;
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[macro_use]
extern crate objc;
#[cfg(target_os = "macos")]
extern crate cgl;
#[cfg(target_os = "macos")]
extern crate cocoa;
#[cfg(target_os = "macos")]
extern crate core_foundation;
#[cfg(target_os = "macos")]
extern crate core_graphics;
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
extern crate x11_dl;
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))]
#[macro_use(wayland_env)]
extern crate wayland_client;
pub use events::*;
pub use headless::{HeadlessRendererBuilder, HeadlessContext};
pub use window::{WindowBuilder, WindowProxy, PollEventsIterator, WaitEventsIterator};
pub use window::{AvailableMonitorsIter, MonitorId, get_available_monitors, get_primary_monitor};
pub use native_monitor::NativeMonitorId;
use std::io;
#[cfg(not(target_os = "macos"))]
use std::cmp::Ordering;
mod api;
mod platform;
mod events;
mod headless;
mod window;
pub mod os;
pub struct Window {
window: platform::Window,
}
pub trait GlContext {
unsafe fn make_current(&self) -> Result<(), ContextError>;
fn is_current(&self) -> bool;
fn get_proc_address(&self, addr: &str) -> *const ();
fn swap_buffers(&self) -> Result<(), ContextError>;
fn get_api(&self) -> Api;
fn get_pixel_format(&self) -> PixelFormat;
}
#[derive(Debug)]
pub enum CreationError {
OsError(String),
NotSupported,
NoBackendAvailable(Box<std::error::Error + Send>),
RobustnessNotSupported,
OpenGlVersionNotSupported,
NoAvailablePixelFormat,
}
impl CreationError {
fn to_string(&self) -> &str {
match *self {
CreationError::OsError(ref text) => &text,
CreationError::NotSupported => "Some of the requested attributes are not supported",
CreationError::NoBackendAvailable(_) => "No backend is available",
CreationError::RobustnessNotSupported => "You requested robustness, but it is \
not supported.",
CreationError::OpenGlVersionNotSupported => "The requested OpenGL version is not \
supported.",
CreationError::NoAvailablePixelFormat => "Couldn't find any pixel format that matches \
the criterias.",
}
}
}
impl std::fmt::Display for CreationError {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
formatter.write_str(self.to_string())
}
}
impl std::error::Error for CreationError {
fn description(&self) -> &str {
self.to_string()
}
fn cause(&self) -> Option<&std::error::Error> {
match *self {
CreationError::NoBackendAvailable(ref err) => Some(&**err),
_ => None
}
}
}
#[derive(Debug)]
pub enum ContextError {
IoError(io::Error),
ContextLost,
}
impl ContextError {
fn to_string(&self) -> &str {
use std::error::Error;
match *self {
ContextError::IoError(ref err) => err.description(),
ContextError::ContextLost => "Context lost"
}
}
}
impl std::fmt::Display for ContextError {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
formatter.write_str(self.to_string())
}
}
impl std::error::Error for ContextError {
fn description(&self) -> &str {
self.to_string()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Api {
OpenGl,
OpenGlEs,
WebGl,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GlProfile {
Compatibility,
Core,
}
#[derive(Debug, Copy, Clone)]
pub enum GlRequest {
Latest,
Specific(Api, (u8, u8)),
GlThenGles {
opengl_version: (u8, u8),
opengles_version: (u8, u8),
},
}
impl GlRequest {
pub fn to_gl_version(&self) -> Option<(u8, u8)> {
match self {
&GlRequest::Specific(Api::OpenGl, version) => Some(version),
&GlRequest::GlThenGles { opengl_version: version, .. } => Some(version),
_ => None,
}
}
}
pub static GL_CORE: GlRequest = GlRequest::Specific(Api::OpenGl, (3, 2));
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Robustness {
NotRobust,
NoError,
RobustNoResetNotification,
TryRobustNoResetNotification,
RobustLoseContextOnReset,
TryRobustLoseContextOnReset,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ReleaseBehavior {
None,
Flush,
}
#[derive(Debug, Copy, Clone)]
pub enum MouseCursor {
Default,
Crosshair,
Hand,
Arrow,
Move,
Text,
Wait,
Help,
Progress,
NotAllowed,
ContextMenu,
NoneCursor,
Cell,
VerticalText,
Alias,
Copy,
NoDrop,
Grab,
Grabbing,
AllScroll,
ZoomIn,
ZoomOut,
EResize,
NResize,
NeResize,
NwResize,
SResize,
SeResize,
SwResize,
WResize,
EwResize,
NsResize,
NeswResize,
NwseResize,
ColResize,
RowResize,
}
#[derive(Debug, Copy, Clone)]
pub enum CursorState {
Normal,
Hide,
Grab,
}
#[allow(missing_docs)]
#[derive(Debug, Clone)]
pub struct PixelFormat {
pub hardware_accelerated: bool,
pub color_bits: u8,
pub alpha_bits: u8,
pub depth_bits: u8,
pub stencil_bits: u8,
pub stereoscopy: bool,
pub double_buffer: bool,
pub multisampling: Option<u16>,
pub srgb: bool,
}
#[derive(Clone, Debug)]
pub struct PixelFormatRequirements {
pub hardware_accelerated: Option<bool>,
pub color_bits: Option<u8>,
pub float_color_buffer: bool,
pub alpha_bits: Option<u8>,
pub depth_bits: Option<u8>,
pub stencil_bits: Option<u8>,
pub double_buffer: Option<bool>,
pub multisampling: Option<u16>,
pub stereoscopy: bool,
pub srgb: bool,
pub release_behavior: ReleaseBehavior,
}
impl Default for PixelFormatRequirements {
#[inline]
fn default() -> PixelFormatRequirements {
PixelFormatRequirements {
hardware_accelerated: Some(true),
color_bits: Some(24),
float_color_buffer: false,
alpha_bits: Some(8),
depth_bits: Some(24),
stencil_bits: Some(8),
double_buffer: None,
multisampling: None,
stereoscopy: false,
srgb: false,
release_behavior: ReleaseBehavior::Flush,
}
}
}
#[derive(Clone)]
pub struct WindowAttributes {
pub dimensions: Option<(u32, u32)>,
pub min_dimensions: Option<(u32, u32)>,
pub max_dimensions: Option<(u32, u32)>,
pub monitor: Option<platform::MonitorId>,
pub title: String,
pub visible: bool,
pub transparent: bool,
pub decorations: bool,
pub multitouch: bool,
}
impl Default for WindowAttributes {
#[inline]
fn default() -> WindowAttributes {
WindowAttributes {
dimensions: None,
min_dimensions: None,
max_dimensions: None,
monitor: None,
title: "glutin window".to_owned(),
visible: true,
transparent: false,
decorations: true,
multitouch: false,
}
}
}
#[derive(Clone)]
pub struct GlAttributes<S> {
pub sharing: Option<S>,
pub version: GlRequest,
pub profile: Option<GlProfile>,
pub debug: bool,
pub robustness: Robustness,
pub vsync: bool,
}
impl<S> GlAttributes<S> {
#[inline]
pub fn map_sharing<F, T>(self, f: F) -> GlAttributes<T> where F: FnOnce(S) -> T {
GlAttributes {
sharing: self.sharing.map(f),
version: self.version,
profile: self.profile,
debug: self.debug,
robustness: self.robustness,
vsync: self.vsync,
}
}
}
impl<S> Default for GlAttributes<S> {
#[inline]
fn default() -> GlAttributes<S> {
GlAttributes {
sharing: None,
version: GlRequest::Latest,
profile: None,
debug: cfg!(debug_assertions),
robustness: Robustness::NotRobust,
vsync: false,
}
}
}
mod native_monitor {
#[derive(Clone, PartialEq, Eq)]
pub enum NativeMonitorId {
Numeric(u32),
Name(String),
Unavailable
}
}