#include "window.h"
#include "backend.h"
#include "wrapper/instance.h"
#include "wrapper/device.h"
#include "wrapper/swapchain_creator.h"
#include "vulkanapi.h"
#include "zlog.h"
namespace vulkanapi {
	VulkanWindow::VulkanWindow(int frames, uint32_t width, uint32_t height, const char* title)
		:engineapi::Window(width, height , title)
		, mSurfaceKHR(nullptr)
		, mSwapchain(nullptr)
	{
		RenderVulkanAPI* api = RenderVulkanAPI::GetSingletonPtr();
		if (!api) {
			zlog::error("init RenderAPI error,Window is rely on RenderAPI!");
			return;
		}
		Backend& backend = api->backend;
		VkInstance instance = backend.GetInstance().Ptr();
		VkWin32SurfaceCreateInfoKHR surface_create_info = {
		  VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,  // VkStructureType                 sType
		  nullptr,                                          // const void                    * pNext
		  0,                                                // VkWin32SurfaceCreateFlagsKHR    flags
		  WindowClass::GetInstance(),                       // HINSTANCE                       hinstance
		  mPtr											    // HWND                            hwnd
		};
		vkCreateWin32SurfaceKHR(instance, &surface_create_info, nullptr, &mSurfaceKHR);
		SwapchainCreator swapchainCreator(backend.GetDevice(), frames, width, height, mSurfaceKHR);
		mSwapchain = new Swapchain(swapchainCreator);
	}
}