Added KRTexture::TextureHandle::destroy to eliminate duplicate code in KRTexture::destroyHandles and KRTexture::destroyNewHandles.
Now creating an image view for each KRTexture for full access.
This commit is contained in:
@@ -53,13 +53,25 @@ KRTexture::~KRTexture()
|
||||
releaseHandles();
|
||||
}
|
||||
|
||||
void KRTexture::TextureHandle::destroy(KRDeviceManager* deviceManager)
|
||||
{
|
||||
std::unique_ptr<KRDevice>& d = deviceManager->getDevice(device);
|
||||
// TODO - Validate that device has not been lost
|
||||
if (fullImageView != VK_NULL_HANDLE) {
|
||||
vkDestroyImageView(d->m_logicalDevice, fullImageView, nullptr);
|
||||
fullImageView = VK_NULL_HANDLE;
|
||||
}
|
||||
if (image != VK_NULL_HANDLE) {
|
||||
VmaAllocator allocator = d->getAllocator();
|
||||
vmaDestroyImage(allocator, image, allocation);
|
||||
}
|
||||
}
|
||||
|
||||
void KRTexture::destroyHandles()
|
||||
{
|
||||
KRDeviceManager* deviceManager = getContext().getDeviceManager();
|
||||
for (TextureHandle t : m_handles) {
|
||||
std::unique_ptr<KRDevice>& device = deviceManager->getDevice(t.device);
|
||||
VmaAllocator allocator = device->getAllocator();
|
||||
vmaDestroyImage(allocator, t.image, t.allocation);
|
||||
t.destroy(deviceManager);
|
||||
}
|
||||
m_handles.clear();
|
||||
m_textureMemUsed = 0;
|
||||
@@ -69,9 +81,7 @@ void KRTexture::destroyNewHandles()
|
||||
{
|
||||
KRDeviceManager* deviceManager = getContext().getDeviceManager();
|
||||
for (TextureHandle t : m_newHandles) {
|
||||
std::unique_ptr<KRDevice>& device = deviceManager->getDevice(t.device);
|
||||
VmaAllocator allocator = device->getAllocator();
|
||||
vmaDestroyImage(allocator, t.image, t.allocation);
|
||||
t.destroy(deviceManager);
|
||||
}
|
||||
m_newHandles.clear();
|
||||
m_newTextureMemUsed = 0;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
class KRDataBlock;
|
||||
class KRCamera;
|
||||
class KRDeviceManager;
|
||||
|
||||
class KRTexture : public KRResource {
|
||||
public:
|
||||
@@ -95,8 +96,11 @@ protected:
|
||||
|
||||
struct TextureHandle {
|
||||
VkImage image;
|
||||
VkImageView fullImageView;
|
||||
KrDeviceHandle device;
|
||||
VmaAllocation allocation;
|
||||
|
||||
void destroy(KRDeviceManager* deviceManager);
|
||||
};
|
||||
|
||||
std::vector<TextureHandle> m_handles;
|
||||
|
||||
@@ -70,6 +70,22 @@ bool KRTexture2D::createGPUTexture(int lod_max_dim) {
|
||||
break;
|
||||
}
|
||||
|
||||
VkImageViewCreateInfo viewInfo{};
|
||||
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
viewInfo.image = texture.image;
|
||||
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
viewInfo.format = VK_FORMAT_R8G8B8A8_SRGB;
|
||||
viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
viewInfo.subresourceRange.baseMipLevel = 0;
|
||||
viewInfo.subresourceRange.levelCount = 1;
|
||||
viewInfo.subresourceRange.baseArrayLayer = 0;
|
||||
viewInfo.subresourceRange.layerCount = 1;
|
||||
VkResult res = vkCreateImageView(device.m_logicalDevice, &viewInfo, nullptr, &texture.fullImageView);
|
||||
if(res != VK_SUCCESS) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!uploadTexture(device, texture.image, lod_max_dim, m_new_lod_max_dim)) {
|
||||
success = false;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user