mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Set vertex and index buffers
This commit is contained in:
parent
eff92d3427
commit
08cd75f38c
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -660,7 +660,7 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -681,7 +681,7 @@ name = "rand_hc"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -719,7 +719,7 @@ name = "rand_xorshift"
|
|||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
|
use crate::resource::BufferUsageFlags;
|
||||||
use crate::registry::{Items, HUB};
|
use crate::registry::{Items, HUB};
|
||||||
use crate::track::{BufferTracker, TextureTracker};
|
use crate::track::{BufferTracker, TextureTracker, TrackPermit};
|
||||||
use crate::{CommandBuffer, CommandBufferId, RenderPassId, Stored};
|
use crate::{
|
||||||
|
CommandBuffer, Stored,
|
||||||
|
BufferId, CommandBufferId, RenderPassId,
|
||||||
|
};
|
||||||
|
|
||||||
use hal::command::RawCommandBuffer;
|
use hal::command::RawCommandBuffer;
|
||||||
|
|
||||||
@ -47,3 +51,63 @@ pub extern "C" fn wgpu_render_pass_end_pass(pass_id: RenderPassId) -> CommandBuf
|
|||||||
cmb.raw.push(pass.raw);
|
cmb.raw.push(pass.raw);
|
||||||
pass.cmb_id.value
|
pass.cmb_id.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn wgpu_render_pass_set_index_buffer(
|
||||||
|
pass_id: RenderPassId, buffer_id: BufferId, offset: u32
|
||||||
|
) {
|
||||||
|
let mut pass_guard = HUB.render_passes.write();
|
||||||
|
let buffer_guard = HUB.buffers.read();
|
||||||
|
|
||||||
|
let pass = pass_guard.get_mut(pass_id);
|
||||||
|
let buffer = buffer_guard.get(buffer_id);
|
||||||
|
pass.buffer_tracker
|
||||||
|
.transit(
|
||||||
|
buffer_id,
|
||||||
|
&buffer.life_guard.ref_count,
|
||||||
|
BufferUsageFlags::INDEX,
|
||||||
|
TrackPermit::EXTEND,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let view = hal::buffer::IndexBufferView {
|
||||||
|
buffer: &buffer.raw,
|
||||||
|
offset: offset as u64,
|
||||||
|
index_type: hal::IndexType::U16, //TODO?
|
||||||
|
};
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
pass.raw.bind_index_buffer(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn wgpu_render_pass_set_vertex_buffers(
|
||||||
|
pass_id: RenderPassId, buffers: &[BufferId], offsets: &[u32]
|
||||||
|
) {
|
||||||
|
let mut pass_guard = HUB.render_passes.write();
|
||||||
|
let buffer_guard = HUB.buffers.read();
|
||||||
|
|
||||||
|
let pass = pass_guard.get_mut(pass_id);
|
||||||
|
for &id in buffers {
|
||||||
|
let buffer = buffer_guard.get(id);
|
||||||
|
pass.buffer_tracker
|
||||||
|
.transit(
|
||||||
|
id,
|
||||||
|
&buffer.life_guard.ref_count,
|
||||||
|
BufferUsageFlags::VERTEX,
|
||||||
|
TrackPermit::EXTEND,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(buffers.len(), offsets.len());
|
||||||
|
let buffers = buffers
|
||||||
|
.iter()
|
||||||
|
.map(|&id| &buffer_guard.get(id).raw)
|
||||||
|
.zip(offsets.iter().map(|&off| off as u64));
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
pass.raw.bind_vertex_buffers(0, buffers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -26,7 +26,12 @@ pub struct Query<T> {
|
|||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
pub struct TrackPermit: u32 {
|
pub struct TrackPermit: u32 {
|
||||||
|
/// Allow extension of the current usage. This is useful during render pass
|
||||||
|
/// recording, where the usage has to stay constant, but we can defer the
|
||||||
|
/// decision on what it is until the end of the pass.
|
||||||
const EXTEND = 1;
|
const EXTEND = 1;
|
||||||
|
/// Allow replacing the current usage with the new one. This is useful when
|
||||||
|
/// recording a command buffer live, and the current usage is already been set.
|
||||||
const REPLACE = 2;
|
const REPLACE = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user