comparison src/video/nds/SDL_ndsrender.c @ 2680:4135aa9c5645 gsoc2008_nds

More work on the accelerated 2D video driver, beginnings of sprite-based rendering support. Also some initial work on an audio driver.
author Darren Alton <dalton@stevens.edu>
date Sat, 19 Jul 2008 17:37:19 +0000
parents bc3e3e889f6d
children c15b6c758be5
comparison
equal deleted inserted replaced
2679:bc3e3e889f6d 2680:4135aa9c5645
157 int bpp = 15; 157 int bpp = 15;
158 Uint32 Rmask, Gmask, Bmask, Amask; 158 Uint32 Rmask, Gmask, Bmask, Amask;
159 /* Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000; 159 /* Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
160 Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000; 160 Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000;
161 */ 161 */
162 printf("+NDS_CreateRenderer\n");
162 163
163 /* hard coded this to BGR555 for now */ 164 /* hard coded this to BGR555 for now */
164 if (!SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_BGR555, &bpp, 165 if (!SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_BGR555, &bpp,
165 &Rmask, &Gmask, &Bmask, &Amask)) { 166 &Rmask, &Gmask, &Bmask, &Amask)) {
166 SDL_SetError("Unknown display format"); 167 SDL_SetError("Unknown display format");
218 /*data->fb = (u16*)0x06020000;*/ 219 /*data->fb = (u16*)0x06020000;*/
219 data->bg = &BACKGROUND; 220 data->bg = &BACKGROUND;
220 data->bg_taken[2] = data->bg_taken[3] = 0; 221 data->bg_taken[2] = data->bg_taken[3] = 0;
221 data->sub = 0; 222 data->sub = 0;
222 223
224 printf("-NDS_CreateRenderer\n");
223 return renderer; 225 return renderer;
224 } 226 }
225 227
226 static int 228 static int
227 NDS_ActivateRenderer(SDL_Renderer * renderer) 229 NDS_ActivateRenderer(SDL_Renderer * renderer)
228 { 230 {
229 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; 231 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
230 /* stub. TODO: figure out what needs to be done, if anything. */ 232 /* stub. TODO: figure out what needs to be done, if anything. */
233 printf("!NDS_ActivateRenderer\n");
231 return 0; 234 return 0;
232 } 235 }
233 236
234 static int 237 static int
235 NDS_DisplayModeChanged(SDL_Renderer * renderer) 238 NDS_DisplayModeChanged(SDL_Renderer * renderer)
236 { 239 {
237 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; 240 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
238 /* stub. TODO: figure out what needs to be done */ 241 /* stub. TODO: figure out what needs to be done */
242 printf("!NDS_DisplayModeChanged\n");
239 return 0; 243 return 0;
240 } 244 }
241 245
242 static int 246 static int
243 NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) 247 NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
244 { 248 {
245 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; 249 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
246 NDS_TextureData *txdat = NULL; 250 NDS_TextureData *txdat = NULL;
251 printf("+NDS_CreateTexture\n");
247 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 252 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
248 SDL_SetError("Unsupported texture format"); 253 SDL_SetError("Unsupported texture format");
249 return -1; 254 return -1;
250 } else { 255 } else {
251 int bpp; 256 int bpp;
299 } else { 304 } else {
300 SDL_SetError("Texture too big for NDS hardware."); 305 SDL_SetError("Texture too big for NDS hardware.");
301 } 306 }
302 } 307 }
303 308
309 printf("-NDS_CreateTexture\n");
304 if (!texture->driverdata) { 310 if (!texture->driverdata) {
305 return -1; 311 return -1;
306 } 312 }
307 return 0; 313 return 0;
308 } 314 }
309 315
310 static int 316 static int
311 NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, 317 NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
312 void **pixels, int *pitch) 318 void **pixels, int *pitch)
313 { 319 {
320 printf("+NDS_QueryTexturePixels\n");
314 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 321 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
315 SDL_SetError("Unsupported texture format"); 322 SDL_SetError("Unsupported texture format");
316 return -1; 323 return -1;
317 } else { 324 } else {
318 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; 325 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
319 326
320 *pixels = txdat->vram; 327 *pixels = txdat->vram;
321 *pitch = txdat->dim.pitch; 328 *pitch = txdat->dim.pitch;
329 printf("-NDS_QueryTexturePixels\n");
322 return 0; 330 return 0;
323 } 331 }
324 } 332 }
325 333
326 static int 334 static int
327 NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, 335 NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
328 const SDL_Color * colors, int firstcolor, int ncolors) 336 const SDL_Color * colors, int firstcolor, int ncolors)
329 { 337 {
338 printf("+NDS_SetTexturePalette\n");
330 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 339 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
331 SDL_SetError("YUV textures don't have a palette"); 340 SDL_SetError("YUV textures don't have a palette");
332 return -1; 341 return -1;
333 } else { 342 } else {
334 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; 343 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
335 /* TODO: mess with 8-bit modes and/or 16-color palette modes */ 344 /* TODO: mess with 8-bit modes and/or 16-color palette modes */
345 printf("-NDS_SetTexturePalette\n");
336 return 0; 346 return 0;
337 } 347 }
338 } 348 }
339 349
340 static int 350 static int
341 NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, 351 NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
342 SDL_Color * colors, int firstcolor, int ncolors) 352 SDL_Color * colors, int firstcolor, int ncolors)
343 { 353 {
354 printf("+NDS_GetTexturePalette\n");
344 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 355 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
345 SDL_SetError("YUV textures don't have a palette"); 356 SDL_SetError("YUV textures don't have a palette");
346 return -1; 357 return -1;
347 } else { 358 } else {
348 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; 359 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
360 printf("-NDS_GetTexturePalette\n");
349 /* TODO: mess with 8-bit modes and/or 16-color palette modes */ 361 /* TODO: mess with 8-bit modes and/or 16-color palette modes */
350 return 0; 362 return 0;
351 } 363 }
352 } 364 }
353 365
354 static int 366 static int
355 NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) 367 NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
356 { 368 {
369 printf("!NDS_SetTextureColorMod\n");
357 /* stub. TODO: figure out what needs to be done, if anything */ 370 /* stub. TODO: figure out what needs to be done, if anything */
358 return 0; 371 return 0;
359 } 372 }
360 373
361 static int 374 static int
362 NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) 375 NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
363 { 376 {
377 printf("!NDS_SetTextureAlphaMod\n");
364 /* stub. TODO: figure out what needs to be done, if anything */ 378 /* stub. TODO: figure out what needs to be done, if anything */
365 return 0; 379 return 0;
366 } 380 }
367 381
368 static int 382 static int
369 NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) 383 NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
370 { 384 {
385 printf("!NDS_SetTextureBlendMode\n");
371 /* stub. TODO: figure out what needs to be done, if anything */ 386 /* stub. TODO: figure out what needs to be done, if anything */
372 return 0; 387 return 0;
373 } 388 }
374 389
375 static int 390 static int
376 NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) 391 NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
377 { 392 {
393 printf("!NDS_SetTextureScaleMode\n");
378 /* stub. TODO: figure out what needs to be done. 394 /* stub. TODO: figure out what needs to be done.
379 (NDS hardware scaling is nearest neighbor.) */ 395 (NDS hardware scaling is nearest neighbor.) */
380 return 0; 396 return 0;
381 } 397 }
382 398
383 static int 399 static int
384 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 400 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
385 const SDL_Rect * rect, const void *pixels, int pitch) 401 const SDL_Rect * rect, const void *pixels, int pitch)
386 { 402 {
403 printf("+NDS_UpdateTexture\n");
387 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 404 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
388 SDL_SetError("Unsupported texture format"); 405 SDL_SetError("Unsupported texture format");
389 return -1; 406 return -1;
390 } else { 407 } else {
391 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; 408 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
401 for (row = 0; row < rect->h; ++row) { 418 for (row = 0; row < rect->h; ++row) {
402 SDL_memcpy(dst, src, length); 419 SDL_memcpy(dst, src, length);
403 src += pitch; 420 src += pitch;
404 dst += txdat->dim.pitch; 421 dst += txdat->dim.pitch;
405 } 422 }
423 printf("-NDS_UpdateTexture\n");
406 return 0; 424 return 0;
407 } 425 }
408 } 426 }
409 427
410 static int 428 static int
411 NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 429 NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
412 const SDL_Rect * rect, int markDirty, void **pixels, 430 const SDL_Rect * rect, int markDirty, void **pixels,
413 int *pitch) 431 int *pitch)
414 { 432 {
433 printf("+NDS_LockTexture\n");
415 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 434 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
416 SDL_SetError("Unsupported texture format"); 435 SDL_SetError("Unsupported texture format");
417 return -1; 436 return -1;
418 } else { 437 } else {
419 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; 438 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
420 439
421 *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch 440 *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch
422 + rect->x * (txdat->dim.bpp/8)); 441 + rect->x * (txdat->dim.bpp/8));
423 *pitch = txdat->dim.pitch; 442 *pitch = txdat->dim.pitch;
443 printf("-NDS_LockTexture\n");
424 return 0; 444 return 0;
425 } 445 }
426 } 446 }
427 447
428 static void 448 static void
429 NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) 449 NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
430 { 450 {
431 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 451 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
432 SDL_SetError("Unsupported texture format"); 452 SDL_SetError("Unsupported texture format");
433 } 453 }
454 printf("!NDS_UnlockTexture\n");
434 } 455 }
435 456
436 static void 457 static void
437 NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, 458 NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
438 int numrects, const SDL_Rect * rects) 459 int numrects, const SDL_Rect * rects)
439 { /* stub */ 460 { /* stub */
461 printf("!NDS_DirtyTexture\n");
440 } 462 }
441 463
442 static int 464 static int
443 NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, 465 NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
444 Uint8 a, const SDL_Rect * rect) 466 Uint8 a, const SDL_Rect * rect)
446 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; 468 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
447 SDL_Rect real_rect = *rect; 469 SDL_Rect real_rect = *rect;
448 u16 color; 470 u16 color;
449 int i, j; 471 int i, j;
450 472
473 printf("+NDS_RenderFill\n");
451 /* TODO: make a single-color sprite and stretch it. 474 /* TODO: make a single-color sprite and stretch it.
452 color = RGB15(r>>3,g>>3,b>>3); 475 color = RGB15(r>>3,g>>3,b>>3);
453 for (i = real_rect.x; i < real_rect.x+real_rect.w; ++i) { 476 for (i = real_rect.x; i < real_rect.x+real_rect.w; ++i) {
454 for (j = real_rect.y; j < real_rect.y+real_rect.h; ++j) { 477 for (j = real_rect.y; j < real_rect.y+real_rect.h; ++j) {
455 data->fb[(j + real_rect.y) * 256 + i + real_rect.x] = 478 data->fb[(j + real_rect.y) * 256 + i + real_rect.x] =
456 0x8000 | color; 479 0x8000 | color;
457 } 480 }
458 }*/ 481 }*/
482 printf("-NDS_RenderFill\n");
459 return 0; 483 return 0;
460 } 484 }
461 485
462 static int 486 static int
463 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 487 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
465 { 489 {
466 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; 490 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
467 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 491 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
468 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 492 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
469 493
494 printf("+NDS_RenderCopy\n");
470 #if 0 495 #if 0
471 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 496 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
472 SDL_Surface *target = data->screens[data->current_screen]; 497 SDL_Surface *target = data->screens[data->current_screen];
473 void *pixels = 498 void *pixels =
474 (Uint8 *) target->pixels + dstrect->y * target->pitch + 499 (Uint8 *) target->pixels + dstrect->y * target->pitch +
483 SDL_Rect real_srcrect = *srcrect; 508 SDL_Rect real_srcrect = *srcrect;
484 SDL_Rect real_dstrect = *dstrect; 509 SDL_Rect real_dstrect = *dstrect;
485 return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect); 510 return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
486 } 511 }
487 #endif 512 #endif
513 printf("-NDS_RenderCopy\n");
488 return 0; 514 return 0;
489 } 515 }
490 516
491 517
492 static void 518 static void
493 NDS_RenderPresent(SDL_Renderer * renderer) 519 NDS_RenderPresent(SDL_Renderer * renderer)
494 { 520 {
495 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; 521 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
496 /* Send the data to the display TODO */ 522 /* Send the data to the display TODO */
497 523
524 printf("+NDS_RenderPresent\n");
498 /* Update the flipping chain, if any */ 525 /* Update the flipping chain, if any */
499 if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { 526 if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
500 swiWaitForVBlank(); 527 swiWaitForVBlank();
501 } 528 }
529 printf("-NDS_RenderPresent\n");
502 } 530 }
503 531
504 static void 532 static void
505 NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) 533 NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
506 { 534 {
535 printf("+NDS_DestroyTexture\n");
507 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 536 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
508 SDL_SetError("Unsupported texture format"); 537 SDL_SetError("Unsupported texture format");
509 } else { 538 } else {
510 /* free anything else allocated for texture */ 539 /* free anything else allocated for texture */
511 SDL_free(texture->driverdata); 540 SDL_free(texture->driverdata);
512 } 541 }
542 printf("-NDS_DestroyTexture\n");
513 } 543 }
514 544
515 static void 545 static void
516 NDS_DestroyRenderer(SDL_Renderer * renderer) 546 NDS_DestroyRenderer(SDL_Renderer * renderer)
517 { 547 {
518 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; 548 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
519 /*SDL_Window *window = SDL_GetWindowFromID(renderer->window); 549 /*SDL_Window *window = SDL_GetWindowFromID(renderer->window);
520 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/ 550 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/
521 int i; 551 int i;
522 552
553 printf("+NDS_DestroyRenderer\n");
523 if (data) { 554 if (data) {
524 /* TODO: free anything relevant. */ 555 /* TODO: free anything relevant. */
525 /*for (i = 0; i < SDL_arraysize(data->texture); ++i) { 556 /*for (i = 0; i < SDL_arraysize(data->texture); ++i) {
526 if (data->texture[i]) { 557 if (data->texture[i]) {
527 DestroyTexture(data->renderer, data->texture[i]); 558 DestroyTexture(data->renderer, data->texture[i]);
537 } 568 }
538 SDL_FreeDirtyRects(&data->dirty);*/ 569 SDL_FreeDirtyRects(&data->dirty);*/
539 SDL_free(data); 570 SDL_free(data);
540 } 571 }
541 SDL_free(renderer); 572 SDL_free(renderer);
573 printf("-NDS_DestroyRenderer\n");
542 } 574 }
543 575
544 /* vi: set ts=4 sw=4 expandtab: */ 576 /* vi: set ts=4 sw=4 expandtab: */