Skip to content

Commit

Permalink
Merge #230
Browse files Browse the repository at this point in the history
230: update to latest glutin r=vitvakatu a=happydpc



Co-authored-by: happydpc <[email protected]>
  • Loading branch information
bors[bot] and happydpc authored Sep 10, 2019
2 parents 02a6fc8 + a3787e7 commit 78e0534
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
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)
.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

0 comments on commit 78e0534

Please sign in to comment.