updating node buffer max once per frame
This commit is contained in:
@@ -11,6 +11,7 @@ pub const NODE_TEX_SIZE: usize = 48; // 32x32x32 nodes in texture
|
||||
pub struct Content {
|
||||
node_buffer: Box<[u32]>,
|
||||
node_texture: wgpu::Texture,
|
||||
node_dirty: bool,
|
||||
block_freeidx: usize,
|
||||
block_texture: wgpu::Texture,
|
||||
pub bind_layout: wgpu::BindGroupLayout,
|
||||
@@ -68,7 +69,7 @@ impl Content {
|
||||
|
||||
// Done
|
||||
let block_freeidx = 0;
|
||||
Self { node_buffer, node_texture, block_freeidx, block_texture, bind_layout, bind_group }
|
||||
Self { node_buffer, node_dirty: false, node_texture, block_freeidx, block_texture, bind_layout, bind_group }
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
@@ -84,9 +85,10 @@ impl Content {
|
||||
self.node_buffer[index] = value as u32;
|
||||
self.block_freeidx = value;
|
||||
//println!("Alloc: {}", value);
|
||||
}
|
||||
|
||||
//println!("Index: {} Value: {}", index, value);
|
||||
// Mark node buffer as dirty
|
||||
self.node_dirty = true;
|
||||
}
|
||||
|
||||
// Calculate position in block texture
|
||||
let y = ((value-1) % BLOCK_TEX_SIZE * BLOCK_SIZE) as u32;
|
||||
@@ -102,6 +104,11 @@ impl Content {
|
||||
wgpu::TextureCopyView { texture: &self.block_texture, mip_level: 0, origin: block_origin }, &block_bytes,
|
||||
wgpu::TextureDataLayout { offset: 0, bytes_per_row: block_size.width, rows_per_image: block_size.height }, block_size
|
||||
);
|
||||
}
|
||||
|
||||
pub fn update(&mut self, queue: &wgpu::Queue) {
|
||||
if self.node_dirty {
|
||||
self.node_dirty = false;
|
||||
|
||||
// Convert u32 node buffer to u8
|
||||
let node_size = wgpu::Extent3d { width: NODE_TEX_SIZE as u32, height: NODE_TEX_SIZE as u32, depth: NODE_TEX_SIZE as u32 };
|
||||
@@ -114,4 +121,5 @@ impl Content {
|
||||
wgpu::TextureDataLayout { offset: 0, bytes_per_row: 4*node_size.width, rows_per_image: node_size.height }, node_size
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,9 @@ impl Renderer {
|
||||
self.buffers.uniforms.values.update(&self.camera, self.start.elapsed().as_secs_f32());
|
||||
self.queue.write_buffer(&self.buffers.uniforms.buffer, 0, bytemuck::cast_slice(&[self.buffers.uniforms.values]));
|
||||
|
||||
// Update content
|
||||
self.buffers.content.update(&self.queue);
|
||||
|
||||
// Get next frame to render to
|
||||
let frame = self.swapchain.get_current_frame()?.output;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user