From e87c7940f59db12670089a4ed79c91dfbca92b33 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 13 Apr 2021 14:42:38 +0200 Subject: [PATCH] Fixed bug 3829 - Don't FOURCC format for target textures FOURCC isn't supported by renderer back-ends for target access So use a correct format and fallback to with native/yuv path --- src/render/SDL_render.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 0c6388f22..8288b0f3c 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -1086,6 +1086,7 @@ SDL_Texture * SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int h) { SDL_Texture *texture; + SDL_bool texture_is_fourcc_and_target; CHECK_RENDERER_MAGIC(renderer, NULL); @@ -1131,15 +1132,24 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int } renderer->textures = texture; - if (IsSupportedFormat(renderer, format)) { + /* FOURCC format cannot be used directly by renderer back-ends for target texture */ + texture_is_fourcc_and_target = (access == SDL_TEXTUREACCESS_TARGET && SDL_ISPIXELFORMAT_FOURCC(texture->format)); + + if (texture_is_fourcc_and_target == SDL_FALSE && IsSupportedFormat(renderer, format)) { if (renderer->CreateTexture(renderer, texture) < 0) { SDL_DestroyTexture(texture); return NULL; } } else { - texture->native = SDL_CreateTexture(renderer, - GetClosestSupportedFormat(renderer, format), - access, w, h); + int closest_format; + + if (texture_is_fourcc_and_target == SDL_FALSE) { + closest_format = GetClosestSupportedFormat(renderer, format); + } else { + closest_format = renderer->info.texture_formats[0]; + } + + texture->native = SDL_CreateTexture(renderer, closest_format, access, w, h); if (!texture->native) { SDL_DestroyTexture(texture); return NULL;