Some small bug fixes and more work on video gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Fri, 25 Jul 2008 23:39:14 +0000
branchgsoc2008_nds
changeset 2681c15b6c758be5
parent 2680 4135aa9c5645
child 2682 f7594fc66bda
Some small bug fixes and more work on video
src/video/nds/SDL_ndsrender.c
src/video/nds/SDL_ndsvideo.c
     1.1 --- a/src/video/nds/SDL_ndsrender.c	Sat Jul 19 17:37:19 2008 +0000
     1.2 +++ b/src/video/nds/SDL_ndsrender.c	Fri Jul 25 23:39:14 2008 +0000
     1.3 @@ -87,8 +87,8 @@
     1.4          3, /* u32 num_texture_formats */
     1.5          {
     1.6              SDL_PIXELFORMAT_INDEX8,
     1.7 -            SDL_PIXELFORMAT_RGB555,
     1.8 -            SDL_PIXELFORMAT_RGB565
     1.9 +            SDL_PIXELFORMAT_ABGR1555,
    1.10 +            SDL_PIXELFORMAT_BGR555,
    1.11          }, /* u32 texture_formats[20] */
    1.12          (256), /* int max_texture_width */
    1.13          (256), /* int max_texture_height */
    1.14 @@ -100,6 +100,7 @@
    1.15      bg_attribute *bg;
    1.16      u8 bg_taken[4];
    1.17      int sub;
    1.18 +    SDL_DirtyRectList dirty;
    1.19  } NDS_RenderData;
    1.20  
    1.21  typedef struct
    1.22 @@ -437,6 +438,10 @@
    1.23      } else {
    1.24          NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
    1.25  
    1.26 +        if (markDirty) {
    1.27 +            SDL_AddDirtyRect(&txdat->dirty, rect);
    1.28 +        }
    1.29 +
    1.30          *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch
    1.31                              + rect->x * (txdat->dim.bpp/8));
    1.32          *pitch = txdat->dim.pitch;
    1.33 @@ -488,30 +493,34 @@
    1.34                     const SDL_Rect * srcrect, const SDL_Rect * dstrect)
    1.35  {
    1.36      NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
    1.37 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
    1.38 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    1.39 +    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
    1.40 +//    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
    1.41 +//    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    1.42  
    1.43  printf("+NDS_RenderCopy\n");
    1.44 -#if 0
    1.45 -    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
    1.46 -        SDL_Surface *target = data->screens[data->current_screen];
    1.47 -        void *pixels =
    1.48 -            (Uint8 *) target->pixels + dstrect->y * target->pitch +
    1.49 -            dstrect->x * target->format->BytesPerPixel;
    1.50 -        return SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata,
    1.51 -                                   srcrect, display->current_mode.format,
    1.52 -                                   dstrect->w, dstrect->h, pixels,
    1.53 -                                   target->pitch);
    1.54 -    } else {
    1.55 -        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
    1.56 -        SDL_Surface *target = data->screens[data->current_screen];
    1.57 -        SDL_Rect real_srcrect = *srcrect;
    1.58 -        SDL_Rect real_dstrect = *dstrect;
    1.59 -        return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
    1.60 +
    1.61 +    if (txdat->dirty.list) {
    1.62 +        SDL_DirtyRect *dirty;
    1.63 +        void *pixels;
    1.64 +        int bpp = SDL_BYTESPERPIXEL(texture->format);
    1.65 +        int pitch = txdat->pitch;
    1.66 +/* below was borrowed from SDL_renderer_gl.c.  doesn't work, obv.
    1.67 +   figure out how to get the graphics data into VRAM. */
    1.68 +
    1.69 +        for (dirty = txdat->dirty.list; dirty; dirty = dirty->next) {
    1.70 +            SDL_Rect *rect = &dirty->rect;
    1.71 +            /*pixels =
    1.72 +                (void *) ((Uint8 *) txdat->vram + rect->y * pitch +
    1.73 +                          rect->x * bpp);
    1.74 +            data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
    1.75 +                                  rect->w, rect->h, texturedata->format,
    1.76 +                                  texturedata->formattype, pixels);*/
    1.77 +        }
    1.78 +        SDL_ClearDirtyRects(&txdat->dirty);
    1.79      }
    1.80 -#endif
    1.81 +
    1.82  printf("-NDS_RenderCopy\n");
    1.83 -    return 0;
    1.84 +    return status;
    1.85  }
    1.86  
    1.87  
    1.88 @@ -537,7 +546,9 @@
    1.89          SDL_SetError("Unsupported texture format");
    1.90      } else {
    1.91          /* free anything else allocated for texture */
    1.92 -        SDL_free(texture->driverdata);
    1.93 +        NDS_TextureData *txdat = texture->driverdata;
    1.94 +        SDL_FreeDirtyRects(&txdat->dirty);
    1.95 +        SDL_free(txdat);
    1.96      }
    1.97  printf("-NDS_DestroyTexture\n");
    1.98  }
     2.1 --- a/src/video/nds/SDL_ndsvideo.c	Sat Jul 19 17:37:19 2008 +0000
     2.2 +++ b/src/video/nds/SDL_ndsvideo.c	Fri Jul 25 23:39:14 2008 +0000
     2.3 @@ -198,10 +198,12 @@
     2.4  {
     2.5  printf("+NDS_SetDisplayMode\n");
     2.6      /* right now this function is just hard-coded for 256x192 ABGR1555 */
     2.7 -    videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);       /* display on main core */
     2.8 -    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub */
     2.9 +    videoSetMode(MODE_5_2D |
    2.10 +        DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE
    2.11 +        DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE); /* display on main core */
    2.12 +    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */
    2.13      vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000,
    2.14 -                     VRAM_C_SUB_BG_0x06200000,  VRAM_C_SUB_BG_0x06220000);
    2.15 +                     VRAM_C_SUB_BG_0x06200000,  VRAM_D_SUB_BG_0x06220000);
    2.16      vramSetBankE(VRAM_E_MAIN_SPRITE);
    2.17      /* set up console for debug text 'n stuff */
    2.18      SUB_BG0_CR = BG_MAP_BASE(31);