Changeset 4e705d6 in opengl-game
- Timestamp:
- Jun 9, 2020, 2:14:06 PM (4 years ago)
- Branches:
- feature/imgui-sdl, master
- Children:
- e1f88a9
- Parents:
- b8d4456
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
rb8d4456 r4e705d6 42 42 cout << "Vulkan Game" << endl; 43 43 44 // This gets the runtime version, use SDL_VERSION() for the comppile-time version 44 if (initUI(width, height, guiFlags) == RTWO_ERROR) { 45 return; 46 } 47 48 initVulkan(); 49 mainLoop(); 50 cleanup(); 51 52 close_log(); 53 } 54 55 bool VulkanGame::initUI(int width, int height, unsigned char guiFlags) { 45 56 // TODO: Create a game-gui function to get the gui version and retrieve it that way 46 SDL_GetVersion(&sdlVersion); 57 58 SDL_VERSION(&sdlVersion); // This gets the compile-time version 59 SDL_GetVersion(&sdlVersion); // This gets the runtime version 60 61 cout << "SDL "<< 62 to_string(sdlVersion.major) << "." << 63 to_string(sdlVersion.minor) << "." << 64 to_string(sdlVersion.patch) << endl; 47 65 48 66 // TODO: Refactor the logger api to be more flexible, … … 54 72 to_string(sdlVersion.patch).c_str()); 55 73 74 // TODO: Use open_Log() and related functions instead of gl_log ones 56 75 open_log(); 57 76 get_log() << "starting SDL" << endl; … … 61 80 (int)sdlVersion.patch << endl; 62 81 63 if (initWindow(width, height, guiFlags) == RTWO_ERROR) {64 return;65 }66 67 initVulkan();68 mainLoop();69 cleanup();70 71 close_log();72 }73 74 // TODO: Make some more init functions, or call this initUI if the75 // amount of things initialized here keeps growing76 bool VulkanGame::initWindow(int width, int height, unsigned char guiFlags) {77 82 // TODO: Put all fonts, textures, and images in the assets folder 78 83 gui = new GameGui_SDL(); … … 102 107 } 103 108 104 SDL_VERSION(&sdlVersion); 105 106 cout << "SDL "<< 107 to_string(sdlVersion.major) << "." << 108 to_string(sdlVersion.minor) << "." << 109 to_string(sdlVersion.patch) << endl; 109 uiOverlay = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 110 gui->getWindowWidth(), gui->getWindowHeight()); 111 112 if (uiOverlay == nullptr) { 113 cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << endl; 114 return RTWO_ERROR; 115 } 116 if (SDL_SetTextureBlendMode(uiOverlay, SDL_BLENDMODE_BLEND) != 0) { 117 cout << "Unable to set texture blend mode! SDL Error: " << SDL_GetError() << endl; 118 return RTWO_ERROR; 119 } 120 121 SDL_SetRenderTarget(renderer, uiOverlay); 110 122 111 123 font = TTF_OpenFont("assets/fonts/lazy.ttf", 28); … … 145 157 146 158 SDL_FreeSurface(imageSDLSurface); 147 148 // In SDL 2.0.10 (currently, the latest), SDL_TEXTUREACCESS_TARGET is required to get a transparent overlay working149 // However, the latest SDL version available through homebrew on Mac is 2.0.9, which requires SDL_TEXTUREACCESS_STREAMING150 // I tried building sdl 2.0.10 (and sdl_image and sdl_ttf) from source on Mac, but had some issues, so this is easier151 // until the homebrew recipe is updated152 if (sdlVersion.major == 2 && sdlVersion.minor == 0 && sdlVersion.patch == 9) {153 uiOverlay = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING,154 gui->getWindowWidth(), gui->getWindowHeight());155 } else {156 uiOverlay = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET,157 gui->getWindowWidth(), gui->getWindowHeight());158 }159 160 if (uiOverlay == nullptr) {161 cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << endl;162 return RTWO_ERROR;163 }164 if (SDL_SetTextureBlendMode(uiOverlay, SDL_BLENDMODE_BLEND) != 0) {165 cout << "Unable to set texture blend mode! SDL Error: " << SDL_GetError() << endl;166 return RTWO_ERROR;167 }168 169 SDL_SetRenderTarget(renderer, uiOverlay);170 159 171 160 return RTWO_SUCCESS; … … 755 744 break; 756 745 case UI_EVENT_MOUSEBUTTONDOWN: 757 cout << "Mouse button down event detected" << endl;758 break;759 746 case UI_EVENT_MOUSEBUTTONUP: 760 cout << "Mouse button up event detected" << endl;761 break;762 747 case UI_EVENT_MOUSEMOTION: 763 748 break; 764 749 case UI_EVENT_UNKNOWN: 765 cout << "Unknown event type: 0x" << hex << e.unknown.eventType << dec << endl;750 //cout << "Unknown event type: 0x" << hex << e.unknown.eventType << dec << endl; 766 751 break; 767 752 default: … … 1030 1015 uint32_t imageIndex; 1031 1016 1017 // TODO: Recreate the swap chain here if the user went to a new screen 1018 1032 1019 VkResult result = vkAcquireNextImageKHR(device, swapChain, numeric_limits<uint64_t>::max(), 1033 1020 imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex); … … 1127 1114 // If they do, I don't need to check for that 1128 1115 1116 if (fontSDLTexture != nullptr) { 1117 SDL_DestroyTexture(fontSDLTexture); 1118 fontSDLTexture = nullptr; 1119 } 1120 1121 if (imageSDLTexture != nullptr) { 1122 SDL_DestroyTexture(imageSDLTexture); 1123 imageSDLTexture = nullptr; 1124 } 1125 1126 TTF_CloseFont(font); 1127 font = nullptr; 1128 1129 1129 if (uiOverlay != nullptr) { 1130 1130 SDL_DestroyTexture(uiOverlay); 1131 1131 uiOverlay = nullptr; 1132 1132 } 1133 1134 if (fontSDLTexture != nullptr) {1135 SDL_DestroyTexture(fontSDLTexture);1136 fontSDLTexture = nullptr;1137 }1138 1139 if (imageSDLTexture != nullptr) {1140 SDL_DestroyTexture(imageSDLTexture);1141 imageSDLTexture = nullptr;1142 }1143 1144 TTF_CloseFont(font);1145 font = nullptr;1146 1133 1147 1134 SDL_DestroyRenderer(renderer); -
vulkan-game.hpp
rb8d4456 r4e705d6 11 11 #include <glm/gtc/matrix_transform.hpp> 12 12 13 #include "vulkan-utils.hpp" 14 #include "graphics-pipeline_vulkan.hpp" 15 13 16 #include "game-gui-sdl.hpp" 14 #include "graphics-pipeline_vulkan.hpp"15 16 #include "vulkan-utils.hpp"17 17 18 18 using namespace glm; 19 19 using namespace std::chrono; 20 21 // TODO: Switch from union to std::variant 20 22 21 23 #ifdef NDEBUG … … 193 195 void run(int width, int height, unsigned char guiFlags); 194 196 197 GraphicsPipeline_Vulkan<OverlayVertex, void*> overlayPipeline; 198 199 GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline; 200 201 GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject> shipPipeline; 202 203 GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline; 204 205 GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline; 206 207 GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline; 208 195 209 private: 196 210 // TODO: Make these consts static 211 // Also, maybe move them into consts.hpp 197 212 198 213 const int MAX_FRAMES_IN_FLIGHT; … … 207 222 vec3 cam_pos; 208 223 224 // TODO: Good place to start using smart pointers 209 225 GameGui* gui; 210 226 … … 237 253 VulkanImage depthImage; 238 254 239 VkSampler textureSampler;240 241 VulkanImage sdlOverlayImage;242 VkDescriptorImageInfo sdlOverlayImageDescriptor;243 244 VulkanImage floorTextureImage;245 VkDescriptorImageInfo floorTextureImageDescriptor;246 247 VulkanImage laserTextureImage;248 VkDescriptorImageInfo laserTextureImageDescriptor;249 250 TTF_Font* font;251 SDL_Texture* fontSDLTexture;252 253 SDL_Texture* imageSDLTexture;254 255 255 vector<VkSemaphore> imageAvailableSemaphores; 256 256 vector<VkSemaphore> renderFinishedSemaphores; … … 261 261 bool framebufferResized; 262 262 263 VkSampler textureSampler; 264 265 VulkanImage sdlOverlayImage; 266 VkDescriptorImageInfo sdlOverlayImageDescriptor; 267 268 VulkanImage floorTextureImage; 269 VkDescriptorImageInfo floorTextureImageDescriptor; 270 271 VulkanImage laserTextureImage; 272 VkDescriptorImageInfo laserTextureImageDescriptor; 273 274 TTF_Font* font; 275 SDL_Texture* fontSDLTexture; 276 277 SDL_Texture* imageSDLTexture; 278 263 279 mat4 viewMat, projMat; 264 265 GraphicsPipeline_Vulkan<OverlayVertex, void*> overlayPipeline;266 vector<SceneObject<OverlayVertex, void*>> overlayObjects;267 280 268 281 // TODO: Maybe make the ubo objects part of the pipeline class since there's only one ubo … … 274 287 // if there is a need to add other uniform variables to one or more of the shaders 275 288 276 GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline; 289 vector<SceneObject<OverlayVertex, void*>> overlayObjects; 290 277 291 vector<SceneObject<ModelVertex, SSBO_ModelObject>> modelObjects; 278 292 … … 283 297 UBO_VP_mats object_VP_mats; 284 298 285 GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject> shipPipeline;286 299 vector<SceneObject<ShipVertex, SSBO_ModelObject>> shipObjects; 287 300 … … 292 305 UBO_VP_mats ship_VP_mats; 293 306 294 GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline;295 307 vector<SceneObject<AsteroidVertex, SSBO_Asteroid>> asteroidObjects; 296 308 … … 301 313 UBO_VP_mats asteroid_VP_mats; 302 314 303 GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline;304 315 vector<SceneObject<LaserVertex, SSBO_Laser>> laserObjects; 305 316 … … 310 321 UBO_VP_mats laser_VP_mats; 311 322 312 GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline;313 323 vector<SceneObject<ExplosionVertex, SSBO_Explosion>> explosionObjects; 314 324 … … 336 346 EffectOverTime<AsteroidVertex, SSBO_Asteroid>* rightLaserEffect = nullptr; 337 347 338 bool init Window(int width, int height, unsigned char guiFlags);348 bool initUI(int width, int height, unsigned char guiFlags); 339 349 void initVulkan(); 340 350 void initGraphicsPipelines();
Note:
See TracChangeset
for help on using the changeset viewer.