From 93bdd869174884d68cbdb4c78ea886edf8efa65c Mon Sep 17 00:00:00 2001 From: saschawillems Date: Sat, 7 Jan 2017 21:52:59 +0100 Subject: [PATCH] Vulkan resource deallocation function for texture class --- base/vulkanTextureLoader.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/base/vulkanTextureLoader.hpp b/base/vulkanTextureLoader.hpp index e1daa4b1..78424b70 100644 --- a/base/vulkanTextureLoader.hpp +++ b/base/vulkanTextureLoader.hpp @@ -24,6 +24,7 @@ namespace vkTools */ struct VulkanTexture { + VkDevice device; VkSampler sampler; VkImage image; VkImageLayout imageLayout; @@ -41,6 +42,18 @@ namespace vkTools descriptor.imageView = view; descriptor.imageLayout = imageLayout; } + + /** @brief Release all Vulkan resources held by this texture */ + void destroy() + { + vkDestroyImageView(device, view, nullptr); + vkDestroyImage(device, image, nullptr); + if (sampler) + { + vkDestroySampler(device, sampler, nullptr); + } + vkFreeMemory(device, deviceMemory, nullptr); + } }; /** @@ -134,6 +147,7 @@ namespace vkTools #endif assert(!tex2D.empty()); + texture->device = vulkanDevice->logicalDevice; texture->width = static_cast(tex2D[0].dimensions().x); texture->height = static_cast(tex2D[0].dimensions().y); texture->mipLevels = static_cast(tex2D.levels()); @@ -464,6 +478,7 @@ namespace vkTools #endif assert(!texCube.empty()); + texture->device = vulkanDevice->logicalDevice; texture->width = static_cast(texCube.dimensions().x); texture->height = static_cast(texCube.dimensions().y); texture->mipLevels = static_cast(texCube.levels()); @@ -687,6 +702,7 @@ namespace vkTools assert(!tex2DArray.empty()); + texture->device = vulkanDevice->logicalDevice; texture->width = static_cast(tex2DArray.dimensions().x); texture->height = static_cast(tex2DArray.dimensions().y); texture->layerCount = static_cast(tex2DArray.layers()); @@ -892,6 +908,7 @@ namespace vkTools { assert(buffer); + texture->device = vulkanDevice->logicalDevice; texture->width = width; texture->height = height; texture->mipLevels = 1;