whillothewhisp

Command_buffer_recording

Jan 5th, 2022 (edited)
1,811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1.     //object picking;
  2.     if (settings.pick) {
  3.         //start recording object picking command buffer
  4.         if (vkBeginCommandBuffer(object_picking_commandBuffer[image_index], &beginInfo) != VK_SUCCESS) {
  5.             throw std::runtime_error("failed to begin recording command buffer!");
  6.         }
  7.         //begin renderpass
  8.         VkRenderPassBeginInfo object_picking_renderpass_begin_info{};
  9.         object_picking_renderpass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
  10.         object_picking_renderpass_begin_info.renderPass = object_picking_pass;
  11.         object_picking_renderpass_begin_info.framebuffer = object_picking_fb;
  12.         object_picking_renderpass_begin_info.renderArea.offset = { 0,0 };
  13.         object_picking_renderpass_begin_info.renderArea.extent = swapChainExtent;
  14.         object_picking_renderpass_begin_info.clearValueCount = static_cast<uint32_t>(clearValues.size());
  15.         object_picking_renderpass_begin_info.pClearValues = clearValues.data();
  16.  
  17.         vkCmdBeginRenderPass(object_picking_commandBuffer[image_index], &object_picking_renderpass_begin_info,
  18.                              VK_SUBPASS_CONTENTS_INLINE);
  19.        
  20.         vkCmdBindPipeline(object_picking_commandBuffer[image_index], VK_PIPELINE_BIND_POINT_GRAPHICS,        
  21.                           pipelines[object_picking_pipeline].pipeline);
  22.        
  23.         //render all renderables
  24.         for (size_t j = 0; j < active_renderables.size(); j++)
  25.         {
  26.             //the dynamic pipeline state means we have to set the scissor before each draw
  27.             VkRect2D rect{};
  28.             rect.offset.x = InputSystem::get_mouse_position().x > 0 ? InputSystem::get_mouse_position().x : 0;
  29.             rect.offset.y = InputSystem::get_mouse_position().y > 0 ? InputSystem::get_mouse_position().y : 0;
  30.             rect.extent = { 1,1 };
  31.            
  32.             //can only be used with a dynamic scissor state
  33.             vkCmdSetScissor(object_picking_commandBuffer[image_index], 0, 1, &rect);
  34.        
  35.             //bind descriptor sets for current object
  36.             vkCmdBindDescriptorSets(commandBuffers[image_index], VK_PIPELINE_BIND_POINT_GRAPHICS,
  37.                                     pipelines[object_picking_pipeline].pipeline_layout, 0, 1,/*choose correct descriptor*/,
  38.                                     0,nullptr);
  39.            
  40.             //bind vertex and index buffers for current object
  41.             vkCmdBindVertexBuffers(commandBuffers[image_index], 0, 1,
  42.                                    &vkvertexBuffers[renderables[active_renderables[j]].vertex_buffer_index], &vertexOffsets[j]);
  43.             vkCmdBindIndexBuffer(commandBuffers[image_index], vkindexBuffers[renderables[active_renderables[j]].index_buffer_index],
  44.                                  0,VK_INDEX_TYPE_UINT32);
  45.  
  46.             //draw
  47.             vkCmdDrawIndexed(object_picking_commandBuffer[image_index], static_cast<uint32_t>(index_size), 1, 0, 0, 0);
  48.  
  49.             offset += index_size[j];
  50.        }
  51.         vkCmdEndRenderPass(object_picking_commandBuffer[image_index]);
  52.  
  53.         if (vkEndCommandBuffer(object_picking_commandBuffer[image_index]) != VK_SUCCESS) {
  54.             throw std::runtime_error("failed to record command buffer!");
  55.         }
  56.  
  57.  
  58.     }
  59.  
Add Comment
Please, Sign In to add comment