Index: vulkan-game.cpp
===================================================================
--- vulkan-game.cpp	(revision 5ea0a37095f83aa1eb8ad853b90c9675730b6782)
+++ vulkan-game.cpp	(revision 90880fb20c607160a5a48bacee6fd39c33e88e18)
@@ -77,16 +77,16 @@
                      , gui(nullptr)
                      , window(nullptr)
+                     , vp_mats_modelPipeline()
                      , objects_modelPipeline()
+                     , vp_mats_shipPipeline()
                      , objects_shipPipeline()
+                     , vp_mats_asteroidPipeline()
                      , objects_asteroidPipeline()
+                     , vp_mats_laserPipeline()
                      , objects_laserPipeline()
+                     , uniforms_explosionPipeline()
                      , objects_explosionPipeline()
                      , score(0)
                      , fps(0.0f) {
-   object_VP_mats = {};
-   ship_VP_mats = {};
-   asteroid_VP_mats = {};
-   laser_VP_mats = {};
-   explosion_UBO = {};
 }
 
@@ -110,12 +110,31 @@
    vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties);
 
+   vp_mats_modelPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
+                                                     deviceProperties.limits.minUniformBufferOffsetAlignment);
+
    objects_modelPipeline = VulkanBuffer<SSBO_ModelObject>(10, deviceProperties.limits.maxStorageBufferRange,
                                                           deviceProperties.limits.minStorageBufferOffsetAlignment);
+
+   vp_mats_shipPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
+                                                    deviceProperties.limits.minUniformBufferOffsetAlignment);
+
    objects_shipPipeline = VulkanBuffer<SSBO_ModelObject>(10, deviceProperties.limits.maxStorageBufferRange,
                                                          deviceProperties.limits.minStorageBufferOffsetAlignment);
+
+   vp_mats_asteroidPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
+                                                        deviceProperties.limits.minUniformBufferOffsetAlignment);
+
    objects_asteroidPipeline = VulkanBuffer<SSBO_Asteroid>(10, deviceProperties.limits.maxStorageBufferRange,
                                                           deviceProperties.limits.minStorageBufferOffsetAlignment);
+
+   vp_mats_laserPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
+                                                     deviceProperties.limits.minUniformBufferOffsetAlignment);
+
    objects_laserPipeline = VulkanBuffer<SSBO_Laser>(2, deviceProperties.limits.maxStorageBufferRange,
                                                     deviceProperties.limits.minStorageBufferOffsetAlignment);
+
+   uniforms_explosionPipeline = VulkanBuffer<UBO_Explosion>(1, deviceProperties.limits.maxUniformBufferRange,
+                                                            deviceProperties.limits.minUniformBufferOffsetAlignment);
+
    objects_explosionPipeline = VulkanBuffer<SSBO_Explosion>(2, deviceProperties.limits.maxStorageBufferRange,
                                                             deviceProperties.limits.minStorageBufferOffsetAlignment);
@@ -138,5 +157,5 @@
    modelPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex));
 
-   createBufferSet(sizeof(UBO_VP_mats),
+   createBufferSet(vp_mats_modelPipeline.memorySize(),
                    VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
@@ -208,5 +227,5 @@
    shipPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex));
 
-   createBufferSet(sizeof(UBO_VP_mats),
+   createBufferSet(vp_mats_shipPipeline.memorySize(),
                    VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
@@ -475,5 +494,5 @@
    asteroidPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex));
 
-   createBufferSet(sizeof(UBO_VP_mats),
+   createBufferSet(vp_mats_asteroidPipeline.memorySize(),
                    VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
@@ -500,5 +519,5 @@
    laserPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&LaserVertex::objIndex));
 
-   createBufferSet(sizeof(UBO_VP_mats),
+   createBufferSet(vp_mats_laserPipeline.memorySize(),
                    VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
@@ -527,5 +546,5 @@
    explosionPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ExplosionVertex::objIndex));
 
