Changeset c1d9b2a in opengl-game
- Timestamp:
- Sep 15, 2019, 5:44:41 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- df2cc24
- Parents:
- 92cbc6a
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
VulkanGame.vcxproj
r92cbc6a rc1d9b2a 139 139 <ClCompile Include="StackWalker.cpp" /> 140 140 <ClCompile Include="vulkan-game.cpp" /> 141 <ClCompile Include="vulkan-utils.cpp" /> 141 142 </ItemGroup> 142 143 <ItemGroup> … … 150 151 <ClInclude Include="StackWalker.h" /> 151 152 <ClInclude Include="vulkan-game.hpp" /> 153 <ClInclude Include="vulkan-utils.hpp" /> 152 154 </ItemGroup> 153 155 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> -
vulkan-game.cpp
r92cbc6a rc1d9b2a 5 5 #include "consts.hpp" 6 6 #include "logger.hpp" 7 8 #include "vulkan-utils.hpp" 7 9 8 10 using namespace std; … … 44 46 } 45 47 46 SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);47 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);48 49 SDL_RenderClear(renderer);50 51 SDL_RenderPresent(renderer);52 53 48 initVulkan(); 54 49 mainLoop(); … … 81 76 cout << "Actual window size: (" << gui->getWindowWidth() << ", " << gui->getWindowHeight() << ")" << endl; 82 77 78 renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); 79 if (renderer == nullptr) { 80 cout << "Renderer could not be created!" << endl; 81 cout << gui->getError() << endl; 82 return RTWO_ERROR; 83 } 84 83 85 return RTWO_SUCCESS; 84 86 } 85 87 86 88 void VulkanGame::initVulkan() { 89 const vector<const char*> validationLayers = { 90 "VK_LAYER_KHRONOS_validation" 91 }; 92 93 createVulkanInstance(validationLayers); 94 setupDebugMessenger(); 87 95 } 88 96 … … 90 98 UIEvent e; 91 99 bool quit = false; 100 101 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); 92 102 93 103 while (!quit) { … … 123 133 } 124 134 } 135 136 SDL_RenderClear(renderer); 137 SDL_RenderPresent(renderer); 125 138 } 126 139 } 127 140 128 141 void VulkanGame::cleanup() { 142 if (ENABLE_VALIDATION_LAYERS) { 143 VulkanUtils::destroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr); 144 } 145 vkDestroyInstance(instance, nullptr); 146 147 SDL_DestroyRenderer(renderer); 148 renderer = nullptr; 149 129 150 gui->destroyWindow(); 130 151 gui->shutdown(); 131 152 delete gui; 132 153 } 154 155 void VulkanGame::createVulkanInstance(const vector<const char*> &validationLayers) { 156 if (ENABLE_VALIDATION_LAYERS && !VulkanUtils::checkValidationLayerSupport(validationLayers)) { 157 throw runtime_error("validation layers requested, but not available!"); 158 } 159 160 VkApplicationInfo appInfo = {}; 161 appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; 162 appInfo.pApplicationName = "Vulkan Game"; 163 appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); 164 appInfo.pEngineName = "No Engine"; 165 appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); 166 appInfo.apiVersion = VK_API_VERSION_1_0; 167 168 VkInstanceCreateInfo createInfo = {}; 169 createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; 170 createInfo.pApplicationInfo = &appInfo; 171 172 vector<const char*> extensions = gui->getRequiredExtensions(); 173 if (ENABLE_VALIDATION_LAYERS) { 174 extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); 175 } 176 177 createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size()); 178 createInfo.ppEnabledExtensionNames = extensions.data(); 179 180 cout << endl << "Extensions:" << endl; 181 for (const char* extensionName : extensions) { 182 cout << extensionName << endl; 183 } 184 cout << endl; 185 186 VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo; 187 if (ENABLE_VALIDATION_LAYERS) { 188 createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size()); 189 createInfo.ppEnabledLayerNames = validationLayers.data(); 190 191 populateDebugMessengerCreateInfo(debugCreateInfo); 192 createInfo.pNext = &debugCreateInfo; 193 } else { 194 createInfo.enabledLayerCount = 0; 195 196 createInfo.pNext = nullptr; 197 } 198 199 if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) { 200 throw runtime_error("failed to create instance!"); 201 } 202 } 203 204 void VulkanGame::setupDebugMessenger() { 205 if (!ENABLE_VALIDATION_LAYERS) return; 206 207 VkDebugUtilsMessengerCreateInfoEXT createInfo; 208 populateDebugMessengerCreateInfo(createInfo); 209 210 if (VulkanUtils::createDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger) != VK_SUCCESS) { 211 throw runtime_error("failed to set up debug messenger!"); 212 } 213 } 214 215 void VulkanGame::populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo) { 216 createInfo = {}; 217 createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; 218 createInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; 219 createInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; 220 createInfo.pfnUserCallback = debugCallback; 221 } 222 223 VKAPI_ATTR VkBool32 VKAPI_CALL VulkanGame::debugCallback( 224 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, 225 VkDebugUtilsMessageTypeFlagsEXT messageType, 226 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, 227 void* pUserData) { 228 cerr << "validation layer: " << pCallbackData->pMessage << endl; 229 230 return VK_FALSE; 231 } -
vulkan-game.hpp
r92cbc6a rc1d9b2a 22 22 SDL_version sdlVersion; 23 23 SDL_Window* window; 24 SDL_Renderer* renderer; 25 26 VkInstance instance; 27 VkDebugUtilsMessengerEXT debugMessenger; 24 28 25 29 bool initWindow(int width, int height, unsigned char guiFlags); … … 27 31 void mainLoop(); 28 32 void cleanup(); 33 34 void createVulkanInstance(const vector<const char*> &validationLayers); 35 void setupDebugMessenger(); 36 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo); 37 38 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback( 39 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, 40 VkDebugUtilsMessageTypeFlagsEXT messageType, 41 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, 42 void* pUserData); 29 43 }; 30 44
Note:
See TracChangeset
for help on using the changeset viewer.