Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 1912:8d384b647307
Setting up the OpenGL support
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 16 Jul 2006 09:34:01 +0000 |
parents | 8f1ab2f7c722 |
children | 83420da906a5 |
comparison
equal
deleted
inserted
replaced
1911:7577fd11cee4 | 1912:8d384b647307 |
---|---|
149 } | 149 } |
150 if (a.refresh_rate != b.refresh_rate) { | 150 if (a.refresh_rate != b.refresh_rate) { |
151 return b.refresh_rate - a.refresh_rate; | 151 return b.refresh_rate - a.refresh_rate; |
152 } | 152 } |
153 return 0; | 153 return 0; |
154 } | |
155 | |
156 static void | |
157 SDL_UninitializedVideo() | |
158 { | |
159 SDL_SetError("Video subsystem has not been initialized"); | |
154 } | 160 } |
155 | 161 |
156 int | 162 int |
157 SDL_GetNumVideoDrivers(void) | 163 SDL_GetNumVideoDrivers(void) |
158 { | 164 { |
283 | 289 |
284 const char * | 290 const char * |
285 SDL_GetCurrentVideoDriver() | 291 SDL_GetCurrentVideoDriver() |
286 { | 292 { |
287 if (!_this) { | 293 if (!_this) { |
294 SDL_UninitializedVideo(); | |
288 return NULL; | 295 return NULL; |
289 } | 296 } |
290 return _this->name; | 297 return _this->name; |
291 } | 298 } |
292 | 299 |
332 | 339 |
333 int | 340 int |
334 SDL_GetNumVideoDisplays(void) | 341 SDL_GetNumVideoDisplays(void) |
335 { | 342 { |
336 if (!_this) { | 343 if (!_this) { |
344 SDL_UninitializedVideo(); | |
337 return 0; | 345 return 0; |
338 } | 346 } |
339 return _this->num_displays; | 347 return _this->num_displays; |
340 } | 348 } |
341 | 349 |
342 int | 350 int |
343 SDL_SelectVideoDisplay(int index) | 351 SDL_SelectVideoDisplay(int index) |
344 { | 352 { |
345 if (!_this) { | 353 if (!_this) { |
346 SDL_SetError("Video subsystem has not been initialized"); | 354 SDL_UninitializedVideo(); |
347 return (-1); | 355 return (-1); |
348 } | 356 } |
349 if (index >= 0) { | 357 if (index >= 0) { |
350 if (index >= _this->num_displays) { | 358 if (index >= _this->num_displays) { |
351 SDL_SetError("index must be in the range 0 - %d", | 359 SDL_SetError("index must be in the range 0 - %d", |
533 SDL_VideoDisplay *display; | 541 SDL_VideoDisplay *display; |
534 SDL_DisplayMode display_mode; | 542 SDL_DisplayMode display_mode; |
535 int i, ncolors; | 543 int i, ncolors; |
536 | 544 |
537 if (!_this) { | 545 if (!_this) { |
538 SDL_SetError("Video subsystem has not been initialized"); | 546 SDL_UninitializedVideo(); |
539 return -1; | 547 return -1; |
540 } | 548 } |
541 | 549 |
542 if (!mode) { | 550 if (!mode) { |
543 mode = SDL_GetDesktopDisplayMode(); | 551 mode = SDL_GetDesktopDisplayMode(); |
619 { | 627 { |
620 SDL_VideoDisplay *display; | 628 SDL_VideoDisplay *display; |
621 int i; | 629 int i; |
622 | 630 |
623 if (!_this) { | 631 if (!_this) { |
624 SDL_SetError("Video subsystem has not been initialized"); | 632 SDL_UninitializedVideo(); |
625 return -1; | 633 return -1; |
626 } | 634 } |
627 | 635 |
628 display = &SDL_CurrentDisplay; | 636 display = &SDL_CurrentDisplay; |
629 if (mode) { | 637 if (mode) { |
657 { | 665 { |
658 SDL_Palette *palette; | 666 SDL_Palette *palette; |
659 int status = 0; | 667 int status = 0; |
660 | 668 |
661 if (!_this) { | 669 if (!_this) { |
662 SDL_SetError("Video subsystem has not been initialized"); | 670 SDL_UninitializedVideo(); |
663 return -1; | 671 return -1; |
664 } | 672 } |
665 palette = SDL_CurrentDisplay.palette; | 673 palette = SDL_CurrentDisplay.palette; |
666 if (!palette) { | 674 if (!palette) { |
667 SDL_SetError("Display mode does not have a palette"); | 675 SDL_SetError("Display mode does not have a palette"); |
682 SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors) | 690 SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors) |
683 { | 691 { |
684 SDL_Palette *palette; | 692 SDL_Palette *palette; |
685 | 693 |
686 if (!_this) { | 694 if (!_this) { |
687 SDL_SetError("Video subsystem has not been initialized"); | 695 SDL_UninitializedVideo(); |
688 return -1; | 696 return -1; |
689 } | 697 } |
690 | 698 |
691 palette = SDL_CurrentDisplay.palette; | 699 palette = SDL_CurrentDisplay.palette; |
692 if (!palette->ncolors) { | 700 if (!palette->ncolors) { |
719 SDL_Window window; | 727 SDL_Window window; |
720 int num_windows; | 728 int num_windows; |
721 SDL_Window *windows; | 729 SDL_Window *windows; |
722 | 730 |
723 if (!_this) { | 731 if (!_this) { |
724 SDL_SetError("Video subsystem has not been initialized"); | 732 SDL_UninitializedVideo(); |
733 return 0; | |
734 } | |
735 | |
736 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { | |
737 SDL_SetError("No OpenGL support in video driver"); | |
725 return 0; | 738 return 0; |
726 } | 739 } |
727 | 740 |
728 SDL_zero(window); | 741 SDL_zero(window); |
729 window.id = _this->next_object_id++; | 742 window.id = _this->next_object_id++; |
781 SDL_Window window; | 794 SDL_Window window; |
782 int num_windows; | 795 int num_windows; |
783 SDL_Window *windows; | 796 SDL_Window *windows; |
784 | 797 |
785 if (!_this) { | 798 if (!_this) { |
786 SDL_SetError("Video subsystem has not been initialized"); | 799 SDL_UninitializedVideo(); |
787 return (0); | 800 return (0); |
788 } | 801 } |
789 | 802 |
790 SDL_zero(window); | 803 SDL_zero(window); |
791 window.id = _this->next_object_id++; | 804 window.id = _this->next_object_id++; |
820 SDL_GetWindowFromID(SDL_WindowID windowID) | 833 SDL_GetWindowFromID(SDL_WindowID windowID) |
821 { | 834 { |
822 int i, j; | 835 int i, j; |
823 | 836 |
824 if (!_this) { | 837 if (!_this) { |
838 SDL_UninitializedVideo(); | |
825 return NULL; | 839 return NULL; |
826 } | 840 } |
827 | 841 |
828 for (i = 0; i < _this->num_displays; ++i) { | 842 for (i = 0; i < _this->num_displays; ++i) { |
829 SDL_VideoDisplay *display = &_this->displays[i]; | 843 SDL_VideoDisplay *display = &_this->displays[i]; |
839 | 853 |
840 SDL_VideoDisplay * | 854 SDL_VideoDisplay * |
841 SDL_GetDisplayFromWindow(SDL_Window * window) | 855 SDL_GetDisplayFromWindow(SDL_Window * window) |
842 { | 856 { |
843 if (!_this) { | 857 if (!_this) { |
858 SDL_UninitializedVideo(); | |
844 return NULL; | 859 return NULL; |
845 } | 860 } |
846 return &_this->displays[window->display]; | 861 return &_this->displays[window->display]; |
847 } | 862 } |
848 | 863 |
1279 | 1294 |
1280 int | 1295 int |
1281 SDL_GetRendererInfo(int index, SDL_RendererInfo * info) | 1296 SDL_GetRendererInfo(int index, SDL_RendererInfo * info) |
1282 { | 1297 { |
1283 if (!_this) { | 1298 if (!_this) { |
1299 SDL_UninitializedVideo(); | |
1284 return -1; | 1300 return -1; |
1285 } | 1301 } |
1286 | 1302 |
1287 if (index >= SDL_GetNumRenderers()) { | 1303 if (index >= SDL_GetNumRenderers()) { |
1288 SDL_SetError("index must be in the range of 0 - %d", | 1304 SDL_SetError("index must be in the range of 0 - %d", |
1372 int hash; | 1388 int hash; |
1373 SDL_Renderer *renderer; | 1389 SDL_Renderer *renderer; |
1374 SDL_Texture *texture; | 1390 SDL_Texture *texture; |
1375 | 1391 |
1376 if (!_this) { | 1392 if (!_this) { |
1393 SDL_UninitializedVideo(); | |
1377 return 0; | 1394 return 0; |
1378 } | 1395 } |
1379 | 1396 |
1380 renderer = SDL_CurrentDisplay.current_renderer; | 1397 renderer = SDL_CurrentDisplay.current_renderer; |
1381 if (!renderer || !renderer->CreateTexture) { | 1398 if (!renderer || !renderer->CreateTexture) { |
1750 SDL_Renderer *renderer; | 1767 SDL_Renderer *renderer; |
1751 SDL_Window *window; | 1768 SDL_Window *window; |
1752 SDL_Rect real_rect; | 1769 SDL_Rect real_rect; |
1753 | 1770 |
1754 if (!_this) { | 1771 if (!_this) { |
1772 SDL_UninitializedVideo(); | |
1755 return -1; | 1773 return -1; |
1756 } | 1774 } |
1757 | 1775 |
1758 renderer = SDL_CurrentDisplay.current_renderer; | 1776 renderer = SDL_CurrentDisplay.current_renderer; |
1759 if (!renderer || !renderer->RenderFill) { | 1777 if (!renderer || !renderer->RenderFill) { |
1819 SDL_RenderPresent(void) | 1837 SDL_RenderPresent(void) |
1820 { | 1838 { |
1821 SDL_Renderer *renderer; | 1839 SDL_Renderer *renderer; |
1822 | 1840 |
1823 if (!_this) { | 1841 if (!_this) { |
1842 SDL_UninitializedVideo(); | |
1824 return; | 1843 return; |
1825 } | 1844 } |
1826 | 1845 |
1827 renderer = SDL_CurrentDisplay.current_renderer; | 1846 renderer = SDL_CurrentDisplay.current_renderer; |
1828 if (!renderer || !renderer->RenderPresent) { | 1847 if (!renderer || !renderer->RenderPresent) { |
1837 int hash; | 1856 int hash; |
1838 SDL_Texture *prev, *texture; | 1857 SDL_Texture *prev, *texture; |
1839 SDL_Renderer *renderer; | 1858 SDL_Renderer *renderer; |
1840 | 1859 |
1841 if (!_this) { | 1860 if (!_this) { |
1861 SDL_UninitializedVideo(); | |
1842 return; | 1862 return; |
1843 } | 1863 } |
1844 | 1864 |
1845 /* Look up the texture in the hash table */ | 1865 /* Look up the texture in the hash table */ |
1846 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures)); | 1866 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures)); |
1975 } | 1995 } |
1976 _this->free(_this); | 1996 _this->free(_this); |
1977 _this = NULL; | 1997 _this = NULL; |
1978 } | 1998 } |
1979 | 1999 |
1980 /* Load the GL driver library */ | |
1981 int | 2000 int |
1982 SDL_GL_LoadLibrary(const char *path) | 2001 SDL_GL_LoadLibrary(const char *path) |
1983 { | 2002 { |
1984 int retval; | 2003 int retval; |
1985 | 2004 |
1986 retval = -1; | 2005 if (!_this) { |
1987 if (_this == NULL) { | 2006 SDL_UninitializedVideo(); |
1988 SDL_SetError("Video subsystem has not been initialized"); | 2007 return -1; |
2008 } | |
2009 | |
2010 if (_this->GL_LoadLibrary) { | |
2011 retval = _this->GL_LoadLibrary(_this, path); | |
1989 } else { | 2012 } else { |
1990 if (_this->GL_LoadLibrary) { | 2013 SDL_SetError("No dynamic GL support in video driver"); |
1991 retval = _this->GL_LoadLibrary(_this, path); | 2014 retval = -1; |
1992 } else { | |
1993 SDL_SetError("No dynamic GL support in video driver"); | |
1994 } | |
1995 } | 2015 } |
1996 return (retval); | 2016 return (retval); |
1997 } | 2017 } |
1998 | 2018 |
1999 void * | 2019 void * |
2000 SDL_GL_GetProcAddress(const char *proc) | 2020 SDL_GL_GetProcAddress(const char *proc) |
2001 { | 2021 { |
2002 void *func; | 2022 void *func; |
2023 | |
2024 if (!_this) { | |
2025 SDL_UninitializedVideo(); | |
2026 return NULL; | |
2027 } | |
2003 | 2028 |
2004 func = NULL; | 2029 func = NULL; |
2005 if (_this->GL_GetProcAddress) { | 2030 if (_this->GL_GetProcAddress) { |
2006 if (_this->gl_config.driver_loaded) { | 2031 if (_this->gl_config.driver_loaded) { |
2007 func = _this->GL_GetProcAddress(_this, proc); | 2032 func = _this->GL_GetProcAddress(_this, proc); |
2012 SDL_SetError("No dynamic GL support in video driver"); | 2037 SDL_SetError("No dynamic GL support in video driver"); |
2013 } | 2038 } |
2014 return func; | 2039 return func; |
2015 } | 2040 } |
2016 | 2041 |
2017 /* Set the specified GL attribute for setting up a GL video mode */ | |
2018 int | 2042 int |
2019 SDL_GL_SetAttribute(SDL_GLattr attr, int value) | 2043 SDL_GL_SetAttribute(SDL_GLattr attr, int value) |
2020 { | 2044 { |
2021 int retval; | 2045 int retval; |
2046 | |
2047 if (!_this) { | |
2048 SDL_UninitializedVideo(); | |
2049 return -1; | |
2050 } | |
2022 | 2051 |
2023 retval = 0; | 2052 retval = 0; |
2024 switch (attr) { | 2053 switch (attr) { |
2025 case SDL_GL_RED_SIZE: | 2054 case SDL_GL_RED_SIZE: |
2026 _this->gl_config.red_size = value; | 2055 _this->gl_config.red_size = value; |
2073 default: | 2102 default: |
2074 SDL_SetError("Unknown OpenGL attribute"); | 2103 SDL_SetError("Unknown OpenGL attribute"); |
2075 retval = -1; | 2104 retval = -1; |
2076 break; | 2105 break; |
2077 } | 2106 } |
2078 return (retval); | 2107 return retval; |
2079 } | 2108 } |
2080 | 2109 |
2081 /* Retrieve an attribute value from the windowing system. */ | 2110 int |
2082 int | 2111 SDL_GL_GetWindowAttribute(SDL_WindowID windowID, SDL_GLattr attr, int *value) |
2083 SDL_GL_GetAttribute(SDL_GLattr attr, int *value) | 2112 { |
2084 { | 2113 SDL_Window *window = SDL_GetWindowFromID(windowID); |
2085 int retval = -1; | 2114 int retval; |
2115 | |
2116 if (!window) { | |
2117 return -1; | |
2118 } | |
2086 | 2119 |
2087 if (_this->GL_GetAttribute) { | 2120 if (_this->GL_GetAttribute) { |
2088 retval = _this->GL_GetAttribute(_this, attr, value); | 2121 retval = _this->GL_GetAttribute(_this, attr, value); |
2089 } else { | 2122 } else { |
2090 *value = 0; | 2123 *value = 0; |
2091 SDL_SetError("GL_GetAttribute not supported"); | 2124 SDL_SetError("GL_GetAttribute not supported"); |
2125 retval = -1; | |
2092 } | 2126 } |
2093 return retval; | 2127 return retval; |
2094 } | 2128 } |
2095 | 2129 |
2096 /* Perform a GL buffer swap on the current GL context */ | 2130 SDL_GLContext |
2097 void | 2131 SDL_GL_CreateContext(SDL_WindowID windowID) |
2098 SDL_GL_SwapBuffers(void) | 2132 { |
2099 { | 2133 SDL_Window *window = SDL_GetWindowFromID(windowID); |
2100 // FIXME: Track the current window context - do we provide N contexts, and match them to M windows, or is there a one-to-one mapping? | 2134 |
2101 _this->GL_SwapBuffers(_this); | 2135 if (!window) { |
2136 return NULL; | |
2137 } | |
2138 if (!(window->flags & SDL_WINDOW_OPENGL)) { | |
2139 SDL_SetError("The specified window isn't an OpenGL window"); | |
2140 return NULL; | |
2141 } | |
2142 return _this->GL_CreateContext(_this, window); | |
2143 } | |
2144 | |
2145 int | |
2146 SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context) | |
2147 { | |
2148 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
2149 | |
2150 if (!window || !context) { | |
2151 return -1; | |
2152 } | |
2153 if (!(window->flags & SDL_WINDOW_OPENGL)) { | |
2154 SDL_SetError("The specified window isn't an OpenGL window"); | |
2155 return -1; | |
2156 } | |
2157 return _this->GL_MakeCurrent(_this, window, context); | |
2158 } | |
2159 | |
2160 int | |
2161 SDL_GL_SetSwapInterval(int interval) | |
2162 { | |
2163 if (!_this) { | |
2164 SDL_UninitializedVideo(); | |
2165 return -1; | |
2166 } | |
2167 | |
2168 if (_this->GL_SetSwapInterval) { | |
2169 return _this->GL_SetSwapInterval(_this, interval); | |
2170 } else { | |
2171 SDL_SetError("Setting the swap interval is not supported"); | |
2172 return -1; | |
2173 } | |
2174 } | |
2175 | |
2176 int | |
2177 SDL_GL_GetSwapInterval(void) | |
2178 { | |
2179 if (!_this) { | |
2180 SDL_UninitializedVideo(); | |
2181 return -1; | |
2182 } | |
2183 | |
2184 if (_this->GL_GetSwapInterval) { | |
2185 return _this->GL_GetSwapInterval(_this); | |
2186 } else { | |
2187 SDL_SetError("Getting the swap interval is not supported"); | |
2188 return -1; | |
2189 } | |
2190 } | |
2191 | |
2192 void | |
2193 SDL_GL_SwapWindow(SDL_WindowID windowID) | |
2194 { | |
2195 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
2196 | |
2197 if (!window) { | |
2198 return; | |
2199 } | |
2200 if (!(window->flags & SDL_WINDOW_OPENGL)) { | |
2201 SDL_SetError("The specified window isn't an OpenGL window"); | |
2202 return; | |
2203 } | |
2204 return _this->GL_SwapWindow(_this, window); | |
2205 } | |
2206 | |
2207 void | |
2208 SDL_GL_DeleteContext(SDL_GLContext context) | |
2209 { | |
2210 if (!_this || !context) { | |
2211 return; | |
2212 } | |
2213 _this->GL_DeleteContext(_this, context); | |
2102 } | 2214 } |
2103 | 2215 |
2104 #if 0 // FIXME | 2216 #if 0 // FIXME |
2105 /* Utility function used by SDL_WM_SetIcon(); | 2217 /* Utility function used by SDL_WM_SetIcon(); |
2106 * flags & 1 for color key, flags & 2 for alpha channel. */ | 2218 * flags & 1 for color key, flags & 2 for alpha channel. */ |