fn record_commands(&self, device: &VkDevice, dimension: vk::Extent2D) -> VkResult<()> {

        let cmd_begin_ci = vk::CommandBufferBeginInfo {
            s_type: vk::StructureType::COMMAND_BUFFER_BEGIN_INFO,
            p_next: ptr::null(),
            flags : vk::CommandBufferUsageFlags::empty(),
            p_inheritance_info: ptr::null(),
        };

        // Set clear values for all framebuffer attachments with loadOp set to clear.
        // Use two attachments (color and depth) that are cleared at the start of the subpass,
        // and as such we need to set clear values for both.
        let clear_values = [
            vk::ClearValue { color: vk::ClearColorValue { float32: [0.0, 0.0, 0.2, 1.0] } },
            vk::ClearValue { depth_stencil: vk::ClearDepthStencilValue { depth: 1.0, stencil: 0 } },
        ];

        for (i, command) in self.commands.iter().enumerate() {

            let renderpass_begin_ci = vk::RenderPassBeginInfo {
                s_type: vk::StructureType::RENDER_PASS_BEGIN_INFO,
                p_next: ptr::null(),
                render_pass: self.render_pass,
                framebuffer: self.framebuffers[i],
                render_area: vk::Rect2D {
                    extent: dimension,
                    offset: vk::Offset2D { x: 0, y: 0 },
                },
                clear_value_count: clear_values.len() as _,
                p_clear_values   : clear_values.as_ptr(),
            };

            let viewport = vk::Viewport {
                x: 0.0, y: 0.0,
                width: dimension.width as f32, height: dimension.height as f32,
                min_depth: 0.0, max_depth: 1.0,
            };

            let scissor = vk::Rect2D {
                extent: dimension.clone(),
                offset: vk::Offset2D { x: 0, y: 0 },
            };

            // Start the first sub pass specified in our default render pass setup by the base class.
            // This will clear the color and depth attachment.
            unsafe {

                device.logic.handle.begin_command_buffer(command.clone(), &cmd_begin_ci)
                    .map_err(|_| VkError::device("Begin command buffer"))?;

                device.logic.handle.cmd_begin_render_pass(command.clone(), &renderpass_begin_ci, vk::SubpassContents::INLINE);
                // update viewport state.
                device.logic.handle.cmd_set_viewport(command.clone(), 0, &[viewport]);
                // update dynamic scissor state.
                device.logic.handle.cmd_set_scissor(command.clone(), 0, &[scissor]);
                // bind descriptor sets describing shader binding points.
                device.logic.handle.cmd_bind_descriptor_sets(command.clone(), vk::PipelineBindPoint::GRAPHICS, self.pipeline_layout, 0, &[self.descriptor_set], &[]);

                // bind the rendering pipeline.
                // the pipeline (state object) contains all states of the rendering pipeline.
                // binding it will set all the states specified at pipeline creation time.
                device.logic.handle.cmd_bind_pipeline(command.clone(), vk::PipelineBindPoint::GRAPHICS, self.pipeline);

                // bind triangle vertices buffer (contains position and colors).
                device.logic.handle.cmd_bind_vertex_buffers(command.clone(), 0, &[self.vertex_buffer.buffer], &[0]);
                // bind triangle index buffer.
                device.logic.handle.cmd_bind_index_buffer(command.clone(), self.index_buffer.buffer, 0, vk::IndexType::UINT32);

                // draw indexed triangle.
                device.logic.handle.cmd_draw_indexed(command.clone(), self.index_buffer.count, 1, 0, 0, 1);

                device.logic.handle.cmd_end_render_pass(command.clone());

                // ending the render pass will add an implicit barrier transitioning the frame buffer color attachment to
                // VK_IMAGE_LAYOUT_PRESENT_SRC_KHR for presenting it to the windowing system.
                device.logic.handle.end_command_buffer(command.clone())
                    .map_err(|_| VkError::device("End command buffer"))?;
            }

        }

        Ok(())
    }
