font i guess?
This commit is contained in:
@@ -95,6 +95,7 @@ pub struct MeshHandle {
|
||||
}
|
||||
|
||||
pub(crate) type TextureHandle = usize;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Texture {
|
||||
pub image: Arc<ImmutableImage<Format>>,
|
||||
pub sampler: Arc<Sampler>
|
||||
@@ -331,7 +332,11 @@ impl VulkanRenderer {
|
||||
Arc::new(builder.build().unwrap())
|
||||
}
|
||||
|
||||
|
||||
pub fn update_descriptor_set(&mut self, game_object_handle: &mut GameObjectHandle) {
|
||||
let pipeline_index = game_object_handle.get_game_object_mut(self).unwrap().pipeline_index;
|
||||
let textures = game_object_handle.get_game_object_mut(self).unwrap().textures.clone();
|
||||
self.pipelines[pipeline_index].create_descriptor_set(&textures, self);
|
||||
}
|
||||
|
||||
pub fn render_loop(self: &mut Self, new_ubo: vs::ty::ObjectUniformData) {
|
||||
// cleanup previous frame
|
||||
@@ -460,17 +465,16 @@ impl VulkanRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn upload_texture(self: &mut Self, bytes: &[u8], width: u32, height: u32, format: Format, filter: Filter, wrap: SamplerAddressMode, device: Arc<Device>) {
|
||||
pub fn upload_texture(self: &mut Self, bytes: &[u8], width: u32, height: u32, format: Format, filter: Filter, wrap: SamplerAddressMode, device: Arc<Device>) -> Texture {
|
||||
let dimensions = Dimensions::Dim2d { width, height };
|
||||
|
||||
let usage = ImageUsage {
|
||||
transfer_destination: true,
|
||||
transfer_source: false,
|
||||
transfer_source: true,
|
||||
sampled: true,
|
||||
..ImageUsage::none()
|
||||
};
|
||||
|
||||
let layout = ImageLayout::ShaderReadOnlyOptimal;
|
||||
let mip_maps = if format == Format::R8Uint { MipmapsCount::One } else { MipmapsCount::Log2 };
|
||||
|
||||
let (image_view, initializer) = ImmutableImage::uninitialized(
|
||||
@@ -479,7 +483,7 @@ impl VulkanRenderer {
|
||||
format,
|
||||
mip_maps,
|
||||
usage,
|
||||
layout,
|
||||
ImageLayout::ShaderReadOnlyOptimal,
|
||||
device.active_queue_families(),
|
||||
).unwrap();
|
||||
|
||||
@@ -548,11 +552,79 @@ impl VulkanRenderer {
|
||||
MipmapMode::Linear, wrap, wrap, wrap,
|
||||
0.0, 1.0, 0.0, (image_view.mipmap_levels() - 1) as f32).unwrap();
|
||||
|
||||
self.game_data.textures.push(Texture { image: image_view, sampler });
|
||||
Texture { image: image_view, sampler }
|
||||
}
|
||||
|
||||
pub fn blit_and_update_texture(&mut self, texture: &Texture, new_data: &[u8], new_data_dimensions: [u32; 3], device: Arc<Device>) -> Texture {
|
||||
let new_image_usage = ImageUsage {
|
||||
transfer_destination: true,
|
||||
transfer_source: true,
|
||||
sampled: true,
|
||||
..ImageUsage::none()
|
||||
};
|
||||
|
||||
let (new_image_view, new_image_initializer) = ImmutableImage::uninitialized(
|
||||
device.clone(),
|
||||
Dimensions::Dim2d { width: texture.image.dimensions().width(), height: texture.image.dimensions().height() },
|
||||
texture.image.format(),
|
||||
texture.image.mipmap_levels(),
|
||||
new_image_usage,
|
||||
ImageLayout::ShaderReadOnlyOptimal,
|
||||
device.active_queue_families(),
|
||||
).unwrap();
|
||||
|
||||
let new_sub_image = SubImage::new(
|
||||
Arc::new(new_image_initializer),
|
||||
0,
|
||||
new_image_view.mipmap_levels(),
|
||||
0,
|
||||
1,
|
||||
ImageLayout::ShaderReadOnlyOptimal,
|
||||
);
|
||||
|
||||
let mut cbb = AutoCommandBufferBuilder::new(device.clone(), self.queue.family()).unwrap();
|
||||
|
||||
// cbb.copy_image(
|
||||
// texture.image.clone(),
|
||||
// [0, 0, 0],
|
||||
// 0,
|
||||
// 0,
|
||||
// new_sub_image.clone(),
|
||||
// [0, 0, 0],
|
||||
// 0,
|
||||
// 0,
|
||||
// texture.image.dimensions().width_height_depth(),
|
||||
// 1
|
||||
// ).unwrap();
|
||||
|
||||
let upload_source = CpuAccessibleBuffer::from_iter(
|
||||
device.clone(),
|
||||
BufferUsage::transfer_source(),
|
||||
false,
|
||||
new_data.iter().cloned(),
|
||||
).unwrap();
|
||||
|
||||
cbb.copy_buffer_to_image_dimensions(
|
||||
upload_source.clone(),
|
||||
new_sub_image.clone(),
|
||||
[0, 0, 0],
|
||||
new_data_dimensions,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
).unwrap();
|
||||
|
||||
let cb = cbb.build().unwrap();
|
||||
|
||||
let future = cb.execute(self.queue.clone()).unwrap();
|
||||
|
||||
future.flush().unwrap();
|
||||
|
||||
Texture { image: new_image_view, sampler: texture.sampler.clone() }
|
||||
}
|
||||
|
||||
pub fn add_game_object(self: &mut Self, mut game_object: GameObject) -> GameObjectHandle {
|
||||
self.pipelines[game_object.pipeline_index].create_descriptor_set(&mut game_object, self);
|
||||
game_object.descriptor_sets = self.pipelines[game_object.pipeline_index].create_descriptor_set(&game_object.textures, self);
|
||||
self.game_data.game_objects.push(game_object);
|
||||
|
||||
GameObjectHandle {
|
||||
|
||||
Reference in New Issue
Block a user