From b1aa35f8cc5d0a5dbb01df92f15214ac23d31824 Mon Sep 17 00:00:00 2001 From: Darren Alton Date: Fri, 25 Jul 2008 23:39:14 +0000 Subject: [PATCH] Some small bug fixes and more work on video --- src/video/nds/SDL_ndsrender.c | 57 +++++++++++++++++++++-------------- src/video/nds/SDL_ndsvideo.c | 8 +++-- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/video/nds/SDL_ndsrender.c b/src/video/nds/SDL_ndsrender.c index 3a40c250c..f4d982dff 100644 --- a/src/video/nds/SDL_ndsrender.c +++ b/src/video/nds/SDL_ndsrender.c @@ -87,8 +87,8 @@ SDL_RenderDriver NDS_RenderDriver = { 3, /* u32 num_texture_formats */ { SDL_PIXELFORMAT_INDEX8, - SDL_PIXELFORMAT_RGB555, - SDL_PIXELFORMAT_RGB565 + SDL_PIXELFORMAT_ABGR1555, + SDL_PIXELFORMAT_BGR555, }, /* u32 texture_formats[20] */ (256), /* int max_texture_width */ (256), /* int max_texture_height */ @@ -100,6 +100,7 @@ typedef struct bg_attribute *bg; u8 bg_taken[4]; int sub; + SDL_DirtyRectList dirty; } NDS_RenderData; typedef struct @@ -437,6 +438,10 @@ printf("+NDS_LockTexture\n"); } else { NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; + if (markDirty) { + SDL_AddDirtyRect(&txdat->dirty, rect); + } + *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch + rect->x * (txdat->dim.bpp/8)); *pitch = txdat->dim.pitch; @@ -488,30 +493,34 @@ NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect) { NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - SDL_Window *window = SDL_GetWindowFromID(renderer->window); - SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); + NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; +// SDL_Window *window = SDL_GetWindowFromID(renderer->window); +// SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); printf("+NDS_RenderCopy\n"); -#if 0 - if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { - SDL_Surface *target = data->screens[data->current_screen]; - void *pixels = - (Uint8 *) target->pixels + dstrect->y * target->pitch + - dstrect->x * target->format->BytesPerPixel; - return SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata, - srcrect, display->current_mode.format, - dstrect->w, dstrect->h, pixels, - target->pitch); - } else { - SDL_Surface *surface = (SDL_Surface *) texture->driverdata; - SDL_Surface *target = data->screens[data->current_screen]; - SDL_Rect real_srcrect = *srcrect; - SDL_Rect real_dstrect = *dstrect; - return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect); + + if (txdat->dirty.list) { + SDL_DirtyRect *dirty; + void *pixels; + int bpp = SDL_BYTESPERPIXEL(texture->format); + int pitch = txdat->pitch; +/* below was borrowed from SDL_renderer_gl.c. doesn't work, obv. + figure out how to get the graphics data into VRAM. */ + + for (dirty = txdat->dirty.list; dirty; dirty = dirty->next) { + SDL_Rect *rect = &dirty->rect; + /*pixels = + (void *) ((Uint8 *) txdat->vram + rect->y * pitch + + rect->x * bpp); + data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y, + rect->w, rect->h, texturedata->format, + texturedata->formattype, pixels);*/ + } + SDL_ClearDirtyRects(&txdat->dirty); } -#endif + printf("-NDS_RenderCopy\n"); - return 0; + return status; } @@ -537,7 +546,9 @@ printf("+NDS_DestroyTexture\n"); SDL_SetError("Unsupported texture format"); } else { /* free anything else allocated for texture */ - SDL_free(texture->driverdata); + NDS_TextureData *txdat = texture->driverdata; + SDL_FreeDirtyRects(&txdat->dirty); + SDL_free(txdat); } printf("-NDS_DestroyTexture\n"); } diff --git a/src/video/nds/SDL_ndsvideo.c b/src/video/nds/SDL_ndsvideo.c index 7a86e0983..6676acf42 100644 --- a/src/video/nds/SDL_ndsvideo.c +++ b/src/video/nds/SDL_ndsvideo.c @@ -198,10 +198,12 @@ NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode) { printf("+NDS_SetDisplayMode\n"); /* right now this function is just hard-coded for 256x192 ABGR1555 */ - videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE); /* display on main core */ - videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */ + videoSetMode(MODE_5_2D | + DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE + DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE); /* display on main core */ + videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */ vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, - VRAM_C_SUB_BG_0x06200000, VRAM_C_SUB_BG_0x06220000); + VRAM_C_SUB_BG_0x06200000, VRAM_D_SUB_BG_0x06220000); vramSetBankE(VRAM_E_MAIN_SPRITE); /* set up console for debug text 'n stuff */ SUB_BG0_CR = BG_MAP_BASE(31);