#include "sdl_context.hpp" #include #include #include #include namespace bookmouse { using fud::assertFail; SdlContext::SdlContext() { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { const auto* lastError = SDL_GetError(); throw std::runtime_error{lastError}; } // Decide GL+GLSL versions #if defined(IMGUI_IMPL_OPENGL_ES2) // GL ES 2.0 + GLSL 100 setAttribute(SDL_GL_CONTEXT_FLAGS, 0); setAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); setAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); setAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); #elif defined(__APPLE__) // GL 3.2 Core + GLSL 150 setAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac setAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); setAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); setAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); #else // GL 3.0 + GLSL 130 setAttribute(SDL_GL_CONTEXT_FLAGS, 0); setAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); setAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); setAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); #endif // From 2.0.18: Enable native IME. #ifdef SDL_HINT_IME_SHOW_UI auto hintSet = SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1"); fudAssert(hintSet == SDL_TRUE); #endif } SdlContext::~SdlContext() { SDL_Quit(); } int SdlContext::setAttribute(SDL_GLattr attr, int value) const { auto result = SDL_GL_SetAttribute(attr, value); assert(result == 0); return result; } } // namespace bookmouse