Changeset cefdf23 in opengl-game


Ignore:
Timestamp:
Apr 5, 2021, 1:09:02 AM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
e469aed
Parents:
aa7e5f0
git-author:
Dmitry Portnoy <dportnoy@…> (04/05/21 01:07:42)
git-committer:
Dmitry Portnoy <dportnoy@…> (04/05/21 01:09:02)
Message:

Rename createImguiDescriptorPool and createImguiDescriptorPool to
initImGuiOverlay and cleanupImGuiOverlay respectively and move all
ImGui-related init and cleanup code into them

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    raa7e5f0 rcefdf23  
    5252VulkanGame::VulkanGame()
    5353                     : swapChainImageCount(0)
    54                       , swapChainMinImageCount(0)
     54                     , swapChainMinImageCount(0)
    5555                     , swapChainSurfaceFormat({})
    5656                     , swapChainPresentMode(VK_PRESENT_MODE_MAX_ENUM_KHR)
     
    7070                     , shouldRecreateSwapChain(false)
    7171                     , frameCount(0)
    72                      , currentFrame()
     72                     , currentFrame(0)
    7373                     , imageIndex(0)
    7474                     , fpsStartTime(0.0f)
     
    9191
    9292void VulkanGame::run(int width, int height, unsigned char guiFlags) {
    93    // TODO: Maybe call the init code in the constructor instead of in run()
    94    // Research this
    9593   seedRandomNums();
    9694
     
    9997   cout << "Vulkan Game" << endl;
    10098
    101    // TODO: Move IMGUI initialization in here
    10299   if (initUI(width, height, guiFlags) == RTWO_ERROR) {
    103100      return;
     
    106103   initVulkan();
    107104
     105   initImGuiOverlay();
     106
     107   // TODO: Figure out how much of ubo creation and associated variables should be in the pipeline class
     108   // Maybe combine the ubo-related objects into a new class
     109
     110   initGraphicsPipelines();
     111
     112   initMatrices();
     113
     114   cout << "INITIALIZING OBJECTS" << endl;
     115
     116   modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::pos));
     117   modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::color));
     118   modelPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&ModelVertex::texCoord));
     119   modelPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex));
     120
     121   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     122      uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline);
     123
     124   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     125      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline);
     126   modelPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
     127   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
     128      VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor);
     129
     130   SceneObject<ModelVertex, SSBO_ModelObject>* texturedSquare = nullptr;
     131
     132   texturedSquare = &addObject(modelObjects, modelPipeline,
     133      addObjectIndex<ModelVertex>(modelObjects.size(), {
     134         {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
     135         {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
     136         {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
     137         {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}
     138         }), {
     139            0, 1, 2, 2, 3, 0
     140      }, {
     141         mat4(1.0f)
     142      }, false);
     143
     144   texturedSquare->model_base =
     145      translate(mat4(1.0f), vec3(0.0f, 0.0f, -2.0f));
     146   texturedSquare->modified = true;
     147
     148   texturedSquare = &addObject(modelObjects, modelPipeline,
     149      addObjectIndex<ModelVertex>(modelObjects.size(), {
     150         {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
     151         {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
     152         {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
     153         {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}
     154         }), {
     155            0, 1, 2, 2, 3, 0
     156      }, {
     157         mat4(1.0f)
     158      }, false);
     159
     160   texturedSquare->model_base =
     161      translate(mat4(1.0f), vec3(0.0f, 0.0f, -1.5f));
     162   texturedSquare->modified = true;
     163
     164   modelPipeline.createDescriptorSetLayout();
     165   modelPipeline.createPipeline("shaders/model-vert.spv", "shaders/model-frag.spv");
     166   modelPipeline.createDescriptorPool(swapChainImages);
     167   modelPipeline.createDescriptorSets(swapChainImages);
     168
     169   shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::pos));
     170   shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::color));
     171   shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::normal));
     172   shipPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ShipVertex::objIndex));
     173
     174   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     175      uniformBuffers_shipPipeline, uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline);
     176
     177   shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     178      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline);
     179   shipPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
     180
     181   // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly
     182   // the same data. Add an option to make some pipelines not use indexing
     183   SceneObject<ShipVertex, SSBO_ModelObject>& ship = addObject(shipObjects, shipPipeline,
     184      addObjectIndex<ShipVertex>(shipObjects.size(),
     185         addVertexNormals<ShipVertex>({
     186
     187            //back
     188            {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     189            {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     190            {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     191            {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     192            {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     193            {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     194
     195            // left back
     196            {{ -0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     197            {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     198            {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     199            {{ -0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     200            {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     201            {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     202
     203            // right back
     204            {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     205            {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     206            {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     207            {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     208            {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     209            {{  0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     210
     211            // left mid
     212            {{-0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
     213            {{-0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
     214            {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     215            {{-0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
     216            {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     217            {{ -0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     218
     219            // right mid
     220            {{  0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     221            {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     222            {{ 0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
     223            {{  0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
     224            {{ 0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
     225            {{ 0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
     226
     227            // left front
     228            {{  0.0f,   0.0f,  -3.5f}, {0.0f, 0.0f, 1.0f}},
     229            {{-0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
     230            {{-0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
     231
     232            // right front
     233            {{ 0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
     234            {{ 0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
     235            {{  0.0f,   0.0f,  -3.5f}, {0.0f, 0.0f, 1.0f}},
     236
     237            // top back
     238            {{ -0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
     239            {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 1.0f}},
     240            {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 1.0f}},
     241            {{ -0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
     242            {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 1.0f}},
     243            {{  0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
     244
     245            // bottom back
     246            {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 1.0f}},
     247            {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
     248            {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 1.0f}},
     249            {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 1.0f}},
     250            {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
     251            {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
     252
     253            // top mid
     254            {{-0.25f,   0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}},
     255            {{ -0.5f,   0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}},
     256            {{  0.5f,   0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}},
     257            {{ -0.25f,  0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}},
     258            {{  0.5f,   0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}},
     259            {{ 0.25f,   0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}},
     260
     261            // bottom mid
     262            {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
     263            {{-0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
     264            {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
     265            {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
     266            {{-0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
     267            {{ 0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
     268
     269            // top front
     270            {{-0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
     271            {{ 0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
     272            {{  0.0f,   0.0f,  -3.5f}, {0.0f, 0.0f, 0.3f}},
     273
     274            // bottom front
     275            {{ 0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
     276            {{-0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
     277            {{  0.0f,   0.0f,  -3.5f}, {0.0f, 0.0f, 0.3f}},
     278
     279            // left wing start back
     280            {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     281            {{ -1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     282            {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     283            {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     284            {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     285            {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     286
     287            // left wing start top
     288            {{ -0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     289            {{ -1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     290            {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     291            {{ -0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     292            {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     293            {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     294
     295            // left wing start front
     296            {{ -0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     297            {{ -0.5f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     298            {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     299            {{ -0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     300            {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     301            {{ -1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     302
     303            // left wing start bottom
     304            {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     305            {{ -1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     306            {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     307            {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     308            {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     309            {{ -0.5f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     310
     311            // left wing end outside
     312            {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     313            {{ -2.2f,   0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}},
     314            {{ -1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     315
     316            // left wing end top
     317            {{ -1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     318            {{ -2.2f,   0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}},
     319            {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     320
     321            // left wing end front
     322            {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     323            {{ -2.2f,  0.15f,  -0.8f}, {0.0f, 0.0f, 0.3f}},
     324            {{ -1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     325
     326            // left wing end bottom
     327            {{ -1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     328            {{ -2.2f,  0.15f,  -0.8f}, {0.0f, 0.0f, 0.3f}},
     329            {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     330
     331            // right wing start back
     332            {{  1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     333            {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     334            {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     335            {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     336            {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     337            {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     338
     339            // right wing start top
     340            {{  1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     341            {{  0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     342            {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     343            {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     344            {{  0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     345            {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     346
     347            // right wing start front
     348            {{  0.5f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     349            {{  0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     350            {{  1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     351            {{  1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     352            {{  0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     353            {{  1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     354
     355            // right wing start bottom
     356            {{  1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     357            {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     358            {{ 1.3f,    0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     359            {{ 1.3f,    0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     360            {{ 0.5f,    0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     361            {{ 0.5f,    0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     362
     363            // right wing end outside
     364            {{  2.2f,   0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}},
     365            {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     366            {{  1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     367
     368            // right wing end top
     369            {{  2.2f,  0.15f,  -0.8f}, {0.0f, 0.0f, 0.3f}},
     370            {{  1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     371            {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     372
     373            // right wing end front
     374            {{  2.2f,   0.15f,  -0.8f}, {0.0f, 0.0f, 0.3f}},
     375            {{  1.3f,   0.0f,   -0.3f}, {0.0f, 0.0f, 0.3f}},
     376            {{  1.3f,   0.3f,   -0.3f}, {0.0f, 0.0f, 0.3f}},
     377
     378            // right wing end bottom
     379            {{  2.2f,  0.15f,  -0.8f}, {0.0f, 0.0f, 0.3f}},
     380            {{  1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
     381            {{  1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
     382         })), {
     383              0,   1,   2,   3,   4,   5,
     384              6,   7,   8,   9,  10,  11,
     385             12,  13,  14,  15,  16,  17,
     386             18,  19,  20,  21,  22,  23,
     387             24,  25,  26,  27,  28,  29,
     388             30,  31,  32,
     389             33,  34,  35,
     390             36,  37,  38,  39,  40,  41,
     391             42,  43,  44,  45,  46,  47,
     392             48,  49,  50,  51,  52,  53,
     393             54,  55,  56,  57,  58,  59,
     394             60,  61,  62,
     395             63,  64,  65,
     396             66,  67,  68,  69,  70,  71,
     397             72,  73,  74,  75,  76,  77,
     398             78,  79,  80,  81,  82,  83,
     399             84,  85,  86,  87,  88,  89,
     400             90,  91,  92,
     401             93,  94,  95,
     402             96,  97,  98,
     403             99, 100, 101,
     404            102, 103, 104, 105, 106, 107,
     405            108, 109, 110, 111, 112, 113,
     406            114, 115, 116, 117, 118, 119,
     407            120, 121, 122, 123, 124, 125,
     408            126, 127, 128,
     409            129, 130, 131,
     410            132, 133, 134,
     411            135, 136, 137,
     412      }, {
     413         mat4(1.0f)
     414      }, false);
     415
     416   ship.model_base =
     417      translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)) *
     418      scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
     419   ship.modified = true;
     420
     421   shipPipeline.createDescriptorSetLayout();
     422   shipPipeline.createPipeline("shaders/ship-vert.spv", "shaders/ship-frag.spv");
     423   shipPipeline.createDescriptorPool(swapChainImages);
     424   shipPipeline.createDescriptorSets(swapChainImages);
     425
     426   asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::pos));
     427   asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::color));
     428   asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::normal));
     429   asteroidPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&AsteroidVertex::objIndex));
     430
     431   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     432      uniformBuffers_asteroidPipeline, uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline);
     433
     434   asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     435      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline);
     436   asteroidPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
     437
     438   asteroidPipeline.createDescriptorSetLayout();
     439   asteroidPipeline.createPipeline("shaders/asteroid-vert.spv", "shaders/asteroid-frag.spv");
     440   asteroidPipeline.createDescriptorPool(swapChainImages);
     441   asteroidPipeline.createDescriptorSets(swapChainImages);
     442
     443   laserPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&LaserVertex::pos));
     444   laserPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&LaserVertex::texCoord));
     445   laserPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&LaserVertex::objIndex));
     446
     447   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     448      uniformBuffers_laserPipeline, uniformBuffersMemory_laserPipeline, uniformBufferInfoList_laserPipeline);
     449
     450   laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     451      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_laserPipeline);
     452   laserPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT);
     453   laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
     454      VK_SHADER_STAGE_FRAGMENT_BIT, &laserTextureImageDescriptor);
     455
     456   laserPipeline.createDescriptorSetLayout();
     457   laserPipeline.createPipeline("shaders/laser-vert.spv", "shaders/laser-frag.spv");
     458   laserPipeline.createDescriptorPool(swapChainImages);
     459   laserPipeline.createDescriptorSets(swapChainImages);
     460
     461   explosionPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ExplosionVertex::particleStartVelocity));
     462   explosionPipeline.addAttribute(VK_FORMAT_R32_SFLOAT, offset_of(&ExplosionVertex::particleStartTime));
     463   explosionPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ExplosionVertex::objIndex));
     464
     465   createBufferSet(sizeof(UBO_Explosion), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     466      uniformBuffers_explosionPipeline, uniformBuffersMemory_explosionPipeline, uniformBufferInfoList_explosionPipeline);
     467
     468   explosionPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     469      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_explosionPipeline);
     470   explosionPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
     471
     472   explosionPipeline.createDescriptorSetLayout();
     473   explosionPipeline.createPipeline("shaders/explosion-vert.spv", "shaders/explosion-frag.spv");
     474   explosionPipeline.createDescriptorPool(swapChainImages);
     475   explosionPipeline.createDescriptorSets(swapChainImages);
     476
     477   currentRenderScreenFn = &VulkanGame::renderMainScreen;
     478
    108479   ImGuiIO& io = ImGui::GetIO();
    109 
    110    currentRenderScreenFn = &VulkanGame::renderMainScreen;
    111480
    112481   initGuiValueLists(valueLists);
     
    190559   createSwapChain();
    191560   createImageViews();
     561
     562   createResourceCommandPool();
     563   createImageResources();
     564
    192565   createRenderPass();
    193 
    194    createResourceCommandPool();
    195566   createCommandPools();
    196 
    197    createImageResources();
    198567   createFramebuffers();
    199 
    200    // TODO: I think I can start setting up IMGUI here
    201    // ImGui_ImplVulkan_Init will create the Vulkan pipeline for ImGui for me
    202    // imgui_impl_vulkan keeps track of the imgui pipeline internally
    203    // TODO: Check how the example recreates the pipeline and what code I need
    204    // to copy over to do that
    205 
    206    createImguiDescriptorPool();
    207 
    208    IMGUI_CHECKVERSION();
    209    ImGui::CreateContext();
    210    ImGuiIO& io = ImGui::GetIO(); (void)io;
    211    //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;     // Enable Keyboard Controls
    212    //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;      // Enable Gamepad Controls
    213 
    214    // Setup Dear ImGui style
    215    ImGui::StyleColorsDark();
    216    //ImGui::StyleColorsClassic();
    217 
    218    // TODO: Maybe call this once and save the results since it's also called when creating the logical device
    219    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    220 
    221    ImGui_ImplSDL2_InitForVulkan(window);
    222    ImGui_ImplVulkan_InitInfo init_info = {};
    223    init_info.Instance = this->instance;
    224    init_info.PhysicalDevice = this->physicalDevice;
    225    init_info.Device = this->device;
    226    init_info.QueueFamily = indices.graphicsFamily.value();
    227    init_info.Queue = graphicsQueue;
    228    init_info.DescriptorPool = this->imguiDescriptorPool; // TODO: Create a descriptor pool for IMGUI
    229    init_info.Allocator = nullptr;
    230    init_info.MinImageCount = this->swapChainMinImageCount;
    231    init_info.ImageCount = this->swapChainImageCount;
    232    init_info.CheckVkResultFn = check_imgui_vk_result;
    233    ImGui_ImplVulkan_Init(&init_info, this->renderPass);
    234 
    235    cout << "Got here" << endl;
    236 
    237    // TODO: I think I have code in VkUtil for creating VkImages, which uses command buffers
    238    // Maybe check how that code works
    239 
    240    // Upload Fonts
    241    {
    242       VkCommandBuffer command_buffer;
    243 
    244       // Create the command buffer to load
    245       VkCommandBufferAllocateInfo info = {};
    246       info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
    247       info.commandPool = resourceCommandPool;
    248       info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
    249       info.commandBufferCount = 1;
    250 
    251       VKUTIL_CHECK_RESULT(vkAllocateCommandBuffers(this->device, &info, &command_buffer),
    252          "failed to allocate command buffers!");
    253 
    254       //err = vkResetCommandPool(this->device, command_pool, 0); // Probably not really needed here since the command pool is never used before this
    255       //check_vk_result(err);
    256       VkCommandBufferBeginInfo begin_info = {};
    257       begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
    258       begin_info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
    259       VKUTIL_CHECK_RESULT(vkBeginCommandBuffer(command_buffer, &begin_info),
    260          "failed to begin recording command buffer!");
    261 
    262       ImGui_ImplVulkan_CreateFontsTexture(command_buffer);
    263 
    264       VkSubmitInfo end_info = {};
    265       end_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
    266       end_info.commandBufferCount = 1;
    267       end_info.pCommandBuffers = &command_buffer;
    268 
    269       VKUTIL_CHECK_RESULT(vkEndCommandBuffer(command_buffer),
    270          "failed to record command buffer!");
    271 
    272       VKUTIL_CHECK_RESULT(vkQueueSubmit(this->graphicsQueue, 1, &end_info, VK_NULL_HANDLE),
    273          "failed to submit draw command buffer!");
    274 
    275       if (vkDeviceWaitIdle(this->device) != VK_SUCCESS) {
    276          throw runtime_error("failed to wait for device!");
    277       }
    278 
    279       ImGui_ImplVulkan_DestroyFontUploadObjects();
    280 
    281       // This should make the command pool reusable for later
    282       VKUTIL_CHECK_RESULT(vkResetCommandPool(this->device, resourceCommandPool, 0),
    283          "failed to reset command pool!");
    284    }
    285 
    286    cout << "And now here" << endl;
    287 
    288    initMatrices();
    289 
    290    // TODO: Figure out how much of ubo creation and associated variables should be in the pipeline class
    291    // Maybe combine the ubo-related objects into a new class
    292 
    293    initGraphicsPipelines();
    294 
    295    modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::pos));
    296    modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::color));
    297    modelPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&ModelVertex::texCoord));
    298    modelPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex));
    299 
    300    createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    301       uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline);
    302 
    303    modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
    304       VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline);
    305    modelPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
    306    modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
    307       VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor);
    308 
    309    SceneObject<ModelVertex, SSBO_ModelObject>* texturedSquare = nullptr;
    310 
    311    texturedSquare = &addObject(modelObjects, modelPipeline,
    312       addObjectIndex<ModelVertex>(modelObjects.size(), {
    313          {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
    314          {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
    315          {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
    316          {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}
    317       }), {
    318          0, 1, 2, 2, 3, 0
    319       }, {
    320          mat4(1.0f)
    321       }, false);
    322 
    323    texturedSquare->model_base =
    324       translate(mat4(1.0f), vec3(0.0f, 0.0f, -2.0f));
    325    texturedSquare->modified = true;
    326 
    327    texturedSquare = &addObject(modelObjects, modelPipeline,
    328       addObjectIndex<ModelVertex>(modelObjects.size(), {
    329          {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
    330          {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
    331          {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
    332          {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}
    333       }), {
    334          0, 1, 2, 2, 3, 0
    335       }, {
    336          mat4(1.0f)
    337       }, false);
    338 
    339    texturedSquare->model_base =
    340       translate(mat4(1.0f), vec3(0.0f, 0.0f, -1.5f));
    341    texturedSquare->modified = true;
    342 
    343    modelPipeline.createDescriptorSetLayout();
    344    modelPipeline.createPipeline("shaders/model-vert.spv", "shaders/model-frag.spv");
    345    modelPipeline.createDescriptorPool(swapChainImages);
    346    modelPipeline.createDescriptorSets(swapChainImages);
    347 
    348    shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::pos));
    349    shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::color));
    350    shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::normal));
    351    shipPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ShipVertex::objIndex));
    352 
    353    createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    354       uniformBuffers_shipPipeline, uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline);
    355 
    356    shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
    357       VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline);
    358    shipPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
    359 
    360    // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly
    361    // the same data. Add an option to make some pipelines not use indexing
    362    SceneObject<ShipVertex, SSBO_ModelObject>& ship = addObject(shipObjects, shipPipeline,
    363       addObjectIndex<ShipVertex>(shipObjects.size(),
    364       addVertexNormals<ShipVertex>({
    365 
    366          //back
    367          {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    368          {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    369          {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    370          {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    371          {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    372          {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    373 
    374          // left back
    375          {{ -0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    376          {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    377          {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    378          {{ -0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    379          {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    380          {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    381 
    382          // right back
    383          {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    384          {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    385          {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    386          {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    387          {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    388          {{  0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    389 
    390          // left mid
    391          {{-0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
    392          {{-0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
    393          {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    394          {{-0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
    395          {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    396          {{ -0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    397 
    398          // right mid
    399          {{  0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    400          {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    401          {{ 0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
    402          {{  0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 0.3f}},
    403          {{ 0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
    404          {{ 0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
    405 
    406          // left front
    407          {{  0.0f,   0.0f,  -3.5f}, {0.0f, 0.0f, 1.0f}},
    408          {{-0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
    409          {{-0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
    410 
    411          // right front
    412          {{ 0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
    413          {{ 0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
    414          {{  0.0f,   0.0f,  -3.5f}, {0.0f, 0.0f, 1.0f}},
    415 
    416          // top back
    417          {{ -0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
    418          {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 1.0f}},
    419          {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 1.0f}},
    420          {{ -0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
    421          {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 1.0f}},
    422          {{  0.5f,   0.3f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
    423 
    424          // bottom back
    425          {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 1.0f}},
    426          {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
    427          {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 1.0f}},
    428          {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 1.0f}},
    429          {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
    430          {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
    431 
    432          // top mid
    433          {{-0.25f,   0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}},
    434          {{ -0.5f,   0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}},
    435          {{  0.5f,   0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}},
    436          {{ -0.25f,  0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}},
    437          {{  0.5f,   0.3f, -2.0f}, {0.0f, 0.0f, 1.0f}},
    438          {{ 0.25f,   0.3f, -3.0f}, {0.0f, 0.0f, 1.0f}},
    439 
    440          // bottom mid
    441          {{ -0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
    442          {{-0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
    443          {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
    444          {{  0.5f,   0.0f,  -2.0f}, {0.0f, 0.0f, 1.0f}},
    445          {{-0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
    446          {{ 0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 1.0f}},
    447 
    448          // top front
    449          {{-0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
    450          {{ 0.25f,   0.3f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
    451          {{  0.0f,   0.0f,  -3.5f}, {0.0f, 0.0f, 0.3f}},
    452 
    453          // bottom front
    454          {{ 0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
    455          {{-0.25f,   0.0f,  -3.0f}, {0.0f, 0.0f, 0.3f}},
    456          {{  0.0f,   0.0f,  -3.5f}, {0.0f, 0.0f, 0.3f}},
    457 
    458          // left wing start back
    459          {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    460          {{ -1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    461          {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    462          {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    463          {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    464          {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    465 
    466          // left wing start top
    467          {{ -0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    468          {{ -1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    469          {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    470          {{ -0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    471          {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    472          {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    473 
    474          // left wing start front
    475          {{ -0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    476          {{ -0.5f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    477          {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    478          {{ -0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    479          {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    480          {{ -1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    481 
    482          // left wing start bottom
    483          {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    484          {{ -1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    485          {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    486          {{ -0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    487          {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    488          {{ -0.5f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    489 
    490          // left wing end outside
    491          {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    492          {{ -2.2f,   0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}},
    493          {{ -1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    494 
    495          // left wing end top
    496          {{ -1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    497          {{ -2.2f,   0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}},
    498          {{ -1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    499 
    500          // left wing end front
    501          {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    502          {{ -2.2f,  0.15f,  -0.8f}, {0.0f, 0.0f, 0.3f}},
    503          {{ -1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    504 
    505          // left wing end bottom
    506          {{ -1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    507          {{ -2.2f,  0.15f,  -0.8f}, {0.0f, 0.0f, 0.3f}},
    508          {{ -1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    509 
    510          // right wing start back
    511          {{  1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    512          {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    513          {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    514          {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    515          {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    516          {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    517 
    518          // right wing start top
    519          {{  1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    520          {{  0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    521          {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    522          {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    523          {{  0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    524          {{  0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    525 
    526          // right wing start front
    527          {{  0.5f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    528          {{  0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    529          {{  1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    530          {{  1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    531          {{  0.5f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    532          {{  1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    533 
    534          // right wing start bottom
    535          {{  1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    536          {{  0.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    537          {{ 1.3f,    0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    538          {{ 1.3f,    0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    539          {{ 0.5f,    0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    540          {{ 0.5f,    0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    541 
    542          // right wing end outside
    543          {{  2.2f,   0.15f, -0.8f}, {0.0f, 0.0f, 0.3f}},
    544          {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    545          {{  1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    546 
    547          // right wing end top
    548          {{  2.2f,  0.15f,  -0.8f}, {0.0f, 0.0f, 0.3f}},
    549          {{  1.3f,   0.3f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    550          {{  1.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    551 
    552          // right wing end front
    553          {{  2.2f,   0.15f,  -0.8f}, {0.0f, 0.0f, 0.3f}},
    554          {{  1.3f,   0.0f,   -0.3f}, {0.0f, 0.0f, 0.3f}},
    555          {{  1.3f,   0.3f,   -0.3f}, {0.0f, 0.0f, 0.3f}},
    556 
    557          // right wing end bottom
    558          {{  2.2f,  0.15f,  -0.8f}, {0.0f, 0.0f, 0.3f}},
    559          {{  1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    560          {{  1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    561       })), {
    562            0,   1,   2,   3,   4,   5,
    563            6,   7,   8,   9,  10,  11,
    564           12,  13,  14,  15,  16,  17,
    565           18,  19,  20,  21,  22,  23,
    566           24,  25,  26,  27,  28,  29,
    567           30,  31,  32,
    568           33,  34,  35,
    569           36,  37,  38,  39,  40,  41,
    570           42,  43,  44,  45,  46,  47,
    571           48,  49,  50,  51,  52,  53,
    572           54,  55,  56,  57,  58,  59,
    573           60,  61,  62,
    574           63,  64,  65,
    575           66,  67,  68,  69,  70,  71,
    576           72,  73,  74,  75,  76,  77,
    577           78,  79,  80,  81,  82,  83,
    578           84,  85,  86,  87,  88,  89,
    579           90,  91,  92,
    580           93,  94,  95,
    581           96,  97,  98,
    582           99, 100, 101,
    583          102, 103, 104, 105, 106, 107,
    584          108, 109, 110, 111, 112, 113,
    585          114, 115, 116, 117, 118, 119,
    586          120, 121, 122, 123, 124, 125,
    587          126, 127, 128,
    588          129, 130, 131,
    589          132, 133, 134,
    590          135, 136, 137,
    591       }, {
    592          mat4(1.0f)
    593       }, false);
    594 
    595    ship.model_base =
    596       translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)) *
    597       scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
    598    ship.modified = true;
    599 
    600    shipPipeline.createDescriptorSetLayout();
    601    shipPipeline.createPipeline("shaders/ship-vert.spv", "shaders/ship-frag.spv");
    602    shipPipeline.createDescriptorPool(swapChainImages);
    603    shipPipeline.createDescriptorSets(swapChainImages);
    604 
    605    asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::pos));
    606    asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::color));
    607    asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::normal));
    608    asteroidPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&AsteroidVertex::objIndex));
    609 
    610    createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    611       uniformBuffers_asteroidPipeline, uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline);
    612 
    613    asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
    614       VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline);
    615    asteroidPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
    616 
    617    asteroidPipeline.createDescriptorSetLayout();
    618    asteroidPipeline.createPipeline("shaders/asteroid-vert.spv", "shaders/asteroid-frag.spv");
    619    asteroidPipeline.createDescriptorPool(swapChainImages);
    620    asteroidPipeline.createDescriptorSets(swapChainImages);
    621 
    622    laserPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&LaserVertex::pos));
    623    laserPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&LaserVertex::texCoord));
    624    laserPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&LaserVertex::objIndex));
    625 
    626    createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    627       uniformBuffers_laserPipeline, uniformBuffersMemory_laserPipeline, uniformBufferInfoList_laserPipeline);
    628 
    629    laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
    630       VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_laserPipeline);
    631    laserPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT);
    632    laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
    633       VK_SHADER_STAGE_FRAGMENT_BIT, &laserTextureImageDescriptor);
    634 
    635    laserPipeline.createDescriptorSetLayout();
    636    laserPipeline.createPipeline("shaders/laser-vert.spv", "shaders/laser-frag.spv");
    637    laserPipeline.createDescriptorPool(swapChainImages);
    638    laserPipeline.createDescriptorSets(swapChainImages);
    639 
    640    explosionPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ExplosionVertex::particleStartVelocity));
    641    explosionPipeline.addAttribute(VK_FORMAT_R32_SFLOAT, offset_of(&ExplosionVertex::particleStartTime));
    642    explosionPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ExplosionVertex::objIndex));
    643 
    644    createBufferSet(sizeof(UBO_Explosion), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    645       uniformBuffers_explosionPipeline, uniformBuffersMemory_explosionPipeline, uniformBufferInfoList_explosionPipeline);
    646 
    647    explosionPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
    648       VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_explosionPipeline);
    649    explosionPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
    650 
    651    explosionPipeline.createDescriptorSetLayout();
    652    explosionPipeline.createPipeline("shaders/explosion-vert.spv", "shaders/explosion-frag.spv");
    653    explosionPipeline.createDescriptorPool(swapChainImages);
    654    explosionPipeline.createDescriptorSets(swapChainImages);
    655 
    656    cout << "Created all the graphics pipelines" << endl;
    657 
    658568   createCommandBuffers();
    659 
    660569   createSyncObjects();
    661 
    662    cout << "Finished init function" << endl;
    663570}
    664571
     
    688595// TODO: Maybe changes the name to initScene() or something similar
    689596void VulkanGame::initMatrices() {
    690    this->cam_pos = vec3(0.0f, 0.0f, 2.0f);
     597   cam_pos = vec3(0.0f, 0.0f, 2.0f);
    691598
    692599   float cam_yaw = 0.0f;
     
    697604
    698605   mat4 R_view = pitch_mat * yaw_mat;
    699    mat4 T_view = translate(mat4(1.0f), vec3(-this->cam_pos.x, -this->cam_pos.y, -this->cam_pos.z));
     606   mat4 T_view = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z));
    700607   viewMat = R_view * T_view;
    701608
     
    733640   while (!done) {
    734641
    735       this->prevTime = curTime;
    736       curTime = duration<float, seconds::period>(steady_clock::now() - this->startTime).count();
    737       this->elapsedTime = curTime - this->prevTime;
    738 
    739       if (curTime - this->fpsStartTime >= 1.0f) {
    740          this->fps = (float)frameCount / (curTime - this->fpsStartTime);
    741 
    742          this->frameCount = 0;
    743          this->fpsStartTime = curTime;
    744       }
    745 
    746       this->frameCount++;
     642      prevTime = curTime;
     643      curTime = duration<float, seconds::period>(steady_clock::now() - startTime).count();
     644      elapsedTime = curTime - prevTime;
     645
     646      if (curTime - fpsStartTime >= 1.0f) {
     647         fps = (float)frameCount / (curTime - fpsStartTime);
     648
     649         frameCount = 0;
     650         fpsStartTime = curTime;
     651      }
     652
     653      frameCount++;
    747654
    748655      gui->processEvents();
     
    924831      updateScene();
    925832
     833      // TODO: Move this into a renderImGuiOverlay() function
    926834      ImGui_ImplVulkan_NewFrame();
    927835      ImGui_ImplSDL2_NewFrame(window);
     
    11361044
    11371045void VulkanGame::cleanup() {
     1046   // FIXME: We could wait on the Queue if we had the queue in wd-> (otherwise VulkanH functions can't use globals)
     1047   //vkQueueWaitIdle(g_Queue);
    11381048   VKUTIL_CHECK_RESULT(vkDeviceWaitIdle(device), "failed to wait for device!");
    11391049
    1140    ImGui_ImplVulkan_Shutdown();
    1141    ImGui_ImplSDL2_Shutdown();
    1142    ImGui::DestroyContext();
    1143 
    1144    // TODO: Probably move this into cleanupSwapChain once I finish the integration
    1145    destroyImguiDescriptorPool();
     1050   cleanupImGuiOverlay();
    11461051
    11471052   cleanupSwapChain();
     
    14671372         VK_IMAGE_ASPECT_COLOR_BIT);
    14681373   }
     1374}
     1375
     1376void VulkanGame::createResourceCommandPool() {
     1377   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
     1378
     1379   VkCommandPoolCreateInfo poolInfo = {};
     1380   poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
     1381   poolInfo.queueFamilyIndex = indices.graphicsFamily.value();
     1382   poolInfo.flags = 0;
     1383
     1384   if (vkCreateCommandPool(device, &poolInfo, nullptr, &resourceCommandPool) != VK_SUCCESS) {
     1385      throw runtime_error("failed to create resource command pool!");
     1386   }
     1387}
     1388
     1389void VulkanGame::createImageResources() {
     1390   VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent,
     1391      depthImage, graphicsQueue);
     1392
     1393   createTextureSampler();
     1394
     1395   // TODO: Move all images/textures somewhere into the assets folder
     1396
     1397   VulkanUtils::createVulkanImageFromFile(device, physicalDevice, resourceCommandPool, "textures/texture.jpg",
     1398      floorTextureImage, graphicsQueue);
     1399
     1400   floorTextureImageDescriptor = {};
     1401   floorTextureImageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
     1402   floorTextureImageDescriptor.imageView = floorTextureImage.imageView;
     1403   floorTextureImageDescriptor.sampler = textureSampler;
     1404
     1405   VulkanUtils::createVulkanImageFromFile(device, physicalDevice, resourceCommandPool, "textures/laser.png",
     1406      laserTextureImage, graphicsQueue);
     1407
     1408   laserTextureImageDescriptor = {};
     1409   laserTextureImageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
     1410   laserTextureImageDescriptor.imageView = laserTextureImage.imageView;
     1411   laserTextureImageDescriptor.sampler = textureSampler;
     1412}
     1413
     1414VkFormat VulkanGame::findDepthFormat() {
     1415   return VulkanUtils::findSupportedFormat(
     1416      physicalDevice,
     1417      { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT },
     1418      VK_IMAGE_TILING_OPTIMAL,
     1419      VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
     1420   );
    14691421}
    14701422
     
    15271479}
    15281480
    1529 VkFormat VulkanGame::findDepthFormat() {
    1530    return VulkanUtils::findSupportedFormat(
    1531       physicalDevice,
    1532       { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT },
    1533       VK_IMAGE_TILING_OPTIMAL,
    1534       VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
    1535    );
    1536 }
    1537 
    1538 void VulkanGame::createResourceCommandPool() {
    1539    QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
    1540 
    1541    VkCommandPoolCreateInfo poolInfo = {};
    1542    poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
    1543    poolInfo.queueFamilyIndex = indices.graphicsFamily.value();
    1544    poolInfo.flags = 0;
    1545 
    1546    if (vkCreateCommandPool(device, &poolInfo, nullptr, &resourceCommandPool) != VK_SUCCESS) {
    1547       throw runtime_error("failed to create resource command pool!");
    1548    }
    1549 }
    1550 
    15511481void VulkanGame::createCommandPools() {
    15521482   commandPools.resize(swapChainImageCount);
     
    15631493         "failed to create graphics command pool!");
    15641494   }
    1565 }
    1566 
    1567 void VulkanGame::createImageResources() {
    1568    VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent,
    1569       depthImage, graphicsQueue);
    1570 
    1571    createTextureSampler();
    1572 
    1573    // TODO: Move all images/textures somewhere into the assets folder
    1574 
    1575    VulkanUtils::createVulkanImageFromFile(device, physicalDevice, resourceCommandPool, "textures/texture.jpg",
    1576       floorTextureImage, graphicsQueue);
    1577 
    1578    floorTextureImageDescriptor = {};
    1579    floorTextureImageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
    1580    floorTextureImageDescriptor.imageView = floorTextureImage.imageView;
    1581    floorTextureImageDescriptor.sampler = textureSampler;
    1582 
    1583    VulkanUtils::createVulkanImageFromFile(device, physicalDevice, resourceCommandPool, "textures/laser.png",
    1584       laserTextureImage, graphicsQueue);
    1585 
    1586    laserTextureImageDescriptor = {};
    1587    laserTextureImageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
    1588    laserTextureImageDescriptor.imageView = laserTextureImage.imageView;
    1589    laserTextureImageDescriptor.sampler = textureSampler;
    15901495}
    15911496
     
    16111516   samplerInfo.maxLod = 0.0f;
    16121517
    1613    if (vkCreateSampler(device, &samplerInfo, nullptr, &textureSampler) != VK_SUCCESS) {
    1614       throw runtime_error("failed to create texture sampler!");
    1615    }
     1518   VKUTIL_CHECK_RESULT(vkCreateSampler(device, &samplerInfo, nullptr, &textureSampler),
     1519      "failed to create texture sampler!");
    16161520}
    16171521
     
    16531557      if (vkAllocateCommandBuffers(device, &allocInfo, &commandBuffers[i]) != VK_SUCCESS) {
    16541558         throw runtime_error("failed to allocate command buffer!");
     1559      }
     1560   }
     1561}
     1562
     1563void VulkanGame::createSyncObjects() {
     1564   imageAcquiredSemaphores.resize(swapChainImageCount);
     1565   renderCompleteSemaphores.resize(swapChainImageCount);
     1566   inFlightFences.resize(swapChainImageCount);
     1567
     1568   VkSemaphoreCreateInfo semaphoreInfo = {};
     1569   semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
     1570
     1571   VkFenceCreateInfo fenceInfo = {};
     1572   fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
     1573   fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
     1574
     1575   for (size_t i = 0; i < swapChainImageCount; i++) {
     1576      if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &imageAcquiredSemaphores[i]) != VK_SUCCESS) {
     1577         throw runtime_error("failed to create image acquired sempahore for a frame!");
     1578      }
     1579
     1580      if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &renderCompleteSemaphores[i]) != VK_SUCCESS) {
     1581         throw runtime_error("failed to create render complete sempahore for a frame!");
     1582      }
     1583
     1584      if (vkCreateFence(device, &fenceInfo, nullptr, &inFlightFences[i]) != VK_SUCCESS) {
     1585         throw runtime_error("failed to create fence for a frame!");
    16551586      }
    16561587   }
     
    17631694}
    17641695
    1765 void VulkanGame::createSyncObjects() {
    1766    imageAcquiredSemaphores.resize(swapChainImageCount);
    1767    renderCompleteSemaphores.resize(swapChainImageCount);
    1768    inFlightFences.resize(swapChainImageCount);
    1769 
    1770    VkSemaphoreCreateInfo semaphoreInfo = {};
    1771    semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
    1772 
    1773    VkFenceCreateInfo fenceInfo = {};
    1774    fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
    1775    fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
    1776 
    1777    for (size_t i = 0; i < swapChainImageCount; i++) {
    1778       if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &imageAcquiredSemaphores[i]) != VK_SUCCESS) {
    1779          throw runtime_error("failed to create image acquired sempahore for a frame!");
    1780       }
    1781 
    1782       if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &renderCompleteSemaphores[i]) != VK_SUCCESS) {
    1783          throw runtime_error("failed to create render complete sempahore for a frame!");
    1784       }
    1785 
    1786       if (vkCreateFence(device, &fenceInfo, nullptr, &inFlightFences[i]) != VK_SUCCESS) {
    1787          throw runtime_error("failed to create fence for a frame!");
    1788       }
    1789    }
    1790 }
    1791 
    1792 void VulkanGame::createImguiDescriptorPool() {
     1696void VulkanGame::initImGuiOverlay() {
    17931697   vector<VkDescriptorPoolSize> pool_sizes{
    17941698       { VK_DESCRIPTOR_TYPE_SAMPLER, 1000 },
     
    18111715   pool_info.poolSizeCount = static_cast<uint32_t>(pool_sizes.size());
    18121716   pool_info.pPoolSizes = pool_sizes.data();
    1813    if (vkCreateDescriptorPool(device, &pool_info, nullptr, &imguiDescriptorPool) != VK_SUCCESS) {
    1814       throw runtime_error("failed to create IMGUI descriptor pool!");
    1815    }
    1816 }
    1817 
    1818 void VulkanGame::destroyImguiDescriptorPool() {
     1717
     1718   VKUTIL_CHECK_RESULT(vkCreateDescriptorPool(device, &pool_info, nullptr, &imguiDescriptorPool),
     1719      "failed to create IMGUI descriptor pool!");
     1720
     1721   // TODO: Do this in one place and save it instead of redoing it every time I need a queue family index
     1722   QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface);
     1723
     1724   // Setup Dear ImGui context
     1725   IMGUI_CHECKVERSION();
     1726   ImGui::CreateContext();
     1727   ImGuiIO& io = ImGui::GetIO();
     1728   //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;     // Enable Keyboard Controls
     1729   //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;      // Enable Gamepad Controls
     1730
     1731   // Setup Dear ImGui style
     1732   ImGui::StyleColorsDark();
     1733   //ImGui::StyleColorsClassic();
     1734
     1735   // Setup Platform/Renderer bindings
     1736   ImGui_ImplSDL2_InitForVulkan(window);
     1737   ImGui_ImplVulkan_InitInfo init_info = {};
     1738   init_info.Instance = instance;
     1739   init_info.PhysicalDevice = physicalDevice;
     1740   init_info.Device = device;
     1741   init_info.QueueFamily = indices.graphicsFamily.value();
     1742   init_info.Queue = graphicsQueue;
     1743   init_info.DescriptorPool = imguiDescriptorPool;
     1744   init_info.Allocator = nullptr;
     1745   init_info.MinImageCount = swapChainMinImageCount;
     1746   init_info.ImageCount = swapChainImageCount;
     1747   init_info.CheckVkResultFn = check_imgui_vk_result;
     1748   ImGui_ImplVulkan_Init(&init_info, renderPass);
     1749
     1750   // Load Fonts
     1751   // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
     1752   // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
     1753   // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
     1754   // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
     1755   // - Read 'docs/FONTS.md' for more instructions and details.
     1756   // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
     1757   //io.Fonts->AddFontDefault();
     1758   //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
     1759   //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
     1760   //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
     1761   //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
     1762   //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
     1763   //assert(font != NULL);
     1764
     1765   // Upload Fonts
     1766   {
     1767      VkCommandBuffer commandBuffer = VulkanUtils::beginSingleTimeCommands(device, resourceCommandPool);
     1768
     1769      ImGui_ImplVulkan_CreateFontsTexture(commandBuffer);
     1770
     1771      VulkanUtils::endSingleTimeCommands(device, resourceCommandPool, commandBuffer, graphicsQueue);
     1772
     1773      ImGui_ImplVulkan_DestroyFontUploadObjects();
     1774   }
     1775}
     1776
     1777void VulkanGame::cleanupImGuiOverlay() {
     1778   ImGui_ImplVulkan_Shutdown();
     1779   ImGui_ImplSDL2_Shutdown();
     1780   ImGui::DestroyContext();
     1781
    18191782   vkDestroyDescriptorPool(device, imguiDescriptorPool, nullptr);
     1783}
     1784
     1785void VulkanGame::createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,
     1786   vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, vector<VkDescriptorBufferInfo>& bufferInfoList) {
     1787   buffers.resize(swapChainImageCount);
     1788   buffersMemory.resize(swapChainImageCount);
     1789   bufferInfoList.resize(swapChainImageCount);
     1790
     1791   for (size_t i = 0; i < swapChainImageCount; i++) {
     1792      VulkanUtils::createBuffer(device, physicalDevice, bufferSize, flags,
     1793         VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     1794         buffers[i], buffersMemory[i]);
     1795
     1796      bufferInfoList[i].buffer = buffers[i];
     1797      bufferInfoList[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now
     1798      bufferInfoList[i].range = bufferSize; // Size of the update starting from offset, or VK_WHOLE_SIZE
     1799   }
    18201800}
    18211801
     
    20242004}
    20252005
    2026 void VulkanGame::createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,
    2027       vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, vector<VkDescriptorBufferInfo>& bufferInfoList) {
    2028    buffers.resize(swapChainImageCount);
    2029    buffersMemory.resize(swapChainImageCount);
    2030    bufferInfoList.resize(swapChainImageCount);
    2031 
    2032    for (size_t i = 0; i < swapChainImageCount; i++) {
    2033       VulkanUtils::createBuffer(device, physicalDevice, bufferSize, flags,
    2034          VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
    2035          buffers[i], buffersMemory[i]);
    2036 
    2037       bufferInfoList[i].buffer = buffers[i];
    2038       bufferInfoList[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now
    2039       bufferInfoList[i].range = bufferSize; // Size of the update starting from offset, or VK_WHOLE_SIZE
    2040    }
    2041 }
    2042 
    20432006void VulkanGame::addExplosion(mat4 model_mat, float duration, float cur_time) {
    20442007   vector<ExplosionVertex> vertices;
     
    20872050   createSwapChain();
    20882051   createImageViews();
    2089    createRenderPass();
    2090 
    2091    createCommandPools();
    20922052
    20932053   // The depth buffer does need to be recreated with the swap chain since its dimensions depend on the window size
     
    20952055   VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent,
    20962056      depthImage, graphicsQueue);
     2057
     2058   createRenderPass();
     2059   createCommandPools();
    20972060   createFramebuffers();
     2061   createCommandBuffers();
     2062   createSyncObjects();
    20982063
    20992064   // TODO: Move UBO creation/management into GraphicsPipeline_Vulkan, like I did with SSBOs
     2065   // TODO: Check if the shader stages and maybe some other properties of the pipeline can be re-used
     2066   // instead of recreated every time
    21002067
    21012068   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     
    21382105   explosionPipeline.createDescriptorPool(swapChainImages);
    21392106   explosionPipeline.createDescriptorSets(swapChainImages);
    2140 
    2141    createCommandBuffers();
    2142 
    2143    createSyncObjects();
    21442107
    21452108   imageIndex = 0;
  • vulkan-game.hpp

    raa7e5f0 rcefdf23  
    3434   const bool ENABLE_VALIDATION_LAYERS = true;
    3535#endif
     36
     37// TODO: Consider if there is a better way of dealing with all the vertex types and ssbo types, maybe
     38// by consolidating some and trying to keep new ones to a minimum
    3639
    3740struct OverlayVertex {
     
    193196};
    194197
     198// TODO: Maybe move this to a different header
     199
    195200enum UIValueType {
    196201   UIVALUE_INT,
     
    208213class VulkanGame {
    209214   public:
     215
    210216      VulkanGame();
    211217      ~VulkanGame();
     
    213219      void run(int width, int height, unsigned char guiFlags);
    214220
    215       GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline;
    216       GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject> shipPipeline;
    217       GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline;
    218       GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline;
    219       GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline;
    220 
    221221   private:
     222
    222223      static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
    223224         VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
     
    226227         void* pUserData);
    227228
     229      // TODO: Maybe pass these in as parameters to some Camera class
    228230      const float NEAR_CLIP = 0.1f;
    229231      const float FAR_CLIP = 100.0f;
    230       const float FOV_ANGLE = 67.0f; // means the camera lens goes from -33 deg to 33 def
     232      const float FOV_ANGLE = 67.0f; // means the camera lens goes from -33 deg to 33 deg
    231233
    232234      const int EXPLOSION_PARTICLE_COUNT = 300;
     
    286288      bool shouldRecreateSwapChain;
    287289
    288       VkDescriptorPool imguiDescriptorPool;
    289 
    290290      VkSampler textureSampler;
    291291
     
    297297
    298298      mat4 viewMat, projMat;
     299
     300      // Maybe at some point create an imgui pipeline class, but I don't think it makes sense right now
     301      VkDescriptorPool imguiDescriptorPool;
     302
     303      // TODO: Probably restructure the GraphicsPipeline_Vulkan class based on what I learned about descriptors and textures
     304      // while working on graphics-library. Double-check exactly what this was and note it down here.
     305      // Basically, I think the point was that if I have several modesl that all use the same shaders and, therefore,
     306      // the same pipeline, but use different textures, the approach I took when initially creating GraphicsPipeline_Vulkan
     307      // wouldn't work since the whole pipeline couldn't have a common set of descriptors for the textures
     308      GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline;
     309      GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject> shipPipeline;
     310      GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline;
     311      GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline;
     312      GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline;
    299313
    300314      // TODO: Maybe make the ubo objects part of the pipeline class since there's only one ubo
     
    371385
    372386      // TODO: Make a separate TImer class
    373       // It could also deal with the steady_clock vs high_resolution_clock issue
    374387      time_point<steady_clock> startTime;
    375388      float fpsStartTime, curTime, prevTime, elapsedTime;
     
    398411      void createSwapChain();
    399412      void createImageViews();
     413      void createResourceCommandPool();
     414      void createImageResources();
     415      VkFormat findDepthFormat(); // TODO: Declare/define (in the cpp file) this function in some util functions section
    400416      void createRenderPass();
    401       VkFormat findDepthFormat(); // TODO: Declare/define (in the cpp file) this function in some util functions section
    402       void createResourceCommandPool();
    403417      void createCommandPools();
    404       void createImageResources();
    405418      void createFramebuffers();
    406419      void createCommandBuffers();
     
    409422      void createTextureSampler();
    410423
    411       void createImguiDescriptorPool();
    412       void destroyImguiDescriptorPool();
     424      void initImGuiOverlay();
     425      void cleanupImGuiOverlay();
     426
     427      void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,
     428         vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory,
     429         vector<VkDescriptorBufferInfo>& bufferInfoList);
    413430
    414431      // TODO: Since addObject() returns a reference to the new object now,
     
    421438            bool pipelinesCreated);
    422439
     440      template<class VertexType>
     441      vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices);
     442
     443      template<class VertexType>
     444      vector<VertexType> addVertexNormals(vector<VertexType> vertices);
     445
     446      template<class VertexType, class SSBOType>
     447      void centerObject(SceneObject<VertexType, SSBOType>& object);
     448
    423449      template<class VertexType, class SSBOType>
    424450      void updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
     
    428454      void updateObjectVertices(GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
    429455            SceneObject<VertexType, SSBOType>& obj, size_t index);
    430 
    431       template<class VertexType>
    432       vector<VertexType> addVertexNormals(vector<VertexType> vertices);
    433 
    434       template<class VertexType>
    435       vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices);
    436 
    437       template<class VertexType, class SSBOType>
    438       void centerObject(SceneObject<VertexType, SSBOType>& object);
    439456
    440457      void addLaser(vec3 start, vec3 end, vec3 color, float width);
     
    445462
    446463      void addExplosion(mat4 model_mat, float duration, float cur_time);
    447 
    448       void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,
    449             vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory,
    450             vector<VkDescriptorBufferInfo>& bufferInfoList);
    451464
    452465      void renderFrame(ImDrawData* draw_data);
     
    503516   SceneObject<VertexType, SSBOType>& obj = objects.back();
    504517
     518   // TODO: Specify whether to center the object outside of this function or, worst case, maybe
     519   // with a boolean being passed in here, so that I don't have to rely on checking the specific object
     520   // type
    505521   if (!is_same_v<VertexType, LaserVertex> && !is_same_v<VertexType, ExplosionVertex>) {
    506522      centerObject(obj);
     
    533549}
    534550
    535 // TODO: Just pass in the single object instead of a list of all of them
    536 template<class VertexType, class SSBOType>
    537 void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    538       GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, size_t index) {
    539    SceneObject<VertexType, SSBOType>& obj = objects[index];
    540 
    541    obj.ssbo.model = obj.model_transform * obj.model_base;
    542    obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    543 
    544    pipeline.updateObject(index, obj.ssbo);
    545 
    546    obj.modified = false;
    547 }
    548 
    549 template<class VertexType, class SSBOType>
    550 void VulkanGame::updateObjectVertices(GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
    551       SceneObject<VertexType, SSBOType>& obj, size_t index) {
    552    pipeline.updateObjectVertices(index, obj.vertices, resourceCommandPool, graphicsQueue);
     551template<class VertexType>
     552vector<VertexType> VulkanGame::addObjectIndex(unsigned int objIndex, vector<VertexType> vertices) {
     553   for (VertexType& vertex : vertices) {
     554      vertex.objIndex = objIndex;
     555   }
     556
     557   return vertices;
    553558}
    554559
     
    557562   for (unsigned int i = 0; i < vertices.size(); i += 3) {
    558563      vec3 p1 = vertices[i].pos;
    559       vec3 p2 = vertices[i+1].pos;
    560       vec3 p3 = vertices[i+2].pos;
     564      vec3 p2 = vertices[i + 1].pos;
     565      vec3 p3 = vertices[i + 2].pos;
    561566
    562567      vec3 normal = normalize(cross(p2 - p1, p3 - p1));
     
    564569      // Add the same normal for all 3 vertices
    565570      vertices[i].normal = normal;
    566       vertices[i+1].normal = normal;
    567       vertices[i+2].normal = normal;
    568    }
    569 
    570    return vertices;
    571 }
    572 
    573 template<class VertexType>
    574 vector<VertexType> VulkanGame::addObjectIndex(unsigned int objIndex, vector<VertexType> vertices) {
    575    for (VertexType& vertex : vertices) {
    576       vertex.objIndex = objIndex;
     571      vertices[i + 1].normal = normal;
     572      vertices[i + 2].normal = normal;
    577573   }
    578574
     
    626622}
    627623
     624// TODO: Just pass in the single object instead of a list of all of them
     625template<class VertexType, class SSBOType>
     626void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
     627      GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, size_t index) {
     628   SceneObject<VertexType, SSBOType>& obj = objects[index];
     629
     630   obj.ssbo.model = obj.model_transform * obj.model_base;
     631   obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
     632
     633   pipeline.updateObject(index, obj.ssbo);
     634
     635   obj.modified = false;
     636}
     637
     638template<class VertexType, class SSBOType>
     639void VulkanGame::updateObjectVertices(GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
     640      SceneObject<VertexType, SSBOType>& obj, size_t index) {
     641   pipeline.updateObjectVertices(index, obj.vertices, resourceCommandPool, graphicsQueue);
     642}
     643
    628644#endif // _VULKAN_GAME_H
Note: See TracChangeset for help on using the changeset viewer.