Changeset cefdf23 in opengl-game for vulkan-game.hpp
- Timestamp:
- Apr 5, 2021, 1:09:02 AM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- e469aed
- Parents:
- aa7e5f0
- git-author:
- Dmitry Portnoy <dportnoy@…> (04/05/21 01:07:42)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (04/05/21 01:09:02)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.hpp
raa7e5f0 rcefdf23 34 34 const bool ENABLE_VALIDATION_LAYERS = true; 35 35 #endif 36 37 // TODO: Consider if there is a better way of dealing with all the vertex types and ssbo types, maybe 38 // by consolidating some and trying to keep new ones to a minimum 36 39 37 40 struct OverlayVertex { … … 193 196 }; 194 197 198 // TODO: Maybe move this to a different header 199 195 200 enum UIValueType { 196 201 UIVALUE_INT, … … 208 213 class VulkanGame { 209 214 public: 215 210 216 VulkanGame(); 211 217 ~VulkanGame(); … … 213 219 void run(int width, int height, unsigned char guiFlags); 214 220 215 GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline;216 GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject> shipPipeline;217 GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline;218 GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline;219 GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline;220 221 221 private: 222 222 223 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback( 223 224 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, … … 226 227 void* pUserData); 227 228 229 // TODO: Maybe pass these in as parameters to some Camera class 228 230 const float NEAR_CLIP = 0.1f; 229 231 const float FAR_CLIP = 100.0f; 230 const float FOV_ANGLE = 67.0f; // means the camera lens goes from -33 deg to 33 de f232 const float FOV_ANGLE = 67.0f; // means the camera lens goes from -33 deg to 33 deg 231 233 232 234 const int EXPLOSION_PARTICLE_COUNT = 300; … … 286 288 bool shouldRecreateSwapChain; 287 289 288 VkDescriptorPool imguiDescriptorPool;289 290 290 VkSampler textureSampler; 291 291 … … 297 297 298 298 mat4 viewMat, projMat; 299 300 // Maybe at some point create an imgui pipeline class, but I don't think it makes sense right now 301 VkDescriptorPool imguiDescriptorPool; 302 303 // TODO: Probably restructure the GraphicsPipeline_Vulkan class based on what I learned about descriptors and textures 304 // while working on graphics-library. Double-check exactly what this was and note it down here. 305 // Basically, I think the point was that if I have several modesl that all use the same shaders and, therefore, 306 // the same pipeline, but use different textures, the approach I took when initially creating GraphicsPipeline_Vulkan 307 // wouldn't work since the whole pipeline couldn't have a common set of descriptors for the textures 308 GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline; 309 GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject> shipPipeline; 310 GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline; 311 GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline; 312 GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline; 299 313 300 314 // TODO: Maybe make the ubo objects part of the pipeline class since there's only one ubo … … 371 385 372 386 // TODO: Make a separate TImer class 373 // It could also deal with the steady_clock vs high_resolution_clock issue374 387 time_point<steady_clock> startTime; 375 388 float fpsStartTime, curTime, prevTime, elapsedTime; … … 398 411 void createSwapChain(); 399 412 void createImageViews(); 413 void createResourceCommandPool(); 414 void createImageResources(); 415 VkFormat findDepthFormat(); // TODO: Declare/define (in the cpp file) this function in some util functions section 400 416 void createRenderPass(); 401 VkFormat findDepthFormat(); // TODO: Declare/define (in the cpp file) this function in some util functions section402 void createResourceCommandPool();403 417 void createCommandPools(); 404 void createImageResources();405 418 void createFramebuffers(); 406 419 void createCommandBuffers(); … … 409 422 void createTextureSampler(); 410 423 411 void createImguiDescriptorPool(); 412 void destroyImguiDescriptorPool(); 424 void initImGuiOverlay(); 425 void cleanupImGuiOverlay(); 426 427 void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, 428 vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, 429 vector<VkDescriptorBufferInfo>& bufferInfoList); 413 430 414 431 // TODO: Since addObject() returns a reference to the new object now, … … 421 438 bool pipelinesCreated); 422 439 440 template<class VertexType> 441 vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices); 442 443 template<class VertexType> 444 vector<VertexType> addVertexNormals(vector<VertexType> vertices); 445 446 template<class VertexType, class SSBOType> 447 void centerObject(SceneObject<VertexType, SSBOType>& object); 448 423 449 template<class VertexType, class SSBOType> 424 450 void updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, … … 428 454 void updateObjectVertices(GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 429 455 SceneObject<VertexType, SSBOType>& obj, size_t index); 430 431 template<class VertexType>432 vector<VertexType> addVertexNormals(vector<VertexType> vertices);433 434 template<class VertexType>435 vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices);436 437 template<class VertexType, class SSBOType>438 void centerObject(SceneObject<VertexType, SSBOType>& object);439 456 440 457 void addLaser(vec3 start, vec3 end, vec3 color, float width); … … 445 462 446 463 void addExplosion(mat4 model_mat, float duration, float cur_time); 447 448 void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,449 vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory,450 vector<VkDescriptorBufferInfo>& bufferInfoList);451 464 452 465 void renderFrame(ImDrawData* draw_data); … … 503 516 SceneObject<VertexType, SSBOType>& obj = objects.back(); 504 517 518 // TODO: Specify whether to center the object outside of this function or, worst case, maybe 519 // with a boolean being passed in here, so that I don't have to rely on checking the specific object 520 // type 505 521 if (!is_same_v<VertexType, LaserVertex> && !is_same_v<VertexType, ExplosionVertex>) { 506 522 centerObject(obj); … … 533 549 } 534 550 535 // TODO: Just pass in the single object instead of a list of all of them 536 template<class VertexType, class SSBOType> 537 void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, 538 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, size_t index) { 539 SceneObject<VertexType, SSBOType>& obj = objects[index]; 540 541 obj.ssbo.model = obj.model_transform * obj.model_base; 542 obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f)); 543 544 pipeline.updateObject(index, obj.ssbo); 545 546 obj.modified = false; 547 } 548 549 template<class VertexType, class SSBOType> 550 void VulkanGame::updateObjectVertices(GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 551 SceneObject<VertexType, SSBOType>& obj, size_t index) { 552 pipeline.updateObjectVertices(index, obj.vertices, resourceCommandPool, graphicsQueue); 551 template<class VertexType> 552 vector<VertexType> VulkanGame::addObjectIndex(unsigned int objIndex, vector<VertexType> vertices) { 553 for (VertexType& vertex : vertices) { 554 vertex.objIndex = objIndex; 555 } 556 557 return vertices; 553 558 } 554 559 … … 557 562 for (unsigned int i = 0; i < vertices.size(); i += 3) { 558 563 vec3 p1 = vertices[i].pos; 559 vec3 p2 = vertices[i +1].pos;560 vec3 p3 = vertices[i +2].pos;564 vec3 p2 = vertices[i + 1].pos; 565 vec3 p3 = vertices[i + 2].pos; 561 566 562 567 vec3 normal = normalize(cross(p2 - p1, p3 - p1)); … … 564 569 // Add the same normal for all 3 vertices 565 570 vertices[i].normal = normal; 566 vertices[i+1].normal = normal; 567 vertices[i+2].normal = normal; 568 } 569 570 return vertices; 571 } 572 573 template<class VertexType> 574 vector<VertexType> VulkanGame::addObjectIndex(unsigned int objIndex, vector<VertexType> vertices) { 575 for (VertexType& vertex : vertices) { 576 vertex.objIndex = objIndex; 571 vertices[i + 1].normal = normal; 572 vertices[i + 2].normal = normal; 577 573 } 578 574 … … 626 622 } 627 623 624 // TODO: Just pass in the single object instead of a list of all of them 625 template<class VertexType, class SSBOType> 626 void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, 627 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, size_t index) { 628 SceneObject<VertexType, SSBOType>& obj = objects[index]; 629 630 obj.ssbo.model = obj.model_transform * obj.model_base; 631 obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f)); 632 633 pipeline.updateObject(index, obj.ssbo); 634 635 obj.modified = false; 636 } 637 638 template<class VertexType, class SSBOType> 639 void VulkanGame::updateObjectVertices(GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 640 SceneObject<VertexType, SSBOType>& obj, size_t index) { 641 pipeline.updateObjectVertices(index, obj.vertices, resourceCommandPool, graphicsQueue); 642 } 643 628 644 #endif // _VULKAN_GAME_H
Note:
See TracChangeset
for help on using the changeset viewer.