Added RAII vulkan instance destructor

This commit is contained in:
Warwick 2023-11-29 10:54:15 +00:00
parent 66af7fc1e8
commit c3b623384f
3 changed files with 20 additions and 5 deletions

View file

@ -15,6 +15,8 @@ private:
void createGraphicsPipeline(const std::string &vertFilepath, void createGraphicsPipeline(const std::string &vertFilepath,
const std::string &fragFilepath); const std::string &fragFilepath);
}; };
} // namespace yave } // namespace yave

View file

@ -1,8 +1,10 @@
#include "yave_vulkan_instance.hpp" #include "yave_vulkan_instance.hpp"
#include <vulkan/vulkan_core.h>
namespace yave { namespace yave {
YaveVulkanInstance::YaveVulkanInstance() { createInstance(); } YaveVulkanInstance::YaveVulkanInstance() { createInstance(); }
YaveVulkanInstance::~YaveVulkanInstance() { destroyInstance(); }
void YaveVulkanInstance::createInstance() { void YaveVulkanInstance::createInstance() {
VkApplicationInfo appInfo{}; VkApplicationInfo appInfo{};
@ -32,4 +34,8 @@ void YaveVulkanInstance::createInstance() {
} }
} }
void YaveVulkanInstance::destroyInstance() {
vkDestroyInstance(this->instance, nullptr);
}
} // namespace yave } // namespace yave

View file

@ -14,8 +14,15 @@ class YaveVulkanInstance {
void createInstance(); void createInstance();
public: void destroyInstance();
YaveVulkanInstance();
public:
// Delete Copy constructors
// This class should match one to one with vulkan instances
YaveVulkanInstance(const YaveVulkanInstance&) = delete;
YaveVulkanInstance &operator=(const YaveVulkanInstance &) = delete;
YaveVulkanInstance();
~YaveVulkanInstance();
}; };
} // namespace yave } // namespace yave