comparison src/video/SDL_video.c @ 1985:8055185ae4ed

Added source color and alpha modulation support. Added perl script to generate optimized render copy functions.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 28 Aug 2006 03:17:39 +0000
parents 3f21778e7433
children da8332c8f480
comparison
equal deleted inserted replaced
1984:b910bcabec26 1985:8055185ae4ed
1508 texture->id = _this->next_object_id++; 1508 texture->id = _this->next_object_id++;
1509 texture->format = format; 1509 texture->format = format;
1510 texture->access = access; 1510 texture->access = access;
1511 texture->w = w; 1511 texture->w = w;
1512 texture->h = h; 1512 texture->h = h;
1513 texture->r = 255;
1514 texture->g = 255;
1515 texture->b = 255;
1516 texture->a = 255;
1513 texture->renderer = renderer; 1517 texture->renderer = renderer;
1514 1518
1515 if (renderer->CreateTexture(renderer, texture) < 0) { 1519 if (renderer->CreateTexture(renderer, texture) < 0) {
1516 if (renderer->DestroyTexture) { 1520 if (renderer->DestroyTexture) {
1517 renderer->DestroyTexture(renderer, texture); 1521 renderer->DestroyTexture(renderer, texture);
1770 return renderer->GetTexturePalette(renderer, texture, colors, firstcolor, 1774 return renderer->GetTexturePalette(renderer, texture, colors, firstcolor,
1771 ncolors); 1775 ncolors);
1772 } 1776 }
1773 1777
1774 int 1778 int
1779 SDL_SetTextureColorMod(SDL_TextureID textureID, Uint8 r, Uint8 g, Uint8 b)
1780 {
1781 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1782 SDL_Renderer *renderer;
1783
1784 if (!texture) {
1785 return -1;
1786 }
1787
1788 renderer = texture->renderer;
1789 if (!renderer->SetTextureColorMod) {
1790 return -1;
1791 }
1792 if (r < 255 | g < 255 | b < 255) {
1793 texture->modMode |= SDL_TEXTUREMODULATE_COLOR;
1794 } else {
1795 texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
1796 }
1797 texture->r = r;
1798 texture->g = g;
1799 texture->b = b;
1800 return renderer->SetTextureColorMod(renderer, texture);
1801 }
1802
1803 int
1804 SDL_GetTextureColorMod(SDL_TextureID textureID, Uint8 * r, Uint8 * g,
1805 Uint8 * b)
1806 {
1807 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1808 SDL_Renderer *renderer;
1809
1810 if (!texture) {
1811 return -1;
1812 }
1813
1814 renderer = texture->renderer;
1815 if (r) {
1816 *r = texture->r;
1817 }
1818 if (g) {
1819 *g = texture->g;
1820 }
1821 if (b) {
1822 *b = texture->b;
1823 }
1824 return 0;
1825 }
1826
1827 int
1828 SDL_SetTextureAlphaMod(SDL_TextureID textureID, Uint8 alpha)
1829 {
1830 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1831 SDL_Renderer *renderer;
1832
1833 if (!texture) {
1834 return -1;
1835 }
1836
1837 renderer = texture->renderer;
1838 if (!renderer->SetTextureAlphaMod) {
1839 return -1;
1840 }
1841 if (alpha < 255) {
1842 texture->modMode |= SDL_TEXTUREMODULATE_ALPHA;
1843 } else {
1844 texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
1845 }
1846 texture->a = alpha;
1847 return renderer->SetTextureAlphaMod(renderer, texture);
1848 }
1849
1850 int
1851 SDL_GetTextureAlphaMod(SDL_TextureID textureID, Uint8 * alpha)
1852 {
1853 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1854 SDL_Renderer *renderer;
1855
1856 if (!texture) {
1857 return -1;
1858 }
1859
1860 if (alpha) {
1861 *alpha = texture->a;
1862 }
1863 return 0;
1864 }
1865
1866 int
1867 SDL_SetTextureBlendMode(SDL_TextureID textureID, int blendMode)
1868 {
1869 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1870 SDL_Renderer *renderer;
1871
1872 if (!texture) {
1873 return -1;
1874 }
1875
1876 renderer = texture->renderer;
1877 if (!renderer->SetTextureBlendMode) {
1878 return -1;
1879 }
1880 texture->blendMode = blendMode;
1881 return renderer->SetTextureBlendMode(renderer, texture);
1882 }
1883
1884 int
1885 SDL_GetTextureBlendMode(SDL_TextureID textureID, int *blendMode)
1886 {
1887 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1888 SDL_Renderer *renderer;
1889
1890 if (!texture) {
1891 return -1;
1892 }
1893
1894 if (blendMode) {
1895 *blendMode = texture->blendMode;
1896 }
1897 return 0;
1898 }
1899
1900 int
1901 SDL_SetTextureScaleMode(SDL_TextureID textureID, int scaleMode)
1902 {
1903 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1904 SDL_Renderer *renderer;
1905
1906 if (!texture) {
1907 return -1;
1908 }
1909
1910 renderer = texture->renderer;
1911 if (!renderer->SetTextureScaleMode) {
1912 return -1;
1913 }
1914 texture->scaleMode = scaleMode;
1915 return renderer->SetTextureScaleMode(renderer, texture);
1916 }
1917
1918 int
1919 SDL_GetTextureScaleMode(SDL_TextureID textureID, int *scaleMode)
1920 {
1921 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1922 SDL_Renderer *renderer;
1923
1924 if (!texture) {
1925 return -1;
1926 }
1927
1928 if (scaleMode) {
1929 *scaleMode = texture->scaleMode;
1930 }
1931 return 0;
1932 }
1933
1934 int
1775 SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect, 1935 SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect,
1776 const void *pixels, int pitch) 1936 const void *pixels, int pitch)
1777 { 1937 {
1778 SDL_Texture *texture = SDL_GetTextureFromID(textureID); 1938 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1779 SDL_Renderer *renderer; 1939 SDL_Renderer *renderer;
1862 } 2022 }
1863 renderer->DirtyTexture(renderer, texture, numrects, rects); 2023 renderer->DirtyTexture(renderer, texture, numrects, rects);
1864 } 2024 }
1865 2025
1866 int 2026 int
1867 SDL_RenderFill(const SDL_Rect * rect, Uint32 color) 2027 SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect)
1868 { 2028 {
1869 SDL_Renderer *renderer; 2029 SDL_Renderer *renderer;
1870 SDL_Window *window; 2030 SDL_Window *window;
1871 SDL_Rect real_rect; 2031 SDL_Rect real_rect;
1872 2032
1889 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { 2049 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
1890 return 0; 2050 return 0;
1891 } 2051 }
1892 } 2052 }
1893 2053
1894 return renderer->RenderFill(renderer, &real_rect, color); 2054 return renderer->RenderFill(renderer, r, g, b, a, &real_rect);
1895 } 2055 }
1896 2056
1897 int 2057 int
1898 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect, 2058 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
1899 const SDL_Rect * dstrect, int blendMode, int scaleMode) 2059 const SDL_Rect * dstrect)
1900 { 2060 {
1901 SDL_Texture *texture = SDL_GetTextureFromID(textureID); 2061 SDL_Texture *texture = SDL_GetTextureFromID(textureID);
1902 SDL_Renderer *renderer; 2062 SDL_Renderer *renderer;
1903 SDL_Window *window; 2063 SDL_Window *window;
1904 SDL_Rect real_srcrect; 2064 SDL_Rect real_srcrect;
1930 real_dstrect.w = window->w; 2090 real_dstrect.w = window->w;
1931 real_dstrect.h = window->h; 2091 real_dstrect.h = window->h;
1932 } 2092 }
1933 2093
1934 return renderer->RenderCopy(renderer, texture, &real_srcrect, 2094 return renderer->RenderCopy(renderer, texture, &real_srcrect,
1935 &real_dstrect, blendMode, scaleMode); 2095 &real_dstrect);
1936 } 2096 }
1937 2097
1938 void 2098 void
1939 SDL_RenderPresent(void) 2099 SDL_RenderPresent(void)
1940 { 2100 {