Mercurial > mplayer.hg
comparison libvo/gl_common.c @ 36123:99c8f7888cbe
Simplify drawing OpenGL vertices.
Avoid duplicating the calculation, and use
triangle strip instead of quads also for desktop
OpenGL.
author | reimar |
---|---|
date | Sat, 04 May 2013 10:30:07 +0000 |
parents | cf45e1421a71 |
children | c4075d9e329d |
comparison
equal
deleted
inserted
replaced
36122:cf45e1421a71 | 36123:99c8f7888cbe |
---|---|
1811 mpglDisable(GL_BLEND); | 1811 mpglDisable(GL_BLEND); |
1812 break; | 1812 break; |
1813 } | 1813 } |
1814 } | 1814 } |
1815 | 1815 |
1816 /** | 1816 static void draw_vertices(GLfloat x, GLfloat y, GLfloat w, GLfloat h, |
1817 * \brief draw a texture part at given 2D coordinates | 1817 GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th, |
1818 * \param x screen top coordinate | 1818 GLfloat tx2, GLfloat ty2, GLfloat tw2, GLfloat th2, |
1819 * \param y screen left coordinate | 1819 int is_yv12, int use_stipple) |
1820 * \param w screen width coordinate | 1820 { |
1821 * \param h screen height coordinate | 1821 int i; |
1822 * \param tx texture top coordinate in pixels | 1822 GLfloat vertices [8] = { x, y, x, y + h, x + w, y, x + w, y + h}; |
1823 * \param ty texture left coordinate in pixels | 1823 GLfloat texcoords [8] = {tx, ty, tx, ty + th, tx + tw, ty, tx + tw, ty + th}; |
1824 * \param tw texture part width in pixels | 1824 GLfloat texcoords2[8] = {tx2, ty2, tx2, ty2 + th2, tx2 + tw2, ty2, tx2 + tw2, ty2 + th2}; |
1825 * \param th texture part height in pixels | |
1826 * \param sx width of texture in pixels | |
1827 * \param sy height of texture in pixels | |
1828 * \param rect_tex whether this texture uses texture_rectangle extension | |
1829 * \param is_yv12 if != 0, also draw the textures from units 1 and 2, | |
1830 * bits 8 - 15 and 16 - 23 specify the x and y scaling of those textures | |
1831 * \param flip flip the texture upside down | |
1832 * \param use_stipple overlay texture 3 as 4x4 alpha stipple | |
1833 * \ingroup gltexture | |
1834 */ | |
1835 void glDrawTex(GLfloat x, GLfloat y, GLfloat w, GLfloat h, | |
1836 GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th, | |
1837 int sx, int sy, int rect_tex, int is_yv12, int flip, | |
1838 int use_stipple) { | |
1839 int chroma_x_shift = (is_yv12 >> 8) & 31; | |
1840 int chroma_y_shift = (is_yv12 >> 16) & 31; | |
1841 GLfloat texcoords3[8] = {vo_dx / 4.0, vo_dy / 4.0, vo_dx / 4.0, (vo_dy + vo_dheight) / 4.0, (vo_dx + vo_dwidth) / 4.0, vo_dy / 4.0, (vo_dx + vo_dwidth) / 4.0, (vo_dy + vo_dheight) / 4.0}; | 1825 GLfloat texcoords3[8] = {vo_dx / 4.0, vo_dy / 4.0, vo_dx / 4.0, (vo_dy + vo_dheight) / 4.0, (vo_dx + vo_dwidth) / 4.0, vo_dy / 4.0, (vo_dx + vo_dwidth) / 4.0, (vo_dy + vo_dheight) / 4.0}; |
1842 GLfloat xscale = 1 << chroma_x_shift; | |
1843 GLfloat yscale = 1 << chroma_y_shift; | |
1844 GLfloat tx2 = tx / xscale, ty2 = ty / yscale, tw2 = tw / xscale, th2 = th / yscale; | |
1845 if (!rect_tex) { | |
1846 tx /= sx; ty /= sy; tw /= sx; th /= sy; | |
1847 tx2 = tx, ty2 = ty, tw2 = tw, th2 = th; | |
1848 } | |
1849 if (flip) { | |
1850 y += h; | |
1851 h = -h; | |
1852 } | |
1853 | 1826 |
1854 if (!mpglBegin) { | 1827 if (!mpglBegin) { |
1855 GLfloat vertices [8] = { x, y, x, y + h, x + w, y, x + w, y + h}; | |
1856 GLfloat texcoords [8] = {tx, ty, tx, ty + th, tx + tw, ty, tx + tw, ty + th}; | |
1857 GLfloat texcoords2[8] = {tx2, ty2, tx2, ty2 + th2, tx2 + tw2, ty2, tx2 + tw2, ty2 + th2}; | |
1858 mpglEnableClientState(GL_VERTEX_ARRAY); | 1828 mpglEnableClientState(GL_VERTEX_ARRAY); |
1859 mpglVertexPointer(2, GL_FLOAT, 0, vertices); | 1829 mpglVertexPointer(2, GL_FLOAT, 0, vertices); |
1860 mpglEnableClientState(GL_TEXTURE_COORD_ARRAY); | 1830 mpglEnableClientState(GL_TEXTURE_COORD_ARRAY); |
1861 mpglTexCoordPointer(2, GL_FLOAT, 0, texcoords); | 1831 mpglTexCoordPointer(2, GL_FLOAT, 0, texcoords); |
1862 if (use_stipple) { | 1832 if (use_stipple) { |
1887 } | 1857 } |
1888 mpglDisableClientState(GL_VERTEX_ARRAY); | 1858 mpglDisableClientState(GL_VERTEX_ARRAY); |
1889 return; | 1859 return; |
1890 } | 1860 } |
1891 | 1861 |
1892 mpglBegin(GL_QUADS); | 1862 mpglBegin(GL_TRIANGLE_STRIP); |
1893 mpglTexCoord2f(tx, ty); | 1863 for (i = 0; i < 4; i++) { |
1894 if (is_yv12) { | 1864 int px = 2*i; |
1895 mpglMultiTexCoord2f(GL_TEXTURE1, tx2, ty2); | 1865 int py = 2*i + 1; |
1896 mpglMultiTexCoord2f(GL_TEXTURE2, tx2, ty2); | 1866 mpglTexCoord2f(texcoords[px], texcoords[py]); |
1897 } | 1867 if (is_yv12) { |
1898 if (use_stipple) | 1868 mpglMultiTexCoord2f(GL_TEXTURE1, texcoords2[px], texcoords[py]); |
1899 mpglMultiTexCoord2f(GL_TEXTURE3, texcoords3[0], texcoords3[1]); | 1869 mpglMultiTexCoord2f(GL_TEXTURE2, texcoords2[px], texcoords[py]); |
1900 mpglVertex2f(x, y); | 1870 } |
1901 mpglTexCoord2f(tx, ty + th); | 1871 if (use_stipple) |
1902 if (is_yv12) { | 1872 mpglMultiTexCoord2f(GL_TEXTURE3, texcoords3[px], texcoords3[py]); |
1903 mpglMultiTexCoord2f(GL_TEXTURE1, tx2, ty2 + th2); | 1873 mpglVertex2f(vertices[px], vertices[py]); |
1904 mpglMultiTexCoord2f(GL_TEXTURE2, tx2, ty2 + th2); | 1874 } |
1905 } | |
1906 if (use_stipple) | |
1907 mpglMultiTexCoord2f(GL_TEXTURE3, texcoords3[2], texcoords3[3]); | |
1908 mpglVertex2f(x, y + h); | |
1909 mpglTexCoord2f(tx + tw, ty + th); | |
1910 if (is_yv12) { | |
1911 mpglMultiTexCoord2f(GL_TEXTURE1, tx2 + tw2, ty2 + th2); | |
1912 mpglMultiTexCoord2f(GL_TEXTURE2, tx2 + tw2, ty2 + th2); | |
1913 } | |
1914 if (use_stipple) | |
1915 mpglMultiTexCoord2f(GL_TEXTURE3, texcoords3[6], texcoords3[7]); | |
1916 mpglVertex2f(x + w, y + h); | |
1917 mpglTexCoord2f(tx + tw, ty); | |
1918 if (is_yv12) { | |
1919 mpglMultiTexCoord2f(GL_TEXTURE1, tx2 + tw2, ty2); | |
1920 mpglMultiTexCoord2f(GL_TEXTURE2, tx2 + tw2, ty2); | |
1921 } | |
1922 if (use_stipple) | |
1923 mpglMultiTexCoord2f(GL_TEXTURE3, texcoords3[4], texcoords3[5]); | |
1924 mpglVertex2f(x + w, y); | |
1925 mpglEnd(); | 1875 mpglEnd(); |
1876 } | |
1877 | |
1878 /** | |
1879 * \brief draw a texture part at given 2D coordinates | |
1880 * \param x screen top coordinate | |
1881 * \param y screen left coordinate | |
1882 * \param w screen width coordinate | |
1883 * \param h screen height coordinate | |
1884 * \param tx texture top coordinate in pixels | |
1885 * \param ty texture left coordinate in pixels | |
1886 * \param tw texture part width in pixels | |
1887 * \param th texture part height in pixels | |
1888 * \param sx width of texture in pixels | |
1889 * \param sy height of texture in pixels | |
1890 * \param rect_tex whether this texture uses texture_rectangle extension | |
1891 * \param is_yv12 if != 0, also draw the textures from units 1 and 2, | |
1892 * bits 8 - 15 and 16 - 23 specify the x and y scaling of those textures | |
1893 * \param flip flip the texture upside down | |
1894 * \param use_stipple overlay texture 3 as 4x4 alpha stipple | |
1895 * \ingroup gltexture | |
1896 */ | |
1897 void glDrawTex(GLfloat x, GLfloat y, GLfloat w, GLfloat h, | |
1898 GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th, | |
1899 int sx, int sy, int rect_tex, int is_yv12, int flip, | |
1900 int use_stipple) { | |
1901 int chroma_x_shift = (is_yv12 >> 8) & 31; | |
1902 int chroma_y_shift = (is_yv12 >> 16) & 31; | |
1903 GLfloat xscale = 1 << chroma_x_shift; | |
1904 GLfloat yscale = 1 << chroma_y_shift; | |
1905 GLfloat tx2 = tx / xscale, ty2 = ty / yscale, tw2 = tw / xscale, th2 = th / yscale; | |
1906 if (!rect_tex) { | |
1907 tx /= sx; ty /= sy; tw /= sx; th /= sy; | |
1908 tx2 = tx; ty2 = ty; tw2 = tw; th2 = th; | |
1909 } | |
1910 if (flip) { | |
1911 y += h; | |
1912 h = -h; | |
1913 } | |
1914 draw_vertices(x, y, w, h, tx, ty, tw, th, tx2, ty2, tw2, th2, is_yv12, use_stipple); | |
1926 } | 1915 } |
1927 | 1916 |
1928 #ifdef CONFIG_GL_WIN32 | 1917 #ifdef CONFIG_GL_WIN32 |
1929 #include "w32_common.h" | 1918 #include "w32_common.h" |
1930 /** | 1919 /** |