update framebuffer setter

pull/2/head
ink-soul 2023-05-23 15:52:04 +08:00
parent 1629bbdcf5
commit 4e175e863b
2 changed files with 74 additions and 3 deletions

View File

@ -609,12 +609,12 @@
if (textures.size() > 0)
{
VulkanglTFModel::Texture texture = textures[materials[primitive.materialIndex].baseColorTextureIndex];
auto normalMap = textures[materials[primitive.materialIndex].normalMapTextureIndex];
auto roughMetalMap = textures[materials[primitive.materialIndex].matalicRoughTextureIndex];
VulkanglTFModel::Texture normalMap = textures[materials[primitive.materialIndex].normalMapTextureIndex];
VulkanglTFModel::Texture roughMetalMap = textures[materials[primitive.materialIndex].matalicRoughTextureIndex];
if (materials[primitive.materialIndex].emissiveTextureIndex >= 0)
{
auto emissiveMap = textures[materials[primitive.materialIndex].emissiveTextureIndex];
VulkanglTFModel::Texture emissiveMap = textures[materials[primitive.materialIndex].emissiveTextureIndex];
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 4, 1, &images[emissiveMap.imageIndex].descriptorSet, 0, nullptr);
}
@ -674,8 +674,78 @@ void VulkanExample::setupFrameBuffer()
VkFormat attachDepthFormat;
VkBool32 validDepthFormat = vks::tools::getSupportedDepthFormat(physicalDevice, &attachDepthFormat);
assert(validDepthFormat);
VulkanExample::createAttachment(VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, &pbrFrameBuffer.color, width, height);
VulkanExample::createAttachment(attachDepthFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, &pbrFrameBuffer.depth, width, height);
std::array<VkAttachmentDescription, 2> attachs = {};
for (uint32_t i = 0; i < static_cast<uint32_t>(attachs.size()); i++)
{
attachs[i].samples = VK_SAMPLE_COUNT_1_BIT;
attachs[i].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachs[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachs[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachs[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachs[i].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
attachs[i].finalLayout = 1 ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL;
}
attachs[0].format = pbrFrameBuffer.color.format;
attachs[1].format = pbrFrameBuffer.depth.format;
VkAttachmentReference colorRefference = {};
colorRefference.attachment = 0;
colorRefference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkAttachmentReference depthRefference = {};
colorRefference.attachment = 1;
colorRefference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.pColorAttachments = &colorRefference;
subpass.colorAttachmentCount = 1;
subpass.pDepthStencilAttachment = &depthRefference;
std::array<VkSubpassDependency, 2> dependencies;
//To test src 0
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
dependencies[0].dstSubpass = 0;
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependencies[0].srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
dependencies[1].srcSubpass = 0;
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependencies[1].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
VkRenderPassCreateInfo renderPassCI = {};
renderPassCI.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassCI.pAttachments = attachs.data();
renderPassCI.attachmentCount = static_cast<uint32_t>(attachs.size());
renderPassCI.pSubpasses = &subpass;
renderPassCI.pDependencies = dependencies.data();
renderPassCI.dependencyCount = 2;
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassCI, nullptr, &pbrFrameBuffer.fbo.renderPass));
// FBO
VkImageView attachments[2] = { pbrFrameBuffer.color.imageView,pbrFrameBuffer.depth.imageView };
VkFramebufferCreateInfo frameBufferCreateInfo = vks::initializers::framebufferCreateInfo();
frameBufferCreateInfo.renderPass = pbrFrameBuffer.fbo.renderPass;
frameBufferCreateInfo.pAttachments = attachments;
frameBufferCreateInfo.attachmentCount = 2;
frameBufferCreateInfo.width = pbrFrameBuffer.fbo.width;
frameBufferCreateInfo.height = pbrFrameBuffer.fbo.height;
frameBufferCreateInfo.layers = 1;
VK_CHECK_RESULT(vkCreateFramebuffer(device, &frameBufferCreateInfo, nullptr, &pbrFrameBuffer.fbo.frameBuffer));
VkSamplerCreateInfo samplerCI = vks::initializers::samplerCreateInfo();
samplerCI.magFilter = VK_FILTER_NEAREST;
}
void VulkanExample::getEnabledFeatures()

View File

@ -273,6 +273,7 @@ public:
VkDeviceMemory deviceMemory;
VkImageView imageView;
VkFormat format;
void destroy(VkDevice device)
{