From 7c0307060d79d2b45cfb1b34623ca5cfd1a44f37 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 16 Jul 2024 18:00:20 -0700 Subject: [PATCH] Textures with alpha format default to SDL_BLENDMODE_BLEND Fixes https://github.com/libsdl-org/SDL/issues/9941 --- docs/README-migration.md | 2 ++ src/render/SDL_render.c | 1 + test/testautomation_render.c | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/docs/README-migration.md b/docs/README-migration.md index 91e8376e7..97f1f255a 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -1265,6 +1265,8 @@ SDL_CreateWindowAndRenderer() now takes the window title as the first parameter. SDL_GetRendererInfo() has been removed. The name of a renderer can be retrieved using SDL_GetRendererName(), and the other information is available as properties on the renderer. +Textures are created with SDL_SCALEMODE_LINEAR by default, and use SDL_BLENDMODE_BLEND by default if they are created with a format that has an alpha channel. + SDL_QueryTexture() has been removed. The properties of the texture can be queried using SDL_PROP_TEXTURE_FORMAT_NUMBER, SDL_PROP_TEXTURE_ACCESS_NUMBER, SDL_PROP_TEXTURE_WIDTH_NUMBER, and SDL_PROP_TEXTURE_HEIGHT_NUMBER. A function SDL_GetTextureSize() has been added to get the size of the texture as floating point values. Mouse and touch events are no longer filtered to change their coordinates, instead you diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 64128c79c..ed049a5d1 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -1355,6 +1355,7 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert texture->color.g = 1.0f; texture->color.b = 1.0f; texture->color.a = 1.0f; + texture->blendMode = SDL_ISPIXELFORMAT_ALPHA(format) ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE; texture->scaleMode = SDL_SCALEMODE_LINEAR; texture->view.pixel_w = w; texture->view.pixel_h = h; diff --git a/test/testautomation_render.c b/test/testautomation_render.c index e867f8389..aebdb32a0 100644 --- a/test/testautomation_render.c +++ b/test/testautomation_render.c @@ -401,6 +401,12 @@ static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFo if (dst == NULL) { return; } + if (SDL_ISPIXELFORMAT_ALPHA(dst_format)) { + SDL_BlendMode blendMode = SDL_BLENDMODE_NONE; + ret = SDL_GetTextureBlendMode(dst, &blendMode); + SDLTest_AssertCheck(ret == 0, "Verify result from SDL_GetTextureBlendMode(), expected: 0, got: %i", ret); + SDLTest_AssertCheck(blendMode == SDL_BLENDMODE_BLEND, "Verify alpha texture blend mode, expected %d, got %" SDL_PRIu32, SDL_BLENDMODE_BLEND, blendMode); + } /* Set as render target */ SDL_SetRenderTarget(renderer, dst);