Set up the commands we need to issue to draw a frame
| 2245 | |
| 2246 | // Set up the commands we need to issue to draw a frame |
| 2247 | void setupDraw() |
| 2248 | { |
| 2249 | // Set up our clear colors |
| 2250 | std::array<VkClearValue, 2> clearColors{}; |
| 2251 | |
| 2252 | // Clear color buffer to opaque black |
| 2253 | clearColors[0] = VkClearValue(); |
| 2254 | clearColors[0].color.float32[0] = 0.0f; |
| 2255 | clearColors[0].color.float32[1] = 0.0f; |
| 2256 | clearColors[0].color.float32[2] = 0.0f; |
| 2257 | clearColors[0].color.float32[3] = 0.0f; |
| 2258 | |
| 2259 | // Clear depth to 1.0f |
| 2260 | clearColors[1] = VkClearValue(); |
| 2261 | clearColors[1].depthStencil.depth = 1.0f; |
| 2262 | clearColors[1].depthStencil.stencil = 0; |
| 2263 | |
| 2264 | VkRenderPassBeginInfo renderPassBeginInfo = VkRenderPassBeginInfo(); |
| 2265 | renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 2266 | renderPassBeginInfo.renderPass = renderPass; |
| 2267 | renderPassBeginInfo.renderArea.offset.x = 0; |
| 2268 | renderPassBeginInfo.renderArea.offset.y = 0; |
| 2269 | renderPassBeginInfo.renderArea.extent = swapchainExtent; |
| 2270 | renderPassBeginInfo.clearValueCount = static_cast<std::uint32_t>(clearColors.size()); |
| 2271 | renderPassBeginInfo.pClearValues = clearColors.data(); |
| 2272 | |
| 2273 | // Simultaneous use: this command buffer can be resubmitted to a queue before a previous submission is completed |
| 2274 | VkCommandBufferBeginInfo commandBufferBeginInfo = VkCommandBufferBeginInfo(); |
| 2275 | commandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 2276 | commandBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; |
| 2277 | |
| 2278 | // Set up the command buffers for each frame in flight |
| 2279 | for (std::size_t i = 0; i < commandBuffers.size(); ++i) |
| 2280 | { |
| 2281 | // Begin the command buffer |
| 2282 | if (vkBeginCommandBuffer(commandBuffers[i], &commandBufferBeginInfo) != VK_SUCCESS) |
| 2283 | { |
| 2284 | vulkanAvailable = false; |
| 2285 | return; |
| 2286 | } |
| 2287 | |
| 2288 | // Begin the renderpass |
| 2289 | renderPassBeginInfo.framebuffer = swapchainFramebuffers[i]; |
| 2290 | |
| 2291 | vkCmdBeginRenderPass(commandBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); |
| 2292 | |
| 2293 | // Bind our graphics pipeline |
| 2294 | vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline); |
| 2295 | |
| 2296 | // Bind our vertex buffer |
| 2297 | const VkDeviceSize offset = 0; |
| 2298 | |
| 2299 | vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, &vertexBuffer, &offset); |
| 2300 | |
| 2301 | // Bind our index buffer |
| 2302 | vkCmdBindIndexBuffer(commandBuffers[i], indexBuffer, 0, VK_INDEX_TYPE_UINT16); |
| 2303 | |
| 2304 | // Bind our descriptor sets |
nothing calls this directly
no test coverage detected