dynamic cache texture size!!

This commit is contained in:
2021-10-14 06:25:58 +02:00
parent ba172ea332
commit 366e3896da
3 changed files with 77 additions and 89 deletions

View File

@@ -568,7 +568,9 @@ impl VulkanRenderer {
Texture { image: image_view, sampler }
}
pub fn update_texture(&mut self, texture: &mut Texture, new_data: &[u8], new_data_dimensions: [u32; 3], new_data_offset: [u32; 3], device: Arc<Device>) {
pub fn update_texture(&mut self, tex_handle: TextureHandle, new_data: &[u8], new_data_dimensions: [u32; 3], new_data_offset: [u32; 3], device: Arc<Device>) {
let texture = &mut self.game_data.textures[tex_handle];
let old_sub_image = SubImage::new(
texture.image.clone(),
0,
@@ -604,7 +606,9 @@ impl VulkanRenderer {
future.flush().unwrap();
}
pub fn resize_texture(&mut self, game_object: &mut GameObject, old_texture: &mut Texture, new_size: Dimensions, device: Arc<Device>) {
pub fn resize_texture(&mut self, game_object: &mut GameObject, texture_handle: TextureHandle, new_size: Dimensions) {
let mut texture = &mut self.game_data.textures[texture_handle];
let new_image_usage = ImageUsage {
transfer_destination: true,
transfer_source: true,
@@ -613,17 +617,17 @@ impl VulkanRenderer {
};
let (new_image_view, new_image_initializer) = ImmutableImage::uninitialized(
device.clone(),
self.device.clone(),
new_size,
old_texture.image.format(),
old_texture.image.mipmap_levels(),
texture.image.format(),
texture.image.mipmap_levels(),
new_image_usage,
ImageLayout::ShaderReadOnlyOptimal,
device.active_queue_families(),
self.device.active_queue_families(),
).unwrap();
let old_sub_image = SubImage::new(
old_texture.image.clone(),
texture.image.clone(),
0,
1,
0,
@@ -640,7 +644,7 @@ impl VulkanRenderer {
ImageLayout::ShaderReadOnlyOptimal,
);
let mut cbb = AutoCommandBufferBuilder::new(device.clone(), self.queue.family()).unwrap();
let mut cbb = AutoCommandBufferBuilder::new(self.device.clone(), self.queue.family()).unwrap();
cbb.copy_image(
old_sub_image.clone(),
@@ -648,7 +652,7 @@ impl VulkanRenderer {
0,
0,
new_sub_image.clone(),
[0, 0, 0],
[10, 0, 0],
0,
0,
old_sub_image.dimensions().width_height_depth(),
@@ -659,7 +663,7 @@ impl VulkanRenderer {
let future = cb.execute(self.queue.clone()).unwrap();
future.flush().unwrap();
old_texture.image = new_image_view;
texture.image = new_image_view;
game_object.init_descriptor_sets(self);
}

View File

@@ -350,6 +350,7 @@ impl Drawcall for TextShader {
let builder = PersistentDescriptorSet::start(descriptor_set_layout.clone());
let diffuse = &renderer.game_data.textures[textures.texture_index];
println!("Using diffuse image with size {:?}", diffuse.image.dimensions());
descriptor_set = Arc::new(builder
.add_buffer(uniform_buffer.clone()).unwrap()