Changeset 3e8cc8b in opengl-game
- Timestamp:
- Jan 16, 2020, 4:20:37 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 4ece3bf
- Parents:
- 0fe8433
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r0fe8433 r3e8cc8b 25 25 object_VP_mats = {}; 26 26 ship_VP_mats = {}; 27 asteroid_VP_mats = {}; 27 28 } 28 29 … … 196 197 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 197 198 uniformBuffers_scenePipeline, uniformBuffersMemory_scenePipeline, uniformBufferInfoList_scenePipeline); 199 // TODO: Calculate the size of this buffer (and all the other SSBOs) based on the number of objects 198 200 createBufferSet(10 * sizeof(SBO_SceneObject), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 199 201 storageBuffers_scenePipeline, storageBuffersMemory_scenePipeline, storageBufferInfoList_scenePipeline); … … 274 276 addObjectIndex<ShipVertex>(shipObjects.size(), 275 277 addVertexNormals<ShipVertex>({ 278 276 279 //back 277 280 {{ -0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, … … 506 509 shipPipeline.createDescriptorSets(swapChainImages); 507 510 511 asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::pos)); 512 asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::color)); 513 asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::normal)); 514 asteroidPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&AsteroidVertex::objIndex)); 515 516 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 517 uniformBuffers_asteroidPipeline, uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline); 518 createBufferSet(10 * sizeof(SBO_Asteroid), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 519 storageBuffers_asteroidPipeline, storageBuffersMemory_asteroidPipeline, storageBufferInfoList_asteroidPipeline); 520 521 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 522 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline); 523 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 524 VK_SHADER_STAGE_VERTEX_BIT, &storageBufferInfoList_asteroidPipeline); 525 526 addObject(asteroidObjects, asteroidPipeline, 527 centerObject<AsteroidVertex>( 528 addObjectIndex<AsteroidVertex>(asteroidObjects.size(), 529 addVertexNormals<AsteroidVertex>({ 530 531 // front 532 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 533 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 534 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 535 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 536 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 537 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 538 539 // top 540 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 541 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 542 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 543 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 544 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 545 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 546 547 // bottom 548 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 549 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 550 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 551 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 552 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 553 {{ 1.0f, -1.0f, -1.0}, {0.4f, 0.4f, 0.4f}}, 554 555 // back 556 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 557 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 558 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 559 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 560 {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 561 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 562 563 // right 564 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 565 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 566 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 567 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 568 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 569 {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 570 571 // left 572 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 573 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 574 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 575 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 576 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 577 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 578 }))), { 579 0, 1, 2, 3, 4, 5, 580 6, 7, 8, 9, 10, 11, 581 12, 13, 14, 15, 16, 17, 582 18, 19, 20, 21, 22, 23, 583 24, 25, 26, 27, 28, 29, 584 30, 31, 32, 33, 34, 35, 585 }); 586 587 asteroidPipeline.createDescriptorSetLayout(); 588 asteroidPipeline.createPipeline("shaders/asteroid-vert.spv", "shaders/asteroid-frag.spv"); 589 asteroidPipeline.createDescriptorPool(swapChainImages); 590 asteroidPipeline.createDescriptorSets(swapChainImages); 591 508 592 cout << "Created all the graphics pipelines" << endl; 509 593 … … 515 599 translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)) * 516 600 scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 601 602 //vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f)); 603 vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, -2.0f); 604 605 asteroidObjects[0].model_base = 606 translate(mat4(1.0f), pos) * 607 rotate(mat4(1.0f), radians(60.0f), vec3(1.0f, 1.0f, -1.0f)) * 608 scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 609 asteroidObjects[0].model_transform = mat4(1.0); // Might not be needed 517 610 } 518 611 … … 526 619 shipPipeline = GraphicsPipeline_Vulkan<ShipVertex>(physicalDevice, device, renderPass, 527 620 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 138, 138); 621 622 asteroidPipeline = GraphicsPipeline_Vulkan<AsteroidVertex>(physicalDevice, device, renderPass, 623 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 24, 36); 528 624 } 529 625 … … 550 646 ship_VP_mats.view = view; 551 647 ship_VP_mats.proj = proj; 648 649 asteroid_VP_mats.view = view; 650 asteroid_VP_mats.proj = proj; 552 651 } 553 652 … … 624 723 } 625 724 725 // this code moves the asteroids 726 transformObject(asteroidObjects[0], translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.04f))); 727 626 728 renderUI(); 627 729 renderScene(); … … 647 749 so_Ship.model = shipObjects[0].model_transform * shipObjects[0].model_base; 648 750 751 so_Asteroid.model = asteroidObjects[0].model_transform * asteroidObjects[0].model_base; 752 so_Asteroid.hp = 10.0; 753 649 754 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_scenePipeline[currentImage], object_VP_mats); 650 755 … … 654 759 655 760 VulkanUtils::copyDataToMemory(device, storageBuffersMemory_shipPipeline[currentImage], so_Ship); 761 762 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_asteroidPipeline[currentImage], asteroid_VP_mats); 763 764 VulkanUtils::copyDataToMemory(device, storageBuffersMemory_asteroidPipeline[currentImage], so_Asteroid); 656 765 } 657 766 … … 757 866 overlayPipeline.cleanupBuffers(); 758 867 shipPipeline.cleanupBuffers(); 868 asteroidPipeline.cleanupBuffers(); 759 869 760 870 for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { … … 1237 1347 modelPipeline.createRenderCommands(commandBuffers[i], i); 1238 1348 shipPipeline.createRenderCommands(commandBuffers[i], i); 1349 asteroidPipeline.createRenderCommands(commandBuffers[i], i); 1239 1350 1240 1351 // Always render this pipeline last … … 1335 1446 shipPipeline.createDescriptorSets(swapChainImages); 1336 1447 1448 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 1449 uniformBuffers_asteroidPipeline, uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline); 1450 createBufferSet(10 * sizeof(SBO_Asteroid), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 1451 storageBuffers_asteroidPipeline, storageBuffersMemory_asteroidPipeline, storageBufferInfoList_asteroidPipeline); 1452 1453 asteroidPipeline.updateRenderPass(renderPass); 1454 asteroidPipeline.createPipeline("shaders/asteroid-vert.spv", "shaders/asteroid-frag.spv"); 1455 asteroidPipeline.createDescriptorPool(swapChainImages); 1456 asteroidPipeline.createDescriptorSets(swapChainImages); 1457 1337 1458 createCommandBuffers(); 1338 1459 } … … 1350 1471 overlayPipeline.cleanup(); 1351 1472 shipPipeline.cleanup(); 1473 asteroidPipeline.cleanup(); 1352 1474 1353 1475 vkDestroyRenderPass(device, renderPass, nullptr); … … 1378 1500 vkFreeMemory(device, storageBuffersMemory_shipPipeline[i], nullptr); 1379 1501 } 1380 } 1502 1503 for (size_t i = 0; i < uniformBuffers_asteroidPipeline.size(); i++) { 1504 vkDestroyBuffer(device, uniformBuffers_asteroidPipeline[i], nullptr); 1505 vkFreeMemory(device, uniformBuffersMemory_asteroidPipeline[i], nullptr); 1506 } 1507 1508 for (size_t i = 0; i < storageBuffers_asteroidPipeline.size(); i++) { 1509 vkDestroyBuffer(device, storageBuffers_asteroidPipeline[i], nullptr); 1510 vkFreeMemory(device, storageBuffersMemory_asteroidPipeline[i], nullptr); 1511 } 1512 } -
vulkan-game.hpp
r0fe8433 r3e8cc8b 40 40 }; 41 41 42 struct AsteroidVertex { 43 vec3 pos; 44 vec3 color; 45 vec3 normal; 46 unsigned int objIndex; 47 }; 48 42 49 // TODO: Change the index type to uint32_t and check the Vulkan Tutorial loading model section as a reference 43 50 // TODO: Create a typedef for index type so I can easily change uin16_t to something else later … … 58 65 struct SBO_SceneObject { 59 66 alignas(16) mat4 model; 67 }; 68 69 struct SBO_Asteroid { 70 alignas(16) mat4 model; 71 alignas(4) float hp; 60 72 }; 61 73 … … 130 142 // variables to better reflect the data they hold 131 143 144 // TODO: Create a struct that holds the buffers, memory, and info objects (Probably in VulkanUtils) 145 132 146 GraphicsPipeline_Vulkan<OverlayVertex> overlayPipeline; 133 147 … … 142 156 vector<VkBuffer> uniformBuffers_scenePipeline; 143 157 vector<VkDeviceMemory> uniformBuffersMemory_scenePipeline; 144 145 158 vector<VkDescriptorBufferInfo> uniformBufferInfoList_scenePipeline; 146 159 147 160 vector<VkBuffer> storageBuffers_scenePipeline; 148 161 vector<VkDeviceMemory> storageBuffersMemory_scenePipeline; 149 150 162 vector<VkDescriptorBufferInfo> storageBufferInfoList_scenePipeline; 151 163 … … 159 171 vector<VkBuffer> uniformBuffers_shipPipeline; 160 172 vector<VkDeviceMemory> uniformBuffersMemory_shipPipeline; 161 162 173 vector<VkDescriptorBufferInfo> uniformBufferInfoList_shipPipeline; 163 174 164 175 vector<VkBuffer> storageBuffers_shipPipeline; 165 176 vector<VkDeviceMemory> storageBuffersMemory_shipPipeline; 166 167 177 vector<VkDescriptorBufferInfo> storageBufferInfoList_shipPipeline; 168 178 169 179 UBO_VP_mats ship_VP_mats; 170 180 SBO_SceneObject so_Ship; 181 182 GraphicsPipeline_Vulkan<AsteroidVertex> asteroidPipeline; 183 184 vector<SceneObject<AsteroidVertex>> asteroidObjects; 185 186 vector<VkBuffer> uniformBuffers_asteroidPipeline; 187 vector<VkDeviceMemory> uniformBuffersMemory_asteroidPipeline; 188 vector<VkDescriptorBufferInfo> uniformBufferInfoList_asteroidPipeline; 189 190 vector<VkBuffer> storageBuffers_asteroidPipeline; 191 vector<VkDeviceMemory> storageBuffersMemory_asteroidPipeline; 192 vector<VkDescriptorBufferInfo> storageBufferInfoList_asteroidPipeline; 193 194 UBO_VP_mats asteroid_VP_mats; 195 SBO_Asteroid so_Asteroid; 171 196 172 197 bool initWindow(int width, int height, unsigned char guiFlags);
Note:
See TracChangeset
for help on using the changeset viewer.