Advertise support for all supported texture formats.
authorSunny Sachanandani <sunnysachanandani@gmail.com>
Thu, 22 Jul 2010 10:53:41 +0530
changeset 46129a5db97cd569
parent 4611 a2ed55b5ff85
child 4613 56b888179f95
Advertise support for all supported texture formats.
include/SDL_video.h
src/video/x11/SDL_x11render.c
     1.1 --- a/include/SDL_video.h	Wed Jul 21 23:18:53 2010 +0530
     1.2 +++ b/include/SDL_video.h	Thu Jul 22 10:53:41 2010 +0530
     1.3 @@ -190,7 +190,7 @@
     1.4      Uint32 blend_modes;         /**< A mask of supported blend modes */
     1.5      Uint32 scale_modes;         /**< A mask of supported scale modes */
     1.6      Uint32 num_texture_formats; /**< The number of available texture formats */
     1.7 -    Uint32 texture_formats[20]; /**< The available texture formats */
     1.8 +    Uint32 texture_formats[50]; /**< The available texture formats */
     1.9      int max_texture_width;      /**< The maximimum texture width */
    1.10      int max_texture_height;     /**< The maximimum texture height */
    1.11  } SDL_RendererInfo;
     2.1 --- a/src/video/x11/SDL_x11render.c	Wed Jul 21 23:18:53 2010 +0530
     2.2 +++ b/src/video/x11/SDL_x11render.c	Thu Jul 22 10:53:41 2010 +0530
     2.3 @@ -252,6 +252,28 @@
     2.4  }
     2.5  #endif
     2.6  
     2.7 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
     2.8 +static Uint32
     2.9 +XRenderPictFormatToSDLPixelFormatEnum(XRenderPictFormat *pict_format) {
    2.10 +    if (pict_format->type != PictTypeDirect) {
    2.11 +        SDL_SetError("Indexed pict formats not supported ATM");
    2.12 +        return 0;
    2.13 +    }
    2.14 +    Uint32 Amask, Rmask, Gmask, Bmask;
    2.15 +    int bpp;
    2.16 +
    2.17 +    Rmask = pict_format->direct.redMask << pict_format->direct.red;
    2.18 +    Gmask = pict_format->direct.greenMask << pict_format->direct.green;
    2.19 +    Bmask = pict_format->direct.blueMask << pict_format->direct.blue;
    2.20 +    Amask = pict_format->direct.alphaMask << pict_format->direct.alpha;
    2.21 +    bpp = pict_format->depth;
    2.22 +
    2.23 +    Uint32 format;
    2.24 +    format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
    2.25 +    return format;
    2.26 +}
    2.27 +#endif
    2.28 +
    2.29  void
    2.30  X11_AddRenderDriver(_THIS)
    2.31  {
    2.32 @@ -270,7 +292,23 @@
    2.33  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
    2.34      int major, minor;
    2.35      if (CheckXRender(data->display, &major, &minor)) {
    2.36 -        info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_ARGB8888;
    2.37 +        XRenderPictFormat templ;
    2.38 +        templ.type = PictTypeDirect;
    2.39 +        XRenderPictFormat *pict_format;
    2.40 +        Uint32 format;
    2.41 +        int i = 0;
    2.42 +        while (info->num_texture_formats < 50) {
    2.43 +            pict_format =
    2.44 +                XRenderFindFormat(data->display, PictFormatType, &templ, i++);
    2.45 +            if (pict_format) {
    2.46 +                format = XRenderPictFormatToSDLPixelFormatEnum(pict_format);
    2.47 +                if (format != SDL_PIXELTYPE_UNKNOWN) {
    2.48 +                    info->texture_formats[info->num_texture_formats++] = format;
    2.49 +                }
    2.50 +            }
    2.51 +            else
    2.52 +                break;
    2.53 +        }
    2.54          info->blend_modes = (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD |
    2.55                               SDL_BLENDMODE_MOD | SDL_BLENDMODE_MASK);
    2.56          info->scale_modes = (SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_SLOW |
    2.57 @@ -379,11 +417,6 @@
    2.58                           0, 0,
    2.59                           0, 0,
    2.60                           window->w, window->h);
    2.61 -        /* Add some blending modes to the list of supported blending modes */
    2.62 -        renderer->info.blend_modes |=
    2.63 -            (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MASK | SDL_BLENDMODE_MOD);
    2.64 -        renderer->info.scale_modes |=
    2.65 -            (SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST);
    2.66          /* Create a clip mask that is used for rendering primitives. */
    2.67          data->stencil = XCreatePixmap(data->display, data->xwindow,
    2.68                                     window->w, window->h, 32);
    2.69 @@ -422,7 +455,6 @@
    2.70          data->blend_op = PictOpOver;
    2.71      }
    2.72  #endif
    2.73 -    
    2.74      if (flags & SDL_RENDERER_SINGLEBUFFER) {
    2.75          renderer->info.flags |=
    2.76              (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY);