fix texture format
This commit is contained in:
@@ -2,7 +2,7 @@ use wgpu::util::DeviceExt;
|
||||
use std::convert::TryInto;
|
||||
|
||||
const BRICK_SIZE : usize = 32; // 32x32x32 brick size
|
||||
const BRICK_NUM : usize = 10000; // 64 bricks in texture
|
||||
const BRICK_NUM : usize = 1; // 64 bricks in texture
|
||||
|
||||
const BRICK_LEN : usize = BRICK_SIZE*BRICK_SIZE*BRICK_SIZE;
|
||||
const DATA_LEN : usize = BRICK_LEN * BRICK_NUM;
|
||||
@@ -46,7 +46,7 @@ impl BrickBuffer {
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D3,
|
||||
format: wgpu::TextureFormat::R32Uint,
|
||||
format: wgpu::TextureFormat::R8Uint,
|
||||
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, // STORAGE?
|
||||
label: Some("Brick texture"),
|
||||
}
|
||||
@@ -93,6 +93,7 @@ impl BrickBuffer {
|
||||
|
||||
// Data
|
||||
let mut bricks = BrickData::new();
|
||||
println!("Brick buffer size: {} MB", DATA_LEN as f32 / 1024.0 / 1024.0);
|
||||
for x in 0..32 {
|
||||
for y in 0..16 {
|
||||
for z in 0..32 {
|
||||
@@ -102,23 +103,26 @@ impl BrickBuffer {
|
||||
}
|
||||
|
||||
// Done
|
||||
println!("Brick buffer size: {} MB", DATA_LEN as f32 / 1024.0 / 1024.0);
|
||||
Self { bricks, texture, size, bind_layout, bind_group }
|
||||
}
|
||||
|
||||
pub fn write(&mut self, queue: &wgpu::Queue)
|
||||
/*
|
||||
Write brick data to gpu, should be called to apply changes
|
||||
offset: Brick index to copy
|
||||
*/
|
||||
pub fn write(&mut self, queue: &wgpu::Queue, offset: usize)
|
||||
{
|
||||
return ();
|
||||
|
||||
// Get first brick
|
||||
let brick_bytes : [u8;BRICK_LEN] = self.bricks.data[0..BRICK_LEN].try_into().unwrap();
|
||||
let brick_offset = offset*BRICK_LEN;
|
||||
let brick_bytes : [u8;BRICK_LEN] = self.bricks.data[brick_offset..brick_offset+BRICK_LEN].try_into().unwrap();
|
||||
let brick_size = wgpu::Extent3d{ width: BRICK_SIZE as u32, height: BRICK_SIZE as u32, depth: BRICK_SIZE as u32 };
|
||||
let brick_origin = wgpu::Origin3d{ x:0, y:0, z: offset as u32 };
|
||||
|
||||
// Write
|
||||
queue.write_texture(
|
||||
wgpu::TextureCopyView { texture: &self.texture, mip_level: 0, origin: wgpu::Origin3d::ZERO },
|
||||
wgpu::TextureCopyView { texture: &self.texture, mip_level: 0, origin: brick_origin },
|
||||
&brick_bytes,
|
||||
wgpu::TextureDataLayout { offset: 0, bytes_per_row: self.size.width, rows_per_image: self.size.height },
|
||||
wgpu::TextureDataLayout { offset: 0, bytes_per_row: brick_size.width, rows_per_image: brick_size.height },
|
||||
brick_size
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user