Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 3057:089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Make sure OpenGL library is loaded before working with OpenGL windows,
even those created with SDL_CreateWindowFrom()
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 09 Feb 2009 05:32:12 +0000 |
parents | aa34d1180d30 |
children | 17c5930f498e |
comparison
equal
deleted
inserted
replaced
3056:a434fe6360df | 3057:089a77aebb7d |
---|---|
760 | 760 |
761 if (!_this) { | 761 if (!_this) { |
762 SDL_UninitializedVideo(); | 762 SDL_UninitializedVideo(); |
763 return 0; | 763 return 0; |
764 } | 764 } |
765 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { | 765 if (flags & SDL_WINDOW_OPENGL) { |
766 SDL_SetError("No OpenGL support in video driver"); | 766 if (!_this->GL_CreateContext) { |
767 return 0; | 767 SDL_SetError("No OpenGL support in video driver"); |
768 return 0; | |
769 } | |
770 SDL_GL_LoadLibrary(NULL); | |
768 } | 771 } |
769 SDL_zero(window); | 772 SDL_zero(window); |
770 window.id = _this->next_object_id++; | 773 window.id = _this->next_object_id++; |
771 window.x = x; | 774 window.x = x; |
772 window.y = y; | 775 window.y = y; |
774 window.h = h; | 777 window.h = h; |
775 window.flags = (flags & allowed_flags); | 778 window.flags = (flags & allowed_flags); |
776 window.display = _this->current_display; | 779 window.display = _this->current_display; |
777 | 780 |
778 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { | 781 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { |
782 if (flags & SDL_WINDOW_OPENGL) { | |
783 SDL_GL_UnloadLibrary(); | |
784 } | |
779 return 0; | 785 return 0; |
780 } | 786 } |
781 display = &SDL_CurrentDisplay; | 787 display = &SDL_CurrentDisplay; |
782 num_windows = display->num_windows; | 788 num_windows = display->num_windows; |
783 windows = | 789 windows = |
784 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows)); | 790 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows)); |
785 if (!windows) { | 791 if (!windows) { |
786 if (_this->DestroyWindow) { | 792 if (_this->DestroyWindow) { |
787 _this->DestroyWindow(_this, &window); | 793 _this->DestroyWindow(_this, &window); |
788 } | 794 } |
795 if (flags & SDL_WINDOW_OPENGL) { | |
796 SDL_GL_UnloadLibrary(); | |
797 } | |
789 return 0; | 798 return 0; |
790 } | 799 } |
791 windows[num_windows] = window; | 800 windows[num_windows] = window; |
792 display->windows = windows; | 801 display->windows = windows; |
793 display->num_windows++; | 802 display->num_windows++; |
822 return (0); | 831 return (0); |
823 } | 832 } |
824 SDL_zero(window); | 833 SDL_zero(window); |
825 window.id = _this->next_object_id++; | 834 window.id = _this->next_object_id++; |
826 window.display = _this->current_display; | 835 window.display = _this->current_display; |
836 window.flags = SDL_WINDOW_FOREIGN; | |
827 | 837 |
828 if (!_this->CreateWindowFrom || | 838 if (!_this->CreateWindowFrom || |
829 _this->CreateWindowFrom(_this, &window, data) < 0) { | 839 _this->CreateWindowFrom(_this, &window, data) < 0) { |
830 return 0; | 840 return 0; |
831 } | 841 } |
850 } | 860 } |
851 | 861 |
852 int | 862 int |
853 SDL_RecreateWindow(SDL_Window * window, Uint32 flags) | 863 SDL_RecreateWindow(SDL_Window * window, Uint32 flags) |
854 { | 864 { |
865 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | | |
866 SDL_WINDOW_OPENGL | | |
867 SDL_WINDOW_BORDERLESS | | |
868 SDL_WINDOW_RESIZABLE | | |
869 SDL_WINDOW_INPUT_GRABBED); | |
855 char *title = window->title; | 870 char *title = window->title; |
856 | 871 |
857 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { | 872 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { |
858 SDL_SetError("No OpenGL support in video driver"); | 873 SDL_SetError("No OpenGL support in video driver"); |
859 return -1; | 874 return -1; |
860 } | 875 } |
861 if (_this->DestroyWindow) { | 876 if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) { |
877 if (flags & SDL_WINDOW_OPENGL) { | |
878 SDL_GL_LoadLibrary(NULL); | |
879 } else { | |
880 SDL_GL_UnloadLibrary(); | |
881 } | |
882 } | |
883 | |
884 if (window->flags & SDL_WINDOW_FOREIGN) { | |
885 /* Can't destroy and re-create foreign windows, hrm */ | |
886 flags |= SDL_WINDOW_FOREIGN; | |
887 } else { | |
888 flags &= ~SDL_WINDOW_FOREIGN; | |
889 } | |
890 | |
891 if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) { | |
862 _this->DestroyWindow(_this, window); | 892 _this->DestroyWindow(_this, window); |
863 } | 893 } |
894 | |
864 window->title = NULL; | 895 window->title = NULL; |
865 window->flags = | 896 window->flags = (flags & allowed_flags); |
866 (flags & | 897 |
867 ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED | SDL_WINDOW_SHOWN | | 898 if (_this->CreateWindow && !(flags & SDL_WINDOW_FOREIGN)) { |
868 SDL_WINDOW_INPUT_GRABBED)); | 899 if (_this->CreateWindow(_this, window) < 0) { |
869 | 900 if (flags & SDL_WINDOW_OPENGL) { |
870 if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) { | 901 SDL_GL_UnloadLibrary(); |
871 return -1; | 902 } |
872 } | 903 return -1; |
904 } | |
905 } | |
906 | |
873 if (title) { | 907 if (title) { |
874 SDL_SetWindowTitle(window->id, title); | 908 SDL_SetWindowTitle(window->id, title); |
875 SDL_free(title); | 909 SDL_free(title); |
876 } | 910 } |
877 if (flags & SDL_WINDOW_MAXIMIZED) { | 911 if (flags & SDL_WINDOW_MAXIMIZED) { |
1350 window->renderer = NULL; | 1384 window->renderer = NULL; |
1351 } | 1385 } |
1352 if (_this->DestroyWindow) { | 1386 if (_this->DestroyWindow) { |
1353 _this->DestroyWindow(_this, window); | 1387 _this->DestroyWindow(_this, window); |
1354 } | 1388 } |
1389 if (window->flags & SDL_WINDOW_OPENGL) { | |
1390 SDL_GL_UnloadLibrary(); | |
1391 } | |
1355 if (j != display->num_windows - 1) { | 1392 if (j != display->num_windows - 1) { |
1356 SDL_memcpy(&display->windows[i], | 1393 SDL_memcpy(&display->windows[i], |
1357 &display->windows[i + 1], | 1394 &display->windows[i + 1], |
1358 (display->num_windows - i - 1) * sizeof(*window)); | 1395 (display->num_windows - i - 1) * sizeof(*window)); |
1359 } | 1396 } |
1541 | 1578 |
1542 SDL_TextureID | 1579 SDL_TextureID |
1543 SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) | 1580 SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) |
1544 { | 1581 { |
1545 SDL_TextureID textureID; | 1582 SDL_TextureID textureID; |
1583 Uint32 requested_format = format; | |
1546 SDL_PixelFormat *fmt; | 1584 SDL_PixelFormat *fmt; |
1547 int bpp; | 1585 int bpp; |
1548 Uint32 Rmask, Gmask, Bmask, Amask; | 1586 Uint32 Rmask, Gmask, Bmask, Amask; |
1549 | 1587 |
1550 if (!surface) { | 1588 if (!surface) { |
1584 } | 1622 } |
1585 | 1623 |
1586 textureID = | 1624 textureID = |
1587 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, | 1625 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, |
1588 surface->h); | 1626 surface->h); |
1627 if (!textureID && !requested_format) { | |
1628 SDL_DisplayMode desktop_mode; | |
1629 SDL_GetDesktopDisplayMode(&desktop_mode); | |
1630 format = desktop_mode.format; | |
1631 textureID = | |
1632 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, | |
1633 surface->h); | |
1634 } | |
1589 if (!textureID) { | 1635 if (!textureID) { |
1590 return 0; | 1636 return 0; |
1591 } | 1637 } |
1592 if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask | 1638 if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask |
1593 && Bmask == fmt->Bmask && Amask == fmt->Amask) { | 1639 && Bmask == fmt->Bmask && Amask == fmt->Amask) { |
2458 | 2504 |
2459 if (!_this) { | 2505 if (!_this) { |
2460 SDL_UninitializedVideo(); | 2506 SDL_UninitializedVideo(); |
2461 return -1; | 2507 return -1; |
2462 } | 2508 } |
2463 if (_this->GL_LoadLibrary) { | 2509 if (_this->gl_config.driver_loaded) { |
2510 if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) { | |
2511 SDL_SetError("OpenGL library already loaded"); | |
2512 return -1; | |
2513 } | |
2514 retval = 0; | |
2515 } else { | |
2516 if (!_this->GL_LoadLibrary) { | |
2517 SDL_SetError("No dynamic GL support in video driver"); | |
2518 return -1; | |
2519 } | |
2464 retval = _this->GL_LoadLibrary(_this, path); | 2520 retval = _this->GL_LoadLibrary(_this, path); |
2465 } else { | 2521 } |
2466 SDL_SetError("No dynamic GL support in video driver"); | 2522 if (retval == 0) { |
2467 retval = -1; | 2523 ++_this->gl_config.driver_loaded; |
2468 } | 2524 } |
2469 return (retval); | 2525 return (retval); |
2470 } | 2526 } |
2471 | 2527 |
2472 void * | 2528 void * |
2487 } | 2543 } |
2488 } else { | 2544 } else { |
2489 SDL_SetError("No dynamic GL support in video driver"); | 2545 SDL_SetError("No dynamic GL support in video driver"); |
2490 } | 2546 } |
2491 return func; | 2547 return func; |
2548 } | |
2549 | |
2550 void | |
2551 SDL_GL_UnloadLibrary(void) | |
2552 { | |
2553 if (!_this) { | |
2554 SDL_UninitializedVideo(); | |
2555 return; | |
2556 } | |
2557 if (_this->gl_config.driver_loaded > 0) { | |
2558 if (--_this->gl_config.driver_loaded > 0) { | |
2559 return; | |
2560 } | |
2561 if (_this->GL_UnloadLibrary) { | |
2562 _this->GL_UnloadLibrary(_this); | |
2563 } | |
2564 } | |
2492 } | 2565 } |
2493 | 2566 |
2494 SDL_bool | 2567 SDL_bool |
2495 SDL_GL_ExtensionSupported(const char *extension) | 2568 SDL_GL_ExtensionSupported(const char *extension) |
2496 { | 2569 { |