Index: vulkan-ref.cpp
===================================================================
--- vulkan-ref.cpp	(revision 771b33a137aed1be0c097e401feb8e3727bb1166)
+++ vulkan-ref.cpp	(revision b79417880394af692ba165be4054f0843fdb1c91)
@@ -80,4 +80,5 @@
 };
 
+/*** START OF REFACTORED CODE ***/
 struct DescriptorInfo {
    VkDescriptorType type;
@@ -87,6 +88,8 @@
    VkDescriptorImageInfo* imageData;
 };
+/*** END OF REFACTORED CODE ***/
 
 struct GraphicsPipelineInfo {
+/*** START OF REFACTORED CODE ***/
    VkPipelineLayout pipelineLayout;
    VkPipeline pipeline;
@@ -100,4 +103,5 @@
    VkDescriptorSetLayout descriptorSetLayout;
    vector<VkDescriptorSet> descriptorSets;
+/*** END OF REFACTORED CODE ***/
 
    size_t numVertices; // Currently unused
@@ -153,6 +157,6 @@
       SDL_Window* window = nullptr;
       SDL_Renderer* gRenderer = nullptr;
-/*** END OF REFACTORED CODE ***/
       SDL_Texture* uiOverlay = nullptr;
+/*** END OF REFACTORED CODE ***/
 
       TTF_Font* gFont = nullptr;
@@ -176,5 +180,6 @@
 /*** END OF REFACTORED CODE ***/
       // (This was taken out of vulkan-game for now and replaced with Viewport)
-      // It will definitely be needed when creating render passes and I could use it in a few other places
+      // It will definitely be needed when creating command buffers and I could use it in a few other places
+      // TODO: Check above ^
       VkExtent2D swapChainExtent;
 /*** START OF REFACTORED CODE ***/
@@ -190,4 +195,5 @@
       vector<VkCommandBuffer> commandBuffers;
 
+/*** START OF REFACTORED CODE ***/
       // The images and the sampler are used to store data for specific attributes. I probably
       // want to keep them separate from the GraphicsPipelineInfo objects and start passing
@@ -197,4 +203,5 @@
       VkDeviceMemory depthImageMemory;
       VkImageView depthImageView;
+/*** END OF REFACTORED CODE ***/
 
       VkImage textureImage;
@@ -202,25 +209,25 @@
       VkImageView textureImageView;
 
-      VkImage overlayImage;
-      VkDeviceMemory overlayImageMemory;
-      VkImageView overlayImageView;
-
       VkImage sdlOverlayImage;
       VkDeviceMemory sdlOverlayImageMemory;
       VkImageView sdlOverlayImageView;
 
+/*** START OF REFACTORED CODE ***/
       VkSampler textureSampler;
 
       // These are currently to store the MVP matrix
       // I should figure out if it makes sense to use them for other uniforms in the future
-      // If not, I should rename them to better indicate their puprose.
+      // If not, I should rename them to better indicate their purpose.
       // I should also decide if I can use these for all shaders, or if I need a separapte set of buffers for each one
       vector<VkBuffer> uniformBuffers;
       vector<VkDeviceMemory> uniformBuffersMemory;
+/*** END OF REFACTORED CODE ***/
 
       VkDescriptorImageInfo sceneImageInfo;
       VkDescriptorImageInfo overlayImageInfo;
 
+/*** START OF REFACTORED CODE ***/
       vector<VkDescriptorBufferInfo> uniformBufferInfoList;
+/*** END OF REFACTORED CODE ***/
 
       GraphicsPipelineInfo scenePipeline;
@@ -257,5 +264,4 @@
             return RTWO_ERROR;
          }
-/*** END OF REFACTORED CODE ***/
 
          SDL_VERSION(&sdlVersion);
@@ -277,4 +283,5 @@
             cout << "Unable to set texture blend mode! SDL Error: " << SDL_GetError() << endl;
          }
+/*** END OF REFACTORED CODE ***/
 
          gFont = TTF_OpenFont("fonts/lazy.ttf", 28);
@@ -334,8 +341,6 @@
 /*** END OF REFACTORED CODE ***/
 
-         // THIS SECTION IS WHERE TEXTURES ARE CREATED, MAYBE SPLIT IT OFF INTO A SEPARATE FUNCTION
-         // MAY WANT TO CREATE A STRUCT TO HOLD SIMILAR VARIABLES< LIKE THOSE FOR A TEXTURE
-
          createImageResources("textures/texture.jpg", textureImage, textureImageMemory, textureImageView);
