| 969 | } |
| 970 | |
| 971 | void Demo::draw_build_cmd(const SubmissionResources &submission_resource, const SwapchainImageResources &swapchain_image_resource) { |
| 972 | const auto commandBuffer = submission_resource.cmd; |
| 973 | vk::ClearValue const clearValues[2] = {vk::ClearColorValue(std::array<float, 4>({{0.2f, 0.2f, 0.2f, 0.2f}})), |
| 974 | vk::ClearDepthStencilValue(1.0f, 0u)}; |
| 975 | auto result = commandBuffer.reset(); |
| 976 | VERIFY(result == vk::Result::eSuccess); |
| 977 | |
| 978 | result = commandBuffer.begin(vk::CommandBufferBeginInfo().setFlags(vk::CommandBufferUsageFlagBits::eSimultaneousUse)); |
| 979 | VERIFY(result == vk::Result::eSuccess); |
| 980 | |
| 981 | commandBuffer.beginRenderPass(vk::RenderPassBeginInfo() |
| 982 | .setRenderPass(render_pass) |
| 983 | .setFramebuffer(swapchain_image_resource.framebuffer) |
| 984 | .setRenderArea(vk::Rect2D(vk::Offset2D{}, vk::Extent2D(width, height))) |
| 985 | .setClearValueCount(2) |
| 986 | .setPClearValues(clearValues), |
| 987 | vk::SubpassContents::eInline); |
| 988 | |
| 989 | commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline); |
| 990 | commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline_layout, 0, submission_resource.descriptor_set, {}); |
| 991 | float viewport_dimension; |
| 992 | float viewport_x = 0.0f; |
| 993 | float viewport_y = 0.0f; |
| 994 | if (width < height) { |
| 995 | viewport_dimension = static_cast<float>(width); |
| 996 | viewport_y = (height - width) / 2.0f; |
| 997 | } else { |
| 998 | viewport_dimension = static_cast<float>(height); |
| 999 | viewport_x = (width - height) / 2.0f; |
| 1000 | } |
| 1001 | |
| 1002 | commandBuffer.setViewport(0, vk::Viewport() |
| 1003 | .setX(viewport_x) |
| 1004 | .setY(viewport_y) |
| 1005 | .setWidth(viewport_dimension) |
| 1006 | .setHeight(viewport_dimension) |
| 1007 | .setMinDepth(0.0f) |
| 1008 | .setMaxDepth(1.0f)); |
| 1009 | |
| 1010 | commandBuffer.setScissor(0, vk::Rect2D(vk::Offset2D{}, vk::Extent2D(width, height))); |
| 1011 | commandBuffer.draw(12 * 3, 1, 0, 0); |
| 1012 | // Note that ending the renderpass changes the image's layout from |
| 1013 | // COLOR_ATTACHMENT_OPTIMAL to PRESENT_SRC_KHR |
| 1014 | commandBuffer.endRenderPass(); |
| 1015 | |
| 1016 | if (separate_present_queue) { |
| 1017 | // We have to transfer ownership from the graphics queue family to |
| 1018 | // the |
| 1019 | // present queue family to be able to present. Note that we don't |
| 1020 | // have |
| 1021 | // to transfer from present queue family back to graphics queue |
| 1022 | // family at |
| 1023 | // the start of the next frame because we don't care about the |
| 1024 | // image's |
| 1025 | // contents at that point. |
| 1026 | commandBuffer.pipelineBarrier( |
| 1027 | vk::PipelineStageFlagBits::eBottomOfPipe, vk::PipelineStageFlagBits::eBottomOfPipe, vk::DependencyFlagBits(), {}, {}, |
| 1028 | vk::ImageMemoryBarrier() |