… | |
… | |
114 | av_push (texture_av, (SV *)(size_t)name); |
114 | av_push (texture_av, (SV *)(size_t)name); |
115 | glDeleteTextures (1, &name); |
115 | glDeleteTextures (1, &name); |
116 | } |
116 | } |
117 | |
117 | |
118 | #include "texcache.c" |
118 | #include "texcache.c" |
|
|
119 | #include "rendercache.c" |
119 | |
120 | |
120 | #include "pango-font.c" |
121 | #include "pango-font.c" |
121 | #include "pango-fontmap.c" |
122 | #include "pango-fontmap.c" |
122 | #include "pango-render.c" |
123 | #include "pango-render.c" |
123 | |
124 | |
… | |
… | |
1713 | |
1714 | |
1714 | void |
1715 | void |
1715 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
1716 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
1716 | CODE: |
1717 | CODE: |
1717 | { |
1718 | { |
|
|
1719 | int x, y, z; |
|
|
1720 | |
1718 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1721 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
1719 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1722 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
1720 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
1723 | static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) |
1721 | smooth_key skey; |
1724 | smooth_key skey; |
1722 | int x, y, z; |
1725 | |
1723 | int last_name; |
1726 | rc_t *rc = rc_alloc (); |
|
|
1727 | rc_key_t key; |
|
|
1728 | rc_array_t *arr; |
1724 | |
1729 | |
1725 | // thats current max. sorry. |
1730 | // thats current max. sorry. |
1726 | if (sw > 255) sw = 255; |
1731 | if (sw > 255) sw = 255; |
1727 | if (sh > 255) sh = 255; |
1732 | if (sh > 255) sh = 255; |
1728 | |
1733 | |
1729 | // clear key, in case of extra padding |
1734 | // clear key, in case of extra padding |
1730 | memset (&skey, 0, sizeof (skey)); |
1735 | memset (&skey, 0, sizeof (skey)); |
1731 | |
1736 | |
1732 | glColor4ub (255, 255, 255, 255); |
1737 | memset (&key, 0, sizeof (key)); |
1733 | |
1738 | key.r = 255; |
1734 | glEnable (GL_BLEND); |
1739 | key.g = 255; |
1735 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1740 | key.b = 255; |
1736 | glEnable (GL_TEXTURE_2D); |
1741 | key.a = 255; |
1737 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1742 | key.mode = GL_QUADS; |
1738 | |
1743 | key.format = GL_T2F_V3F; |
1739 | glBegin (GL_QUADS); |
|
|
1740 | |
|
|
1741 | last_name = -1; |
1744 | key.texname = -1; |
1742 | |
1745 | |
1743 | mx += self->x; |
1746 | mx += self->x; |
1744 | my += self->y; |
1747 | my += self->y; |
1745 | |
1748 | |
1746 | // first pass: determine smooth_max |
1749 | // first pass: determine smooth_max |
… | |
… | |
1762 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1765 | MAX (self->tex [cell->tile [0]].smoothlevel, |
1763 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1766 | MAX (self->tex [cell->tile [1]].smoothlevel, |
1764 | self->tex [cell->tile [2]].smoothlevel)); |
1767 | self->tex [cell->tile [2]].smoothlevel)); |
1765 | } |
1768 | } |
1766 | } |
1769 | } |
|
|
1770 | |
|
|
1771 | glEnable (GL_BLEND); |
|
|
1772 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1773 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1767 | |
1774 | |
1768 | for (z = 0; z <= 2; z++) |
1775 | for (z = 0; z <= 2; z++) |
1769 | { |
1776 | { |
1770 | memset (smooth_level, 0, sizeof (smooth_level)); |
1777 | memset (smooth_level, 0, sizeof (smooth_level)); |
1771 | |
1778 | |
… | |
… | |
1785 | maptex tex = self->tex [tile]; |
1792 | maptex tex = self->tex [tile]; |
1786 | int px, py; |
1793 | int px, py; |
1787 | |
1794 | |
1788 | // suppressing texture state switches here |
1795 | // suppressing texture state switches here |
1789 | // is only moderately effective, but worth the extra effort |
1796 | // is only moderately effective, but worth the extra effort |
1790 | if (last_name != tex.name) |
1797 | if (key.texname != tex.name) |
1791 | { |
1798 | { |
1792 | if (!tex.name) |
1799 | if (!tex.name) |
1793 | tex = self->tex [2]; /* missing, replace by noface */ |
1800 | tex = self->tex [2]; /* missing, replace by noface */ |
1794 | |
1801 | |
1795 | glEnd (); |
1802 | key.texname = tex.name; |
1796 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1803 | arr = rc_array (rc, &key); |
1797 | glBegin (GL_QUADS); |
|
|
1798 | } |
1804 | } |
1799 | |
1805 | |
1800 | px = (x + 1) * T - tex.w; |
1806 | px = (x + 1) * T - tex.w; |
1801 | py = (y + 1) * T - tex.h; |
1807 | py = (y + 1) * T - tex.h; |
1802 | |
1808 | |
1803 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1809 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
1804 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1810 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
1805 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1811 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
1806 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1812 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
1807 | |
1813 | |
1808 | if (cell->flags && z == 2) |
1814 | if (cell->flags && z == 2) |
1809 | { |
1815 | { |
|
|
1816 | // overlays such as the speech bubble, probably more to come |
1810 | if (cell->flags & 1) |
1817 | if (cell->flags & 1) |
1811 | { |
1818 | { |
1812 | maptex tex = self->tex [1]; |
1819 | maptex tex = self->tex [1]; |
1813 | int px = x * T + T * 2 / 32; |
1820 | int px = x * T + T * 2 / 32; |
1814 | int py = y * T - T * 6 / 32; |
1821 | int py = y * T - T * 6 / 32; |
1815 | |
1822 | |
|
|
1823 | if (tex.name) |
1816 | glEnd (); |
1824 | { |
1817 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1825 | if (key.texname != tex.name) |
|
|
1826 | { |
|
|
1827 | key.texname = tex.name; |
|
|
1828 | arr = rc_array (rc, &key); |
|
|
1829 | } |
|
|
1830 | |
|
|
1831 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
1832 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
|
|
1833 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
|
|
1834 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
1818 | glBegin (GL_QUADS); |
1835 | } |
1819 | |
|
|
1820 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1821 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + T); |
|
|
1822 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T); |
|
|
1823 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py ); |
|
|
1824 | } |
1836 | } |
1825 | } |
1837 | } |
1826 | |
1838 | |
1827 | // update smooth hash |
1839 | // update smooth hash |
1828 | if (tex.smoothtile) |
1840 | if (tex.smoothtile) |
… | |
… | |
1897 | int border = bits & 15; |
1909 | int border = bits & 15; |
1898 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1910 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
1899 | float dx = tex.s * .0625f; // 16 images/row |
1911 | float dx = tex.s * .0625f; // 16 images/row |
1900 | float dy = tex.t * .5f ; // 2 images/column |
1912 | float dy = tex.t * .5f ; // 2 images/column |
1901 | |
1913 | |
1902 | // this time naively avoiding texture state changes |
|
|
1903 | // save gobs of state changes. |
|
|
1904 | if (last_name != tex.name) |
1914 | if (tex.name) |
1905 | { |
1915 | { |
|
|
1916 | // this time avoiding texture state changes |
|
|
1917 | // save gobs of state changes. |
1906 | if (!tex.name) |
1918 | if (key.texname != tex.name) |
1907 | continue; // smoothing not yet available |
|
|
1908 | |
|
|
1909 | glEnd (); |
1919 | { |
1910 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1920 | key.texname = tex.name; |
1911 | glBegin (GL_QUADS); |
1921 | arr = rc_array (rc, &key); |
1912 | } |
1922 | } |
1913 | |
1923 | |
1914 | if (border) |
1924 | if (border) |
1915 | { |
1925 | { |
1916 | float ox = border * dx; |
1926 | float ox = border * dx; |
1917 | |
1927 | |
1918 | glTexCoord2f (ox , 0.f ); glVertex2f (px , py ); |
1928 | rc_t2f_v3f (arr, ox , 0.f , px , py , 0); |
1919 | glTexCoord2f (ox , dy ); glVertex2f (px , py + T); |
1929 | rc_t2f_v3f (arr, ox , dy , px , py + T, 0); |
1920 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py + T); |
1930 | rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0); |
1921 | glTexCoord2f (ox + dx, 0.f ); glVertex2f (px + T, py ); |
1931 | rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0); |
1922 | } |
1932 | } |
1923 | |
1933 | |
1924 | if (corner) |
1934 | if (corner) |
1925 | { |
1935 | { |
1926 | float ox = corner * dx; |
1936 | float ox = corner * dx; |
1927 | |
1937 | |
1928 | glTexCoord2f (ox , dy ); glVertex2f (px , py ); |
1938 | rc_t2f_v3f (arr, ox , dy , px , py , 0); |
1929 | glTexCoord2f (ox , dy * 2.f); glVertex2f (px , py + T); |
1939 | rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0); |
1930 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2f (px + T, py + T); |
1940 | rc_t2f_v3f (arr, ox + dx, dy * 2.f, px + T, py + T, 0); |
1931 | glTexCoord2f (ox + dx, dy ); glVertex2f (px + T, py ); |
1941 | rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0); |
|
|
1942 | } |
1932 | } |
1943 | } |
1933 | } |
1944 | } |
1934 | } |
1945 | } |
1935 | } |
1946 | } |
1936 | } |
1947 | } |
1937 | } |
1948 | } |
1938 | |
1949 | |
1939 | hv_clear (smooth); |
1950 | hv_clear (smooth); |
|
|
1951 | rc_draw (rc); |
|
|
1952 | rc_clear (rc); |
1940 | } |
1953 | } |
1941 | |
1954 | |
1942 | glEnd (); |
|
|
1943 | |
|
|
1944 | glDisable (GL_TEXTURE_2D); |
|
|
1945 | glDisable (GL_BLEND); |
1955 | glDisable (GL_BLEND); |
|
|
1956 | rc_free (rc); |
1946 | |
1957 | |
1947 | // top layer: overlays such as the health bar |
1958 | // top layer: overlays such as the health bar |
1948 | for (y = 0; y < sh; y++) |
1959 | for (y = 0; y < sh; y++) |
1949 | if (0 <= y + my && y + my < self->rows) |
1960 | if (0 <= y + my && y + my < self->rows) |
1950 | { |
1961 | { |