Changeset 34bdf3a in opengl-game
- Timestamp:
- Oct 24, 2019, 3:35:49 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 87c8f1a
- Parents:
- 603b5bc
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main-vulkan.cpp
r603b5bc r34bdf3a 17 17 18 18 int __main(int argc, char* argv[]) { 19 const int MAX_FRAMES_IN_FLIGHT = 2; 20 19 21 cout << "Starting Vulkan Game..." << endl; 20 22 21 VulkanGame game ;23 VulkanGame game(MAX_FRAMES_IN_FLIGHT); 22 24 23 25 try { -
vulkan-game.cpp
r603b5bc r34bdf3a 18 18 }; 19 19 20 VulkanGame::VulkanGame( ) {20 VulkanGame::VulkanGame(int maxFramesInFlight) : MAX_FRAMES_IN_FLIGHT(maxFramesInFlight) { 21 21 gui = nullptr; 22 22 window = nullptr; … … 169 169 graphicsPipelines.back().createDescriptorSets(swapChainImages); 170 170 171 createCommandBuffers();172 173 171 // TODO: Creating the descriptor pool and descriptor sets might need to be redone when the 174 172 // swap chain is recreated 175 173 176 174 cout << "Created " << graphicsPipelines.size() << " graphics pipelines" << endl; 175 176 createCommandBuffers(); 177 178 createSyncObjects(); 177 179 } 178 180 … … 250 252 } 251 253 254 for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { 255 vkDestroySemaphore(device, renderFinishedSemaphores[i], nullptr); 256 vkDestroySemaphore(device, imageAvailableSemaphores[i], nullptr); 257 vkDestroyFence(device, inFlightFences[i], nullptr); 258 } 259 252 260 vkDestroyCommandPool(device, commandPool, nullptr); 253 261 vkDestroyDevice(device, nullptr); … … 741 749 } 742 750 751 void VulkanGame::createSyncObjects() { 752 imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT); 753 renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT); 754 inFlightFences.resize(MAX_FRAMES_IN_FLIGHT); 755 756 VkSemaphoreCreateInfo semaphoreInfo = {}; 757 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; 758 759 VkFenceCreateInfo fenceInfo = {}; 760 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; 761 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; 762 763 for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { 764 if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &imageAvailableSemaphores[i]) != VK_SUCCESS || 765 vkCreateSemaphore(device, &semaphoreInfo, nullptr, &renderFinishedSemaphores[i]) != VK_SUCCESS || 766 vkCreateFence(device, &fenceInfo, nullptr, &inFlightFences[i]) != VK_SUCCESS) { 767 throw runtime_error("failed to create synchronization objects for a frame!"); 768 } 769 } 770 } 771 743 772 void VulkanGame::cleanupSwapChain() { 744 773 VulkanUtils::destroyVulkanImage(device, depthImage); -
vulkan-game.hpp
r603b5bc r34bdf3a 30 30 class VulkanGame { 31 31 public: 32 VulkanGame( );32 VulkanGame(int maxFramesInFlight); 33 33 ~VulkanGame(); 34 34 … … 36 36 37 37 private: 38 const int MAX_FRAMES_IN_FLIGHT; 39 38 40 GameGui* gui; 39 41 … … 85 87 VkDescriptorImageInfo sdlOverlayImageDescriptor; 86 88 89 vector<VkSemaphore> imageAvailableSemaphores; 90 vector<VkSemaphore> renderFinishedSemaphores; 91 vector<VkFence> inFlightFences; 92 87 93 bool framebufferResized = false; 88 94 … … 114 120 void createUniformBuffers(); 115 121 void createCommandBuffers(); 122 void createSyncObjects(); 116 123 117 124 void cleanupSwapChain(); -
vulkan-ref.cpp
r603b5bc r34bdf3a 27 27 using namespace glm; 28 28 29 /*** START OF REFACTORED CODE ***/ 29 30 const int SCREEN_WIDTH = 800; 30 31 const int SCREEN_HEIGHT = 600; … … 32 33 const int MAX_FRAMES_IN_FLIGHT = 2; 33 34 34 /*** START OF REFACTORED CODE ***/35 35 #ifdef NDEBUG 36 36 const bool enableValidationLayers = false; … … 219 219 GraphicsPipelineInfo scenePipeline; 220 220 GraphicsPipelineInfo overlayPipeline; 221 /*** END OF REFACTORED CODE ***/222 221 223 222 vector<VkSemaphore> imageAvailableSemaphores; 224 223 vector<VkSemaphore> renderFinishedSemaphores; 225 224 vector<VkFence> inFlightFences; 225 /*** END OF REFACTORED CODE ***/ 226 226 227 227 size_t currentFrame = 0; … … 400 400 401 401 createBufferResources(); 402 /*** END OF REFACTORED CODE ***/403 402 404 403 createSyncObjects(); … … 475 474 } 476 475 477 /*** START OF REFACTORED CODE ***/478 476 vector<const char*> getRequiredExtensions() { 479 477 vector<const char*> extensions = gui->getRequiredExtensions(); … … 1696 1694 /*** START OF REFACTORED CODE ***/ 1697 1695 } 1698 /*** END OF REFACTORED CODE ***/1699 1696 1700 1697 void createSyncObjects() { … … 1718 1715 } 1719 1716 } 1717 /*** END OF REFACTORED CODE ***/ 1720 1718 1721 1719 bool addObjectToScene(GraphicsPipelineInfo& info, … … 1970 1968 cleanupPipelineBuffers(scenePipeline); 1971 1969 cleanupPipelineBuffers(overlayPipeline); 1972 /*** END OF REFACTORED CODE ***/1973 1970 1974 1971 for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { … … 1978 1975 } 1979 1976 1980 /*** START OF REFACTORED CODE ***/1981 1977 vkDestroyCommandPool(device, commandPool, nullptr); 1982 1978 vkDestroyDevice(device, nullptr);
Note:
See TracChangeset
for help on using the changeset viewer.