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 v0.16 dependencies & examples to glutin 0.9 / winit 0.7 #1377

Merged
merged 3 commits into from Jul 17, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "gfx_app"
version = "0.6.0"
version = "0.7.0"
description = "GFX example application framework"
homepage = "https://github.com/gfx-rs/gfx"
keywords = ["graphics", "gamedev"]
Expand All @@ -23,14 +23,14 @@ name = "gfx_app"
[dependencies]
log = "0.3"
env_logger = "0.4"
glutin = "0.8.0"
winit = "0.6.0"
glutin = "0.9"
winit = "0.7"
gfx_core = { path = "src/core", version = "0.7.1" }
gfx_corell = { path = "src/corell", version = "0.1" }
gfx = { path = "src/render", version = "0.16" }
gfx_macros = { path = "src/macros", version = "0.2" }
gfx_device_gl = { path = "src/backend/gl", version = "0.14" }
gfx_window_glutin = { path = "src/window/glutin", version = "0.16" }
gfx_window_glutin = { path = "src/window/glutin", version = "0.17" }

[dependencies.gfx_device_vulkan]
path = "src/backend/vulkan"
Expand All @@ -44,7 +44,7 @@ optional = true

[dependencies.gfx_window_vulkan]
path = "src/window/vulkan"
version = "0.2"
version = "0.3"
optional = true

[dependencies.gfx_device_metal]
Expand All @@ -69,7 +69,7 @@ gfx_window_sdl = { path = "src/window/sdl", version = "0.6" }
[target.'cfg(windows)'.dependencies]
gfx_device_dx11 = { path = "src/backend/dx11", version = "0.6" }
# gfx_device_dx12ll = { path = "src/backend/dx12ll", version = "0.1" }
gfx_window_dxgi = { path = "src/window/dxgi", version = "0.8" }
gfx_window_dxgi = { path = "src/window/dxgi", version = "0.9" }

[[example]]
name = "blend"
Expand Down Expand Up @@ -142,4 +142,4 @@ rand = "0.3"
genmesh = "0.4"
noise = "0.1"
image = "0.13"
winit = "0.6"
winit = "0.7"
32 changes: 15 additions & 17 deletions appveyor.yml
@@ -1,21 +1,19 @@
environment:
RUST_BACKTRACE: full
matrix:
- TARGET: 1.16.0-x86_64-pc-windows
COMPILER: gnu
- TARGET: 1.16.0-x86_64-pc-windows
COMPILER: msvc
- TARGET: nightly-x86_64-pc-windows
COMPILER: msvc
- channel: stable
target: x86_64-pc-windows-msvc
- channel: stable
target: x86_64-pc-windows-gnu
- channel: nightly
target: x86_64-pc-windows-msvc
install:
- if %COMPILER%==gnu choco install -y mingw
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}-${env:COMPILER}.exe" -FileName "rust-install.exe"
- ps: .\rust-install.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null
- ps: $env:PATH="$env:PATH;C:\rust\bin;C:\tools\mingw64\bin"
- if %COMPILER%==gnu gcc -v
- rustc -vV
- cargo -vV
build_script:
- cargo build --features vulkan
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- rustup-init -yv --default-toolchain %channel% --default-host %target%
- set PATH=%PATH%;%USERPROFILE%\.cargo\bin
- rustc -vV
- cargo -vV
build: false
test_script:
- cargo test --all --features vulkan
- cargo test -p gfx -p gfx_core --features "cgmath-types serialize"
- cargo test --all --features vulkan
- cargo test -p gfx -p gfx_core --features "cgmath-types serialize"
21 changes: 12 additions & 9 deletions examples/blend/main.rs
Expand Up @@ -152,15 +152,18 @@ impl<R: gfx::Resources> gfx_app::Application<R> for App<R> {
}

