Changeset a3cefaa in opengl-game for vulkan-game.cpp
- Timestamp:
- May 17, 2021, 4:06:33 PM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 1abebc1
- Parents:
- 996dd3e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r996dd3e ra3cefaa 77 77 , gui(nullptr) 78 78 , window(nullptr) 79 , objects_modelPipeline() 80 , objects_shipPipeline() 81 , objects_asteroidPipeline() 82 , objects_laserPipeline() 83 , objects_explosionPipeline() 79 84 , score(0) 80 85 , fps(0.0f) { … … 102 107 initVulkan(); 103 108 109 VkPhysicalDeviceProperties deviceProperties; 110 vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties); 111 112 objects_modelPipeline = VulkanBuffer<SSBO_ModelObject>(10, deviceProperties.limits.minUniformBufferOffsetAlignment); 113 objects_shipPipeline = VulkanBuffer<SSBO_ModelObject>(10, deviceProperties.limits.minUniformBufferOffsetAlignment); 114 objects_asteroidPipeline = VulkanBuffer<SSBO_Asteroid>(10, deviceProperties.limits.minUniformBufferOffsetAlignment); 115 objects_laserPipeline = VulkanBuffer<SSBO_Laser>(2, deviceProperties.limits.minUniformBufferOffsetAlignment); 116 objects_explosionPipeline = VulkanBuffer<SSBO_Explosion>(2, deviceProperties.limits.minUniformBufferOffsetAlignment); 117 104 118 initImGuiOverlay(); 105 119 … … 131 145 132 146 SceneObject<ModelVertex, SSBO_ModelObject>* texturedSquare = nullptr; 147 148 // TODO: Ideally, avoid having to make the squares as modified upon creation 133 149 134 150 texturedSquare = &addObject(modelObjects, modelPipeline, … … 145 161 }, { 146 162 mat4(1.0f) 147 }, storageBuffers_modelPipeline , false);148 149 updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo);163 }, storageBuffers_modelPipeline); 164 165 objects_modelPipeline.numObjects++; 150 166 151 167 texturedSquare->model_base = … … 166 182 }, { 167 183 mat4(1.0f) 168 }, storageBuffers_modelPipeline , false);169 170 updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo);184 }, storageBuffers_modelPipeline); 185 186 objects_modelPipeline.numObjects++; 171 187 172 188 texturedSquare->model_base = … … 428 444 }, { 429 445 mat4(1.0f) 430 }, storageBuffers_shipPipeline , false);431 432 updateStorageBuffer(storageBuffers_shipPipeline, shipPipeline.numObjects - 1, ship.ssbo);446 }, storageBuffers_shipPipeline); 447 448 objects_shipPipeline.numObjects++; 433 449 434 450 ship.model_base = … … 600 616 modelPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 601 617 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 602 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 24 , 10);603 604 createBufferSet( modelPipeline.objectCapacity * sizeof(SSBO_ModelObject),618 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 24); 619 620 createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject), 605 621 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 606 622 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 610 626 shipPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 611 627 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 612 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 138, 138 , 10);613 614 createBufferSet( modelPipeline.objectCapacity * sizeof(SSBO_ModelObject),628 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 138, 138); 629 630 createBufferSet(objects_shipPipeline.capacity * sizeof(SSBO_ModelObject), 615 631 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 616 632 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 620 636 asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 621 637 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 622 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 36 , 10);623 624 createBufferSet( modelPipeline.objectCapacity * sizeof(SSBO_Asteroid),638 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 36); 639 640 createBufferSet(objects_asteroidPipeline.capacity * sizeof(SSBO_Asteroid), 625 641 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 626 642 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 630 646 laserPipeline = GraphicsPipeline_Vulkan<LaserVertex>( 631 647 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 632 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 8, 18 , 2);633 634 createBufferSet( modelPipeline.objectCapacity * sizeof(SSBO_Laser),648 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 8, 18); 649 650 createBufferSet(objects_laserPipeline.capacity * sizeof(SSBO_Laser), 635 651 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 636 652 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 641 657 VK_PRIMITIVE_TOPOLOGY_POINT_LIST, physicalDevice, device, renderPass, 642 658 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 643 swapChainImages, EXPLOSION_PARTICLE_COUNT, EXPLOSION_PARTICLE_COUNT , 2);644 645 createBufferSet( modelPipeline.objectCapacity * sizeof(SSBO_Explosion),659 swapChainImages, EXPLOSION_PARTICLE_COUNT, EXPLOSION_PARTICLE_COUNT); 660 661 createBufferSet(objects_explosionPipeline.capacity * sizeof(SSBO_Explosion), 646 662 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 647 663 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, … … 768 784 }, { 769 785 mat4(1.0f) 770 }, storageBuffers_modelPipeline , true);771 772 updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare.ssbo);786 }, storageBuffers_modelPipeline); 787 788 objects_modelPipeline.numObjects++; 773 789 774 790 texturedSquare.model_base = … … 929 945 // where it will run just once per frame 930 946 void VulkanGame::updateScene() { 947 // Rotate the textured squares 931 948 for (SceneObject<ModelVertex, SSBO_ModelObject>& model : this->modelObjects) { 932 949 model.model_transform = … … 1050 1067 10.0f, 1051 1068 false 1052 }, storageBuffers_asteroidPipeline , true);1053 1054 updateStorageBuffer(storageBuffers_asteroidPipeline, asteroidPipeline.numObjects - 1, asteroid.ssbo);1069 }, storageBuffers_asteroidPipeline); 1070 1071 objects_asteroidPipeline.numObjects++; 1055 1072 1056 1073 // This accounts for the scaling in model_base. … … 1077 1094 } 1078 1095 1096 // TODO: Probably move the resizing to the VulkanBuffer class 1097 if (objects_modelPipeline.numObjects > objects_modelPipeline.capacity) { 1098 resizeStorageBufferSet(storageBuffers_modelPipeline, objects_modelPipeline, modelPipeline, resourceCommandPool, 1099 graphicsQueue); 1100 } 1101 1102 for (size_t i = 0; i < modelObjects.size(); i++) { 1103 if (modelObjects[i].modified) { 1104 updateObject(modelObjects, modelPipeline, i); 1105 updateStorageBuffer(storageBuffers_modelPipeline, i, modelObjects[i].ssbo); 1106 } 1107 } 1108 1109 // TODO: Probably move the resizing to the VulkanBuffer class 1110 if (objects_shipPipeline.numObjects > objects_shipPipeline.capacity) { 1111 resizeStorageBufferSet(storageBuffers_shipPipeline, objects_shipPipeline, shipPipeline, resourceCommandPool, 1112 graphicsQueue); 1113 } 1114 1079 1115 for (size_t i = 0; i < shipObjects.size(); i++) { 1080 1116 if (shipObjects[i].modified) { … … 1084 1120 } 1085 1121 1086 for (size_t i = 0; i < modelObjects.size(); i++) { 1087 if (modelObjects[i].modified) { 1088 updateObject(modelObjects, modelPipeline, i); 1089 updateStorageBuffer(storageBuffers_modelPipeline, i, modelObjects[i].ssbo); 1090 } 1122 // TODO: Probably move the resizing to the VulkanBuffer class 1123 if (objects_asteroidPipeline.numObjects > objects_asteroidPipeline.capacity) { 1124 resizeStorageBufferSet(storageBuffers_asteroidPipeline, objects_asteroidPipeline, asteroidPipeline, 1125 resourceCommandPool, graphicsQueue); 1091 1126 } 1092 1127 … … 1098 1133 } 1099 1134 1135 // TODO: Probably move the resizing to the VulkanBuffer class 1136 if (objects_laserPipeline.numObjects > objects_laserPipeline.capacity) { 1137 resizeStorageBufferSet(storageBuffers_laserPipeline, objects_laserPipeline, laserPipeline, resourceCommandPool, 1138 graphicsQueue); 1139 } 1140 1100 1141 for (size_t i = 0; i < laserObjects.size(); i++) { 1101 1142 if (laserObjects[i].modified) { … … 1103 1144 updateStorageBuffer(storageBuffers_laserPipeline, i, laserObjects[i].ssbo); 1104 1145 } 1146 } 1147 1148 // TODO: Probably move the resizing to the VulkanBuffer class 1149 if (objects_explosionPipeline.numObjects > objects_explosionPipeline.capacity) { 1150 resizeStorageBufferSet(storageBuffers_explosionPipeline, objects_explosionPipeline, explosionPipeline, 1151 resourceCommandPool, graphicsQueue); 1105 1152 } 1106 1153 … … 1525 1572 return VulkanUtils::findSupportedFormat( 1526 1573 physicalDevice, 1527 { VK_FORMAT_D32_SFLOAT , VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT },1574 { VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_D24_UNORM_S8_UINT }, 1528 1575 VK_IMAGE_TILING_OPTIMAL, 1529 1576 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT … … 1929 1976 color, 1930 1977 false 1931 }, storageBuffers_laserPipeline , true);1932 1933 updateStorageBuffer(storageBuffers_laserPipeline, laserPipeline.numObjects - 1, laser.ssbo);1978 }, storageBuffers_laserPipeline); 1979 1980 objects_laserPipeline.numObjects++; 1934 1981 1935 1982 float xAxisRotation = asin(ray.y / length); … … 2141 2188 duration, 2142 2189 false 2143 }, storageBuffers_explosionPipeline , true);2144 2145 updateStorageBuffer(storageBuffers_explosionPipeline, explosionPipeline.numObjects - 1, explosion.ssbo);2190 }, storageBuffers_explosionPipeline); 2191 2192 objects_explosionPipeline.numObjects++; 2146 2193 2147 2194 explosion.model_base = model_mat;
Note:
See TracChangeset
for help on using the changeset viewer.