We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2424 - Software rendering fails when colorkey is enabled and alpha/color modulation modified
Summary: Software rendering fails when colorkey is enabled and alpha/color modulation ...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: 2.0.1
Hardware: x86_64 Windows 7
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-01 13:09 UTC by Roberto Prieto
Modified: 2014-07-08 04:38 UTC (History)
0 users

See Also:


Attachments
Small application showing the issue (23.94 KB, application/x-rar-compressed)
2014-03-01 13:09 UTC, Roberto Prieto
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Roberto Prieto 2014-03-01 13:09:08 UTC
Created attachment 1582 [details]
Small application showing the issue

Hi,

Im sharing the same texture among different objects(tiles, sprites, etc.) and each object has its own alpha modulation and color modulation which is set before calling SDL_RenderCopy(). The colorkey is only set on the parent object and the children can not modify it, just alpha and color modulations.

If I follow this sequence:

1) Create a Surface
2) Set the colorkey on the Surface
3) Create a Texture from that Surface 
4a) Now, modify the alpha or color mod. before the first RenderCopy(): it works!
4b) But if I modify the alpha or color mod. after the first RenderCopy(): it fails and no render output

Im using SDL 2.0.2 8147 and only fails on software mode when the texture is SDL_TEXTUREACCESS_STATIC, other modes (software with streaming textures, Direct3D or OpenGL drivers) work fine.

I was investigating why it fails and whatever I found is that on step 3), SW_CreateTexture() is called and has this condition:
if (texture->access == SDL_TEXTUREACCESS_STATIC) {
        SDL_SetSurfaceRLE(texture->driverdata, 1);
    }
So I suspected that this issue was related to the RLE encoding.
Further more, in SDL_RLESurface() where the surface is RLE encoded there is a check:
/* Pass on combinations not supported */
    if ((flags & SDL_COPY_MODULATE_COLOR) ||
        ((flags & SDL_COPY_MODULATE_ALPHA) && surface->format->Amask) ||
        (flags & (SDL_COPY_ADD | SDL_COPY_MOD)) ||
        (flags & SDL_COPY_NEAREST)) {
        return -1;
    }
so when I use alpha/color modulations, the RLE enconding will no be used which is fine.

Following the code, in case 4a) I understand why is working: the calls to SDL_RLESurface() dont pass the check as alpha/color modulations are in use and the surface is never RLE encoded.

However, in case 4b), I follow the code and in the first RenderCopy() without alpha/color modulations, it does the RLE encoding and after modifying the alpha/color modulations and calling again to RenderCopy(), the code detects this change and does some RLE tasks but I wasnt able to detect exactly where the issue is.

I attach a small code in order to check the issue. If you need further information, please let me know.

Cheers
Roberto
Comment 1 Roberto Prieto 2014-07-04 17:46:50 UTC
Hi,

I checked again if the bug is still there with latest SDL 2.0.3 code snapshot from Mercurial and the issue is not there anymore :).

So it was fixed.

Thanks!
Roberto
Comment 2 Sam Lantinga 2014-07-08 04:38:34 UTC
Thanks!