Lugdunum  0.1.0
Instance.cpp
Go to the documentation of this file.
2 
3 namespace lug {
4 namespace Graphics {
5 namespace Vulkan {
6 namespace API {
7 namespace Builder {
8 
9 bool Instance::build(API::Instance& instance, VkResult* returnResult) {
10  // Create the application information for vkCreateInstance
11  const VkApplicationInfo applicationInfo {
12  /* applicationInfo.sType */ VK_STRUCTURE_TYPE_APPLICATION_INFO,
13  /* applicationInfo.pNext */ nullptr,
14  /* applicationInfo.pApplicationName */ _appInfo.appName.data(),
15  /* applicationInfo.applicationVersion */ static_cast<uint32_t>(_appInfo.appVersion),
16  /* applicationInfo.pEngineName */ _appInfo.engineName.data(),
17  /* applicationInfo.engineVersion */ static_cast<uint32_t>(_appInfo.engineVersion),
18  /* applicationInfo.apiVersion */ static_cast<uint32_t>(_appInfo.apiVersion),
19  };
20 
21  // Create the instance creation information for vkCreateInstance
22  const VkInstanceCreateInfo createInfo{
23  /* createInfo.sType */ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
24  /* createInfo.pNext */ nullptr,
25  /* createInfo.flags */ 0,
26  /* createInfo.pApplicationInfo */ &applicationInfo,
27  /* createInfo.enabledLayerCount */ static_cast<uint32_t>(_layers.size()),
28  /* createInfo.ppEnabledLayerNames */ _layers.data(),
29  /* createInfo.enabledExtensionCount */ static_cast<uint32_t>(_extensions.size()),
30  /* createInfo.ppEnabledExtensionNames */ _extensions.data()
31  };
32 
33  // Create the instance
34  VkInstance vkInstance{VK_NULL_HANDLE};
35  VkResult result = vkCreateInstance(&createInfo, nullptr, &vkInstance);
36 
37  if (returnResult) {
38  *returnResult = result;
39  }
40 
41  if (result != VK_SUCCESS) {
42  return false;
43  }
44 
45  instance = API::Instance(vkInstance);
46 
47  return true;
48 }
49 
50 std::unique_ptr<API::Instance> Instance::build(VkResult* returnResult) {
51  std::unique_ptr<API::Instance> instance = std::make_unique<API::Instance>();
52  return build(*instance, returnResult) ? std::move(instance) : nullptr;
53 }
54 
55 } // Builder
56 } // API
57 } // Vulkan
58 } // Graphics
59 } // lug
std::vector< const char * > _extensions
Definition: Instance.hpp:55
bool build(API::Instance &instance, VkResult *returnResult=nullptr)
Definition: Instance.cpp:9
std::vector< const char * > _layers
Definition: Instance.hpp:54