-   createBufferSet(sizeof(UBO_Explosion),
+   createBufferSet(uniforms_explosionPipeline.memorySize(),
                    VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
@@ -684,19 +703,4 @@
    projMat = perspective(radians(FOV_ANGLE), (float)swapChainExtent.width / (float)swapChainExtent.height, NEAR_CLIP, FAR_CLIP);
    projMat[1][1] *= -1; // flip the y-axis so that +y is up
-
-   object_VP_mats.view = viewMat;
-   object_VP_mats.proj = projMat;
-
-   ship_VP_mats.view = viewMat;
-   ship_VP_mats.proj = projMat;
-
-   asteroid_VP_mats.view = viewMat;
-   asteroid_VP_mats.proj = projMat;
-
-   laser_VP_mats.view = viewMat;
-   laser_VP_mats.proj = projMat;
-
-   explosion_UBO.view = viewMat;
-   explosion_UBO.proj = projMat;
 }
 
@@ -940,4 +944,34 @@
 // where it will run just once per frame
 void VulkanGame::updateScene() {
+
+   vp_mats_modelPipeline.data()->view = viewMat;
+   vp_mats_modelPipeline.data()->proj = projMat;
+
+   vp_mats_shipPipeline.data()->view = viewMat;
+   vp_mats_shipPipeline.data()->proj = projMat;
+
+   vp_mats_asteroidPipeline.data()->view = viewMat;
+   vp_mats_asteroidPipeline.data()->proj = projMat;
+
+   vp_mats_laserPipeline.data()->view = viewMat;
+   vp_mats_laserPipeline.data()->proj = projMat;
+
+   uniforms_explosionPipeline.data()->view = viewMat;
+   uniforms_explosionPipeline.data()->proj = projMat;
+   uniforms_explosionPipeline.data()->cur_time = curTime;
+
+   for (vector<BaseEffectOverTime*>::iterator it = effects.begin(); it != effects.end(); ) {
+      if ((*it)->deleted) {
+         delete *it;
+         it = effects.erase(it);
+      } else {
+         BaseEffectOverTime* eot = *it;
+
+         eot->applyEffect(curTime);
+
+         it++;
+      }
+   }
+
    if (curTime - lastSpawn_asteroid > spawnRate_asteroid) {
       lastSpawn_asteroid = curTime;
@@ -1046,4 +1080,7 @@
    }
 
+   VulkanUtils::copyDataToMemory(device, vp_mats_modelPipeline.data(), uniformBuffers_modelPipeline.memory[imageIndex],
+                                 0, vp_mats_modelPipeline.memorySize(), false);
+
    VulkanUtils::copyDataToMemory(device, objects_modelPipeline.data(), storageBuffers_modelPipeline.memory[imageIndex],
                                  0, objects_modelPipeline.memorySize(), false);
@@ -1066,4 +1103,7 @@
       obj.center = vec3(objData.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    }
+
+   VulkanUtils::copyDataToMemory(device, vp_mats_shipPipeline.data(), uniformBuffers_shipPipeline.memory[imageIndex],
+                                 0, vp_mats_shipPipeline.memorySize(), false);
 
    VulkanUtils::copyDataToMemory(device, objects_shipPipeline.data(), storageBuffers_shipPipeline.memory[imageIndex],
@@ -1111,4 +1151,7 @@
    }
 
+   VulkanUtils::copyDataToMemory(device, vp_mats_asteroidPipeline.data(), uniformBuffers_asteroidPipeline.memory[imageIndex],
+                                 0, vp_mats_asteroidPipeline.memorySize(), false);
+
    VulkanUtils::copyDataToMemory(device, objects_asteroidPipeline.data(), storageBuffers_asteroidPipeline.memory[imageIndex],
                                  0, objects_asteroidPipeline.memorySize(), false);
@@ -1137,4 +1180,7 @@
       obj.center = vec3(objData.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    }
+
+   VulkanUtils::copyDataToMemory(device, vp_mats_laserPipeline.data(), uniformBuffers_laserPipeline.memory[imageIndex],
+                                 0, vp_mats_laserPipeline.memorySize(), false);
 
    VulkanUtils::copyDataToMemory(device, objects_laserPipeline.data(), storageBuffers_laserPipeline.memory[imageIndex],
@@ -1164,36 +1210,9 @@
    }
 
+   VulkanUtils::copyDataToMemory(device, uniforms_explosionPipeline.data(), uniformBuffers_explosionPipeline.memory[imageIndex],
+                                 0, uniforms_explosionPipeline.memorySize(), false);
+
    VulkanUtils::copyDataToMemory(device, objects_explosionPipeline.data(), storageBuffers_explosionPipeline.memory[imageIndex],
                                  0, objects_explosionPipeline.memorySize(), false);
-
-   explosion_UBO.cur_time = curTime;
-
-   for (vector<BaseEffectOverTime*>::iterator it = effects.begin(); it != effects.end(); ) {
-      if ((*it)->deleted) {
-         delete *it;
-         it = effects.erase(it);
-      } else {
-         BaseEffectOverTime* eot = *it;
-
-         eot->applyEffect(curTime);
-
-         it++;
-      }
-   }
-
-   VulkanUtils::copyDataToMemory(device, &object_VP_mats, uniformBuffers_modelPipeline.memory[imageIndex], 0,
-                                 sizeof(object_VP_mats), false);
-
-   VulkanUtils::copyDataToMemory(device, &ship_VP_mats, uniformBuffers_shipPipeline.memory[imageIndex], 0,
-                                 sizeof(ship_VP_mats), false);
-
-   VulkanUtils::copyDataToMemory(device, &asteroid_VP_mats, uniformBuffers_asteroidPipeline.memory[imageIndex], 0,
-                                 sizeof(asteroid_VP_mats), false);
-
-   VulkanUtils::copyDataToMemory(device, &laser_VP_mats, uniformBuffers_laserPipeline.memory[imageIndex], 0,
-                                 sizeof(laser_VP_mats), false);
-
-   VulkanUtils::copyDataToMemory(device, &explosion_UBO, uniformBuffers_explosionPipeline.memory[imageIndex], 0,
-                                 sizeof(explosion_UBO), false);
 }
 
@@ -2234,5 +2253,5 @@
    createSyncObjects();
 
-   createBufferSet(sizeof(UBO_VP_mats),
+   createBufferSet(vp_mats_modelPipeline.memorySize(),
                    VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
@@ -2250,5 +2269,5 @@
    modelPipeline.createDescriptorSets(swapChainImages.size());
 
-   createBufferSet(sizeof(UBO_VP_mats),
+   createBufferSet(vp_mats_shipPipeline.memorySize(),
                    VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
@@ -2266,5 +2285,5 @@
    shipPipeline.createDescriptorSets(swapChainImages.size());
 
-   createBufferSet(sizeof(UBO_VP_mats),
+   createBufferSet(vp_mats_asteroidPipeline.memorySize(),
                    VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
@@ -2282,5 +2301,5 @@
    asteroidPipeline.createDescriptorSets(swapChainImages.size());
 
-   createBufferSet(sizeof(UBO_VP_mats),
+   createBufferSet(vp_mats_laserPipeline.memorySize(),
                    VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
@@ -2298,5 +2317,5 @@
    laserPipeline.createDescriptorSets(swapChainImages.size());
 
-   createBufferSet(sizeof(UBO_Explosion),
+   createBufferSet(uniforms_explosionPipeline.memorySize(),
                    VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
