From 57b2ba89c5104210a93aa1c265b4c23a250f9f95 Mon Sep 17 00:00:00 2001 From: happydpc Date: Mon, 9 Sep 2019 13:38:49 +0800 Subject: [PATCH 1/2] update to latest glutin --- Cargo.toml | 10 +++++----- src/render/mod.rs | 14 ++++++++------ src/window.rs | 32 +++++++++++++++++++------------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3150951..5958dd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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" diff --git a/src/render/mod.rs b/src/render/mod.rs index ea10b6c..d94d44c 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -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; @@ -538,13 +539,14 @@ impl Renderer { #[cfg(feature = "opengl")] pub(crate) fn new( builder: glutin::WindowBuilder, - context: glutin::ContextBuilder, + context: glutin::ContextBuilder, event_loop: &glutin::EventsLoop, source: &source::Set, - ) -> (Self, glutin::GlWindow, Factory) { + ) -> (Self, glutin::WindowedContext, 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::( t::Kind::D2(1, 1, t::AaMode::Single), @@ -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. @@ -651,7 +653,7 @@ impl Renderer { pub(crate) fn resize( &mut self, - window: &glutin::GlWindow, + window: &glutin::WindowedContext, size: glutin::dpi::LogicalSize, ) { // skip updating view and self size if some @@ -666,7 +668,7 @@ impl Renderer { pub(crate) fn dpi_change( &mut self, - window: &glutin::GlWindow, + window: &glutin::WindowedContext, dpi: f64, ) { self.dpi = dpi; diff --git a/src/window.rs b/src/window.rs index b9e5162..ccc25ad 100644 --- a/src/window.rs +++ b/src/window.rs @@ -10,6 +10,7 @@ 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. /// @@ -17,7 +18,7 @@ use std::path::PathBuf; /// [`Factory`](struct.Factory.html) and [`Renderer`](struct.Renderer.html). pub struct Window { event_loop: glutin::EventsLoop, - window: glutin::GlWindow, + windowedContext: glutin::WindowedContext, dpi: f64, /// See [`Input`](struct.Input.html). pub input: Input, @@ -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) .with_vsync(self.vsync) .with_multisampling(self.multisampling); @@ -147,12 +150,13 @@ 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(); +// let window = windowedContext.window(); Window { event_loop, - window, + windowedContext, dpi, input: Input::new(), renderer, @@ -191,16 +195,17 @@ impl Window { input.reset(); } - self.window.swap_buffers().unwrap(); - let window = &self.window; +// self.windowedContext.window().swap_buffers().unwrap(); + 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 { @@ -242,17 +247,18 @@ impl Window { /// Get current window size in pixels. pub fn size(&self) -> mint::Vector2 { - 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::Window`. #[cfg(feature = "opengl")] - pub fn glutin_window(&self) -> &glutin::GlWindow { - &self.window + pub fn glutin_window(&self) -> &glutin::WindowedContext { + &self.windowedContext } /// Returns the current full screen mode. @@ -272,7 +278,7 @@ impl Window { } else { None }; - self.window.set_fullscreen(monitor); + self.windowedContext.window().set_fullscreen(monitor); } /// Toggles the full screen mode. From a3787e70d34dbcf05e1cc8c265b604b5ed60fb3c Mon Sep 17 00:00:00 2001 From: happydpc Date: Tue, 10 Sep 2019 11:51:03 +0800 Subject: [PATCH 2/2] remove the comments and some underscore --- src/render/mod.rs | 6 +++--- src/window.rs | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index d94d44c..1512903 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -545,8 +545,8 @@ impl Renderer { ) -> (Self, glutin::WindowedContext, Factory) { use gfx::texture as t; - let (_windowedContext, device, mut gl_factory, out_color, out_depth) = gfx_window_glutin::init(builder, context, event_loop).unwrap(); - let window = _windowedContext.window(); + 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::( t::Kind::D2(1, 1, t::AaMode::Single), @@ -640,7 +640,7 @@ impl Renderer { dpi: window.get_hidpi_factor(), }; let factory = Factory::new(gl_factory); - (renderer, _windowedContext, factory) + (renderer, windowedContext, factory) } /// Reloads the shaders. diff --git a/src/window.rs b/src/window.rs index ccc25ad..4cfe785 100644 --- a/src/window.rs +++ b/src/window.rs @@ -153,7 +153,6 @@ impl Builder { let (renderer, windowedContext, mut factory) = Renderer::new(builder, context, &event_loop, &source_set); let dpi = windowedContext.window().get_hidpi_factor(); let scene = factory.scene(); -// let window = windowedContext.window(); Window { event_loop, windowedContext, @@ -195,7 +194,6 @@ impl Window { input.reset(); } -// self.windowedContext.window().swap_buffers().unwrap(); let wc = &self.windowedContext; self.windowedContext.swap_buffers().unwrap(); let dpi = self.dpi; @@ -255,7 +253,7 @@ impl Window { [size.width as f32, size.height as f32].into() } - /// Returns underlaying `glutin::Window`. + /// Returns underlaying `glutin::WindowedContext`. #[cfg(feature = "opengl")] pub fn glutin_window(&self) -> &glutin::WindowedContext { &self.windowedContext