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(
+9 -5
View File
@@ -1,12 +1,16 @@
// Consts
pub const WORLD_SIZE: usize = 32;
pub const NUM_NODES: usize = (WORLD_SIZE*WORLD_SIZE*WORLD_SIZE) as usize;
pub const BLOCK_SIZE : usize = 32; // 32x32x32 block size
pub const BLOCK_TEX_SIZE : usize = 64; // 64x64 blocks in texture
pub const NODE_TEX_SIZE: usize = 32; // 32x32x32 nodes in texture
pub const NODE_TEX_LEN: usize = NODE_TEX_SIZE*NODE_TEX_SIZE*NODE_TEX_SIZE; // Number of u32 in node texture
pub const BLOCK_LEN : usize = BLOCK_SIZE*BLOCK_SIZE*BLOCK_SIZE; // Number of u8 in one block
pub const BLOCK_TEX_LEN: usize = BLOCK_TEX_SIZE*BLOCK_TEX_SIZE * BLOCK_LEN; // Number of u8 in block texture
pub const BLOCK_SIZE : usize = 32; // 32x32x32 brick size
pub const BLOCK_NUM : usize = 32768; // max bricks in texture
pub const BLOCK_LEN : usize = BLOCK_SIZE*BLOCK_SIZE*BLOCK_SIZE;
// Import names
+4 -4
View File
@@ -1,7 +1,7 @@
use byteorder::{ByteOrder, LittleEndian};
use rand::prelude::*;
use crate::renderer::buffers::{WORLD_SIZE, NUM_NODES};
use crate::renderer::buffers::{NODE_TEX_SIZE, NODE_TEX_LEN};
pub struct Nodes {
pub nodes: Box<[u32]>,
@@ -16,7 +16,7 @@ impl Nodes {
pub fn new(device: &wgpu::Device) -> Self {
// Create texture
let size = wgpu::Extent3d { width: WORLD_SIZE as u32, height: WORLD_SIZE as u32, depth: WORLD_SIZE as u32 };
let size = wgpu::Extent3d { width: NODE_TEX_SIZE as u32, height: NODE_TEX_SIZE as u32, depth: NODE_TEX_SIZE as u32 };
let texture = device.create_texture(
&wgpu::TextureDescriptor {
size: size,
@@ -69,7 +69,7 @@ impl Nodes {
);
// Data
let nodes = vec![0_u32; NUM_NODES].into_boxed_slice();
let nodes = vec![0_u32; NODE_TEX_LEN].into_boxed_slice();
println!("Node buffer size: {} MB", nodes.len() as f32 * 4.0 / 1024.0 / 1024.0);
// Done
@@ -78,7 +78,7 @@ impl Nodes {
pub fn write(&mut self, queue: &wgpu::Queue) {
// Convert 32 bit values to 8 bit
let mut bytes = [0_u8; NUM_NODES*4];
let mut bytes = [0_u8; NODE_TEX_LEN*4];
LittleEndian::write_u32_into(&self.nodes, &mut bytes);
// Write