Changeset f94eea9 in opengl-game


Ignore:
Timestamp:
Sep 27, 2019, 7:20:55 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
6fc24c7
Parents:
054d9ed
Message:

In vulkangame, add code to create image views

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r054d9ed rf94eea9  
    101101   createLogicalDevice(validationLayers, deviceExtensions);
    102102   createSwapChain();
     103   createImageViews();
    103104}
    104105
     
    175176   gui->shutdown();
    176177   delete gui;
    177 }
    178 
    179 void VulkanGame::cleanupSwapChain() {
    180    vkDestroySwapchainKHR(device, swapChain, nullptr);
    181178}
    182179
     
    389386      createInfo.queueFamilyIndexCount = 2;
    390387      createInfo.pQueueFamilyIndices = queueFamilyIndices;
    391    }
    392    else {
     388   } else {
    393389      createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
    394390      createInfo.queueFamilyIndexCount = 0;
     
    413409   swapChainExtent = extent;
    414410}
     411
     412void 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
     421void 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  
    3737      VkFormat swapChainImageFormat;
    3838      VkExtent2D swapChainExtent;
     39      vector<VkImageView> swapChainImageViews;
    3940
    4041      bool initWindow(int width, int height, unsigned char guiFlags);
     
    5556         const vector<const char*>& deviceExtensions);
    5657      void createSwapChain();
     58      void createImageViews();
     59
    5760      void cleanupSwapChain();
    5861
  • vulkan-ref.cpp

    r054d9ed rf94eea9  
    173173      VkFormat swapChainImageFormat;
    174174      VkExtent2D swapChainExtent;
     175      vector<VkImageView> swapChainImageViews;
    175176/*** END OF REFACTORED CODE ***/
    176       vector<VkImageView> swapChainImageViews;
    177177      vector<VkFramebuffer> swapChainFramebuffers;
    178178
     
    317317         pickPhysicalDevice();
    318318         createLogicalDevice();
    319 /*** END OF REFACTORED CODE ***/
    320319         createSwapChain();
    321320         createImageViews();
     321/*** END OF REFACTORED CODE ***/
    322322         createRenderPass();
    323323
     
    685685         return details;
    686686      }
    687 /*** END OF REFACTORED CODE ***/
    688687
    689688      VkSurfaceFormatKHR chooseSwapSurfaceFormat(const vector<VkSurfaceFormatKHR>& availableFormats) {
     
    735734         }
    736735      }
     736/*** END OF REFACTORED CODE ***/
    737737
    738738      void createRenderPass() {
     
    13301330      }
    13311331
     1332/*** START OF REFACTORED CODE ***/
    13321333      VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags) {
    13331334         VkImageViewCreateInfo viewInfo = {};
     
    13551356         return imageView;
    13561357      }
     1358/*** END OF REFACTORED CODE ***/
    13571359
    13581360      void createTextureSampler() {
     
    17081710         vkDeviceWaitIdle(device);
    17091711      }
     1712
     1713      void drawFrame() {
    17101714/*** END OF REFACTORED CODE ***/
    1711 
    1712       void drawFrame() {
    17131715         vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, numeric_limits<uint64_t>::max());
    17141716
     
    17721774         currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
    17731775         currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
     1776/*** START OF REFACTORED CODE ***/
    17741777      }
    17751778
    17761779      void drawUI() {
     1780/*** END OF REFACTORED CODE ***/
    17771781         // TODO: Since I currently don't use any other render targets,
    17781782         // I may as well set this once before the render loop
     
    18011805
    18021806         populateImageFromSDLTexture(uiOverlay, sdlOverlayImage);
    1803       }
     1807/*** START OF REFACTORED CODE ***/
     1808      }
     1809/*** END OF REFACTORED CODE ***/
    18041810
    18051811      void updateUniformBuffer(uint32_t currentImage) {
     
    19441950         vkDestroyRenderPass(device, renderPass, nullptr);
    19451951
     1952/*** START OF REFACTORED CODE ***/
    19461953         for (auto imageView : swapChainImageViews) {
    19471954            vkDestroyImageView(device, imageView, nullptr);
    19481955         }
    19491956
    1950 /*** START OF REFACTORED CODE ***/
    19511957         vkDestroySwapchainKHR(device, swapChain, nullptr);
    19521958/*** END OF REFACTORED CODE ***/
  • vulkan-utils.cpp

    r054d9ed rf94eea9  
    166166   }
    167167}
     168
     169VkImageView 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  
    4343      static VkPresentModeKHR chooseSwapPresentMode(const vector<VkPresentModeKHR>& availablePresentModes);
    4444      static VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, int width, int height);
     45      static VkImageView createImageView(VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags);
    4546};
    4647
Note: See TracChangeset for help on using the changeset viewer.