Skip to content

Commit

Permalink
Changes for Rust 2018. Removed distinction between `{Combined,
Browse files Browse the repository at this point in the history
Separated}Context`s. Style changes.

Signed-off-by: Hal Gentz <[email protected]>
  • Loading branch information
goddessfreya committed Feb 27, 2019
1 parent 23b3b10 commit a427abd
Show file tree
Hide file tree
Showing 40 changed files with 640 additions and 767 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
- Fixes `Context::is_current` incorrectly returning `false`.
- **Breaking:** Renamed `GlContext{,Ext}` to `ContextTrait{,Ext}`.
- Implemented context sharing support for Windows and Linux.
- Added `SeparatedContext`.
- **Breaking:** Renamed `GlWindow` to `CombinedContext`.
- Added support for separated contexts.
- **Breaking:** Removed `shareable_with_windowed_contexts`. Now you must build
OsMesa contexts via a separate extension.
- Added `ContextBuilder::build` method.
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme = "README.md"
repository = "https://github.com/tomaka/glutin"
documentation = "https://docs.rs/glutin"
build = "build.rs"
edition = "2018"

[package.metadata.docs.rs]
features = ["icon_loading", "serde"]
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ gl = "*"
```

```rust
extern crate gl;
extern crate glutin;

use glutin::dpi::*;
use glutin::ContextTrait;

Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate gl_generator;
extern crate gl_generator; // Needed for android for some reason

use gl_generator::{Api, Fallbacks, Profile, Registry};
use std::env;
Expand Down
2 changes: 0 additions & 2 deletions examples/fullscreen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate glutin;

mod support;

use glutin::ContextTrait;
Expand Down
2 changes: 0 additions & 2 deletions examples/multiwindow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate glutin;

mod support;

use glutin::ContextTrait;
Expand Down
25 changes: 14 additions & 11 deletions examples/separated_context.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
extern crate glutin;

mod support;

use glutin::ContextTrait;
use std::sync::Arc;

fn main() {
let mut el = glutin::EventsLoop::new();
let win = glutin::WindowBuilder::new()
.with_title("A fantastic window!")
.build(&el)
.unwrap();

let separated_context = glutin::ContextBuilder::new()
.build_separated(&win, &el)
.unwrap();
let (separated_context, mut el, win) = {
let el = glutin::EventsLoop::new();
let win = glutin::WindowBuilder::new()
.with_title("A fantastic window!")
.build(&el)
.unwrap();
let win = Arc::new(win);

let separated_context = glutin::ContextBuilder::new()
.build_separated(Arc::clone(&win), &el)
.unwrap();
(separated_context, el, win)
};

unsafe { separated_context.make_current().unwrap() }

Expand Down
2 changes: 0 additions & 2 deletions examples/sharing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Requires OpenGL 4.2 minimium.

extern crate glutin;

mod support;

use glutin::ContextTrait;
Expand Down
2 changes: 0 additions & 2 deletions examples/transparent.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate glutin;

mod support;

use glutin::ContextTrait;
Expand Down
2 changes: 0 additions & 2 deletions examples/window.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate glutin;

mod support;

use glutin::ContextTrait;
Expand Down
11 changes: 7 additions & 4 deletions src/api/android/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals,
)]

use libc;

use std::os::raw;

#[link(name = "android")]
Expand Down
35 changes: 14 additions & 21 deletions src/api/android/mod.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
#![cfg(target_os = "android")]

extern crate android_glue;

use libc;
mod ffi;

use CreationError::{self, OsError};
use crate::api::egl::{ffi, Context as EglContext, NativeDisplay};
use crate::CreationError::{self, OsError};
use crate::{
Api, ContextError, GlAttributes, PixelFormat, PixelFormatRequirements,
};

use libc;
use winit;
use winit::os::android::EventsLoopExt;

use Api;
use ContextError;
use GlAttributes;
use PixelFormat;
use PixelFormatRequirements;

use api::egl;
use api::egl::Context as EglContext;
use std::cell::Cell;
use std::sync::Arc;
use winit::os::android::EventsLoopExt;

