35 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
36 #include <SDL_events.h>
37 #include <SDL_hints.h>
38 #include <SDL_render.h>
39 #include <SDL_syswm.h>
46 std::set<std::string> modes;
47 const int numDisplays = SDL_GetNumVideoDisplays();
48 for (
int display = 0; display < numDisplays; display ++)
50 const int numModes = SDL_GetNumDisplayModes(display);
53 for (
int f = 0; f < numModes; f ++)
56 SDL_GetDisplayMode(display, f, &mode);
59 logger->
log(
"%dx%dx%d", w, h, mode.refresh_rate);
64 FOR_EACH (std::set<std::string>::const_iterator, it, modes)
65 modeList.push_back(*it);
71 SDL_SetWindowTitle(window, title);
76 SDL_SetWindowIcon(window, icon);
81 SDL_SetWindowGrab(window, grab ? SDL_TRUE : SDL_FALSE);
86 SDL_SetWindowBrightness(window, gamma);
91 SDL_GL_SetSwapInterval(val);
96 return SDL_GetWindowWMInfo(window,
info);
103 return SDL_CreateThread(fn, name,
data);
111 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
112 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
113 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile);
116 void *context = SDL_GL_CreateContext(window);
117 if (context ==
nullptr)
119 logger->
log(
"Error to switch to context %d.%d: %s",
124 if (context ==
nullptr && (major > 3 || (major == 3 && minor > 3)))
126 logger->
log(
"Try fallback to OpenGL 3.3 context");
127 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
128 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
130 context = SDL_GL_CreateContext(window);
131 if (context ==
nullptr)
133 logger->
log(
"Error to switch to context 3.3: %s",
136 if (context ==
nullptr && profile == 0x01)
138 logger->
log(
"Try fallback to OpenGL 3.3 compatibility context");
139 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
140 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
141 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0x02);
143 context = SDL_GL_CreateContext(window);
144 if (context ==
nullptr)
146 logger->
log(
"Error to switch to compatibility context 3.3: %s",
151 if (context ==
nullptr && (major > 3 || (major == 3 && minor > 0)))
153 logger->
log(
"Error to switch to core context %d.%d: %s",
157 logger->
log(
"Try fallback to OpenGL 3.0 core context");
158 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
159 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
160 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile);
161 context = SDL_GL_CreateContext(window);
162 if (context ==
nullptr)
164 logger->
log(
"Error to switch to core context 3.0: %s",
168 if (context ==
nullptr && (major > 2 || (major == 2 && minor > 1)))
170 logger->
log(
"Try fallback to OpenGL 2.1 compatibility context");
171 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
172 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
173 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0x02);
174 context = SDL_GL_CreateContext(window);
175 if (context ==
nullptr)
177 logger->
log(
"Error to switch to compatibility context 2.1: %s",
181 if (context ==
nullptr)
183 logger->
log(
"Cant find working context.");
204 if (thread !=
nullptr)
205 SDL_WaitThread(thread,
nullptr);
211 return SDL_PeepEvents(event,
222 #if SDL_VERSION_ATLEAST(2, 0, 2)
223 SDL_SetHintWithPriority(SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
227 SDL_EnableScreenSaver();
231 #if SDL_VERSION_ATLEAST(2, 0, 2)
232 SDL_SetHintWithPriority(SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
236 SDL_DisableScreenSaver();
241 const std::string ¤tRenderer)
243 SDL_RendererInfo
info;
244 const int num = SDL_GetNumRenderDrivers();
245 for (
int f = 0; f < num; f ++)
247 if (!SDL_GetRenderDriverInfo(f, &
info))
248 list.push_back(
info.name);
250 if (!currentRenderer.empty())
255 if (*it == currentRenderer)
262 list.push_back(currentRenderer);
264 std::sort(list.begin(), list.end());
267 void SDL::setRendererHint(
const std::string &driver)
271 SDL_SetHintWithPriority(SDL_HINT_RENDER_DRIVER,
void log(const char *const log_text,...)
#define FOR_EACH(type, iter, array)
bool info(InputEvent &event)
SDL_Thread * createThread(int(*fn)(void *), const char *const name, void *const data)
void SetWindowTitle(const SDL_Surface *const window, const char *const title)
void WaitThread(SDL_Thread *const thread)
bool PollEvent(SDL_Event *event)
bool getWindowWMInfo(const SDL_Surface *const window, SDL_SysWMinfo *const info)
void setLogLevel(const int level)
void SetWindowIcon(const SDL_Surface *const window, SDL_Surface *const icon)
void makeCurrentContext(void *const context)
void grabInput(const SDL_Surface *const window, const bool grab)
void setGamma(const SDL_Surface *const window, const float gamma)
void setVsync(const int val)
bool getAllVideoModes(StringVect &modeList)
void allowScreenSaver(const bool allow)
void * createGLContext(SDL_Surface *const window, const int major, const int minor, const int profile)
std::string strprintf(const char *const format,...)
StringVect::const_iterator StringVectCIter
std::vector< std::string > StringVect