src/video/nds/SDL_ndsrender.c
author Darren Alton <dalton@stevens.edu>
Sat, 26 Jul 2008 05:52:59 +0000
branchgsoc2008_nds
changeset 2682 f7594fc66bda
parent 2681 c15b6c758be5
child 2683 e858ac8868b6
permissions -rw-r--r--
Some debug work on the video driver, shows an error in the BG's vertical placement
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 #include <stdio.h>
    24 #include <stdlib.h>
    25 #include <nds.h>
    26 
    27 #include "SDL_config.h"
    28 
    29 #include "SDL_video.h"
    30 #include "../SDL_sysvideo.h"
    31 #include "../SDL_yuv_sw_c.h"
    32 #include "../SDL_renderer_sw.h"
    33 
    34 
    35 /* SDL surface based renderer implementation */
    36 
    37 static SDL_Renderer *NDS_CreateRenderer(SDL_Window * window, Uint32 flags);
    38 static int NDS_ActivateRenderer(SDL_Renderer * renderer);
    39 static int NDS_DisplayModeChanged(SDL_Renderer * renderer);
    40 static int NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    41 static int NDS_QueryTexturePixels(SDL_Renderer * renderer,
    42                                  SDL_Texture * texture, void **pixels,
    43                                  int *pitch);
    44 static int NDS_SetTexturePalette(SDL_Renderer * renderer,
    45                                 SDL_Texture * texture,
    46                                 const SDL_Color * colors, int firstcolor,
    47                                 int ncolors);
    48 static int NDS_GetTexturePalette(SDL_Renderer * renderer,
    49                                 SDL_Texture * texture, SDL_Color * colors,
    50                                 int firstcolor, int ncolors);
    51 static int NDS_SetTextureColorMod(SDL_Renderer * renderer,
    52                                  SDL_Texture * texture);
    53 static int NDS_SetTextureAlphaMod(SDL_Renderer * renderer,
    54                                  SDL_Texture * texture);
    55 static int NDS_SetTextureBlendMode(SDL_Renderer * renderer,
    56                                   SDL_Texture * texture);
    57 static int NDS_SetTextureScaleMode(SDL_Renderer * renderer,
    58                                   SDL_Texture * texture);
    59 static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    60                             const SDL_Rect * rect, const void *pixels,
    61                             int pitch);
    62 static int NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    63                           const SDL_Rect * rect, int markDirty, void **pixels,
    64                           int *pitch);
    65 static void NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    66 static void NDS_DirtyTexture(SDL_Renderer * renderer,
    67                             SDL_Texture * texture, int numrects,
    68                             const SDL_Rect * rects);
    69 static int NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
    70                               Uint8 b, Uint8 a, const SDL_Rect * rect);
    71 static int NDS_RenderCopy(SDL_Renderer * renderer,
    72                               SDL_Texture * texture,
    73                               const SDL_Rect * srcrect,
    74                               const SDL_Rect * dstrect);
    75 static void NDS_RenderPresent(SDL_Renderer * renderer);
    76 static void NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    77 static void NDS_DestroyRenderer(SDL_Renderer * renderer);
    78 
    79 
    80 SDL_RenderDriver NDS_RenderDriver = {
    81     NDS_CreateRenderer,
    82     {   "nds", /* char* name */
    83         (SDL_RENDERER_SINGLEBUFFER|SDL_RENDERER_ACCELERATED), /* u32 flags */
    84         (SDL_TEXTUREMODULATE_NONE), /* u32 mod_modes */
    85         (SDL_TEXTUREBLENDMODE_NONE), /* u32 blend_modes */
    86         (SDL_TEXTURESCALEMODE_NONE), /* u32 scale_modes */
    87         3, /* u32 num_texture_formats */
    88         {
    89             SDL_PIXELFORMAT_INDEX8,
    90             SDL_PIXELFORMAT_ABGR1555,
    91             SDL_PIXELFORMAT_BGR555,
    92         }, /* u32 texture_formats[20] */
    93         (256), /* int max_texture_width */
    94         (256), /* int max_texture_height */
    95     }
    96 };
    97 
    98 typedef struct
    99 {
   100     bg_attribute *bg;
   101     u8 bg_taken[4];
   102     int sub;
   103 } NDS_RenderData;
   104 
   105 typedef struct
   106 {
   107     enum { NDSTX_BG, NDSTX_SPR } type;
   108     int hw_index;
   109     struct { int w, h, pitch, bpp; } dim;
   110     u16 *vram;
   111 } NDS_TextureData;
   112 
   113 
   114 /* this is mainly hackish testing/debugging stuff to get cleaned up soon
   115    anything named sdlds_blah shouldn't make it into the stable version
   116  */
   117 
   118 u16
   119 sdlds_rgb2bgr(u16 c)
   120 {
   121 /* hack to get the proper colors until I actually get BGR555 to work right */
   122     u16 Rmask = 0x7C00, Bmask = 0x001F, GAmask = 0x83E0, r, b;
   123     r = (c & Rmask) >> 10;
   124     b = (c & Bmask) << 10;
   125     return (c & GAmask) | r | b;
   126 }
   127 
   128 void
   129 sdlds_print_pixfmt_info(SDL_PixelFormat * f)
   130 {
   131     if (!f)
   132         return;
   133     printf("bpp: %d\nRGBA: %x %x %x %x\n",
   134            f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
   135 }
   136 
   137 void
   138 sdlds_print_surface_info(SDL_Surface * s)
   139 {
   140     if (!s)
   141         return;
   142     printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n",
   143            s->flags, s->w, s->h, s->pitch, s->locked, s->refcount);
   144     sdlds_print_pixfmt_info(s->format);
   145 }
   146 
   147 /* again the above shouldn't make it into the stable version */
   148 
   149 SDL_Renderer *
   150 NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
   151 {
   152     SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   153     SDL_DisplayMode *displayMode = &display->current_mode;
   154     SDL_Renderer *renderer;
   155     NDS_RenderData *data;
   156     int i, n;
   157     int bpp = 15;
   158     Uint32 Rmask, Gmask, Bmask, Amask;
   159 /*  Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
   160     Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000;
   161 */
   162 printf("+NDS_CreateRenderer\n");
   163 
   164     /* hard coded this to BGR555 for now */
   165     if (!SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_BGR555, &bpp,
   166                                     &Rmask, &Gmask, &Bmask, &Amask)) {
   167         SDL_SetError("Unknown display format");
   168         return NULL;
   169     }
   170 
   171     renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   172     if (!renderer) {
   173         SDL_OutOfMemory();
   174         return NULL;
   175     }
   176 
   177     data = (NDS_RenderData *) SDL_malloc(sizeof(*data));
   178     if (!data) {
   179         NDS_DestroyRenderer(renderer);
   180         SDL_OutOfMemory();
   181         return NULL;
   182     }
   183     SDL_zerop(data);
   184 
   185     renderer->RenderFill = NDS_RenderFill;
   186     renderer->RenderCopy = NDS_RenderCopy;
   187     renderer->RenderPresent = NDS_RenderPresent;
   188     renderer->DestroyRenderer = NDS_DestroyRenderer;
   189     renderer->info.name = NDS_RenderDriver.info.name;
   190     renderer->info.flags = 0;
   191     renderer->window = window->id;
   192     renderer->driverdata = data;
   193     renderer->CreateTexture = NDS_CreateTexture;
   194     renderer->QueryTexturePixels = NDS_QueryTexturePixels;
   195     renderer->SetTexturePalette = NDS_SetTexturePalette;
   196     renderer->GetTexturePalette = NDS_GetTexturePalette;
   197     renderer->SetTextureColorMod = NDS_SetTextureColorMod;
   198     renderer->SetTextureAlphaMod = NDS_SetTextureAlphaMod;
   199     renderer->SetTextureBlendMode = NDS_SetTextureBlendMode;
   200     renderer->SetTextureScaleMode = NDS_SetTextureScaleMode;
   201     renderer->UpdateTexture = NDS_UpdateTexture;
   202     renderer->LockTexture = NDS_LockTexture;
   203     renderer->UnlockTexture = NDS_UnlockTexture;
   204     renderer->DirtyTexture = NDS_DirtyTexture;
   205     renderer->DestroyTexture = NDS_DestroyTexture;
   206 
   207     renderer->info.mod_modes = NDS_RenderDriver.info.mod_modes;
   208     renderer->info.blend_modes = NDS_RenderDriver.info.blend_modes;
   209     renderer->info.scale_modes = NDS_RenderDriver.info.scale_modes;
   210     renderer->info.num_texture_formats =
   211         NDS_RenderDriver.info.num_texture_formats;
   212     SDL_memcpy(renderer->info.texture_formats,
   213                NDS_RenderDriver.info.texture_formats,
   214                sizeof(renderer->info.texture_formats));;
   215     renderer->info.max_texture_width = NDS_RenderDriver.info.max_texture_width;
   216     renderer->info.max_texture_height =
   217         NDS_RenderDriver.info.max_texture_height;
   218 
   219     /*data->fb = (u16*)0x06020000;*/
   220     data->bg = &BACKGROUND;
   221     data->bg_taken[2] = data->bg_taken[3] = 0;
   222     data->sub = 0;
   223 
   224 printf("-NDS_CreateRenderer\n");
   225     return renderer;
   226 }
   227 
   228 static int
   229 NDS_ActivateRenderer(SDL_Renderer * renderer)
   230 {
   231     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   232     /* stub. TODO: figure out what needs to be done, if anything. */
   233 printf("!NDS_ActivateRenderer\n");
   234     return 0;
   235 }
   236 
   237 static int
   238 NDS_DisplayModeChanged(SDL_Renderer * renderer)
   239 {
   240     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   241     /* stub. TODO: figure out what needs to be done */
   242 printf("!NDS_DisplayModeChanged\n");
   243     return 0;
   244 }
   245 
   246 static int
   247 NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   248 {
   249     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   250     NDS_TextureData *txdat = NULL;
   251     int i;
   252 printf("+NDS_CreateTexture\n");
   253     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   254         SDL_SetError("Unsupported texture format");
   255         return -1;
   256     } else {
   257         int bpp;
   258         Uint32 Rmask, Gmask, Bmask, Amask;
   259 
   260         if (!SDL_PixelFormatEnumToMasks
   261             (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   262             SDL_SetError("Unknown texture format");
   263             return -1;
   264         }
   265         /* conditional statements on w/h to place it as bg/sprite */
   266         /*if(texture->w <= 64 && texture->h <= 64) {
   267             sprites not implemented yet.  elegant, I know.
   268         } else*/ if(texture->w <= 256 && texture->h <= 256) {
   269             int whichbg = -1;
   270             if(!data->bg_taken[2]) {
   271                 whichbg = 2;
   272                 data->bg->bg2_rotation.xdx = 0x100;
   273                 data->bg->bg2_rotation.xdy = 0;
   274                 data->bg->bg2_rotation.ydx = 0;
   275                 data->bg->bg2_rotation.ydy = 0x100;
   276                 data->bg->bg2_rotation.centerX = 0;
   277                 data->bg->bg2_rotation.centerY = 0;
   278             } else if(!data->bg_taken[3]) {
   279                 whichbg = 3;
   280                 data->bg->bg3_rotation.xdx = 0x100;
   281                 data->bg->bg3_rotation.xdy = 0;
   282                 data->bg->bg3_rotation.ydx = 0;
   283                 data->bg->bg3_rotation.ydy = 0x100;
   284                 data->bg->bg3_rotation.centerX = 0;
   285                 data->bg->bg3_rotation.centerY = 0;
   286             }
   287             if(whichbg >= 0) {
   288                 data->bg->control[whichbg] = (bpp == 8) ?
   289                     BG_BMP8_256x256 : BG_BMP16_256x256;
   290                 data->bg->scroll[whichbg].x = 0;
   291                 data->bg->scroll[whichbg].y = 0;
   292                 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
   293                 txdat = (NDS_TextureData*)texture->driverdata;
   294                 txdat->type = NDSTX_BG;
   295                 txdat->hw_index = whichbg;
   296                 txdat->dim.w = texture->w;
   297                 txdat->dim.h = texture->h;
   298                 txdat->dim.pitch = 256 * (bpp/8);
   299                 txdat->dim.bpp = bpp;
   300                 txdat->vram = (u16*)(data->sub ?
   301                     BG_BMP_RAM_SUB(whichbg) : BG_BMP_RAM(whichbg));
   302                 for(i = 0; i < 256*256; ++i) {
   303                     txdat->vram[i] = 0x8000|RGB15(0,31,31);
   304                 }
   305                 for(i = 0; i < 60; ++i) swiWaitForVBlank();
   306             } else {
   307                 SDL_SetError("Out of NDS backgrounds.");
   308             }
   309         } else {
   310             SDL_SetError("Texture too big for NDS hardware.");
   311         }
   312     }
   313 
   314 printf("-NDS_CreateTexture\n");
   315     if (!texture->driverdata) {
   316         return -1;
   317     }
   318     return 0;
   319 }
   320 
   321 static int
   322 NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   323                       void **pixels, int *pitch)
   324 {
   325 printf("+NDS_QueryTexturePixels\n");
   326     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   327         SDL_SetError("Unsupported texture format");
   328         return -1;
   329     } else {
   330         NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   331 
   332         *pixels = txdat->vram;
   333         *pitch = txdat->dim.pitch;
   334 printf("-NDS_QueryTexturePixels\n");
   335         return 0;
   336     }
   337 }
   338 
   339 static int
   340 NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   341                      const SDL_Color * colors, int firstcolor, int ncolors)
   342 {
   343 printf("+NDS_SetTexturePalette\n");
   344     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   345         SDL_SetError("YUV textures don't have a palette");
   346         return -1;
   347     } else {
   348         NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   349         /* TODO: mess with 8-bit modes and/or 16-color palette modes */
   350 printf("-NDS_SetTexturePalette\n");
   351         return 0;
   352     }
   353 }
   354 
   355 static int
   356 NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   357                      SDL_Color * colors, int firstcolor, int ncolors)
   358 {
   359 printf("+NDS_GetTexturePalette\n");
   360     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   361         SDL_SetError("YUV textures don't have a palette");
   362         return -1;
   363     } else {
   364         NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   365 printf("-NDS_GetTexturePalette\n");
   366         /* TODO: mess with 8-bit modes and/or 16-color palette modes */
   367         return 0;
   368     }
   369 }
   370 
   371 static int
   372 NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
   373 {
   374 printf("!NDS_SetTextureColorMod\n");
   375     /* stub. TODO: figure out what needs to be done, if anything */
   376     return 0;
   377 }
   378 
   379 static int
   380 NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
   381 {
   382 printf("!NDS_SetTextureAlphaMod\n");
   383     /* stub. TODO: figure out what needs to be done, if anything */
   384     return 0;
   385 }
   386 
   387 static int
   388 NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   389 {
   390 printf("!NDS_SetTextureBlendMode\n");
   391     /* stub. TODO: figure out what needs to be done, if anything */
   392     return 0;
   393 }
   394 
   395 static int
   396 NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
   397 {
   398 printf("!NDS_SetTextureScaleMode\n");
   399     /* stub. TODO: figure out what needs to be done.
   400        (NDS hardware scaling is nearest neighbor.) */
   401     return 0;
   402 }
   403 
   404 static int
   405 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   406                  const SDL_Rect * rect, const void *pixels, int pitch)
   407 {
   408 printf("+NDS_UpdateTexture\n");
   409     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   410         SDL_SetError("Unsupported texture format");
   411         return -1;
   412     } else {
   413         NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   414         Uint8 *src, *dst;
   415         int row;
   416         size_t length;
   417         /* IMPORTANT! copy the new pixels into the sprite or bg. */
   418         src = (Uint8 *) pixels;
   419         dst =
   420             (Uint8 *) txdat->vram + rect->y * txdat->dim.pitch +
   421             rect->x * (txdat->dim.bpp/8);
   422         length = rect->w * (txdat->dim.bpp/8);
   423         for (row = 0; row < rect->h; ++row) {
   424             SDL_memcpy(dst, src, length);
   425             src += pitch;
   426             dst += txdat->dim.pitch;
   427         }
   428 printf("-NDS_UpdateTexture\n");
   429         return 0;
   430     }
   431 }
   432 
   433 static int
   434 NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   435                const SDL_Rect * rect, int markDirty, void **pixels,
   436                int *pitch)
   437 {
   438 printf("+NDS_LockTexture\n");
   439     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   440         SDL_SetError("Unsupported texture format");
   441         return -1;
   442     } else {
   443         NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   444 
   445         if (markDirty) {
   446             /*SDL_AddDirtyRect(&txdat->dirty, rect);*/
   447         }
   448 
   449         *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch
   450                             + rect->x * (txdat->dim.bpp/8));
   451         *pitch = txdat->dim.pitch;
   452 printf("-NDS_LockTexture\n");
   453         return 0;
   454     }
   455 }
   456 
   457 static void
   458 NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   459 {
   460     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   461         SDL_SetError("Unsupported texture format");
   462     }
   463 printf("!NDS_UnlockTexture\n");
   464 }
   465 
   466 static void
   467 NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   468                 int numrects, const SDL_Rect * rects)
   469 { /* stub */
   470 printf("!NDS_DirtyTexture\n");
   471 }
   472 
   473 static int
   474 NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
   475                    Uint8 a, const SDL_Rect * rect)
   476 {
   477     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   478     SDL_Rect real_rect = *rect;
   479     u16 color;
   480     int i, j;
   481 
   482 printf("+NDS_RenderFill\n");
   483     /* TODO: make a single-color sprite and stretch it.
   484     color = RGB15(r>>3,g>>3,b>>3);
   485     for (i = real_rect.x; i < real_rect.x+real_rect.w; ++i) {
   486         for (j = real_rect.y; j < real_rect.y+real_rect.h; ++j) {
   487             data->fb[(j + real_rect.y) * 256 + i + real_rect.x] = 
   488                 0x8000 | color;
   489         }
   490     }*/
   491 printf("-NDS_RenderFill\n");
   492     return 0;
   493 }
   494 
   495 static int
   496 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   497                    const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   498 {
   499     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   500     NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   501 //    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   502 //    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   503     int i;
   504 printf("+NDS_RenderCopy\n");
   505     for(i = 0; i <= 0xFFFF; ++i) {
   506         txdat->vram[i] = 0x8000|i;
   507     }
   508     printf("/txdat->hw_index = %d\n", txdat->hw_index);
   509 #if 0
   510     if (txdat->dirty.list) {
   511         SDL_DirtyRect *dirty;
   512         void *pixels;
   513         int bpp = SDL_BYTESPERPIXEL(texture->format);
   514         int pitch = txdat->pitch;
   515 /* below was borrowed from SDL_renderer_gl.c.  doesn't work, obv.
   516    figure out how to get the graphics data into VRAM. */
   517 
   518         for (dirty = txdat->dirty.list; dirty; dirty = dirty->next) {
   519             SDL_Rect *rect = &dirty->rect;
   520             /*pixels =
   521                 (void *) ((Uint8 *) txdat->vram + rect->y * pitch +
   522                           rect->x * bpp);
   523             data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
   524                                   rect->w, rect->h, texturedata->format,
   525                                   texturedata->formattype, pixels);*/
   526         }
   527         SDL_ClearDirtyRects(&txdat->dirty);
   528     }
   529 #endif
   530 printf("-NDS_RenderCopy\n");
   531     return 0;
   532 }
   533 
   534 
   535 static void
   536 NDS_RenderPresent(SDL_Renderer * renderer)
   537 {
   538     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   539     /* Send the data to the display TODO */
   540 
   541 printf("+NDS_RenderPresent\n");
   542     /* Update the flipping chain, if any */
   543     if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
   544         swiWaitForVBlank();
   545     }
   546 printf("-NDS_RenderPresent\n");
   547 }
   548 
   549 static void
   550 NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   551 {
   552 printf("+NDS_DestroyTexture\n");
   553     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   554         SDL_SetError("Unsupported texture format");
   555     } else {
   556         /* free anything else allocated for texture */
   557         NDS_TextureData *txdat = texture->driverdata;
   558         /*SDL_FreeDirtyRects(&txdat->dirty);*/
   559         SDL_free(txdat);
   560     }
   561 printf("-NDS_DestroyTexture\n");
   562 }
   563 
   564 static void
   565 NDS_DestroyRenderer(SDL_Renderer * renderer)
   566 {
   567     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   568     /*SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   569     SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/
   570     int i;
   571 
   572 printf("+NDS_DestroyRenderer\n");
   573     if (data) {
   574         /* TODO: free anything relevant. */
   575         /*for (i = 0; i < SDL_arraysize(data->texture); ++i) {
   576             if (data->texture[i]) {
   577                 DestroyTexture(data->renderer, data->texture[i]);
   578             }
   579         }
   580         if (data->surface.format) {
   581             SDL_SetSurfacePalette(&data->surface, NULL);
   582             SDL_FreeFormat(data->surface.format);
   583         }
   584         if (display->palette) {
   585             SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged,
   586                                 data);
   587         }
   588         SDL_FreeDirtyRects(&data->dirty);*/
   589         SDL_free(data);
   590     }
   591     SDL_free(renderer);
   592 printf("-NDS_DestroyRenderer\n");
   593 }
   594 
   595 /* vi: set ts=4 sw=4 expandtab: */