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 deps #218

Merged
merged 4 commits into from
Jan 11, 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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
/target

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Expand Down
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ default = ["opengl"]
opengl = ["gfx_device_gl", "gfx_window_glutin", "glutin"]

[build-dependencies]
includedir_codegen = "0.3"
includedir_codegen = "0.5"

[dependencies]
arrayvec = "0.4"
bitflags = "1"
cgmath = { version = "0.15", features = ["mint"] }
cgmath = { version = "0.16", features = ["mint"] }
derivative = "1.0"
froggy = "0.4.4"
genmesh = "0.5"
genmesh = "0.6"
gfx = "0.17.1"
gfx_glyph = "0.13"
gltf = { features = ["names", "utils", "import"], optional = true, version = "0.11.1" }
image = "0.18"
includedir = "0.3"
itertools = "0.7"
image = "0.20"
includedir = "0.5"
itertools = "0.8"
log = "0.4"
obj = { version = "0.8.1", features = ["genmesh"] }
obj = { version = "0.9", features = ["genmesh"] }
phf = "0.7.12"
quick-error = "1.2"
rodio = "0.8"
Expand All @@ -44,13 +44,13 @@ vec_map = "0.8"

# OpenGL
gfx_device_gl = { version = "0.15", optional = true }
gfx_window_glutin = { version = "0.20", optional = true }
glutin = { version = "0.12", optional = true }
gfx_window_glutin = { version = "0.28", optional = true }
glutin = { version = "0.19", optional = true }

[dev-dependencies]
env_logger = "0.5"
env_logger = "0.6"
notify = "4"
rand = "0.3"
rand = "0.6"

