Changeset 6486ba8 in opengl-game for vulkan-game.cpp
- Timestamp:
- Jun 11, 2021, 8:12:29 PM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 5ea0a37
- Parents:
- c1ec4f6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
rc1ec4f6 r6486ba8 139 139 140 140 createBufferSet(sizeof(UBO_VP_mats), 141 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 142 uniformBuffers_modelPipeline); 141 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 142 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 143 uniformBuffers_modelPipeline); 144 145 createBufferSet(objects_modelPipeline.memorySize(), 146 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 147 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 148 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 149 storageBuffers_modelPipeline); 143 150 144 151 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, … … 149 156 VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor); 150 157 151 SceneObject<ModelVertex , SSBO_ModelObject>* texturedSquare = nullptr;158 SceneObject<ModelVertex>* texturedSquare = nullptr; 152 159 153 160 texturedSquare = &addObject(modelObjects, modelPipeline, … … 202 209 203 210 createBufferSet(sizeof(UBO_VP_mats), 204 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 205 uniformBuffers_shipPipeline); 211 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 212 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 213 uniformBuffers_shipPipeline); 214 215 createBufferSet(objects_shipPipeline.memorySize(), 216 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 217 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 218 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 219 storageBuffers_shipPipeline); 206 220 207 221 shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, … … 212 226 // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly 213 227 // the same data. Add an option to make some pipelines not use indexing 214 SceneObject<ModelVertex , SSBO_ModelObject>& ship = addObject(shipObjects, shipPipeline,228 SceneObject<ModelVertex>& ship = addObject(shipObjects, shipPipeline, 215 229 addObjectIndex<ModelVertex>(shipObjects.size(), 216 230 addVertexNormals<ModelVertex>({ … … 462 476 463 477 createBufferSet(sizeof(UBO_VP_mats), 464 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 465 uniformBuffers_asteroidPipeline); 478 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 479 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 480 uniformBuffers_asteroidPipeline); 481 482 createBufferSet(objects_asteroidPipeline.memorySize(), 483 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 484 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 485 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 486 storageBuffers_asteroidPipeline); 466 487 467 488 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, … … 480 501 481 502 createBufferSet(sizeof(UBO_VP_mats), 482 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 483 uniformBuffers_laserPipeline); 503 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 504 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 505 uniformBuffers_laserPipeline); 506 507 createBufferSet(objects_laserPipeline.memorySize(), 508 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 509 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 510 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 511 storageBuffers_laserPipeline); 484 512 485 513 laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, … … 500 528 501 529 createBufferSet(sizeof(UBO_Explosion), 502 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 503 uniformBuffers_explosionPipeline); 530 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 531 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 532 uniformBuffers_explosionPipeline); 533 534 createBufferSet(objects_explosionPipeline.memorySize(), 535 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 536 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 537 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 538 storageBuffers_explosionPipeline); 504 539 505 540 explosionPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, … … 615 650 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 24, 24); 616 651 617 createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject),618 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT619 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,620 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,621 storageBuffers_modelPipeline);622 623 652 shipPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 624 653 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 625 654 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 138, 138); 626 655 627 createBufferSet(objects_shipPipeline.capacity * sizeof(SSBO_ModelObject),628 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT629 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,630 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,631 storageBuffers_shipPipeline);632 633 656 asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 634 657 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 635 658 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 24, 36); 636 659 637 createBufferSet(objects_asteroidPipeline.capacity * sizeof(SSBO_Asteroid),638 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT639 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,640 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,641 storageBuffers_asteroidPipeline);642 643 660 laserPipeline = GraphicsPipeline_Vulkan<LaserVertex>( 644 661 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 645 662 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 8, 18); 646 647 createBufferSet(objects_laserPipeline.capacity * sizeof(SSBO_Laser),648 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT649 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,650 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,651 storageBuffers_laserPipeline);652 663 653 664 explosionPipeline = GraphicsPipeline_Vulkan<ExplosionVertex>( … … 655 666 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 656 667 EXPLOSION_PARTICLE_COUNT, EXPLOSION_PARTICLE_COUNT); 657 658 createBufferSet(objects_explosionPipeline.capacity * sizeof(SSBO_Explosion),659 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT660 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,661 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,662 storageBuffers_explosionPipeline);663 668 } 664 669 … … 767 772 float zOffset = -2.0f + (0.5f * modelObjects.size()); 768 773 769 SceneObject<ModelVertex, SSBO_ModelObject>& texturedSquare = 770 addObject(modelObjects, modelPipeline, 771 addObjectIndex<ModelVertex>(modelObjects.size(), 772 addVertexNormals<ModelVertex>({ 773 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 774 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 775 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 776 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 777 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 778 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}} 779 })), 780 { 781 0, 1, 2, 3, 4, 5 782 }, objects_modelPipeline, { 783 mat4(1.0f) 784 }); 774 SceneObject<ModelVertex>& texturedSquare = addObject(modelObjects, modelPipeline, 775 addObjectIndex<ModelVertex>(modelObjects.size(), 776 addVertexNormals<ModelVertex>({ 777 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 778 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 779 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 780 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 781 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 782 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}} 783 })), 784 { 785 0, 1, 2, 3, 4, 5 786 }, objects_modelPipeline, { 787 mat4(1.0f) 788 }); 785 789 786 790 texturedSquare.model_base = … … 817 821 // START UNREVIEWED SECTION 818 822 if (e.key.keycode == SDL_SCANCODE_Z && leftLaserIdx != -1) { 819 laserObjects[leftLaserIdx].ssbo.deleted = true;823 objects_laserPipeline.get(leftLaserIdx).deleted = true; 820 824 leftLaserIdx = -1; 821 825 … … 825 829 } 826 830 } else if (e.key.keycode == SDL_SCANCODE_X && rightLaserIdx != -1) { 827 laserObjects[rightLaserIdx].ssbo.deleted = true;831 objects_laserPipeline.get(rightLaserIdx).deleted = true; 828 832 rightLaserIdx = -1; 829 833 … … 857 861 // Check which keys are held down 858 862 859 SceneObject<ModelVertex , SSBO_ModelObject>& ship = shipObjects[0];863 SceneObject<ModelVertex>& ship = shipObjects[0]; 860 864 861 865 if (gui->keyPressed(SDL_SCANCODE_LEFT)) { … … 936 940 // where it will run just once per frame 937 941 void VulkanGame::updateScene() { 938 if (curTime - this->lastSpawn_asteroid > this->spawnRate_asteroid) { 939 this->lastSpawn_asteroid = curTime; 940 941 SceneObject<ModelVertex, SSBO_Asteroid>& asteroid = 942 addObject(asteroidObjects, asteroidPipeline, 943 addObjectIndex<ModelVertex>(asteroidObjects.size(), 944 addVertexNormals<ModelVertex>({ 945 946 // front 947 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 948 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 949 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 950 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 951 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 952 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 953 954 // top 955 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 956 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 957 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 958 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 959 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 960 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 961 962 // bottom 963 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 964 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 965 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 966 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 967 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 968 {{ 1.0f, -1.0f, -1.0}, {0.4f, 0.4f, 0.4f}}, 969 970 // back 971 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 972 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 973 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 974 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 975 {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 976 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 977 978 // right 979 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 980 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 981 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 982 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 983 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 984 {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 985 986 // left 987 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 988 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 989 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 990 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 991 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 992 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 993 })), 994 { 995 0, 1, 2, 3, 4, 5, 996 6, 7, 8, 9, 10, 11, 997 12, 13, 14, 15, 16, 17, 998 18, 19, 20, 21, 22, 23, 999 24, 25, 26, 27, 28, 29, 1000 30, 31, 32, 33, 34, 35, 1001 }, objects_asteroidPipeline, { 1002 mat4(1.0f), 1003 10.0f, 1004 false 1005 }); 942 if (curTime - lastSpawn_asteroid > spawnRate_asteroid) { 943 lastSpawn_asteroid = curTime; 944 945 SceneObject<ModelVertex>& asteroid = addObject(asteroidObjects, asteroidPipeline, 946 addObjectIndex<ModelVertex>(asteroidObjects.size(), 947 addVertexNormals<ModelVertex>({ 948 949 // front 950 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 951 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 952 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 953 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 954 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 955 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 956 957 // top 958 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 959 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 960 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 961 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 962 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 963 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 964 965 // bottom 966 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 967 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 968 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 969 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 970 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 971 {{ 1.0f, -1.0f, -1.0}, {0.4f, 0.4f, 0.4f}}, 972 973 // back 974 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 975 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 976 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 977 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 978 {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 979 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 980 981 // right 982 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 983 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 984 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 985 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 986 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 987 {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 988 989 // left 990 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 991 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 992 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 993 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 994 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 995 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 996 })), 997 { 998 0, 1, 2, 3, 4, 5, 999 6, 7, 8, 9, 10, 11, 1000 12, 13, 14, 15, 16, 17, 1001 18, 19, 20, 21, 22, 23, 1002 24, 25, 26, 27, 28, 29, 1003 30, 31, 32, 33, 34, 35, 1004 }, objects_asteroidPipeline, { 1005 mat4(1.0f), 1006 10.0f, 1007 false 1008 }); 1006 1009 1007 1010 // This accounts for the scaling in model_base. … … 1033 1036 1034 1037 for (size_t i = 0; i < modelObjects.size(); i++) { 1035 SceneObject<ModelVertex , SSBO_ModelObject>& obj = modelObjects[i];1036 SSBO_ModelObject& objData = obj .ssbo;1038 SceneObject<ModelVertex>& obj = modelObjects[i]; 1039 SSBO_ModelObject& objData = objects_modelPipeline.get(i); 1037 1040 1038 1041 // Rotate the textured squares … … 1058 1061 // TODO: Move ship position updates from the ui event handling code into this function 1059 1062 for (size_t i = 0; i < shipObjects.size(); i++) { 1060 SceneObject<ModelVertex , SSBO_ModelObject>& obj = shipObjects[i];1061 SSBO_ModelObject& objData = obj .ssbo;1063 SceneObject<ModelVertex>& obj = shipObjects[i]; 1064 SSBO_ModelObject& objData = objects_shipPipeline.get(i); 1062 1065 1063 1066 objData.model = obj.model_transform * obj.model_base; … … 1077 1080 1078 1081 for (size_t i = 0; i < asteroidObjects.size(); i++) { 1079 SceneObject<ModelVertex , SSBO_Asteroid>& obj = asteroidObjects[i];1080 SSBO_Asteroid& objData = obj .ssbo;1082 SceneObject<ModelVertex>& obj = asteroidObjects[i]; 1083 SSBO_Asteroid& objData = objects_asteroidPipeline.get(i); 1081 1084 1082 1085 if (!objData.deleted) { … … 1127 1130 1128 1131 for (size_t i = 0; i < laserObjects.size(); i++) { 1129 SceneObject<LaserVertex , SSBO_Laser>& obj = laserObjects[i];1130 SSBO_Laser& objData = obj .ssbo;1132 SceneObject<LaserVertex>& obj = laserObjects[i]; 1133 SSBO_Laser& objData = objects_laserPipeline.get(i); 1131 1134 1132 1135 objData.model = obj.model_transform * obj.model_base; … … 1146 1149 1147 1150 for (size_t i = 0; i < explosionObjects.size(); i++) { 1148 SceneObject<ExplosionVertex , SSBO_Explosion>& obj = explosionObjects[i];1149 SSBO_Explosion& objData = obj .ssbo;1151 SceneObject<ExplosionVertex>& obj = explosionObjects[i]; 1152 SSBO_Explosion& objData = objects_explosionPipeline.get(i); 1150 1153 1151 1154 if (!objData.deleted) { … … 1212 1215 laserPipeline.cleanupBuffers(); 1213 1216 explosionPipeline.cleanupBuffers(); 1214 1215 for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) {1216 vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr);1217 vkFreeMemory(device, storageBuffers_modelPipeline.memory[i], nullptr);1218 }1219 1220 for (size_t i = 0; i < storageBuffers_shipPipeline.buffers.size(); i++) {1221 vkDestroyBuffer(device, storageBuffers_shipPipeline.buffers[i], nullptr);1222 vkFreeMemory(device, storageBuffers_shipPipeline.memory[i], nullptr);1223 }1224 1225 for (size_t i = 0; i < storageBuffers_asteroidPipeline.buffers.size(); i++) {1226 vkDestroyBuffer(device, storageBuffers_asteroidPipeline.buffers[i], nullptr);1227 vkFreeMemory(device, storageBuffers_asteroidPipeline.memory[i], nullptr);1228 }1229 1230 for (size_t i = 0; i < storageBuffers_laserPipeline.buffers.size(); i++) {1231 vkDestroyBuffer(device, storageBuffers_laserPipeline.buffers[i], nullptr);1232 vkFreeMemory(device, storageBuffers_laserPipeline.memory[i], nullptr);1233 }1234 1235 for (size_t i = 0; i < storageBuffers_explosionPipeline.buffers.size(); i++) {1236 vkDestroyBuffer(device, storageBuffers_explosionPipeline.buffers[i], nullptr);1237 vkFreeMemory(device, storageBuffers_explosionPipeline.memory[i], nullptr);1238 }1239 1217 1240 1218 // END UNREVIEWED SECTION … … 2004 1982 float length = glm::length(ray); 2005 1983 2006 SceneObject<LaserVertex, SSBO_Laser>& laser = addObject( 2007 laserObjects, laserPipeline, 1984 SceneObject<LaserVertex>& laser = addObject(laserObjects, laserPipeline, 2008 1985 addObjectIndex<LaserVertex>(laserObjects.size(), { 2009 1986 {{ width / 2, 0.0f, -width / 2 }, {1.0f, 0.5f }}, … … 2051 2028 2052 2029 void VulkanGame::translateLaser(size_t index, const vec3& translation) { 2053 SceneObject<LaserVertex , SSBO_Laser>& laser = this->laserObjects[index];2030 SceneObject<LaserVertex>& laser = laserObjects[index]; 2054 2031 2055 2032 // TODO: A lot of the values calculated here can be calculated once and saved when the laser is created, … … 2081 2058 2082 2059 void VulkanGame::updateLaserTarget(size_t index) { 2083 SceneObject<LaserVertex , SSBO_Laser>& laser = this->laserObjects[index];2060 SceneObject<LaserVertex>& laser = laserObjects[index]; 2084 2061 2085 2062 // TODO: A lot of the values calculated here can be calculated once and saved when the laser is created, … … 2090 2067 2091 2068 vec3 intersection(0.0f), closestIntersection(0.0f); 2092 SceneObject<ModelVertex , SSBO_Asteroid>* closestAsteroid = nullptr;2069 SceneObject<ModelVertex>* closestAsteroid = nullptr; 2093 2070 unsigned int closestAsteroidIndex = -1; 2094 2071 2095 for (int i = 0; i < this->asteroidObjects.size(); i++) {2096 if (! this->asteroidObjects[i].ssbo.deleted &&2097 this->getLaserAndAsteroidIntersection(this->asteroidObjects[i], start, end, intersection)) {2072 for (int i = 0; i < asteroidObjects.size(); i++) { 2073 if (!objects_asteroidPipeline.get(i).deleted && 2074 getLaserAndAsteroidIntersection(asteroidObjects[i], start, end, intersection)) { 2098 2075 // TODO: Implement a more generic algorithm for testing the closest object by getting the distance between the points 2099 2076 // TODO: Also check which intersection is close to the start of the laser. This would make the algorithm work … … 2119 2096 } 2120 2097 2121 EffectOverTime< ModelVertex,SSBO_Asteroid>* eot = nullptr;2098 EffectOverTime<SSBO_Asteroid>* eot = nullptr; 2122 2099 2123 2100 if (closestAsteroid != nullptr) { 2124 // TODO: Use some sort ofsmart pointer instead2125 eot = new EffectOverTime <ModelVertex, SSBO_Asteroid>(asteroidPipeline, asteroidObjects, closestAsteroidIndex,2126 offset_of(&SSBO_Asteroid::hp),curTime, -20.0f);2101 // TODO: Figure out if I should use a smart pointer instead 2102 eot = new EffectOverTime(objects_asteroidPipeline, closestAsteroidIndex, offset_of(&SSBO_Asteroid::hp), 2103 curTime, -20.0f); 2127 2104 effects.push_back(eot); 2128 2105 } … … 2146 2123 2147 2124 // TODO: Consider if I want to set a flag and do this update in updateScene() instead 2148 updateObjectVertices( this->laserPipeline, laser, index);2125 updateObjectVertices(laserPipeline, laser, index); 2149 2126 } 2150 2127 2151 2128 // TODO: Determine if I should pass start and end by reference or value since they don't get changed 2152 2129 // Probably use const reference 2153 bool VulkanGame::getLaserAndAsteroidIntersection(SceneObject<ModelVertex , SSBO_Asteroid>& asteroid,2154 vec3& start, vec3& end,vec3& intersection) {2130 bool VulkanGame::getLaserAndAsteroidIntersection(SceneObject<ModelVertex>& asteroid, vec3& start, vec3& end, 2131 vec3& intersection) { 2155 2132 /* 2156 2133 ### LINE EQUATIONS ### … … 2221 2198 iota(indices.begin(), indices.end(), 0); 2222 2199 2223 SceneObject<ExplosionVertex , SSBO_Explosion>& explosion = addObject(explosionObjects, explosionPipeline,2200 SceneObject<ExplosionVertex>& explosion = addObject(explosionObjects, explosionPipeline, 2224 2201 addObjectIndex(explosionObjects.size(), vertices), indices, objects_explosionPipeline, { 2225 2202 mat4(1.0f), … … 2254 2231 createSyncObjects(); 2255 2232 2256 // TODO: Move UBO creation/management into GraphicsPipeline_Vulkan, like I did with SSBOs2257 // TODO: Check if the shader stages and maybe some other properties of the pipeline can be re-used2258 // instead of recreated every time2259 2260 2233 createBufferSet(sizeof(UBO_VP_mats), 2261 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2262 uniformBuffers_modelPipeline); 2234 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2235 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2236 uniformBuffers_modelPipeline); 2237 2238 createBufferSet(objects_modelPipeline.memorySize(), 2239 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 2240 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 2241 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2242 storageBuffers_modelPipeline); 2263 2243 2264 2244 modelPipeline.updateRenderPass(renderPass); … … 2268 2248 2269 2249 createBufferSet(sizeof(UBO_VP_mats), 2270 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2271 uniformBuffers_shipPipeline); 2250 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2251 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2252 uniformBuffers_shipPipeline); 2253 2254 createBufferSet(objects_shipPipeline.memorySize(), 2255 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 2256 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 2257 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2258 storageBuffers_shipPipeline); 2272 2259 2273 2260 shipPipeline.updateRenderPass(renderPass); … … 2277 2264 2278 2265 createBufferSet(sizeof(UBO_VP_mats), 2279 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2280 uniformBuffers_asteroidPipeline); 2266 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2267 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2268 uniformBuffers_asteroidPipeline); 2269 2270 createBufferSet(objects_asteroidPipeline.memorySize(), 2271 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 2272 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 2273 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2274 storageBuffers_asteroidPipeline); 2281 2275 2282 2276 asteroidPipeline.updateRenderPass(renderPass); … … 2286 2280 2287 2281 createBufferSet(sizeof(UBO_VP_mats), 2288 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2289 uniformBuffers_laserPipeline); 2282 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2283 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2284 uniformBuffers_laserPipeline); 2285 2286 createBufferSet(objects_laserPipeline.memorySize(), 2287 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 2288 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 2289 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2290 storageBuffers_laserPipeline); 2290 2291 2291 2292 laserPipeline.updateRenderPass(renderPass); … … 2295 2296 2296 2297 createBufferSet(sizeof(UBO_Explosion), 2297 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2298 uniformBuffers_explosionPipeline); 2298 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2299 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2300 uniformBuffers_explosionPipeline); 2301 2302 createBufferSet(objects_explosionPipeline.memorySize(), 2303 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 2304 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 2305 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2306 storageBuffers_explosionPipeline); 2299 2307 2300 2308 explosionPipeline.updateRenderPass(renderPass); … … 2329 2337 } 2330 2338 2339 for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) { 2340 vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr); 2341 vkFreeMemory(device, storageBuffers_modelPipeline.memory[i], nullptr); 2342 } 2343 2331 2344 for (size_t i = 0; i < uniformBuffers_shipPipeline.buffers.size(); i++) { 2332 2345 vkDestroyBuffer(device, uniformBuffers_shipPipeline.buffers[i], nullptr); … … 2334 2347 } 2335 2348 2349 for (size_t i = 0; i < storageBuffers_shipPipeline.buffers.size(); i++) { 2350 vkDestroyBuffer(device, storageBuffers_shipPipeline.buffers[i], nullptr); 2351 vkFreeMemory(device, storageBuffers_shipPipeline.memory[i], nullptr); 2352 } 2353 2336 2354 for (size_t i = 0; i < uniformBuffers_asteroidPipeline.buffers.size(); i++) { 2337 2355 vkDestroyBuffer(device, uniformBuffers_asteroidPipeline.buffers[i], nullptr); … … 2339 2357 } 2340 2358 2359 for (size_t i = 0; i < storageBuffers_asteroidPipeline.buffers.size(); i++) { 2360 vkDestroyBuffer(device, storageBuffers_asteroidPipeline.buffers[i], nullptr); 2361 vkFreeMemory(device, storageBuffers_asteroidPipeline.memory[i], nullptr); 2362 } 2363 2341 2364 for (size_t i = 0; i < uniformBuffers_laserPipeline.buffers.size(); i++) { 2342 2365 vkDestroyBuffer(device, uniformBuffers_laserPipeline.buffers[i], nullptr); … … 2344 2367 } 2345 2368 2369 for (size_t i = 0; i < storageBuffers_laserPipeline.buffers.size(); i++) { 2370 vkDestroyBuffer(device, storageBuffers_laserPipeline.buffers[i], nullptr); 2371 vkFreeMemory(device, storageBuffers_laserPipeline.memory[i], nullptr); 2372 } 2373 2346 2374 for (size_t i = 0; i < uniformBuffers_explosionPipeline.buffers.size(); i++) { 2347 2375 vkDestroyBuffer(device, uniformBuffers_explosionPipeline.buffers[i], nullptr); 2348 2376 vkFreeMemory(device, uniformBuffers_explosionPipeline.memory[i], nullptr); 2377 } 2378 2379 for (size_t i = 0; i < storageBuffers_explosionPipeline.buffers.size(); i++) { 2380 vkDestroyBuffer(device, storageBuffers_explosionPipeline.buffers[i], nullptr); 2381 vkFreeMemory(device, storageBuffers_explosionPipeline.memory[i], nullptr); 2349 2382 } 2350 2383
Note:
See TracChangeset
for help on using the changeset viewer.