Files
Copium/CopiumEngine/src/copium/sampler/DepthAttachment.cpp
T
2023-04-04 21:14:01 +02:00

41 lines
1.3 KiB
C++

#include "copium/sampler/DepthAttachment.h"
#include "copium/core/Vulkan.h"
#include "copium/sampler/Image.h"
namespace Copium
{
DepthAttachment::DepthAttachment(int width, int height)
: Sampler{}
{
InitializeDepthAttachment(width, height);
}
DepthAttachment::~DepthAttachment()
{
vkDestroyImage(Vulkan::GetDevice(), image, nullptr);
vkFreeMemory(Vulkan::GetDevice(), imageMemory, nullptr);
vkDestroyImageView(Vulkan::GetDevice(), imageView, nullptr);
}
VkDescriptorImageInfo DepthAttachment::GetDescriptorImageInfo(int index) const
{
VkDescriptorImageInfo imageInfo{};
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
imageInfo.sampler = sampler;
imageInfo.imageView = imageView;
return imageInfo;
}
VkImageView DepthAttachment::GetImageView() const
{
return imageView;
}
void DepthAttachment::InitializeDepthAttachment(int width, int height)
{
VkFormat depthFormat = Image::SelectDepthFormat();
Image::InitializeImage(width, height, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &image, &imageMemory);
imageView = Image::InitializeImageView(image, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT);
}
}