changed brick texture from being 32x32x32 1D to 32x32x32 2D (smaller indexes)

This commit is contained in:
Piotrek
2021-04-26 14:01:13 +02:00
parent 1bb45ec31b
commit 6206800df9
7 changed files with 44 additions and 27 deletions
+9 -7
View File
@@ -1,7 +1,5 @@
use std::convert::TryInto;
use crate::renderer::buffers::{BLOCK_SIZE, BLOCK_NUM, BLOCK_LEN};
const DATA_LEN : usize = BLOCK_LEN * BLOCK_NUM;
use crate::renderer::buffers::{BLOCK_SIZE, BLOCK_TEX_SIZE, BLOCK_TEX_LEN, BLOCK_LEN};
pub struct Blocks {
@@ -20,7 +18,8 @@ impl Blocks {
pub fn new(device: &wgpu::Device) -> Self {
// Create texture
let size = wgpu::Extent3d { width: BLOCK_SIZE as u32, height: BLOCK_SIZE as u32, depth: (BLOCK_SIZE*BLOCK_NUM) as u32 };
let BLOCK_TEX_DIM = BLOCK_TEX_SIZE * BLOCK_SIZE;
let size = wgpu::Extent3d { width: BLOCK_SIZE as u32, height: BLOCK_TEX_DIM as u32, depth: BLOCK_TEX_DIM as u32 };
let texture = device.create_texture(
&wgpu::TextureDescriptor {
size: size,
@@ -73,9 +72,9 @@ impl Blocks {
);
// Data
let mut blocks = vec![0_u8; DATA_LEN].into_boxed_slice();
let mut blocks = vec![0_u8; BLOCK_TEX_LEN].into_boxed_slice();
blocks[0] = 1;
println!("block buffer size: {} MB", DATA_LEN as f32 / 1024.0 / 1024.0);
println!("block buffer size: {} MB", BLOCK_TEX_LEN as f32 / 1024.0 / 1024.0);
// Done
Self { blocks, texture, bind_layout, bind_group, free_block: 0 }
@@ -90,7 +89,10 @@ impl Blocks {
let block_offset = block*BLOCK_LEN;
let block_bytes : [u8;BLOCK_LEN] = self.blocks[block_offset..block_offset+BLOCK_LEN].try_into().unwrap();
let block_size = wgpu::Extent3d{ width: BLOCK_SIZE as u32, height: BLOCK_SIZE as u32, depth: BLOCK_SIZE as u32 };
let block_origin = wgpu::Origin3d{ x:0, y:0, z: (block*BLOCK_SIZE) as u32 };
let y = (block%BLOCK_TEX_SIZE * BLOCK_SIZE) as u32;
let z = (block/BLOCK_TEX_SIZE * BLOCK_SIZE) as u32;
let block_origin = wgpu::Origin3d{ x:0, y, z };
// Write
queue.write_texture(