comparison src/video/nds/SDL_ndsrender.c @ 2695:c04a266c277a gsoc2008_nds

More sprite-driven texture work in the render/video drivers.
author Darren Alton <dalton@stevens.edu>
date Sun, 17 Aug 2008 09:50:28 +0000
parents c1c7cb1b5a47
children 0b395a60deff
comparison
equal deleted inserted replaced
2694:c1c7cb1b5a47 2695:c04a266c277a
328 break; 328 break;
329 } 329 }
330 } 330 }
331 if(whichspr >= 0) { 331 if(whichspr >= 0) {
332 SpriteEntry *sprent = &(data->oam_copy.spriteBuffer[whichspr]); 332 SpriteEntry *sprent = &(data->oam_copy.spriteBuffer[whichspr]);
333 int maxside = texture->w > texture->h ? texture->w : texture->h;
334 int pitch;
333 335
334 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); 336 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
335 txdat = (NDS_TextureData*)texture->driverdata; 337 txdat = (NDS_TextureData*)texture->driverdata;
336 if(!txdat) { 338 if(!txdat) {
337 SDL_OutOfMemory(); 339 SDL_OutOfMemory();
347 if(whichspr < MATRIX_COUNT) { 349 if(whichspr < MATRIX_COUNT) {
348 sprent->isRotoscale = 1; 350 sprent->isRotoscale = 1;
349 sprent->rsMatrixIdx = whichspr; 351 sprent->rsMatrixIdx = whichspr;
350 } 352 }
351 353
354 /* containing shape (square or 2:1 rectangles) */
352 sprent->objShape = OBJSHAPE_SQUARE; 355 sprent->objShape = OBJSHAPE_SQUARE;
353 if(texture->w/2 >= texture->h) { 356 if(texture->w/2 >= texture->h) {
354 sprent->objShape = OBJSHAPE_WIDE; 357 sprent->objShape = OBJSHAPE_WIDE;
355 } else if(texture->h/2 >= texture->w) { 358 } else if(texture->h/2 >= texture->w) {
356 sprent->objShape = OBJSHAPE_TALL; 359 sprent->objShape = OBJSHAPE_TALL;
357 } 360 }
361
362 /* size in pixels */
363 /* FIXME: "pitch" is hardcoded for 2bytes per pixel. */
364 sprent->objSize = OBJSIZE_64;
365 pitch = 128;
366 if(maxside <= 8) {
367 sprent->objSize = OBJSIZE_8;
368 pitch = 16;
369 } else if(maxside <= 16) {
370 sprent->objSize = OBJSIZE_16;
371 pitch = 32;
372 } else if(maxside <= 32) {
373 sprent->objSize = OBJSIZE_32;
374 pitch = 64;
375 }
376
377 /* FIXME: this is hard-coded and will obviously only work for one
378 sprite-texture. tells it to look at the beginning of SPRITE_GFX
379 for its pixels. */
380 sprent->tileIdx = 0;
381
382 /* now for the texture data */
383 txdat->type = NDSTX_SPR;
384 txdat->hw_index = whichspr;
385 txdat->dim.hdx = 0x100; txdat->dim.hdy = 0;
386 txdat->dim.vdx = 0; txdat->dim.vdy = 0x100;
387 txdat->dim.pitch = pitch;
388 txdat->dim.bpp = bpp;
389 txdat->vram_pixels = (u16*)(data->sub ?
390 SPRITE_GFX_SUB : SPRITE_GFX); /* FIXME: use tileIdx*boundary
391 to point to proper location */
358 } else { 392 } else {
359 SDL_SetError("Out of NDS sprites."); 393 SDL_SetError("Out of NDS sprites.");
360 } 394 }
361 } else if(texture->w <= 256 && texture->h <= 256) { 395 } else if(texture->w <= 256 && texture->h <= 256) {
362 int whichbg = -1, base = 0; 396 int whichbg = -1, base = 0;
372 if(!txdat) { 406 if(!txdat) {
373 SDL_OutOfMemory(); 407 SDL_OutOfMemory();
374 return -1; 408 return -1;
375 } 409 }
376 410
377 /* TODO: maybe this should be in RenderPresent or RenderCopy 411 /* this is hard-coded to being 256x256 ABGR1555 for now. */
378 instead, copying from a malloc'd system RAM pixel buffer. */
379 /* this is hard-coded to being 256x256 for now. */
380 data->bg->control[whichbg] = (bpp == 8) ? 412 data->bg->control[whichbg] = (bpp == 8) ?
381 BG_BMP8_256x256 : BG_BMP16_256x256; 413 BG_BMP8_256x256 : BG_BMP16_256x256;
382 414
383 data->bg->control[whichbg] |= BG_BMP_BASE(base); 415 data->bg->control[whichbg] |= BG_BMP_BASE(base);
384 416
387 419
388 txdat->type = NDSTX_BG; 420 txdat->type = NDSTX_BG;
389 txdat->hw_index = whichbg; 421 txdat->hw_index = whichbg;
390 txdat->dim.hdx = 0x100; txdat->dim.hdy = 0; 422 txdat->dim.hdx = 0x100; txdat->dim.hdy = 0;
391 txdat->dim.vdx = 0; txdat->dim.vdy = 0x100; 423 txdat->dim.vdx = 0; txdat->dim.vdy = 0x100;
392 txdat->dim.pitch = texture->w * ((bpp+1)/8); 424 txdat->dim.pitch = 512;
393 txdat->dim.bpp = bpp; 425 txdat->dim.bpp = bpp;
394 txdat->vram_pixels = (u16*)(data->sub ? 426 txdat->vram_pixels = (u16*)(data->sub ?
395 BG_BMP_RAM_SUB(base) : BG_BMP_RAM(base)); 427 BG_BMP_RAM_SUB(base) : BG_BMP_RAM(base));
396 428
397 /*txdat->size = txdat->dim.pitch * texture->h;*/ 429 /*txdat->size = txdat->dim.pitch * texture->h;*/
536 } else { 568 } else {
537 /* sprites not fully implemented yet */ 569 /* sprites not fully implemented yet */
538 SpriteEntry *spr = &(data->oam_copy.spriteBuffer[txdat->hw_index]); 570 SpriteEntry *spr = &(data->oam_copy.spriteBuffer[txdat->hw_index]);
539 spr->posX = dstrect->x; 571 spr->posX = dstrect->x;
540 spr->posY = dstrect->y; 572 spr->posY = dstrect->y;
541 if(txdat->hw_index < MATRIX_COUNT) { 573 if(txdat->hw_index < MATRIX_COUNT && spr->isRotoscale) {
542 SpriteRotation *sprot = &(data->oam_copy.matrixBuffer[txdat->hw_index]); 574 SpriteRotation *sprot = &(data->oam_copy.matrixBuffer[txdat->hw_index]);
543 sprot->hdx = txdat->dim.hdx; 575 sprot->hdx = txdat->dim.hdx;
544 sprot->hdy = txdat->dim.hdy; 576 sprot->hdy = txdat->dim.hdy;
545 sprot->vdx = txdat->dim.vdx; 577 sprot->vdx = txdat->dim.vdx;
546 sprot->vdy = txdat->dim.vdy; 578 sprot->vdy = txdat->dim.vdy;
571 } 603 }
572 604
573 static void 605 static void
574 NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) 606 NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
575 { 607 {
608 NDS_TextureData *txdat = texture->driverdata;
576 TRACE("+NDS_DestroyTexture\n"); 609 TRACE("+NDS_DestroyTexture\n");
577 /* free anything else allocated for texture */ 610 /* free anything else allocated for texture */
578 NDS_TextureData *txdat = texture->driverdata;
579 /*SDL_FreeDirtyRects(&txdat->dirty);*/ 611 /*SDL_FreeDirtyRects(&txdat->dirty);*/
580 SDL_free(txdat); 612 SDL_free(txdat);
581 TRACE("-NDS_DestroyTexture\n"); 613 TRACE("-NDS_DestroyTexture\n");
582 } 614 }
583 615
584 static void 616 static void
585 NDS_DestroyRenderer(SDL_Renderer * renderer) 617 NDS_DestroyRenderer(SDL_Renderer * renderer)
586 { 618 {
587 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; 619 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
588 /*SDL_Window *window = SDL_GetWindowFromID(renderer->window); 620 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
589 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/ 621 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
590 int i; 622 int i;
591 623
592 TRACE("+NDS_DestroyRenderer\n"); 624 TRACE("+NDS_DestroyRenderer\n");
593 if (data) { 625 if (data) {
594 /* TODO: free anything else relevant. */ 626 /* TODO: free anything else relevant. */
621 653
622 static int 654 static int
623 NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, 655 NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
624 SDL_Color * colors, int firstcolor, int ncolors) 656 SDL_Color * colors, int firstcolor, int ncolors)
625 { 657 {
658 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
626 TRACE("+NDS_GetTexturePalette\n"); 659 TRACE("+NDS_GetTexturePalette\n");
627 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
628 TRACE("-NDS_GetTexturePalette\n"); 660 TRACE("-NDS_GetTexturePalette\n");
629 return 0; 661 return 0;
630 } 662 }
631 663
632 static int 664 static int