Newer
Older
GameEngine / src / Vulkan / VulkanSwapChain.cpp
@John Ryland John Ryland on 22 Aug 1 KB save more of the WIP
/*
	VulkanFramework
	by John Ryland
	Copyright (c) 2023
*/

////////////////////////////////////////////////////////////////////////////////////
//	Vulkan SwapChain

#include "VulkanSwapChain.h"
#include <memory>

namespace Vulkan {

SwapChain::SwapChain(Device& device, Surface& surface)
    : m_owner(device)
    , m_surface(surface)
{
    Create();
}

// virtual
SwapChain::~SwapChain()
{
    Destroy();
}

// virtual
void SwapChain::Create()
{
    m_presentMode = SelectPresentMode();
}

// virtual
void SwapChain::Destroy()
{
}

// virtual
VkPresentModeKHR SwapChain::SelectPresentMode()
{
    return m_surface.m_presentMode;
}

} // Vulkan namespace


/*

struct SwapChainSupportDetails
{
    VkSurfaceCapabilitiesKHR        capabilities;
    std::vector<VkSurfaceFormatKHR> formats;
    std::vector<VkPresentModeKHR>   presentModes;
};


void SwapChain::Prepare(uint32_t width, uint32_t height)
{
    //ImGui_ImplVulkan_SetMinImageCount(m_MinImageCount);
    //ImGui_ImplVulkanH_CreateOrResizeWindow(m_Instance, m_PhysicalDevice, m_Device, &m_MainWindowData, m_QueueFamily, m_Allocator, width, height, m_MinImageCount);
}


void SwapChain::FramePresent()
{
    if (m_SwapChainRebuild)
        return;
    VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
    VkPresentInfoKHR info = {};
    info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
    info.waitSemaphoreCount = 1;
    info.pWaitSemaphores = &render_complete_semaphore;
    info.swapchainCount = 1;
    info.pSwapchains = &wd->Swapchain;
    info.pImageIndices = &wd->FrameIndex;
    VkResult err = vkQueuePresentKHR(m_Queue, &info);
    if (err == VK_ERROR_OUT_OF_DATE_KHR || err == VK_SUBOPTIMAL_KHR)
    {
        m_SwapChainRebuild = true;
        return;
    }
    check_vk_result(err);
    wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->ImageCount; // Now we can use the next set of semaphores
}

*/