More sprite-driven texture work in the render/video drivers. gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Sun, 17 Aug 2008 09:50:28 +0000
branchgsoc2008_nds
changeset 2695c04a266c277a
parent 2694 c1c7cb1b5a47
child 2696 0b395a60deff
More sprite-driven texture work in the render/video drivers.
src/video/nds/SDL_ndsrender.c
src/video/nds/SDL_ndsvideo.c
test/nds-test-progs/sprite2/Makefile
test/nds-test-progs/sprite2/source/testsprite2.c
     1.1 --- a/src/video/nds/SDL_ndsrender.c	Sat Aug 16 12:58:36 2008 +0000
     1.2 +++ b/src/video/nds/SDL_ndsrender.c	Sun Aug 17 09:50:28 2008 +0000
     1.3 @@ -330,6 +330,8 @@
     1.4          }
     1.5          if(whichspr >= 0) {
     1.6              SpriteEntry *sprent = &(data->oam_copy.spriteBuffer[whichspr]);
     1.7 +            int maxside = texture->w > texture->h ? texture->w : texture->h;
     1.8 +            int pitch;
     1.9  
    1.10              texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
    1.11              txdat = (NDS_TextureData*)texture->driverdata;
    1.12 @@ -349,12 +351,44 @@
    1.13                  sprent->rsMatrixIdx = whichspr;
    1.14              }
    1.15  
    1.16 +            /* containing shape (square or 2:1 rectangles) */
    1.17              sprent->objShape = OBJSHAPE_SQUARE;
    1.18              if(texture->w/2 >= texture->h) {
    1.19                  sprent->objShape = OBJSHAPE_WIDE;
    1.20              } else if(texture->h/2 >= texture->w) {
    1.21                  sprent->objShape = OBJSHAPE_TALL;
    1.22              }
    1.23 +
    1.24 +            /* size in pixels */
    1.25 +            /* FIXME: "pitch" is hardcoded for 2bytes per pixel. */
    1.26 +            sprent->objSize = OBJSIZE_64;
    1.27 +            pitch = 128;
    1.28 +            if(maxside <= 8) {
    1.29 +                sprent->objSize = OBJSIZE_8;
    1.30 +                pitch = 16;
    1.31 +            } else if(maxside <= 16) {
    1.32 +                sprent->objSize = OBJSIZE_16;
    1.33 +                pitch = 32;
    1.34 +            } else if(maxside <= 32) {
    1.35 +                sprent->objSize = OBJSIZE_32;
    1.36 +                pitch = 64;
    1.37 +            }
    1.38 +
    1.39 +            /* FIXME: this is hard-coded and will obviously only work for one
    1.40 +               sprite-texture.  tells it to look at the beginning of SPRITE_GFX
    1.41 +               for its pixels. */
    1.42 +            sprent->tileIdx = 0;
    1.43 +
    1.44 +            /* now for the texture data */
    1.45 +            txdat->type = NDSTX_SPR;
    1.46 +            txdat->hw_index = whichspr;
    1.47 +            txdat->dim.hdx = 0x100; txdat->dim.hdy = 0;
    1.48 +            txdat->dim.vdx = 0;     txdat->dim.vdy = 0x100;
    1.49 +            txdat->dim.pitch = pitch;
    1.50 +            txdat->dim.bpp = bpp;
    1.51 +            txdat->vram_pixels = (u16*)(data->sub ?
    1.52 +                SPRITE_GFX_SUB : SPRITE_GFX); /* FIXME: use tileIdx*boundary
    1.53 +                                                 to point to proper location */
    1.54          } else {
    1.55              SDL_SetError("Out of NDS sprites.");
    1.56          }
    1.57 @@ -374,9 +408,7 @@
    1.58                  return -1;
    1.59              }
    1.60  
    1.61 -            /* TODO: maybe this should be in RenderPresent or RenderCopy
    1.62 -               instead, copying from a malloc'd system RAM pixel buffer. */
    1.63 -            /* this is hard-coded to being 256x256 for now. */
    1.64 +            /* this is hard-coded to being 256x256 ABGR1555 for now. */
    1.65              data->bg->control[whichbg] = (bpp == 8) ?
    1.66                  BG_BMP8_256x256 : BG_BMP16_256x256;
    1.67  
    1.68 @@ -389,7 +421,7 @@
    1.69              txdat->hw_index = whichbg;
    1.70              txdat->dim.hdx = 0x100; txdat->dim.hdy = 0;
    1.71              txdat->dim.vdx = 0;     txdat->dim.vdy = 0x100;
    1.72 -            txdat->dim.pitch = texture->w * ((bpp+1)/8);
    1.73 +            txdat->dim.pitch = 512;
    1.74              txdat->dim.bpp = bpp;
    1.75              txdat->vram_pixels = (u16*)(data->sub ?
    1.76                  BG_BMP_RAM_SUB(base) : BG_BMP_RAM(base));
    1.77 @@ -538,7 +570,7 @@
    1.78          SpriteEntry *spr = &(data->oam_copy.spriteBuffer[txdat->hw_index]);
    1.79          spr->posX = dstrect->x;
    1.80          spr->posY = dstrect->y;
    1.81 -        if(txdat->hw_index < MATRIX_COUNT) {
    1.82 +        if(txdat->hw_index < MATRIX_COUNT && spr->isRotoscale) {
    1.83              SpriteRotation *sprot = &(data->oam_copy.matrixBuffer[txdat->hw_index]);
    1.84              sprot->hdx = txdat->dim.hdx;
    1.85              sprot->hdy = txdat->dim.hdy;
    1.86 @@ -573,9 +605,9 @@
    1.87  static void
    1.88  NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
    1.89  {
    1.90 +    NDS_TextureData *txdat = texture->driverdata;
    1.91      TRACE("+NDS_DestroyTexture\n");
    1.92      /* free anything else allocated for texture */
    1.93 -    NDS_TextureData *txdat = texture->driverdata;
    1.94      /*SDL_FreeDirtyRects(&txdat->dirty);*/
    1.95      SDL_free(txdat);
    1.96      TRACE("-NDS_DestroyTexture\n");
    1.97 @@ -585,8 +617,8 @@
    1.98  NDS_DestroyRenderer(SDL_Renderer * renderer)
    1.99  {
   1.100      NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   1.101 -    /*SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.102 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/
   1.103 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.104 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   1.105      int i;
   1.106  
   1.107      TRACE("+NDS_DestroyRenderer\n");
   1.108 @@ -623,8 +655,8 @@
   1.109  NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   1.110                       SDL_Color * colors, int firstcolor, int ncolors)
   1.111  {
   1.112 +    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   1.113      TRACE("+NDS_GetTexturePalette\n");
   1.114 -    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   1.115      TRACE("-NDS_GetTexturePalette\n");
   1.116      return 0;
   1.117  }
     2.1 --- a/src/video/nds/SDL_ndsvideo.c	Sat Aug 16 12:58:36 2008 +0000
     2.2 +++ b/src/video/nds/SDL_ndsvideo.c	Sun Aug 17 09:50:28 2008 +0000
     2.3 @@ -150,6 +150,8 @@
     2.4                   DISPLAY_BG3_ACTIVE |
     2.5                   DISPLAY_BG_EXT_PALETTE |
     2.6                   DISPLAY_SPR_1D_LAYOUT |
     2.7 +                 DISPLAY_SPR_1D_BMP |
     2.8 +                 DISPLAY_SPR_1D_BMP_SIZE_256 | /* try 128 if 256 is trouble. */
     2.9                   DISPLAY_SPR_ACTIVE |
    2.10                   DISPLAY_SPR_EXT_PALETTE); /* display on main core
    2.11                                                with lots of flags set for
     3.1 --- a/test/nds-test-progs/sprite2/Makefile	Sat Aug 16 12:58:36 2008 +0000
     3.2 +++ b/test/nds-test-progs/sprite2/Makefile	Sun Aug 17 09:50:28 2008 +0000
     3.3 @@ -119,7 +119,7 @@
     3.4  $(OUTPUT).elf	:	$(OFILES)
     3.5   
     3.6  #---------------------------------------------------------------------------------
     3.7 -%.pcx.o	:	%.pcx
     3.8 +%.bin.o	:	%.bin
     3.9  #---------------------------------------------------------------------------------
    3.10  	@echo $(notdir $<)
    3.11  	@$(bin2o)
     4.1 --- a/test/nds-test-progs/sprite2/source/testsprite2.c	Sat Aug 16 12:58:36 2008 +0000
     4.2 +++ b/test/nds-test-progs/sprite2/source/testsprite2.c	Sun Aug 17 09:50:28 2008 +0000
     4.3 @@ -7,6 +7,8 @@
     4.4  #include <fat.h>
     4.5  #include "common.h"
     4.6  
     4.7 +#include "icon_bmp_bin.h"
     4.8 +
     4.9  #define NUM_SPRITES	10
    4.10  #define MAX_SPEED 	1
    4.11  
    4.12 @@ -79,6 +81,24 @@
    4.13      return (0);
    4.14  }
    4.15  
    4.16 +int LoadSprite2(const u8* ptr, int size) {
    4.17 +    int i;
    4.18 +    SDL_Rect r = {0,0,32,32};
    4.19 +    for (i = 0; i < state->num_windows; ++i) {
    4.20 +        SDL_SelectRenderer(state->windows[i]);
    4.21 +        sprites[i] = SDL_CreateTexture(SDL_PIXELFORMAT_ABGR1555,
    4.22 +                                       SDL_TEXTUREACCESS_STATIC, r.w, r.h);
    4.23 +        if (!sprites[i]) {
    4.24 +            fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
    4.25 +            return -1;
    4.26 +        }
    4.27 +        SDL_UpdateTexture(sprites[i], &r, ptr, r.w*2);
    4.28 +        SDL_SetTextureBlendMode(sprites[i], blendMode);
    4.29 +        SDL_SetTextureScaleMode(sprites[i], scaleMode);
    4.30 +    }
    4.31 +    return 0;
    4.32 +}
    4.33 +
    4.34  void
    4.35  MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
    4.36  {
    4.37 @@ -236,7 +256,8 @@
    4.38          SDL_SelectRenderer(state->windows[i]);
    4.39          SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
    4.40      }
    4.41 -    if (LoadSprite("icon.bmp") < 0) {
    4.42 +    if (LoadSprite2(icon_bmp_bin, icon_bmp_bin_size) < 0) {
    4.43 +        printf("errored.\n");
    4.44          quit(2);
    4.45      }
    4.46