Changeset 3b84bb6 in opengl-game
- Timestamp:
- Feb 25, 2020, 6:51:02 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 44f23af
- Parents:
- 2da64ef
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
graphics-pipeline_vulkan.hpp
r2da64ef r3b84bb6 71 71 void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage); 72 72 73 void addVertices(const vector<VertexType>& vertices, vector<uint16_t> indices, VkCommandPool commandPool,74 Vk Queue graphicsQueue);73 bool addObject(const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType& ssbo, 74 VkCommandPool commandPool, VkQueue graphicsQueue); 75 75 76 76 void updateObject(size_t objIndex, SSBOType& ssbo); … … 125 125 126 126 // TODO: Verify that vertex capacity and index capacity are both > 0 127 // TODO: See if it would be feasible to move code in the createPipeline method 128 // into the constructor. That way, I can also put relevant cleanup code into the destructor 127 129 template<class VertexType, class SSBOType> 128 130 GraphicsPipeline_Vulkan<VertexType, SSBOType>::GraphicsPipeline_Vulkan( … … 473 475 474 476 template<class VertexType, class SSBOType> 475 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addVertices(const vector<VertexType>& vertices, vector<uint16_t> indices, 476 VkCommandPool commandPool, VkQueue graphicsQueue) { 477 bool GraphicsPipeline_Vulkan<VertexType, SSBOType>::addObject( 478 const vector<VertexType>& vertices, vector<uint16_t> indices, 479 SSBOType& ssbo, VkCommandPool commandPool, VkQueue graphicsQueue) { 480 481 // TODO: When resizing the vertex or index buffer, take deleted objects into account. 482 // Remove their data from the buffer and determine the new size of the bufer based on # of remining objects 483 484 // If # non-deleted objects > currentCapacity / 2 485 // - resize and double capacity 486 // else If # non-deleted objects < currentCapacity / 4 487 // - resize amd halve capacity 488 // else 489 // - don't resize, but rewrite data in the buffer to only have non-deleted objects 477 490 478 491 if (numVertices + vertices.size() > vertexCapacity) { … … 490 503 graphicsQueue); 491 504 numIndices += indices.size(); 505 506 bool resizedStorageBuffer = false; 507 508 return resizedStorageBuffer; 492 509 } 493 510 -
vulkan-game.cpp
r2da64ef r3b84bb6 208 208 }, { 209 209 0, 1, 2, 2, 3, 0 210 }, {} );210 }, {}, false); 211 211 212 212 overlayPipeline.createDescriptorSetLayout(); … … 240 240 }, { 241 241 mat4(1.0f) 242 } );242 }, false); 243 243 244 244 addObject(modelObjects, modelPipeline, … … 252 252 }, { 253 253 mat4(1.0f) 254 } );254 }, false); 255 255 256 256 modelPipeline.createDescriptorSetLayout(); … … 274 274 // the same data. Add an option to make some pipelines not use indexing 275 275 addObject(shipObjects, shipPipeline, 276 centerObject<ShipVertex>(277 276 addObjectIndex<ShipVertex>(shipObjects.size(), 278 277 addVertexNormals<ShipVertex>({ … … 473 472 {{ 1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 474 473 {{ 1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 475 })) ), {474 })), { 476 475 0, 1, 2, 3, 4, 5, 477 476 6, 7, 8, 9, 10, 11, … … 505 504 }, { 506 505 mat4(1.0f) 507 } );506 }, false); 508 507 509 508 shipPipeline.createDescriptorSetLayout(); … … 619 618 float zOffset = -2.0f + (0.5f * modelObjects.size()); 620 619 621 vkDeviceWaitIdle(device);622 vkFreeCommandBuffers(device, commandPool, static_cast<uint32_t>(commandBuffers.size()), commandBuffers.data());623 624 620 addObject(modelObjects, modelPipeline, 625 621 addObjectIndex<ModelVertex>(modelObjects.size(), { … … 632 628 }, { 633 629 mat4(1.0f) 634 }); 635 636 createCommandBuffers(); 630 }, true); 637 631 } else if (e.key.keycode == SDL_SCANCODE_Z) { 638 vkDeviceWaitIdle(device);639 vkFreeCommandBuffers(device, commandPool, static_cast<uint32_t>(commandBuffers.size()), commandBuffers.data());640 641 632 addObject(asteroidObjects, asteroidPipeline, 642 633 addObjectIndex<AsteroidVertex>(asteroidObjects.size(), … … 701 692 10.0f, 702 693 0 703 } );694 }, true); 704 695 705 696 // translate(mat4(1.0f), vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f))) * … … 710 701 711 702 updateObject(asteroidObjects, asteroidPipeline, asteroidObjects.size() - 1); 712 createCommandBuffers();713 703 } else { 714 704 cout << "Key event detected" << endl; … … 750 740 } 751 741 742 if (gui->keyPressed(SDL_SCANCODE_X)) { 743 if (asteroidObjects.size() > 0 && !asteroidObjects[0].ssbo.deleted) { 744 updateObject(asteroidObjects, asteroidPipeline, 0); 745 } 746 } 747 752 748 renderUI(); 753 749 renderScene(); -
vulkan-game.hpp
r2da64ef r3b84bb6 58 58 mat4 model_base; 59 59 mat4 model_transform; 60 vec3 center; 61 float radius; 60 62 }; 61 63 … … 217 219 void addObject(vector<SceneObject<VertexType, SSBOType>>& objects, 218 220 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 219 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo); 221 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo, 222 bool pipelinesCreated); 220 223 221 224 template<class VertexType, class SSBOType> … … 229 232 vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices); 230 233 231 template<class VertexType >232 v ector<VertexType> centerObject(vector<VertexType> vertices);234 template<class VertexType, class SSBOType> 235 void centerObject(SceneObject<VertexType, SSBOType>& object); 233 236 234 237 void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, … … 246 249 }; 247 250 251 // TODO: Right now, it's basically necessary to pass the identity matrix in for ssbo.model 252 // and to change the model matrix later by setting model_transform and then calling updateObject() 253 // Figure out a better way to allow the model matrix to be set during objecting creation 248 254 template<class VertexType, class SSBOType> 249 255 void VulkanGame::addObject(vector<SceneObject<VertexType, SSBOType>>& objects, 250 256 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 251 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo) { 257 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo, 258 bool pipelinesCreated) { 252 259 size_t numVertices = pipeline.getNumVertices(); 253 260 … … 257 264 258 265 objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f) }); 259 260 pipeline.addVertices(vertices, indices, commandPool, graphicsQueue); 266 centerObject(objects.back()); 267 268 bool storageBufferResized = pipeline.addObject(vertices, indices, ssbo, commandPool, graphicsQueue); 269 270 if (pipelinesCreated) { 271 if (storageBufferResized) { 272 } 273 274 createCommandBuffers(); 275 } 261 276 } 262 277 … … 302 317 } 303 318 304 template<class VertexType> 305 vector<VertexType> VulkanGame::centerObject(vector<VertexType> vertices) { 319 template<class VertexType, class SSBOType> 320 void VulkanGame::centerObject(SceneObject<VertexType, SSBOType>& object) { 321 vector<VertexType>& vertices = object.vertices; 322 306 323 float min_x = vertices[0].pos.x; 307 324 float max_x = vertices[0].pos.x; … … 313 330 // start from the second point 314 331 for (unsigned int i = 1; i < vertices.size(); i++) { 315 if (min_x > vertices[i].pos.x) { 316 min_x = vertices[i].pos.x; 317 } else if (max_x < vertices[i].pos.x) { 318 max_x = vertices[i].pos.x; 332 vec3& pos = vertices[i].pos; 333 334 if (min_x > pos.x) { 335 min_x = pos.x; 336 } else if (max_x < pos.x) { 337 max_x = pos.x; 319 338 } 320 339 321 if (min_y > vertices[i].pos.y) {322 min_y = vertices[i].pos.y;323 } else if (max_y < vertices[i].pos.y) {324 max_y = vertices[i].pos.y;340 if (min_y > pos.y) { 341 min_y = pos.y; 342 } else if (max_y < pos.y) { 343 max_y = pos.y; 325 344 } 326 345 327 if (min_z > vertices[i].pos.z) {328 min_z = vertices[i].pos.z;329 } else if (max_z < vertices[i].pos.z) {330 max_z = vertices[i].pos.z;346 if (min_z > pos.z) { 347 min_z = pos.z; 348 } else if (max_z < pos.z) { 349 max_z = pos.z; 331 350 } 332 351 } … … 338 357 } 339 358 340 return vertices; 359 object.radius = std::max(center.x, center.y); 360 object.radius = std::max(object.radius, center.z); 361 object.center = vec3(0.0f, 0.0f, 0.0f); 341 362 } 342 363
Note:
See TracChangeset
for help on using the changeset viewer.