#include #include #include // callback function for validation layers static VKAPI_ATTR VkBool32 VKAPI_CALL VulkanReportFunc( VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) { printf("VULKAN VALIDATION: [%s] %s\n", layerPrefix, msg); return VK_FALSE; } int main(int argc, char *argv[]) { // This needs to be called first to initialize SDL glfwInit(); // create a default window and initialize all vulkan // objects. auto window = new vkw::VKWVulkanWindow(); auto glfw_window = new vkw::GLFWVulkanWindowAdapter(); // 1. create the window and set the adapater glfw_window->createWindow("Title", 1024,768); window->setWindowAdapater(glfw_window); // 2. Create the Instance vkw::VKWVulkanWindow::InstanceInitilizationInfo2 instanceInfo; instanceInfo.debugCallback = &VulkanReportFunc; instanceInfo.vulkanVersion = VK_MAKE_VERSION(1, 2, 0); instanceInfo.enabledExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); window->createVulkanInstance(instanceInfo); // 3. Create the surface vkw::VKWVulkanWindow::SurfaceInitilizationInfo2 surfaceInfo; surfaceInfo.depthFormat = VkFormat::VK_FORMAT_D32_SFLOAT_S8_UINT; surfaceInfo.presentMode = VK_PRESENT_MODE_FIFO_KHR; surfaceInfo.additionalImageCount = 1;// how many additional swapchain images should we create ( total = min_images + additionalImageCount window->createVulkanSurface(surfaceInfo); // 4. Create the device // and add additional extensions that we want to enable vkw::VKWVulkanWindow::DeviceInitilizationInfo2 deviceInfo; #if 0 // set to zero if you want to VKW to choose // a device for you deviceInfo.deviceID = 0; #else for(auto &d : window->getAvailablePhysicalDevices()) { if(d.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) { deviceInfo.deviceID = d.deviceID; break; } } #endif deviceInfo.deviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); deviceInfo.deviceExtensions.push_back(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME); // enable a new extended feature VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT dynamicVertexState = {}; dynamicVertexState.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT; dynamicVertexState.vertexInputDynamicState = true; deviceInfo.enabledFeatures12.pNext = &dynamicVertexState; window->createVulkanDevice(deviceInfo); bool running = true; while (!glfwWindowShouldClose(glfw_window->m_window) ) { glfwPollEvents(); bool resize = glfw_window->requiresResize(); glfw_window->clearRequireResize(); if( resize ) { // If the window has changed size. we need to rebuild the swapchain // and any other textures (depth texture) window->rebuildSwapchain(); } // Get the next available frame. // the Frame struct is simply a POD containing // all the information that you need to record a command buffer auto frame = window->acquireNextFrame(); frame.beginCommandBuffer(); frame.clearColor = {{1.f,0.f,0.f,0.f}}; frame.beginRenderPass( frame.commandBuffer ); // record to frame.commandbuffer frame.endRenderPass(frame.commandBuffer); frame.endCommandBuffer(); window->submitFrame(frame); // Present the frame after you have recorded // the command buffer; window->presentFrame(frame); window->waitForPresent(); } // delete the window to destroy all objects // that were created. window->destroy(); delete window; glfwTerminate(); return 0; } #include