Index: sdl-game.cpp
===================================================================
--- sdl-game.cpp	(revision c1ec4f63156230af7a921799acc46120ccc4b110)
+++ sdl-game.cpp	(revision 6486ba8f42f8ee2b61912e3a96ac6921ee30292b)
@@ -111,6 +111,13 @@
 
    createBufferSet(sizeof(UBO_VP_mats),
-      VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
-      uniformBuffers_modelPipeline);
+                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
+                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
+                   uniformBuffers_modelPipeline);
+
+   createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject),
+                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
+                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
+                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
+                   storageBuffers_modelPipeline);
 
    modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
@@ -121,15 +128,15 @@
       VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor);
 
-   SceneObject<ModelVertex, SSBO_ModelObject>* texturedSquare = nullptr;
+   SceneObject<ModelVertex>* texturedSquare = nullptr;
 
    texturedSquare = &addObject(modelObjects, modelPipeline,
       addObjectIndex<ModelVertex>(modelObjects.size(),
          addVertexNormals<ModelVertex>({
-            {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0},
-            {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0},
-            {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0},
-            {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0},
-            {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0},
-            {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0}
+            {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
+            {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
+            {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
+            {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
+            {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}},
+            {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}
          })),
       {
@@ -264,10 +271,4 @@
       VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass,
       { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 16, 24);
-
-   createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject),
-                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
-                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
-                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
-                   storageBuffers_modelPipeline);
 }
 
@@ -362,20 +363,19 @@
                   float zOffset = -2.0f + (0.5f * modelObjects.size());
 
-                  SceneObject<ModelVertex, SSBO_ModelObject>& texturedSquare =
-                     addObject(modelObjects, modelPipeline,
-                        addObjectIndex<ModelVertex>(modelObjects.size(),
-                           addVertexNormals<ModelVertex>({
-                              {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0},
-                              {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0},
-                              {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0},
-                              {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0},
-                              {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0},
-                              {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0}
-                           })),
-                        {
-                           0, 1, 2, 3, 4, 5
-                        }, objects_modelPipeline, {
-                           mat4(1.0f)
-                        });
+                  SceneObject<ModelVertex>& texturedSquare = addObject(modelObjects, modelPipeline,
+                     addObjectIndex<ModelVertex>(modelObjects.size(),
+                        addVertexNormals<ModelVertex>({
+                           {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
+                           {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
+                           {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
+                           {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
+                           {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}},
+                           {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}
+                        })),
+                     {
+                        0, 1, 2, 3, 4, 5
+                     }, objects_modelPipeline, {
+                        mat4(1.0f)
+                     });
 
                   texturedSquare.model_base =
@@ -455,6 +455,6 @@
 
    for (size_t i = 0; i < modelObjects.size(); i++) {
-      SceneObject<ModelVertex, SSBO_ModelObject>& obj = modelObjects[i];
-      SSBO_ModelObject& objData = obj.ssbo;
+      SceneObject<ModelVertex>& obj = modelObjects[i];
+      SSBO_ModelObject& objData = objects_modelPipeline.get(i);
 
       // Rotate the textured squares
@@ -488,9 +488,4 @@
 
    modelPipeline.cleanupBuffers();
-
-   for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) {
-      vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr);
-      vkFreeMemory(device, storageBuffers_modelPipeline.memory[i], nullptr);
-   }
 
    // END UNREVIEWED SECTION
@@ -1279,11 +1274,14 @@
    createSyncObjects();
 
-   // TODO: Move UBO creation/management into GraphicsPipeline_Vulkan, like I did with SSBOs
-   // TODO: Check if the shader stages and maybe some other properties of the pipeline can be re-used
-   // instead of recreated every time
-
    createBufferSet(sizeof(UBO_VP_mats),
-      VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
-      uniformBuffers_modelPipeline);
+                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
+                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
+                   uniformBuffers_modelPipeline);
+
+   createBufferSet(objects_modelPipeline.memorySize(),
+                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
+                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
+                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
+                   storageBuffers_modelPipeline);
 
    modelPipeline.updateRenderPass(renderPass);
@@ -1312,4 +1310,9 @@
       vkDestroyBuffer(device, uniformBuffers_modelPipeline.buffers[i], nullptr);
       vkFreeMemory(device, uniformBuffers_modelPipeline.memory[i], nullptr);
+   }
+
+   for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) {
+      vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr);
+      vkFreeMemory(device, storageBuffers_modelPipeline.memory[i], nullptr);
    }
 
