comparison src/video/nds/SDL_ndsrender.c @ 2681:c15b6c758be5 gsoc2008_nds

Some small bug fixes and more work on video
author Darren Alton <dalton@stevens.edu>
date Fri, 25 Jul 2008 23:39:14 +0000
parents 4135aa9c5645
children f7594fc66bda
comparison
equal deleted inserted replaced
2680:4135aa9c5645 2681:c15b6c758be5
85 (SDL_TEXTUREBLENDMODE_NONE), /* u32 blend_modes */ 85 (SDL_TEXTUREBLENDMODE_NONE), /* u32 blend_modes */
86 (SDL_TEXTURESCALEMODE_NONE), /* u32 scale_modes */ 86 (SDL_TEXTURESCALEMODE_NONE), /* u32 scale_modes */
87 3, /* u32 num_texture_formats */ 87 3, /* u32 num_texture_formats */
88 { 88 {
89 SDL_PIXELFORMAT_INDEX8, 89 SDL_PIXELFORMAT_INDEX8,
90 SDL_PIXELFORMAT_RGB555, 90 SDL_PIXELFORMAT_ABGR1555,
91 SDL_PIXELFORMAT_RGB565 91 SDL_PIXELFORMAT_BGR555,
92 }, /* u32 texture_formats[20] */ 92 }, /* u32 texture_formats[20] */
93 (256), /* int max_texture_width */ 93 (256), /* int max_texture_width */
94 (256), /* int max_texture_height */ 94 (256), /* int max_texture_height */
95 } 95 }
96 }; 96 };
98 typedef struct 98 typedef struct
99 { 99 {
100 bg_attribute *bg; 100 bg_attribute *bg;
101 u8 bg_taken[4]; 101 u8 bg_taken[4];
102 int sub; 102 int sub;
103 SDL_DirtyRectList dirty;
103 } NDS_RenderData; 104 } NDS_RenderData;
104 105
105 typedef struct 106 typedef struct
106 { 107 {
107 enum { NDSTX_BG, NDSTX_SPR } type; 108 enum { NDSTX_BG, NDSTX_SPR } type;
435 SDL_SetError("Unsupported texture format"); 436 SDL_SetError("Unsupported texture format");
436 return -1; 437 return -1;
437 } else { 438 } else {
438 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; 439 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
439 440
441 if (markDirty) {
442 SDL_AddDirtyRect(&txdat->dirty, rect);
443 }
444
440 *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch 445 *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch
441 + rect->x * (txdat->dim.bpp/8)); 446 + rect->x * (txdat->dim.bpp/8));
442 *pitch = txdat->dim.pitch; 447 *pitch = txdat->dim.pitch;
443 printf("-NDS_LockTexture\n"); 448 printf("-NDS_LockTexture\n");
444 return 0; 449 return 0;
486 static int 491 static int
487 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 492 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
488 const SDL_Rect * srcrect, const SDL_Rect * dstrect) 493 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
489 { 494 {
490 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; 495 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
491 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 496 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
492 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 497 // SDL_Window *window = SDL_GetWindowFromID(renderer->window);
498 // SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
493 499
494 printf("+NDS_RenderCopy\n"); 500 printf("+NDS_RenderCopy\n");
495 #if 0 501
496 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 502 if (txdat->dirty.list) {
497 SDL_Surface *target = data->screens[data->current_screen]; 503 SDL_DirtyRect *dirty;
498 void *pixels = 504 void *pixels;
499 (Uint8 *) target->pixels + dstrect->y * target->pitch + 505 int bpp = SDL_BYTESPERPIXEL(texture->format);
500 dstrect->x * target->format->BytesPerPixel; 506 int pitch = txdat->pitch;
501 return SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata, 507 /* below was borrowed from SDL_renderer_gl.c. doesn't work, obv.
502 srcrect, display->current_mode.format, 508 figure out how to get the graphics data into VRAM. */
503 dstrect->w, dstrect->h, pixels, 509
504 target->pitch); 510 for (dirty = txdat->dirty.list; dirty; dirty = dirty->next) {
505 } else { 511 SDL_Rect *rect = &dirty->rect;
506 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; 512 /*pixels =
507 SDL_Surface *target = data->screens[data->current_screen]; 513 (void *) ((Uint8 *) txdat->vram + rect->y * pitch +
508 SDL_Rect real_srcrect = *srcrect; 514 rect->x * bpp);
509 SDL_Rect real_dstrect = *dstrect; 515 data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
510 return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect); 516 rect->w, rect->h, texturedata->format,
511 } 517 texturedata->formattype, pixels);*/
512 #endif 518 }
519 SDL_ClearDirtyRects(&txdat->dirty);
520 }
521
513 printf("-NDS_RenderCopy\n"); 522 printf("-NDS_RenderCopy\n");
514 return 0; 523 return status;
515 } 524 }
516 525
517 526
518 static void 527 static void
519 NDS_RenderPresent(SDL_Renderer * renderer) 528 NDS_RenderPresent(SDL_Renderer * renderer)
535 printf("+NDS_DestroyTexture\n"); 544 printf("+NDS_DestroyTexture\n");
536 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 545 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
537 SDL_SetError("Unsupported texture format"); 546 SDL_SetError("Unsupported texture format");
538 } else { 547 } else {
539 /* free anything else allocated for texture */ 548 /* free anything else allocated for texture */
540 SDL_free(texture->driverdata); 549 NDS_TextureData *txdat = texture->driverdata;
550 SDL_FreeDirtyRects(&txdat->dirty);
551 SDL_free(txdat);
541 } 552 }
542 printf("-NDS_DestroyTexture\n"); 553 printf("-NDS_DestroyTexture\n");
543 } 554 }
544 555
545 static void 556 static void