Changeset 7865c5b in opengl-game
- Timestamp:
- Mar 17, 2021, 12:50:49 AM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- aa7e5f0
- Parents:
- 85b5fec
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
VulkanGame.vcxproj
r85b5fec r7865c5b 202 202 </ItemGroup> 203 203 <ItemGroup> 204 <Text Include="docs\DESIGN.txt" /> 205 <Text Include="docs\notes.txt" /> 206 <Text Include="docs\README.txt" /> 207 <Text Include="docs\scene-notes.txt" /> 208 <Text Include="docs\TODO.txt" /> 209 <Text Include="docs\upgrade-TODO.txt" /> 204 210 <Text Include="scene-notes.txt" /> 205 211 </ItemGroup> -
VulkanGame.vcxproj.filters
r85b5fec r7865c5b 106 106 <ItemGroup> 107 107 <Text Include="scene-notes.txt" /> 108 <Text Include="docs\DESIGN.txt"> 109 <Filter>docs</Filter> 110 </Text> 111 <Text Include="docs\notes.txt"> 112 <Filter>docs</Filter> 113 </Text> 114 <Text Include="docs\README.txt"> 115 <Filter>docs</Filter> 116 </Text> 117 <Text Include="docs\scene-notes.txt"> 118 <Filter>docs</Filter> 119 </Text> 120 <Text Include="docs\TODO.txt"> 121 <Filter>docs</Filter> 122 </Text> 123 <Text Include="docs\upgrade-TODO.txt"> 124 <Filter>docs</Filter> 125 </Text> 108 126 </ItemGroup> 109 127 <ItemGroup> … … 120 138 <UniqueIdentifier>{2954212f-ed3d-45c5-b46a-bbb81a16ca78}</UniqueIdentifier> 121 139 </Filter> 140 <Filter Include="docs"> 141 <UniqueIdentifier>{7a1e3c9c-c984-4cf9-9c02-9a4332a7ce92}</UniqueIdentifier> 142 </Filter> 122 143 </ItemGroup> 123 144 </Project> -
docs/README.txt
r85b5fec r7865c5b 90 90 91 91 Actually, I think now this should work, after following the online instructions for installing Vulkan: 92 sudo apt-get install libglm-dev libsdl2-dev libsdl2-image-dev libsdl2-gfx-dev libsdl2-ttf-dev 92 sudo apt-get install vulkan-sdk libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libglm-dev 93 (Follow the instructions at https://vulkan.lunarg.com/sdk/home#linux to add the latest Vulkan SDK version to apt-get) 94 (Verify that installing libvulkan-1 is not required) 93 95 94 96 make vulkangame && ./vulkangame -
sdl-game.cpp
r85b5fec r7865c5b 40 40 } 41 41 42 VulkanGame::VulkanGame() { 43 // TODO: Double-check whether initialization should happen in the header, where the variables are declared, or here 44 // Also, decide whether to use this-> for all instance variables, or only when necessary 45 46 debugMessenger = VK_NULL_HANDLE; 47 48 gui = nullptr; 49 window = nullptr; 50 51 swapChainPresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR; 52 swapChainMinImageCount = 0; 53 currentFrame = 0; 54 imageIndex = 0; 55 shouldRecreateSwapChain = false; 56 57 score = 0; 58 fps = 0.0f; 42 VulkanGame::VulkanGame() 43 : swapChainImageCount(0) 44 , swapChainMinImageCount(0) 45 , swapChainSurfaceFormat({}) 46 , swapChainPresentMode(VK_PRESENT_MODE_MAX_ENUM_KHR) 47 , swapChainExtent{ 0, 0 } 48 , swapChain(VK_NULL_HANDLE) 49 , vulkanSurface(VK_NULL_HANDLE) 50 , sdlVersion({ 0, 0, 0 }) 51 , instance(VK_NULL_HANDLE) 52 , physicalDevice(VK_NULL_HANDLE) 53 , device(VK_NULL_HANDLE) 54 , debugMessenger(VK_NULL_HANDLE) 55 , resourceCommandPool(VK_NULL_HANDLE) 56 , renderPass(VK_NULL_HANDLE) 57 , graphicsQueue(VK_NULL_HANDLE) 58 , presentQueue(VK_NULL_HANDLE) 59 , depthImage({}) 60 , shouldRecreateSwapChain(false) 61 , frameCount(0) 62 , currentFrame() 63 , imageIndex(0) 64 , fpsStartTime(0.0f) 65 , curTime(0.0f) 66 , done(false) 67 , currentRenderScreenFn(nullptr) 68 , descriptorPool(VK_NULL_HANDLE) 69 , gui(nullptr) 70 , window(nullptr) 71 , score(0) 72 , fps(0.0f) { 59 73 } 60 74 … … 104 118 105 119 // TODO: Do this in one place and save it instead of redoing it every time I need a queue family index 106 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);120 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 107 121 108 122 // Setup Dear ImGui context … … 376 390 377 391 vkDestroyDevice(device, nullptr); 378 vkDestroySurfaceKHR(instance, surface, nullptr);392 vkDestroySurfaceKHR(instance, vulkanSurface, nullptr); 379 393 380 394 if (ENABLE_VALIDATION_LAYERS) { … … 461 475 462 476 void VulkanGame::createVulkanSurface() { 463 if (gui->createVulkanSurface(instance, & surface) == RTWO_ERROR) {477 if (gui->createVulkanSurface(instance, &vulkanSurface) == RTWO_ERROR) { 464 478 throw runtime_error("failed to create window surface!"); 465 479 } … … 507 521 } 508 522 509 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);523 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 510 524 bool extensionsSupported = VulkanUtils::checkDeviceExtensionSupport(physicalDevice, deviceExtensions); 511 525 bool swapChainAdequate = false; 512 526 513 527 if (extensionsSupported) { 514 vector<VkSurfaceFormatKHR> formats = VulkanUtils::querySwapChainFormats(physicalDevice, surface);515 vector<VkPresentModeKHR> presentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, surface);528 vector<VkSurfaceFormatKHR> formats = VulkanUtils::querySwapChainFormats(physicalDevice, vulkanSurface); 529 vector<VkPresentModeKHR> presentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, vulkanSurface); 516 530 517 531 swapChainAdequate = !formats.empty() && !presentModes.empty(); … … 526 540 void VulkanGame::createLogicalDevice(const vector<const char*>& validationLayers, 527 541 const vector<const char*>& deviceExtensions) { 528 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);542 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 529 543 530 544 if (!indices.isComplete()) { … … 582 596 583 597 void VulkanGame::chooseSwapChainProperties() { 584 vector<VkSurfaceFormatKHR> availableFormats = VulkanUtils::querySwapChainFormats(physicalDevice, surface);585 vector<VkPresentModeKHR> availablePresentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, surface);598 vector<VkSurfaceFormatKHR> availableFormats = VulkanUtils::querySwapChainFormats(physicalDevice, vulkanSurface); 599 vector<VkPresentModeKHR> availablePresentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, vulkanSurface); 586 600 587 601 // Per Spec Format and View Format are expected to be the same unless VK_IMAGE_CREATE_MUTABLE_BIT was set at image creation … … 605 619 cout << "[vulkan] Selected PresentMode = " << swapChainPresentMode << endl; 606 620 607 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);621 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface); 608 622 609 623 // If min image count was not specified, request different count of images dependent on selected present mode … … 632 646 633 647 void VulkanGame::createSwapChain() { 634 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);648 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface); 635 649 636 650 swapChainExtent = VulkanUtils::chooseSwapExtent(capabilities, gui->getWindowWidth(), gui->getWindowHeight()); … … 638 652 VkSwapchainCreateInfoKHR createInfo = {}; 639 653 createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; 640 createInfo.surface = surface;654 createInfo.surface = vulkanSurface; 641 655 createInfo.minImageCount = swapChainMinImageCount; 642 656 createInfo.imageFormat = swapChainSurfaceFormat.format; … … 647 661 648 662 // TODO: Maybe save this result so I don't have to recalculate it every time 649 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);663 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 650 664 uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() }; 651 665 … … 762 776 763 777 void VulkanGame::createResourceCommandPool() { 764 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);778 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 765 779 766 780 VkCommandPoolCreateInfo poolInfo = {}; … … 777 791 commandPools.resize(swapChainImageCount); 778 792 779 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);793 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 780 794 781 795 for (size_t i = 0; i < swapChainImageCount; i++) { -
sdl-game.hpp
r85b5fec r7865c5b 66 66 67 67 VkInstance instance; 68 VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE;69 VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface70 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;68 VkDebugUtilsMessengerEXT debugMessenger; 69 VkSurfaceKHR vulkanSurface; 70 VkPhysicalDevice physicalDevice; 71 71 VkDevice device; 72 72 -
vulkan-game.cpp
r85b5fec r7865c5b 50 50 } 51 51 52 VulkanGame::VulkanGame() { 53 // TODO: Double-check whether initialization should happen in the header, where the variables are declared, or here 54 // Also, decide whether to use this-> for all instance variables, or only when necessary 55 56 debugMessenger = VK_NULL_HANDLE; 57 58 gui = nullptr; 59 window = nullptr; 60 61 swapChainPresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR; 62 swapChainMinImageCount = 0; 63 currentFrame = 0; 64 imageIndex = 0; 65 shouldRecreateSwapChain = false; 66 52 VulkanGame::VulkanGame() 53 : swapChainImageCount(0) 54 , swapChainMinImageCount(0) 55 , swapChainSurfaceFormat({}) 56 , swapChainPresentMode(VK_PRESENT_MODE_MAX_ENUM_KHR) 57 , swapChainExtent{ 0, 0 } 58 , swapChain(VK_NULL_HANDLE) 59 , vulkanSurface(VK_NULL_HANDLE) 60 , sdlVersion({ 0, 0, 0 }) 61 , instance(VK_NULL_HANDLE) 62 , physicalDevice(VK_NULL_HANDLE) 63 , device(VK_NULL_HANDLE) 64 , debugMessenger(VK_NULL_HANDLE) 65 , resourceCommandPool(VK_NULL_HANDLE) 66 , renderPass(VK_NULL_HANDLE) 67 , graphicsQueue(VK_NULL_HANDLE) 68 , presentQueue(VK_NULL_HANDLE) 69 , depthImage({}) 70 , shouldRecreateSwapChain(false) 71 , frameCount(0) 72 , currentFrame() 73 , imageIndex(0) 74 , fpsStartTime(0.0f) 75 , curTime(0.0f) 76 , done(false) 77 , currentRenderScreenFn(nullptr) 78 , gui(nullptr) 79 , window(nullptr) 80 , score(0) 81 , fps(0.0f) { 67 82 object_VP_mats = {}; 68 83 ship_VP_mats = {}; … … 70 85 laser_VP_mats = {}; 71 86 explosion_UBO = {}; 72 73 score = 0;74 fps = 0.0f;75 87 } 76 88 … … 205 217 206 218 // TODO: Maybe call this once and save the results since it's also called when creating the logical device 207 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);219 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 208 220 209 221 ImGui_ImplSDL2_InitForVulkan(window); … … 1149 1161 1150 1162 vkDestroyDevice(device, nullptr); 1151 vkDestroySurfaceKHR(instance, surface, nullptr);1163 vkDestroySurfaceKHR(instance, vulkanSurface, nullptr); 1152 1164 1153 1165 if (ENABLE_VALIDATION_LAYERS) { … … 1244 1256 1245 1257 void VulkanGame::createVulkanSurface() { 1246 if (gui->createVulkanSurface(instance, & surface) == RTWO_ERROR) {1258 if (gui->createVulkanSurface(instance, &vulkanSurface) == RTWO_ERROR) { 1247 1259 throw runtime_error("failed to create window surface!"); 1248 1260 } … … 1290 1302 } 1291 1303 1292 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);1304 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 1293 1305 bool extensionsSupported = VulkanUtils::checkDeviceExtensionSupport(physicalDevice, deviceExtensions); 1294 1306 bool swapChainAdequate = false; 1295 1307 1296 1308 if (extensionsSupported) { 1297 vector<VkSurfaceFormatKHR> formats = VulkanUtils::querySwapChainFormats(physicalDevice, surface);1298 vector<VkPresentModeKHR> presentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, surface);1309 vector<VkSurfaceFormatKHR> formats = VulkanUtils::querySwapChainFormats(physicalDevice, vulkanSurface); 1310 vector<VkPresentModeKHR> presentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, vulkanSurface); 1299 1311 1300 1312 swapChainAdequate = !formats.empty() && !presentModes.empty(); … … 1309 1321 void VulkanGame::createLogicalDevice(const vector<const char*>& validationLayers, 1310 1322 const vector<const char*>& deviceExtensions) { 1311 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);1323 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 1312 1324 1313 1325 if (!indices.isComplete()) { … … 1364 1376 1365 1377 void VulkanGame::chooseSwapChainProperties() { 1366 vector<VkSurfaceFormatKHR> availableFormats = VulkanUtils::querySwapChainFormats(physicalDevice, surface);1367 vector<VkPresentModeKHR> availablePresentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, surface);1378 vector<VkSurfaceFormatKHR> availableFormats = VulkanUtils::querySwapChainFormats(physicalDevice, vulkanSurface); 1379 vector<VkPresentModeKHR> availablePresentModes = VulkanUtils::querySwapChainPresentModes(physicalDevice, vulkanSurface); 1368 1380 1369 1381 swapChainSurfaceFormat = VulkanUtils::chooseSwapSurfaceFormat(availableFormats, … … 1380 1392 cout << "[vulkan] Selected PresentMode = " << swapChainPresentMode << endl; 1381 1393 1382 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);1394 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface); 1383 1395 1384 1396 if (swapChainPresentMode == VK_PRESENT_MODE_MAILBOX_KHR) { … … 1400 1412 1401 1413 void VulkanGame::createSwapChain() { 1402 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, surface);1414 VkSurfaceCapabilitiesKHR capabilities = VulkanUtils::querySwapChainCapabilities(physicalDevice, vulkanSurface); 1403 1415 1404 1416 swapChainExtent = VulkanUtils::chooseSwapExtent(capabilities, gui->getWindowWidth(), gui->getWindowHeight()); … … 1406 1418 VkSwapchainCreateInfoKHR createInfo = {}; 1407 1419 createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; 1408 createInfo.surface = surface;1420 createInfo.surface = vulkanSurface; 1409 1421 createInfo.minImageCount = swapChainMinImageCount; 1410 1422 createInfo.imageFormat = swapChainSurfaceFormat.format; … … 1415 1427 1416 1428 // TODO: Maybe save this result so I don't have to recalculate it every time 1417 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);1429 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 1418 1430 uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() }; 1419 1431 … … 1525 1537 1526 1538 void VulkanGame::createResourceCommandPool() { 1527 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);1539 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 1528 1540 1529 1541 VkCommandPoolCreateInfo poolInfo = {}; … … 1540 1552 commandPools.resize(swapChainImageCount); 1541 1553 1542 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface);1554 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, vulkanSurface); 1543 1555 1544 1556 for (size_t i = 0; i < swapChainImageCount; i++) { -
vulkan-game.hpp
r85b5fec r7865c5b 247 247 VkInstance instance; 248 248 VkDebugUtilsMessengerEXT debugMessenger; 249 VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface249 VkSurfaceKHR vulkanSurface; 250 250 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; 251 251 VkDevice device;
Note:
See TracChangeset
for help on using the changeset viewer.