Changeset 90880fb in opengl-game for vulkan-game.cpp
- Timestamp:
- Jun 17, 2021, 11:59:14 PM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 2f4ff8c
- Parents:
- 5ea0a37
- git-author:
- Dmitry Portnoy <dportnoy@…> (06/13/21 23:57:17)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (06/17/21 23:59:14)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r5ea0a37 r90880fb 77 77 , gui(nullptr) 78 78 , window(nullptr) 79 , vp_mats_modelPipeline() 79 80 , objects_modelPipeline() 81 , vp_mats_shipPipeline() 80 82 , objects_shipPipeline() 83 , vp_mats_asteroidPipeline() 81 84 , objects_asteroidPipeline() 85 , vp_mats_laserPipeline() 82 86 , objects_laserPipeline() 87 , uniforms_explosionPipeline() 83 88 , objects_explosionPipeline() 84 89 , score(0) 85 90 , fps(0.0f) { 86 object_VP_mats = {};87 ship_VP_mats = {};88 asteroid_VP_mats = {};89 laser_VP_mats = {};90 explosion_UBO = {};91 91 } 92 92 … … 110 110 vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties); 111 111 112 vp_mats_modelPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange, 113 deviceProperties.limits.minUniformBufferOffsetAlignment); 114 112 115 objects_modelPipeline = VulkanBuffer<SSBO_ModelObject>(10, deviceProperties.limits.maxStorageBufferRange, 113 116 deviceProperties.limits.minStorageBufferOffsetAlignment); 117 118 vp_mats_shipPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange, 119 deviceProperties.limits.minUniformBufferOffsetAlignment); 120 114 121 objects_shipPipeline = VulkanBuffer<SSBO_ModelObject>(10, deviceProperties.limits.maxStorageBufferRange, 115 122 deviceProperties.limits.minStorageBufferOffsetAlignment); 123 124 vp_mats_asteroidPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange, 125 deviceProperties.limits.minUniformBufferOffsetAlignment); 126 116 127 objects_asteroidPipeline = VulkanBuffer<SSBO_Asteroid>(10, deviceProperties.limits.maxStorageBufferRange, 117 128 deviceProperties.limits.minStorageBufferOffsetAlignment); 129 130 vp_mats_laserPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange, 131 deviceProperties.limits.minUniformBufferOffsetAlignment); 132 118 133 objects_laserPipeline = VulkanBuffer<SSBO_Laser>(2, deviceProperties.limits.maxStorageBufferRange, 119 134 deviceProperties.limits.minStorageBufferOffsetAlignment); 135 136 uniforms_explosionPipeline = VulkanBuffer<UBO_Explosion>(1, deviceProperties.limits.maxUniformBufferRange, 137 deviceProperties.limits.minUniformBufferOffsetAlignment); 138 120 139 objects_explosionPipeline = VulkanBuffer<SSBO_Explosion>(2, deviceProperties.limits.maxStorageBufferRange, 121 140 deviceProperties.limits.minStorageBufferOffsetAlignment); … … 138 157 modelPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex)); 139 158 140 createBufferSet( sizeof(UBO_VP_mats),159 createBufferSet(vp_mats_modelPipeline.memorySize(), 141 160 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 142 161 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 208 227 shipPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex)); 209 228 210 createBufferSet( sizeof(UBO_VP_mats),229 createBufferSet(vp_mats_shipPipeline.memorySize(), 211 230 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 212 231 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 475 494 asteroidPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex)); 476 495 477 createBufferSet( sizeof(UBO_VP_mats),496 createBufferSet(vp_mats_asteroidPipeline.memorySize(), 478 497 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 479 498 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 500 519 laserPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&LaserVertex::objIndex)); 501 520 502 createBufferSet( sizeof(UBO_VP_mats),521 createBufferSet(vp_mats_laserPipeline.memorySize(), 503 522 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 504 523 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 527 546 explosionPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ExplosionVertex::objIndex)); 528 547 529 createBufferSet( sizeof(UBO_Explosion),548 createBufferSet(uniforms_explosionPipeline.memorySize(), 530 549 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 531 550 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 684 703 projMat = perspective(radians(FOV_ANGLE), (float)swapChainExtent.width / (float)swapChainExtent.height, NEAR_CLIP, FAR_CLIP); 685 704 projMat[1][1] *= -1; // flip the y-axis so that +y is up 686 687 object_VP_mats.view = viewMat;688 object_VP_mats.proj = projMat;689 690 ship_VP_mats.view = viewMat;691 ship_VP_mats.proj = projMat;692 693 asteroid_VP_mats.view = viewMat;694 asteroid_VP_mats.proj = projMat;695 696 laser_VP_mats.view = viewMat;697 laser_VP_mats.proj = projMat;698 699 explosion_UBO.view = viewMat;700 explosion_UBO.proj = projMat;701 705 } 702 706 … … 940 944 // where it will run just once per frame 941 945 void VulkanGame::updateScene() { 946 947 vp_mats_modelPipeline.data()->view = viewMat; 948 vp_mats_modelPipeline.data()->proj = projMat; 949 950 vp_mats_shipPipeline.data()->view = viewMat; 951 vp_mats_shipPipeline.data()->proj = projMat; 952 953 vp_mats_asteroidPipeline.data()->view = viewMat; 954 vp_mats_asteroidPipeline.data()->proj = projMat; 955 956 vp_mats_laserPipeline.data()->view = viewMat; 957 vp_mats_laserPipeline.data()->proj = projMat; 958 959 uniforms_explosionPipeline.data()->view = viewMat; 960 uniforms_explosionPipeline.data()->proj = projMat; 961 uniforms_explosionPipeline.data()->cur_time = curTime; 962 963 for (vector<BaseEffectOverTime*>::iterator it = effects.begin(); it != effects.end(); ) { 964 if ((*it)->deleted) { 965 delete *it; 966 it = effects.erase(it); 967 } else { 968 BaseEffectOverTime* eot = *it; 969 970 eot->applyEffect(curTime); 971 972 it++; 973 } 974 } 975 942 976 if (curTime - lastSpawn_asteroid > spawnRate_asteroid) { 943 977 lastSpawn_asteroid = curTime; … … 1046 1080 } 1047 1081 1082 VulkanUtils::copyDataToMemory(device, vp_mats_modelPipeline.data(), uniformBuffers_modelPipeline.memory[imageIndex], 1083 0, vp_mats_modelPipeline.memorySize(), false); 1084 1048 1085 VulkanUtils::copyDataToMemory(device, objects_modelPipeline.data(), storageBuffers_modelPipeline.memory[imageIndex], 1049 1086 0, objects_modelPipeline.memorySize(), false); … … 1066 1103 obj.center = vec3(objData.model * vec4(0.0f, 0.0f, 0.0f, 1.0f)); 1067 1104 } 1105 1106 VulkanUtils::copyDataToMemory(device, vp_mats_shipPipeline.data(), uniformBuffers_shipPipeline.memory[imageIndex], 1107 0, vp_mats_shipPipeline.memorySize(), false); 1068 1108 1069 1109 VulkanUtils::copyDataToMemory(device, objects_shipPipeline.data(), storageBuffers_shipPipeline.memory[imageIndex], … … 1111 1151 } 1112 1152 1153 VulkanUtils::copyDataToMemory(device, vp_mats_asteroidPipeline.data(), uniformBuffers_asteroidPipeline.memory[imageIndex], 1154 0, vp_mats_asteroidPipeline.memorySize(), false); 1155 1113 1156 VulkanUtils::copyDataToMemory(device, objects_asteroidPipeline.data(), storageBuffers_asteroidPipeline.memory[imageIndex], 1114 1157 0, objects_asteroidPipeline.memorySize(), false); … … 1137 1180 obj.center = vec3(objData.model * vec4(0.0f, 0.0f, 0.0f, 1.0f)); 1138 1181 } 1182 1183 VulkanUtils::copyDataToMemory(device, vp_mats_laserPipeline.data(), uniformBuffers_laserPipeline.memory[imageIndex], 1184 0, vp_mats_laserPipeline.memorySize(), false); 1139 1185 1140 1186 VulkanUtils::copyDataToMemory(device, objects_laserPipeline.data(), storageBuffers_laserPipeline.memory[imageIndex], … … 1164 1210 } 1165 1211 1212 VulkanUtils::copyDataToMemory(device, uniforms_explosionPipeline.data(), uniformBuffers_explosionPipeline.memory[imageIndex], 1213 0, uniforms_explosionPipeline.memorySize(), false); 1214 1166 1215 VulkanUtils::copyDataToMemory(device, objects_explosionPipeline.data(), storageBuffers_explosionPipeline.memory[imageIndex], 1167 1216 0, objects_explosionPipeline.memorySize(), false); 1168 1169 explosion_UBO.cur_time = curTime;1170 1171 for (vector<BaseEffectOverTime*>::iterator it = effects.begin(); it != effects.end(); ) {1172 if ((*it)->deleted) {1173 delete *it;1174 it = effects.erase(it);1175 } else {1176 BaseEffectOverTime* eot = *it;1177 1178 eot->applyEffect(curTime);1179 1180 it++;1181 }1182 }1183 1184 VulkanUtils::copyDataToMemory(device, &object_VP_mats, uniformBuffers_modelPipeline.memory[imageIndex], 0,1185 sizeof(object_VP_mats), false);1186 1187 VulkanUtils::copyDataToMemory(device, &ship_VP_mats, uniformBuffers_shipPipeline.memory[imageIndex], 0,1188 sizeof(ship_VP_mats), false);1189 1190 VulkanUtils::copyDataToMemory(device, &asteroid_VP_mats, uniformBuffers_asteroidPipeline.memory[imageIndex], 0,1191 sizeof(asteroid_VP_mats), false);1192 1193 VulkanUtils::copyDataToMemory(device, &laser_VP_mats, uniformBuffers_laserPipeline.memory[imageIndex], 0,1194 sizeof(laser_VP_mats), false);1195 1196 VulkanUtils::copyDataToMemory(device, &explosion_UBO, uniformBuffers_explosionPipeline.memory[imageIndex], 0,1197 sizeof(explosion_UBO), false);1198 1217 } 1199 1218 … … 2234 2253 createSyncObjects(); 2235 2254 2236 createBufferSet( sizeof(UBO_VP_mats),2255 createBufferSet(vp_mats_modelPipeline.memorySize(), 2237 2256 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2238 2257 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 2250 2269 modelPipeline.createDescriptorSets(swapChainImages.size()); 2251 2270 2252 createBufferSet( sizeof(UBO_VP_mats),2271 createBufferSet(vp_mats_shipPipeline.memorySize(), 2253 2272 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2254 2273 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 2266 2285 shipPipeline.createDescriptorSets(swapChainImages.size()); 2267 2286 2268 createBufferSet( sizeof(UBO_VP_mats),2287 createBufferSet(vp_mats_asteroidPipeline.memorySize(), 2269 2288 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2270 2289 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 2282 2301 asteroidPipeline.createDescriptorSets(swapChainImages.size()); 2283 2302 2284 createBufferSet( sizeof(UBO_VP_mats),2303 createBufferSet(vp_mats_laserPipeline.memorySize(), 2285 2304 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2286 2305 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 2298 2317 laserPipeline.createDescriptorSets(swapChainImages.size()); 2299 2318 2300 createBufferSet( sizeof(UBO_Explosion),2319 createBufferSet(uniforms_explosionPipeline.memorySize(), 2301 2320 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2302 2321 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
Note:
See TracChangeset
for help on using the changeset viewer.