Changeset c7fb883 in opengl-game
- Timestamp:
- Jul 25, 2019, 3:22:59 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- eea05dd
- Parents:
- de32fda
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
rde32fda rc7fb883 171 171 VkPipeline graphicsPipeline; 172 172 VkCommandPool commandPool; 173 VkDescriptorPool descriptorPool; 174 vector<VkDescriptorSet> descriptorSets; 173 175 174 176 VkBuffer vertexBuffer; … … 224 226 createIndexBuffer(); 225 227 createUniformBuffers(); 228 createDescriptorPool(); 229 createDescriptorSets(); 226 230 createCommandBuffers(); 227 231 createSyncObjects(); … … 248 252 createFramebuffers(); 249 253 createUniformBuffers(); 254 createDescriptorPool(); 255 createDescriptorSets(); 250 256 createCommandBuffers(); 251 257 } … … 272 278 vkFreeMemory(device, uniformBuffersMemory[i], nullptr); 273 279 } 280 281 vkDestroyDescriptorPool(device, descriptorPool, nullptr); 274 282 } 275 283 … … 802 810 rasterizer.lineWidth = 1.0f; 803 811 rasterizer.cullMode = VK_CULL_MODE_BACK_BIT; 804 rasterizer.frontFace = VK_FRONT_FACE_C LOCKWISE;812 rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; 805 813 rasterizer.depthBiasEnable = false; 806 814 … … 957 965 } 958 966 959 void createUniformBuffers() {960 VkDeviceSize bufferSize = sizeof(UniformBufferObject);961 962 uniformBuffers.resize(swapChainImages.size());963 uniformBuffersMemory.resize(swapChainImages.size());964 965 for (size_t i = 0; i < swapChainImages.size(); i++) {966 createBuffer(bufferSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,967 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,968 uniformBuffers[i], uniformBuffersMemory[i]);969 }970 }971 972 967 void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, 973 968 VkBuffer& buffer, VkDeviceMemory& bufferMemory) { … … 1046 1041 } 1047 1042 1043 void createUniformBuffers() { 1044 VkDeviceSize bufferSize = sizeof(UniformBufferObject); 1045 1046 uniformBuffers.resize(swapChainImages.size()); 1047 uniformBuffersMemory.resize(swapChainImages.size()); 1048 1049 for (size_t i = 0; i < swapChainImages.size(); i++) { 1050 createBuffer(bufferSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 1051 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 1052 uniformBuffers[i], uniformBuffersMemory[i]); 1053 } 1054 } 1055 1056 void createDescriptorPool() { 1057 VkDescriptorPoolSize poolSize = {}; 1058 poolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; 1059 poolSize.descriptorCount = static_cast<uint32_t>(swapChainImages.size()); 1060 1061 VkDescriptorPoolCreateInfo poolInfo = {}; 1062 poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; 1063 poolInfo.poolSizeCount = 1; 1064 poolInfo.pPoolSizes = &poolSize; 1065 poolInfo.maxSets = static_cast<uint32_t>(swapChainImages.size()); 1066 1067 if (vkCreateDescriptorPool(device, &poolInfo, nullptr, &descriptorPool) != VK_SUCCESS) { 1068 throw runtime_error("failed to create descriptor pool!"); 1069 } 1070 } 1071 1072 void createDescriptorSets() { 1073 vector<VkDescriptorSetLayout> layouts(swapChainImages.size(), descriptorSetLayout); 1074 VkDescriptorSetAllocateInfo allocInfo = {}; 1075 allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; 1076 allocInfo.descriptorPool = descriptorPool; 1077 allocInfo.descriptorSetCount = static_cast<uint32_t>(swapChainImages.size()); 1078 allocInfo.pSetLayouts = layouts.data(); 1079 1080 descriptorSets.resize(swapChainImages.size()); 1081 if (vkAllocateDescriptorSets(device, &allocInfo, descriptorSets.data()) != VK_SUCCESS) { 1082 throw runtime_error("failed to allocate descriptor sets!"); 1083 } 1084 1085 for (size_t i = 0; i < swapChainImages.size(); i++) { 1086 VkDescriptorBufferInfo bufferInfo = {}; 1087 bufferInfo.buffer = uniformBuffers[i]; 1088 bufferInfo.offset = 0; 1089 bufferInfo.range = sizeof(UniformBufferObject); 1090 1091 VkWriteDescriptorSet descriptorWrite = {}; 1092 descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; 1093 descriptorWrite.dstSet = descriptorSets[i]; 1094 descriptorWrite.dstBinding = 0; 1095 descriptorWrite.dstArrayElement = 0; 1096 descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; 1097 descriptorWrite.descriptorCount = 1; 1098 descriptorWrite.pBufferInfo = &bufferInfo; 1099 descriptorWrite.pImageInfo = nullptr; 1100 descriptorWrite.pTexelBufferView = nullptr; 1101 1102 vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0, nullptr); 1103 } 1104 } 1105 1048 1106 void createCommandBuffers() { 1049 1107 commandBuffers.resize(swapChainFramebuffers.size()); … … 1088 1146 1089 1147 vkCmdBindIndexBuffer(commandBuffers[i], indexBuffer, 0, VK_INDEX_TYPE_UINT16); 1148 vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets[i], 0, nullptr); 1090 1149 1091 1150 vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(indices.size()), 1, 0, 0, 0);
Note:
See TracChangeset
for help on using the changeset viewer.