Changeset 4994692 in opengl-game for vulkan-game.cpp
- Timestamp:
- Apr 19, 2020, 1:23:02 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 5ba732a
- Parents:
- 6385d0f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r6385d0f r4994692 12 12 using namespace std; 13 13 14 // TODO: Update all occurances of instance variables to use this-> 15 14 16 VulkanGame::VulkanGame(int maxFramesInFlight) : MAX_FRAMES_IN_FLIGHT(maxFramesInFlight) { 15 gui = nullptr;16 window = nullptr;17 font = nullptr;18 fontSDLTexture = nullptr;19 imageSDLTexture = nullptr;20 21 currentFrame = 0;22 framebufferResized = false;23 24 object_VP_mats = {};25 ship_VP_mats = {};26 asteroid_VP_mats = {};17 this->gui = nullptr; 18 this->window = nullptr; 19 this->font = nullptr; 20 this->fontSDLTexture = nullptr; 21 this->imageSDLTexture = nullptr; 22 23 this->currentFrame = 0; 24 this->framebufferResized = false; 25 26 this->object_VP_mats = {}; 27 this->ship_VP_mats = {}; 28 this->asteroid_VP_mats = {}; 27 29 } 28 30 … … 226 228 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 227 229 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline); 228 modelPipeline.addStorageDescriptor(); 229 230 modelPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT); 230 231 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 231 232 VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor); 232 233 233 addObject(modelObjects, modelPipeline, 234 SceneObject<ModelVertex, SSBO_ModelObject>* texturedSquare = nullptr; 235 236 texturedSquare = &addObject(modelObjects, modelPipeline, 234 237 addObjectIndex<ModelVertex>(modelObjects.size(), { 235 238 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, … … 243 246 }, false); 244 247 245 modelObjects.back().model_base =248 texturedSquare->model_base = 246 249 translate(mat4(1.0f), vec3(0.0f, 0.0f, -2.0f)); 247 248 250 updateObject(modelObjects, modelPipeline, modelObjects.size() - 1); 249 251 250 addObject(modelObjects, modelPipeline,252 texturedSquare = &addObject(modelObjects, modelPipeline, 251 253 addObjectIndex<ModelVertex>(modelObjects.size(), { 252 254 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, … … 260 262 }, false); 261 263 262 modelObjects.back().model_base =264 texturedSquare->model_base = 263 265 translate(mat4(1.0f), vec3(0.0f, 0.0f, -1.5f)); 264 265 266 updateObject(modelObjects, modelPipeline, modelObjects.size() - 1); 266 267 … … 280 281 shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 281 282 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline); 282 shipPipeline.addStorageDescriptor( );283 shipPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT); 283 284 284 285 // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly 285 286 // the same data. Add an option to make some pipelines not use indexing 286 addObject(shipObjects, shipPipeline,287 SceneObject<ShipVertex, SSBO_ModelObject>& ship = addObject(shipObjects, shipPipeline, 287 288 addObjectIndex<ShipVertex>(shipObjects.size(), 288 289 addVertexNormals<ShipVertex>({ … … 532 533 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 533 534 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline); 534 asteroidPipeline.addStorageDescriptor( );535 asteroidPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT); 535 536 536 537 asteroidPipeline.createDescriptorSetLayout(); … … 545 546 createSyncObjects(); 546 547 547 ship Objects[0].model_base =548 ship.model_base = 548 549 translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)) * 549 550 scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 550 551 551 updateObject(shipObjects, shipPipeline, 0); 552 552 } … … 568 568 // TODO: Maybe changes the name to initScene() or something similar 569 569 void VulkanGame::initMatrices() { 570 cam_pos = vec3(0.0f, 0.0f, 2.0f);570 this->cam_pos = vec3(0.0f, 0.0f, 2.0f); 571 571 572 572 float cam_yaw = 0.0f; … … 577 577 578 578 mat4 R_view = pitch_mat * yaw_mat; 579 mat4 T_view = translate(mat4(1.0f), vec3(- cam_pos.x, -cam_pos.y, -cam_pos.z));579 mat4 T_view = translate(mat4(1.0f), vec3(-this->cam_pos.x, -this->cam_pos.y, -this->cam_pos.z)); 580 580 viewMat = R_view * T_view; 581 581 … … 625 625 break; 626 626 case UI_EVENT_KEYDOWN: 627 if (e.key.repeat) { 628 break; 629 } 630 627 631 if (e.key.keycode == SDL_SCANCODE_ESCAPE) { 628 632 quit = true; … … 631 635 float zOffset = -2.0f + (0.5f * modelObjects.size()); 632 636 633 addObject(modelObjects, modelPipeline, 634 addObjectIndex<ModelVertex>(modelObjects.size(), { 635 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 636 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 637 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 638 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}} 639 }), { 640 0, 1, 2, 2, 3, 0 641 }, { 642 mat4(1.0f) 643 }, true); 644 645 modelObjects.back().model_base = 637 SceneObject<ModelVertex, SSBO_ModelObject>& texturedSquare = 638 addObject(modelObjects, modelPipeline, 639 addObjectIndex<ModelVertex>(modelObjects.size(), { 640 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 641 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 642 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 643 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}} 644 }), { 645 0, 1, 2, 2, 3, 0 646 }, { 647 mat4(1.0f) 648 }, true); 649 650 texturedSquare.model_base = 646 651 translate(mat4(1.0f), vec3(0.0f, 0.0f, zOffset)); 647 648 652 updateObject(modelObjects, modelPipeline, modelObjects.size() - 1); 649 653 } else { … … 671 675 // Check which keys are held down 672 676 677 SceneObject<ShipVertex, SSBO_ModelObject>& ship = shipObjects[0]; 678 673 679 if (gui->keyPressed(SDL_SCANCODE_LEFT)) { 674 shipObjects[0].model_transform = translate(mat4(1.0f), vec3(-this->shipSpeed * this->elapsedTime, 0.0f, 0.0f)) 680 float distance = -this->shipSpeed * this->elapsedTime; 681 682 ship.model_transform = translate(mat4(1.0f), vec3(distance, 0.0f, 0.0f)) 675 683 * shipObjects[0].model_transform; 676 684 677 685 updateObject(shipObjects, shipPipeline, 0); 678 686 } else if (gui->keyPressed(SDL_SCANCODE_RIGHT)) { 679 shipObjects[0].model_transform = translate(mat4(1.0f), vec3(this->shipSpeed * this->elapsedTime, 0.0f, 0.0f)) 687 float distance = this->shipSpeed * this->elapsedTime; 688 689 ship.model_transform = translate(mat4(1.0f), vec3(distance, 0.0f, 0.0f)) 680 690 * shipObjects[0].model_transform; 681 691 … … 721 731 this->lastSpawn_asteroid = this->curTime; 722 732 723 addObject(asteroidObjects, asteroidPipeline, 733 SceneObject<AsteroidVertex, SSBO_Asteroid>& asteroid = addObject( 734 asteroidObjects, asteroidPipeline, 724 735 addObjectIndex<AsteroidVertex>(asteroidObjects.size(), 725 736 addVertexNormals<AsteroidVertex>({ … … 782 793 mat4(1.0f), 783 794 10.0f, 784 0795 false 785 796 }, true); 786 797 … … 790 801 // TODO: Figure out the best way to take scaling into account when calculating the radius 791 802 // Keep in mind that the main complicating factor is the currently poor radius calculation 792 asteroid Objects.back().radius /= 8.0f;793 794 asteroid Objects.back().model_base =803 asteroid.radius /= 8.0f; 804 805 asteroid.model_base = 795 806 translate(mat4(1.0f), vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f))) * 796 807 rotate(mat4(1.0f), radians(60.0f), vec3(1.0f, 1.0f, -1.0f)) * … … 900 911 cleanupSwapChain(); 901 912 913 VulkanUtils::destroyVulkanImage(device, sdlOverlayImage); 902 914 VulkanUtils::destroyVulkanImage(device, floorTextureImage); 903 VulkanUtils::destroyVulkanImage(device, sdlOverlayImage);904 915 905 916 vkDestroySampler(device, textureSampler, nullptr); … … 1282 1293 createTextureSampler(); 1283 1294 1295 // TODO: Move all images/textures somewhere into the assets folder 1296 1297 VulkanUtils::createVulkanImageFromSDLTexture(device, physicalDevice, uiOverlay, sdlOverlayImage); 1298 1299 sdlOverlayImageDescriptor = {}; 1300 sdlOverlayImageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; 1301 sdlOverlayImageDescriptor.imageView = sdlOverlayImage.imageView; 1302 sdlOverlayImageDescriptor.sampler = textureSampler; 1303 1284 1304 VulkanUtils::createVulkanImageFromFile(device, physicalDevice, commandPool, "textures/texture.jpg", 1285 1305 floorTextureImage, graphicsQueue); … … 1289 1309 floorTextureImageDescriptor.imageView = floorTextureImage.imageView; 1290 1310 floorTextureImageDescriptor.sampler = textureSampler; 1291 1292 VulkanUtils::createVulkanImageFromSDLTexture(device, physicalDevice, uiOverlay, sdlOverlayImage);1293 1294 sdlOverlayImageDescriptor = {};1295 sdlOverlayImageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;1296 sdlOverlayImageDescriptor.imageView = sdlOverlayImage.imageView;1297 sdlOverlayImageDescriptor.sampler = textureSampler;1298 1311 } 1299 1312
Note:
See TracChangeset
for help on using the changeset viewer.