1818constexpr auto NO_TIMEOUT = std::numeric_limits<uint64_t >::max();
1919
2020const std::vector<Vertex> VERTICES = {
21- {{-0 .5f , -0 .5f }, {1 .0f , 0 .0f , 0 .0f }},
22- {{0 .5f , -0 .5f }, {0 .0f , 1 .0f , 0 .0f }},
23- {{0 .5f , 0 .5f }, {0 .0f , 0 .0f , 1 .0f }},
24- {{-0 .5f , 0 .5f }, {1 .0f , 1 .0f , 1 .0f }}};
21+ {{-0 .5f , -0 .5f }, {1 .0f , 0 .0f , 0 .0f }, {1 .0f , 0 .0f }},
22+ {{0 .5f , -0 .5f }, {0 .0f , 1 .0f , 0 .0f }, {0 .0f , 0 .0f }},
23+ {{0 .5f , 0 .5f }, {0 .0f , 0 .0f , 1 .0f }, {0 .0f , 1 .0f }},
24+ {{-0 .5f , 0 .5f }, {1 .0f , 1 .0f , 1 .0f }, {1 .0f , 1 .0f }}};
25+
2526
2627const std::vector<uint16_t > INDICES = {0 , 1 , 2 , 2 , 3 , 0 };
2728
@@ -60,6 +61,8 @@ void Application::initVulkan() {
6061 createFrameBuffers ();
6162 createCommandPool ();
6263 createTextureImage ();
64+ createTextureImageView ();
65+ createTextureSampler ();
6366 createVertexBuffer ();
6467 createIndexBuffer ();
6568 createUniformBuffers ();
@@ -401,8 +404,18 @@ void Application::createDescriptorSetLayout() {
401404 .setDescriptorType (vk::DescriptorType::eUniformBuffer)
402405 .setStageFlags (vk::ShaderStageFlagBits::eVertex);
403406
407+ const auto samplerLayoutBinding =
408+ vk::DescriptorSetLayoutBinding ()
409+ .setBinding (1 )
410+ .setDescriptorCount (1 )
411+ .setDescriptorType (vk::DescriptorType::eCombinedImageSampler)
412+ .setStageFlags (vk::ShaderStageFlagBits::eFragment);
413+
414+
415+ std::array bindings = {uboLayoutBinding, samplerLayoutBinding};
416+
404417 vk::DescriptorSetLayoutCreateInfo layoutInfo;
405- layoutInfo.setBindings (uboLayoutBinding );
418+ layoutInfo.setBindings (bindings );
406419
407420 m_descriptorSetLayout = m_device.createDescriptorSetLayout (layoutInfo);
408421}
@@ -728,14 +741,21 @@ void Application::createUniformBuffers() {
728741}
729742
730743void Application::createDescriptorPool () {
731- vk::DescriptorPoolSize poolSize;
732- poolSize.type = vk::DescriptorType::eUniformBuffer;
733- poolSize.descriptorCount =
744+ const auto maxFramesInFlight =
734745 static_cast <uint32_t >(Config::MAX_FRAMES_IN_FLIGHT);
735746
747+ std::array<vk::DescriptorPoolSize, 2 > poolSizes;
748+
749+ poolSizes[0 ].type = vk::DescriptorType::eUniformBuffer;
750+ poolSizes[0 ].descriptorCount = maxFramesInFlight;
751+
752+ poolSizes[1 ].type = vk::DescriptorType::eCombinedImageSampler;
753+ poolSizes[1 ].descriptorCount = maxFramesInFlight;
754+
755+
736756 vk::DescriptorPoolCreateInfo poolInfo;
737- poolInfo.setPoolSizes (poolSize );
738- poolInfo.maxSets = static_cast < uint32_t >(Config::MAX_FRAMES_IN_FLIGHT) ;
757+ poolInfo.setPoolSizes (poolSizes );
758+ poolInfo.maxSets = maxFramesInFlight ;
739759
740760 m_descriptorPool = m_device.createDescriptorPool (poolInfo);
741761}
@@ -759,15 +779,30 @@ void Application::createDescriptorSets() {
759779 bufferInfo.offset = 0 ;
760780 bufferInfo.range = sizeof (UniformBufferObject);
761781
762- vk::WriteDescriptorSet descriptorWrite;
763- descriptorWrite.dstSet = m_descriptorSets[i];
764- descriptorWrite.dstBinding = 0 ;
765- descriptorWrite.dstArrayElement = 0 ;
766- descriptorWrite.descriptorType = vk::DescriptorType::eUniformBuffer;
767- descriptorWrite.descriptorCount = 1 ;
768- descriptorWrite.setBufferInfo (bufferInfo);
782+ vk::DescriptorImageInfo imageInfo;
783+ imageInfo.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
784+ imageInfo.imageView = textureImageView;
785+ imageInfo.sampler = textureSampler;
786+
787+ std::array<vk::WriteDescriptorSet, 2 > descriptorWrites;
788+
789+ descriptorWrites[0 ].dstSet = m_descriptorSets[i];
790+ descriptorWrites[0 ].dstBinding = 0 ;
791+ descriptorWrites[0 ].dstArrayElement = 0 ;
792+ descriptorWrites[0 ].descriptorType = vk::DescriptorType::eUniformBuffer;
793+ descriptorWrites[0 ].descriptorCount = 1 ;
794+ descriptorWrites[0 ].pBufferInfo = &bufferInfo;
769795
770- m_device.updateDescriptorSets (descriptorWrite, {});
796+ descriptorWrites[1 ].dstSet = m_descriptorSets[i];
797+ descriptorWrites[1 ].dstBinding = 1 ;
798+ descriptorWrites[1 ].dstArrayElement = 0 ;
799+ descriptorWrites[1 ].descriptorType =
800+ vk::DescriptorType::eCombinedImageSampler;
801+ descriptorWrites[1 ].descriptorCount = 1 ;
802+ descriptorWrites[1 ].pImageInfo = &imageInfo;
803+
804+
805+ m_device.updateDescriptorSets (descriptorWrites, {});
771806 }
772807}
773808
@@ -1074,7 +1109,7 @@ void Application::createImage(
10741109 vk::MemoryRequirements memRequirements =
10751110 m_device.getImageMemoryRequirements (image);
10761111
1077- vk::MemoryAllocateInfo allocInfo{} ;
1112+ vk::MemoryAllocateInfo allocInfo;
10781113 allocInfo.allocationSize = memRequirements.size ;
10791114 allocInfo.memoryTypeIndex =
10801115 findMemoryType (memRequirements.memoryTypeBits , properties);
@@ -1091,7 +1126,7 @@ void Application::transitionImageLayout(
10911126) {
10921127 vk::CommandBuffer commandBuffer = beginSingleTimeCommands ();
10931128
1094- vk::ImageMemoryBarrier barrier{} ;
1129+ vk::ImageMemoryBarrier barrier;
10951130 barrier.oldLayout = oldLayout;
10961131 barrier.newLayout = newLayout;
10971132 barrier.srcQueueFamilyIndex = vk::QueueFamilyIgnored;
@@ -1142,7 +1177,7 @@ void Application::copyBufferToImage(
11421177) {
11431178 vk::CommandBuffer commandBuffer = beginSingleTimeCommands ();
11441179
1145- vk::BufferImageCopy region{} ;
1180+ vk::BufferImageCopy region;
11461181 region.bufferOffset = 0 ;
11471182 region.bufferRowLength = 0 ;
11481183 region.bufferImageHeight = 0 ;
0 commit comments