Changeset 0fe8433 in opengl-game
- Timestamp:
- Dec 24, 2019, 2:57:03 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 3e8cc8b
- Parents:
- cd1cb0f
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
graphics-pipeline_vulkan.hpp
rcd1cb0f r0fe8433 29 29 vector<VkDescriptorBufferInfo>* bufferDataList; 30 30 VkDescriptorImageInfo* imageData; 31 };32 33 // TODO: Change the index type to uint32_t and check the Vulkan Tutorial loading model section as a reference34 // TODO: Create a typedef for index type so I can easily change uin16_t to something else later35 template<class VertexType>36 struct SceneObject {37 vector<VertexType> vertices;38 vector<uint16_t> indices;39 40 mat4 model_base;41 mat4 model_transform;42 31 }; 43 32 … … 50 39 ~GraphicsPipeline_Vulkan(); 51 40 41 size_t getNumVertices(); 42 52 43 void updateRenderPass(VkRenderPass renderPass); 53 44 … … 66 57 void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage); 67 58 68 vector<SceneObject<VertexType>>& getObjects(); 69 void addObject(const vector<VertexType>& vertices, vector<uint16_t> indices, VkCommandPool commandPool, 59 void addVertices(const vector<VertexType>& vertices, vector<uint16_t> indices, VkCommandPool commandPool, 70 60 VkQueue graphicsQueue); 71 61 … … 100 90 VkDeviceMemory indexBufferMemory; 101 91 102 // TODO: The objects vector isn't used at all in this class, except in the method that returns103 // the number of objects. Move this vector and the SceneObject declaration into VulkanGame, esp.104 // since I'll be adding other object-specific fields such as transforms to SceneObject later105 vector<SceneObject<VertexType>> objects;106 107 92 VkShaderModule createShaderModule(const vector<char>& code); 108 93 vector<char> readFile(const string& filename); … … 151 136 template<class VertexType> 152 137 GraphicsPipeline_Vulkan<VertexType>::~GraphicsPipeline_Vulkan() { 138 } 139 140 template<class VertexType> 141 size_t GraphicsPipeline_Vulkan<VertexType>::getNumVertices() { 142 return numVertices; 153 143 } 154 144 … … 422 412 423 413 template<class VertexType> 424 vector<SceneObject<VertexType>>& GraphicsPipeline_Vulkan<VertexType>::getObjects() { 425 return objects; 426 } 427 428 template<class VertexType> 429 void GraphicsPipeline_Vulkan<VertexType>::addObject(const vector<VertexType>& vertices, vector<uint16_t> indices, 414 void GraphicsPipeline_Vulkan<VertexType>::addVertices(const vector<VertexType>& vertices, vector<uint16_t> indices, 430 415 VkCommandPool commandPool, VkQueue graphicsQueue) { 431 416 … … 436 421 resizeIndexBuffer(commandPool, graphicsQueue); 437 422 } 438 439 for (uint16_t& idx : indices) {440 idx += numVertices;441 }442 objects.push_back({ vertices, indices, mat4(1.0f), mat4(1.0f) });443 423 444 424 VulkanUtils::copyDataToBuffer(device, physicalDevice, commandPool, vertices, vertexBuffer, numVertices, -
vulkan-game.cpp
rcd1cb0f r0fe8433 207 207 VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor); 208 208 209 modelPipeline.addObject({ 209 addObject(modelObjects, modelPipeline, 210 { 210 211 {{-0.5f, -0.5f, -2.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 211 212 {{ 0.5f, -0.5f, -2.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, … … 214 215 }, { 215 216 0, 1, 2, 2, 3, 0 216 }, commandPool, graphicsQueue); 217 218 modelPipeline.addObject({ 217 }); 218 219 addObject(modelObjects, modelPipeline, 220 { 219 221 {{-0.5f, -0.5f, -1.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 220 222 {{ 0.5f, -0.5f, -1.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, … … 223 225 }, { 224 226 0, 1, 2, 2, 3, 0 225 } , commandPool, graphicsQueue);227 }); 226 228 227 229 modelPipeline.createDescriptorSetLayout(); … … 236 238 VK_SHADER_STAGE_FRAGMENT_BIT, &sdlOverlayImageDescriptor); 237 239 238 overlayPipeline.addObject({ 240 addObject(overlayObjects, overlayPipeline, 241 { 239 242 {{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}}, 240 243 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, … … 243 246 }, { 244 247 0, 1, 2, 2, 3, 0 245 } , commandPool, graphicsQueue);248 }); 246 249 247 250 overlayPipeline.createDescriptorSetLayout(); … … 267 270 // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly 268 271 // the same data. Add an option to make some pipelines not use indexing 269 shipPipeline.addObject(272 addObject(shipObjects, shipPipeline, 270 273 centerObject<ShipVertex>( 271 addObjectIndex<ShipVertex>(ship Pipeline.getObjects().size(),274 addObjectIndex<ShipVertex>(shipObjects.size(), 272 275 addVertexNormals<ShipVertex>({ 273 276 //back … … 496 499 132, 133, 134, 497 500 135, 136, 137, 498 } , commandPool, graphicsQueue);501 }); 499 502 500 503 shipPipeline.createDescriptorSetLayout(); … … 509 512 createSyncObjects(); 510 513 511 ship Pipeline.getObjects()[0].model_base =514 shipObjects[0].model_base = 512 515 translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)) * 513 516 scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); … … 575 578 } else if (e.key.keycode == SDL_SCANCODE_SPACE) { 576 579 cout << "Adding a plane" << endl; 577 float zOffset = -2.0f + (0.5f * model Pipeline.getObjects().size());580 float zOffset = -2.0f + (0.5f * modelObjects.size()); 578 581 579 582 vkDeviceWaitIdle(device); 580 583 vkFreeCommandBuffers(device, commandPool, static_cast<uint32_t>(commandBuffers.size()), commandBuffers.data()); 581 584 582 modelPipeline.addObject({ 583 {{-0.5f, -0.5f, zOffset}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 584 {{ 0.5f, -0.5f, zOffset}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 585 {{ 0.5f, 0.5f, zOffset}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 586 {{-0.5f, 0.5f, zOffset}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}} 587 }, { 588 0, 1, 2, 2, 3, 0 589 }, commandPool, graphicsQueue); 585 addObject(modelObjects, modelPipeline, 586 { 587 {{-0.5f, -0.5f, zOffset}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 588 {{ 0.5f, -0.5f, zOffset}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 589 {{ 0.5f, 0.5f, zOffset}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 590 {{-0.5f, 0.5f, zOffset}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}} 591 }, { 592 0, 1, 2, 2, 3, 0 593 }); 590 594 591 595 createCommandBuffers(); … … 615 619 616 620 if (gui->keyPressed(SDL_SCANCODE_LEFT)) { 617 transformObject(ship Pipeline.getObjects()[0], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)));621 transformObject(shipObjects[0], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f))); 618 622 } else if (gui->keyPressed(SDL_SCANCODE_RIGHT)) { 619 transformObject(ship Pipeline.getObjects()[0], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)));623 transformObject(shipObjects[0], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f))); 620 624 } 621 625 … … 641 645 rotate(mat4(1.0f), time * radians(90.0f), vec3(0.0f, 0.0f, 1.0f)); 642 646 643 so_Ship.model = ship Pipeline.getObjects()[0].model_transform * shipPipeline.getObjects()[0].model_base;647 so_Ship.model = shipObjects[0].model_transform * shipObjects[0].model_base; 644 648 645 649 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_scenePipeline[currentImage], object_VP_mats); -
vulkan-game.hpp
rcd1cb0f r0fe8433 40 40 }; 41 41 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 44 template<class VertexType> 45 struct SceneObject { 46 vector<VertexType> vertices; 47 vector<uint16_t> indices; 48 49 mat4 model_base; 50 mat4 model_transform; 51 }; 52 42 53 struct UBO_VP_mats { 43 54 alignas(16) mat4 view; … … 65 76 vec3 cam_pos; 66 77 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 73 78 GameGui* gui; 74 75 GraphicsPipeline_Vulkan<ModelVertex> modelPipeline;76 GraphicsPipeline_Vulkan<OverlayVertex> overlayPipeline;77 GraphicsPipeline_Vulkan<ShipVertex> shipPipeline;78 79 79 80 SDL_version sdlVersion; … … 107 108 VkSampler textureSampler; 108 109 109 // TODO: I should probably rename the uniformBuffer* and storageBuffer*110 // variables to better reflect the data they hold111 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 132 110 VulkanImage floorTextureImage; 133 111 VkDescriptorImageInfo floorTextureImageDescriptor; … … 148 126 149 127 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; 150 171 151 172 bool initWindow(int width, int height, unsigned char guiFlags); … … 181 202 182 203 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> 183 208 vector<VertexType> addVertexNormals(vector<VertexType> vertices); 184 209 … … 205 230 void* pUserData); 206 231 }; 232 233 template<class VertexType> 234 void 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 } 207 246 208 247 template<class VertexType>
Note:
See TracChangeset
for help on using the changeset viewer.