ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.224 by root, Sat Aug 11 11:21:46 2007 UTC vs.
Revision 1.227 by root, Mon Aug 13 14:15:09 2007 UTC

150typedef struct cf_layout { 150typedef struct cf_layout {
151 PangoLayout *pl; 151 PangoLayout *pl;
152 float r, g, b, a; // default color for rgba mode 152 float r, g, b, a; // default color for rgba mode
153 int base_height; 153 int base_height;
154 CFPlus__Font font; 154 CFPlus__Font font;
155 rc_t *rc;
155} *CFPlus__Layout; 156} *CFPlus__Layout;
156 157
157static CFPlus__Font default_font; 158static CFPlus__Font default_font;
158static PangoContext *opengl_context; 159static PangoContext *opengl_context;
159static PangoFontMap *opengl_fontmap; 160static PangoFontMap *opengl_fontmap;
1036 RETVAL->g = 1.; 1037 RETVAL->g = 1.;
1037 RETVAL->b = 1.; 1038 RETVAL->b = 1.;
1038 RETVAL->a = 1.; 1039 RETVAL->a = 1.;
1039 RETVAL->base_height = MIN_FONT_HEIGHT; 1040 RETVAL->base_height = MIN_FONT_HEIGHT;
1040 RETVAL->font = 0; 1041 RETVAL->font = 0;
1042 RETVAL->rc = rc_alloc ();
1041 1043
1042 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1044 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1043 layout_update_font (RETVAL); 1045 layout_update_font (RETVAL);
1044 OUTPUT: 1046 OUTPUT:
1045 RETVAL 1047 RETVAL
1046 1048
1047void 1049void
1048DESTROY (CFPlus::Layout self) 1050DESTROY (CFPlus::Layout self)
1049 CODE: 1051 CODE:
1050 g_object_unref (self->pl); 1052 g_object_unref (self->pl);
1053 rc_free (self->rc);
1051 Safefree (self); 1054 Safefree (self);
1052 1055
1053void 1056void
1054set_text (CFPlus::Layout self, SV *text_) 1057set_text (CFPlus::Layout self, SV *text_)
1055 CODE: 1058 CODE:
1307 } 1310 }
1308} 1311}
1309 1312
1310void 1313void
1311render (CFPlus::Layout self, float x, float y, int flags = 0) 1314render (CFPlus::Layout self, float x, float y, int flags = 0)
1312 PPCODE: 1315 CODE:
1316 rc_clear (self->rc);
1313 pango_opengl_render_layout_subpixel ( 1317 pango_opengl_render_layout_subpixel (
1314 self->pl, 1318 self->pl,
1319 self->rc,
1315 x * PANGO_SCALE, y * PANGO_SCALE, 1320 x * PANGO_SCALE, y * PANGO_SCALE,
1316 self->r, self->g, self->b, self->a, 1321 self->r, self->g, self->b, self->a,
1317 flags 1322 flags
1318 ); 1323 );
1324 // we assume that context_change actually clears/frees stuff
1325 // and does not do any recomputation...
1326 pango_layout_context_changed (self->pl);
1327
1328void
1329draw (CFPlus::Layout self)
1330 CODE:
1331{
1332 glEnable (GL_TEXTURE_2D);
1333 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1334 glEnable (GL_BLEND);
1335 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1336 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1337 glEnable (GL_ALPHA_TEST);
1338 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1339
1340 rc_draw (self->rc);
1341
1342 glDisable (GL_ALPHA_TEST);
1343 glDisable (GL_BLEND);
1344 glDisable (GL_TEXTURE_2D);
1345}
1319 1346
1320MODULE = CFPlus PACKAGE = CFPlus::Texture 1347MODULE = CFPlus PACKAGE = CFPlus::Texture
1321 1348
1322PROTOTYPES: ENABLE 1349PROTOTYPES: ENABLE
1323 1350
1718{ 1745{
1719 int x, y, z; 1746 int x, y, z;
1720 1747
1721 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); 1748 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
1722 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 1749 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
1723 static uint8_t smooth_max[256][256]; // egad, fats and wasteful on memory (64k) 1750 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
1724 smooth_key skey; 1751 smooth_key skey;
1725 1752
1726 rc_t *rc = rc_alloc (); 1753 rc_t *rc = rc_alloc ();
1727 rc_key_t key; 1754 rc_key_t key;
1728 rc_array_t *arr; 1755 rc_array_t *arr;
1790 if (tile) 1817 if (tile)
1791 { 1818 {
1792 maptex tex = self->tex [tile]; 1819 maptex tex = self->tex [tile];
1793 int px, py; 1820 int px, py;
1794 1821
1795 // suppressing texture state switches here
1796 // is only moderately effective, but worth the extra effort
1797 if (key.texname != tex.name) 1822 if (key.texname != tex.name)
1798 { 1823 {
1799 if (!tex.name) 1824 if (!tex.name)
1800 tex = self->tex [2]; /* missing, replace by noface */ 1825 tex = self->tex [2]; /* missing, replace by noface */
1801 1826
1884 // go through all smoothlevels, lowest to highest, then draw. 1909 // go through all smoothlevels, lowest to highest, then draw.
1885 // this is basically counting sort 1910 // this is basically counting sort
1886 { 1911 {
1887 int w, b; 1912 int w, b;
1888 1913
1914 glEnable (GL_TEXTURE_2D);
1915 glBegin (GL_QUADS);
1889 for (w = 0; w < 256 / 32; ++w) 1916 for (w = 0; w < 256 / 32; ++w)
1890 { 1917 {
1891 uint32_t smask = smooth_level [w]; 1918 uint32_t smask = smooth_level [w];
1892 if (smask) 1919 if (smask)
1893 for (b = 0; b < 32; ++b) 1920 for (b = 0; b < 32; ++b)
1918 { 1945 {
1919 // this time avoiding texture state changes 1946 // this time avoiding texture state changes
1920 // save gobs of state changes. 1947 // save gobs of state changes.
1921 if (key.texname != tex.name) 1948 if (key.texname != tex.name)
1922 { 1949 {
1950 glEnd ();
1923 key.texname = tex.name; 1951 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
1924 arr = rc_array (rc, &key); 1952 glBegin (GL_QUADS);
1925 } 1953 }
1926 1954
1927 if (border) 1955 if (border)
1928 { 1956 {
1929 float ox = border * dx; 1957 float ox = border * dx;
1930 1958
1931 rc_t2f_v3f (arr, ox , 0.f , px , py , 0); 1959 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
1932 rc_t2f_v3f (arr, ox , dy , px , py + T, 0); 1960 glTexCoord2f (ox , dy ); glVertex2i (px , py + T);
1933 rc_t2f_v3f (arr, ox + dx, dy , px + T, py + T, 0); 1961 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T);
1934 rc_t2f_v3f (arr, ox + dx, 0.f , px + T, py , 0); 1962 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py );
1935 } 1963 }
1936 1964
1937 if (corner) 1965 if (corner)
1938 { 1966 {
1939 float ox = corner * dx; 1967 float ox = corner * dx;
1940 1968
1941 rc_t2f_v3f (arr, ox , dy , px , py , 0); 1969 glTexCoord2f (ox , dy ); glVertex2i (px , py );
1942 rc_t2f_v3f (arr, ox , dy * 2.f, px , py + T, 0); 1970 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T);
1943 rc_t2f_v3f (arr, ox + dx, dy * 2.f, px + T, py + T, 0); 1971 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T);
1944 rc_t2f_v3f (arr, ox + dx, dy , px + T, py , 0); 1972 glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py );
1945 } 1973 }
1946 } 1974 }
1947 } 1975 }
1948 } 1976 }
1949 } 1977 }
1950 } 1978 }
1979
1980 glEnd ();
1981 glDisable (GL_TEXTURE_2D);
1982 key.texname = -1;
1951 } 1983 }
1952 1984
1953 hv_clear (smooth); 1985 hv_clear (smooth);
1954 rc_draw (rc);
1955 rc_clear (rc);
1956 } 1986 }
1957 1987
1958 glDisable (GL_BLEND); 1988 glDisable (GL_BLEND);
1959 rc_free (rc); 1989 rc_free (rc);
1960 1990
2213 int x, y, z; 2243 int x, y, z;
2214 int w, h; 2244 int w, h;
2215 int x1, y1; 2245 int x1, y1;
2216 2246
2217 if (*data++ != 0) 2247 if (*data++ != 0)
2218 return; /* version mismatch */ 2248 XSRETURN_EMPTY; /* version mismatch */
2219 2249
2220 w = *data++ << 8; w |= *data++; 2250 w = *data++ << 8; w |= *data++;
2221 h = *data++ << 8; h |= *data++; 2251 h = *data++ << 8; h |= *data++;
2222 2252
2223 // we need to do this 'cause we don't keep an absolute coord system for rows 2253 // we need to do this 'cause we don't keep an absolute coord system for rows

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines