13 #include <GLFW/glfw3.h> 21 VkApplicationInfo appInfo = {};
22 appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
23 appInfo.pApplicationName =
"SimpleGL Application (Vulkan backend)";
24 appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
25 appInfo.pEngineName =
"SimpleGL";
26 appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
27 appInfo.apiVersion = VK_API_VERSION_1_0;
30 vector<const char*> requiredLayers;
32 requiredLayers.push_back(
"VK_LAYER_LUNARG_standard_validation");
36 uint32_t glfwExtensionCount = 0;
37 const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
40 vector<const char*> requiredExtensions(glfwExtensions, glfwExtensions + glfwExtensionCount);
42 requiredExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
46 VkInstanceCreateInfo createInfo = {};
47 createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
48 createInfo.pApplicationInfo = &appInfo;
49 createInfo.enabledLayerCount = requiredLayers.size();
50 createInfo.ppEnabledLayerNames = requiredLayers.data();
51 createInfo.enabledExtensionCount = requiredExtensions.size();
52 createInfo.ppEnabledExtensionNames = requiredExtensions.data();
55 if (vkCreateInstance(&createInfo,
nullptr, &handle) != VK_SUCCESS) {
56 throw runtime_error(
"Could not create Vulkan instance!");
60 Instance::~Instance(
void) {
62 vkDestroyInstance(handle,
nullptr);
65 VkInstance Instance::getHandle() {
69 PFN_vkVoidFunction Instance::getProcAddr(std::string name) {
70 return vkGetInstanceProcAddr(handle, name.c_str());
73 std::vector<VkPhysicalDevice> Instance::enumeratePhysicalDevices() {
75 uint32_t physicalDeviceCount = 0;
76 vkEnumeratePhysicalDevices(handle, &physicalDeviceCount,
nullptr);
77 if (physicalDeviceCount == 0) {
78 throw runtime_error(
"Failed to find a GPU with Vulkan support!");
82 vector<VkPhysicalDevice> physicalDevices(physicalDeviceCount);
83 vkEnumeratePhysicalDevices(handle, &physicalDeviceCount, physicalDevices.data());
85 return physicalDevices;
Generic namespace for the SimpleGL framework.
const bool debugMode
Tells if the library is compiled in debug mode.