[[example]]
name = "lights"
Expand Down
6 changes: 3 additions & 3 deletions examples/aviator/sky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ impl Sky {
let template = factory.mesh(geo, material.clone());
for i in 0i32 .. rng.gen_range(3, 6) {
let m = factory.mesh_instance(&template);
let rot: cgmath::Quaternion<f32> = rng.gen();
let rot = cgmath::Quaternion::<f32>::new(rng.gen(), rng.gen(), rng.gen(), rng.gen());
let q = rot.normalize();
m.set_transform(
[
i as f32 * 15.0,
rng.next_f32() * 10.0,
rng.next_f32() * 10.0,
rng.gen::<f32>() * 10.0,
rng.gen::<f32>() * 10.0,
],
q,
rng.gen_range(0.1, 1.0),
Expand Down
18 changes: 9 additions & 9 deletions src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Geometry {
) -> Self {
Self::generate(
generators::Plane::new(),
|GenVertex { pos, .. }| [pos[0] * 0.5 * width, pos[1] * 0.5 * height, 0.0].into(),
|GenVertex { pos, .. }| [pos.x * 0.5 * width, pos.y * 0.5 * height, 0.0].into(),
|v| v.normal.into(),
)
}
Expand Down Expand Up @@ -188,9 +188,9 @@ impl Geometry {
generators::Cube::new(),
|GenVertex { pos, .. }| {
[
pos[0] * 0.5 * width,
pos[1] * 0.5 * height,
pos[2] * 0.5 * depth,
pos.x * 0.5 * width,
pos.y * 0.5 * height,
pos.z * 0.5 * depth,
].into()
},
|v| v.normal.into(),
Expand Down Expand Up @@ -230,10 +230,10 @@ impl Geometry {
generators::Cylinder::new(radius_segments),
//Three.js has height along the Y axis for some reason
|GenVertex { pos, .. }| {
let scale = (pos[2] + 1.0) * 0.5 * radius_top + (1.0 - pos[2]) * 0.5 * radius_bottom;
[pos[1] * scale, pos[2] * 0.5 * height, pos[0] * scale].into()
let scale = (pos.z + 1.0) * 0.5 * radius_top + (1.0 - pos.z) * 0.5 * radius_bottom;
[pos.y * scale, pos.z * 0.5 * height, pos.x * scale].into()
},
|GenVertex { normal, .. }| [normal[1], normal[2], normal[0]].into(),
|GenVertex { normal, .. }| [normal.y, normal.z, normal.x].into(),
)
}

Expand All @@ -257,8 +257,8 @@ impl Geometry {
meridional_segments: usize,
) -> Self {
Self::generate(
generators::SphereUV::new(equatorial_segments, meridional_segments),
|GenVertex { pos, .. }| [pos[0] * radius, pos[1] * radius, pos[2] * radius].into(),
generators::SphereUv::new(equatorial_segments, meridional_segments),
|GenVertex { pos, .. }| [pos.x * radius, pos.y * radius, pos.z * radius].into(),
|v| v.normal.into(),
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl Input {
) {
self.delta.mouse_wheel.push(match delta {
MouseScrollDelta::LineDelta(_, y) => y * PIXELS_PER_LINE,
MouseScrollDelta::PixelDelta(_, y) => y,
MouseScrollDelta::PixelDelta(delta) => delta.y as f32,
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,4 @@ pub use texture::{CubeMap, CubeMapPath, FilterMethod, Sampler, Texture, WrapMode

#[cfg(feature = "opengl")]
#[doc(inline)]
pub use window::{CursorState, Window};
pub use window::Window;
30 changes: 20 additions & 10 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ pub struct Renderer {
map_default: Texture<[f32; 4]>,
shadow_default: Texture<f32>,
debug_quads: froggy::Storage<DebugQuad>,
size: (u32, u32),
size: glutin::dpi::LogicalSize,
dpi: f64,
font_cache: HashMap<String, Font>,
instance_cache: HashMap<InstanceCacheKey, InstanceData>,
/// `ShadowType` of this `Renderer`.
Expand All @@ -543,7 +544,7 @@ impl Renderer {
) -> (Self, glutin::GlWindow, Factory) {
use gfx::texture as t;

let (window, device, mut gl_factory, out_color, out_depth) = gfx_window_glutin::init(builder, context, event_loop);
let (window, device, mut gl_factory, out_color, out_depth) = gfx_window_glutin::init(builder, context, event_loop).unwrap();
let (_, srv_white) = gl_factory
.create_texture_immutable::<gfx::format::Rgba8>(
t::Kind::D2(1, 1, t::AaMode::Single),
Expand Down Expand Up @@ -634,6 +635,7 @@ impl Renderer {
debug_quads: froggy::Storage::new(),
font_cache: HashMap::new(),
size: window.get_inner_size().unwrap(),
dpi: window.get_hidpi_factor(),
};
let factory = Factory::new(gl_factory);
(renderer, window, factory)
Expand All @@ -650,22 +652,30 @@ impl Renderer {
pub(crate) fn resize(
&mut self,
window: &glutin::GlWindow,
size: glutin::dpi::LogicalSize,
) {
let size = window.get_inner_size().unwrap();

// skip updating view and self size if some
// of the sides equals to zero (fixes crash on minimize on Windows machines)
if size.0 == 0 || size.1 == 0 {
if size.width == 0.0 || size.height == 0.0 {
return;
}

self.size = size;
gfx_window_glutin::update_views(window, &mut self.out_color, &mut self.out_depth);
}

pub(crate) fn dpi_change(
&mut self,
window: &glutin::GlWindow,
dpi: f64,
) {
self.dpi = dpi;
gfx_window_glutin::update_views(window, &mut self.out_color, &mut self.out_depth);
}

/// Returns current viewport aspect ratio, i.e. width / height.
pub fn aspect_ratio(&self) -> f32 {
self.size.0 as f32 / self.size.1 as f32
self.size.to_physical(self.dpi).width as f32 / self.size.to_physical(self.dpi).height as f32
}

/// Map screen pixel coordinates to Normalized Display Coordinates.
Expand All @@ -677,8 +687,8 @@ impl Renderer {
) -> mint::Point2<f32> {
let point = point.into();
mint::Point2 {
x: 2.0 * point.x / self.size.0 as f32 - 1.0,
y: 1.0 - 2.0 * point.y / self.size.1 as f32,
x: 2.0 * point.x / self.size.to_physical(self.dpi).width as f32 - 1.0,
y: 1.0 - 2.0 * point.y / self.size.to_physical(self.dpi).height as f32,
}
}

Expand Down Expand Up @@ -1113,12 +1123,12 @@ impl Renderer {
if quad.pos[0] >= 0 {
quad.pos[0]
} else {
self.size.0 as i32 + quad.pos[0] - quad.size[0]
self.size.to_physical(self.dpi).width as i32 + quad.pos[0] - quad.size[0]
},
if quad.pos[1] >= 0 {
quad.pos[1]
} else {
self.size.1 as i32 + quad.pos[1] - quad.size[1]
self.size.to_physical(self.dpi).height as i32 + quad.pos[1] - quad.size[1]
},
];
let p0 = self.map_to_ndc([pos[0] as f32, pos[1] as f32]);
Expand Down
69 changes: 28 additions & 41 deletions src/window.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Primitives for creating and controlling [`Window`](struct.Window.html).

use glutin;
use glutin::GlContext;
use mint;
use render;

Expand All @@ -12,15 +11,14 @@ use render::Renderer;
use scene::Scene;
use std::path::PathBuf;

pub use glutin::CursorState;

/// `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,
dpi: f64,
/// See [`Input`](struct.Input.html).
pub input: Input,
/// See [`Renderer`](struct.Renderer.html).
Expand All @@ -38,7 +36,7 @@ pub struct Window {
/// Builder for creating new [`Window`](struct.Window.html) with desired parameters.
#[derive(Debug, Clone)]
pub struct Builder {
dimensions: (u32, u32),
dimensions: glutin::dpi::LogicalSize,
fullscreen: bool,
multisampling: u16,
shader_directory: Option<PathBuf>,
Expand All @@ -47,13 +45,15 @@ pub struct Builder {
}

impl Builder {
/// Set the size of the viewport (the resolution) in pixels. Defaults to 1024x768.
/// Set the size of the viewport (the resolution) in logical pixels.
/// That is the dpi setting affects the amount of pixels used but the window will
/// take up the same amount of space regardless of dpi. Defaults to 1024x768.
pub fn dimensions(
&mut self,
width: u32,
height: u32,
width: f64,
height: f64,
) -> &mut Self {
self.dimensions = (width, height);
self.dimensions = glutin::dpi::LogicalSize::new(width, height);
self
}

Expand Down Expand Up @@ -105,7 +105,7 @@ impl Builder {

let builder = glutin::WindowBuilder::new()
.with_fullscreen(monitor_id)
.with_dimensions(self.dimensions.0, self.dimensions.1)
.with_dimensions(self.dimensions)
.with_title(self.title.clone());

let context = glutin::ContextBuilder::new()
Expand Down Expand Up @@ -146,10 +146,12 @@ impl Builder {
}

let (renderer, window, mut factory) = Renderer::new(builder, context, &event_loop, &source_set);
let dpi = window.get_hidpi_factor();
let scene = factory.scene();
Window {
event_loop,
window,
dpi,
input: Input::new(),
renderer,
factory,
Expand All @@ -168,7 +170,7 @@ impl Window {
/// Create new `Builder` with standard parameters.
pub fn builder<T: Into<String>>(title: T) -> Builder {
Builder {
dimensions: (1024, 768),
dimensions: glutin::dpi::LogicalSize::new(1024.0, 768.0),
fullscreen: false,
multisampling: 0,
shader_directory: None,
Expand All @@ -188,30 +190,30 @@ impl Window {

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

self.event_loop.poll_events(|event| {
use glutin::WindowEvent::{Closed, Focused, KeyboardInput, MouseInput, CursorMoved, MouseWheel, Resized};
use glutin::WindowEvent;
match event {
glutin::Event::WindowEvent { event, .. } => match event {
Resized(..) => renderer.resize(window),
Focused(state) => input.window_focus(state),
Closed => running = false,
KeyboardInput {
WindowEvent::Resized(size) => renderer.resize(window, size),
WindowEvent::HiDpiFactorChanged(dpi) => renderer.dpi_change(window, dpi),
WindowEvent::Focused(state) => input.window_focus(state),
WindowEvent::CloseRequested | WindowEvent::Destroyed => running = false,
WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
state,
virtual_keycode: Some(keycode),
..
},
..
} => input.keyboard_input(state, keycode),
MouseInput { state, button, .. } => input.mouse_input(state, button),
CursorMoved {
position: (x, y), ..
} => input.mouse_moved(
[x as f32, y as f32].into(),
renderer.map_to_ndc([x as f32, y as f32]),
),
MouseWheel { delta, .. } => input.mouse_wheel_input(delta),
WindowEvent::MouseInput { state, button, .. } => input.mouse_input(state, button),
WindowEvent::CursorMoved { position, .. } => {
let pos = position.to_physical(dpi);
input.mouse_moved([pos.x as f32, pos.y as f32].into(), renderer.map_to_ndc([pos.x as f32, pos.y as f32]));
}
WindowEvent::MouseWheel { delta, .. } => input.mouse_wheel_input(delta),
_ => {}
},
glutin::Event::DeviceEvent { event, .. } => match event {
Expand Down Expand Up @@ -239,24 +241,9 @@ impl Window {
pub fn size(&self) -> mint::Vector2<f32> {
let size = self.window
.get_inner_size()
.expect("Can't get window size");
[size.0 as f32, size.1 as f32].into()
}

/// Sets how the cursor should be handled.
///
/// See the documentation for [`CursorState`] for the possible cursor states.
///
/// Note that if you use [`CursorState::Grab`], you should use [`Input::mouse_delta_raw`] for
/// detecting mouse movement, as [`Input::mouse_delta`] will only report movement of the cursor
/// within the window.
///
/// [`CursorState`]: enum.CursorState.html
/// [`CursorState::Grab`]: enum.CursorState.html#variant.Grab
/// [`Input::mouse_delta_raw`]: struct.Input.html#method.mouse_delta_raw
/// [`Input::mouse_delta`]: struct.Input.html#method.mouse_delta_raw
pub fn set_cursor_state(&self, state: CursorState) {
let _ = self.window.set_cursor_state(state);
.expect("Can't get window size")
.to_physical(self.dpi);
[size.width as f32, size.height as f32].into()
}

/// Returns underlaying `glutin::GlWindow`.
Expand Down