rust: vertex/index binding

This commit is contained in:
Dzmitry Malyshau 2019-02-03 15:51:54 -05:00
parent d4c8c881d0
commit 3d47436129
4 changed files with 34 additions and 5 deletions

View File

@ -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();
}

View File

@ -9,7 +9,7 @@ use crate::{
use hal::command::RawCommandBuffer;
use std::iter;
use std::{iter, slice};
pub struct RenderPass<B: hal::Backend> {
@ -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)

View File

@ -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",

View File

@ -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<u32>, instances: Range<u32>) {
wgn::wgpu_render_pass_draw(
self.id,