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"
|
#include "renderer.h"
|
||||||
|
|
||||||
Renderer::Renderer() {
|
Renderer::Renderer() {
|
||||||
|
createInstance();
|
||||||
|
createLogicalDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer::~Renderer() {
|
||||||
|
vkDestroyInstance(instance_, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::createInstance() {
|
||||||
VkInstanceCreateInfo instanceCreateInfo = {};
|
VkInstanceCreateInfo instanceCreateInfo = {};
|
||||||
instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||||
|
|
||||||
vkCreateInstance(&instanceCreateInfo, nullptr, &instance_);
|
vkCreateInstance(&instanceCreateInfo, nullptr, &instance_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer() {
|
void Renderer::createLogicalDevice() {
|
||||||
vkDestroyInstance(instance_, nullptr);
|
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();
|
~Renderer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void createInstance();
|
||||||
|
void createLogicalDevice();
|
||||||
|
|
||||||
VkInstance instance_ = nullptr;
|
VkInstance instance_ = nullptr;
|
||||||
|
|
||||||
|
VkDevice device_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue