working 3d textures
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
|
||||
pub const DATA: &[u8] = &[
|
||||
pub const DATA: &[u32] = &[
|
||||
// z0
|
||||
1,0,
|
||||
0,1,
|
||||
0,0,
|
||||
// z1
|
||||
0,1,
|
||||
1,0,
|
||||
];
|
||||
0,0,
|
||||
0,0,
|
||||
];
|
||||
|
||||
|
||||
pub struct NodeBuffer {
|
||||
texture: wgpu::Texture,
|
||||
@@ -27,7 +28,7 @@ impl NodeBuffer {
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D3,
|
||||
format: wgpu::TextureFormat::R8Uint,
|
||||
format: wgpu::TextureFormat::R32Uint,
|
||||
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, // STORAGE?
|
||||
label: Some("Node texture"),
|
||||
}
|
||||
@@ -57,12 +58,8 @@ impl NodeBuffer {
|
||||
// Bind group
|
||||
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Nearest,
|
||||
min_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge, address_mode_v: wgpu::AddressMode::ClampToEdge, address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Nearest, min_filter: wgpu::FilterMode::Nearest, mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
..Default::default()
|
||||
});
|
||||
let bind_group = device.create_bind_group(
|
||||
@@ -81,10 +78,23 @@ impl NodeBuffer {
|
||||
}
|
||||
|
||||
pub fn write(&mut self, queue: &wgpu::Queue) {
|
||||
// Convert 32 bit values to 8 bit
|
||||
const LEN: usize = DATA.len();
|
||||
let mut bytes : [u8; LEN*4] = [0; LEN*4];
|
||||
for i in 0..LEN {
|
||||
let idx = i * 4;
|
||||
let byte = DATA[i].to_be_bytes();
|
||||
bytes[idx+0] = byte[0];
|
||||
bytes[idx+1] = byte[1];
|
||||
bytes[idx+2] = byte[2];
|
||||
bytes[idx+3] = byte[3];
|
||||
}
|
||||
|
||||
// Write
|
||||
queue.write_texture(
|
||||
wgpu::TextureCopyView { texture: &self.texture, mip_level: 0, origin: wgpu::Origin3d::ZERO },
|
||||
DATA,
|
||||
wgpu::TextureDataLayout { offset: 0, bytes_per_row: self.size.width, rows_per_image: self.size.height },
|
||||
&bytes,
|
||||
wgpu::TextureDataLayout { offset: 0, bytes_per_row: 4*self.size.width, rows_per_image: self.size.height },
|
||||
self.size
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user