pub fn prepare_vertices(device: &VkDevice, command_pool: vk::CommandPool) -> VkResult<(VertexBuffer, IndexBuffer)> {

    // A note on memory management in Vulkan in general:
    // This is a very complex topic and while it's fine for an example application to to small individual memory allocations that is not
    // what should be done a real-world application, where you should allocate large chunks of memory at once instead.

    let vertices_data = [
        Vertex { position: [ 1.0,  1.0, 0.0], color: [1.0, 0.0, 0.0] },
        Vertex { position: [-1.0,  1.0, 0.0], color: [0.0, 1.0, 0.0] },
        Vertex { position: [ 0.0, -1.0, 0.0], color: [0.0, 0.0, 1.0] },
    ];
    let vertices = allocate_buffer(device, &vertices_data, vk::BufferUsageFlags::VERTEX_BUFFER)?;

    let indices_data = [0, 1, 2_u32];
    let indices = allocate_buffer(device, &indices_data, vk::BufferUsageFlags::INDEX_BUFFER)?;

    let copy_command = helper::create_command_buffer(device, command_pool, true)?;

    unsafe {

        let vertex_copy_region = vk::BufferCopy {
            src_offset: 0,
            dst_offset: 0,
            size: vertices.buffer_size,
        };
        device.logic.handle.cmd_copy_buffer(copy_command, vertices.staging_buffer, vertices.target_buffer, &[vertex_copy_region]);

        let index_copy_region = vk::BufferCopy {
            src_offset: 0,
            dst_offset: 0,
            size: indices.buffer_size,
        };
        device.logic.handle.cmd_copy_buffer(copy_command, indices.staging_buffer, indices.target_buffer, &[index_copy_region]);
    }

    // Flushing the command buffer will also submit it to the queue
    // and uses a fence to ensure that all commands have been executed before returning.
    helper::flush_command_buffer(device, command_pool, copy_command)?;

    // Destroy staging buffers
    // Note: Staging buffer must not be deleted before the copies have been submitted and executed.
    unsafe {
        device.logic.handle.destroy_buffer(vertices.staging_buffer, None);
        device.logic.handle.free_memory(vertices.staging_memory, None);

        device.logic.handle.destroy_buffer(indices.staging_buffer, None);
        device.logic.handle.free_memory(indices.staging_memory, None);
    }


    let vertex_buffer = VertexBuffer {
        buffer: vertices.target_buffer,
        memory: vertices.target_memory,
    };

    let index_buffer = IndexBuffer {
        buffer: indices.target_buffer,
        memory: indices.target_memory,
        count: indices_data.len() as _,
    };

    Ok((vertex_buffer, index_buffer))
}
// Prepare vertices buffer and index buffer for an indexed triangle.
Prepare vertices buffer and index buffer for an indexed triangle.
Prepare vertices buffer and index buffer for an indexed triangle .
pub fn prepare_vertices(device: &VkDevice, command_pool: vk::CommandPool) -> VkResult<(VertexBuffer, IndexBuffer)> {
    // A note on memory management in Vulkan in general:
    // This is a very complex topic and while it's fine for an example application to to small individual memory allocations that is not
    // what should be done a real-world application, where you should allocate large chunks of memory at once instead.
    let vertices_data = [
        Vertex { position: [ 1.0,  1.0, 0.0], color: [1.0, 0.0, 0.0] },
        Vertex { position: [-1.0,  1.0, 0.0], color: [0.0, 1.0, 0.0] },
        Vertex { position: [ 0.0, -1.0, 0.0], color: [0.0, 0.0, 1.0] },
    ];
    let vertices = allocate_buffer(device, &vertices_data, vk::BufferUsageFlags::VERTEX_BUFFER)?;
    let indices_data = [0, 1, 2_u32];
    let indices = allocate_buffer(device, &indices_data, vk::BufferUsageFlags::INDEX_BUFFER)?;
    let copy_command = helper::create_command_buffer(device, command_pool, true)?;
    unsafe {
        let vertex_copy_region = vk::BufferCopy {
            src_offset: 0,
            dst_offset: 0,
            size: vertices.buffer_size,
        };
        device.logic.handle.cmd_copy_buffer(copy_command, vertices.staging_buffer, vertices.target_buffer, &[vertex_copy_region]);
        let index_copy_region = vk::BufferCopy {
            src_offset: 0,
            dst_offset: 0,
            size: indices.buffer_size,
        };
        device.logic.handle.cmd_copy_buffer(copy_command, indices.staging_buffer, indices.target_buffer, &[index_copy_region]);
    }
    // Flushing the command buffer will also submit it to the queue
    // and uses a fence to ensure that all commands have been executed before returning.
    helper::flush_command_buffer(device, command_pool, copy_command)?;
    // Destroy staging buffers
    // Note: Staging buffer must not be deleted before the copies have been submitted and executed.
    unsafe {
        device.logic.handle.destroy_buffer(vertices.staging_buffer, None);
        device.logic.handle.free_memory(vertices.staging_memory, None);
        device.logic.handle.destroy_buffer(indices.staging_buffer, None);
        device.logic.handle.free_memory(indices.staging_memory, None);
    }
    let vertex_buffer = VertexBuffer {
        buffer: vertices.target_buffer,
        memory: vertices.target_memory,
    };
    let index_buffer = IndexBuffer {
        buffer: indices.target_buffer,
        memory: indices.target_memory,
        count: indices_data.len() as _,
    };
    Ok((vertex_buffer, index_buffer))
}
pub fn prepare_vertices ( device : & VkDevice , command_pool : vk :: CommandPool ) -> VkResult < ( VertexBuffer , IndexBuffer ) > { // A note on memory management in Vulkan in general: // This is a very complex topic and while it's fine for an example application to to small individual memory allocations that is not // what should be done a real-world application, where you should allocate large chunks of memory at once instead. let vertices_data = [ Vertex { position : [ 1.0 , 1.0 , 0.0 ] , color : [ 1.0 , 0.0 , 0.0 ] } , Vertex { position : [ - 1.0 , 1.0 , 0.0 ] , color : [ 0.0 , 1.0 , 0.0 ] } , Vertex { position : [ 0.0 , - 1.0 , 0.0 ] , color : [ 0.0 , 0.0 , 1.0 ] } , ] ; let vertices = allocate_buffer ( device , & vertices_data , vk :: BufferUsageFlags :: VERTEX_BUFFER ) ? ; let indices_data = [ 0 , 1 , 2_u32 ] ; let indices = allocate_buffer ( device , & indices_data , vk :: BufferUsageFlags :: INDEX_BUFFER ) ? ; let copy_command = helper :: create_command_buffer ( device , command_pool , true ) ? ; unsafe { let vertex_copy_region = vk :: BufferCopy { src_offset : 0 , dst_offset : 0 , size : vertices . buffer_size , } ; device . logic . handle . cmd_copy_buffer ( copy_command , vertices . staging_buffer , vertices . target_buffer , & [ vertex_copy_region ] ) ; let index_copy_region = vk :: BufferCopy { src_offset : 0 , dst_offset : 0 , size : indices . buffer_size , } ; device . logic . handle . cmd_copy_buffer ( copy_command , indices . staging_buffer , indices . target_buffer , & [ index_copy_region ] ) ; } // Flushing the command buffer will also submit it to the queue // and uses a fence to ensure that all commands have been executed before returning. helper :: flush_command_buffer ( device , command_pool , copy_command ) ? ; // Destroy staging buffers // Note: Staging buffer must not be deleted before the copies have been submitted and executed. unsafe { device . logic . handle . destroy_buffer ( vertices . staging_buffer , None ) ; device . logic . handle . free_memory ( vertices . staging_memory , None ) ; device . logic . handle . destroy_buffer ( indices . staging_buffer , None ) ; device . logic . handle . free_memory ( indices . staging_memory , None ) ; } let vertex_buffer = VertexBuffer { buffer : vertices . target_buffer , memory : vertices . target_memory , } ; let index_buffer = IndexBuffer { buffer : indices . target_buffer , memory : indices . target_memory , count : indices_data . len ( ) as _ , } ; Ok ( ( vertex_buffer , index_buffer ) ) }
Prepare vertices buffer and index buffer for an indexed triangle.
Prepare vertices buffer and index buffer for an indexed triangle .
device
&VkDevice
command_pool
vk::CommandPool
device
&VkDevice
command_pool
vk::CommandPool