Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for Rust 2018. Removed distinction between {Combined,Separated}Contexts. Style changes. #1105

Merged
merged 2 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
android-test:
working_directory: ~/glutin
docker:
- image: tomaka/cargo-apk
- image: gentz/android-rs-glue
steps:
- run: apt-get -qq update && apt-get install -y git
- checkout
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
- We no longer load `libegl.so` and `libgl.so` multiple times.
- Fixes `Context::is_current` incorrectly returning `false`.
- **Breaking:** Renamed `GlContext{,Ext}` to `ContextTrait{,Ext}`.
- **Breaking:** Renamed `GlWindow` to `WindowedContext`.
- 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
69 changes: 38 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,70 +17,77 @@ glutin = "*"

## [Documentation](https://docs.rs/glutin)

## Try it!
## Usage Examples

Warning: these are examples for master. For the latest released version, 0.19, view [here](https://github.com/tomaka/glutin/tree/72e8c959c4ff538857d028167b9946b8938bdeaa).

### Try it!

```bash
git clone https://github.com/tomaka/glutin
cd glutin
cargo run --example window
```

## Usage
### Usage

Glutin is an OpenGL context creation library and doesn't directly provide OpenGL bindings for you.

```toml
[dependencies]
gl = "*"
```

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

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

fn main() {
let mut events_loop = glutin::EventsLoop::new();
let window_builder = glutin::WindowBuilder::new()
let mut el = glutin::EventsLoop::new();
let wb = glutin::WindowBuilder::new()
.with_title("Hello, world!")
.with_dimensions(dpi::LogicalSize::new(1024.0, 720.0));
let context = glutin::ContextBuilder::new().with_vsync(true);
let window = glutin::GlWindow::new(window_builder, context, &events_loop).unwrap();
.with_dimensions(LogicalSize::new(1024.0, 768.0));
let combined_context = glutin::ContextBuilder::new()
.with_vsync(true)
.build_combined(wb, &el)
.unwrap();

unsafe { window.make_current().unwrap() };
unsafe {
combined_context.make_current().unwrap();
}

unsafe {
gl::load_with(|symbol| window.get_proc_address(symbol) as *const _);
gl::load_with(|symbol| combined_context.get_proc_address(symbol) as *const _);
gl::ClearColor(0.0, 1.0, 0.0, 1.0);
}

let mut should_be_running = true;
while should_be_running {
events_loop.poll_events(|event| match event {
glutin::Event::WindowEvent { event, .. } => match event {
glutin::WindowEvent::CloseRequested => should_be_running = false,
glutin::WindowEvent::Resized(logical_size) => {
let dpi_factor = window.get_hidpi_factor();
window.resize(logical_size.to_physical(dpi_factor));
}
_ => (),
},
_ => (),
let mut running = true;
while running {
el.poll_events(|event| {
match event {
glutin::Event::WindowEvent{ event, .. } => match event {
glutin::WindowEvent::CloseRequested => running = false,
glutin::WindowEvent::Resized(logical_size) => {
let dpi_factor = combined_context.get_hidpi_factor();
combined_context.resize(logical_size.to_physical(dpi_factor));
},
_ => ()
},
_ => ()
}
});

unsafe { gl::Clear(gl::COLOR_BUFFER_BIT) }
unsafe {
gl::Clear(gl::COLOR_BUFFER_BIT);
}

window.swap_buffers().unwrap();
combined_context.swap_buffers().unwrap();
}
}

```

Note that glutin aims at being a low-level brick in your rendering infrastructure. You are encouraged to write another layer of abstraction between glutin and your application.

glutin is only officially supported on the latest stable version of the Rust compiler.
Glutin is only officially supported on the latest stable version of the Rust compiler.

## Platform-specific notes

Expand Down
2 changes: 0 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate gl_generator;

use gl_generator::{Api, Fallbacks, Profile, Registry};
use std::env;
use std::fs::File;
Expand Down
4 changes: 1 addition & 3 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 Expand Up @@ -81,6 +79,6 @@ fn main() {
});

gl.draw_frame([1.0, 0.5, 0.7, 1.0]);
let _ = combined_context.swap_buffers();
combined_context.swap_buffers().unwrap();
}
}
6 changes: 2 additions & 4 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 Expand Up @@ -51,9 +49,9 @@ fn main() {
for (index, window) in windows.values().enumerate() {
let mut color = [1.0, 0.5, 0.7, 1.0];
color.swap(0, index % 3);
let _ = unsafe { window.0.make_current() };
unsafe { window.0.make_current().unwrap() };
window.1.draw_frame(color);
let _ = window.0.swap_buffers();
window.0.swap_buffers().unwrap();
}
}
}
27 changes: 15 additions & 12 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 Expand Up @@ -52,6 +55,6 @@ fn main() {
});

gl.draw_frame([1.0, 0.5, 0.7, 1.0]);
let _ = separated_context.swap_buffers();
separated_context.swap_buffers().unwrap();
}
}
89 changes: 89 additions & 0 deletions examples/separated_context_remake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
mod support;

use glutin::{ContextTrait, EventsLoop, Window, WindowedContext};
use std::mem::ManuallyDrop;
use std::sync::Arc;

fn make_context(
el: &EventsLoop,
win: &Arc<Window>,
) -> (ManuallyDrop<WindowedContext>, support::Gl) {
let separated_context = glutin::ContextBuilder::new()
//.with_hardware_acceleration(None)
.build_separated(Arc::clone(win), el)
.unwrap();

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

println!(
"Pixel format of the window's GL context: {:?}",
separated_context.get_pixel_format()
);

let gl = support::load(&separated_context.context());

(ManuallyDrop::new(separated_context), gl)
}

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

let (mut separated_context, mut gl) = make_context(&el, &win);

let mut running = true;
let mut remake = false;
while running {
el.poll_events(|event| {
println!("el {:?}", event);
match event {
glutin::Event::WindowEvent { event, .. } => match event {
glutin::WindowEvent::KeyboardInput {
input:
glutin::KeyboardInput {
virtual_keycode:
Some(glutin::VirtualKeyCode::Escape),
..
},
..
}
| glutin::WindowEvent::CloseRequested => running = false,
glutin::WindowEvent::KeyboardInput {
input:
glutin::KeyboardInput {
virtual_keycode:
Some(glutin::VirtualKeyCode::R),
..
},
..
} => remake = true,
glutin::WindowEvent::Resized(logical_size) => {
let dpi_factor = win.get_hidpi_factor();
separated_context
.resize(logical_size.to_physical(dpi_factor));
}
_ => (),
},
_ => (),
}
});

gl.draw_frame([1.0, 0.5, 0.7, 1.0]);
separated_context.swap_buffers().unwrap();

if remake {
println!("Remaking context.");
unsafe {
ManuallyDrop::drop(&mut separated_context);
}
let (new_separated_context, new_gl) = make_context(&el, &win);
separated_context = new_separated_context;
gl = new_gl;
remake = false;
}
}
}
4 changes: 1 addition & 3 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 Expand Up @@ -87,7 +85,7 @@ fn main() {
combined_context.resize(size);

unsafe {
let _ = combined_context.make_current();
combined_context.swap_buffers().unwrap();
glw.gl.DeleteTextures(1, &render_tex);
glw.gl.DeleteFramebuffers(1, &window_fb);

Expand Down
4 changes: 1 addition & 3 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 Expand Up @@ -51,6 +49,6 @@ fn main() {
});

gl.draw_frame([0.0; 4]);
let _ = combined_context.swap_buffers();
combined_context.swap_buffers().unwrap();
}
}
4 changes: 1 addition & 3 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 Expand Up @@ -39,6 +37,6 @@ fn main() {
});

gl.draw_frame([1.0, 0.5, 0.7, 1.0]);
let _ = combined_context.swap_buffers();
combined_context.swap_buffers().unwrap();
}
}
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
Loading