498 #endif |
498 #endif |
499 _this->gl_config.flags = 0; |
499 _this->gl_config.flags = 0; |
500 _this->gl_config.profile_mask = 0; |
500 _this->gl_config.profile_mask = 0; |
501 _this->gl_config.share_with_current_context = 0; |
501 _this->gl_config.share_with_current_context = 0; |
502 |
502 |
|
503 _this->current_glwin_tls = SDL_TLSCreate(); |
|
504 _this->current_glctx_tls = SDL_TLSCreate(); |
|
505 |
503 /* Initialize the video subsystem */ |
506 /* Initialize the video subsystem */ |
504 if (_this->VideoInit(_this) < 0) { |
507 if (_this->VideoInit(_this) < 0) { |
505 SDL_VideoQuit(); |
508 SDL_VideoQuit(); |
506 return -1; |
509 return -1; |
507 } |
510 } |
2736 ctx = _this->GL_CreateContext(_this, window); |
2739 ctx = _this->GL_CreateContext(_this, window); |
2737 |
2740 |
2738 /* Creating a context is assumed to make it current in the SDL driver. */ |
2741 /* Creating a context is assumed to make it current in the SDL driver. */ |
2739 _this->current_glwin = window; |
2742 _this->current_glwin = window; |
2740 _this->current_glctx = ctx; |
2743 _this->current_glctx = ctx; |
2741 _this->current_glthread = SDL_ThreadID(); |
2744 SDL_TLSSet(_this->current_glwin_tls, window, NULL); |
|
2745 SDL_TLSSet(_this->current_glctx_tls, ctx, NULL); |
2742 |
2746 |
2743 return ctx; |
2747 return ctx; |
2744 } |
2748 } |
2745 |
2749 |
2746 int |
2750 int |
2747 SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx) |
2751 SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx) |
2748 { |
2752 { |
2749 int retval; |
2753 int retval; |
2750 SDL_threadID thread = SDL_ThreadID(); |
2754 |
|
2755 if (window == SDL_GL_GetCurrentWindow() && |
|
2756 ctx == SDL_GL_GetCurrentContext()) { |
|
2757 /* We're already current. */ |
|
2758 return 0; |
|
2759 } |
2751 |
2760 |
2752 if (!ctx) { |
2761 if (!ctx) { |
2753 window = NULL; |
2762 window = NULL; |
2754 } else { |
2763 } else { |
2755 CHECK_WINDOW_MAGIC(window, -1); |
2764 CHECK_WINDOW_MAGIC(window, -1); |
2757 if (!(window->flags & SDL_WINDOW_OPENGL)) { |
2766 if (!(window->flags & SDL_WINDOW_OPENGL)) { |
2758 return SDL_SetError("The specified window isn't an OpenGL window"); |
2767 return SDL_SetError("The specified window isn't an OpenGL window"); |
2759 } |
2768 } |
2760 } |
2769 } |
2761 |
2770 |
2762 if ((window == _this->current_glwin) && (ctx == _this->current_glctx) && (thread == _this->current_glthread)) { |
2771 retval = _this->GL_MakeCurrent(_this, window, ctx); |
2763 retval = 0; /* we're already current. */ |
2772 if (retval == 0) { |
2764 } else { |
2773 _this->current_glwin = window; |
2765 retval = _this->GL_MakeCurrent(_this, window, ctx); |
2774 _this->current_glctx = ctx; |
2766 if (retval == 0) { |
2775 SDL_TLSSet(_this->current_glwin_tls, window, NULL); |
2767 _this->current_glwin = window; |
2776 SDL_TLSSet(_this->current_glctx_tls, ctx, NULL); |
2768 _this->current_glctx = ctx; |
2777 } |
2769 _this->current_glthread = thread; |
|
2770 } |
|
2771 } |
|
2772 |
|
2773 return retval; |
2778 return retval; |
|
2779 } |
|
2780 |
|
2781 SDL_Window * |
|
2782 SDL_GL_GetCurrentWindow(void) |
|
2783 { |
|
2784 if (!_this) { |
|
2785 SDL_UninitializedVideo(); |
|
2786 return NULL; |
|
2787 } |
|
2788 return (SDL_Window *)SDL_TLSGet(_this->current_glwin_tls); |
|
2789 } |
|
2790 |
|
2791 SDL_GLContext |
|
2792 SDL_GL_GetCurrentContext(void) |
|
2793 { |
|
2794 if (!_this) { |
|
2795 SDL_UninitializedVideo(); |
|
2796 return NULL; |
|
2797 } |
|
2798 return (SDL_GLContext)SDL_TLSGet(_this->current_glctx_tls); |
2774 } |
2799 } |
2775 |
2800 |
2776 int |
2801 int |
2777 SDL_GL_SetSwapInterval(int interval) |
2802 SDL_GL_SetSwapInterval(int interval) |
2778 { |
2803 { |
2779 if (!_this) { |
2804 if (!_this) { |
2780 return SDL_UninitializedVideo(); |
2805 return SDL_UninitializedVideo(); |
2781 } else if (_this->current_glctx == NULL) { |
2806 } else if (SDL_GL_GetCurrentContext() == NULL) { |
2782 return SDL_SetError("No OpenGL context has been made current"); |
2807 return SDL_SetError("No OpenGL context has been made current"); |
2783 } else if (_this->GL_SetSwapInterval) { |
2808 } else if (_this->GL_SetSwapInterval) { |
2784 return _this->GL_SetSwapInterval(_this, interval); |
2809 return _this->GL_SetSwapInterval(_this, interval); |
2785 } else { |
2810 } else { |
2786 return SDL_SetError("Setting the swap interval is not supported"); |
2811 return SDL_SetError("Setting the swap interval is not supported"); |