Implemented blend modes in the D3D renderer
authorSam Lantinga <slouken@libsdl.org>
Wed, 19 Jul 2006 05:03:21 +0000
changeset 1916c773b0c0ac89
parent 1915 a228436a2404
child 1917 3f54b3ec5a07
Implemented blend modes in the D3D renderer
src/stdlib/SDL_string.c
src/video/win32/SDL_d3drender.c
test/common.c
test/testgl2.c
test/testsprite2.c
     1.1 --- a/src/stdlib/SDL_string.c	Wed Jul 19 04:24:41 2006 +0000
     1.2 +++ b/src/stdlib/SDL_string.c	Wed Jul 19 05:03:21 2006 +0000
     1.3 @@ -750,6 +750,8 @@
     1.4          ++str1;
     1.5          ++str2;
     1.6      }
     1.7 +    a = SDL_tolower(*str1);
     1.8 +    b = SDL_tolower(*str2);
     1.9      return (int) ((unsigned char) a - (unsigned char) b);
    1.10  }
    1.11  #endif
    1.12 @@ -769,6 +771,8 @@
    1.13          ++str2;
    1.14          --maxlen;
    1.15      }
    1.16 +    a = SDL_tolower(*str1);
    1.17 +    b = SDL_tolower(*str2);
    1.18      return (int) ((unsigned char) a - (unsigned char) b);
    1.19  }
    1.20  #endif
     2.1 --- a/src/video/win32/SDL_d3drender.c	Wed Jul 19 04:24:41 2006 +0000
     2.2 +++ b/src/video/win32/SDL_d3drender.c	Wed Jul 19 05:03:21 2006 +0000
     2.3 @@ -359,12 +359,6 @@
     2.4      IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
     2.5                                      D3DCULL_NONE);
     2.6      IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
     2.7 -    IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
     2.8 -                                    TRUE);
     2.9 -    IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
    2.10 -                                    D3DBLEND_SRCALPHA);
    2.11 -    IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
    2.12 -                                    D3DBLEND_INVSRCALPHA);
    2.13  
    2.14      return renderer;
    2.15  }
    2.16 @@ -627,6 +621,38 @@
    2.17      vertices[3].u = minu;
    2.18      vertices[3].v = maxv;
    2.19  
    2.20 +    switch (blendMode) {
    2.21 +    case SDL_TextureBlendMode_None:
    2.22 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
    2.23 +                                        FALSE);
    2.24 +        break;
    2.25 +    case SDL_TextureBlendMode_Mask:
    2.26 +    case SDL_TextureBlendMode_Blend:
    2.27 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
    2.28 +                                        TRUE);
    2.29 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
    2.30 +                                        D3DBLEND_SRCALPHA);
    2.31 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
    2.32 +                                        D3DBLEND_INVSRCALPHA);
    2.33 +        break;
    2.34 +    case SDL_TextureBlendMode_Add:
    2.35 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
    2.36 +                                        TRUE);
    2.37 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
    2.38 +                                        D3DBLEND_SRCALPHA);
    2.39 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
    2.40 +                                        D3DBLEND_ONE);
    2.41 +        break;
    2.42 +    case SDL_TextureBlendMode_Mod:
    2.43 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
    2.44 +                                        TRUE);
    2.45 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
    2.46 +                                        D3DBLEND_ZERO);
    2.47 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
    2.48 +                                        D3DBLEND_SRCCOLOR);
    2.49 +        break;
    2.50 +    }
    2.51 +
    2.52      result =
    2.53          IDirect3DDevice9_SetTexture(data->device, 0,
    2.54                                      (IDirect3DBaseTexture9 *) texturedata->
     3.1 --- a/test/common.c	Wed Jul 19 04:24:41 2006 +0000
     3.2 +++ b/test/common.c	Wed Jul 19 05:03:21 2006 +0000
     3.3 @@ -105,7 +105,7 @@
     3.4      }
     3.5      if (SDL_strcasecmp(argv[index], "--windows") == 0) {
     3.6          ++index;
     3.7 -        if (!argv[index] || !isdigit(*argv[index])) {
     3.8 +        if (!argv[index] || !SDL_isdigit(*argv[index])) {
     3.9              return -1;
    3.10          }
    3.11          if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
     4.1 --- a/test/testgl2.c	Wed Jul 19 04:24:41 2006 +0000
     4.2 +++ b/test/testgl2.c	Wed Jul 19 05:03:21 2006 +0000
     4.3 @@ -193,7 +193,7 @@
     4.4              }
     4.5          }
     4.6          if (consumed < 0) {
     4.7 -            fprintf(stderr, "Usage: %s [--fsaa] [--accel] %s", argv[0],
     4.8 +            fprintf(stderr, "Usage: %s %s [--fsaa] [--accel]", argv[0],
     4.9                      CommonUsage(state));
    4.10              quit(1);
    4.11          }
     5.1 --- a/test/testsprite2.c	Wed Jul 19 04:24:41 2006 +0000
     5.2 +++ b/test/testsprite2.c	Wed Jul 19 05:03:21 2006 +0000
     5.3 @@ -8,7 +8,7 @@
     5.4  
     5.5  #define NUM_SPRITES	100
     5.6  #define MAX_SPEED 	1
     5.7 -#define BACKGROUND  0x00FFFFFF
     5.8 +#define BACKGROUND  0x00A0A0A0
     5.9  
    5.10  static CommonState *state;
    5.11  static int num_sprites;
    5.12 @@ -16,6 +16,7 @@
    5.13  static SDL_Rect *positions;
    5.14  static SDL_Rect *velocities;
    5.15  static int sprite_w, sprite_h;
    5.16 +static SDL_TextureBlendMode blendMode = SDL_TextureBlendMode_Mask;
    5.17  
    5.18  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    5.19  static void
    5.20 @@ -107,7 +108,7 @@
    5.21          }
    5.22  
    5.23          /* Blit the sprite onto the screen */
    5.24 -        SDL_RenderCopy(sprite, NULL, position, SDL_TextureBlendMode_Mask,
    5.25 +        SDL_RenderCopy(sprite, NULL, position, blendMode,
    5.26                         SDL_TextureScaleMode_None);
    5.27      }
    5.28  
    5.29 @@ -135,11 +136,31 @@
    5.30  
    5.31          consumed = CommonArg(state, i);
    5.32          if (consumed == 0) {
    5.33 -            num_sprites = SDL_atoi(argv[i]);
    5.34 -            consumed = 1;
    5.35 +            consumed = -1;
    5.36 +            if (SDL_strcasecmp(argv[i], "--blend") == 0) {
    5.37 +                if (argv[i + 1]) {
    5.38 +                    if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
    5.39 +                        blendMode = SDL_TextureBlendMode_None;
    5.40 +                        consumed = 2;
    5.41 +                    } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
    5.42 +                        blendMode = SDL_TextureBlendMode_Blend;
    5.43 +                        consumed = 2;
    5.44 +                    } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
    5.45 +                        blendMode = SDL_TextureBlendMode_Add;
    5.46 +                        consumed = 2;
    5.47 +                    } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
    5.48 +                        blendMode = SDL_TextureBlendMode_Mod;
    5.49 +                        consumed = 2;
    5.50 +                    }
    5.51 +                }
    5.52 +            } else if (SDL_isdigit(*argv[i])) {
    5.53 +                num_sprites = SDL_atoi(argv[i]);
    5.54 +                consumed = 1;
    5.55 +            }
    5.56          }
    5.57          if (consumed < 0) {
    5.58 -            fprintf(stderr, "Usage: %s %s", argv[0], CommonUsage(state));
    5.59 +            fprintf(stderr, "Usage: %s %s [--blend none|blend|add|mod]",
    5.60 +                    argv[0], CommonUsage(state));
    5.61              quit(1);
    5.62          }
    5.63          i += consumed;