diff --git a/gfx-examples/src/cube.rs b/gfx-examples/src/cube.rs index d92a792b9..92be14edb 100644 --- a/gfx-examples/src/cube.rs +++ b/gfx-examples/src/cube.rs @@ -221,8 +221,9 @@ impl fw::Example for Cube { depth_stencil_attachment: None, }); rpass.set_pipeline(&self.pipeline); - //rpass.bind_groups(); - //rpass.set_vertex_buffers(); + 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.end_pass(); } diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index b5b42b801..62057071b 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -9,7 +9,7 @@ use crate::{ use hal::command::RawCommandBuffer; -use std::iter; +use std::{iter, slice}; pub struct RenderPass { @@ -87,10 +87,19 @@ pub extern "C" fn wgpu_render_pass_set_index_buffer( #[no_mangle] pub extern "C" fn wgpu_render_pass_set_vertex_buffers( - pass_id: RenderPassId, buffers: &[BufferId], offsets: &[u32] + pass_id: RenderPassId, + buffer_ptr: *const BufferId, + offset_ptr: *const u32, + count: usize, ) { let mut pass_guard = HUB.render_passes.write(); let buffer_guard = HUB.buffers.read(); + let buffers = unsafe { + slice::from_raw_parts(buffer_ptr, count) + }; + let offsets = unsafe { + slice::from_raw_parts(offset_ptr, count) + }; let pass = pass_guard.get_mut(pass_id); for &id in buffers { @@ -104,7 +113,6 @@ pub extern "C" fn wgpu_render_pass_set_vertex_buffers( .unwrap(); } - assert_eq!(buffers.len(), offsets.len()); let buffers = buffers .iter() .map(|&id| &buffer_guard.get(id).raw) diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index b8ec8655d..a66161ed1 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -50,6 +50,7 @@ pub extern "C" fn wgpu_instance_create_surface_from_winit( instance_id: InstanceId, window: &winit::Window, ) -> SurfaceId { + //TODO: remove these workarounds when porting on gfx-hal 0.2 #[cfg(any( feature = "gfx-backend-vulkan", feature = "gfx-backend-dx11", diff --git a/wgpu-rs/src/lib.rs b/wgpu-rs/src/lib.rs index 2733996bd..ffa8b61c2 100644 --- a/wgpu-rs/src/lib.rs +++ b/wgpu-rs/src/lib.rs @@ -451,6 +451,25 @@ impl<'a> RenderPass<'a> { wgn::wgpu_render_pass_set_pipeline(self.id, pipeline.id); } + pub fn set_index_buffer(&mut self, buffer: &Buffer, offset: u32) { + wgn::wgpu_render_pass_set_index_buffer(self.id, buffer.id, offset); + } + + pub fn set_vertex_buffers(&mut self, buffer_pairs: &[(&Buffer, u32)]) { + let mut buffers = Vec::new(); + let mut offsets = Vec::new(); + for &(buffer, offset) in buffer_pairs { + buffers.push(buffer.id); + offsets.push(offset); + } + wgn::wgpu_render_pass_set_vertex_buffers( + self.id, + buffers.as_ptr(), + offsets.as_ptr(), + buffer_pairs.len(), + ); + } + pub fn draw(&mut self, vertices: Range, instances: Range) { wgn::wgpu_render_pass_draw( self.id,