mod ffi;

struct AndroidContext {
egl_context: EglContext,
Expand Down Expand Up @@ -65,9 +58,9 @@ impl Context {
if native_window.is_null() {
return Err(OsError(format!("Android's native window is null")));
}
let native_display = egl::NativeDisplay::Android;
let context = try!(EglContext::new(pf_reqs, &gl_attr, native_display)
.and_then(|p| p.finish(native_window as *const _)));
let native_display = NativeDisplay::Android;
let context = EglContext::new(pf_reqs, &gl_attr, native_display)
.and_then(|p| p.finish(native_window as *const _))?;
let ctx = Arc::new(AndroidContext {
egl_context: context,
stopped: Some(Cell::new(false)),
Expand Down Expand Up @@ -107,7 +100,7 @@ impl Context {
) -> Result<Self, CreationError> {
let gl_attr = gl_attr.clone().map_sharing(|c| &c.0.egl_context);
let context =
EglContext::new(pf_reqs, &gl_attr, egl::NativeDisplay::Android)?;
EglContext::new(pf_reqs, &gl_attr, NativeDisplay::Android)?;
let context = context.finish_pbuffer((1, 1))?; // TODO:
let ctx = Arc::new(AndroidContext {
egl_context: context,
Expand Down Expand Up @@ -172,12 +165,12 @@ impl Context {
}

#[inline]
pub unsafe fn raw_handle(&self) -> egl::ffi::EGLContext {
pub unsafe fn raw_handle(&self) -> ffi::EGLContext {
self.0.egl_context.raw_handle()
}

#[inline]
pub unsafe fn get_egl_display(&self) -> egl::ffi::EGLDisplay {
pub unsafe fn get_egl_display(&self) -> ffi::EGLDisplay {
self.0.egl_context.get_egl_display()
}
}
14 changes: 7 additions & 7 deletions src/api/caca/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
))]
#![allow(unused_variables, dead_code)]

use api::osmesa::OsMesaContext;
use libc;
mod ffi;

use {
use crate::api::osmesa::OsMesaContext;
use crate::{
Api, ContextError, CreationError, GlAttributes, PixelFormat,
PixelFormatRequirements,
};

use std::path::Path;
use std::ptr;
use libc;

mod ffi;
use std::path::Path;

pub struct Context {
opengl: OsMesaContext,
Expand Down Expand Up @@ -47,7 +46,8 @@ impl Context {
Ok(l) => l,
};

let display = unsafe { (libcaca.caca_create_display)(ptr::null_mut()) };
let display =
unsafe { (libcaca.caca_create_display)(std::ptr::null_mut()) };

if display.is_null() {
return Err(CreationError::OsError(
Expand Down
5 changes: 3 additions & 2 deletions src/api/dlloader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
target_os = "netbsd",
target_os = "openbsd"
))]

use libloading::Library;

use std::ffi::CString;
use std::ops::{Deref, DerefMut};
use std::sync::Arc;

use libloading::Library;

#[derive(Clone)]
pub struct SymWrapper<T> {
inner: T,
Expand Down
13 changes: 5 additions & 8 deletions src/api/egl/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#![allow(non_camel_case_types)]

#[cfg(target_os = "windows")]
extern crate winapi;

pub use self::egl::types::EGLContext;
pub use self::egl::types::EGLDisplay;

use libc;

pub mod egl {
pub type khronos_utime_nanoseconds_t = super::khronos_utime_nanoseconds_t;
pub type khronos_uint64_t = super::khronos_uint64_t;
Expand All @@ -23,6 +15,11 @@ pub mod egl {
include!(concat!(env!("OUT_DIR"), "/egl_bindings.rs"));
}

pub use self::egl::types::EGLContext;
pub use self::egl::types::EGLDisplay;

use libc;

pub type khronos_utime_nanoseconds_t = khronos_uint64_t;
pub type khronos_uint64_t = libc::uint64_t;
pub type khronos_ssize_t = libc::c_long;
Expand Down
Loading

0 comments on commit a427abd

Please sign in to comment.