Changeset 1abebc1 in opengl-game for vulkan-game.hpp


Ignore:
Timestamp:
May 19, 2021, 4:49:43 PM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
c163d81
Parents:
a3cefaa
Message:

Remove the storageBuffers parameter from addObject() since it is no longer used, rename StorageBufferSet, resizeStorageBufferSet(), and updateStorageuffer() to BufferSet, resizeBufferSet(), and updateBufferSet() respectively, and change updateObject() to just take a SceneObject reference.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.hpp

    ra3cefaa r1abebc1  
    103103// has a VkBuffer, VkDeviceMemory, and VkDescriptorBufferInfo
    104104// TODO: Maybe change the structure here since VkDescriptorBufferInfo already stores a reference to the VkBuffer
    105 struct StorageBufferSet {
     105struct BufferSet {
    106106   vector<VkBuffer> buffers;
    107107   vector<VkDeviceMemory> memory;
     
    317317      GraphicsPipeline_Vulkan<ExplosionVertex> explosionPipeline;
    318318
    319       StorageBufferSet storageBuffers_modelPipeline;
     319      BufferSet storageBuffers_modelPipeline;
    320320      VulkanBuffer<SSBO_ModelObject> objects_modelPipeline;
    321321
    322       StorageBufferSet storageBuffers_shipPipeline;
     322      BufferSet storageBuffers_shipPipeline;
    323323      VulkanBuffer<SSBO_ModelObject> objects_shipPipeline;
    324324
    325       StorageBufferSet storageBuffers_asteroidPipeline;
     325      BufferSet storageBuffers_asteroidPipeline;
    326326      VulkanBuffer<SSBO_Asteroid> objects_asteroidPipeline;
    327327
    328       StorageBufferSet storageBuffers_laserPipeline;
     328      BufferSet storageBuffers_laserPipeline;
    329329      VulkanBuffer<SSBO_Laser> objects_laserPipeline;
    330330
    331       StorageBufferSet storageBuffers_explosionPipeline;
     331      BufferSet storageBuffers_explosionPipeline;
    332332      VulkanBuffer<SSBO_Explosion> objects_explosionPipeline;
    333333
     
    454454      // TODO: Remove the need for templating, which is only there so a GraphicsPupeline_Vulkan can be passed in
    455455      template<class VertexType, class SSBOType>
    456       void resizeStorageBufferSet(StorageBufferSet& set, VulkanBuffer<SSBOType>& buffer,
    457                                   GraphicsPipeline_Vulkan<VertexType>& pipeline,
    458                                   VkCommandPool commandPool, VkQueue graphicsQueue);
     456      void resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,
     457                           GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,
     458                           VkQueue graphicsQueue);
    459459
    460460      template<class SSBOType>
    461       void updateStorageBuffer(StorageBufferSet& storageBufferSet, size_t objIndex, SSBOType& ssbo);
     461      void updateBufferSet(BufferSet& set, size_t objIndex, SSBOType& ssbo);
    462462
    463463      // TODO: Since addObject() returns a reference to the new object now,
     
    467467                                                   GraphicsPipeline_Vulkan<VertexType>& pipeline,
    468468                                                   const vector<VertexType>& vertices, vector<uint16_t> indices,
    469                                                    SSBOType ssbo, StorageBufferSet& storageBuffers);
     469                                                   SSBOType ssbo);
    470470
    471471      template<class VertexType>
     
    479479
    480480      template<class VertexType, class SSBOType>
    481       void updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    482             GraphicsPipeline_Vulkan<VertexType>& pipeline, size_t index);
     481      void updateObject(SceneObject<VertexType, SSBOType>& obj);
    483482
    484483      template<class VertexType, class SSBOType>
     
    522521
    523522template<class VertexType, class SSBOType>
    524 void VulkanGame::resizeStorageBufferSet(StorageBufferSet& set, VulkanBuffer<SSBOType>& buffer,
    525                                         GraphicsPipeline_Vulkan<VertexType>& pipeline,
    526                                         VkCommandPool commandPool, VkQueue graphicsQueue) {
     523void VulkanGame::resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,
     524                                 GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,
     525                                 VkQueue graphicsQueue) {
    527526   size_t numObjects = buffer.numObjects < buffer.capacity ? buffer.numObjects : buffer.capacity;
    528527
     
    563562// TODO: See if it makes sense to pass in the current swapchain index instead of updating all of them
    564563template<class SSBOType>
    565 void VulkanGame::updateStorageBuffer(StorageBufferSet& storageBufferSet, size_t objIndex, SSBOType& ssbo) {
    566    for (size_t i = 0; i < storageBufferSet.memory.size(); i++) {
    567       VulkanUtils::copyDataToMemory(device, ssbo, storageBufferSet.memory[i], objIndex * sizeof(SSBOType));
     564void VulkanGame::updateBufferSet(BufferSet& set, size_t objIndex, SSBOType& ssbo) {
     565   for (size_t i = 0; i < set.memory.size(); i++) {
     566      VulkanUtils::copyDataToMemory(device, ssbo, set.memory[i], objIndex * sizeof(SSBOType));
    568567   }
    569568}
     
    576575                                                         GraphicsPipeline_Vulkan<VertexType>& pipeline,
    577576                                                         const vector<VertexType>& vertices, vector<uint16_t> indices,
    578                                                          SSBOType ssbo, StorageBufferSet& storageBuffers) {
     577                                                         SSBOType ssbo) {
    579578   // TODO: Use the model field of ssbo to set the object's model_base
    580579   // currently, the passed in model is useless since it gets overridden in updateObject() anyway
     
    684683// TODO: Just pass in the single object instead of a list of all of them
    685684template<class VertexType, class SSBOType>
    686 void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    687       GraphicsPipeline_Vulkan<VertexType>& pipeline, size_t index) {
    688    SceneObject<VertexType, SSBOType>& obj = objects[index];
    689 
     685void VulkanGame::updateObject(SceneObject<VertexType, SSBOType>& obj) {
    690686   obj.ssbo.model = obj.model_transform * obj.model_base;
    691687   obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
Note: See TracChangeset for help on using the changeset viewer.