Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed bug 4929 - Software renderer produces bugs when optimizations a…
…re turned on with Visual C++ 2019

Konrad

I took the liberty of rewriting this function a bit as it seemed to be unnecessary extended with ifs regarding flags (we can check everything in one pass which seem to be the thing which confuses Visual C++ 2019 as well).

Also, I have made CPU features an int instead of uint because if we check it against flags which are all ints it might as well just be int (no signed/unsigned bitwise comparison).
  • Loading branch information
slouken committed Jan 16, 2020
1 parent c6817a2 commit 572f4a8
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions src/video/SDL_blit.c
Expand Up @@ -128,11 +128,11 @@ static SDL_BlitFunc
SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags,
SDL_BlitFuncEntry * entries)
{
int i, flagcheck;
static Uint32 features = 0xffffffff;
int i, flagcheck = (flags & (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL | SDL_COPY_COLORKEY | SDL_COPY_NEAREST));
static int features = 0x7fffffff;

/* Get the available CPU features */
if (features == 0xffffffff) {
if (features == 0x7fffffff) {
const char *override = SDL_getenv("SDL_BLIT_CPU_FEATURES");

features = SDL_CPU_ANY;
Expand Down Expand Up @@ -172,36 +172,13 @@ SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags,
continue;
}

/* Check modulation flags */
flagcheck =
(flags & (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA));
if ((flagcheck & entries[i].flags) != flagcheck) {
continue;
}

/* Check blend flags */
flagcheck =
(flags &
(SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL));
if ((flagcheck & entries[i].flags) != flagcheck) {
continue;
}

/* Check colorkey flag */
flagcheck = (flags & SDL_COPY_COLORKEY);
if ((flagcheck & entries[i].flags) != flagcheck) {
continue;
}

/* Check scaling flags */
flagcheck = (flags & SDL_COPY_NEAREST);
/* Check flags */
if ((flagcheck & entries[i].flags) != flagcheck) {
continue;
}

/* Check CPU features */
flagcheck = entries[i].cpu;
if ((flagcheck & features) != flagcheck) {
if ((entries[i].cpu & features) != entries[i].cpu) {
continue;
}

Expand Down

0 comments on commit 572f4a8

Please sign in to comment.