Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.86 KB | None | 0 0
  1. m_gBuffer = {
  2.                     m_allocator.createImage(c_windowSize, VK_FORMAT_R8G8B8A8_UNORM,      VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_ASPECT_COLOR_BIT),
  3.                     m_allocator.createImage(c_windowSize, VK_FORMAT_R16G16B16A16_SFLOAT, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_ASPECT_COLOR_BIT),
  4.                     m_allocator.createImage(c_windowSize, VK_FORMAT_R16G16B16A16_SFLOAT, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_ASPECT_COLOR_BIT)
  5.                 };
  6.  
  7.     VkDescriptorSetLayoutBinding gBuffBinding = {};
  8.     gBuffBinding.binding = 0;
  9.     gBuffBinding.descriptorCount = m_gBuffer.size();
  10.     gBuffBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
  11.     gBuffBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
  12.  
  13.     VkDescriptorSetLayoutCreateInfo gBuffInfo = {};
  14.     gBuffInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
  15.     gBuffInfo.pNext = nullptr;
  16.     gBuffInfo.bindingCount = 1;
  17.     gBuffInfo.flags = 0;    
  18.     gBuffInfo.pBindings = &gBuffBinding;
  19.  
  20.     vkCreateDescriptorSetLayout(m_device, &gBuffInfo, nullptr, &m_gBufferSetLayout);
  21.  
  22.     VkDescriptorSetAllocateInfo allocInfo = {};
  23.     allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
  24.     allocInfo.pNext = nullptr;
  25.     allocInfo.descriptorPool = m_descriptorPool;
  26.     allocInfo.descriptorSetCount = 1;
  27.     allocInfo.pSetLayouts = &m_gBufferSetLayout;
  28.  
  29.     vkAllocateDescriptorSets(m_device, &allocInfo, &m_gBufferTexturesSet);
  30.  
  31.     VkSamplerCreateInfo samplerInfo = {};
  32.     samplerInfo.sType        = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
  33.     samplerInfo.pNext        = nullptr;
  34.     samplerInfo.magFilter    = VK_FILTER_LINEAR;
  35.     samplerInfo.minFilter    = VK_FILTER_LINEAR;
  36.     samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
  37.     samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
  38.     samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
  39.     samplerInfo.compareOp    = VK_COMPARE_OP_NEVER;
  40.     samplerInfo.borderColor  = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
  41.  
  42.     vkCreateSampler(m_device, &samplerInfo, nullptr, &m_gBufferSampler);
  43.  
  44.     VkDescriptorImageInfo gBuffImgInfo[m_gBuffer.size()];
  45.  
  46.     for (uint i = 0; i < m_gBuffer.size(); ++i)
  47.     {
  48.         gBuffImgInfo[i].sampler = m_gBufferSampler;
  49.         gBuffImgInfo[i].imageView = m_gBuffer[i].view;
  50.         gBuffImgInfo[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
  51.     }
  52.  
  53.     VkWriteDescriptorSet gBuffTextures = {};
  54.     gBuffTextures.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
  55.     gBuffTextures.pNext = nullptr;
  56.     gBuffTextures.dstBinding = 0;
  57.     gBuffTextures.dstSet = m_gBufferTexturesSet;
  58.     gBuffTextures.descriptorCount = m_gBuffer.size();
  59.     gBuffTextures.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
  60.     gBuffTextures.pImageInfo = gBuffImgInfo;
  61.  
  62.     vkUpdateDescriptorSets(m_device, 1, &gBuffTextures, 0, nullptr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement