comparison src/SDL_compat.c @ 5162:df758fce08e9

Create the video texture based on the available texture formats, not the backbuffer format.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 03 Feb 2011 01:13:48 -0800
parents 307ccc9c135e
children 88c656ffea44
comparison
equal deleted inserted replaced
5161:b3ccd1947786 5162:df758fce08e9
468 { 468 {
469 SDL_DisplayMode desktop_mode; 469 SDL_DisplayMode desktop_mode;
470 int window_x = SDL_WINDOWPOS_UNDEFINED; 470 int window_x = SDL_WINDOWPOS_UNDEFINED;
471 int window_y = SDL_WINDOWPOS_UNDEFINED; 471 int window_y = SDL_WINDOWPOS_UNDEFINED;
472 Uint32 window_flags; 472 Uint32 window_flags;
473 Uint32 desktop_format; 473 Uint32 surface_flags;
474 Uint32 i;
475 SDL_RendererInfo info;
474 Uint32 desired_format; 476 Uint32 desired_format;
475 Uint32 surface_flags;
476 477
477 if (!SDL_GetVideoDevice()) { 478 if (!SDL_GetVideoDevice()) {
478 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { 479 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
479 return NULL; 480 return NULL;
480 } 481 }
487 if (width == 0) { 488 if (width == 0) {
488 width = desktop_mode.w; 489 width = desktop_mode.w;
489 } 490 }
490 if (height == 0) { 491 if (height == 0) {
491 height = desktop_mode.h; 492 height = desktop_mode.h;
493 }
494 if (bpp == 0) {
495 bpp = SDL_BITSPERPIXEL(desktop_mode.format);
492 } 496 }
493 497
494 /* See if we can simply resize the existing window and surface */ 498 /* See if we can simply resize the existing window and surface */
495 if (SDL_ResizeVideoMode(width, height, bpp, flags) == 0) { 499 if (SDL_ResizeVideoMode(width, height, bpp, flags) == 0) {
496 return SDL_PublicSurface; 500 return SDL_PublicSurface;
557 } 561 }
558 if (window_flags & SDL_WINDOW_BORDERLESS) { 562 if (window_flags & SDL_WINDOW_BORDERLESS) {
559 surface_flags |= SDL_NOFRAME; 563 surface_flags |= SDL_NOFRAME;
560 } 564 }
561 565
562 /* Set up the desired display mode */
563 desktop_format = desktop_mode.format;
564 if (desktop_format && ((flags & SDL_ANYFORMAT)
565 || (bpp == SDL_BITSPERPIXEL(desktop_format)))) {
566 desired_format = desktop_format;
567 } else {
568 switch (bpp) {
569 case 0:
570 if (desktop_format) {
571 desired_format = desktop_format;
572 } else {
573 desired_format = SDL_PIXELFORMAT_RGB888;
574 }
575 bpp = SDL_BITSPERPIXEL(desired_format);
576 break;
577 case 8:
578 desired_format = SDL_PIXELFORMAT_INDEX8;
579 break;
580 case 15:
581 desired_format = SDL_PIXELFORMAT_RGB555;
582 break;
583 case 16:
584 desired_format = SDL_PIXELFORMAT_RGB565;
585 break;
586 case 24:
587 desired_format = SDL_PIXELFORMAT_RGB24;
588 break;
589 case 32:
590 desired_format = SDL_PIXELFORMAT_RGB888;
591 break;
592 default:
593 SDL_SetError("Unsupported bpp in SDL_SetVideoMode()");
594 return NULL;
595 }
596 }
597
598 /* Set up the desired display mode */
599 if (flags & SDL_FULLSCREEN) {
600 SDL_DisplayMode mode;
601
602 SDL_zero(mode);
603 mode.format = desired_format;
604 if (SDL_SetWindowDisplayMode(SDL_VideoWindow, &mode) < 0) {
605 return NULL;
606 }
607 }
608
609 /* If we're in OpenGL mode, just create a stub surface and we're done! */ 566 /* If we're in OpenGL mode, just create a stub surface and we're done! */
610 if (flags & SDL_OPENGL) { 567 if (flags & SDL_OPENGL) {
611 SDL_VideoContext = SDL_GL_CreateContext(SDL_VideoWindow); 568 SDL_VideoContext = SDL_GL_CreateContext(SDL_VideoWindow);
612 if (!SDL_VideoContext) { 569 if (!SDL_VideoContext) {
613 return NULL; 570 return NULL;
630 if (!SDL_VideoRenderer) { 587 if (!SDL_VideoRenderer) {
631 return NULL; 588 return NULL;
632 } 589 }
633 590
634 /* Create a texture for the screen surface */ 591 /* Create a texture for the screen surface */
592 SDL_GetRendererInfo(SDL_VideoRenderer, &info);
593 desired_format = info.texture_formats[0];
594 for (i = 0; i < info.num_texture_formats; ++i) {
595 if (!SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
596 desired_format = info.texture_formats[i];
597 break;
598 }
599 }
635 SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desired_format, 600 SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desired_format,
636 SDL_TEXTUREACCESS_STREAMING, 601 SDL_TEXTUREACCESS_STREAMING,
637 width, height); 602 width, height);
638
639 if (!SDL_VideoTexture) {
640 SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desktop_format,
641 SDL_TEXTUREACCESS_STREAMING,
642 width, height);
643 }
644 if (!SDL_VideoTexture) { 603 if (!SDL_VideoTexture) {
645 return NULL; 604 return NULL;
646 } 605 }
647 606
648 /* Create the screen surface */ 607 /* Create the screen surface */