Changeset 6fc24c7 in opengl-game
- Timestamp:
- Sep 27, 2019, 7:58:33 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 0e09340
- Parents:
- f94eea9
- Files:
-
- 5 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); -
vulkan-game.hpp
rf94eea9 r6fc24c7 38 38 VkExtent2D swapChainExtent; 39 39 vector<VkImageView> swapChainImageViews; 40 VkRenderPass renderPass; 40 41 41 42 bool initWindow(int width, int height, unsigned char guiFlags); … … 57 58 void createSwapChain(); 58 59 void createImageViews(); 60 void createRenderPass(); 61 VkFormat findDepthFormat(); 59 62 60 63 void cleanupSwapChain(); -
vulkan-ref.cpp
rf94eea9 r6fc24c7 177 177 vector<VkFramebuffer> swapChainFramebuffers; 178 178 179 /*** START OF REFACTORED CODE ***/ 179 180 VkRenderPass renderPass; 181 /*** END OF REFACTORED CODE ***/ 180 182 181 183 VkCommandPool commandPool; … … 319 321 createSwapChain(); 320 322 createImageViews(); 323 createRenderPass(); 321 324 /*** END OF REFACTORED CODE ***/ 322 createRenderPass();323 325 324 326 createCommandPool(); … … 734 736 } 735 737 } 736 /*** END OF REFACTORED CODE ***/737 738 738 739 void createRenderPass() { … … 793 794 } 794 795 } 796 /*** END OF REFACTORED CODE ***/ 795 797 796 798 void initGraphicsPipelineInfo(GraphicsPipelineInfo& info, … … 1080 1082 } 1081 1083 1084 /*** START OF REFACTORED CODE ***/ 1082 1085 VkFormat findDepthFormat() { 1083 1086 return findSupportedFormat( … … 1105 1108 throw runtime_error("failed to find supported format!"); 1106 1109 } 1110 /*** END OF REFACTORED CODE ***/ 1107 1111 1108 1112 bool hasStencilComponent(VkFormat format) { … … 1948 1952 cleanupPipeline(overlayPipeline); 1949 1953 1954 /*** START OF REFACTORED CODE ***/ 1950 1955 vkDestroyRenderPass(device, renderPass, nullptr); 1951 1956 1952 /*** START OF REFACTORED CODE ***/1953 1957 for (auto imageView : swapChainImageViews) { 1954 1958 vkDestroyImageView(device, imageView, nullptr); -
vulkan-utils.cpp
rf94eea9 r6fc24c7 192 192 return imageView; 193 193 } 194 195 VkFormat VulkanUtils::findSupportedFormat(VkPhysicalDevice physicalDevice, const vector<VkFormat>& candidates, 196 VkImageTiling tiling, VkFormatFeatureFlags features) { 197 for (VkFormat format : candidates) { 198 VkFormatProperties props; 199 vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &props); 200 201 if (tiling == VK_IMAGE_TILING_LINEAR && 202 (props.linearTilingFeatures & features) == features) { 203 return format; 204 } else if (tiling == VK_IMAGE_TILING_OPTIMAL && 205 (props.optimalTilingFeatures & features) == features) { 206 return format; 207 } 208 } 209 210 throw runtime_error("failed to find supported format!"); 211 } -
vulkan-utils.hpp
rf94eea9 r6fc24c7 44 44 static VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, int width, int height); 45 45 static VkImageView createImageView(VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags); 46 static VkFormat findSupportedFormat(VkPhysicalDevice physicalDevice, const vector<VkFormat>& candidates, 47 VkImageTiling tiling, VkFormatFeatureFlags features); 46 48 }; 47 49
Note:
See TracChangeset
for help on using the changeset viewer.