Override renderer for OpenGL window, only in case if OpenGL or OpenGL ES renderers are enabled.
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 /* The high-level video driver subsystem */
27 #include "SDL_video.h"
28 #include "SDL_sysvideo.h"
30 #include "SDL_pixels_c.h"
31 #include "SDL_renderer_gl.h"
32 #include "SDL_renderer_gles.h"
33 #include "SDL_renderer_sw.h"
34 #include "../events/SDL_sysevents.h"
35 #include "../events/SDL_events_c.h"
37 #if SDL_VIDEO_OPENGL_ES
38 #include "SDL_opengles.h"
39 #endif /* SDL_VIDEO_OPENGL_ES */
42 #include "SDL_opengl.h"
44 /* On Windows, windows.h defines CreateWindow */
48 #endif /* SDL_VIDEO_OPENGL */
50 /* Available video drivers */
51 static VideoBootStrap *bootstrap[] = {
52 #if SDL_VIDEO_DRIVER_COCOA
55 #if SDL_VIDEO_DRIVER_X11
58 #if SDL_VIDEO_DRIVER_FBCON
61 #if SDL_VIDEO_DRIVER_DIRECTFB
64 #if SDL_VIDEO_DRIVER_PS2GS
67 #if SDL_VIDEO_DRIVER_PS3
70 #if SDL_VIDEO_DRIVER_SVGALIB
73 #if SDL_VIDEO_DRIVER_GAPI
76 #if SDL_VIDEO_DRIVER_WIN32
79 #if SDL_VIDEO_DRIVER_BWINDOW
82 #if SDL_VIDEO_DRIVER_PHOTON
85 #if SDL_VIDEO_DRIVER_QNXGF
88 #if SDL_VIDEO_DRIVER_EPOC
91 #if SDL_VIDEO_DRIVER_RISCOS
94 #if SDL_VIDEO_DRIVER_NDS
97 #if SDL_VIDEO_DRIVER_UIKIT
100 #if SDL_VIDEO_DRIVER_DUMMY
103 #if SDL_VIDEO_DRIVER_PANDORA
109 static SDL_VideoDevice *_this = NULL;
111 /* Various local functions */
112 static void SDL_UpdateWindowGrab(SDL_Window * window);
115 cmpmodes(const void *A, const void *B)
117 SDL_DisplayMode a = *(const SDL_DisplayMode *) A;
118 SDL_DisplayMode b = *(const SDL_DisplayMode *) B;
126 if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) {
127 return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format);
129 if (SDL_PIXELLAYOUT(a.format) != SDL_PIXELLAYOUT(b.format)) {
130 return SDL_PIXELLAYOUT(b.format) - SDL_PIXELLAYOUT(a.format);
132 if (a.refresh_rate != b.refresh_rate) {
133 return b.refresh_rate - a.refresh_rate;
139 SDL_UninitializedVideo()
141 SDL_SetError("Video subsystem has not been initialized");
145 SDL_GetNumVideoDrivers(void)
147 return SDL_arraysize(bootstrap) - 1;
151 SDL_GetVideoDriver(int index)
153 if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
154 return bootstrap[index]->name;
160 * Initialize the video and event subsystems -- determine native pixel format
163 SDL_VideoInit(const char *driver_name, Uint32 flags)
165 SDL_VideoDevice *video;
169 /* Toggle the event thread flags, based on OS requirements */
170 #if defined(MUST_THREAD_EVENTS)
171 flags |= SDL_INIT_EVENTTHREAD;
172 #elif defined(CANT_THREAD_EVENTS)
173 if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) {
174 SDL_SetError("OS doesn't support threaded events");
179 /* Start the event loop */
180 if (SDL_StartEventLoop(flags) < 0) {
183 /* Check to make sure we don't overwrite '_this' */
187 /* Select the proper video driver */
190 if (driver_name == NULL) {
191 driver_name = SDL_getenv("SDL_VIDEODRIVER");
193 if (driver_name != NULL) {
194 for (i = 0; bootstrap[i]; ++i) {
195 if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) {
196 video = bootstrap[i]->create(index);
201 for (i = 0; bootstrap[i]; ++i) {
202 if (bootstrap[i]->available()) {
203 video = bootstrap[i]->create(index);
212 SDL_SetError("%s not available", driver_name);
214 SDL_SetError("No available video device");
219 _this->name = bootstrap[i]->name;
220 _this->next_object_id = 1;
223 /* Set some very sane GL defaults */
224 _this->gl_config.driver_loaded = 0;
225 _this->gl_config.dll_handle = NULL;
226 _this->gl_config.red_size = 3;
227 _this->gl_config.green_size = 3;
228 _this->gl_config.blue_size = 2;
229 _this->gl_config.alpha_size = 0;
230 _this->gl_config.buffer_size = 0;
231 _this->gl_config.depth_size = 16;
232 _this->gl_config.stencil_size = 0;
233 _this->gl_config.double_buffer = 1;
234 _this->gl_config.accum_red_size = 0;
235 _this->gl_config.accum_green_size = 0;
236 _this->gl_config.accum_blue_size = 0;
237 _this->gl_config.accum_alpha_size = 0;
238 _this->gl_config.stereo = 0;
239 _this->gl_config.multisamplebuffers = 0;
240 _this->gl_config.multisamplesamples = 0;
241 _this->gl_config.retained_backing = 1;
242 _this->gl_config.accelerated = -1; /* not known, don't set */
243 _this->gl_config.major_version = 2;
244 _this->gl_config.minor_version = 1;
246 /* Initialize the video subsystem */
247 if (_this->VideoInit(_this) < 0) {
251 /* Make sure some displays were added */
252 if (_this->num_displays == 0) {
253 SDL_SetError("The video driver did not add any displays");
257 /* The software renderer is always available */
258 for (i = 0; i < _this->num_displays; ++i) {
259 if (_this->GL_CreateContext) {
260 #if SDL_VIDEO_RENDER_OGL
261 SDL_AddRenderDriver(i, &GL_RenderDriver);
263 #if SDL_VIDEO_RENDER_OGL_ES
264 SDL_AddRenderDriver(i, &GL_ES_RenderDriver);
267 if (_this->displays[i].num_render_drivers > 0) {
268 SDL_AddRenderDriver(i, &SW_RenderDriver);
272 /* We're ready to go! */
277 SDL_GetCurrentVideoDriver()
280 SDL_UninitializedVideo();
293 SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode)
295 SDL_VideoDisplay display;
299 display.desktop_mode = *desktop_mode;
301 display.current_mode = display.desktop_mode;
303 return SDL_AddVideoDisplay(&display);
307 SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
309 SDL_VideoDisplay *displays;
313 SDL_realloc(_this->displays,
314 (_this->num_displays + 1) * sizeof(*displays));
316 index = _this->num_displays++;
317 displays[index] = *display;
318 displays[index].device = _this;
319 _this->displays = displays;
327 SDL_GetNumVideoDisplays(void)
330 SDL_UninitializedVideo();
333 return _this->num_displays;
337 SDL_SelectVideoDisplay(int index)
340 SDL_UninitializedVideo();
343 if (index < 0 || index >= _this->num_displays) {
344 SDL_SetError("index must be in the range 0 - %d",
345 _this->num_displays - 1);
348 _this->current_display = index;
353 SDL_GetCurrentVideoDisplay(void)
356 SDL_UninitializedVideo();
359 return _this->current_display;
363 SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
365 SDL_VideoDisplay *display = &_this->displays[displayIndex];
366 SDL_DisplayMode *modes;
369 /* Make sure we don't already have the mode in the list */
370 modes = display->display_modes;
371 nmodes = display->num_display_modes;
372 for (i = nmodes; i--;) {
373 if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) {
378 /* Go ahead and add the new mode */
379 if (nmodes == display->max_display_modes) {
382 (display->max_display_modes + 32) * sizeof(*modes));
386 display->display_modes = modes;
387 display->max_display_modes += 32;
389 modes[nmodes] = *mode;
390 display->num_display_modes++;
392 /* Re-sort video modes */
393 SDL_qsort(display->display_modes, display->num_display_modes,
394 sizeof(SDL_DisplayMode), cmpmodes);
400 SDL_GetNumDisplayModes()
403 SDL_VideoDisplay *display = &SDL_CurrentDisplay;
404 if (!display->num_display_modes && _this->GetDisplayModes) {
405 _this->GetDisplayModes(_this);
406 SDL_qsort(display->display_modes, display->num_display_modes,
407 sizeof(SDL_DisplayMode), cmpmodes);
409 return display->num_display_modes;
415 SDL_GetDisplayMode(int index, SDL_DisplayMode * mode)
417 if (index < 0 || index >= SDL_GetNumDisplayModes()) {
418 SDL_SetError("index must be in the range of 0 - %d",
419 SDL_GetNumDisplayModes() - 1);
423 *mode = SDL_CurrentDisplay.display_modes[index];
429 SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode)
432 SDL_UninitializedVideo();
436 *mode = SDL_CurrentDisplay.desktop_mode;
442 SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode)
445 SDL_UninitializedVideo();
449 *mode = SDL_CurrentDisplay.current_mode;
455 SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode,
456 SDL_DisplayMode * closest)
458 Uint32 target_format;
459 int target_refresh_rate;
461 SDL_DisplayMode *current, *match;
463 if (!_this || !mode || !closest) {
466 /* Default to the desktop format */
468 target_format = mode->format;
470 target_format = SDL_CurrentDisplay.desktop_mode.format;
473 /* Default to the desktop refresh rate */
474 if (mode->refresh_rate) {
475 target_refresh_rate = mode->refresh_rate;
477 target_refresh_rate = SDL_CurrentDisplay.desktop_mode.refresh_rate;
481 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
482 current = &SDL_CurrentDisplay.display_modes[i];
484 if (current->w && (current->w < mode->w)) {
485 /* Out of sorted modes large enough here */
488 if (current->h && (current->h < mode->h)) {
489 if (current->w && (current->w == mode->w)) {
490 /* Out of sorted modes large enough here */
493 /* Wider, but not tall enough, due to a different
494 aspect ratio. This mode must be skipped, but closer
495 modes may still follow. */
498 if (!match || current->w < match->w || current->h < match->h) {
502 if (current->format != match->format) {
503 /* Sorted highest depth to lowest */
504 if (current->format == target_format ||
505 (SDL_BITSPERPIXEL(current->format) >=
506 SDL_BITSPERPIXEL(target_format)
507 && SDL_PIXELTYPE(current->format) ==
508 SDL_PIXELTYPE(target_format))) {
513 if (current->refresh_rate != match->refresh_rate) {
514 /* Sorted highest refresh to lowest */
515 if (current->refresh_rate >= target_refresh_rate) {
522 closest->format = match->format;
524 closest->format = mode->format;
526 if (match->w && match->h) {
527 closest->w = match->w;
528 closest->h = match->h;
530 closest->w = mode->w;
531 closest->h = mode->h;
533 if (match->refresh_rate) {
534 closest->refresh_rate = match->refresh_rate;
536 closest->refresh_rate = mode->refresh_rate;
538 closest->driverdata = match->driverdata;
541 * Pick some reasonable defaults if the app and driver don't
544 if (!closest->format) {
545 closest->format = SDL_PIXELFORMAT_RGB888;
559 SDL_SetDisplayMode(const SDL_DisplayMode * mode)
561 SDL_VideoDisplay *display;
562 SDL_DisplayMode display_mode;
563 SDL_DisplayMode current_mode;
567 SDL_UninitializedVideo();
570 display = &SDL_CurrentDisplay;
572 mode = &display->desktop_mode;
574 display_mode = *mode;
576 /* Default to the current mode */
577 if (!display_mode.format) {
578 display_mode.format = display->current_mode.format;
580 if (!display_mode.w) {
581 display_mode.w = display->current_mode.w;
583 if (!display_mode.h) {
584 display_mode.h = display->current_mode.h;
586 if (!display_mode.refresh_rate) {
587 display_mode.refresh_rate = display->current_mode.refresh_rate;
589 /* Get a good video mode, the closest one possible */
590 if (!SDL_GetClosestDisplayMode(&display_mode, &display_mode)) {
591 SDL_SetError("No video mode large enough for %dx%d",
592 display_mode.w, display_mode.h);
595 /* See if there's anything left to do */
596 SDL_GetCurrentDisplayMode(¤t_mode);
597 if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) {
600 /* Actually change the display mode */
601 if (_this->SetDisplayMode(_this, &display_mode) < 0) {
604 display->current_mode = display_mode;
606 /* Set up a palette, if necessary */
607 if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) {
608 ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format));
612 if ((!ncolors && display->palette) || (ncolors && !display->palette)
613 || (ncolors && ncolors != display->palette->ncolors)) {
614 if (display->palette) {
615 SDL_FreePalette(display->palette);
616 display->palette = NULL;
619 display->palette = SDL_AllocPalette(ncolors);
620 if (!display->palette) {
623 SDL_DitherColors(display->palette->colors,
624 SDL_BITSPERPIXEL(display_mode.format));
627 /* Move any fullscreen windows into position */
628 for (i = 0; i < display->num_windows; ++i) {
629 SDL_Window *window = &display->windows[i];
630 if (FULLSCREEN_VISIBLE(window)) {
631 SDL_SetWindowPosition(window->id, window->x, window->y);
639 SDL_SetFullscreenDisplayMode(const SDL_DisplayMode * mode)
641 SDL_VideoDisplay *display;
642 SDL_DisplayMode fullscreen_mode;
646 SDL_UninitializedVideo();
649 display = &SDL_CurrentDisplay;
651 mode = &display->desktop_mode;
653 if (!SDL_GetClosestDisplayMode(mode, &fullscreen_mode)) {
654 SDL_SetError("Couldn't find display mode match");
659 (&fullscreen_mode, &display->fullscreen_mode,
660 sizeof(fullscreen_mode)) == 0) {
661 /* Nothing to do... */
664 display->fullscreen_mode = fullscreen_mode;
666 /* Actually set the mode if we have a fullscreen window visible */
667 for (i = 0; i < display->num_windows; ++i) {
668 SDL_Window *window = &display->windows[i];
669 if (FULLSCREEN_VISIBLE(window)) {
670 if (SDL_SetDisplayMode(&display->fullscreen_mode) < 0) {
674 if (window->flags & SDL_WINDOW_FULLSCREEN) {
675 SDL_OnWindowResized(window);
682 SDL_GetFullscreenDisplayMode(SDL_DisplayMode * mode)
685 SDL_UninitializedVideo();
689 *mode = SDL_CurrentDisplay.fullscreen_mode;
695 SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors)
697 SDL_Palette *palette;
701 SDL_UninitializedVideo();
704 palette = SDL_CurrentDisplay.palette;
706 SDL_SetError("Display mode does not have a palette");
709 status = SDL_SetPaletteColors(palette, colors, firstcolor, ncolors);
711 if (_this->SetDisplayPalette) {
712 if (_this->SetDisplayPalette(_this, palette) < 0) {
720 SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors)
722 SDL_Palette *palette;
725 SDL_UninitializedVideo();
728 palette = SDL_CurrentDisplay.palette;
729 if (!palette->ncolors) {
730 SDL_SetError("Display mode does not have a palette");
733 if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) {
734 SDL_SetError("Palette indices are out of range");
737 SDL_memcpy(colors, &palette->colors[firstcolor],
738 ncolors * sizeof(*colors));
743 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
745 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN |
747 SDL_WINDOW_BORDERLESS |
748 SDL_WINDOW_RESIZABLE |
749 SDL_WINDOW_INPUT_GRABBED);
750 SDL_VideoDisplay *display;
756 /* Initialize the video system if needed */
757 if (SDL_VideoInit(NULL, 0) < 0) {
761 if (flags & SDL_WINDOW_OPENGL) {
762 if (!_this->GL_CreateContext) {
763 SDL_SetError("No OpenGL support in video driver");
766 SDL_GL_LoadLibrary(NULL);
769 window.id = _this->next_object_id++;
774 window.flags = (flags & allowed_flags);
775 window.display = _this->current_display;
777 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
778 if (flags & SDL_WINDOW_OPENGL) {
779 SDL_GL_UnloadLibrary();
783 display = &SDL_CurrentDisplay;
784 num_windows = display->num_windows;
786 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows));
788 if (_this->DestroyWindow) {
789 _this->DestroyWindow(_this, &window);
791 if (flags & SDL_WINDOW_OPENGL) {
792 SDL_GL_UnloadLibrary();
796 windows[num_windows] = window;
797 display->windows = windows;
798 display->num_windows++;
801 SDL_SetWindowTitle(window.id, title);
803 if (flags & SDL_WINDOW_MAXIMIZED) {
804 SDL_MaximizeWindow(window.id);
806 if (flags & SDL_WINDOW_MINIMIZED) {
807 SDL_MinimizeWindow(window.id);
809 if (flags & SDL_WINDOW_SHOWN) {
810 SDL_ShowWindow(window.id);
812 SDL_UpdateWindowGrab(&window);
818 SDL_CreateWindowFrom(const void *data)
820 SDL_VideoDisplay *display;
826 SDL_UninitializedVideo();
830 window.id = _this->next_object_id++;
831 window.display = _this->current_display;
832 window.flags = SDL_WINDOW_FOREIGN;
834 if (!_this->CreateWindowFrom ||
835 _this->CreateWindowFrom(_this, &window, data) < 0) {
838 display = &SDL_CurrentDisplay;
839 num_windows = display->num_windows;
841 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows));
843 if (_this->DestroyWindow) {
844 _this->DestroyWindow(_this, &window);
847 SDL_free(window.title);
851 windows[num_windows] = window;
852 display->windows = windows;
853 display->num_windows++;
859 SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
861 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN |
863 SDL_WINDOW_BORDERLESS |
864 SDL_WINDOW_RESIZABLE |
865 SDL_WINDOW_INPUT_GRABBED |
867 char *title = window->title;
869 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
870 SDL_SetError("No OpenGL support in video driver");
873 if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
874 if (flags & SDL_WINDOW_OPENGL) {
875 SDL_GL_LoadLibrary(NULL);
877 SDL_GL_UnloadLibrary();
881 if (window->flags & SDL_WINDOW_FOREIGN) {
882 /* Can't destroy and re-create foreign windows, hrm */
883 flags |= SDL_WINDOW_FOREIGN;
885 flags &= ~SDL_WINDOW_FOREIGN;
888 if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
889 _this->DestroyWindow(_this, window);
892 window->title = NULL;
893 window->flags = (flags & allowed_flags);
895 if (_this->CreateWindow && !(flags & SDL_WINDOW_FOREIGN)) {
896 if (_this->CreateWindow(_this, window) < 0) {
897 if (flags & SDL_WINDOW_OPENGL) {
898 SDL_GL_UnloadLibrary();
905 SDL_SetWindowTitle(window->id, title);
908 if (flags & SDL_WINDOW_MAXIMIZED) {
909 SDL_MaximizeWindow(window->id);
911 if (flags & SDL_WINDOW_MINIMIZED) {
912 SDL_MinimizeWindow(window->id);
914 if (flags & SDL_WINDOW_SHOWN) {
915 SDL_ShowWindow(window->id);
917 SDL_UpdateWindowGrab(window);
923 SDL_GetWindowFromID(SDL_WindowID windowID)
928 SDL_UninitializedVideo();
932 for (i = 0; i < _this->num_displays; ++i) {
933 SDL_VideoDisplay *display = &_this->displays[i];
934 for (j = 0; j < display->num_windows; ++j) {
935 SDL_Window *window = &display->windows[j];
936 if (window->id == windowID) {
942 /* Just return the first active window */
943 for (i = 0; i < _this->num_displays; ++i) {
944 SDL_VideoDisplay *display = &_this->displays[i];
945 for (j = 0; j < display->num_windows; ++j) {
946 SDL_Window *window = &display->windows[j];
951 /* Couldn't find the window with the requested ID */
952 SDL_SetError("Invalid window ID");
957 SDL_GetDisplayFromWindow(SDL_Window * window)
960 SDL_UninitializedVideo();
966 return &_this->displays[window->display];
969 static __inline__ SDL_Renderer *
970 SDL_GetCurrentRenderer(SDL_bool create)
973 SDL_UninitializedVideo();
976 if (!SDL_CurrentRenderer) {
978 SDL_SetError("Use SDL_CreateRenderer() to create a renderer");
981 if (SDL_CreateRenderer(0, -1, 0) < 0) {
985 return SDL_CurrentRenderer;
989 SDL_GetWindowFlags(SDL_WindowID windowID)
991 SDL_Window *window = SDL_GetWindowFromID(windowID);
996 return window->flags;
1000 SDL_SetWindowTitle(SDL_WindowID windowID, const char *title)
1002 SDL_Window *window = SDL_GetWindowFromID(windowID);
1004 if (!window || title == window->title) {
1007 if (window->title) {
1008 SDL_free(window->title);
1011 window->title = SDL_strdup(title);
1013 window->title = NULL;
1016 if (_this->SetWindowTitle) {
1017 _this->SetWindowTitle(_this, window);
1022 SDL_GetWindowTitle(SDL_WindowID windowID)
1024 SDL_Window *window = SDL_GetWindowFromID(windowID);
1029 return window->title;
1033 SDL_SetWindowIcon(SDL_WindowID windowID, SDL_Surface * icon)
1035 SDL_Window *window = SDL_GetWindowFromID(windowID);
1040 if (_this->SetWindowIcon) {
1041 _this->SetWindowIcon(_this, window, icon);
1046 SDL_SetWindowData(SDL_WindowID windowID, void *userdata)
1048 SDL_Window *window = SDL_GetWindowFromID(windowID);
1053 window->userdata = userdata;
1057 SDL_GetWindowData(SDL_WindowID windowID)
1059 SDL_Window *window = SDL_GetWindowFromID(windowID);
1064 return window->userdata;
1068 SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y)
1070 SDL_Window *window = SDL_GetWindowFromID(windowID);
1071 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1076 if (x != SDL_WINDOWPOS_UNDEFINED) {
1079 if (y != SDL_WINDOWPOS_UNDEFINED) {
1082 if (_this->SetWindowPosition) {
1083 _this->SetWindowPosition(_this, window);
1085 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, x, y);
1089 SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y)
1091 SDL_Window *window = SDL_GetWindowFromID(windowID);
1105 SDL_SetWindowSize(SDL_WindowID windowID, int w, int h)
1107 SDL_Window *window = SDL_GetWindowFromID(windowID);
1115 if (_this->SetWindowSize) {
1116 _this->SetWindowSize(_this, window);
1118 SDL_OnWindowResized(window);
1122 SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h)
1124 SDL_Window *window = SDL_GetWindowFromID(windowID);
1144 SDL_ShowWindow(SDL_WindowID windowID)
1146 SDL_Window *window = SDL_GetWindowFromID(windowID);
1148 if (!window || (window->flags & SDL_WINDOW_SHOWN)) {
1152 if (_this->ShowWindow) {
1153 _this->ShowWindow(_this, window);
1155 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
1159 SDL_HideWindow(SDL_WindowID windowID)
1161 SDL_Window *window = SDL_GetWindowFromID(windowID);
1163 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
1167 if (_this->HideWindow) {
1168 _this->HideWindow(_this, window);
1170 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
1174 SDL_RaiseWindow(SDL_WindowID windowID)
1176 SDL_Window *window = SDL_GetWindowFromID(windowID);
1178 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
1181 if (_this->RaiseWindow) {
1182 _this->RaiseWindow(_this, window);
1187 SDL_MaximizeWindow(SDL_WindowID windowID)
1189 SDL_Window *window = SDL_GetWindowFromID(windowID);
1191 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) {
1195 if (_this->MaximizeWindow) {
1196 _this->MaximizeWindow(_this, window);
1198 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
1202 SDL_MinimizeWindow(SDL_WindowID windowID)
1204 SDL_Window *window = SDL_GetWindowFromID(windowID);
1206 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) {
1210 if (_this->MinimizeWindow) {
1211 _this->MinimizeWindow(_this, window);
1213 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
1217 SDL_RestoreWindow(SDL_WindowID windowID)
1219 SDL_Window *window = SDL_GetWindowFromID(windowID);
1222 || !(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
1226 if (_this->RestoreWindow) {
1227 _this->RestoreWindow(_this, window);
1229 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
1233 SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen)
1235 SDL_Window *window = SDL_GetWindowFromID(windowID);
1241 fullscreen = SDL_WINDOW_FULLSCREEN;
1243 if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) {
1247 window->flags |= SDL_WINDOW_FULLSCREEN;
1249 if (FULLSCREEN_VISIBLE(window)) {
1250 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1252 /* Hide any other fullscreen windows */
1254 for (i = 0; i < display->num_windows; ++i) {
1255 SDL_Window *other = &display->windows[i];
1256 if (other->id != windowID && FULLSCREEN_VISIBLE(other)) {
1257 SDL_MinimizeWindow(other->id);
1261 SDL_SetDisplayMode(&display->fullscreen_mode);
1264 window->flags &= ~SDL_WINDOW_FULLSCREEN;
1266 if (FULLSCREEN_VISIBLE(window)) {
1267 SDL_SetDisplayMode(NULL);
1274 SDL_SetWindowGrab(SDL_WindowID windowID, int mode)
1276 SDL_Window *window = SDL_GetWindowFromID(windowID);
1278 if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
1282 window->flags |= SDL_WINDOW_INPUT_GRABBED;
1284 window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
1286 SDL_UpdateWindowGrab(window);
1290 SDL_UpdateWindowGrab(SDL_Window * window)
1292 if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) {
1293 _this->SetWindowGrab(_this, window);
1298 SDL_GetWindowGrab(SDL_WindowID windowID)
1300 SDL_Window *window = SDL_GetWindowFromID(windowID);
1305 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0);
1309 SDL_OnWindowShown(SDL_Window * window)
1311 if (window->flags & SDL_WINDOW_FULLSCREEN) {
1312 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
1317 SDL_OnWindowHidden(SDL_Window * window)
1319 if (window->flags & SDL_WINDOW_FULLSCREEN) {
1320 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
1325 SDL_OnWindowResized(SDL_Window * window)
1327 SDL_Renderer *renderer = window->renderer;
1329 if (renderer && renderer->DisplayModeChanged) {
1330 renderer->DisplayModeChanged(renderer);
1335 SDL_OnWindowFocusGained(SDL_Window * window)
1337 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1339 if (window->flags & SDL_WINDOW_FULLSCREEN) {
1340 SDL_SetDisplayMode(&display->fullscreen_mode);
1342 if (display->gamma && _this->SetDisplayGammaRamp) {
1343 _this->SetDisplayGammaRamp(_this, display->gamma);
1345 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
1346 && _this->SetWindowGrab) {
1347 _this->SetWindowGrab(_this, window);
1352 SDL_OnWindowFocusLost(SDL_Window * window)
1354 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1356 if (window->flags & SDL_WINDOW_FULLSCREEN) {
1357 SDL_MinimizeWindow(window->id);
1358 SDL_SetDisplayMode(NULL);
1360 if (display->gamma && _this->SetDisplayGammaRamp) {
1361 _this->SetDisplayGammaRamp(_this, display->saved_gamma);
1363 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
1364 && _this->SetWindowGrab) {
1365 _this->SetWindowGrab(_this, window);
1370 SDL_GetFocusWindow(void)
1372 SDL_VideoDisplay *display;
1378 display = &SDL_CurrentDisplay;
1379 for (i = 0; i < display->num_windows; ++i) {
1380 SDL_Window *window = &display->windows[i];
1382 if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
1390 SDL_DestroyWindow(SDL_WindowID windowID)
1397 /* Restore video mode, etc. */
1398 SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
1400 for (i = 0; i < _this->num_displays; ++i) {
1401 SDL_VideoDisplay *display = &_this->displays[i];
1402 for (j = 0; j < display->num_windows; ++j) {
1403 SDL_Window *window = &display->windows[j];
1404 if (window->id != windowID) {
1407 if (window->title) {
1408 SDL_free(window->title);
1409 window->title = NULL;
1411 if (window->renderer) {
1412 SDL_DestroyRenderer(window->id);
1413 window->renderer = NULL;
1415 if (_this->DestroyWindow) {
1416 _this->DestroyWindow(_this, window);
1418 if (window->flags & SDL_WINDOW_OPENGL) {
1419 SDL_GL_UnloadLibrary();
1421 if (j != display->num_windows - 1) {
1422 SDL_memcpy(&display->windows[i],
1423 &display->windows[i + 1],
1424 (display->num_windows - i - 1) * sizeof(*window));
1426 --display->num_windows;
1433 SDL_AddRenderDriver(int displayIndex, const SDL_RenderDriver * driver)
1435 SDL_VideoDisplay *display;
1436 SDL_RenderDriver *render_drivers;
1438 if (displayIndex >= _this->num_displays) {
1441 display = &_this->displays[displayIndex];
1444 SDL_realloc(display->render_drivers,
1445 (display->num_render_drivers +
1446 1) * sizeof(*render_drivers));
1447 if (render_drivers) {
1448 render_drivers[display->num_render_drivers] = *driver;
1449 display->render_drivers = render_drivers;
1450 display->num_render_drivers++;
1455 SDL_GetNumRenderDrivers(void)
1458 return SDL_CurrentDisplay.num_render_drivers;
1464 SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info)
1467 SDL_UninitializedVideo();
1470 if (index < 0 || index >= SDL_GetNumRenderDrivers()) {
1471 SDL_SetError("index must be in the range of 0 - %d",
1472 SDL_GetNumRenderDrivers() - 1);
1475 *info = SDL_CurrentDisplay.render_drivers[index].info;
1480 SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags)
1482 SDL_Window *window = SDL_GetWindowFromID(windowID);
1485 SDL_SetError("Invalid window ID");
1489 /* Free any existing renderer */
1490 SDL_DestroyRenderer(windowID);
1493 char *override = SDL_getenv("SDL_VIDEO_RENDERER");
1494 int n = SDL_GetNumRenderDrivers();
1496 #if SDL_VIDEO_RENDER_OGL
1497 if (!override && (window->flags & SDL_WINDOW_OPENGL)) {
1498 override = "opengl";
1500 #endif /* SDL_VIDEO_RENDER_OGL */
1501 #if SDL_VIDEO_RENDER_OGL_ES
1502 if (!override && (window->flags & SDL_WINDOW_OPENGL)) {
1503 override = "opengl_es";
1505 #endif /* SDL_VIDEO_RENDER_OGL_ES */
1507 for (index = 0; index < n; ++index) {
1508 SDL_RenderDriver *driver =
1509 &SDL_CurrentDisplay.render_drivers[index];
1511 if (SDL_strcasecmp(override, driver->info.name) == 0) {
1512 /* Create a new renderer instance */
1513 window->renderer = driver->CreateRenderer(window, flags);
1518 for (index = 0; index < n; ++index) {
1519 SDL_RenderDriver *driver =
1520 &SDL_CurrentDisplay.render_drivers[index];
1522 if ((driver->info.flags & flags) == flags) {
1523 /* Create a new renderer instance */
1524 window->renderer = driver->CreateRenderer(window, flags);
1525 if (window->renderer) {
1526 /* Yay, we got one! */
1533 SDL_SetError("Couldn't find matching render driver");
1537 if (index >= SDL_GetNumRenderDrivers()) {
1538 SDL_SetError("index must be -1 or in the range of 0 - %d",
1539 SDL_GetNumRenderDrivers() - 1);
1542 /* Create a new renderer instance */
1543 window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags);
1546 if (window->renderer == NULL) {
1547 /* Assuming renderer set its error */
1551 SDL_SelectRenderer(window->id);
1557 SDL_SelectRenderer(SDL_WindowID windowID)
1559 SDL_Window *window = SDL_GetWindowFromID(windowID);
1560 SDL_Renderer *renderer;
1563 SDL_SetError("Invalid window ID");
1566 renderer = window->renderer;
1568 SDL_SetError("Use SDL_CreateRenderer() to create a renderer");
1571 if (renderer->ActivateRenderer) {
1572 if (renderer->ActivateRenderer(renderer) < 0) {
1576 SDL_CurrentDisplay.current_renderer = renderer;
1581 SDL_GetRendererInfo(SDL_RendererInfo * info)
1583 SDL_Renderer *renderer = SDL_GetCurrentRenderer(SDL_FALSE);
1587 *info = renderer->info;
1592 SDL_CreateTexture(Uint32 format, int access, int w, int h)
1595 SDL_Renderer *renderer;
1596 SDL_Texture *texture;
1598 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
1602 if (!renderer->CreateTexture) {
1606 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
1611 texture->id = _this->next_object_id++;
1612 texture->format = format;
1613 texture->access = access;
1620 texture->renderer = renderer;
1622 if (renderer->CreateTexture(renderer, texture) < 0) {
1623 if (renderer->DestroyTexture) {
1624 renderer->DestroyTexture(renderer, texture);
1629 hash = (texture->id % SDL_arraysize(SDL_CurrentDisplay.textures));
1630 texture->next = SDL_CurrentDisplay.textures[hash];
1631 SDL_CurrentDisplay.textures[hash] = texture;
1637 SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
1639 SDL_TextureID textureID;
1640 Uint32 requested_format = format;
1641 SDL_PixelFormat *fmt;
1642 SDL_Renderer *renderer;
1644 Uint32 Rmask, Gmask, Bmask, Amask;
1647 SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
1650 fmt = surface->format;
1652 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
1658 if (!SDL_PixelFormatEnumToMasks
1659 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
1660 SDL_SetError("Unknown pixel format");
1664 if (surface->format->Amask
1665 || !(surface->map->info.flags &
1666 (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) {
1670 /* Pixel formats, sorted by best first */
1671 static const Uint32 sdl_pformats[] = {
1672 SDL_PIXELFORMAT_ARGB8888,
1673 SDL_PIXELFORMAT_RGBA8888,
1674 SDL_PIXELFORMAT_ABGR8888,
1675 SDL_PIXELFORMAT_BGRA8888,
1676 SDL_PIXELFORMAT_RGB888,
1677 SDL_PIXELFORMAT_BGR888,
1678 SDL_PIXELFORMAT_RGB24,
1679 SDL_PIXELFORMAT_BGR24,
1680 SDL_PIXELFORMAT_RGB565,
1681 SDL_PIXELFORMAT_BGR565,
1682 SDL_PIXELFORMAT_ARGB1555,
1683 SDL_PIXELFORMAT_ABGR1555,
1684 SDL_PIXELFORMAT_RGB555,
1685 SDL_PIXELFORMAT_BGR555,
1686 SDL_PIXELFORMAT_ARGB4444,
1687 SDL_PIXELFORMAT_ABGR4444,
1688 SDL_PIXELFORMAT_RGB444,
1689 SDL_PIXELFORMAT_ARGB2101010,
1690 SDL_PIXELFORMAT_INDEX8,
1691 SDL_PIXELFORMAT_INDEX4LSB,
1692 SDL_PIXELFORMAT_INDEX4MSB,
1693 SDL_PIXELFORMAT_RGB332,
1694 SDL_PIXELFORMAT_INDEX1LSB,
1695 SDL_PIXELFORMAT_INDEX1MSB,
1696 SDL_PIXELFORMAT_UNKNOWN
1699 bpp = fmt->BitsPerPixel;
1706 SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
1708 SDL_SetError("Unknown pixel format");
1712 /* Search requested format in the supported texture */
1713 /* formats by current renderer */
1714 for (it = 0; it < renderer->info.num_texture_formats; it++) {
1715 if (renderer->info.texture_formats[it] == format) {
1720 /* If requested format can't be found, search any best */
1721 /* format which renderer provides */
1722 if (it == renderer->info.num_texture_formats) {
1725 if (sdl_pformats[pfmt] == SDL_PIXELFORMAT_UNKNOWN) {
1729 for (it = 0; it < renderer->info.num_texture_formats;
1731 if (renderer->info.texture_formats[it] ==
1732 sdl_pformats[pfmt]) {
1737 if (it != renderer->info.num_texture_formats) {
1738 /* The best format has been found */
1744 /* If any format can't be found, then return an error */
1745 if (it == renderer->info.num_texture_formats) {
1747 ("Any of the supported pixel formats can't be found");
1751 /* Convert found pixel format back to color masks */
1752 if (SDL_PixelFormatEnumToMasks
1753 (renderer->info.texture_formats[it], &bpp, &Rmask, &Gmask,
1754 &Bmask, &Amask) != SDL_TRUE) {
1755 SDL_SetError("Unknown pixel format");
1760 /* Need a format with alpha */
1764 /* Pixel formats with alpha, sorted by best first */
1765 static const Uint32 sdl_alpha_pformats[] = {
1766 SDL_PIXELFORMAT_ARGB8888,
1767 SDL_PIXELFORMAT_RGBA8888,
1768 SDL_PIXELFORMAT_ABGR8888,
1769 SDL_PIXELFORMAT_BGRA8888,
1770 SDL_PIXELFORMAT_ARGB1555,
1771 SDL_PIXELFORMAT_ABGR1555,
1772 SDL_PIXELFORMAT_ARGB4444,
1773 SDL_PIXELFORMAT_ABGR4444,
1774 SDL_PIXELFORMAT_ARGB2101010,
1775 SDL_PIXELFORMAT_UNKNOWN
1778 if (surface->format->Amask) {
1779 /* If surface already has alpha, then try an original */
1780 /* surface format first */
1781 bpp = fmt->BitsPerPixel;
1795 SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
1797 SDL_SetError("Unknown pixel format");
1801 /* Search this format in the supported texture formats */
1802 /* by current renderer */
1803 for (it = 0; it < renderer->info.num_texture_formats; it++) {
1804 if (renderer->info.texture_formats[it] == format) {
1809 /* If this format can't be found, search any best */
1810 /* compatible format with alpha which renderer provides */
1811 if (it == renderer->info.num_texture_formats) {
1814 if (sdl_alpha_pformats[apfmt] == SDL_PIXELFORMAT_UNKNOWN) {
1818 for (it = 0; it < renderer->info.num_texture_formats;
1820 if (renderer->info.texture_formats[it] ==
1821 sdl_alpha_pformats[apfmt]) {
1826 if (it != renderer->info.num_texture_formats) {
1827 /* Compatible format has been found */
1833 /* If compatible format can't be found, then return an error */
1834 if (it == renderer->info.num_texture_formats) {
1835 SDL_SetError("Compatible pixel format can't be found");
1839 /* Convert found pixel format back to color masks */
1840 if (SDL_PixelFormatEnumToMasks
1841 (renderer->info.texture_formats[it], &bpp, &Rmask, &Gmask,
1842 &Bmask, &Amask) != SDL_TRUE) {
1843 SDL_SetError("Unknown pixel format");
1849 format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
1851 SDL_SetError("Unknown pixel format");
1857 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w,
1859 if (!textureID && !requested_format) {
1860 SDL_DisplayMode desktop_mode;
1861 SDL_GetDesktopDisplayMode(&desktop_mode);
1862 format = desktop_mode.format;
1864 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w,
1870 if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask
1871 && Bmask == fmt->Bmask && Amask == fmt->Amask) {
1872 if (SDL_MUSTLOCK(surface)) {
1873 SDL_LockSurface(surface);
1874 SDL_UpdateTexture(textureID, NULL, surface->pixels,
1876 SDL_UnlockSurface(surface);
1878 SDL_UpdateTexture(textureID, NULL, surface->pixels,
1882 SDL_PixelFormat dst_fmt;
1883 SDL_Surface *dst = NULL;
1885 /* Set up a destination surface for the texture update */
1886 SDL_InitFormat(&dst_fmt, bpp, Rmask, Gmask, Bmask, Amask);
1887 if (SDL_ISPIXELFORMAT_INDEXED(format)) {
1889 SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format)));
1890 if (dst_fmt.palette) {
1892 * FIXME: Should we try to copy
1895 SDL_DitherColors(dst_fmt.palette->colors,
1896 SDL_BITSPERPIXEL(format));
1899 dst = SDL_ConvertSurface(surface, &dst_fmt, 0);
1901 SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch);
1902 SDL_FreeSurface(dst);
1904 if (dst_fmt.palette) {
1905 SDL_FreePalette(dst_fmt.palette);
1908 SDL_DestroyTexture(textureID);
1918 SDL_GetSurfaceColorMod(surface, &r, &g, &b);
1919 SDL_SetTextureColorMod(textureID, r, g, b);
1921 SDL_GetSurfaceAlphaMod(surface, &a);
1922 SDL_SetTextureAlphaMod(textureID, a);
1924 SDL_GetSurfaceBlendMode(surface, &blendMode);
1925 SDL_SetTextureBlendMode(textureID, blendMode);
1927 SDL_GetSurfaceScaleMode(surface, &scaleMode);
1928 SDL_SetTextureScaleMode(textureID, scaleMode);
1931 if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) {
1932 SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
1933 fmt->palette->ncolors);
1938 static __inline__ SDL_Texture *
1939 SDL_GetTextureFromID(SDL_TextureID textureID)
1942 SDL_Texture *texture;
1947 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
1948 for (texture = SDL_CurrentDisplay.textures[hash]; texture;
1949 texture = texture->next) {
1950 if (texture->id == textureID) {
1958 SDL_QueryTexture(SDL_TextureID textureID, Uint32 * format, int *access,
1961 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1967 *format = texture->format;
1970 *access = texture->access;
1982 SDL_QueryTexturePixels(SDL_TextureID textureID, void **pixels, int *pitch)
1984 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1985 SDL_Renderer *renderer;
1990 renderer = texture->renderer;
1991 if (!renderer->QueryTexturePixels) {
1995 return renderer->QueryTexturePixels(renderer, texture, pixels, pitch);
1999 SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors,
2000 int firstcolor, int ncolors)
2002 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2003 SDL_Renderer *renderer;
2008 renderer = texture->renderer;
2009 if (!renderer->SetTexturePalette) {
2013 return renderer->SetTexturePalette(renderer, texture, colors, firstcolor,
2018 SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors,
2019 int firstcolor, int ncolors)
2021 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2022 SDL_Renderer *renderer;
2027 renderer = texture->renderer;
2028 if (!renderer->GetTexturePalette) {
2032 return renderer->GetTexturePalette(renderer, texture, colors, firstcolor,
2037 SDL_SetTextureColorMod(SDL_TextureID textureID, Uint8 r, Uint8 g, Uint8 b)
2039 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2040 SDL_Renderer *renderer;
2045 renderer = texture->renderer;
2046 if (!renderer->SetTextureColorMod) {
2050 if (r < 255 || g < 255 || b < 255) {
2051 texture->modMode |= SDL_TEXTUREMODULATE_COLOR;
2053 texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
2058 return renderer->SetTextureColorMod(renderer, texture);
2062 SDL_GetTextureColorMod(SDL_TextureID textureID, Uint8 * r, Uint8 * g,
2065 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2066 SDL_Renderer *renderer;
2071 renderer = texture->renderer;
2085 SDL_SetTextureAlphaMod(SDL_TextureID textureID, Uint8 alpha)
2087 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2088 SDL_Renderer *renderer;
2093 renderer = texture->renderer;
2094 if (!renderer->SetTextureAlphaMod) {
2099 texture->modMode |= SDL_TEXTUREMODULATE_ALPHA;
2101 texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
2104 return renderer->SetTextureAlphaMod(renderer, texture);
2108 SDL_GetTextureAlphaMod(SDL_TextureID textureID, Uint8 * alpha)
2110 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2116 *alpha = texture->a;
2122 SDL_SetTextureBlendMode(SDL_TextureID textureID, int blendMode)
2124 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2125 SDL_Renderer *renderer;
2130 renderer = texture->renderer;
2131 if (!renderer->SetTextureBlendMode) {
2135 texture->blendMode = blendMode;
2136 return renderer->SetTextureBlendMode(renderer, texture);
2140 SDL_GetTextureBlendMode(SDL_TextureID textureID, int *blendMode)
2142 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2148 *blendMode = texture->blendMode;
2154 SDL_SetTextureScaleMode(SDL_TextureID textureID, int scaleMode)
2156 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2157 SDL_Renderer *renderer;
2162 renderer = texture->renderer;
2163 if (!renderer->SetTextureScaleMode) {
2167 texture->scaleMode = scaleMode;
2168 return renderer->SetTextureScaleMode(renderer, texture);
2172 SDL_GetTextureScaleMode(SDL_TextureID textureID, int *scaleMode)
2174 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2180 *scaleMode = texture->scaleMode;
2186 SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect,
2187 const void *pixels, int pitch)
2189 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2190 SDL_Renderer *renderer;
2196 renderer = texture->renderer;
2197 if (!renderer->UpdateTexture) {
2204 full_rect.w = texture->w;
2205 full_rect.h = texture->h;
2208 return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
2212 SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty,
2213 void **pixels, int *pitch)
2215 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2216 SDL_Renderer *renderer;
2222 if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
2223 SDL_SetError("SDL_LockTexture(): texture must be streaming");
2226 renderer = texture->renderer;
2227 if (!renderer->LockTexture) {
2234 full_rect.w = texture->w;
2235 full_rect.h = texture->h;
2238 return renderer->LockTexture(renderer, texture, rect, markDirty, pixels,
2243 SDL_UnlockTexture(SDL_TextureID textureID)
2245 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2246 SDL_Renderer *renderer;
2251 if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
2254 renderer = texture->renderer;
2255 if (!renderer->UnlockTexture) {
2258 renderer->UnlockTexture(renderer, texture);
2262 SDL_DirtyTexture(SDL_TextureID textureID, int numrects,
2263 const SDL_Rect * rects)
2265 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2266 SDL_Renderer *renderer;
2271 if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
2274 renderer = texture->renderer;
2275 if (!renderer->DirtyTexture) {
2278 renderer->DirtyTexture(renderer, texture, numrects, rects);
2282 SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2284 SDL_Renderer *renderer;
2286 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2294 if (renderer->SetDrawColor) {
2295 return renderer->SetDrawColor(renderer);
2302 SDL_GetRenderDrawColor(Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
2304 SDL_Renderer *renderer;
2306 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2326 SDL_SetRenderDrawBlendMode(int blendMode)
2328 SDL_Renderer *renderer;
2330 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2334 renderer->blendMode = blendMode;
2335 if (renderer->SetDrawBlendMode) {
2336 return renderer->SetDrawBlendMode(renderer);
2343 SDL_GetRenderDrawBlendMode(int *blendMode)
2345 SDL_Renderer *renderer;
2347 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2351 *blendMode = renderer->blendMode;
2356 SDL_RenderPoint(int x, int y)
2358 SDL_Renderer *renderer;
2361 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2365 if (!renderer->RenderPoint) {
2369 window = SDL_GetWindowFromID(renderer->window);
2370 if (x < 0 || y < 0 || x >= window->w || y >= window->h) {
2373 return renderer->RenderPoint(renderer, x, y);
2377 SDL_RenderLine(int x1, int y1, int x2, int y2)
2379 SDL_Renderer *renderer;
2383 if (x1 == x2 && y1 == y2) {
2384 return SDL_RenderPoint(x1, y1);
2387 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2391 if (!renderer->RenderLine) {
2395 window = SDL_GetWindowFromID(renderer->window);
2399 real_rect.w = window->w;
2400 real_rect.h = window->h;
2401 if (!SDL_IntersectRectAndLine(&real_rect, &x1, &y1, &x2, &y2)) {
2404 return renderer->RenderLine(renderer, x1, y1, x2, y2);
2408 SDL_RenderFill(const SDL_Rect * rect)
2410 SDL_Renderer *renderer;
2414 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2418 if (!renderer->RenderFill) {
2422 window = SDL_GetWindowFromID(renderer->window);
2426 real_rect.w = window->w;
2427 real_rect.h = window->h;
2429 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
2433 return renderer->RenderFill(renderer, &real_rect);
2437 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
2438 const SDL_Rect * dstrect)
2440 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
2441 SDL_Renderer *renderer;
2443 SDL_Rect real_srcrect;
2444 SDL_Rect real_dstrect;
2446 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2451 SDL_SetError("Texture not found");
2454 if (texture->renderer != renderer) {
2455 SDL_SetError("Texture was not created with this renderer");
2458 if (!renderer->RenderCopy) {
2462 window = SDL_GetWindowFromID(renderer->window);
2466 real_srcrect.w = texture->w;
2467 real_srcrect.h = texture->h;
2469 if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
2476 real_dstrect.w = window->w;
2477 real_dstrect.h = window->h;
2479 if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) {
2482 /* Clip srcrect by the same amount as dstrect was clipped */
2483 if (dstrect->w != real_dstrect.w) {
2484 int deltax = (real_dstrect.x - dstrect->x);
2485 int deltaw = (real_dstrect.w - dstrect->w);
2486 real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
2487 real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;
2489 if (dstrect->h != real_dstrect.h) {
2490 int deltay = (real_dstrect.y - dstrect->y);
2491 int deltah = (real_dstrect.h - dstrect->h);
2492 real_srcrect.y += (deltay * real_srcrect.h) / dstrect->h;
2493 real_srcrect.h += (deltah * real_srcrect.h) / dstrect->h;
2497 return renderer->RenderCopy(renderer, texture, &real_srcrect,
2502 SDL_RenderReadPixels(const SDL_Rect * rect, Uint32 format,
2503 void * pixels, int pitch)
2505 SDL_Renderer *renderer;
2509 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2513 if (!renderer->RenderReadPixels) {
2517 window = SDL_GetWindowFromID(renderer->window);
2520 format = SDL_GetDisplayFromWindow(window)->current_mode.format;
2525 real_rect.w = window->w;
2526 real_rect.h = window->h;
2528 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
2531 if (real_rect.y > rect->y) {
2532 pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
2534 if (real_rect.x > rect->x) {
2535 Uint32 format = SDL_CurrentDisplay.current_mode.format;
2536 int bpp = SDL_BYTESPERPIXEL(format);
2537 pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
2541 return renderer->RenderReadPixels(renderer, &real_rect,
2542 format, pixels, pitch);
2546 SDL_RenderWritePixels(const SDL_Rect * rect, Uint32 format,
2547 const void * pixels, int pitch)
2549 SDL_Renderer *renderer;
2553 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2557 if (!renderer->RenderWritePixels) {
2561 window = SDL_GetWindowFromID(renderer->window);
2564 format = SDL_GetDisplayFromWindow(window)->current_mode.format;
2569 real_rect.w = window->w;
2570 real_rect.h = window->h;
2572 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
2575 if (real_rect.y > rect->y) {
2576 pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y);
2578 if (real_rect.x > rect->x) {
2579 Uint32 format = SDL_CurrentDisplay.current_mode.format;
2580 int bpp = SDL_BYTESPERPIXEL(format);
2581 pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x);
2585 return renderer->RenderWritePixels(renderer, &real_rect,
2586 format, pixels, pitch);
2590 SDL_RenderPresent(void)
2592 SDL_Renderer *renderer;
2594 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2595 if (!renderer || !renderer->RenderPresent) {
2598 renderer->RenderPresent(renderer);
2602 SDL_DestroyTexture(SDL_TextureID textureID)
2605 SDL_Texture *prev, *texture;
2606 SDL_Renderer *renderer;
2609 SDL_UninitializedVideo();
2612 /* Look up the texture in the hash table */
2613 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
2615 for (texture = SDL_CurrentDisplay.textures[hash]; texture;
2616 prev = texture, texture = texture->next) {
2617 if (texture->id == textureID) {
2624 /* Unlink the texture from the list */
2626 prev->next = texture->next;
2628 SDL_CurrentDisplay.textures[hash] = texture->next;
2631 /* Free the texture */
2632 renderer = texture->renderer;
2633 renderer->DestroyTexture(renderer, texture);
2638 SDL_DestroyRenderer(SDL_WindowID windowID)
2640 SDL_Window *window = SDL_GetWindowFromID(windowID);
2641 SDL_Renderer *renderer;
2647 renderer = window->renderer;
2651 /* Free existing textures for this renderer */
2652 for (i = 0; i < SDL_arraysize(SDL_CurrentDisplay.textures); ++i) {
2653 SDL_Texture *texture;
2654 SDL_Texture *prev = NULL;
2656 for (texture = SDL_CurrentDisplay.textures[i]; texture;
2658 next = texture->next;
2659 if (texture->renderer == renderer) {
2663 SDL_CurrentDisplay.textures[i] = next;
2665 renderer->DestroyTexture(renderer, texture);
2673 /* Free the renderer instance */
2674 renderer->DestroyRenderer(renderer);
2676 /* Clear references */
2677 window->renderer = NULL;
2678 if (SDL_CurrentDisplay.current_renderer == renderer) {
2679 SDL_CurrentDisplay.current_renderer = NULL;
2684 SDL_IsScreenSaverEnabled()
2689 return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE;
2693 SDL_EnableScreenSaver()
2698 if (!_this->suspend_screensaver) {
2701 _this->suspend_screensaver = SDL_FALSE;
2702 if (_this->SuspendScreenSaver) {
2703 _this->SuspendScreenSaver(_this);
2708 SDL_DisableScreenSaver()
2713 if (_this->suspend_screensaver) {
2716 _this->suspend_screensaver = SDL_TRUE;
2717 if (_this->SuspendScreenSaver) {
2718 _this->SuspendScreenSaver(_this);
2730 /* Halt event processing before doing anything else */
2731 SDL_StopEventLoop();
2732 SDL_EnableScreenSaver();
2734 /* Clean up the system video */
2735 for (i = _this->num_displays; i--;) {
2736 SDL_VideoDisplay *display = &_this->displays[i];
2737 for (j = display->num_windows; j--;) {
2738 SDL_DestroyWindow(display->windows[i].id);
2740 if (display->windows) {
2741 SDL_free(display->windows);
2742 display->windows = NULL;
2744 display->num_windows = 0;
2745 if (display->render_drivers) {
2746 SDL_free(display->render_drivers);
2747 display->render_drivers = NULL;
2749 display->num_render_drivers = 0;
2751 _this->VideoQuit(_this);
2753 for (i = _this->num_displays; i--;) {
2754 SDL_VideoDisplay *display = &_this->displays[i];
2755 for (j = display->num_display_modes; j--;) {
2756 if (display->display_modes[j].driverdata) {
2757 SDL_free(display->display_modes[j].driverdata);
2758 display->display_modes[j].driverdata = NULL;
2761 if (display->display_modes) {
2762 SDL_free(display->display_modes);
2763 display->display_modes = NULL;
2765 if (display->desktop_mode.driverdata) {
2766 SDL_free(display->desktop_mode.driverdata);
2767 display->desktop_mode.driverdata = NULL;
2769 if (display->palette) {
2770 SDL_FreePalette(display->palette);
2771 display->palette = NULL;
2773 if (display->gamma) {
2774 SDL_free(display->gamma);
2775 display->gamma = NULL;
2777 if (display->driverdata) {
2778 SDL_free(display->driverdata);
2779 display->driverdata = NULL;
2782 if (_this->displays) {
2783 SDL_free(_this->displays);
2784 _this->displays = NULL;
2791 SDL_GL_LoadLibrary(const char *path)
2796 SDL_UninitializedVideo();
2799 if (_this->gl_config.driver_loaded) {
2800 if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) {
2801 SDL_SetError("OpenGL library already loaded");
2806 if (!_this->GL_LoadLibrary) {
2807 SDL_SetError("No dynamic GL support in video driver");
2810 retval = _this->GL_LoadLibrary(_this, path);
2813 ++_this->gl_config.driver_loaded;
2819 SDL_GL_GetProcAddress(const char *proc)
2824 SDL_UninitializedVideo();
2828 if (_this->GL_GetProcAddress) {
2829 if (_this->gl_config.driver_loaded) {
2830 func = _this->GL_GetProcAddress(_this, proc);
2832 SDL_SetError("No GL driver has been loaded");
2835 SDL_SetError("No dynamic GL support in video driver");
2841 SDL_GL_UnloadLibrary(void)
2844 SDL_UninitializedVideo();
2847 if (_this->gl_config.driver_loaded > 0) {
2848 if (--_this->gl_config.driver_loaded > 0) {
2851 if (_this->GL_UnloadLibrary) {
2852 _this->GL_UnloadLibrary(_this);
2858 SDL_GL_ExtensionSupported(const char *extension)
2860 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
2861 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
2862 const char *extensions;
2864 const char *where, *terminator;
2866 /* Extension names should not have spaces. */
2867 where = SDL_strchr(extension, ' ');
2868 if (where || *extension == '\0') {
2871 /* See if there's an environment variable override */
2872 start = SDL_getenv(extension);
2873 if (start && *start == '0') {
2876 /* Lookup the available extensions */
2877 glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
2878 if (glGetStringFunc) {
2879 extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
2887 * It takes a bit of care to be fool-proof about parsing the OpenGL
2888 * extensions string. Don't be fooled by sub-strings, etc.
2894 where = SDL_strstr(start, extension);
2898 terminator = where + SDL_strlen(extension);
2899 if (where == start || *(where - 1) == ' ')
2900 if (*terminator == ' ' || *terminator == '\0')
2912 SDL_GL_SetAttribute(SDL_GLattr attr, int value)
2914 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
2918 SDL_UninitializedVideo();
2923 case SDL_GL_RED_SIZE:
2924 _this->gl_config.red_size = value;
2926 case SDL_GL_GREEN_SIZE:
2927 _this->gl_config.green_size = value;
2929 case SDL_GL_BLUE_SIZE:
2930 _this->gl_config.blue_size = value;
2932 case SDL_GL_ALPHA_SIZE:
2933 _this->gl_config.alpha_size = value;
2935 case SDL_GL_DOUBLEBUFFER:
2936 _this->gl_config.double_buffer = value;
2938 case SDL_GL_BUFFER_SIZE:
2939 _this->gl_config.buffer_size = value;
2941 case SDL_GL_DEPTH_SIZE:
2942 _this->gl_config.depth_size = value;
2944 case SDL_GL_STENCIL_SIZE:
2945 _this->gl_config.stencil_size = value;
2947 case SDL_GL_ACCUM_RED_SIZE:
2948 _this->gl_config.accum_red_size = value;
2950 case SDL_GL_ACCUM_GREEN_SIZE:
2951 _this->gl_config.accum_green_size = value;
2953 case SDL_GL_ACCUM_BLUE_SIZE:
2954 _this->gl_config.accum_blue_size = value;
2956 case SDL_GL_ACCUM_ALPHA_SIZE:
2957 _this->gl_config.accum_alpha_size = value;
2960 _this->gl_config.stereo = value;
2962 case SDL_GL_MULTISAMPLEBUFFERS:
2963 _this->gl_config.multisamplebuffers = value;
2965 case SDL_GL_MULTISAMPLESAMPLES:
2966 _this->gl_config.multisamplesamples = value;
2968 case SDL_GL_ACCELERATED_VISUAL:
2969 _this->gl_config.accelerated = value;
2971 case SDL_GL_RETAINED_BACKING:
2972 _this->gl_config.retained_backing = value;
2974 case SDL_GL_CONTEXT_MAJOR_VERSION:
2975 _this->gl_config.major_version = value;
2977 case SDL_GL_CONTEXT_MINOR_VERSION:
2978 _this->gl_config.minor_version = value;
2981 SDL_SetError("Unknown OpenGL attribute");
2989 #endif /* SDL_VIDEO_OPENGL */
2993 SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
2995 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
2996 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
2997 GLenum(APIENTRY * glGetErrorFunc) (void);
3001 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
3002 if (!glGetIntegervFunc) {
3006 glGetErrorFunc = SDL_GL_GetProcAddress("glGetError");
3007 if (!glGetErrorFunc) {
3011 /* Clear value in any case */
3015 case SDL_GL_RETAINED_BACKING:
3016 *value = _this->gl_config.retained_backing;
3018 case SDL_GL_RED_SIZE:
3019 attrib = GL_RED_BITS;
3021 case SDL_GL_BLUE_SIZE:
3022 attrib = GL_BLUE_BITS;
3024 case SDL_GL_GREEN_SIZE:
3025 attrib = GL_GREEN_BITS;
3027 case SDL_GL_ALPHA_SIZE:
3028 attrib = GL_ALPHA_BITS;
3030 case SDL_GL_DOUBLEBUFFER:
3031 #ifndef SDL_VIDEO_OPENGL_ES
3032 attrib = GL_DOUBLEBUFFER;
3035 /* OpenGL ES 1.0 and above specifications have EGL_SINGLE_BUFFER */
3036 /* parameter which switches double buffer to single buffer. OpenGL ES */
3037 /* SDL driver must set proper value after initialization */
3038 *value = _this->gl_config.double_buffer;
3041 case SDL_GL_DEPTH_SIZE:
3042 attrib = GL_DEPTH_BITS;
3044 case SDL_GL_STENCIL_SIZE:
3045 attrib = GL_STENCIL_BITS;
3047 #ifndef SDL_VIDEO_OPENGL_ES
3048 case SDL_GL_ACCUM_RED_SIZE:
3049 attrib = GL_ACCUM_RED_BITS;
3051 case SDL_GL_ACCUM_GREEN_SIZE:
3052 attrib = GL_ACCUM_GREEN_BITS;
3054 case SDL_GL_ACCUM_BLUE_SIZE:
3055 attrib = GL_ACCUM_BLUE_BITS;
3057 case SDL_GL_ACCUM_ALPHA_SIZE:
3058 attrib = GL_ACCUM_ALPHA_BITS;
3064 case SDL_GL_ACCUM_RED_SIZE:
3065 case SDL_GL_ACCUM_GREEN_SIZE:
3066 case SDL_GL_ACCUM_BLUE_SIZE:
3067 case SDL_GL_ACCUM_ALPHA_SIZE:
3069 /* none of these are supported in OpenGL ES */
3073 case SDL_GL_MULTISAMPLEBUFFERS:
3074 #ifndef SDL_VIDEO_OPENGL_ES
3075 attrib = GL_SAMPLE_BUFFERS_ARB;
3077 attrib = GL_SAMPLE_BUFFERS;
3080 case SDL_GL_MULTISAMPLESAMPLES:
3081 #ifndef SDL_VIDEO_OPENGL_ES
3082 attrib = GL_SAMPLES_ARB;
3084 attrib = GL_SAMPLES;
3087 case SDL_GL_BUFFER_SIZE:
3093 * there doesn't seem to be a single flag in OpenGL
3096 glGetIntegervFunc(GL_RED_BITS, &component);
3098 glGetIntegervFunc(GL_GREEN_BITS, &component);
3100 glGetIntegervFunc(GL_BLUE_BITS, &component);
3102 glGetIntegervFunc(GL_ALPHA_BITS, &component);
3108 case SDL_GL_ACCELERATED_VISUAL:
3110 /* FIXME: How do we get this information? */
3111 *value = (_this->gl_config.accelerated != 0);
3115 SDL_SetError("Unknown OpenGL attribute");
3119 glGetIntegervFunc(attrib, (GLint *) value);
3120 error = glGetErrorFunc();
3121 if (error != GL_NO_ERROR) {
3123 case GL_INVALID_ENUM:
3125 SDL_SetError("OpenGL error: GL_INVALID_ENUM");
3128 case GL_INVALID_VALUE:
3130 SDL_SetError("OpenGL error: GL_INVALID_VALUE");
3135 SDL_SetError("OpenGL error: %08X", error);
3145 #endif /* SDL_VIDEO_OPENGL */
3149 SDL_GL_CreateContext(SDL_WindowID windowID)
3151 SDL_Window *window = SDL_GetWindowFromID(windowID);
3156 if (!(window->flags & SDL_WINDOW_OPENGL)) {
3157 SDL_SetError("The specified window isn't an OpenGL window");
3160 return _this->GL_CreateContext(_this, window);
3164 SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context)
3166 SDL_Window *window = SDL_GetWindowFromID(windowID);
3168 if (window && !(window->flags & SDL_WINDOW_OPENGL)) {
3169 SDL_SetError("The specified window isn't an OpenGL window");
3175 return _this->GL_MakeCurrent(_this, window, context);
3179 SDL_GL_SetSwapInterval(int interval)
3182 SDL_UninitializedVideo();
3185 if (_this->GL_SetSwapInterval) {
3186 return _this->GL_SetSwapInterval(_this, interval);
3188 SDL_SetError("Setting the swap interval is not supported");
3194 SDL_GL_GetSwapInterval(void)
3197 SDL_UninitializedVideo();
3200 if (_this->GL_GetSwapInterval) {
3201 return _this->GL_GetSwapInterval(_this);
3203 SDL_SetError("Getting the swap interval is not supported");
3209 SDL_GL_SwapWindow(SDL_WindowID windowID)
3211 SDL_Window *window = SDL_GetWindowFromID(windowID);
3216 if (!(window->flags & SDL_WINDOW_OPENGL)) {
3217 SDL_SetError("The specified window isn't an OpenGL window");
3220 _this->GL_SwapWindow(_this, window);
3224 SDL_GL_DeleteContext(SDL_GLContext context)
3226 if (!_this || !context) {
3229 _this->GL_MakeCurrent(_this, NULL, NULL);
3230 _this->GL_DeleteContext(_this, context);
3235 * Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags
3236 * & 2 for alpha channel.
3239 CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags)
3243 #define SET_MASKBIT(icon, x, y, mask) \
3244 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
3246 colorkey = icon->format->colorkey;
3247 switch (icon->format->BytesPerPixel) {
3251 for (y = 0; y < icon->h; ++y) {
3252 pixels = (Uint8 *) icon->pixels + y * icon->pitch;
3253 for (x = 0; x < icon->w; ++x) {
3254 if (*pixels++ == colorkey) {
3255 SET_MASKBIT(icon, x, y, mask);
3265 for (y = 0; y < icon->h; ++y) {
3266 pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2;
3267 for (x = 0; x < icon->w; ++x) {
3268 if ((flags & 1) && *pixels == colorkey) {
3269 SET_MASKBIT(icon, x, y, mask);
3270 } else if ((flags & 2)
3271 && (*pixels & icon->format->Amask) == 0) {
3272 SET_MASKBIT(icon, x, y, mask);
3283 for (y = 0; y < icon->h; ++y) {
3284 pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4;
3285 for (x = 0; x < icon->w; ++x) {
3286 if ((flags & 1) && *pixels == colorkey) {
3287 SET_MASKBIT(icon, x, y, mask);
3288 } else if ((flags & 2)
3289 && (*pixels & icon->format->Amask) == 0) {
3290 SET_MASKBIT(icon, x, y, mask);
3301 * Sets the window manager icon for the display window.
3304 SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
3306 if (icon && _this->SetIcon) {
3307 /* Generate a mask if necessary, and create the icon! */
3309 int mask_len = icon->h * (icon->w + 7) / 8;
3311 mask = (Uint8 *) SDL_malloc(mask_len);
3315 SDL_memset(mask, ~0, mask_len);
3316 if (icon->flags & SDL_SRCCOLORKEY)
3318 if (icon->flags & SDL_SRCALPHA)
3321 CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
3323 _this->SetIcon(_this, icon, mask);
3326 _this->SetIcon(_this, icon, mask);
3333 SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo *info)
3335 SDL_Window *window = SDL_GetWindowFromID(windowID);
3337 if (!window || !_this->GetWindowWMInfo) {
3340 return (_this->GetWindowWMInfo(_this, window, info));
3344 SDL_StartTextInput(void)
3346 if (_this->StartTextInput) {
3347 _this->StartTextInput(_this);
3349 SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
3350 SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);
3354 SDL_StopTextInput(void)
3356 if (_this->StopTextInput) {
3357 _this->StopTextInput(_this);
3359 SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
3360 SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
3364 SDL_SetTextInputRect(SDL_Rect *rect)
3366 if (_this->SetTextInputRect) {
3367 _this->SetTextInputRect(_this, rect);
3371 /* vi: set ts=4 sw=4 expandtab: */