summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Alton <dalton@stevens.edu>2008-08-14 04:33:55 +0000
committerDarren Alton <dalton@stevens.edu>2008-08-14 04:33:55 +0000
commit994600862dbd15f5e3e6a9014b4f02cbd7385fc0 (patch)
treed9dc6c64e8c99014219c2a76444fc7daddc281fc
parent53d96e52a15d102a1697c152dc3bf03284afab75 (diff)
downloadsdl-994600862dbd15f5e3e6a9014b4f02cbd7385fc0.tar.gz
renderer: Added a separate copy of texture pixels in system RAM, copied into VRAM during RenderPresent. Still trying to fix rendering.
-rw-r--r--src/video/nds/SDL_ndsrender.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/video/nds/SDL_ndsrender.c b/src/video/nds/SDL_ndsrender.c
index 48557387d..4ec194175 100644
--- a/src/video/nds/SDL_ndsrender.c
+++ b/src/video/nds/SDL_ndsrender.c
@@ -109,6 +109,8 @@ typedef struct
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 @@ printf("+NDS_CreateTexture\n");
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 @@ printf("+NDS_UpdateTexture\n");
/* 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 @@ printf("+NDS_LockTexture\n");
/*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_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
{
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 @@ static void
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 @@ printf("+NDS_DestroyTexture\n");
/* 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");