Changeset 0fe8433 in opengl-game for vulkan-game.hpp


Ignore:
Timestamp:
Dec 24, 2019, 2:57:03 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
3e8cc8b
Parents:
cd1cb0f
Message:

Create an addObject() method in VulkanGame (which wraps the old addObject() method in GraphicsPipeline_Vulkan), and move the list of objects and other code to manage objects from the pipeline to the VulkanGame class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.hpp

    rcd1cb0f r0fe8433  
    4040};
    4141
     42// TODO: Change the index type to uint32_t and check the Vulkan Tutorial loading model section as a reference
     43// TODO: Create a typedef for index type so I can easily change uin16_t to something else later
     44template<class VertexType>
     45struct SceneObject {
     46   vector<VertexType> vertices;
     47   vector<uint16_t> indices;
     48
     49   mat4 model_base;
     50   mat4 model_transform;
     51};
     52
    4253struct UBO_VP_mats {
    4354   alignas(16) mat4 view;
     
    6576      vec3 cam_pos;
    6677
    67       UBO_VP_mats object_VP_mats;
    68       SBO_SceneObject so_Object;
    69 
    70       UBO_VP_mats ship_VP_mats;
    71       SBO_SceneObject so_Ship;
    72 
    7378      GameGui* gui;
    74 
    75       GraphicsPipeline_Vulkan<ModelVertex> modelPipeline;
    76       GraphicsPipeline_Vulkan<OverlayVertex> overlayPipeline;
    77       GraphicsPipeline_Vulkan<ShipVertex> shipPipeline;
    7879
    7980      SDL_version sdlVersion;
     
    107108      VkSampler textureSampler;
    108109
    109       // TODO: I should probably rename the uniformBuffer* and storageBuffer*
    110       // variables to better reflect the data they hold
    111 
    112       vector<VkBuffer> uniformBuffers_scenePipeline;
    113       vector<VkDeviceMemory> uniformBuffersMemory_scenePipeline;
    114 
    115       vector<VkDescriptorBufferInfo> uniformBufferInfoList_scenePipeline;
    116 
    117       vector<VkBuffer> storageBuffers_scenePipeline;
    118       vector<VkDeviceMemory> storageBuffersMemory_scenePipeline;
    119 
    120       vector<VkDescriptorBufferInfo> storageBufferInfoList_scenePipeline;
    121 
    122       vector<VkBuffer> uniformBuffers_shipPipeline;
    123       vector<VkDeviceMemory> uniformBuffersMemory_shipPipeline;
    124 
    125       vector<VkDescriptorBufferInfo> uniformBufferInfoList_shipPipeline;
    126 
    127       vector<VkBuffer> storageBuffers_shipPipeline;
    128       vector<VkDeviceMemory> storageBuffersMemory_shipPipeline;
    129 
    130       vector<VkDescriptorBufferInfo> storageBufferInfoList_shipPipeline;
    131 
    132110      VulkanImage floorTextureImage;
    133111      VkDescriptorImageInfo floorTextureImageDescriptor;
     
    148126
    149127      bool framebufferResized;
     128
     129      // TODO: I should probably rename the uniformBuffer* and storageBuffer*
     130      // variables to better reflect the data they hold
     131
     132      GraphicsPipeline_Vulkan<OverlayVertex> overlayPipeline;
     133
     134      vector<SceneObject<OverlayVertex>> overlayObjects;
     135
     136      // TODO: Rename all the variables related to modelPipeline to use the same pipelie name
     137
     138      GraphicsPipeline_Vulkan<ModelVertex> modelPipeline;
     139
     140      vector<SceneObject<ModelVertex>> modelObjects;
     141
     142      vector<VkBuffer> uniformBuffers_scenePipeline;
     143      vector<VkDeviceMemory> uniformBuffersMemory_scenePipeline;
     144
     145      vector<VkDescriptorBufferInfo> uniformBufferInfoList_scenePipeline;
     146
     147      vector<VkBuffer> storageBuffers_scenePipeline;
     148      vector<VkDeviceMemory> storageBuffersMemory_scenePipeline;
     149
     150      vector<VkDescriptorBufferInfo> storageBufferInfoList_scenePipeline;
     151
     152      UBO_VP_mats object_VP_mats;
     153      SBO_SceneObject so_Object;
     154
     155      GraphicsPipeline_Vulkan<ShipVertex> shipPipeline;
     156
     157      vector<SceneObject<ShipVertex>> shipObjects;
     158
     159      vector<VkBuffer> uniformBuffers_shipPipeline;
     160      vector<VkDeviceMemory> uniformBuffersMemory_shipPipeline;
     161
     162      vector<VkDescriptorBufferInfo> uniformBufferInfoList_shipPipeline;
     163
     164      vector<VkBuffer> storageBuffers_shipPipeline;
     165      vector<VkDeviceMemory> storageBuffersMemory_shipPipeline;
     166
     167      vector<VkDescriptorBufferInfo> storageBufferInfoList_shipPipeline;
     168
     169      UBO_VP_mats ship_VP_mats;
     170      SBO_SceneObject so_Ship;
    150171
    151172      bool initWindow(int width, int height, unsigned char guiFlags);
     
    181202
    182203      template<class VertexType>
     204      void addObject(vector<SceneObject<VertexType>>& objects, GraphicsPipeline_Vulkan<VertexType>& pipeline,
     205         const vector<VertexType>& vertices, vector<uint16_t> indices);
     206
     207      template<class VertexType>
    183208      vector<VertexType> addVertexNormals(vector<VertexType> vertices);
    184209
     
    205230            void* pUserData);
    206231};
     232
     233template<class VertexType>
     234void VulkanGame::addObject(vector<SceneObject<VertexType>>& objects, GraphicsPipeline_Vulkan<VertexType>& pipeline,
     235      const vector<VertexType>& vertices, vector<uint16_t> indices) {
     236   size_t numVertices = pipeline.getNumVertices();
     237
     238   for (uint16_t& idx : indices) {
     239      idx += numVertices;
     240   }
     241
     242   objects.push_back({ vertices, indices, mat4(1.0f), mat4(1.0f) });
     243
     244   pipeline.addVertices(vertices, indices, commandPool, graphicsQueue);
     245}
    207246
    208247template<class VertexType>
Note: See TracChangeset for help on using the changeset viewer.