Changeset c324d6a in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
Jan 2, 2021, 4:07:45 PM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl, master
Children:
3b7d497, ca188cc
Parents:
a2f62d7
Message:

Make some minor updates to VulkanGame

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    ra2f62d7 rc324d6a  
    55#include <numeric>
    66#include <set>
    7 
    8 #include "consts.hpp"
     7#include <stdexcept>
     8
    99#include "logger.hpp"
    1010
     
    1616using namespace std;
    1717
    18 // TODO: Update all occurances of instance variables to use this->
     18// TODO: Update all occurances of instance variables to use this-> (Actually, not sure if I really want to do this)
     19
     20/* TODO: Try doing the following tasks based on the Vulkan implementation of IMGUI (Also maybe looks at Sascha Willems' code to see how he does these things)
     21 *
     22 * - When recreating the swapchain, pass the old one in and destroy the old one after the new one is created
     23 * - Recreate semaphores when recreating the swapchain
     24 *     - imgui uses one image acquired and one render complete sem  and once fence per frame\
     25 * - IMGUI creates one command pool per framebuffer
     26 */
    1927
    2028VulkanGame::VulkanGame(int maxFramesInFlight) : MAX_FRAMES_IN_FLIGHT(maxFramesInFlight) {
    2129   this->gui = nullptr;
    2230   this->window = nullptr;
     31
     32   this->debugMessenger = VK_NULL_HANDLE;
    2333
    2434   this->currentFrame = 0;
     
    8595
    8696   // TODO: Refactor the logger api to be more flexible,
    87    // esp. since gl_log() and gl_log_err() have issues printing anything besides stirngs
     97   // esp. since gl_log() and gl_log_err() have issues printing anything besides strings
    8898   restart_gl_log();
    8999   gl_log("starting SDL\n%s.%s.%s",
     
    93103
    94104   // TODO: Use open_Log() and related functions instead of gl_log ones
     105   // TODO: In addition, delete the gl_log functions
    95106   open_log();
    96107   get_log() << "starting SDL" << endl;
     
    807818   }
    808819
     820   // TODO: Should probably check the returned result
    809821   vkDeviceWaitIdle(device);
    810822}
     
    11311143}
    11321144
    1133 void VulkanGame::createVulkanInstance(const vector<const char*> &validationLayers) {
     1145void VulkanGame::createVulkanInstance(const vector<const char*>& validationLayers) {
    11341146   if (ENABLE_VALIDATION_LAYERS && !VulkanUtils::checkValidationLayerSupport(validationLayers)) {
    11351147      throw runtime_error("validation layers requested, but not available!");
     
    11811193
    11821194void VulkanGame::setupDebugMessenger() {
    1183    if (!ENABLE_VALIDATION_LAYERS) return;
     1195   if (!ENABLE_VALIDATION_LAYERS) {
     1196      return;
     1197   }
    11841198
    11851199   VkDebugUtilsMessengerCreateInfoEXT createInfo;
     
    12171231void VulkanGame::pickPhysicalDevice(const vector<const char*>& deviceExtensions) {
    12181232   uint32_t deviceCount = 0;
     1233   // TODO: Check VkResult
    12191234   vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
    12201235
     
    12241239
    12251240   vector<VkPhysicalDevice> devices(deviceCount);
     1241   // TODO: Check VkResult
    12261242   vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());
    12271243
     
    12621278}
    12631279
    1264 void VulkanGame::createLogicalDevice(
    1265       const vector<const char*> validationLayers, const vector<const char*>& deviceExtensions) {
     1280void VulkanGame::createLogicalDevice(const vector<const char*>& validationLayers,
     1281      const vector<const char*>& deviceExtensions) {
    12661282   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
    12671283
     
    12851301   VkDeviceCreateInfo createInfo = {};
    12861302   createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
     1303
    12871304   createInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfoList.size());
    12881305   createInfo.pQueueCreateInfos = queueCreateInfoList.data();
     
    13171334   VkExtent2D extent = VulkanUtils::chooseSwapExtent(swapChainSupport.capabilities, gui->getWindowWidth(), gui->getWindowHeight());
    13181335
    1319    uint32_t imageCount = swapChainSupport.capabilities.minImageCount + 1;
    1320    if (swapChainSupport.capabilities.maxImageCount > 0 && imageCount > swapChainSupport.capabilities.maxImageCount) {
    1321       imageCount = swapChainSupport.capabilities.maxImageCount;
     1336   swapChainImageCount = swapChainSupport.capabilities.minImageCount + 1;
     1337   if (swapChainSupport.capabilities.maxImageCount > 0 && swapChainImageCount > swapChainSupport.capabilities.maxImageCount) {
     1338      swapChainImageCount = swapChainSupport.capabilities.maxImageCount;
    13221339   }
    13231340
     
    13251342   createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
    13261343   createInfo.surface = surface;
    1327    createInfo.minImageCount = imageCount;
     1344   createInfo.minImageCount = swapChainImageCount;
    13281345   createInfo.imageFormat = surfaceFormat.format;
    13291346   createInfo.imageColorSpace = surfaceFormat.colorSpace;
     
    13551372   }
    13561373
    1357    vkGetSwapchainImagesKHR(device, swapChain, &imageCount, nullptr);
    1358    swapChainImages.resize(imageCount);
    1359    vkGetSwapchainImagesKHR(device, swapChain, &imageCount, swapChainImages.data());
     1374   vkGetSwapchainImagesKHR(device, swapChain, &swapChainImageCount, nullptr);
     1375   swapChainImages.resize(swapChainImageCount);
     1376   vkGetSwapchainImagesKHR(device, swapChain, &swapChainImageCount, swapChainImages.data());
    13601377
    13611378   swapChainImageFormat = surfaceFormat.format;
Note: See TracChangeset for help on using the changeset viewer.