This commit is contained in:
1 parent
f29712d158
commit
3e053a81ab
123 files changed
+31930
-1404
No files matched your search
@@ -0,0 +1,70 @@
|
||||
use crate::define_atomic_id;
|
||||
use crate::renderer::WgpuWrapper;
|
||||
use core::ops::{Deref, RangeBounds};
|
||||
|
||||
define_atomic_id!(BufferId);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Buffer {
|
||||
id: BufferId,
|
||||
value: WgpuWrapper<wgpu::Buffer>,
|
||||
}
|
||||
|
||||
impl Buffer {
|
||||
#[inline]
|
||||
pub fn id(&self) -> BufferId {
|
||||
self.id
|
||||
}
|
||||
|
||||
pub fn slice(&self, bounds: impl RangeBounds<wgpu::BufferAddress>) -> BufferSlice<'_> {
|
||||
BufferSlice {
|
||||
id: self.id,
|
||||
value: self.value.slice(bounds),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn unmap(&self) {
|
||||
self.value.unmap();
|
||||
}
|
||||
}
|
||||
|
||||
impl From<wgpu::Buffer> for Buffer {
|
||||
fn from(value: wgpu::Buffer) -> Self {
|
||||
Buffer {
|
||||
id: BufferId::new(),
|
||||
value: WgpuWrapper::new(value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Buffer {
|
||||
type Target = wgpu::Buffer;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BufferSlice<'a> {
|
||||
id: BufferId,
|
||||
value: wgpu::BufferSlice<'a>,
|
||||
}
|
||||
|
||||
impl<'a> BufferSlice<'a> {
|
||||
#[inline]
|
||||
pub fn id(&self) -> BufferId {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for BufferSlice<'a> {
|
||||
type Target = wgpu::BufferSlice<'a>;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user