Changeset 6fc24c7 in opengl-game for vulkan-game.cpp
- Timestamp:
- Sep 27, 2019, 7:58:33 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 0e09340
- Parents:
- f94eea9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
rf94eea9 r6fc24c7 1 1 #include "vulkan-game.hpp" 2 2 3 #include <array> 3 4 #include <iostream> 4 5 #include <set> … … 102 103 createSwapChain(); 103 104 createImageViews(); 105 createRenderPass(); 104 106 } 105 107 … … 419 421 } 420 422 423 void VulkanGame::createRenderPass() { 424 VkAttachmentDescription colorAttachment = {}; 425 colorAttachment.format = swapChainImageFormat; 426 colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT; 427 colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; 428 colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; 429 colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; 430 colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; 431 colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; 432 colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; 433 434 VkAttachmentReference colorAttachmentRef = {}; 435 colorAttachmentRef.attachment = 0; 436 colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 437 438 VkAttachmentDescription depthAttachment = {}; 439 depthAttachment.format = findDepthFormat(); 440 depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT; 441 depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; 442 depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; 443 depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; 444 depthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; 445 depthAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; 446 depthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; 447 448 VkAttachmentReference depthAttachmentRef = {}; 449 depthAttachmentRef.attachment = 1; 450 depthAttachmentRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; 451 452 VkSubpassDescription subpass = {}; 453 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; 454 subpass.colorAttachmentCount = 1; 455 subpass.pColorAttachments = &colorAttachmentRef; 456 subpass.pDepthStencilAttachment = &depthAttachmentRef; 457 458 VkSubpassDependency dependency = {}; 459 dependency.srcSubpass = VK_SUBPASS_EXTERNAL; 460 dependency.dstSubpass = 0; 461 dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; 462 dependency.srcAccessMask = 0; 463 dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; 464 dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; 465 466 array<VkAttachmentDescription, 2> attachments = { colorAttachment, depthAttachment }; 467 VkRenderPassCreateInfo renderPassInfo = {}; 468 renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; 469 renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size()); 470 renderPassInfo.pAttachments = attachments.data(); 471 renderPassInfo.subpassCount = 1; 472 renderPassInfo.pSubpasses = &subpass; 473 renderPassInfo.dependencyCount = 1; 474 renderPassInfo.pDependencies = &dependency; 475 476 if (vkCreateRenderPass(device, &renderPassInfo, nullptr, &renderPass) != VK_SUCCESS) { 477 throw runtime_error("failed to create render pass!"); 478 } 479 } 480 481 VkFormat VulkanGame::findDepthFormat() { 482 return VulkanUtils::findSupportedFormat( 483 physicalDevice, 484 { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT }, 485 VK_IMAGE_TILING_OPTIMAL, 486 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT 487 ); 488 } 489 421 490 void VulkanGame::cleanupSwapChain() { 491 vkDestroyRenderPass(device, renderPass, nullptr); 492 422 493 for (auto imageView : swapChainImageViews) { 423 494 vkDestroyImageView(device, imageView, nullptr);
Note:
See TracChangeset
for help on using the changeset viewer.