changeset 2687:5166b19b6808 gsoc2008_nds

renderer: Added a separate copy of texture pixels in system RAM, copied into VRAM during RenderPresent. Still trying to fix rendering.
author Darren Alton <dalton@stevens.edu>
date Thu, 14 Aug 2008 04:33:55 +0000
parents e9f27fe4f2a1
children 71c56e900f8b
files src/video/nds/SDL_ndsrender.c
diffstat 1 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/nds/SDL_ndsrender.c	Wed Aug 13 00:49:03 2008 +0000
+++ b/src/video/nds/SDL_ndsrender.c	Thu Aug 14 04:33:55 2008 +0000
@@ -109,6 +109,8 @@
     int hw_index;
     struct { int hdx, hdy, vdx, vdy, pitch, bpp; } dim;
     u16 *vram;
+    u16 *system_ram_copy;
+    int size;
 } NDS_TextureData;
 
 
@@ -269,7 +271,8 @@
                 txdat->dim.bpp = bpp;
                 txdat->vram = (u16*)(data->sub ?
                     BG_BMP_RAM_SUB(whichbg) : BG_BMP_RAM(whichbg));
-                for(i = 0; i < 60; ++i) swiWaitForVBlank();
+                txdat->size = txdat->dim.pitch * texture->h;
+                txdat->system_ram_copy = SDL_malloc(txdat->size);
             } else {
                 SDL_SetError("Out of NDS backgrounds.");
                 printf("ran out.\n");
@@ -320,7 +323,7 @@
         /* IMPORTANT! copy the new pixels into the sprite or bg. */
         src = (Uint8 *) pixels;
         dst =
-            (Uint8 *) txdat->vram + rect->y * txdat->dim.pitch +
+            (Uint8 *) txdat->system_ram_copy + rect->y * txdat->dim.pitch +
             rect->x * (txdat->dim.bpp/8);
         length = rect->w * (txdat->dim.bpp/8);
         for (row = 0; row < rect->h; ++row) {
@@ -350,8 +353,8 @@
             /*SDL_AddDirtyRect(&txdat->dirty, rect);*/
         }
 
-        *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch
-                            + rect->x * (txdat->dim.bpp/8));
+        *pixels = (void *) ((u8 *)txdat->system_ram_copy + rect->y
+                            * txdat->dim.pitch + rect->x * (txdat->dim.bpp/8));
         *pitch = txdat->dim.pitch;
         printf("  pixels = %08x\n", (u32)*pixels);
 printf("-NDS_LockTexture\n");
@@ -403,8 +406,8 @@
 {
     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
     NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
-//    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
-//    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
+    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
+    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
     int i;
     int bpp = SDL_BYTESPERPIXEL(texture->format);
     int pitch = txdat->dim.pitch;
@@ -431,11 +434,20 @@
 NDS_RenderPresent(SDL_Renderer * renderer)
 {
     NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
-    /* Send the data to the display TODO */
-    /* shouldn't it already be there at this point?
+    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
+    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
+    int i;
+    /* Send the data to the display TODO :
+       shouldn't it already be there at this point?
        I guess set the BG's and sprites "visible" flags here. */
 printf("+NDS_RenderPresent\n");
 
+    for(i = 0; i < 64; ++i) {
+        SDL_Texture * tx = display->textures[i];
+        NDS_TextureData * txdat = (NDS_TextureData*)tx->driverdata;
+        SDL_memcpy(txdat->vram, txdat->system_ram_copy, txdat->size);
+    }
+
     /* vsync for NDS */
     if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
         swiWaitForVBlank();
@@ -453,6 +465,7 @@
         /* free anything else allocated for texture */
         NDS_TextureData *txdat = texture->driverdata;
         /*SDL_FreeDirtyRects(&txdat->dirty);*/
+        SDL_free(txdat->system_ram_copy);
         SDL_free(txdat);
     }
 printf("-NDS_DestroyTexture\n");