update framebuffer setup

pull/2/head
ink-soul 2023-05-23 11:30:21 +08:00
parent 7733ba49ee
commit 1629bbdcf5
2 changed files with 84 additions and 0 deletions

View File

@ -660,7 +660,23 @@ VulkanExample::VulkanExample():
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
} }
void VulkanExample::setupFrameBuffer()
{
if (pbrFrameBuffer.bCreate && (pbrFrameBuffer.fbo.width != width || pbrFrameBuffer.fbo.height != height))
{
pbrFrameBuffer.color.destroy(device);
pbrFrameBuffer.depth.destroy(device);
pbrFrameBuffer.fbo.destroy(device);
vkDestroySampler(device, colorSampler, nullptr);
}
pbrFrameBuffer.fbo.setSize(width, height);
VkFormat attachDepthFormat;
VkBool32 validDepthFormat = vks::tools::getSupportedDepthFormat(physicalDevice, &attachDepthFormat);
assert(validDepthFormat);
}
void VulkanExample::getEnabledFeatures() void VulkanExample::getEnabledFeatures()
{ {
@ -994,6 +1010,72 @@ void VulkanExample::getEnabledFeatures()
memcpy(shaderData.buffer.mapped, &shaderData.values, sizeof(shaderData.values)); memcpy(shaderData.buffer.mapped, &shaderData.values, sizeof(shaderData.values));
} }
//-------------------------- pbr precompute start ----------------------------------
#pragma region pbr render pass setting
void VulkanExample::createAttachment(VkFormat format, VkImageUsageFlagBits usage, VulkanExample::FrameBufferAttachment* attachment, uint32_t width, uint32_t height)
{
VkImageAspectFlags aspectMask = 0;
VkImageUsageFlags imageUsage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
attachment->format = format;
if (usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
{
aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
imageUsage |= VK_IMAGE_USAGE_SAMPLED_BIT;
}
if (usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
{
aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
if (format >= VK_FORMAT_D16_UNORM_S8_UINT)
aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
}
assert(aspectMask > 0);
VkImageCreateInfo image = vks::initializers::imageCreateInfo();
image.imageType = VK_IMAGE_TYPE_2D;
image.format = format;
image.extent.width = width;
image.extent.height = height;
image.extent.depth = 1;
image.mipLevels = 1;
image.arrayLayers = 1;
image.samples = VK_SAMPLE_COUNT_1_BIT;
image.tiling = VK_IMAGE_TILING_OPTIMAL;
image.usage = imageUsage | usage;
VkMemoryAllocateInfo memAlloc = vks::initializers::memoryAllocateInfo();
VkMemoryRequirements memReqs;
VK_CHECK_RESULT(vkCreateImage(device, &image, nullptr, &attachment->image));
vkGetImageMemoryRequirements(device, attachment->image, &memReqs);
memAlloc.allocationSize = memReqs.size;
memAlloc.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
VK_CHECK_RESULT(vkAllocateMemory(device, &memAlloc, nullptr, &attachment->deviceMemory));
VK_CHECK_RESULT(vkBindImageMemory(device, attachment->image, attachment->deviceMemory, 0));
VkImageViewCreateInfo imageView = vks::initializers::imageViewCreateInfo();
imageView.viewType = VK_IMAGE_VIEW_TYPE_2D;
imageView.format = format;
imageView.subresourceRange = {};
imageView.subresourceRange.aspectMask = aspectMask;
imageView.subresourceRange.baseMipLevel = 0;
imageView.subresourceRange.levelCount = 1;
imageView.subresourceRange.baseArrayLayer = 0;
imageView.subresourceRange.layerCount = 1;
imageView.image = attachment->image;
VK_CHECK_RESULT(vkCreateImageView(device, &imageView, nullptr, &attachment->imageView));
}
#pragma endregion
// ----------------------- pbr precompute end ---------------------------------------
void VulkanExample::prepare() void VulkanExample::prepare()
{ {
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();

View File

@ -357,6 +357,8 @@ public:
} }
void loadglTFFile(std::string filename); void loadglTFFile(std::string filename);
virtual void getEnabledFeatures(); virtual void getEnabledFeatures();
void createAttachment(VkFormat format, VkImageUsageFlagBits usage, FrameBufferAttachment* attachment, uint32_t width, uint32_t height);
virtual void setupFrameBuffer();
void buildCommandBuffers(); void buildCommandBuffers();
void loadAssets(); void loadAssets();
void setupDescriptors(); void setupDescriptors();