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.232 by root, Sun Aug 19 15:57:40 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;
202 203
203typedef uint16_t tileid; 204typedef uint16_t tileid;
204typedef uint16_t faceid; 205typedef uint16_t faceid;
205 206
206typedef struct { 207typedef struct {
207 int name; 208 GLuint name;
208 int w, h; 209 int w, h;
209 float s, t; 210 float s, t;
210 uint8_t r, g, b, a; 211 uint8_t r, g, b, a;
211 tileid smoothtile; 212 tileid smoothtile;
212 uint8_t smoothlevel; 213 uint8_t smoothlevel;
714 715
715 if (RETVAL) 716 if (RETVAL)
716 { 717 {
717 av_clear (texture_av); 718 av_clear (texture_av);
718 719
719 SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); 720 SDL_WM_SetCaption ("Crossfire TRT Client " VERSION, "Crossfire TRT");
720#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); 721#define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name);
721#include "glfunc.h" 722#include "glfunc.h"
722#undef GL_FUNC 723#undef GL_FUNC
723 } 724 }
724} 725}
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
2519 const_iv (GL_INTENSITY), 2549 const_iv (GL_INTENSITY),
2520 const_iv (GL_LUMINANCE), 2550 const_iv (GL_LUMINANCE),
2521 const_iv (GL_LUMINANCE_ALPHA), 2551 const_iv (GL_LUMINANCE_ALPHA),
2522 const_iv (GL_FLOAT), 2552 const_iv (GL_FLOAT),
2523 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), 2553 const_iv (GL_UNSIGNED_INT_8_8_8_8_REV),
2554 const_iv (GL_COMPRESSED_ALPHA_ARB),
2555 const_iv (GL_COMPRESSED_LUMINANCE_ARB),
2556 const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB),
2557 const_iv (GL_COMPRESSED_INTENSITY_ARB),
2558 const_iv (GL_COMPRESSED_RGB_ARB),
2559 const_iv (GL_COMPRESSED_RGBA_ARB),
2524 const_iv (GL_COMPILE), 2560 const_iv (GL_COMPILE),
2525 const_iv (GL_PROXY_TEXTURE_1D), 2561 const_iv (GL_PROXY_TEXTURE_1D),
2526 const_iv (GL_PROXY_TEXTURE_2D), 2562 const_iv (GL_PROXY_TEXTURE_2D),
2527 const_iv (GL_TEXTURE_1D), 2563 const_iv (GL_TEXTURE_1D),
2528 const_iv (GL_TEXTURE_2D), 2564 const_iv (GL_TEXTURE_2D),
2567 const_iv (GL_PERSPECTIVE_CORRECTION_HINT), 2603 const_iv (GL_PERSPECTIVE_CORRECTION_HINT),
2568 const_iv (GL_POINT_SMOOTH_HINT), 2604 const_iv (GL_POINT_SMOOTH_HINT),
2569 const_iv (GL_LINE_SMOOTH_HINT), 2605 const_iv (GL_LINE_SMOOTH_HINT),
2570 const_iv (GL_POLYGON_SMOOTH_HINT), 2606 const_iv (GL_POLYGON_SMOOTH_HINT),
2571 const_iv (GL_GENERATE_MIPMAP_HINT), 2607 const_iv (GL_GENERATE_MIPMAP_HINT),
2608 const_iv (GL_TEXTURE_COMPRESSION_HINT),
2572 const_iv (GL_FASTEST), 2609 const_iv (GL_FASTEST),
2573 const_iv (GL_DONT_CARE), 2610 const_iv (GL_DONT_CARE),
2574 const_iv (GL_NICEST), 2611 const_iv (GL_NICEST),
2575 const_iv (GL_V2F), 2612 const_iv (GL_V2F),
2576 const_iv (GL_V3F), 2613 const_iv (GL_V3F),
2584 2621
2585 texture_av = newAV (); 2622 texture_av = newAV ();
2586 AvREAL_off (texture_av); 2623 AvREAL_off (texture_av);
2587} 2624}
2588 2625
2626void
2627disable_GL_EXT_blend_func_separate ()
2628 CODE:
2629 gl.BlendFuncSeparate = 0;
2630 gl.BlendFuncSeparateEXT = 0;
2631
2589char * 2632char *
2590gl_vendor () 2633gl_vendor ()
2591 CODE: 2634 CODE:
2592 RETVAL = (char *)glGetString (GL_VENDOR); 2635 RETVAL = (char *)glGetString (GL_VENDOR);
2593 OUTPUT: 2636 OUTPUT:
2824 NV x, y, w, h; 2867 NV x, y, w, h;
2825 SV *draw_x_sv = GvSV (draw_x_gv); 2868 SV *draw_x_sv = GvSV (draw_x_gv);
2826 SV *draw_y_sv = GvSV (draw_y_gv); 2869 SV *draw_y_sv = GvSV (draw_y_gv);
2827 SV *draw_w_sv = GvSV (draw_w_gv); 2870 SV *draw_w_sv = GvSV (draw_w_gv);
2828 SV *draw_h_sv = GvSV (draw_h_gv); 2871 SV *draw_h_sv = GvSV (draw_h_gv);
2829 SV *hover;
2830 double draw_x, draw_y, draw_w, draw_h; 2872 double draw_x, draw_y;
2831 2873
2832 if (!SvROK (self)) 2874 if (!SvROK (self))
2833 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); 2875 croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self));
2834 2876
2835 hv = (HV *)SvRV (self); 2877 hv = (HV *)SvRV (self);
2863 { 2905 {
2864 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0); 2906 svp = hv_fetch (hv, "can_hover", sizeof ("can_hover") - 1, 0);
2865 2907
2866 if (svp && SvTRUE (*svp)) 2908 if (svp && SvTRUE (*svp))
2867 { 2909 {
2868 glColor4f (1*0.2f, 0.8*0.2f, 0.5*0.2f, 0.2f); 2910 glColor4f (1.0f * 0.2f, 0.8f * 0.2f, 0.5f * 0.2f, 0.2f);
2869 glEnable (GL_BLEND); 2911 glEnable (GL_BLEND);
2870 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 2912 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2871 glBegin (GL_QUADS); 2913 glBegin (GL_QUADS);
2872 glVertex2f (0, 0); 2914 glVertex2f (0, 0);
2873 glVertex2f (w, 0); 2915 glVertex2f (w, 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines