Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //object picking;
- if (settings.pick) {
- //start recording object picking command buffer
- if (vkBeginCommandBuffer(object_picking_commandBuffer[image_index], &beginInfo) != VK_SUCCESS) {
- throw std::runtime_error("failed to begin recording command buffer!");
- }
- //begin renderpass
- VkRenderPassBeginInfo object_picking_renderpass_begin_info{};
- object_picking_renderpass_begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
- object_picking_renderpass_begin_info.renderPass = object_picking_pass;
- object_picking_renderpass_begin_info.framebuffer = object_picking_fb;
- object_picking_renderpass_begin_info.renderArea.offset = { 0,0 };
- object_picking_renderpass_begin_info.renderArea.extent = swapChainExtent;
- object_picking_renderpass_begin_info.clearValueCount = static_cast<uint32_t>(clearValues.size());
- object_picking_renderpass_begin_info.pClearValues = clearValues.data();
- vkCmdBeginRenderPass(object_picking_commandBuffer[image_index], &object_picking_renderpass_begin_info,
- VK_SUBPASS_CONTENTS_INLINE);
- vkCmdBindPipeline(object_picking_commandBuffer[image_index], VK_PIPELINE_BIND_POINT_GRAPHICS,
- pipelines[object_picking_pipeline].pipeline);
- //render all renderables
- for (size_t j = 0; j < active_renderables.size(); j++)
- {
- //the dynamic pipeline state means we have to set the scissor before each draw
- VkRect2D rect{};
- rect.offset.x = InputSystem::get_mouse_position().x > 0 ? InputSystem::get_mouse_position().x : 0;
- rect.offset.y = InputSystem::get_mouse_position().y > 0 ? InputSystem::get_mouse_position().y : 0;
- rect.extent = { 1,1 };
- //can only be used with a dynamic scissor state
- vkCmdSetScissor(object_picking_commandBuffer[image_index], 0, 1, &rect);
- //bind descriptor sets for current object
- vkCmdBindDescriptorSets(commandBuffers[image_index], VK_PIPELINE_BIND_POINT_GRAPHICS,
- pipelines[object_picking_pipeline].pipeline_layout, 0, 1,/*choose correct descriptor*/,
- 0,nullptr);
- //bind vertex and index buffers for current object
- vkCmdBindVertexBuffers(commandBuffers[image_index], 0, 1,
- &vkvertexBuffers[renderables[active_renderables[j]].vertex_buffer_index], &vertexOffsets[j]);
- vkCmdBindIndexBuffer(commandBuffers[image_index], vkindexBuffers[renderables[active_renderables[j]].index_buffer_index],
- 0,VK_INDEX_TYPE_UINT32);
- //draw
- vkCmdDrawIndexed(object_picking_commandBuffer[image_index], static_cast<uint32_t>(index_size), 1, 0, 0, 0);
- offset += index_size[j];
- }
- vkCmdEndRenderPass(object_picking_commandBuffer[image_index]);
- if (vkEndCommandBuffer(object_picking_commandBuffer[image_index]) != VK_SUCCESS) {
- throw std::runtime_error("failed to record command buffer!");
- }
- }
Add Comment
Please, Sign In to add comment