Lugdunum  0.1.0
MaterialTextures.cpp
Go to the documentation of this file.
2 
4 
5 namespace lug {
6 namespace Graphics {
7 namespace Vulkan {
8 namespace Render {
9 namespace DescriptorSetPool {
10 
12 
13 const DescriptorSet* MaterialTextures::allocate(const API::GraphicsPipeline& pipeline, const std::vector<const ::lug::Graphics::Vulkan::Render::Texture*>& textures) {
14  // Generate hash
15  size_t hash = textures.size();
16  for (uint32_t i = 0; i < textures.size(); ++i) {
17  hash ^= textures[i]->getHandle().value + 0x9e3779b9 + (hash << 6) + (hash >> 2);
18  }
19 
20  const auto& result = DescriptorSetPool::allocate(
21  hash,
22  pipeline.getLayout()->getDescriptorSetLayouts()[3]
23  );
24 
25  if (std::get<0>(result) && std::get<1>(result)) {
26  std::vector<VkDescriptorImageInfo> imageInfos(textures.size());
27 
28  for (uint32_t i = 0; i < textures.size(); ++i) {
29  imageInfos[i].sampler = static_cast<VkSampler>(textures[i]->getSampler());
30  imageInfos[i].imageView = static_cast<VkImageView>(textures[i]->getImageView());
31  imageInfos[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
32  }
33 
34 
35  std::get<1>(result)->getDescriptorSet().updateImages(
36  0,
37  0,
38  VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
39  imageInfos
40  );
41  }
42 
43  return std::get<1>(result);
44 }
45 
46 } // DescriptorSetPool
47 } // Render
48 } // Vulkan
49 } // Graphics
50 } // lug
const DescriptorSet * allocate(const API::GraphicsPipeline &pipeline, const std::vector< const ::lug::Graphics::Vulkan::Render::Texture *> &textures)
std::tuple< bool, const DescriptorSet * > allocate(size_t hash, const API::DescriptorSetLayout &descriptorSetLayout)
const PipelineLayout * getLayout() const
const std::vector< DescriptorSetLayout > & getDescriptorSetLayouts() const
Gets the DescriptorSetLayouts of the PipelineLayout. The PipelineLayout owns these DescriptorSetLayou...