-
Notifications
You must be signed in to change notification settings - Fork 0
/
Instance.cpp
57 lines (45 loc) · 2.2 KB
/
Instance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <vulkan/vulkan_core.h>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include "Instance.h"
#include "Utility.h"
#include "Debug.h"
#include <vulkan/vulkan_core.h>
namespace ShmulkInstance {
void createInstance(std::vector<const char*> validationLayers, VkInstance* instance) {
if (ShmulkDebug::enableValidationLayers() && !ShmulkDebug::checkValidationLayerSupport(validationLayers)) {
throw std::runtime_error("validation layers requested, but not available!");
}
VkApplicationInfo appInfo{};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Hello Triangle";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.pEngineName = "No Engine";
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.apiVersion = VK_API_VERSION_1_0;
VkInstanceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
auto extensions = ShmulkUtilities::getRequiredExtensions();
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
createInfo.ppEnabledExtensionNames = extensions.data();
VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo{};
if (ShmulkDebug::enableValidationLayers()) {
createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
createInfo.ppEnabledLayerNames = validationLayers.data();
ShmulkDebug::populateDebugMessengerCreateInfo(debugCreateInfo);
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
} else {
createInfo.enabledLayerCount = 0;
createInfo.pNext = nullptr;
}
if (vkCreateInstance(&createInfo, nullptr, instance) != VK_SUCCESS) {
throw std::runtime_error("failed to create instance!");
}
}
void createSurface(VkInstance* instance, GLFWwindow* window, VkSurfaceKHR* surface) {
if (glfwCreateWindowSurface(*instance, window, nullptr, surface) != VK_SUCCESS) {
throw std::runtime_error("failed to create window surface!");
}
}
}