Changeset f94eea9 in opengl-game
- Timestamp:
- Sep 27, 2019, 7:20:55 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 6fc24c7
- Parents:
- 054d9ed
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r054d9ed rf94eea9 101 101 createLogicalDevice(validationLayers, deviceExtensions); 102 102 createSwapChain(); 103 createImageViews(); 103 104 } 104 105 … … 175 176 gui->shutdown(); 176 177 delete gui; 177 }178 179 void VulkanGame::cleanupSwapChain() {180 vkDestroySwapchainKHR(device, swapChain, nullptr);181 178 } 182 179 … … 389 386 createInfo.queueFamilyIndexCount = 2; 390 387 createInfo.pQueueFamilyIndices = queueFamilyIndices; 391 } 392 else { 388 } else { 393 389 createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; 394 390 createInfo.queueFamilyIndexCount = 0; … … 413 409 swapChainExtent = extent; 414 410 } 411 412 void VulkanGame::createImageViews() { 413 swapChainImageViews.resize(swapChainImages.size()); 414 415 for (size_t i = 0; i < swapChainImages.size(); i++) { 416 swapChainImageViews[i] = VulkanUtils::createImageView(device, swapChainImages[i], swapChainImageFormat, 417 VK_IMAGE_ASPECT_COLOR_BIT); 418 } 419 } 420 421 void VulkanGame::cleanupSwapChain() { 422 for (auto imageView : swapChainImageViews) { 423 vkDestroyImageView(device, imageView, nullptr); 424 } 425 426 vkDestroySwapchainKHR(device, swapChain, nullptr); 427 } -
vulkan-game.hpp
r054d9ed rf94eea9 37 37 VkFormat swapChainImageFormat; 38 38 VkExtent2D swapChainExtent; 39 vector<VkImageView> swapChainImageViews; 39 40 40 41 bool initWindow(int width, int height, unsigned char guiFlags); … … 55 56 const vector<const char*>& deviceExtensions); 56 57 void createSwapChain(); 58 void createImageViews(); 59 57 60 void cleanupSwapChain(); 58 61 -
vulkan-ref.cpp
r054d9ed rf94eea9 173 173 VkFormat swapChainImageFormat; 174 174 VkExtent2D swapChainExtent; 175 vector<VkImageView> swapChainImageViews; 175 176 /*** END OF REFACTORED CODE ***/ 176 vector<VkImageView> swapChainImageViews;177 177 vector<VkFramebuffer> swapChainFramebuffers; 178 178 … … 317 317 pickPhysicalDevice(); 318 318 createLogicalDevice(); 319 /*** END OF REFACTORED CODE ***/320 319 createSwapChain(); 321 320 createImageViews(); 321 /*** END OF REFACTORED CODE ***/ 322 322 createRenderPass(); 323 323 … … 685 685 return details; 686 686 } 687 /*** END OF REFACTORED CODE ***/688 687 689 688 VkSurfaceFormatKHR chooseSwapSurfaceFormat(const vector<VkSurfaceFormatKHR>& availableFormats) { … … 735 734 } 736 735 } 736 /*** END OF REFACTORED CODE ***/ 737 737 738 738 void createRenderPass() { … … 1330 1330 } 1331 1331 1332 /*** START OF REFACTORED CODE ***/ 1332 1333 VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags) { 1333 1334 VkImageViewCreateInfo viewInfo = {}; … … 1355 1356 return imageView; 1356 1357 } 1358 /*** END OF REFACTORED CODE ***/ 1357 1359 1358 1360 void createTextureSampler() { … … 1708 1710 vkDeviceWaitIdle(device); 1709 1711 } 1712 1713 void drawFrame() { 1710 1714 /*** END OF REFACTORED CODE ***/ 1711 1712 void drawFrame() {1713 1715 vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, numeric_limits<uint64_t>::max()); 1714 1716 … … 1772 1774 currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT; 1773 1775 currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT; 1776 /*** START OF REFACTORED CODE ***/ 1774 1777 } 1775 1778 1776 1779 void drawUI() { 1780 /*** END OF REFACTORED CODE ***/ 1777 1781 // TODO: Since I currently don't use any other render targets, 1778 1782 // I may as well set this once before the render loop … … 1801 1805 1802 1806 populateImageFromSDLTexture(uiOverlay, sdlOverlayImage); 1803 } 1807 /*** START OF REFACTORED CODE ***/ 1808 } 1809 /*** END OF REFACTORED CODE ***/ 1804 1810 1805 1811 void updateUniformBuffer(uint32_t currentImage) { … … 1944 1950 vkDestroyRenderPass(device, renderPass, nullptr); 1945 1951 1952 /*** START OF REFACTORED CODE ***/ 1946 1953 for (auto imageView : swapChainImageViews) { 1947 1954 vkDestroyImageView(device, imageView, nullptr); 1948 1955 } 1949 1956 1950 /*** START OF REFACTORED CODE ***/1951 1957 vkDestroySwapchainKHR(device, swapChain, nullptr); 1952 1958 /*** END OF REFACTORED CODE ***/ -
vulkan-utils.cpp
r054d9ed rf94eea9 166 166 } 167 167 } 168 169 VkImageView VulkanUtils::createImageView(VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags) { 170 VkImageViewCreateInfo viewInfo = {}; 171 viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; 172 viewInfo.image = image; 173 viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; 174 viewInfo.format = format; 175 176 viewInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; 177 viewInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; 178 viewInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; 179 viewInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; 180 181 viewInfo.subresourceRange.aspectMask = aspectFlags; 182 viewInfo.subresourceRange.baseMipLevel = 0; 183 viewInfo.subresourceRange.levelCount = 1; 184 viewInfo.subresourceRange.baseArrayLayer = 0; 185 viewInfo.subresourceRange.layerCount = 1; 186 187 VkImageView imageView; 188 if (vkCreateImageView(device, &viewInfo, nullptr, &imageView) != VK_SUCCESS) { 189 throw runtime_error("failed to create image view!"); 190 } 191 192 return imageView; 193 } -
vulkan-utils.hpp
r054d9ed rf94eea9 43 43 static VkPresentModeKHR chooseSwapPresentMode(const vector<VkPresentModeKHR>& availablePresentModes); 44 44 static VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, int width, int height); 45 static VkImageView createImageView(VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags); 45 46 }; 46 47
Note:
See TracChangeset
for help on using the changeset viewer.