| 735 | } |
| 736 | |
| 737 | void vkRenderer::createCommandBuffers() { |
| 738 | commandBuffers.resize(swapChainFramebuffers.size()); |
| 739 | |
| 740 | VkCommandBufferAllocateInfo allocInfo = {}; |
| 741 | allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 742 | allocInfo.commandPool = commandPool; |
| 743 | allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 744 | allocInfo.commandBufferCount = (uint32_t) commandBuffers.size(); |
| 745 | |
| 746 | if (vkAllocateCommandBuffers(device, &allocInfo, commandBuffers.data()) != VK_SUCCESS) { |
| 747 | throw std::runtime_error("failed to allocate command buffers!"); |
| 748 | } |
| 749 | |
| 750 | for (size_t i = 0; i < commandBuffers.size(); i++) { |
| 751 | VkCommandBufferBeginInfo beginInfo = {}; |
| 752 | beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 753 | beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; |
| 754 | |
| 755 | if (vkBeginCommandBuffer(commandBuffers[i], &beginInfo) != VK_SUCCESS) { |
| 756 | throw std::runtime_error("failed to begin recording command buffer!"); |
| 757 | } |
| 758 | |
| 759 | VkRenderPassBeginInfo renderPassInfo = {}; |
| 760 | renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 761 | renderPassInfo.renderPass = renderPass; |
| 762 | renderPassInfo.framebuffer = swapChainFramebuffers[i]; |
| 763 | renderPassInfo.renderArea.offset = {0, 0}; |
| 764 | renderPassInfo.renderArea.extent = swapChainExtent; |
| 765 | |
| 766 | VkClearValue clearColor = {0.0f, 0.0f, 0.0f, 1.0f}; |
| 767 | renderPassInfo.clearValueCount = 1; |
| 768 | renderPassInfo.pClearValues = &clearColor; |
| 769 | |
| 770 | vkCmdBeginRenderPass(commandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); |
| 771 | |
| 772 | vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline); |
| 773 | |
| 774 | VkBuffer *vertexBufs = {&vertexBuffers[0]}; |
| 775 | VkDeviceSize offsets[] = {0}; |
| 776 | std::cout << vertexBuffers.size(); |
| 777 | vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBufs, offsets); |
| 778 | |
| 779 | vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, |
| 780 | &descriptorSet, 0, nullptr); |
| 781 | |
| 782 | //for(auto &vertices : model_vertices){ |
| 783 | vkCmdDraw(commandBuffers[i], static_cast<uint32_t>(model_vertices[0].size()), 1, 0, 0); |
| 784 | //} |
| 785 | |
| 786 | vkCmdEndRenderPass(commandBuffers[i]); |
| 787 | |
| 788 | if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) { |
| 789 | throw std::runtime_error("failed to record command buffer!"); |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | void vkRenderer::createSemaphores() { |
nothing calls this directly
no outgoing calls
no test coverage detected