aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs64
1 files changed, 58 insertions, 6 deletions
diff --git a/src/lib.rs b/src/lib.rs
index b12b894..974ef0b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -53,7 +53,6 @@ extern crate glutin_core_graphics as core_graphics;
extern crate x11;
pub use events::*;
-#[cfg(feature = "headless")]
pub use headless::{HeadlessRendererBuilder, HeadlessContext};
#[cfg(feature = "window")]
pub use window::{WindowBuilder, Window, WindowProxy, PollEventsIterator, WaitEventsIterator};
@@ -65,11 +64,38 @@ pub use native_monitor::NativeMonitorId;
mod api;
mod platform;
mod events;
-#[cfg(feature = "headless")]
mod headless;
#[cfg(feature = "window")]
mod window;
+/// Trait that describes objects that have access to an OpenGL context.
+pub trait GlContext {
+ /// Sets the context as the current context.
+ unsafe fn make_current(&self);
+
+ /// Returns true if this context is the current one in this thread.
+ fn is_current(&self) -> bool;
+
+ /// Returns the address of an OpenGL function.
+ fn get_proc_address(&self, addr: &str) -> *const libc::c_void;
+
+ /// Swaps the buffers in case of double or triple buffering.
+ ///
+ /// You should call this function every time you have finished rendering, or the image
+ /// may not be displayed on the screen.
+ ///
+ /// **Warning**: if you enabled vsync, this function will block until the next time the screen
+ /// is refreshed. However drivers can choose to override your vsync settings, which means that
+ /// you can't know in advance whether `swap_buffers` will block or not.
+ fn swap_buffers(&self);
+
+ /// Returns the OpenGL API being used.
+ fn get_api(&self) -> Api;
+
+ /// Returns the pixel format of the main framebuffer of the context.
+ fn get_pixel_format(&self) -> PixelFormat;
+}
+
/// Error that can happen while creating a window or a headless renderer.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CreationError {
@@ -109,6 +135,15 @@ pub enum Api {
WebGl,
}
+/// Describes the requested OpenGL context profiles.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum GlProfile {
+ /// Include all the immediate more functions and definitions.
+ Compatibility,
+ /// Include all the future-compatible functions and definitions.
+ Core,
+}
+
/// Describes the OpenGL API and version that are being requested when a context is created.
#[derive(Debug, Copy, Clone)]
pub enum GlRequest {
@@ -133,6 +168,22 @@ pub enum GlRequest {
},
}
+impl GlRequest {
+ /// Extract the desktop GL version, if any.
+ 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,
+ }
+ }
+}
+
+/// The minimum core profile GL context. Useful for getting the minimum
+/// required GL version while still running on OSX, which often forbids
+/// the compatibility profile features.
+pub static GL_CORE: GlRequest = GlRequest::Specific(Api::OpenGl, (3, 2));
+
#[derive(Debug, Copy, Clone)]
pub enum MouseCursor {
/// The platform-dependent default cursor.
@@ -211,9 +262,7 @@ pub enum CursorState {
#[derive(Debug, Clone)]
pub struct PixelFormat {
pub hardware_accelerated: bool,
- pub red_bits: u8,
- pub green_bits: u8,
- pub blue_bits: u8,
+ pub color_bits: u8,
pub alpha_bits: u8,
pub depth_bits: u8,
pub stencil_bits: u8,
@@ -235,6 +284,7 @@ pub struct BuilderAttribs<'a> {
title: String,
monitor: Option<platform::MonitorID>,
gl_version: GlRequest,
+ gl_profile: Option<GlProfile>,
gl_debug: bool,
vsync: bool,
visible: bool,
@@ -257,6 +307,7 @@ impl BuilderAttribs<'static> {
title: "glutin window".to_string(),
monitor: None,
gl_version: GlRequest::Latest,
+ gl_profile: None,
gl_debug: cfg!(debug_assertions),
vsync: false,
visible: true,
@@ -283,6 +334,7 @@ impl<'a> BuilderAttribs<'a> {
title: self.title,
monitor: self.monitor,
gl_version: self.gl_version,
+ gl_profile: self.gl_profile,
gl_debug: self.gl_debug,
vsync: self.vsync,
visible: self.visible,
@@ -306,7 +358,7 @@ impl<'a> BuilderAttribs<'a> {
// TODO: do this more properly
for (id, format) in iter {
- if format.red_bits + format.green_bits + format.blue_bits < self.color_bits.unwrap_or(0) {
+ if format.color_bits < self.color_bits.unwrap_or(0) {
continue;
}