Changeset c1c2021 in opengl-game
- Timestamp:
- Sep 23, 2019, 12:32:48 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 502bd0b
- Parents:
- a0c5f28
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
ra0c5f28 rc1c2021 2 2 3 3 #include <iostream> 4 #include <set> 4 5 5 6 #include "consts.hpp" … … 98 99 createVulkanSurface(); 99 100 pickPhysicalDevice(deviceExtensions); 101 createLogicalDevice(validationLayers, deviceExtensions); 100 102 } 101 103 … … 142 144 renderScene(); 143 145 } 146 147 vkDeviceWaitIdle(device); 144 148 } 145 149 … … 153 157 154 158 void VulkanGame::cleanup() { 159 cleanupSwapChain(); 160 161 vkDestroyDevice(device, nullptr); 162 vkDestroySurfaceKHR(instance, surface, nullptr); 163 155 164 if (ENABLE_VALIDATION_LAYERS) { 156 165 VulkanUtils::destroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr); 157 166 } 167 158 168 vkDestroyInstance(instance, nullptr); 159 169 … … 164 174 gui->shutdown(); 165 175 delete gui; 176 } 177 178 void VulkanGame::cleanupSwapChain() { 166 179 } 167 180 … … 295 308 return indices.isComplete() && extensionsSupported && swapChainAdequate && supportedFeatures.samplerAnisotropy; 296 309 } 310 311 void VulkanGame::createLogicalDevice( 312 const vector<const char*> validationLayers, 313 const vector<const char*>& deviceExtensions) { 314 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface); 315 316 vector<VkDeviceQueueCreateInfo> queueCreateInfos; 317 set<uint32_t> uniqueQueueFamilies = { indices.graphicsFamily.value(), indices.presentFamily.value() }; 318 319 float queuePriority = 1.0f; 320 for (uint32_t queueFamily : uniqueQueueFamilies) { 321 VkDeviceQueueCreateInfo queueCreateInfo = {}; 322 queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; 323 queueCreateInfo.queueFamilyIndex = queueFamily; 324 queueCreateInfo.queueCount = 1; 325 queueCreateInfo.pQueuePriorities = &queuePriority; 326 327 queueCreateInfos.push_back(queueCreateInfo); 328 } 329 330 VkPhysicalDeviceFeatures deviceFeatures = {}; 331 deviceFeatures.samplerAnisotropy = VK_TRUE; 332 333 VkDeviceCreateInfo createInfo = {}; 334 createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; 335 createInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size()); 336 createInfo.pQueueCreateInfos = queueCreateInfos.data(); 337 338 createInfo.pEnabledFeatures = &deviceFeatures; 339 340 createInfo.enabledExtensionCount = static_cast<uint32_t>(deviceExtensions.size()); 341 createInfo.ppEnabledExtensionNames = deviceExtensions.data(); 342 343 // These fields are ignored by up-to-date Vulkan implementations, 344 // but it's a good idea to set them for backwards compatibility 345 if (ENABLE_VALIDATION_LAYERS) { 346 createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size()); 347 createInfo.ppEnabledLayerNames = validationLayers.data(); 348 } else { 349 createInfo.enabledLayerCount = 0; 350 } 351 352 if (vkCreateDevice(physicalDevice, &createInfo, nullptr, &device) != VK_SUCCESS) { 353 throw runtime_error("failed to create logical device!"); 354 } 355 356 vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue); 357 vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue); 358 } -
vulkan-game.hpp
ra0c5f28 rc1c2021 28 28 VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface 29 29 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; 30 VkDevice device; 31 32 VkQueue graphicsQueue; 33 VkQueue presentQueue; 30 34 31 35 bool initWindow(int width, int height, unsigned char guiFlags); … … 42 46 void pickPhysicalDevice(const vector<const char*>& deviceExtensions); 43 47 bool isDeviceSuitable(VkPhysicalDevice device, const vector<const char*>& deviceExtensions); 48 void createLogicalDevice( 49 const vector<const char*> validationLayers, 50 const vector<const char*>& deviceExtensions); 51 void cleanupSwapChain(); 44 52 45 53 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback( -
vulkan-ref.cpp
ra0c5f28 rc1c2021 164 164 165 165 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; 166 /*** END OF REFACTORED CODE ***/167 166 VkDevice device; 168 167 169 168 VkQueue graphicsQueue; 170 169 VkQueue presentQueue; 170 /*** END OF REFACTORED CODE ***/ 171 171 172 172 VkSwapchainKHR swapChain; … … 316 316 createSurface(); 317 317 pickPhysicalDevice(); 318 createLogicalDevice(); 318 319 /*** END OF REFACTORED CODE ***/ 319 createLogicalDevice();320 320 createSwapChain(); 321 321 createImageViews(); … … 561 561 return requiredExtensions.empty(); 562 562 } 563 /*** END OF REFACTORED CODE ***/564 563 565 564 void createLogicalDevice() { … … 609 608 vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue); 610 609 } 610 /*** END OF REFACTORED CODE ***/ 611 611 612 612 void createSwapChain() { … … 1674 1674 } 1675 1675 1676 /*** START OF REFACTORED CODE ***/ 1676 1677 void mainLoop() { 1677 1678 // TODO: Create some generic event-handling functions in game-gui-* … … 1690 1691 quit = true; 1691 1692 } 1693 /*** END OF REFACTORED CODE ***/ 1692 1694 if (e.type == SDL_WINDOWEVENT) { 1693 1695 if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED || … … 1696 1698 } 1697 1699 } 1700 /*** START OF REFACTORED CODE ***/ 1698 1701 } 1699 1702 … … 1705 1708 vkDeviceWaitIdle(device); 1706 1709 } 1710 /*** END OF REFACTORED CODE ***/ 1707 1711 1708 1712 void drawFrame() { … … 1853 1857 } 1854 1858 1859 /*** START OF REFACTORED CODE ***/ 1855 1860 void cleanup() { 1856 1861 cleanupSwapChain(); 1862 /*** END OF REFACTORED CODE ***/ 1857 1863 1858 1864 vkDestroySampler(device, textureSampler, nullptr); … … 1880 1886 1881 1887 vkDestroyCommandPool(device, commandPool, nullptr); 1888 /*** START OF REFACTORED CODE ***/ 1882 1889 vkDestroyDevice(device, nullptr); 1883 1890 vkDestroySurfaceKHR(instance, surface, nullptr); 1884 1891 1885 /*** START OF REFACTORED CODE ***/1886 1892 if (enableValidationLayers) { 1887 1893 DestroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr); … … 1919 1925 gui->shutdown(); 1920 1926 delete gui; 1927 } 1928 1929 void cleanupSwapChain() { 1921 1930 /*** END OF REFACTORED CODE ***/ 1922 }1923 1924 void cleanupSwapChain() {1925 1931 vkDestroyImageView(device, depthImageView, nullptr); 1926 1932 vkDestroyImage(device, depthImage, nullptr); … … 1948 1954 vkFreeMemory(device, uniformBuffersMemory[i], nullptr); 1949 1955 } 1950 } 1956 /*** START OF REFACTORED CODE ***/ 1957 } 1958 /*** END OF REFACTORED CODE ***/ 1951 1959 1952 1960 void cleanupPipeline(GraphicsPipelineInfo& pipeline) {
Note:
See TracChangeset
for help on using the changeset viewer.