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


Ignore:
Timestamp:
Apr 19, 2020, 1:23:02 AM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
5ba732a
Parents:
6385d0f
Message:

Change VulkanGame::addObject() to return a reference to the newly-created object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.hpp

    r6385d0f r4994692  
    5151};
    5252
     53struct UBO_VP_mats {
     54   alignas(16) mat4 view;
     55   alignas(16) mat4 proj;
     56};
     57
     58struct SSBO_ModelObject {
     59   alignas(16) mat4 model;
     60};
     61
     62struct SSBO_Asteroid {
     63   alignas(16) mat4 model;
     64   alignas(4) float hp;
     65   alignas(4) unsigned int deleted;
     66};
     67
    5368// TODO: Change the index type to uint32_t and check the Vulkan Tutorial loading model section as a reference
    5469// TODO: Create a typedef for index type so I can easily change uin16_t to something else later
     70// TODO: Maybe create a typedef for each of the templated SceneObject types
    5571template<class VertexType, class SSBOType>
    5672struct SceneObject {
     
    6177   mat4 model_base;
    6278   mat4 model_transform;
     79
     80   // TODO: Figure out if I should make child classes that have these fields instead of putting them in the
     81   // parent class
    6382   vec3 center; // currently only matters for asteroids
    6483   float radius; // currently only matters for asteroids
    6584};
    6685
    67 struct UBO_VP_mats {
    68    alignas(16) mat4 view;
    69    alignas(16) mat4 proj;
    70 };
    71 
    72 struct SSBO_ModelObject {
    73    alignas(16) mat4 model;
    74 };
    75 
    76 struct SSBO_Asteroid {
    77    alignas(16) mat4 model;
    78    alignas(4) float hp;
    79    alignas(4) unsigned int deleted;
    80 };
    81 
    82 // Have to figure out how to include an optional ssbo parameter for each object
     86// TODO: Have to figure out how to include an optional ssbo parameter for each object
    8387// Could probably use the same approach to make indices optional
     88// Figure out if there are sufficient use cases to make either of these optional or is it fine to make
     89// them mamdatory
    8490
    8591class VulkanGame {
     
    131137      VkSampler textureSampler;
    132138
     139      VulkanImage sdlOverlayImage;
     140      VkDescriptorImageInfo sdlOverlayImageDescriptor;
     141
    133142      VulkanImage floorTextureImage;
    134143      VkDescriptorImageInfo floorTextureImageDescriptor;
    135 
    136       VulkanImage sdlOverlayImage;
    137       VkDescriptorImageInfo sdlOverlayImageDescriptor;
    138144
    139145      TTF_Font* font;
     
    230236      void createSyncObjects();
    231237
     238      // TODO: Since addObject() returns a reference to the new object now,
     239      // stop using objects.back() to access the object that was just created
    232240      template<class VertexType, class SSBOType>
    233       void addObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    234          GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
    235          const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo,
    236          bool pipelinesCreated);
     241      SceneObject<VertexType, SSBOType>& addObject(
     242            vector<SceneObject<VertexType, SSBOType>>& objects,
     243            GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
     244            const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo,
     245            bool pipelinesCreated);
    237246
    238247      template<class VertexType, class SSBOType>
    239248      void updateObject(vector<SceneObject<VertexType, SSBOType>>& objects,
    240          GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, size_t index);
     249            GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, size_t index);
    241250
    242251      template<class VertexType>
     
    250259
    251260      void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,
    252          vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, vector<VkDescriptorBufferInfo>& bufferInfoList);
     261            vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory,
     262            vector<VkDescriptorBufferInfo>& bufferInfoList);
    253263
    254264      void recreateSwapChain();
     
    272282// to account for scaling
    273283template<class VertexType, class SSBOType>
    274 void VulkanGame::addObject(vector<SceneObject<VertexType, SSBOType>>& objects,
     284SceneObject<VertexType, SSBOType>& VulkanGame::addObject(
     285      vector<SceneObject<VertexType, SSBOType>>& objects,
    275286      GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline,
    276287      const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo,
     
    289300   centerObject(obj);
    290301
    291    bool storageBufferResized = pipeline.addObject(obj.vertices, obj.indices, obj.ssbo, commandPool, graphicsQueue);
     302   bool storageBufferResized = pipeline.addObject(obj.vertices, obj.indices, obj.ssbo,
     303      this->commandPool, this->graphicsQueue);
    292304
    293305   if (pipelinesCreated) {
     
    307319      createCommandBuffers();
    308320   }
     321
     322   return obj;
    309323}
    310324
Note: See TracChangeset for help on using the changeset viewer.