Changeset f97c5e7 in opengl-game for vulkan-game.hpp


Ignore:
Timestamp:
Nov 22, 2019, 7:58:45 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
aa00bf2
Parents:
8e02b6b
Message:

Create an initGraphicsPipelines() function and templatize and generalize the createUniformBuffers() functionso it can be used to create a uniform buffer of any type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.hpp

    r8e02b6b rf97c5e7  
    8888      VkSampler textureSampler;
    8989
    90       vector<VkDescriptorBufferInfo> uniformBufferInfoList;
    91 
    9290      // These are currently to store the MVP matrix
    9391      // I should figure out if it makes sense to use them for other uniforms in the future
    9492      // If not, I should rename them to better indicate their purpose.
    95       // I should also decide if I can use these for all shaders, or if I need a separapte set of buffers for each one
    9693      vector<VkBuffer> uniformBuffers;
    9794      vector<VkDeviceMemory> uniformBuffersMemory;
     95
     96      vector<VkDescriptorBufferInfo> uniformBufferInfoList;
    9897
    9998      VulkanImage floorTextureImage;
     
    118117      bool initWindow(int width, int height, unsigned char guiFlags);
    119118      void initVulkan();
     119      void initGraphicsPipelines();
    120120      void initMatrices();
    121121      void mainLoop();
     
    143143      void createTextureSampler();
    144144      void createFramebuffers();
    145       void createUniformBuffers();
    146145      void createCommandBuffers();
    147146      void createSyncObjects();
     147
     148      template<class UniformType>
     149      void createUniformBuffers(vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory,
     150         vector<VkDescriptorBufferInfo>& bufferInfoList);
    148151
    149152      void recreateSwapChain();
     
    158161};
    159162
     163template<class UniformType>
     164void VulkanGame::createUniformBuffers(vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory,
     165      vector<VkDescriptorBufferInfo>& bufferInfoList) {
     166   buffers.resize(swapChainImages.size());
     167   buffersMemory.resize(swapChainImages.size());
     168   bufferInfoList.resize(swapChainImages.size());
     169
     170   for (size_t i = 0; i < swapChainImages.size(); i++) {
     171      VulkanUtils::createBuffer(device, physicalDevice, sizeof(UniformType), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     172         VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     173         buffers[i], buffersMemory[i]);
     174
     175      bufferInfoList[i].buffer = buffers[i];
     176      bufferInfoList[i].offset = 0;
     177      bufferInfoList[i].range = sizeof(UniformType);
     178   }
     179}
     180
    160181#endif // _VULKAN_GAME_H
Note: See TracChangeset for help on using the changeset viewer.