diff --git a/gfx/common/d3d9_common.c b/gfx/common/d3d9_common.c index 286c1a40b0..a0fc7ce6d2 100644 --- a/gfx/common/d3d9_common.c +++ b/gfx/common/d3d9_common.c @@ -1211,7 +1211,7 @@ uintptr_t d3d9_load_texture(void *video_data, void *data, #ifdef HAVE_THREADS if (threaded) - return video_thread_texture_load(&info, + return video_thread_texture_handle(&info, d3d9_video_texture_load_wrap_d3d); #endif diff --git a/gfx/drivers/d3d8.c b/gfx/drivers/d3d8.c index e4d547145a..1bbe7ed4c0 100644 --- a/gfx/drivers/d3d8.c +++ b/gfx/drivers/d3d8.c @@ -2121,7 +2121,7 @@ static uintptr_t d3d8_load_texture(void *video_data, void *data, info.type = filter_type; if (threaded) - return video_thread_texture_load(&info, + return video_thread_texture_handle(&info, d3d8_video_texture_load_wrap_d3d); d3d8_video_texture_load_d3d(&info, &id); diff --git a/gfx/drivers/gl1.c b/gfx/drivers/gl1.c index 0fa7ac58cd..0c5300d691 100644 --- a/gfx/drivers/gl1.c +++ b/gfx/drivers/gl1.c @@ -2130,12 +2130,30 @@ static void video_texture_load_gl1( static int video_texture_load_wrap_gl1(void *data) { uintptr_t id = 0; - if (!data) - return 0; - video_texture_load_gl1((struct texture_image*)data, - TEXTURE_FILTER_NEAREST, &id); + gl1_t *gl1 = (gl1_t*)video_driver_get_ptr(); + + if (gl1->ctx_driver->make_current) + gl1->ctx_driver->make_current(false); + + if (data) + video_texture_load_gl1((struct texture_image*)data, + TEXTURE_FILTER_NEAREST, &id); return (int)id; } + +static int video_texture_unload_wrap_gl1(void *data) +{ + GLuint glid; + uintptr_t id = (uintptr_t)data; + gl1_t *gl1 = (gl1_t*)video_driver_get_ptr(); + + if (gl1 && gl1->ctx_driver->make_current) + gl1->ctx_driver->make_current(false); + + glid = (GLuint)id; + glDeleteTextures(1, &glid); + return 0; +} #endif static uintptr_t gl1_load_texture(void *video_data, void *data, @@ -2149,10 +2167,7 @@ static uintptr_t gl1_load_texture(void *video_data, void *data, gl1_t *gl1 = (gl1_t*)video_data; custom_command_method_t func = video_texture_load_wrap_gl1; - if (gl1->ctx_driver->make_current) - gl1->ctx_driver->make_current(false); - - return video_thread_texture_load(data, func); + return video_thread_texture_handle(data, func); } #endif @@ -2171,15 +2186,15 @@ static void gl1_unload_texture(void *data, bool threaded, uintptr_t id) { GLuint glid; - gl1_t *gl1 = (gl1_t*)data; if (!id) return; #ifdef HAVE_THREADS if (threaded) { - if (gl1->ctx_driver->make_current) - gl1->ctx_driver->make_current(false); + custom_command_method_t func = video_texture_unload_wrap_gl1; + video_thread_texture_handle((void *)id, func); + return; } #endif diff --git a/gfx/drivers/gl2.c b/gfx/drivers/gl2.c index de40ecb307..791ef5c89d 100644 --- a/gfx/drivers/gl2.c +++ b/gfx/drivers/gl2.c @@ -5156,24 +5156,44 @@ static void video_texture_load_gl2( static int video_texture_load_wrap_gl2_mipmap(void *data) { uintptr_t id = 0; + gl2_t *gl = (gl2_t*)video_driver_get_ptr(); - if (!data) - return 0; - video_texture_load_gl2((struct texture_image*)data, - TEXTURE_FILTER_MIPMAP_LINEAR, &id); + if (gl && gl->ctx_driver->make_current) + gl->ctx_driver->make_current(false); + + if (data) + video_texture_load_gl2((struct texture_image*)data, + TEXTURE_FILTER_MIPMAP_LINEAR, &id); return (int)id; } static int video_texture_load_wrap_gl2(void *data) { uintptr_t id = 0; + gl2_t *gl = (gl2_t*)video_driver_get_ptr(); - if (!data) - return 0; - video_texture_load_gl2((struct texture_image*)data, - TEXTURE_FILTER_LINEAR, &id); + if (gl && gl->ctx_driver->make_current) + gl->ctx_driver->make_current(false); + + if (data) + video_texture_load_gl2((struct texture_image*)data, + TEXTURE_FILTER_LINEAR, &id); return (int)id; } + +static int video_texture_unload_wrap_gl2(void *data) +{ + GLuint glid; + uintptr_t id = (uintptr_t)data; + gl2_t *gl = (gl2_t*)video_driver_get_ptr(); + + if (gl && gl->ctx_driver->make_current) + gl->ctx_driver->make_current(false); + + glid = (GLuint)id; + glDeleteTextures(1, &glid); + return 0; +} #endif static uintptr_t gl2_load_texture(void *video_data, void *data, @@ -5184,12 +5204,7 @@ static uintptr_t gl2_load_texture(void *video_data, void *data, #ifdef HAVE_THREADS if (threaded) { - gl2_t *gl = (gl2_t*)video_data; custom_command_method_t func = video_texture_load_wrap_gl2; - - if (gl->ctx_driver->make_current) - gl->ctx_driver->make_current(false); - switch (filter_type) { case TEXTURE_FILTER_MIPMAP_LINEAR: @@ -5199,7 +5214,7 @@ static uintptr_t gl2_load_texture(void *video_data, void *data, default: break; } - return video_thread_texture_load(data, func); + return video_thread_texture_handle(data, func); } #endif @@ -5217,10 +5232,9 @@ static void gl2_unload_texture(void *data, #ifdef HAVE_THREADS if (threaded) { - gl2_t *gl = (gl2_t*)data; - if (gl && gl->ctx_driver) - if (gl->ctx_driver->make_current) - gl->ctx_driver->make_current(false); + custom_command_method_t func = video_texture_unload_wrap_gl2; + video_thread_texture_handle((void *)id, func); + return; } #endif diff --git a/gfx/drivers/gl3.c b/gfx/drivers/gl3.c index 50de2d8895..07104f49c5 100644 --- a/gfx/drivers/gl3.c +++ b/gfx/drivers/gl3.c @@ -2585,7 +2585,7 @@ static bool gl3_frame(void *data, const void *frame, #endif gl3_filter_chain_set_rotation(gl->filter_chain, retroarch_get_rotation()); - /* Sub-frame info for multiframe shaders (per real content frame). + /* Sub-frame info for multiframe shaders (per real content frame). Should always be 1 for non-use of subframes*/ if (!(gl->flags & GL3_FLAG_FRAME_DUPE_LOCK)) { @@ -2604,7 +2604,7 @@ static bool gl3_frame(void *data, const void *frame, gl->filter_chain, 1); } -#ifdef GL3_ROLLING_SCANLINE_SIMULATION +#ifdef GL3_ROLLING_SCANLINE_SIMULATION if ( (video_info->shader_subframes > 1) && (video_info->scan_subframes) && !video_info->black_frame_insertion @@ -2620,8 +2620,8 @@ static bool gl3_frame(void *data, const void *frame, { gl3_filter_chain_set_simulate_scanline( gl->filter_chain, false); - } -#endif // GL3_ROLLING_SCANLINE_SIMULATION + } +#endif // GL3_ROLLING_SCANLINE_SIMULATION gl3_filter_chain_set_input_texture(gl->filter_chain, &texture); gl3_filter_chain_build_offscreen_passes(gl->filter_chain, @@ -2845,24 +2845,44 @@ static struct video_shader *gl3_get_current_shader(void *data) static int video_texture_load_wrap_gl3_mipmap(void *data) { GLuint id = 0; + gl3_t *gl = (gl3_t*)video_driver_get_ptr(); - if (!data) - return 0; - video_texture_load_gl3((struct texture_image*)data, - TEXTURE_FILTER_MIPMAP_LINEAR, &id); + if (gl && gl->ctx_driver->make_current) + gl->ctx_driver->make_current(false); + + if (data) + video_texture_load_gl3((struct texture_image*)data, + TEXTURE_FILTER_MIPMAP_LINEAR, &id); return (int)id; } static int video_texture_load_wrap_gl3(void *data) { GLuint id = 0; + gl3_t *gl = (gl3_t*)video_driver_get_ptr(); - if (!data) - return 0; - video_texture_load_gl3((struct texture_image*)data, - TEXTURE_FILTER_LINEAR, &id); + if (gl && gl->ctx_driver->make_current) + gl->ctx_driver->make_current(false); + + if (data) + video_texture_load_gl3((struct texture_image*)data, + TEXTURE_FILTER_LINEAR, &id); return (int)id; } + +static int video_texture_unload_wrap_gl3(void *data) +{ + GLuint glid; + uintptr_t id = (uintptr_t)data; + gl3_t *gl = (gl3_t*)video_driver_get_ptr(); + + if (gl && gl->ctx_driver->make_current) + gl->ctx_driver->make_current(false); + + glid = (GLuint)id; + glDeleteTextures(1, &glid); + return 0; +} #endif static uintptr_t gl3_load_texture(void *video_data, void *data, @@ -2873,12 +2893,7 @@ static uintptr_t gl3_load_texture(void *video_data, void *data, #ifdef HAVE_THREADS if (threaded) { - gl3_t *gl = (gl3_t*)video_data; custom_command_method_t func = video_texture_load_wrap_gl3; - - if (gl->ctx_driver->make_current) - gl->ctx_driver->make_current(false); - switch (filter_type) { case TEXTURE_FILTER_MIPMAP_LINEAR: @@ -2888,7 +2903,7 @@ static uintptr_t gl3_load_texture(void *video_data, void *data, default: break; } - return video_thread_texture_load(data, func); + return video_thread_texture_handle(data, func); } #endif @@ -2900,15 +2915,15 @@ static void gl3_unload_texture(void *data, bool threaded, uintptr_t id) { GLuint glid; - gl3_t *gl = (gl3_t*)data; if (!id) return; #ifdef HAVE_THREADS if (threaded) { - if (gl->ctx_driver->make_current) - gl->ctx_driver->make_current(false); + custom_command_method_t func = video_texture_unload_wrap_gl3; + video_thread_texture_handle((void *)id, func); + return; } #endif diff --git a/gfx/video_thread_wrapper.c b/gfx/video_thread_wrapper.c index ad369cd2e1..72e8e0db2d 100644 --- a/gfx/video_thread_wrapper.c +++ b/gfx/video_thread_wrapper.c @@ -1423,7 +1423,7 @@ bool video_thread_font_init(const void **font_driver, void **font_handle, return pkt.data.font_init.return_value; } -unsigned video_thread_texture_load(void *data, custom_command_method_t func) +unsigned video_thread_texture_handle(void *data, custom_command_method_t func) { thread_packet_t pkt; video_driver_state_t *video_st = video_state_get_ptr(); diff --git a/gfx/video_thread_wrapper.h b/gfx/video_thread_wrapper.h index 2c83be9b59..a8991961b4 100644 --- a/gfx/video_thread_wrapper.h +++ b/gfx/video_thread_wrapper.h @@ -61,7 +61,7 @@ enum thread_cmd CMD_POKE_SET_HDR_MAX_NITS, CMD_POKE_SET_HDR_PAPER_WHITE_NITS, CMD_POKE_SET_HDR_CONTRAST, - CMD_POKE_SET_HDR_EXPAND_GAMUT, + CMD_POKE_SET_HDR_EXPAND_GAMUT, CMD_DUMMY = INT_MAX }; @@ -270,7 +270,7 @@ bool video_thread_font_init( custom_font_command_method_t func, bool is_threaded); -unsigned video_thread_texture_load(void *data, +unsigned video_thread_texture_handle(void *data, custom_command_method_t func); RETRO_END_DECLS