Add Vulkan logical device creation
This commit is contained in:
parent
46181a9e4d
commit
44f91d99ea
2 changed files with 34 additions and 2 deletions
31
renderer.cpp
31
renderer.cpp
|
@ -1,12 +1,39 @@
|
|||
#include "renderer.h"
|
||||
|
||||
Renderer::Renderer() {
|
||||
createInstance();
|
||||
createLogicalDevice();
|
||||
}
|
||||
|
||||
Renderer::~Renderer() {
|
||||
vkDestroyInstance(instance_, nullptr);
|
||||
}
|
||||
|
||||
void Renderer::createInstance() {
|
||||
VkInstanceCreateInfo instanceCreateInfo = {};
|
||||
instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
|
||||
vkCreateInstance(&instanceCreateInfo, nullptr, &instance_);
|
||||
}
|
||||
|
||||
Renderer::~Renderer() {
|
||||
vkDestroyInstance(instance_, nullptr);
|
||||
void Renderer::createLogicalDevice() {
|
||||
uint32_t physicalDeviceCount = 0;
|
||||
vkEnumeratePhysicalDevices(instance_, &physicalDeviceCount, nullptr);
|
||||
|
||||
VkPhysicalDevice* physicalDevices = new VkPhysicalDevice[physicalDeviceCount];
|
||||
vkEnumeratePhysicalDevices(instance_, &physicalDeviceCount, physicalDevices);
|
||||
|
||||
VkPhysicalDevice physicalDevice = nullptr;
|
||||
|
||||
for(uint32_t i = 0; i < physicalDeviceCount; i++) {
|
||||
VkPhysicalDeviceProperties properties = {};
|
||||
vkGetPhysicalDeviceProperties(physicalDevices[i], &properties);
|
||||
|
||||
physicalDevice = physicalDevices[i];
|
||||
}
|
||||
|
||||
VkDeviceCreateInfo deviceCreateInfo = {};
|
||||
deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||
|
||||
vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &device_);
|
||||
}
|
||||
|
|
|
@ -8,5 +8,10 @@ public:
|
|||
~Renderer();
|
||||
|
||||
private:
|
||||
void createInstance();
|
||||
void createLogicalDevice();
|
||||
|
||||
VkInstance instance_ = nullptr;
|
||||
|
||||
VkDevice device_ = nullptr;
|
||||
};
|
||||
|
|
Reference in a new issue