// Build separate command buffers for every framebuffer image.
// Unlike in OpenGL all rendering commands are recorded once into command buffers that are then resubmitted to the queue.
// This allows to generate work upfront and from multiple threads, one of the biggest advantages of Vulkan.
Build separate command buffers for every framebuffer image.
Unlike in OpenGL all rendering commands are recorded once into command buffers that are then resubmitted to the queue.
This allows to generate work upfront and from multiple threads, one of the biggest advantages of Vulkan.
Build separate command buffers for every framebuffer image . Unlike in OpenGL all rendering commands are recorded once into command buffers that are then resubmitted to the queue . This allows to generate work upfront and from multiple threads one of the biggest advantages of Vulkan .
fn record_commands(&self, device: &VkDevice, dimension: vk::Extent2D) -> VkResult<()> {
        let cmd_begin_ci = vk::CommandBufferBeginInfo {
            s_type: vk::StructureType::COMMAND_BUFFER_BEGIN_INFO,
            p_next: ptr::null(),
            flags : vk::CommandBufferUsageFlags::empty(),
            p_inheritance_info: ptr::null(),
        };
        // Set clear values for all framebuffer attachments with loadOp set to clear.
        // Use two attachments (color and depth) that are cleared at the start of the subpass,
        // and as such we need to set clear values for both.
        let clear_values = [
            vk::ClearValue { color: vk::ClearColorValue { float32: [0.0, 0.0, 0.2, 1.0] } },
            vk::ClearValue { depth_stencil: vk::ClearDepthStencilValue { depth: 1.0, stencil: 0 } },
        ];
        for (i, command) in self.commands.iter().enumerate() {
            let renderpass_begin_ci = vk::RenderPassBeginInfo {
                s_type: vk::StructureType::RENDER_PASS_BEGIN_INFO,
                p_next: ptr::null(),
                render_pass: self.render_pass,
                framebuffer: self.framebuffers[i],
                render_area: vk::Rect2D {
                    extent: dimension,
                    offset: vk::Offset2D { x: 0, y: 0 },
                },
                clear_value_count: clear_values.len() as _,
                p_clear_values   : clear_values.as_ptr(),
            };
            let viewport = vk::Viewport {
                x: 0.0, y: 0.0,
                width: dimension.width as f32, height: dimension.height as f32,
                min_depth: 0.0, max_depth: 1.0,
            };
            let scissor = vk::Rect2D {
                extent: dimension.clone(),
                offset: vk::Offset2D { x: 0, y: 0 },
            };
            // Start the first sub pass specified in our default render pass setup by the base class.
            // This will clear the color and depth attachment.
            unsafe {
                device.logic.handle.begin_command_buffer(command.clone(), &cmd_begin_ci)
                    .map_err(|_| VkError::device("Begin command buffer"))?;
                device.logic.handle.cmd_begin_render_pass(command.clone(), &renderpass_begin_ci, vk::SubpassContents::INLINE);
                // update viewport state.
                device.logic.handle.cmd_set_viewport(command.clone(), 0, &[viewport]);
                // update dynamic scissor state.
                device.logic.handle.cmd_set_scissor(command.clone(), 0, &[scissor]);
                // bind descriptor sets describing shader binding points.
                device.logic.handle.cmd_bind_descriptor_sets(command.clone(), vk::PipelineBindPoint::GRAPHICS, self.pipeline_layout, 0, &[self.descriptor_set], &[]);
                // bind the rendering pipeline.
                // the pipeline (state object) contains all states of the rendering pipeline.
                // binding it will set all the states specified at pipeline creation time.
                device.logic.handle.cmd_bind_pipeline(command.clone(), vk::PipelineBindPoint::GRAPHICS, self.pipeline);
                // bind triangle vertices buffer (contains position and colors).
                device.logic.handle.cmd_bind_vertex_buffers(command.clone(), 0, &[self.vertex_buffer.buffer], &[0]);
                // bind triangle index buffer.
                device.logic.handle.cmd_bind_index_buffer(command.clone(), self.index_buffer.buffer, 0, vk::IndexType::UINT32);
                // draw indexed triangle.
                device.logic.handle.cmd_draw_indexed(command.clone(), self.index_buffer.count, 1, 0, 0, 1);
                device.logic.handle.cmd_end_render_pass(command.clone());
                // ending the render pass will add an implicit barrier transitioning the frame buffer color attachment to
                // VK_IMAGE_LAYOUT_PRESENT_SRC_KHR for presenting it to the windowing system.
                device.logic.handle.end_command_buffer(command.clone())
                    .map_err(|_| VkError::device("End command buffer"))?;
            }
        }
        Ok(())
    }
