Changeset 603b5bc in opengl-game for vulkan-ref.cpp


Ignore:
Timestamp:
Oct 22, 2019, 7:53:48 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
34bdf3a
Parents:
e83b155
git-author:
Dmitry Portnoy <dmitry.portnoy@…> (10/22/19 19:10:44)
git-committer:
Dmitry Portnoy <dmitry.portnoy@…> (10/22/19 19:53:48)
Message:

In vulkangame, add code to create the frame buffers and command buffers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-ref.cpp

    re83b155 r603b5bc  
    178178      vector<VkImage> swapChainImages;
    179179      VkFormat swapChainImageFormat;
    180 /*** END OF REFACTORED CODE ***/
    181       // (This was taken out of vulkan-game for now and replaced with Viewport)
    182       // It will definitely be needed when creating command buffers and I could use it in a few other places
    183       // TODO: Check above ^
    184180      VkExtent2D swapChainExtent;
    185 /*** START OF REFACTORED CODE ***/
    186181      vector<VkImageView> swapChainImageViews;
    187 /*** END OF REFACTORED CODE ***/
    188182      vector<VkFramebuffer> swapChainFramebuffers;
    189183
    190 /*** START OF REFACTORED CODE ***/
    191184      VkRenderPass renderPass;
    192185
    193186      VkCommandPool commandPool;
    194 /*** END OF REFACTORED CODE ***/
    195187      vector<VkCommandBuffer> commandBuffers;
    196188
    197 /*** START OF REFACTORED CODE ***/
    198189      // The images and the sampler are used to store data for specific attributes. I probably
    199190      // want to keep them separate from the GraphicsPipelineInfo objects and start passing
     
    203194      VkDeviceMemory depthImageMemory;
    204195      VkImageView depthImageView;
    205 /*** END OF REFACTORED CODE ***/
    206196
    207197      VkImage textureImage;
     
    213203      VkImageView sdlOverlayImageView;
    214204
    215 /*** START OF REFACTORED CODE ***/
    216205      VkSampler textureSampler;
    217206
     
    222211      vector<VkBuffer> uniformBuffers;
    223212      vector<VkDeviceMemory> uniformBuffersMemory;
    224 /*** END OF REFACTORED CODE ***/
    225213
    226214      VkDescriptorImageInfo sceneImageInfo;
    227215      VkDescriptorImageInfo overlayImageInfo;
    228216
    229 /*** START OF REFACTORED CODE ***/
    230217      vector<VkDescriptorBufferInfo> uniformBufferInfoList;
    231 /*** END OF REFACTORED CODE ***/
    232218
    233219      GraphicsPipelineInfo scenePipeline;
    234220      GraphicsPipelineInfo overlayPipeline;
     221/*** END OF REFACTORED CODE ***/
    235222
    236223      vector<VkSemaphore> imageAvailableSemaphores;
     
    339326
    340327         createCommandPool();
    341 /*** END OF REFACTORED CODE ***/
    342328
    343329         createImageResources("textures/texture.jpg", textureImage, textureImageMemory, textureImageView);
    344 /*** START OF REFACTORED CODE ***/
    345330         createImageResourcesFromSDLTexture(uiOverlay, sdlOverlayImage, sdlOverlayImageMemory, sdlOverlayImageView);
    346331         createTextureSampler();
     
    413398
    414399         createDescriptorSetLayout(overlayPipeline);
     400
     401         createBufferResources();
    415402/*** END OF REFACTORED CODE ***/
    416 
    417          createBufferResources();
    418403
    419404         createSyncObjects();
     
    818803         }
    819804      }
    820 /*** END OF REFACTORED CODE ***/
    821805
    822806      void initGraphicsPipelineInfo(GraphicsPipelineInfo& info,
    823807            const void* vertexData, int vertexSize, size_t numVertices,
    824808            const void* indexData, int indexSize, size_t numIndices) {
    825 /*** START OF REFACTORED CODE ***/
    826809         // Since there is only one array of vertex data, we use binding = 0
    827810         // I'll probably do that for the foreseeable future
     
    1015998         vkDestroyShaderModule(device, fragShaderModule, nullptr);
    1016999      }
    1017 /*** END OF REFACTORED CODE ***/
    10181000
    10191001      VkShaderModule createShaderModule(const vector<char>& code) {
     
    10351017
    10361018         for (size_t i = 0; i < swapChainImageViews.size(); i++) {
    1037             array <VkImageView, 2> attachments = {
     1019            array<VkImageView, 2> attachments = {
    10381020               swapChainImageViews[i],
    10391021               depthImageView
     
    10551037      }
    10561038
    1057 /*** START OF REFACTORED CODE ***/
    10581039      void createCommandPool() {
    10591040         QueueFamilyIndices queueFamilyIndices = findQueueFamilies(physicalDevice);
     
    11001081         return indices;
    11011082      }
    1102 /*** END OF REFACTORED CODE ***/
    11031083
    11041084      void createDepthResources() {
     
    11121092      }
    11131093
    1114 /*** START OF REFACTORED CODE ***/
    11151094      VkFormat findDepthFormat() {
    11161095         return findSupportedFormat(
     
    12391218      }
    12401219
     1220/*** START OF REFACTORED CODE ***/
    12411221      void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage,
    12421222            VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
     
    13641344      }
    13651345
    1366 /*** START OF REFACTORED CODE ***/
    13671346      VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags) {
    13681347         VkImageViewCreateInfo viewInfo = {};
     
    16491628         }
    16501629      }
    1651 /*** END OF REFACTORED CODE ***/
    16521630
    16531631      void createCommandBuffers() {
     
    16901668            vkCmdBeginRenderPass(commandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
    16911669
     1670/*** END OF REFACTORED CODE ***/
    16921671            createGraphicsPipelineCommands(scenePipeline, i);
    16931672            createGraphicsPipelineCommands(overlayPipeline, i);
     1673/*** START OF REFACTORED CODE ***/
    16941674
    16951675            vkCmdEndRenderPass(commandBuffers[i]);
     
    17051685         vkCmdBindDescriptorSets(commandBuffers[currentImage], VK_PIPELINE_BIND_POINT_GRAPHICS, info.pipelineLayout, 0, 1,
    17061686            &info.descriptorSets[currentImage], 0, nullptr);
     1687/*** END OF REFACTORED CODE ***/
    17071688
    17081689         VkBuffer vertexBuffers[] = { info.vertexBuffer };
     
    17131694
    17141695         vkCmdDrawIndexed(commandBuffers[currentImage], static_cast<uint32_t>(info.numIndices), 1, 0, 0, 0);
    1715       }
     1696/*** START OF REFACTORED CODE ***/
     1697      }
     1698/*** END OF REFACTORED CODE ***/
    17161699
    17171700      void createSyncObjects() {
     
    19551938      }
    19561939
     1940/*** START OF REFACTORED CODE ***/
    19571941      void createBufferResources() {
    1958          // TODO: The three functions below will be called in vulkan-game following the
    1959          // pipeline creation (createDescriptorSets()), and before createCommandBuffers()
    19601942         createDepthResources();
    19611943         createFramebuffers();
    19621944         createUniformBuffers();
    19631945
    1964 /*** START OF REFACTORED CODE ***/
    19651946         createGraphicsPipeline("shaders/scene-vert.spv", "shaders/scene-frag.spv", scenePipeline);
    19661947         createDescriptorPool(scenePipeline);
     
    19701951         createDescriptorPool(overlayPipeline);
    19711952         createDescriptorSets(overlayPipeline);
    1972 /*** END OF REFACTORED CODE ***/
    19731953
    19741954         createCommandBuffers();
     
    19761956
    19771957      void cleanup() {
    1978 /*** START OF REFACTORED CODE ***/
    19791958         cleanupSwapChain();
    19801959
     
    20422021
    20432022      void cleanupSwapChain() {
    2044 /*** END OF REFACTORED CODE ***/
    20452023         vkDestroyImageView(device, depthImageView, nullptr);
    20462024         vkDestroyImage(device, depthImage, nullptr);
     
    20532031         vkFreeCommandBuffers(device, commandPool, static_cast<uint32_t>(commandBuffers.size()), commandBuffers.data());
    20542032
    2055 /*** START OF REFACTORED CODE ***/
    20562033         cleanupPipeline(scenePipeline);
    20572034         cleanupPipeline(overlayPipeline);
Note: See TracChangeset for help on using the changeset viewer.