fn on(&mut self, event: winit::WindowEvent) {
match event {
winit::WindowEvent::KeyboardInput(winit::ElementState::Pressed, _, Some(winit::VirtualKeyCode::B), _) => {
self.id += 1;
if self.id as usize >= BLENDS.len() {
self.id = 0;
}
println!("Using '{}' blend equation", BLENDS[self.id as usize]);
},
_ => ()
if let winit::WindowEvent::KeyboardInput {
input: winit::KeyboardInput {
state: winit::ElementState::Pressed,
virtual_keycode: Some(winit::VirtualKeyCode::B),
..
},
.. } = event {
self.id += 1;
if self.id as usize >= BLENDS.len() {
self.id = 0;
}
println!("Using '{}' blend equation", BLENDS[self.id as usize]);
}
}

Expand Down
29 changes: 16 additions & 13 deletions examples/deferred/main.rs
Expand Up @@ -51,7 +51,7 @@ use genmesh::generators::{SharedVertex, IndexedPolygon};
use noise::{Seed, perlin2};
use rand::Rng;
use std::time::{Instant};
use winit::{WindowEvent, VirtualKeyCode, WindowBuilder};
use winit::{WindowEvent, WindowBuilder};

// Remember to also change the constants in the shaders
const NUM_LIGHTS: usize = 250;
Expand Down Expand Up @@ -555,18 +555,21 @@ impl<R: gfx::Resources> gfx_app::Application<R> for App<R> {
}

fn on(&mut self, event: WindowEvent) {
match event {
WindowEvent::KeyboardInput(_, _, Some(VirtualKeyCode::Key1), _) =>
self.debug_buf = Some(self.light.data.tex_pos.0.clone()),
WindowEvent::KeyboardInput(_, _, Some(VirtualKeyCode::Key2), _) =>
self.debug_buf = Some(self.light.data.tex_normal.0.clone()),
WindowEvent::KeyboardInput(_, _, Some(VirtualKeyCode::Key3), _) =>
self.debug_buf = Some(self.light.data.tex_diffuse.0.clone()),
WindowEvent::KeyboardInput(_, _, Some(VirtualKeyCode::Key4), _) =>
self.debug_buf = Some(self.depth_resource.clone()),
WindowEvent::KeyboardInput(_, _, Some(VirtualKeyCode::Key0), _) =>
self.debug_buf = None,
_ => (),
if let WindowEvent::KeyboardInput {
input: winit::KeyboardInput {
virtual_keycode: Some(key),
..
},
.. } = event {
use winit::VirtualKeyCode::*;
match key {
Key1 => self.debug_buf = Some(self.light.data.tex_pos.0.clone()),
Key2 => self.debug_buf = Some(self.light.data.tex_normal.0.clone()),
Key3 => self.debug_buf = Some(self.light.data.tex_diffuse.0.clone()),
Key4 => self.debug_buf = Some(self.depth_resource.clone()),
Key0 => self.debug_buf = None,
_ => (),
}
}
}

Expand Down
35 changes: 22 additions & 13 deletions examples/gamma/main.rs
Expand Up @@ -19,6 +19,7 @@ extern crate glutin;

use gfx::traits::FactoryExt;
use gfx::Device;
use glutin::GlContext;

pub type ColorFormat = gfx::format::Rgba8;
pub type DepthFormat = gfx::format::DepthStencil;
Expand All @@ -45,13 +46,14 @@ const QUAD: [Vertex; 4] = [
const CLEAR_COLOR: [f32; 4] = [0.5, 0.5, 0.5, 1.0];

pub fn main() {
let events_loop = glutin::EventsLoop::new();
let builder = glutin::WindowBuilder::new()
let mut events_loop = glutin::EventsLoop::new();
let window_builder = glutin::WindowBuilder::new()
.with_title("Gamma example".to_string())
.with_dimensions(1024, 768)
.with_vsync();
.with_dimensions(1024, 768);
let context = glutin::ContextBuilder::new()
.with_vsync(true);
let (window, mut device, mut factory, main_color, mut main_depth) =
gfx_window_glutin::init::<ColorFormat, DepthFormat>(builder, &events_loop);
gfx_window_glutin::init::<ColorFormat, DepthFormat>(window_builder, context, &events_loop);
let mut encoder: gfx::Encoder<_, _> = factory.create_command_buffer().into();
let pso = factory.create_pipeline_simple(
include_bytes!("shader/quad_150.glslv"),
Expand All @@ -66,14 +68,21 @@ pub fn main() {

let mut running = true;
while running {
events_loop.poll_events(|glutin::Event::WindowEvent{window_id: _, event}| {
match event {
glutin::WindowEvent::KeyboardInput(_, _, Some(glutin::VirtualKeyCode::Escape), _) |
glutin::WindowEvent::Closed => running = false,
glutin::WindowEvent::Resized(_width, _height) => {
gfx_window_glutin::update_views(&window, &mut data.out, &mut main_depth);
},
_ => {},
events_loop.poll_events(|event| {
if let glutin::Event::WindowEvent { event, .. } = event {
match event {
glutin::WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
virtual_keycode: Some(glutin::VirtualKeyCode::Escape),
.. },
..
} | glutin::WindowEvent::Closed => running = false,
glutin::WindowEvent::Resized(width, height) => {
window.resize(width, height);
gfx_window_glutin::update_views(&window, &mut data.out, &mut main_depth);
},
_ => (),
}
}
});

Expand Down
57 changes: 36 additions & 21 deletions examples/performance/main.rs
Expand Up @@ -33,6 +33,7 @@ use std::ffi::CString;
use std::time::{Duration, Instant};
use gfx_device_gl::{Resources as R, CommandBuffer as CB};
use gfx_core::Device;
use glutin::GlContext;

gfx_defines!{
vertex Vertex {
Expand All @@ -52,7 +53,7 @@ static VERTEX_SRC: &'static [u8] = b"
uniform mat4 u_Transform;

void main() {
gl_Position = u_Transform * vec4(a_Pos, 1.0);
gl_Position = u_Transform * vec4(a_Pos, 1.0);
}
";

Expand Down Expand Up @@ -93,7 +94,7 @@ trait Renderer: Drop {

struct GFX {
dimension: i16,
window: glutin::Window,
window: glutin::GlWindow,
device:gfx_device_gl::Device,
encoder: gfx::Encoder<R,CB>,
data: pipe::Data<R>,
Expand All @@ -103,7 +104,7 @@ struct GFX {

struct GL {
dimension: i16,
window: glutin::Window,
window: glutin::GlWindow,
gl:Gl,
trans_uniform:GLint,
vs:GLuint,
Expand All @@ -115,11 +116,14 @@ struct GL {


impl GFX {
fn new(builder: glutin::WindowBuilder, events_loop: &glutin::EventsLoop, dimension: i16) -> Self {
fn new(window: glutin::WindowBuilder,
context: glutin::ContextBuilder,
events_loop: &glutin::EventsLoop,
dimension: i16) -> Self {
use gfx::traits::FactoryExt;

let (window, device, mut factory, main_color, _) =
gfx_window_glutin::init::<ColorFormat, DepthStencil>(builder, events_loop);
gfx_window_glutin::init::<ColorFormat, DepthStencil>(window, context, events_loop);
let encoder: gfx::Encoder<_,_> = factory.create_command_buffer().into();

let pso = factory.create_pipeline_simple(
Expand Down Expand Up @@ -185,7 +189,10 @@ impl Drop for GFX {


impl GL {
fn new(builder: glutin::WindowBuilder, events_loop: &glutin::EventsLoop, dimension: i16) -> Self {
fn new(builder: glutin::WindowBuilder,
context: glutin::ContextBuilder,
events_loop: &glutin::EventsLoop,
dimension: i16) -> Self {
fn compile_shader (gl:&Gl, src: &[u8], ty: GLenum) -> GLuint {
unsafe {
let shader = gl.CreateShader(ty);
Expand Down Expand Up @@ -213,10 +220,10 @@ impl GL {
}
};

let window = builder.build(events_loop).unwrap();
let window = glutin::GlWindow::new(builder, context, &events_loop).unwrap();
unsafe { window.make_current().unwrap() };
let gl = Gl::load_with(|s| window.get_proc_address(s) as *const _);

// Create GLSL shaders
let vs = compile_shader(&gl, VERTEX_SRC, gl::VERTEX_SHADER);
let fs = compile_shader(&gl, FRAGMENT_SRC, gl::FRAGMENT_SHADER);
Expand Down Expand Up @@ -281,7 +288,7 @@ impl GL {
};

GL {
window: window,
window: window,
dimension: dimension,
gl: gl,
vs: vs,
Expand All @@ -307,7 +314,7 @@ impl Renderer for GL {
self.gl.ClearColor(CLEAR_COLOR.0, CLEAR_COLOR.1, CLEAR_COLOR.2, CLEAR_COLOR.3);
self.gl.Clear(gl::COLOR_BUFFER_BIT);
}

for x in (-self.dimension) ..self.dimension {
for y in (-self.dimension) ..self.dimension {
let mat:Matrix4<f32> = transform(x, y, proj_view).into();
Expand Down Expand Up @@ -352,7 +359,7 @@ fn main() {
let ref mut args = env::args();
let args_count = env::args().count();
if args_count == 1 {
println!("gfx-perf [gl|gfx] <size>");
println!("cargo run --example performance gl|gfx [size]");
return;
}

Expand All @@ -365,16 +372,17 @@ fn main() {

let count = ((count as f64).sqrt() / 2.) as i16;

let events_loop = glutin::EventsLoop::new();
let mut events_loop = glutin::EventsLoop::new();
let builder = glutin::WindowBuilder::new()
.with_title("Performance example".to_string())
.with_dimensions(800, 600)
.with_vsync();
.with_dimensions(800, 600);
let context = glutin::ContextBuilder::new()
.with_vsync(false);

let mut r: Box<Renderer>;
match mode.as_ref() {
"gfx" => r = Box::new(GFX::new(builder, &events_loop, count)),
"gl" => r = Box::new(GL::new(builder, &events_loop, count)),
"gfx" => r = Box::new(GFX::new(builder, context, &events_loop, count)),
"gl" => r = Box::new(GL::new(builder, context, &events_loop, count)),
x => {
panic!("{} is not a known mode", x)
}
Expand All @@ -401,11 +409,18 @@ fn main() {

let mut running = true;
loop {
events_loop.poll_events(|glutin::Event::WindowEvent{window_id: _, event}| {
match event {
glutin::WindowEvent::KeyboardInput(_, _, Some(glutin::VirtualKeyCode::Escape), _) |
glutin::WindowEvent::Closed => running = false,
_ => {},
events_loop.poll_events(|event| {
if let glutin::Event::WindowEvent { event, .. } = event {
match event {
glutin::WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
virtual_keycode: Some(glutin::VirtualKeyCode::Escape),
..
},
..
} | glutin::WindowEvent::Closed => running = false,
_ => ()
}
}
});
if !running {
Expand Down