fn record_commands ( & self , device : & VkDevice , dimension : vk :: Extent2D ) -> VkResult < ( ) > { let cmd_begin_ci = vk :: CommandBufferBeginInfo { s_type : vk :: StructureType :: COMMAND_BUFFER_BEGIN_INFO , p_next : ptr :: null ( ) , flags : vk :: CommandBufferUsageFlags :: empty ( ) , p_inheritance_info : ptr :: null ( ) , } ; // Set clear values for all framebuffer attachments with loadOp set to clear. // Use two attachments (color and depth) that are cleared at the start of the subpass, // and as such we need to set clear values for both. let clear_values = [ vk :: ClearValue { color : vk :: ClearColorValue { float32 : [ 0.0 , 0.0 , 0.2 , 1.0 ] } } , vk :: ClearValue { depth_stencil : vk :: ClearDepthStencilValue { depth : 1.0 , stencil : 0 } } , ] ; for ( i , command ) in self . commands . iter ( ) . enumerate ( ) { let renderpass_begin_ci = vk :: RenderPassBeginInfo { s_type : vk :: StructureType :: RENDER_PASS_BEGIN_INFO , p_next : ptr :: null ( ) , render_pass : self . render_pass , framebuffer : self . framebuffers [ i ] , render_area : vk :: Rect2D { extent : dimension , offset : vk :: Offset2D { x : 0 , y : 0 } , } , clear_value_count : clear_values . len ( ) as _ , p_clear_values : clear_values . as_ptr ( ) , } ; let viewport = vk :: Viewport { x : 0.0 , y : 0.0 , width : dimension . width as f32 , height : dimension . height as f32 , min_depth : 0.0 , max_depth : 1.0 , } ; let scissor = vk :: Rect2D { extent : dimension . clone ( ) , offset : vk :: Offset2D { x : 0 , y : 0 } , } ; // Start the first sub pass specified in our default render pass setup by the base class. // This will clear the color and depth attachment. unsafe { device . logic . handle . begin_command_buffer ( command . clone ( ) , & cmd_begin_ci ) . map_err ( | _ | VkError :: device ( " " ) ) ? ; device . logic . handle . cmd_begin_render_pass ( command . clone ( ) , & renderpass_begin_ci , vk :: SubpassContents :: INLINE ) ; // update viewport state. device . logic . handle . cmd_set_viewport ( command . clone ( ) , 0 , & [ viewport ] ) ; // update dynamic scissor state. device . logic . handle . cmd_set_scissor ( command . clone ( ) , 0 , & [ scissor ] ) ; // bind descriptor sets describing shader binding points. device . logic . handle . cmd_bind_descriptor_sets ( command . clone ( ) , vk :: PipelineBindPoint :: GRAPHICS , self . pipeline_layout , 0 , & [ self . descriptor_set ] , & [ ] ) ; // bind the rendering pipeline. // the pipeline (state object) contains all states of the rendering pipeline. // binding it will set all the states specified at pipeline creation time. device . logic . handle . cmd_bind_pipeline ( command . clone ( ) , vk :: PipelineBindPoint :: GRAPHICS , self . pipeline ) ; // bind triangle vertices buffer (contains position and colors). device . logic . handle . cmd_bind_vertex_buffers ( command . clone ( ) , 0 , & [ self . vertex_buffer . buffer ] , & [ 0 ] ) ; // bind triangle index buffer. device . logic . handle . cmd_bind_index_buffer ( command . clone ( ) , self . index_buffer . buffer , 0 , vk :: IndexType :: UINT32 ) ; // draw indexed triangle. device . logic . handle . cmd_draw_indexed ( command . clone ( ) , self . index_buffer . count , 1 , 0 , 0 , 1 ) ; device . logic . handle . cmd_end_render_pass ( command . clone ( ) ) ; // ending the render pass will add an implicit barrier transitioning the frame buffer color attachment to // VK_IMAGE_LAYOUT_PRESENT_SRC_KHR for presenting it to the windowing system. device . logic . handle . end_command_buffer ( command . clone ( ) ) . map_err ( | _ | VkError :: device ( " " ) ) ? ; } } Ok ( ( ) ) }
Build separate command buffers for every framebuffer image.
Build separate command buffers for every framebuffer image .
&self
device
&VkDevice
dimension
vk::Extent2D
&self
device
&VkDevice
dimension
vk::Extent2D