Implemented scaling in the D3D renderer
authorSam Lantinga <slouken@libsdl.org>
Wed, 19 Jul 2006 05:45:42 +0000
changeset 19173f54b3ec5a07
parent 1916 c773b0c0ac89
child 1918 092bd3a019c5
Implemented scaling in the D3D renderer
src/video/win32/SDL_d3drender.c
test/testsprite2.c
     1.1 --- a/src/video/win32/SDL_d3drender.c	Wed Jul 19 05:03:21 2006 +0000
     1.2 +++ b/src/video/win32/SDL_d3drender.c	Wed Jul 19 05:45:42 2006 +0000
     1.3 @@ -653,6 +653,28 @@
     1.4          break;
     1.5      }
     1.6  
     1.7 +    switch (scaleMode) {
     1.8 +    case SDL_TextureScaleMode_None:
     1.9 +    case SDL_TextureScaleMode_Fast:
    1.10 +        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
    1.11 +                                         D3DTEXF_POINT);
    1.12 +        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
    1.13 +                                         D3DTEXF_POINT);
    1.14 +        break;
    1.15 +    case SDL_TextureScaleMode_Slow:
    1.16 +        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
    1.17 +                                         D3DTEXF_LINEAR);
    1.18 +        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
    1.19 +                                         D3DTEXF_LINEAR);
    1.20 +        break;
    1.21 +    case SDL_TextureScaleMode_Best:
    1.22 +        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
    1.23 +                                         D3DTEXF_GAUSSIANQUAD);
    1.24 +        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
    1.25 +                                         D3DTEXF_GAUSSIANQUAD);
    1.26 +        break;
    1.27 +    }
    1.28 +
    1.29      result =
    1.30          IDirect3DDevice9_SetTexture(data->device, 0,
    1.31                                      (IDirect3DBaseTexture9 *) texturedata->
     2.1 --- a/test/testsprite2.c	Wed Jul 19 05:03:21 2006 +0000
     2.2 +++ b/test/testsprite2.c	Wed Jul 19 05:45:42 2006 +0000
     2.3 @@ -17,6 +17,7 @@
     2.4  static SDL_Rect *velocities;
     2.5  static int sprite_w, sprite_h;
     2.6  static SDL_TextureBlendMode blendMode = SDL_TextureBlendMode_Mask;
     2.7 +static SDL_TextureScaleMode scaleMode = SDL_TextureScaleMode_None;
     2.8  
     2.9  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    2.10  static void
    2.11 @@ -87,12 +88,6 @@
    2.12      /* Move the sprite, bounce at the wall, and draw */
    2.13      n = 0;
    2.14      SDL_RenderFill(NULL, BACKGROUND);
    2.15 -    /*
    2.16 -       for (i = 0; i < num_sprites; ++i) {
    2.17 -       position = &positions[i];
    2.18 -       SDL_RenderFill(position, BACKGROUND);
    2.19 -       }
    2.20 -     */
    2.21      for (i = 0; i < num_sprites; ++i) {
    2.22          position = &positions[i];
    2.23          velocity = &velocities[i];
    2.24 @@ -108,8 +103,7 @@
    2.25          }
    2.26  
    2.27          /* Blit the sprite onto the screen */
    2.28 -        SDL_RenderCopy(sprite, NULL, position, blendMode,
    2.29 -                       SDL_TextureScaleMode_None);
    2.30 +        SDL_RenderCopy(sprite, NULL, position, blendMode, scaleMode);
    2.31      }
    2.32  
    2.33      /* Update the screen! */
    2.34 @@ -142,6 +136,9 @@
    2.35                      if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
    2.36                          blendMode = SDL_TextureBlendMode_None;
    2.37                          consumed = 2;
    2.38 +                    } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) {
    2.39 +                        blendMode = SDL_TextureBlendMode_Mask;
    2.40 +                        consumed = 2;
    2.41                      } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
    2.42                          blendMode = SDL_TextureBlendMode_Blend;
    2.43                          consumed = 2;
    2.44 @@ -153,13 +150,30 @@
    2.45                          consumed = 2;
    2.46                      }
    2.47                  }
    2.48 +            } else if (SDL_strcasecmp(argv[i], "--scale") == 0) {
    2.49 +                if (argv[i + 1]) {
    2.50 +                    if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
    2.51 +                        scaleMode = SDL_TextureScaleMode_None;
    2.52 +                        consumed = 2;
    2.53 +                    } else if (SDL_strcasecmp(argv[i + 1], "fast") == 0) {
    2.54 +                        scaleMode = SDL_TextureScaleMode_Fast;
    2.55 +                        consumed = 2;
    2.56 +                    } else if (SDL_strcasecmp(argv[i + 1], "slow") == 0) {
    2.57 +                        scaleMode = SDL_TextureScaleMode_Slow;
    2.58 +                        consumed = 2;
    2.59 +                    } else if (SDL_strcasecmp(argv[i + 1], "best") == 0) {
    2.60 +                        scaleMode = SDL_TextureScaleMode_Best;
    2.61 +                        consumed = 2;
    2.62 +                    }
    2.63 +                }
    2.64              } else if (SDL_isdigit(*argv[i])) {
    2.65                  num_sprites = SDL_atoi(argv[i]);
    2.66                  consumed = 1;
    2.67              }
    2.68          }
    2.69          if (consumed < 0) {
    2.70 -            fprintf(stderr, "Usage: %s %s [--blend none|blend|add|mod]",
    2.71 +            fprintf(stderr,
    2.72 +                    "Usage: %s %s [--blend none|mask|blend|add|mod] [--scale none|fast|slow|best]",
    2.73                      argv[0], CommonUsage(state));
    2.74              quit(1);
    2.75          }
    2.76 @@ -192,6 +206,10 @@
    2.77          quit(2);
    2.78      }
    2.79      srand(time(NULL));
    2.80 +    if (scaleMode != SDL_TextureScaleMode_None) {
    2.81 +        sprite_w += sprite_w / 2;
    2.82 +        sprite_h += sprite_h / 2;
    2.83 +    }
    2.84      for (i = 0; i < num_sprites; ++i) {
    2.85          positions[i].x = rand() % (state->window_w - sprite_w);
    2.86          positions[i].y = rand() % (state->window_h - sprite_h);