[f898c5f] | 1 | #include "game-gui-sdl.hpp"
|
---|
| 2 |
|
---|
| 3 | bool GameGui_SDL::Init() {
|
---|
| 4 | // may want to define SDL_INIT_NOPARACHUTE when I start handling crashes since it
|
---|
| 5 | // prevents SDL from setting up its own handlers for SIG_SEGV and stuff like that
|
---|
| 6 |
|
---|
| 7 | // If this function fails, I can call SDL_GetError() for more info
|
---|
| 8 | // I should create a generic error retrieval function, similar to SDL_GetError()
|
---|
| 9 |
|
---|
| 10 | // cout << "SDL could not initialize! SDL_Error: " << SDL_GetError() << endl;
|
---|
| 11 |
|
---|
| 12 | return SDL_Init(SDL_INIT_EVERYTHING) < 0 ? RTWO_ERROR : RTWO_SUCCESS;
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | void GameGui_SDL::Shutdown() {
|
---|
| 16 | SDL_Quit();
|
---|
[826df16] | 17 | }
|
---|
[0e6ecf3] | 18 |
|
---|
| 19 | void* GameGui_SDL::CreateWindow(const string& title, unsigned int width, unsigned int height) {
|
---|
| 20 | // On Apple's OS X you must set the NSHighResolutionCapable Info.plist property to YES,
|
---|
| 21 | // otherwise you will not receive a High DPI OpenGL canvas.
|
---|
| 22 | window = SDL_CreateWindow(title.c_str(),
|
---|
| 23 | SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
---|
| 24 | width, height,
|
---|
| 25 | SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
|
---|
| 26 |
|
---|
| 27 | return window;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | void GameGui_SDL::DestroyWindow() {
|
---|
| 31 | // TODO: This function can throw some errors. They should be handled
|
---|
| 32 | SDL_DestroyWindow(window);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | bool GameGui_SDL::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {
|
---|
| 36 | return SDL_Vulkan_CreateSurface(window, instance, surface) ?
|
---|
| 37 | RTWO_SUCCESS : RTWO_ERROR;
|
---|
| 38 | }
|
---|
[8667f76] | 39 |
|
---|
| 40 | vector<const char*> GameGui_SDL::GetRequiredExtensions() {
|
---|
| 41 | uint32_t extensionCount = 0;
|
---|
| 42 | SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, nullptr);
|
---|
| 43 |
|
---|
| 44 | vector<const char*> extensions(extensionCount);
|
---|
| 45 | SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, extensions.data());
|
---|
| 46 |
|
---|
| 47 | return extensions;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | void GameGui_SDL::GetWindowSize(int* width, int* height) {
|
---|
| 51 | SDL_GetWindowSize(window, width, height);
|
---|
| 52 | }
|
---|