Create the video texture based on the available texture formats, not the backbuffer format.
authorSam Lantinga <slouken@libsdl.org>
Thu, 03 Feb 2011 01:13:48 -0800
changeset 5159df758fce08e9
parent 5158 b3ccd1947786
child 5160 53eaa01ab100
Create the video texture based on the available texture formats, not the backbuffer format.
src/SDL_compat.c
     1.1 --- a/src/SDL_compat.c	Thu Feb 03 00:54:29 2011 -0800
     1.2 +++ b/src/SDL_compat.c	Thu Feb 03 01:13:48 2011 -0800
     1.3 @@ -470,9 +470,10 @@
     1.4      int window_x = SDL_WINDOWPOS_UNDEFINED;
     1.5      int window_y = SDL_WINDOWPOS_UNDEFINED;
     1.6      Uint32 window_flags;
     1.7 -    Uint32 desktop_format;
     1.8 +    Uint32 surface_flags;
     1.9 +    Uint32 i;
    1.10 +    SDL_RendererInfo info;
    1.11      Uint32 desired_format;
    1.12 -    Uint32 surface_flags;
    1.13  
    1.14      if (!SDL_GetVideoDevice()) {
    1.15          if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
    1.16 @@ -490,6 +491,9 @@
    1.17      if (height == 0) {
    1.18          height = desktop_mode.h;
    1.19      }
    1.20 +    if (bpp == 0) {
    1.21 +        bpp = SDL_BITSPERPIXEL(desktop_mode.format);
    1.22 +    }
    1.23  
    1.24      /* See if we can simply resize the existing window and surface */
    1.25      if (SDL_ResizeVideoMode(width, height, bpp, flags) == 0) {
    1.26 @@ -559,53 +563,6 @@
    1.27          surface_flags |= SDL_NOFRAME;
    1.28      }
    1.29  
    1.30 -    /* Set up the desired display mode */
    1.31 -    desktop_format = desktop_mode.format;
    1.32 -    if (desktop_format && ((flags & SDL_ANYFORMAT)
    1.33 -                           || (bpp == SDL_BITSPERPIXEL(desktop_format)))) {
    1.34 -        desired_format = desktop_format;
    1.35 -    } else {
    1.36 -        switch (bpp) {
    1.37 -        case 0:
    1.38 -            if (desktop_format) {
    1.39 -                desired_format = desktop_format;
    1.40 -            } else {
    1.41 -                desired_format = SDL_PIXELFORMAT_RGB888;
    1.42 -            }
    1.43 -            bpp = SDL_BITSPERPIXEL(desired_format);
    1.44 -            break;
    1.45 -        case 8:
    1.46 -            desired_format = SDL_PIXELFORMAT_INDEX8;
    1.47 -            break;
    1.48 -        case 15:
    1.49 -            desired_format = SDL_PIXELFORMAT_RGB555;
    1.50 -            break;
    1.51 -        case 16:
    1.52 -            desired_format = SDL_PIXELFORMAT_RGB565;
    1.53 -            break;
    1.54 -        case 24:
    1.55 -            desired_format = SDL_PIXELFORMAT_RGB24;
    1.56 -            break;
    1.57 -        case 32:
    1.58 -            desired_format = SDL_PIXELFORMAT_RGB888;
    1.59 -            break;
    1.60 -        default:
    1.61 -            SDL_SetError("Unsupported bpp in SDL_SetVideoMode()");
    1.62 -            return NULL;
    1.63 -        }
    1.64 -    }
    1.65 -
    1.66 -    /* Set up the desired display mode */
    1.67 -    if (flags & SDL_FULLSCREEN) {
    1.68 -        SDL_DisplayMode mode;
    1.69 -
    1.70 -        SDL_zero(mode);
    1.71 -        mode.format = desired_format;
    1.72 -        if (SDL_SetWindowDisplayMode(SDL_VideoWindow, &mode) < 0) {
    1.73 -            return NULL;
    1.74 -        }
    1.75 -    }
    1.76 -
    1.77      /* If we're in OpenGL mode, just create a stub surface and we're done! */
    1.78      if (flags & SDL_OPENGL) {
    1.79          SDL_VideoContext = SDL_GL_CreateContext(SDL_VideoWindow);
    1.80 @@ -632,15 +589,17 @@
    1.81      }
    1.82  
    1.83      /* Create a texture for the screen surface */
    1.84 +    SDL_GetRendererInfo(SDL_VideoRenderer, &info);
    1.85 +    desired_format = info.texture_formats[0];
    1.86 +    for (i = 0; i < info.num_texture_formats; ++i) {
    1.87 +        if (!SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
    1.88 +            desired_format = info.texture_formats[i];
    1.89 +            break;
    1.90 +        }
    1.91 +    }
    1.92      SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desired_format,
    1.93                                           SDL_TEXTUREACCESS_STREAMING,
    1.94                                           width, height);
    1.95 -
    1.96 -    if (!SDL_VideoTexture) {
    1.97 -        SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desktop_format,
    1.98 -                                             SDL_TEXTUREACCESS_STREAMING,
    1.99 -                                             width, height);
   1.100 -    }
   1.101      if (!SDL_VideoTexture) {
   1.102          return NULL;
   1.103      }