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


Ignore:
Timestamp:
May 19, 2021, 4:49:43 PM (4 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
  • sdl-game.hpp

    ra3cefaa r1abebc1  
    7979// has a VkBuffer, VkDeviceMemory, and VkDescriptorBufferInfo
    8080// TODO: Maybe change the structure here since VkDescriptorBufferInfo already stores a reference to the VkBuffer
    81 struct StorageBufferSet {
     81struct BufferSet {
    8282   vector<VkBuffer> buffers;
    8383   vector<VkDeviceMemory> memory;
     
    220220      GraphicsPipeline_Vulkan<ModelVertex> modelPipeline;
    221221
    222       StorageBufferSet storageBuffers_modelPipeline;
     222      BufferSet storageBuffers_modelPipeline;
    223223      VulkanBuffer<SSBO_ModelObject> objects_modelPipeline;
    224224
     
    299299      // TODO: Remove the need for templating, which is only there so a GraphicsPupeline_Vulkan can be passed in
    300300      template<class VertexType, class SSBOType>
    301       void resizeStorageBufferSet(StorageBufferSet& set, VulkanBuffer<SSBOType>& buffer,
    302                                   GraphicsPipeline_Vulkan<VertexType>& pipeline,
    303                                   VkCommandPool commandPool, VkQueue graphicsQueue);
     301      void resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,
     302                           GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,
     303                           VkQueue graphicsQueue);
    304304
    305305      template<class SSBOType>
    306       void updateStorageBuffer(StorageBufferSet& storageBufferSet, size_t objIndex, SSBOType& ssbo);
     306      void updateBufferSet(BufferSet& set, size_t objIndex, SSBOType& ssbo);
    307307
    308308      // TODO: Since addObject() returns a reference to the new object now,
     
    312312                                                   GraphicsPipeline_Vulkan<VertexType>& pipeline,
    313313                                                   const vector<VertexType>& vertices, vector<uint16_t> indices,
    314                                                    SSBOType ssbo, StorageBufferSet& storageBuffers);
     314                                                   SSBOType ssbo);
    315315
    316316      template<class VertexType>
     
    324324
    325325      template<class VertexType, class SSBOType>
    326       void updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    327                         GraphicsPipeline_Vulkan<VertexType>& pipeline, size_t index);
     326      void updateObject(SceneObject<VertexType, SSBOType>& obj);
    328327
    329328      void renderFrame(ImDrawData* draw_data);
     
    347346
    348347template<class VertexType, class SSBOType>
    349 void VulkanGame::resizeStorageBufferSet(StorageBufferSet& set, VulkanBuffer<SSBOType>& buffer,
    350                                         GraphicsPipeline_Vulkan<VertexType>& pipeline,
    351                                         VkCommandPool commandPool, VkQueue graphicsQueue) {
     348void VulkanGame::resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,
     349                                 GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,
     350                                 VkQueue graphicsQueue) {
    352351   size_t numObjects = buffer.numObjects < buffer.capacity ? buffer.numObjects : buffer.capacity;
    353352
     
    388387// TODO: See if it makes sense to pass in the current swapchain index instead of updating all of them
    389388template<class SSBOType>
    390 void VulkanGame::updateStorageBuffer(StorageBufferSet& storageBufferSet, size_t objIndex, SSBOType& ssbo) {
    391    for (size_t i = 0; i < storageBufferSet.memory.size(); i++) {
    392       VulkanUtils::copyDataToMemory(device, ssbo, storageBufferSet.memory[i], objIndex * sizeof(SSBOType));
     389void VulkanGame::updateBufferSet(BufferSet& set, size_t objIndex, SSBOType& ssbo) {
     390   for (size_t i = 0; i < set.memory.size(); i++) {
     391      VulkanUtils::copyDataToMemory(device, ssbo, set.memory[i], objIndex * sizeof(SSBOType));
    393392   }
    394393}
     
    401400                                                         GraphicsPipeline_Vulkan<VertexType>& pipeline,
    402401                                                         const vector<VertexType>& vertices, vector<uint16_t> indices,
    403                                                          SSBOType ssbo, StorageBufferSet& storageBuffers) {
     402                                                         SSBOType ssbo) {
    404403   // TODO: Use the model field of ssbo to set the object's model_base
    405404   // currently, the passed in model is useless since it gets overridden in updateObject() anyway
     
    504503// TODO: Just pass in the single object instead of a list of all of them
    505504template<class VertexType, class SSBOType>
    506 void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    507                               GraphicsPipeline_Vulkan<VertexType>& pipeline, size_t index) {
    508    SceneObject<VertexType, SSBOType>& obj = objects[index];
    509 
     505void VulkanGame::updateObject(SceneObject<VertexType, SSBOType>& obj) {
    510506   obj.ssbo.model = obj.model_transform * obj.model_base;
    511507   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.