@@ -42,6 +42,7 @@ typedef struct gfx_ctx_sdl_data
4242#ifdef HAVE_SDL2
4343 SDL_Window * win ;
4444 SDL_GLContext ctx ;
45+ SDL_GLContext shared_ctx ;
4546#else
4647 SDL_Surface * win ;
4748#endif
@@ -67,10 +68,14 @@ static void sdl_ctx_destroy_resources(gfx_ctx_sdl_data_t *sdl)
6768 if (sdl -> ctx )
6869 SDL_GL_DeleteContext (sdl -> ctx );
6970
71+ if (sdl -> shared_ctx )
72+ SDL_GL_DeleteContext (sdl -> shared_ctx );
73+
7074 if (sdl -> win )
7175 SDL_DestroyWindow (sdl -> win );
7276
7377 sdl -> ctx = NULL ;
78+ sdl -> shared_ctx = NULL ;
7479#else
7580 if (sdl -> win )
7681 SDL_FreeSurface (sdl -> win );
@@ -424,6 +429,35 @@ static uint32_t sdl_ctx_get_flags(void *data)
424429static bool sdl_ctx_suppress_screensaver (void * data , bool enable ) { return false; }
425430static void sdl_ctx_set_flags (void * data , uint32_t flags ) { }
426431
432+ static void sdl_ctx_bind_hw_render (void * data , bool enable )
433+ {
434+ #ifdef HAVE_SDL2
435+ gfx_ctx_sdl_data_t * sdl = (gfx_ctx_sdl_data_t * )data ;
436+ if (!sdl || !sdl -> win || !sdl -> ctx )
437+ return ;
438+
439+ if (enable )
440+ {
441+ if (!sdl -> shared_ctx )
442+ {
443+ SDL_GL_SetAttribute (SDL_GL_SHARE_WITH_CURRENT_CONTEXT , 1 );
444+ SDL_GL_MakeCurrent (sdl -> win , sdl -> ctx );
445+ sdl -> shared_ctx = SDL_GL_CreateContext (sdl -> win );
446+ if (!sdl -> shared_ctx )
447+ {
448+ RARCH_ERR ("[SDL_GL]: Failed to create shared GL context: %s\n" , SDL_GetError ());
449+ return ;
450+ }
451+ }
452+ SDL_GL_MakeCurrent (sdl -> win , sdl -> shared_ctx );
453+ }
454+ else
455+ {
456+ SDL_GL_MakeCurrent (sdl -> win , sdl -> ctx );
457+ }
458+ #endif
459+ }
460+
427461const gfx_ctx_driver_t gfx_ctx_sdl_gl =
428462{
429463 sdl_ctx_init ,
@@ -454,7 +488,7 @@ const gfx_ctx_driver_t gfx_ctx_sdl_gl =
454488 "gl_sdl" ,
455489 sdl_ctx_get_flags ,
456490 sdl_ctx_set_flags ,
457- NULL , /* bind_hw_render */
491+ sdl_ctx_bind_hw_render ,
458492 NULL ,
459493 NULL
460494};
0 commit comments