Changeset b3671b5 in opengl-game
- Timestamp:
- Jul 8, 2019, 9:03:04 PM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 1c6cd5e
- Parents:
- 909b51a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r909b51a rb3671b5 13 13 #include <iostream> 14 14 #include <vector> 15 #include <set> 15 16 #include <stdexcept> 16 17 #include <cstdlib> … … 37 38 struct QueueFamilyIndices { 38 39 optional<uint32_t> graphicsFamily; 40 optional<uint32_t> presentFamily; 39 41 40 42 bool isComplete() { 41 return graphicsFamily.has_value() ;43 return graphicsFamily.has_value() && presentFamily.has_value(); 42 44 } 43 45 }; … … 94 96 VkInstance instance; 95 97 VkDebugUtilsMessengerEXT debugMessenger; 98 VkSurfaceKHR surface; 99 96 100 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; 97 101 VkDevice device; 102 98 103 VkQueue graphicsQueue; 104 VkQueue presentQueue; 99 105 100 106 // both SDL and GLFW create window functions return NULL on failure … … 125 131 createInstance(); 126 132 setupDebugMessenger(); 133 createSurface(); 127 134 pickPhysicalDevice(); 128 135 createLogicalDevice(); … … 150 157 createInfo.ppEnabledExtensionNames = extensions.data(); 151 158 159 cout << endl << "SDL extensions:" << endl; 160 for (const char* extensionName : extensions) { 161 cout << extensionName << endl; 162 } 163 cout << endl; 164 152 165 VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo; 153 166 if (enableValidationLayers) { … … 177 190 throw runtime_error("failed to setup debug messenger!"); 178 191 } 192 } 193 194 void createSurface() { 195 //SDL_Surface* screenSurface = nullptr; 196 197 if (!SDL_Vulkan_CreateSurface(window, instance, &surface)) { 198 throw runtime_error("failed to create window surface!"); 199 } 200 201 /* 202 if (glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) { 203 throw runtime_error("failed to create window surface!"); 204 } 205 */ 179 206 } 180 207 … … 221 248 QueueFamilyIndices indices = findQueueFamilies(physicalDevice); 222 249 223 VkDeviceQueueCreateInfo queueCreateInfo = {}; 224 queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; 225 queueCreateInfo.queueFamilyIndex = indices.graphicsFamily.value(); 226 queueCreateInfo.queueCount = 1; 250 vector<VkDeviceQueueCreateInfo> queueCreateInfos; 251 set<uint32_t> uniqueQueueFamilies = {indices.graphicsFamily.value(), indices.presentFamily.value()}; 227 252 228 253 float queuePriority = 1.0f; 229 queueCreateInfo.pQueuePriorities = &queuePriority; 254 for (uint32_t queueFamily : uniqueQueueFamilies) { 255 VkDeviceQueueCreateInfo queueCreateInfo = {}; 256 257 queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; 258 queueCreateInfo.queueFamilyIndex = queueFamily; 259 queueCreateInfo.queueCount = 1; 260 queueCreateInfo.pQueuePriorities = &queuePriority; 261 262 queueCreateInfos.push_back(queueCreateInfo); 263 } 230 264 231 265 VkPhysicalDeviceFeatures deviceFeatures = {}; … … 234 268 createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; 235 269 236 createInfo. pQueueCreateInfos = &queueCreateInfo;237 createInfo. queueCreateInfoCount = 1;270 createInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size());; 271 createInfo.pQueueCreateInfos = queueCreateInfos.data(); 238 272 239 273 createInfo.pEnabledFeatures = &deviceFeatures; … … 255 289 256 290 vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue); 291 vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue); 257 292 } 258 293 … … 295 330 if (queueFamily.queueCount > 0 && queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) { 296 331 indices.graphicsFamily = i; 332 } 333 334 VkBool32 presentSupport = false; 335 vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport); 336 337 if (queueFamily.queueCount > 0 && presentSupport) { 338 indices.presentFamily = i; 297 339 } 298 340 … … 335 377 336 378 /* 337 SDL_Surface* screenSurface = nullptr;338 VkSurfaceKHR surface;339 340 if (!SDL_Vulkan_CreateSurface(window, instance, &surface)) {341 cout << "Couild not create Vulkan surface" << endl;342 }343 344 379 screenSurface = SDL_GetWindowSurface(window); 345 380 cout << "Got here" << endl; … … 375 410 } 376 411 412 vkDestroySurfaceKHR(instance, surface, nullptr); 377 413 vkDestroyInstance(instance, nullptr); 378 414
Note:
See TracChangeset
for help on using the changeset viewer.