Changeset 7865c5b in opengl-game for sdl-game.cpp


Ignore:
Timestamp:
Mar 17, 2021, 12:50:49 AM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
aa7e5f0
Parents:
85b5fec
Message:

Rename surface to vulkanSurface and add an initializer list to the VulkanGame constructor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.cpp

    r85b5fec r7865c5b  
    4040}
    4141
    42 VulkanGame::VulkanGame() {
    43    // TODO: Double-check whether initialization should happen in the header, where the variables are declared, or here
    44    // Also, decide whether to use this-> for all instance variables, or only when necessary
    45 
    46    debugMessenger = VK_NULL_HANDLE;
    47 
    48    gui = nullptr;
    49    window = nullptr;
    50 
    51    swapChainPresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR;
    52    swapChainMinImageCount = 0;
    53    currentFrame = 0;
    54    imageIndex = 0;
    55    shouldRecreateSwapChain = false;
    56 
    57    score = 0;
    58    fps = 0.0f;
     42VulkanGame::VulkanGame()
     43                     : swapChainImageCount(0)
     44                     , swapChainMinImageCount(0)
     45                     , swapChainSurfaceFormat({})
     46                     , swapChainPresentMode(VK_PRESENT_MODE_MAX_ENUM_KHR)
     47                     , swapChainExtent{ 0, 0 }
     48                     , swapChain(VK_NULL_HANDLE)
     49                     , vulkanSurface(VK_NULL_HANDLE)
     50                     , sdlVersion({ 0, 0, 0 })
     51                     , instance(VK_NULL_HANDLE)
     52                     , physicalDevice(VK_NULL_HANDLE)
     53                     , device(VK_NULL_HANDLE)
     54                     , debugMessenger(VK_NULL_HANDLE)
     55                     , resourceCommandPool(VK_NULL_HANDLE)
     56                     , renderPass(VK_NULL_HANDLE)
     57                     , graphicsQueue(VK_NULL_HANDLE)
     58                     , presentQueue(VK_NULL_HANDLE)
     59                     , depthImage({})
     60                     , shouldRecreateSwapChain(false)
     61                     , frameCount(0)
     62                     , currentFrame()
     63                     , imageIndex(0)
     64                     , fpsStartTime(0.0f)
     65                     , curTime(0.0f)
     66                     , done(false)
     67                     , currentRenderScreenFn(nullptr)
     68                     , descriptorPool(VK_NULL_HANDLE)
     69                     , gui(nullptr)
     70                     , window(nullptr)
     71                     , score(0)
     72                     , fps(0.0f) {
    5973}
    6074
     
    104118
    105119   // TODO: Do this in one place and save it instead of redoing it every time I need a queue family index
    106    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     120   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    107121
    108122   // Setup Dear ImGui context
     
    376390
    377391   vkDestroyDevice(device, nullptr);
    378    vkDestroySurfaceKHR(instance, surface, nullptr);
     392   vkDestroySurfaceKHR(instance, vulkanSurface, nullptr);
    379393
    380394   if (ENABLE_VALIDATION_LAYERS) {
     
    461475
    462476void VulkanGame::createVulkanSurface() {
    463    if (gui->createVulkanSurface(instance, &surface) == RTWO_ERROR) {
     477   if (gui->createVulkanSurface(instance, &vulkanSurface) == RTWO_ERROR) {
    464478      throw runtime_error("failed to create window surface!");
    465479   }
     
    507521   }
    508522
    509    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     523   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    510524   bool extensionsSupported = VulkanUtils::checkDeviceExtensionSupport(physicalDevice, deviceExtensions);
    511525   bool swapChainAdequate = false;
    512526
    513527   if (extensionsSupported) {
    514       vector<VkSurfaceFormatKHR> formats = VulkanUtils::querySwapChainFormats(physicalDevice, surface);
    515       vector<VkPresentModeKHR> presentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, surface);
     528      vector<VkSurfaceFormatKHR> formats = VulkanUtils::querySwapChainFormats(physicalDevice, vulkanSurface);
     529      vector<VkPresentModeKHR> presentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, vulkanSurface);
    516530
    517531      swapChainAdequate = !formats.empty() && !presentModes.empty();
     
    526540void VulkanGame::createLogicalDevice(const vector<const char*>& validationLayers,
    527541   const vector<const char*>& deviceExtensions) {
    528    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     542   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    529543
    530544   if (!indices.isComplete()) {
     
    582596
    583597void VulkanGame::chooseSwapChainProperties() {
    584    vector<VkSurfaceFormatKHR> availableFormats = VulkanUtils::querySwapChainFormats(physicalDevice, surface);
    585    vector<VkPresentModeKHR> availablePresentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, surface);
     598   vector<VkSurfaceFormatKHR> availableFormats = VulkanUtils::querySwapChainFormats(physicalDevice, vulkanSurface);
     599   vector<VkPresentModeKHR> availablePresentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, vulkanSurface);
    586600
    587601   // Per Spec Format and View Format are expected to be the same unless VK_IMAGE_CREATE_MUTABLE_BIT was set at image creation
     
    605619   cout << "[vulkan] Selected PresentMode = " << swapChainPresentMode << endl;
    606620
    607    VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);
     621   VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface);
    608622
    609623   // If min image count was not specified, request different count of images dependent on selected present mode
     
    632646
    633647void VulkanGame::createSwapChain() {
    634    VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);
     648   VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface);
    635649
    636650   swapChainExtent = VulkanUtils::chooseSwapExtent(capabilities, gui->getWindowWidth(), gui->getWindowHeight());
     
    638652   VkSwapchainCreateInfoKHR createInfo = {};
    639653   createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
    640    createInfo.surface = surface;
     654   createInfo.surface = vulkanSurface;
    641655   createInfo.minImageCount = swapChainMinImageCount;
    642656   createInfo.imageFormat = swapChainSurfaceFormat.format;
     
    647661
    648662   // TODO: Maybe save this result so I don't have to recalculate it every time
    649    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     663   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    650664   uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() };
    651665
     
    762776
    763777void VulkanGame::createResourceCommandPool() {
    764    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     778   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    765779
    766780   VkCommandPoolCreateInfo poolInfo = {};
     
    777791   commandPools.resize(swapChainImageCount);
    778792
    779    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);
     793   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    780794
    781795   for (size_t i = 0; i < swapChainImageCount; i++) {
Note: See TracChangeset for help on using the changeset viewer.