19 DescriptorPool::DescriptorPool(
void) {
20 VkDevice device = VulkanContext::getCurrent()->getDevice()->getHandle();
23 vector<VkDescriptorPoolSize> poolSizes(2);
24 poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
25 poolSizes[0].descriptorCount = 1;
26 poolSizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
27 poolSizes[1].descriptorCount = 1;
30 VkDescriptorPoolCreateInfo createInfo = {};
31 createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
32 createInfo.maxSets = 1;
33 createInfo.poolSizeCount = poolSizes.size();
34 createInfo.pPoolSizes = poolSizes.data();
37 if (vkCreateDescriptorPool(device, &createInfo,
nullptr, &handle) != VK_SUCCESS) {
38 throw runtime_error(
"Could not create a descriptor pool!");
42 DescriptorPool::~DescriptorPool(
void) {
43 VkDevice device = VulkanContext::getCurrent()->getDevice()->getHandle();
46 vkDestroyDescriptorPool(device, handle,
nullptr);
49 VkDescriptorPool DescriptorPool::getHandle() {
54 VkDevice device = VulkanContext::getCurrent()->getDevice()->getHandle();
55 VkDescriptorPool descriptorPool = VulkanContext::getCurrent()->getDescriptorPool()->getHandle();
59 VkDescriptorSetAllocateInfo allocateInfo = {};
60 allocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
61 allocateInfo.descriptorPool = descriptorPool;
62 allocateInfo.descriptorSetCount = 1;
63 allocateInfo.pSetLayouts = &layout;
66 if (vkAllocateDescriptorSets(device, &allocateInfo, &handle) != VK_SUCCESS) {
67 throw runtime_error(
"Could not allocate descriptor set!");
71 DescriptorSet::~DescriptorSet(
void) {
72 VkDevice device = VulkanContext::getCurrent()->getDevice()->getHandle();
73 VkDescriptorPool descriptorPool = VulkanContext::getCurrent()->getDescriptorPool()->getHandle();
76 vkFreeDescriptorSets(device, descriptorPool, 1, &handle);
79 VkDescriptorSet DescriptorSet::getHandle() {
83 void DescriptorSet::update(
UniformBuffer* uniformBuffer, std::vector<glm::mat2> data) {
84 VkDevice device = VulkanContext::getCurrent()->getDevice()->getHandle();
87 VkDescriptorBufferInfo bufferInfo = {};
88 bufferInfo.buffer = uniformBuffer->
getHandle();
89 bufferInfo.offset = 0;
90 bufferInfo.range = data.size() *
sizeof (mat2);
93 VkWriteDescriptorSet descriptorWrite = {};
94 descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
95 descriptorWrite.dstSet = handle;
96 descriptorWrite.dstBinding = 0;
97 descriptorWrite.dstArrayElement = 0;
98 descriptorWrite.descriptorCount = 1;
99 descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
100 descriptorWrite.pBufferInfo = &bufferInfo;
103 vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0,
nullptr);
106 void DescriptorSet::update(
UniformBuffer* uniformBuffer, std::vector<glm::mat3> data) {
107 VkDevice device = VulkanContext::getCurrent()->getDevice()->getHandle();
110 VkDescriptorBufferInfo bufferInfo = {};
111 bufferInfo.buffer = uniformBuffer->
getHandle();
112 bufferInfo.offset = 0;
113 bufferInfo.range = data.size() *
sizeof (mat3);
116 VkWriteDescriptorSet descriptorWrite = {};
117 descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
118 descriptorWrite.dstSet = handle;
119 descriptorWrite.dstBinding = 0;
120 descriptorWrite.dstArrayElement = 0;
121 descriptorWrite.descriptorCount = 1;
122 descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
123 descriptorWrite.pBufferInfo = &bufferInfo;
126 vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0,
nullptr);
129 void DescriptorSet::update(
UniformBuffer* uniformBuffer, std::vector<glm::mat4> data) {
130 VkDevice device = VulkanContext::getCurrent()->getDevice()->getHandle();
133 VkDescriptorBufferInfo bufferInfo = {};
134 bufferInfo.buffer = uniformBuffer->
getHandle();
135 bufferInfo.offset = 0;
136 bufferInfo.range = data.size() *
sizeof (mat4);
139 VkWriteDescriptorSet descriptorWrite = {};
140 descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
141 descriptorWrite.dstSet = handle;
142 descriptorWrite.dstBinding = 0;
143 descriptorWrite.dstArrayElement = 0;
144 descriptorWrite.descriptorCount = 1;
145 descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
146 descriptorWrite.pBufferInfo = &bufferInfo;
149 vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0,
nullptr);
153 VkDevice device = VulkanContext::getCurrent()->getDevice()->getHandle();
156 VkDescriptorImageInfo imageInfo = {};
157 imageInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
159 imageInfo.sampler = textureImage->
getSampler();
162 VkWriteDescriptorSet descriptorWrite = {};
163 descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
164 descriptorWrite.dstSet = handle;
165 descriptorWrite.dstBinding = 1;
166 descriptorWrite.dstArrayElement = 0;
167 descriptorWrite.descriptorCount = 1;
168 descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
169 descriptorWrite.pImageInfo = &imageInfo;
172 vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0,
nullptr);
VkSampler getSampler()
Returns the texture sampler of the image.
VkDescriptorSetLayout getDescriptorSetLayout()
Returns the descriptor set layout of the graphics pipeline.
Generic namespace for the SimpleGL framework.
This class wraps a Vulkan texture image.
This class wraps a Vulkan graphics pipeline.
VkImageView getImageView()
Returns the image view of the texture image.