mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
Fix gfx-cube example
This commit is contained in:
parent
d50f8199dd
commit
8f985dd09e
@ -67,6 +67,7 @@ fn create_vertices() -> (Vec<Vertex>, Vec<u16>) {
|
||||
struct Cube {
|
||||
vertex_buf: wgpu::Buffer,
|
||||
index_buf: wgpu::Buffer,
|
||||
index_count: usize,
|
||||
bind_group: wgpu::BindGroup,
|
||||
pipeline: wgpu::RenderPipeline,
|
||||
}
|
||||
@ -185,7 +186,7 @@ impl fw::Example for Cube {
|
||||
);
|
||||
let mx_total = mx_projection * mx_view;
|
||||
let mx_raw: &[f32; 16] = mx_total.as_ref();
|
||||
vertex_buf.set_sub_data(0, fw::cast_slice(&mx_raw[..]));
|
||||
uniform_buf.set_sub_data(0, fw::cast_slice(&mx_raw[..]));
|
||||
}
|
||||
|
||||
// Create bind group
|
||||
@ -269,6 +270,7 @@ impl fw::Example for Cube {
|
||||
Cube {
|
||||
vertex_buf,
|
||||
index_buf,
|
||||
index_count: index_data.len(),
|
||||
bind_group,
|
||||
pipeline,
|
||||
}
|
||||
@ -293,7 +295,7 @@ impl fw::Example for Cube {
|
||||
rpass.set_bind_group(0, &self.bind_group);
|
||||
rpass.set_index_buffer(&self.index_buf, 0);
|
||||
rpass.set_vertex_buffers(&[(&self.vertex_buf, 0)]);
|
||||
rpass.draw(0..3, 0..1);
|
||||
rpass.draw_indexed(0 .. self.index_count as u32, 0, 0..1);
|
||||
rpass.end_pass();
|
||||
}
|
||||
|
||||
@ -304,5 +306,5 @@ impl fw::Example for Cube {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fw::run::<Cube>();
|
||||
fw::run::<Cube>("cube");
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ pub trait Example {
|
||||
fn render(&mut self, frame: &wgpu::SwapChainOutput, device: &mut wgpu::Device);
|
||||
}
|
||||
|
||||
pub fn run<E: Example>() {
|
||||
pub fn run<E: Example>(title: &str) {
|
||||
use self::wgpu_native::winit::{
|
||||
Event, ElementState, EventsLoop, KeyboardInput, Window, WindowEvent, VirtualKeyCode
|
||||
};
|
||||
@ -67,6 +67,7 @@ pub fn run<E: Example>() {
|
||||
info!("Initializing the window...");
|
||||
let mut events_loop = EventsLoop::new();
|
||||
let window = Window::new(&events_loop).unwrap();
|
||||
window.set_title(title);
|
||||
let size = window
|
||||
.get_inner_size()
|
||||
.unwrap()
|
||||
|
Loading…
Reference in New Issue
Block a user