+/*** START OF REFACTORED CODE ***/
          createImageResourcesFromSDLTexture(uiOverlay, sdlOverlayImage, sdlOverlayImageMemory, sdlOverlayImageView);
          createTextureSampler();
@@ -350,4 +355,5 @@
          overlayImageInfo.imageView = sdlOverlayImageView;
          overlayImageInfo.sampler = textureSampler;
+/*** END OF REFACTORED CODE ***/
 
          // SHADER-SPECIFIC STUFF STARTS HERE
@@ -377,5 +383,4 @@
          addAttributeDescription(scenePipeline, VK_FORMAT_R32G32B32_SFLOAT, offset_of(&Vertex::color));
          addAttributeDescription(scenePipeline, VK_FORMAT_R32G32_SFLOAT, offset_of(&Vertex::texCoord));
-/*** END OF REFACTORED CODE ***/
 
          addDescriptorInfo(scenePipeline, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList, nullptr);
@@ -383,4 +388,5 @@
 
          createDescriptorSetLayout(scenePipeline);
+/*** END OF REFACTORED CODE ***/
 
          numPlanes = 2;
@@ -403,9 +409,9 @@
          addAttributeDescription(overlayPipeline, VK_FORMAT_R32G32B32_SFLOAT, offset_of(&OverlayVertex::pos));
          addAttributeDescription(overlayPipeline, VK_FORMAT_R32G32_SFLOAT, offset_of(&OverlayVertex::texCoord));
-/*** END OF REFACTORED CODE ***/
 
          addDescriptorInfo(overlayPipeline, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr, &overlayImageInfo);
 
          createDescriptorSetLayout(overlayPipeline);
+/*** END OF REFACTORED CODE ***/
 
          createBufferResources();
@@ -847,4 +853,5 @@
       }
 
+/*** START OF REFACTORED CODE ***/
       void addDescriptorInfo(GraphicsPipelineInfo& info, VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData, VkDescriptorImageInfo* imageData) {
          info.descriptorInfoList.push_back({ type, stageFlags, bufferData, imageData });
@@ -873,5 +880,4 @@
 
       void createGraphicsPipeline(string vertShaderFile, string fragShaderFile, GraphicsPipelineInfo& info) {
-/*** START OF REFACTORED CODE ***/
          vector<char> vertShaderCode = readFile(vertShaderFile);
          vector<char> fragShaderCode = readFile(fragShaderFile);
@@ -977,5 +983,4 @@
          pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
          pipelineLayoutInfo.setLayoutCount = 1;
-/*** END OF REFACTORED CODE ***/
          pipelineLayoutInfo.pSetLayouts = &info.descriptorSetLayout;
          pipelineLayoutInfo.pushConstantRangeCount = 0;
@@ -1007,9 +1012,8 @@
          }
 
-/*** START OF REFACTORED CODE ***/
          vkDestroyShaderModule(device, vertShaderModule, nullptr);
          vkDestroyShaderModule(device, fragShaderModule, nullptr);
-/*** END OF REFACTORED CODE ***/
-      }
+      }
+/*** END OF REFACTORED CODE ***/
 
       VkShaderModule createShaderModule(const vector<char>& code) {
@@ -1134,5 +1138,4 @@
          throw runtime_error("failed to find supported format!");
       }
-/*** END OF REFACTORED CODE ***/
 
       bool hasStencilComponent(VkFormat format) {
@@ -1191,4 +1194,5 @@
          view = createImageView(image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT);
       }
+/*** END OF REFACTORED CODE ***/
 
       void populateImageFromSDLTexture(SDL_Texture* texture, VkImage& image) {
@@ -1386,5 +1390,4 @@
          return imageView;
       }
-/*** END OF REFACTORED CODE ***/
 
       void createTextureSampler() {
@@ -1413,4 +1416,5 @@
          }
       }
+/*** END OF REFACTORED CODE ***/
 
       void createVertexBuffer(GraphicsPipelineInfo& info, const void* vertexData, int vertexSize) {
@@ -1462,4 +1466,5 @@
       }
 
+/*** START OF REFACTORED CODE ***/
       void createUniformBuffers() {
          VkDeviceSize bufferSize = sizeof(UniformBufferObject);
@@ -1505,4 +1510,5 @@
          vkBindBufferMemory(device, buffer, bufferMemory, 0);
       }
