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.286 by root, Sun Dec 21 21:30:47 2008 UTC vs.
Revision 1.294 by root, Sat Dec 19 05:06:56 2009 UTC

81#define expect_false(expr) expect ((expr) != 0, 0) 81#define expect_false(expr) expect ((expr) != 0, 0)
82#define expect_true(expr) expect ((expr) != 0, 1) 82#define expect_true(expr) expect ((expr) != 0, 1)
83 83
84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
85 85
86#define FOW_DARKNESS 32 86#define FOW_DARKNESS 64
87#define DARKNESS_ADJUST(n) ((29 * (int)(n)) >> 5) /* times 0.9 */
87 88
88#define MAP_EXTEND_X 32 89#define MAP_EXTEND_X 32
89#define MAP_EXTEND_Y 512 90#define MAP_EXTEND_Y 512
90 91
91#define MIN_FONT_HEIGHT 10 92#define MIN_FONT_HEIGHT 10
1658 glDisable (GL_ALPHA_TEST); 1659 glDisable (GL_ALPHA_TEST);
1659 glDisable (GL_BLEND); 1660 glDisable (GL_BLEND);
1660 } 1661 }
1661} 1662}
1662 1663
1664void
1665draw_fow_texture (float intensity, int name1, float s1, float t1, float w1, float h1, float blend = 0.f, float dx = 0.f, float dy = 0.f, int name2 = 0, float s2 = 0.f, float t2 = 0.f, float w2 = 0.f, float h2 = 0.f)
1666 PROTOTYPE: @
1667 CODE:
1668{
1669 glEnable (GL_TEXTURE_2D);
1670 glEnable (GL_BLEND);
1671 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1672 glBindTexture (GL_TEXTURE_2D, name1);
1673
1674 glColor3f (intensity, intensity, intensity);
1675 glPushMatrix ();
1676 glScalef (1./3, 1./3, 1.);
1677
1678 if (blend > 0.f)
1679 {
1680 float S2, T2; /* 0. 0. for texture 2 */
1681 float w = w1 > w2 ? w1 : w2;
1682 float h = h1 > h2 ? h1 : h2;
1683 GLfloat env_color[4] = { 0., 0., 0., blend };
1684
1685 /* interpolate the two shadow textures */
1686 /* stage 0 == rgb(glcolor) + alpha(t0) */
1687 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1688
1689 /* stage 1 == rgb(glcolor) + alpha(interpolate t0, t1, texenv) */
1690 gl.ActiveTexture (GL_TEXTURE1);
1691 glEnable (GL_TEXTURE_2D);
1692 glBindTexture (GL_TEXTURE_2D, name2);
1693 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
1694
1695 /* rgb == rgb(glcolor) */
1696 glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
1697 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_CONSTANT);
1698 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
1699
1700 /* alpha = interpolate t0, t1 by env_alpha */
1701 glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env_color);
1702
1703 glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE);
1704 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
1705 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
1706
1707 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS);
1708 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
1709
1710 glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT);
1711 glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
1712
1713 s1 *= w / w1;
1714 t1 *= h / h1;
1715
1716 dx *= -3.f / w2;
1717 dy *= -3.f / h2;
1718 dx *= w / w2;
1719 dy *= h / h2;
1720
1721 s2 *= w / w2;
1722 t2 *= h / h2;
1723
1724 glBegin (GL_QUADS);
1725 gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx , dy ); glVertex2f ( 0, 0);
1726 gl.MultiTexCoord2f (GL_TEXTURE0, 0, t1); gl.MultiTexCoord2f (GL_TEXTURE1, dx , dy + t2); glVertex2f ( 0, h1);
1727 gl.MultiTexCoord2f (GL_TEXTURE0, s1, t1); gl.MultiTexCoord2f (GL_TEXTURE1, dx + s2, dy + t2); glVertex2f (w1, h1);
1728 gl.MultiTexCoord2f (GL_TEXTURE0, s1, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx + s2, dy ); glVertex2f (w1, 0);
1729 glEnd ();
1730
1731 glDisable (GL_TEXTURE_2D);
1732 gl.ActiveTexture (GL_TEXTURE0);
1733 }
1734 else
1735 {
1736 /* simple blending of one texture, also opengl <1.3 path */
1737 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1738
1739 glBegin (GL_QUADS);
1740 glTexCoord2f ( 0, 0); glVertex2f ( 0, 0);
1741 glTexCoord2f ( 0, t1); glVertex2f ( 0, h1);
1742 glTexCoord2f (s1, t1); glVertex2f (w1, h1);
1743 glTexCoord2f (s1, 0); glVertex2f (w1, 0);
1744 glEnd ();
1745 }
1746
1747 glPopMatrix ();
1748
1749 glDisable (GL_TEXTURE_2D);
1750 glDisable (GL_BLEND);
1751}
1752
1663IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) 1753IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type)
1664 CODE: 1754 CODE:
1665{ 1755{
1666 GLint width; 1756 GLint width;
1667 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); 1757 glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0);
2016 rc_key_t key; 2106 rc_key_t key;
2017 rc_array_t *arr, *arr_hidden; 2107 rc_array_t *arr, *arr_hidden;
2018 2108
2019 pl_tex.name = 0; 2109 pl_tex.name = 0;
2020 2110
2021 // thats current max. sorry. 2111 // that's current max. sorry.
2022 if (sw > 255) sw = 255; 2112 if (sw > 255) sw = 255;
2023 if (sh > 255) sh = 255; 2113 if (sh > 255) sh = 255;
2024 2114
2025 // clear key, in case of extra padding 2115 // clear key, in case of extra padding
2026 memset (&skey, 0, sizeof (skey)); 2116 memset (&skey, 0, sizeof (skey));
2174 if (cell->flags & 1) 2264 if (cell->flags & 1)
2175 { 2265 {
2176 rc_key_t key_ov = key; 2266 rc_key_t key_ov = key;
2177 maptex tex = self->tex [TEXID_SPEECH]; 2267 maptex tex = self->tex [TEXID_SPEECH];
2178 rc_array_t *arr; 2268 rc_array_t *arr;
2269 int px = x * T + T * 2 / 32;
2270 int py = y * T - T * 6 / 32;
2179 2271
2180 key_ov.texname = tex.name; 2272 key_ov.texname = tex.name;
2181 arr = rc_array (rc_ov, &key_ov); 2273 arr = rc_array (rc_ov, &key_ov);
2182
2183 int px = x * T + T * 2 / 32;
2184 int py = y * T - T * 6 / 32;
2185 2274
2186 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2275 rc_t2f_v3f (arr, 0 , 0 , px , py , 0);
2187 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); 2276 rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0);
2188 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); 2277 rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0);
2189 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); 2278 rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0);
2367 }; 2456 };
2368 2457
2369 int x, y; 2458 int x, y;
2370 2459
2371 glEnable (GL_TEXTURE_2D); 2460 glEnable (GL_TEXTURE_2D);
2461 /* GL_REPLACE would be correct, as we don't need to modulate alpha,
2462 * but the nvidia driver (185.18.14) mishandles alpha textures
2463 * ansd takes the colour from god knows where instead of using
2464 * Cp. MODULATE results in the same colour, but slightly different
2465 * alpha, but atcually gives us the correct colour with nvidia.
2466 */
2372 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2467 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2373 glEnable (GL_BLEND); 2468 glEnable (GL_BLEND);
2374 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2469 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2375 glBegin (GL_QUADS); 2470 glBegin (GL_QUADS);
2376 2471
2377 for (y = 0; y < h; y++) 2472 for (y = 0; y < h; y++)
2384 float *c = color [m & 15]; 2479 float *c = color [m & 15];
2385 2480
2386 float tx1 = m & 0x40 ? 0.5 : 0.; 2481 float tx1 = m & 0x40 ? 0.5 : 0.;
2387 float tx2 = tx1 + 0.5; 2482 float tx2 = tx1 + 0.5;
2388 2483
2389 glColor4f (c[0], c[1], c[2], 0.75); 2484 glColor4f (c[0], c[1], c[2], 1);
2390 glTexCoord2f (tx1, 0.); glVertex2i (x , y ); 2485 glTexCoord2f (tx1, 0.); glVertex2i (x , y );
2391 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); 2486 glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1);
2392 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); 2487 glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1);
2393 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); 2488 glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y );
2394 } 2489 }
2416 SvCUR_set (darkness3_sv, sw34 * sh3); 2511 SvCUR_set (darkness3_sv, sw34 * sh3);
2417 2512
2418 mx += self->x - 1; 2513 mx += self->x - 1;
2419 my += self->y - 1; 2514 my += self->y - 1;
2420 2515
2421 memset (darkness1, 255 - FOW_DARKNESS, sw1 * sh1); 2516 memset (darkness1, DARKNESS_ADJUST (255 - FOW_DARKNESS), sw1 * sh1);
2422 2517
2423 for (y = 0; y < sh1; y++) 2518 for (y = 0; y < sh1; y++)
2424 if (0 <= y + my && y + my < self->rows) 2519 if (0 <= y + my && y + my < self->rows)
2425 { 2520 {
2426 maprow *row = self->row + (y + my); 2521 maprow *row = self->row + (y + my);
2429 if (row->c0 <= x + mx && x + mx < row->c1) 2524 if (row->c0 <= x + mx && x + mx < row->c1)
2430 { 2525 {
2431 mapcell *cell = row->col + (x + mx - row->c0); 2526 mapcell *cell = row->col + (x + mx - row->c0);
2432 2527
2433 darkness1 [y * sw1 + x] = cell->darkness 2528 darkness1 [y * sw1 + x] = cell->darkness
2434 ? 255 - (cell->darkness - 1) 2529 ? DARKNESS_ADJUST (255 - (cell->darkness - 1))
2435 : 255 - FOW_DARKNESS; 2530 : DARKNESS_ADJUST (255 - FOW_DARKNESS);
2436 } 2531 }
2437 } 2532 }
2438 2533
2439 for (y = 0; y < sh; ++y) 2534 for (y = 0; y < sh; ++y)
2440 for (x = 0; x < sw; ++x) 2535 for (x = 0; x < sw; ++x)
2853 } *civ, const_iv[] = { 2948 } *civ, const_iv[] = {
2854# define const_iv(name) { # name, (IV)name } 2949# define const_iv(name) { # name, (IV)name }
2855 const_iv (GL_VENDOR), 2950 const_iv (GL_VENDOR),
2856 const_iv (GL_VERSION), 2951 const_iv (GL_VERSION),
2857 const_iv (GL_EXTENSIONS), 2952 const_iv (GL_EXTENSIONS),
2953 const_iv (GL_MAX_TEXTURE_UNITS),
2858 const_iv (GL_COLOR_MATERIAL), 2954 const_iv (GL_COLOR_MATERIAL),
2859 const_iv (GL_SMOOTH), 2955 const_iv (GL_SMOOTH),
2860 const_iv (GL_FLAT), 2956 const_iv (GL_FLAT),
2861 const_iv (GL_DITHER), 2957 const_iv (GL_DITHER),
2862 const_iv (GL_BLEND), 2958 const_iv (GL_BLEND),
2874 const_iv (GL_ZERO), 2970 const_iv (GL_ZERO),
2875 const_iv (GL_SRC_ALPHA), 2971 const_iv (GL_SRC_ALPHA),
2876 const_iv (GL_DST_ALPHA), 2972 const_iv (GL_DST_ALPHA),
2877 const_iv (GL_ONE_MINUS_SRC_ALPHA), 2973 const_iv (GL_ONE_MINUS_SRC_ALPHA),
2878 const_iv (GL_ONE_MINUS_DST_ALPHA), 2974 const_iv (GL_ONE_MINUS_DST_ALPHA),
2975 const_iv (GL_SRC_COLOR),
2976 const_iv (GL_DST_COLOR),
2977 const_iv (GL_ONE_MINUS_SRC_COLOR),
2978 const_iv (GL_ONE_MINUS_DST_COLOR),
2879 const_iv (GL_SRC_ALPHA_SATURATE), 2979 const_iv (GL_SRC_ALPHA_SATURATE),
2880 const_iv (GL_RGB), 2980 const_iv (GL_RGB),
2881 const_iv (GL_RGBA), 2981 const_iv (GL_RGBA),
2882 const_iv (GL_RGBA4), 2982 const_iv (GL_RGBA4),
2883 const_iv (GL_RGBA8), 2983 const_iv (GL_RGBA8),
2951 const_iv (GL_NICEST), 3051 const_iv (GL_NICEST),
2952 const_iv (GL_V2F), 3052 const_iv (GL_V2F),
2953 const_iv (GL_V3F), 3053 const_iv (GL_V3F),
2954 const_iv (GL_T2F_V3F), 3054 const_iv (GL_T2F_V3F),
2955 const_iv (GL_T2F_N3F_V3F), 3055 const_iv (GL_T2F_N3F_V3F),
3056 const_iv (GL_FUNC_ADD),
3057 const_iv (GL_FUNC_SUBTRACT),
3058 const_iv (GL_FUNC_REVERSE_SUBTRACT),
2956# undef const_iv 3059# undef const_iv
2957 }; 3060 };
2958 3061
2959 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 3062 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
2960 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 3063 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
2967disable_GL_EXT_blend_func_separate () 3070disable_GL_EXT_blend_func_separate ()
2968 CODE: 3071 CODE:
2969 gl.BlendFuncSeparate = 0; 3072 gl.BlendFuncSeparate = 0;
2970 gl.BlendFuncSeparateEXT = 0; 3073 gl.BlendFuncSeparateEXT = 0;
2971 3074
3075void
3076apple_nvidia_bug (int enable)
3077
2972char * 3078char *
2973gl_vendor () 3079gl_vendor ()
2974 CODE: 3080 CODE:
2975 RETVAL = (char *)glGetString (GL_VENDOR); 3081 RETVAL = (char *)glGetString (GL_VENDOR);
2976 OUTPUT: 3082 OUTPUT:
3024void glBlendFunc (int sfactor, int dfactor) 3130void glBlendFunc (int sfactor, int dfactor)
3025 3131
3026void glBlendFuncSeparate (int sa, int da, int saa, int daa) 3132void glBlendFuncSeparate (int sa, int da, int saa, int daa)
3027 CODE: 3133 CODE:
3028 gl_BlendFuncSeparate (sa, da, saa, daa); 3134 gl_BlendFuncSeparate (sa, da, saa, daa);
3135
3136# void glBlendEquation (int se)
3029 3137
3030void glDepthMask (int flag) 3138void glDepthMask (int flag)
3031 3139
3032void glLogicOp (int opcode) 3140void glLogicOp (int opcode)
3033 3141

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines