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

update to latest glutin #230

Merged
merged 2 commits into from
Sep 10, 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
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ cgmath = { version = "0.16", features = ["mint"] }
derivative = "1.0"
froggy = "0.4.4"
genmesh = "0.6"
gfx = "0.17.1"
gfx_glyph = "0.13"
gfx = "0.18.1"
gfx_glyph = "0.15.0"
gltf = { features = ["names", "utils", "import"], optional = true, version = "0.11.1" }
image = "0.20"
includedir = "0.5"
Expand All @@ -44,9 +44,9 @@ mint = "0.5"
vec_map = "0.8"

# OpenGL
gfx_device_gl = { version = "0.15", optional = true }
gfx_window_glutin = { version = "0.28", optional = true }
glutin = { version = "0.19", optional = true }
gfx_device_gl = { version = "0.16.2", optional = true }
gfx_window_glutin = { version = "0.31.0", optional = true }
glutin = { version = "0.21.1", optional = true }

[dev-dependencies]
env_logger = "0.6"
Expand Down
14 changes: 8 additions & 6 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use material::Material;
use scene::{Background, Scene};
use text::Font;
use texture::Texture;
use glutin::{ContextCurrentState, NotCurrent, Window, ContextWrapper, PossiblyCurrent};

/// The format of the back buffer color requested from the windowing system.
pub type ColorFormat = gfx::format::Rgba8;
Expand Down Expand Up @@ -538,13 +539,14 @@ impl Renderer {
#[cfg(feature = "opengl")]
pub(crate) fn new(
builder: glutin::WindowBuilder,
context: glutin::ContextBuilder,
context: glutin::ContextBuilder<NotCurrent>,
event_loop: &glutin::EventsLoop,
source: &source::Set,
) -> (Self, glutin::GlWindow, Factory) {
) -> (Self, glutin::WindowedContext<PossiblyCurrent>, Factory) {
use gfx::texture as t;

let (window, device, mut gl_factory, out_color, out_depth) = gfx_window_glutin::init(builder, context, event_loop).unwrap();
let (windowedContext, device, mut gl_factory, out_color, out_depth) = gfx_window_glutin::init(builder, context, event_loop).unwrap();
let window = windowedContext.window();
let (_, srv_white) = gl_factory
.create_texture_immutable::<gfx::format::Rgba8>(
t::Kind::D2(1, 1, t::AaMode::Single),
Expand Down Expand Up @@ -638,7 +640,7 @@ impl Renderer {
dpi: window.get_hidpi_factor(),
};
let factory = Factory::new(gl_factory);
(renderer, window, factory)
(renderer, windowedContext, factory)
}

/// Reloads the shaders.
Expand All @@ -651,7 +653,7 @@ impl Renderer {

pub(crate) fn resize(
&mut self,
window: &glutin::GlWindow,
window: &glutin::WindowedContext<PossiblyCurrent>,
size: glutin::dpi::LogicalSize,
) {
// skip updating view and self size if some
Expand All @@ -666,7 +668,7 @@ impl Renderer {

pub(crate) fn dpi_change(
&mut self,
window: &glutin::GlWindow,
window: &glutin::WindowedContext<PossiblyCurrent>,
dpi: f64,
) {
self.dpi = dpi;
Expand Down
30 changes: 17 additions & 13 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ use input::Input;
use render::Renderer;
use scene::Scene;
use std::path::PathBuf;
use glutin::{GlRequest, GlProfile, PossiblyCurrent};

/// `Window` is the core entity of every `three-rs` application.
///
/// It provides [user input](struct.Window.html#method.update),
/// [`Factory`](struct.Factory.html) and [`Renderer`](struct.Renderer.html).
pub struct Window {
event_loop: glutin::EventsLoop,
window: glutin::GlWindow,
windowedContext: glutin::WindowedContext<PossiblyCurrent>,
dpi: f64,
/// See [`Input`](struct.Input.html).
pub input: Input,
Expand Down Expand Up @@ -111,6 +112,8 @@ impl Builder {
.with_title(self.title.clone());

let context = glutin::ContextBuilder::new()
.with_gl_profile(GlProfile::Core)
.with_gl(GlRequest::Latest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather prefer to see a specific version here. @kvark what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some older GPUs only support GL 2.1, while some macs do not support older GL 2x. So if we are completely pedantic, we can't have a specific version requirement (even though, practically, GL 3.2 would fit most cases). So having Latest here is fine.

.with_vsync(self.vsync)
.with_multisampling(self.multisampling);

Expand Down Expand Up @@ -147,12 +150,12 @@ impl Builder {
try_override!(basic, gouraud, pbr, phong, quad, shadow, skybox, sprite,);
}

let (renderer, window, mut factory) = Renderer::new(builder, context, &event_loop, &source_set);
let dpi = window.get_hidpi_factor();
let (renderer, windowedContext, mut factory) = Renderer::new(builder, context, &event_loop, &source_set);
let dpi = windowedContext.window().get_hidpi_factor();
let scene = factory.scene();
Window {
event_loop,
window,
windowedContext,
dpi,
input: Input::new(),
renderer,
Expand Down Expand Up @@ -191,16 +194,16 @@ impl Window {
input.reset();
}

self.window.swap_buffers().unwrap();
let window = &self.window;
let wc = &self.windowedContext;
self.windowedContext.swap_buffers().unwrap();
let dpi = self.dpi;

self.event_loop.poll_events(|event| {
use glutin::WindowEvent;
match event {
glutin::Event::WindowEvent { event, .. } => match event {
WindowEvent::Resized(size) => renderer.resize(window, size),
WindowEvent::HiDpiFactorChanged(dpi) => renderer.dpi_change(window, dpi),
WindowEvent::Resized(size) => renderer.resize(wc, size),
WindowEvent::HiDpiFactorChanged(dpi) => renderer.dpi_change(wc, dpi),
WindowEvent::Focused(state) => input.window_focus(state),
WindowEvent::CloseRequested | WindowEvent::Destroyed => running = false,
WindowEvent::KeyboardInput {
Expand Down Expand Up @@ -242,17 +245,18 @@ impl Window {

/// Get current window size in pixels.
pub fn size(&self) -> mint::Vector2<f32> {
let size = self.window
let size = self.windowedContext
.window()
.get_inner_size()
.expect("Can't get window size")
.to_physical(self.dpi);
[size.width as f32, size.height as f32].into()
}

/// Returns underlaying `glutin::GlWindow`.
/// Returns underlaying `glutin::WindowedContext`.
#[cfg(feature = "opengl")]
pub fn glutin_window(&self) -> &glutin::GlWindow {
&self.window
pub fn glutin_window(&self) -> &glutin::WindowedContext<PossiblyCurrent> {
&self.windowedContext
}

/// Returns the current full screen mode.
Expand All @@ -272,7 +276,7 @@ impl Window {
} else {
None
};
self.window.set_fullscreen(monitor);
self.windowedContext.window().set_fullscreen(monitor);
}

/// Toggles the full screen mode.
Expand Down