Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 3178:72edc980789b
1. SDL_CreateTextureFromSurface() now tries to find surface's pixel format.
2. SDL_CreateTextureFromSurface() now has best texture format search for non-alpha pixel formats.
3. Added comparision for pixels packed order to the video mode sorting callback to avoid mixing 1555/565/4444 pixel formats.
4. Added sorting call for current video mode list after each new video mode addition, because SDL_GetClosestDisplayMode() requires video modes to be sorted, and this is one place only where we can detect video modes addition.
author | Mike Gorchak <lestat@i.com.ua> |
---|---|
date | Tue, 09 Jun 2009 08:56:43 +0000 |
parents | f294338ca6eb |
children | 51750b7a966f |
comparison
equal
deleted
inserted
replaced
3177:efe3b3971e4f | 3178:72edc980789b |
---|---|
144 if (a.h != b.h) { | 144 if (a.h != b.h) { |
145 return b.h - a.h; | 145 return b.h - a.h; |
146 } | 146 } |
147 if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) { | 147 if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) { |
148 return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format); | 148 return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format); |
149 } | |
150 if (SDL_PIXELLAYOUT(a.format) != SDL_PIXELLAYOUT(b.format)) { | |
151 return SDL_PIXELLAYOUT(b.format) - SDL_PIXELLAYOUT(a.format); | |
149 } | 152 } |
150 if (a.refresh_rate != b.refresh_rate) { | 153 if (a.refresh_rate != b.refresh_rate) { |
151 return b.refresh_rate - a.refresh_rate; | 154 return b.refresh_rate - a.refresh_rate; |
152 } | 155 } |
153 return 0; | 156 return 0; |
406 display->max_display_modes += 32; | 409 display->max_display_modes += 32; |
407 } | 410 } |
408 modes[nmodes] = *mode; | 411 modes[nmodes] = *mode; |
409 display->num_display_modes++; | 412 display->num_display_modes++; |
410 | 413 |
414 /* Re-sort video modes */ | |
415 SDL_qsort(display->display_modes, display->num_display_modes, | |
416 sizeof(SDL_DisplayMode), cmpmodes); | |
417 | |
411 return SDL_TRUE; | 418 return SDL_TRUE; |
412 } | 419 } |
413 | 420 |
414 int | 421 int |
415 SDL_GetNumDisplayModes() | 422 SDL_GetNumDisplayModes() |
1618 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { | 1625 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { |
1619 SDL_SetError("Unknown pixel format"); | 1626 SDL_SetError("Unknown pixel format"); |
1620 return 0; | 1627 return 0; |
1621 } | 1628 } |
1622 } else { | 1629 } else { |
1623 /* FIXME: Get the best supported texture format */ | |
1624 if (surface->format->Amask | 1630 if (surface->format->Amask |
1625 || !(surface->map->info.flags & | 1631 || !(surface->map->info.flags & |
1626 (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) { | 1632 (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) { |
1633 int it; | |
1634 int pfmt; | |
1635 | |
1636 /* Pixel formats, sorted by best first */ | |
1637 static const Uint32 sdl_pformats[]={ | |
1638 SDL_PIXELFORMAT_ARGB8888, | |
1639 SDL_PIXELFORMAT_RGBA8888, | |
1640 SDL_PIXELFORMAT_ABGR8888, | |
1641 SDL_PIXELFORMAT_BGRA8888, | |
1642 SDL_PIXELFORMAT_RGB888, | |
1643 SDL_PIXELFORMAT_BGR888, | |
1644 SDL_PIXELFORMAT_RGB24, | |
1645 SDL_PIXELFORMAT_BGR24, | |
1646 SDL_PIXELFORMAT_RGB565, | |
1647 SDL_PIXELFORMAT_BGR565, | |
1648 SDL_PIXELFORMAT_ARGB1555, | |
1649 SDL_PIXELFORMAT_ABGR1555, | |
1650 SDL_PIXELFORMAT_RGB555, | |
1651 SDL_PIXELFORMAT_BGR555, | |
1652 SDL_PIXELFORMAT_ARGB4444, | |
1653 SDL_PIXELFORMAT_ABGR4444, | |
1654 SDL_PIXELFORMAT_RGB444, | |
1655 SDL_PIXELFORMAT_ARGB2101010, | |
1656 SDL_PIXELFORMAT_INDEX8, | |
1657 SDL_PIXELFORMAT_INDEX4LSB, | |
1658 SDL_PIXELFORMAT_INDEX4MSB, | |
1659 SDL_PIXELFORMAT_RGB332, | |
1660 SDL_PIXELFORMAT_INDEX1LSB, | |
1661 SDL_PIXELFORMAT_INDEX1MSB, | |
1662 SDL_PIXELFORMAT_UNKNOWN}; | |
1663 | |
1627 bpp = fmt->BitsPerPixel; | 1664 bpp = fmt->BitsPerPixel; |
1628 Rmask = fmt->Rmask; | 1665 Rmask = fmt->Rmask; |
1629 Gmask = fmt->Gmask; | 1666 Gmask = fmt->Gmask; |
1630 Bmask = fmt->Bmask; | 1667 Bmask = fmt->Bmask; |
1631 Amask = fmt->Amask; | 1668 Amask = fmt->Amask; |
1669 | |
1670 format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask); | |
1671 if (!format) { | |
1672 SDL_SetError("Unknown pixel format"); | |
1673 return 0; | |
1674 } | |
1675 | |
1676 /* Search requested format in the supported texture */ | |
1677 /* formats by current renderer */ | |
1678 for (it=0; it<renderer->info.num_texture_formats; it++) | |
1679 { | |
1680 if (renderer->info.texture_formats[it]==format) | |
1681 { | |
1682 break; | |
1683 } | |
1684 } | |
1685 | |
1686 /* If requested format can't be found, search any best */ | |
1687 /* format which renderer provides */ | |
1688 if (it==renderer->info.num_texture_formats) | |
1689 { | |
1690 pfmt=0; | |
1691 for (;;) | |
1692 { | |
1693 if (sdl_pformats[pfmt]==SDL_PIXELFORMAT_UNKNOWN) | |
1694 { | |
1695 break; | |
1696 } | |
1697 | |
1698 for (it=0; it<renderer->info.num_texture_formats; it++) | |
1699 { | |
1700 if (renderer->info.texture_formats[it]==sdl_pformats[pfmt]) | |
1701 { | |
1702 break; | |
1703 } | |
1704 } | |
1705 | |
1706 if (it!=renderer->info.num_texture_formats) | |
1707 { | |
1708 /* The best format has been found */ | |
1709 break; | |
1710 } | |
1711 pfmt++; | |
1712 } | |
1713 | |
1714 /* If any format can't be found, then return an error */ | |
1715 if (it==renderer->info.num_texture_formats) | |
1716 { | |
1717 SDL_SetError("Any of the supported pixel formats can't be found"); | |
1718 return 0; | |
1719 } | |
1720 | |
1721 /* Convert found pixel format back to color masks */ | |
1722 if (SDL_PixelFormatEnumToMasks(renderer->info.texture_formats[it], | |
1723 &bpp, &Rmask, &Gmask, &Bmask, &Amask)!=SDL_TRUE) | |
1724 { | |
1725 SDL_SetError("Unknown pixel format"); | |
1726 return 0; | |
1727 } | |
1728 } | |
1632 } else { | 1729 } else { |
1633 /* Need a format with alpha */ | 1730 /* Need a format with alpha */ |
1634 int it; | 1731 int it; |
1635 int apfmt; | 1732 int apfmt; |
1636 | 1733 |
1646 SDL_PIXELFORMAT_ABGR4444, | 1743 SDL_PIXELFORMAT_ABGR4444, |
1647 SDL_PIXELFORMAT_ARGB2101010, | 1744 SDL_PIXELFORMAT_ARGB2101010, |
1648 SDL_PIXELFORMAT_UNKNOWN | 1745 SDL_PIXELFORMAT_UNKNOWN |
1649 }; | 1746 }; |
1650 | 1747 |
1651 bpp = 32; | 1748 if (surface->format->Amask) { |
1652 Rmask = 0x00FF0000; | 1749 /* If surface already has alpha, then try an original */ |
1653 Gmask = 0x0000FF00; | 1750 /* surface format first */ |
1654 Bmask = 0x000000FF; | 1751 bpp = fmt->BitsPerPixel; |
1655 Amask = 0xFF000000; | 1752 Rmask = fmt->Rmask; |
1753 Gmask = fmt->Gmask; | |
1754 Bmask = fmt->Bmask; | |
1755 Amask = fmt->Amask; | |
1756 } else { | |
1757 bpp = 32; | |
1758 Rmask = 0x00FF0000; | |
1759 Gmask = 0x0000FF00; | |
1760 Bmask = 0x000000FF; | |
1761 Amask = 0xFF000000; | |
1762 } | |
1656 | 1763 |
1657 format = | 1764 format = |
1658 SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask); | 1765 SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask); |
1659 if (!format) { | 1766 if (!format) { |
1660 SDL_SetError("Unknown pixel format"); | 1767 SDL_SetError("Unknown pixel format"); |