bevy/crates/bevy_render/src/render_resource/bind_group.rs

45 lines
1.2 KiB
Rust
Raw Normal View History

2021-06-21 23:28:52 +00:00
use bevy_reflect::Uuid;
use std::{ops::Deref, sync::Arc};
2021-04-11 20:13:07 +00:00
/// A [`BindGroup`] identifier.
2021-06-21 23:28:52 +00:00
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
pub struct BindGroupId(Uuid);
2021-04-11 20:13:07 +00:00
/// Bind groups are responsible for binding render resources (e.g. buffers, textures, samplers)
/// to a [`TrackedRenderPass`](crate::render_phase::TrackedRenderPass).
/// This makes them accessible in the pipeline (shaders) as uniforms.
///
/// May be converted from and dereferences to a wgpu [`BindGroup`](wgpu::BindGroup).
/// Can be created via [`RenderDevice::create_bind_group`](crate::renderer::RenderDevice::create_bind_group).
2021-06-21 23:28:52 +00:00
#[derive(Clone, Debug)]
2021-04-11 20:13:07 +00:00
pub struct BindGroup {
2021-06-21 23:28:52 +00:00
id: BindGroupId,
value: Arc<wgpu::BindGroup>,
2021-04-11 20:13:07 +00:00
}
impl BindGroup {
/// Returns the [`BindGroupId`].
2021-06-21 23:28:52 +00:00
#[inline]
pub fn id(&self) -> BindGroupId {
self.id
2021-04-11 20:13:07 +00:00
}
2021-06-21 23:28:52 +00:00
}
2021-04-11 20:13:07 +00:00
2021-06-21 23:28:52 +00:00
impl From<wgpu::BindGroup> for BindGroup {
fn from(value: wgpu::BindGroup) -> Self {
2021-04-11 20:13:07 +00:00
BindGroup {
2021-06-21 23:28:52 +00:00
id: BindGroupId(Uuid::new_v4()),
value: Arc::new(value),
2021-04-11 20:13:07 +00:00
}
}
}
impl Deref for BindGroup {
type Target = wgpu::BindGroup;
#[inline]
fn deref(&self) -> &Self::Target {
&self.value
}
}