+/*** END OF REFACTORED CODE ***/
 
       void copyDataToBuffer(const void* srcData, VkBuffer dst, VkDeviceSize dstOffset, VkDeviceSize dataSize) {
@@ -1567,4 +1573,5 @@
       }
 
+/*** START OF REFACTORED CODE ***/
       uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties) {
          VkPhysicalDeviceMemoryProperties memProperties;
@@ -1642,4 +1649,5 @@
          }
       }
+/*** END OF REFACTORED CODE ***/
 
       void createCommandBuffers() {
@@ -1948,14 +1956,20 @@
 
       void createBufferResources() {
+         // TODO: The three functions below will be called in vulkan-game following the
+         // pipeline creation (createDescriptorSets()), and before createCommandBuffers()
          createDepthResources();
          createFramebuffers();
          createUniformBuffers();
 
+/*** START OF REFACTORED CODE ***/
          createGraphicsPipeline("shaders/scene-vert.spv", "shaders/scene-frag.spv", scenePipeline);
          createDescriptorPool(scenePipeline);
+/*** END OF REFACTORED CODE ***/
          createDescriptorSets(scenePipeline);
 
+/*** START OF REFACTORED CODE ***/
          createGraphicsPipeline("shaders/overlay-vert.spv", "shaders/overlay-frag.spv", overlayPipeline);
          createDescriptorPool(overlayPipeline);
+/*** END OF REFACTORED CODE ***/
          createDescriptorSets(overlayPipeline);
 
@@ -1963,6 +1977,6 @@
       }
 
-/*** START OF REFACTORED CODE ***/
       void cleanup() {
+/*** START OF REFACTORED CODE ***/
          cleanupSwapChain();
 /*** END OF REFACTORED CODE ***/
@@ -1974,14 +1988,12 @@
          vkFreeMemory(device, textureImageMemory, nullptr);
 
-         vkDestroyImageView(device, overlayImageView, nullptr);
-         vkDestroyImage(device, overlayImage, nullptr);
-         vkFreeMemory(device, overlayImageMemory, nullptr);
-
          vkDestroyImageView(device, sdlOverlayImageView, nullptr);
          vkDestroyImage(device, sdlOverlayImage, nullptr);
          vkFreeMemory(device, sdlOverlayImageMemory, nullptr);
 
+/*** START OF REFACTORED CODE ***/
          cleanupPipelineBuffers(scenePipeline);
          cleanupPipelineBuffers(overlayPipeline);
+ /*** END OF REFACTORED CODE ***/
 
          for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
@@ -2001,5 +2013,4 @@
 
          vkDestroyInstance(instance, nullptr);
-/*** END OF REFACTORED CODE ***/
 
          // TODO: Check if any of these functions accept null parameters
@@ -2010,4 +2021,5 @@
             uiOverlay = nullptr;
          }
+/*** END OF REFACTORED CODE ***/
 
          TTF_CloseFont(gFont);
@@ -2045,8 +2057,8 @@
          vkFreeCommandBuffers(device, commandPool, static_cast<uint32_t>(commandBuffers.size()), commandBuffers.data());
 
+/*** START OF REFACTORED CODE ***/
          cleanupPipeline(scenePipeline);
          cleanupPipeline(overlayPipeline);
 
-/*** START OF REFACTORED CODE ***/
          vkDestroyRenderPass(device, renderPass, nullptr);
 
@@ -2062,8 +2074,7 @@
             vkFreeMemory(device, uniformBuffersMemory[i], nullptr);
          }
-/*** START OF REFACTORED CODE ***/
-      }
-/*** END OF REFACTORED CODE ***/
-
+      }
+
+/*** START OF REFACTORED CODE ***/
       void cleanupPipeline(GraphicsPipelineInfo& pipeline) {
          vkDestroyPipeline(device, pipeline.pipeline, nullptr);
@@ -2071,7 +2082,10 @@
          vkDestroyPipelineLayout(device, pipeline.pipelineLayout, nullptr);
       }
+/*** END OF REFACTORED CODE ***/
 
       void cleanupPipelineBuffers(GraphicsPipelineInfo& pipeline) {
+/*** START OF REFACTORED CODE ***/
          vkDestroyDescriptorSetLayout(device, pipeline.descriptorSetLayout, nullptr);
+/*** END OF REFACTORED CODE ***/
 
          vkDestroyBuffer(device, pipeline.vertexBuffer, nullptr);
