… | |
… | |
2277 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2277 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2278 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2278 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2279 | |
2279 | |
2280 | for (z = 0; z <= 2; z++) |
2280 | for (z = 0; z <= 2; z++) |
2281 | { |
2281 | { |
2282 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
2282 | std::bitset<256> smooth_level; // one bit for every possible smooth level |
2283 | smooth_key skey; |
2283 | smooth_key skey; |
2284 | smooth_hash smooth; |
2284 | smooth_hash smooth; |
2285 | memset (smooth_level, 0, sizeof (smooth_level)); |
|
|
2286 | key.texname = -1; |
2285 | key.texname = -1; |
2287 | |
2286 | |
2288 | for (y = 0; y < sh; y++) |
2287 | for (y = 0; y < sh; y++) |
2289 | if (0 <= y + my && y + my < self->rows) |
2288 | if (0 <= y + my && y + my < self->rows) |
2290 | { |
2289 | { |
… | |
… | |
2332 | if (tex.smoothtile) |
2331 | if (tex.smoothtile) |
2333 | { |
2332 | { |
2334 | skey.tile = tex.smoothtile; |
2333 | skey.tile = tex.smoothtile; |
2335 | skey.level = tex.smoothlevel; |
2334 | skey.level = tex.smoothlevel; |
2336 | |
2335 | |
2337 | smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); |
2336 | smooth_level[tex.smoothlevel] = 1; |
2338 | |
2337 | |
2339 | // add bits to current tile and all neighbours. skey.x|y is |
2338 | // add bits to current tile and all neighbours. skey.x|y is |
2340 | // shifted +1|+1 so we always stay positive. |
2339 | // shifted +1|+1 so we always stay positive. |
2341 | |
2340 | |
2342 | // bits is ___n cccc CCCC bbbb |
2341 | // bits is ___n cccc CCCC bbbb |
… | |
… | |
2399 | { |
2398 | { |
2400 | int w, b; |
2399 | int w, b; |
2401 | |
2400 | |
2402 | glEnable (GL_TEXTURE_2D); |
2401 | glEnable (GL_TEXTURE_2D); |
2403 | glBegin (GL_QUADS); |
2402 | glBegin (GL_QUADS); |
2404 | for (w = 0; w < 256 / 32; ++w) |
2403 | for (int level = 0; level < smooth_level.size (); ++level) |
|
|
2404 | if (smooth_level[level]) |
|
|
2405 | for (auto &&it = smooth.begin (); it != smooth.end (); ++it) |
2405 | { |
2406 | { |
2406 | uint32_t smask = smooth_level [w]; |
2407 | smooth_key &skey = it->first; |
2407 | if (smask) |
2408 | IV bits = it->second; |
2408 | for (b = 0; b < 32; ++b) |
2409 | |
2409 | if (smask & (((uint32_t)1) << b)) |
2410 | if (!(bits & 0x1000) |
|
|
2411 | && skey.level == level |
|
|
2412 | && level > smooth_max [skey.x][skey.y]) |
2410 | { |
2413 | { |
2411 | int level = (w << 5) | b; |
2414 | maptex tex = self->tex [skey.tile]; |
|
|
2415 | int px = (((int)skey.x) - 1) * Tw; |
|
|
2416 | int py = (((int)skey.y) - 1) * Th; |
|
|
2417 | int border = bits & 15; |
|
|
2418 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
2419 | float dx = tex.s * .0625f; // 16 images/row |
|
|
2420 | float dy = tex.t * .5f ; // 2 images/column |
|
|
2421 | |
2412 | HE *he; |
2422 | if (tex.name) |
2413 | |
|
|
2414 | for (auto &&it = smooth.begin (); it != smooth.end (); ++it) |
|
|
2415 | { |
2423 | { |
2416 | smooth_key &skey = it->first; |
2424 | // this time avoiding texture state changes |
2417 | IV bits = it->second; |
2425 | // save gobs of state changes. |
2418 | |
2426 | if (key.texname != tex.name) |
2419 | if (!(bits & 0x1000) |
|
|
2420 | && skey.level == level |
|
|
2421 | && level > smooth_max [skey.x][skey.y]) |
|
|
2422 | { |
2427 | { |
2423 | maptex tex = self->tex [skey.tile]; |
|
|
2424 | int px = (((int)skey.x) - 1) * Tw; |
|
|
2425 | int py = (((int)skey.y) - 1) * Th; |
|
|
2426 | int border = bits & 15; |
|
|
2427 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
2428 | float dx = tex.s * .0625f; // 16 images/row |
|
|
2429 | float dy = tex.t * .5f ; // 2 images/column |
|
|
2430 | |
|
|
2431 | if (tex.name) |
|
|
2432 | { |
|
|
2433 | // this time avoiding texture state changes |
|
|
2434 | // save gobs of state changes. |
|
|
2435 | if (key.texname != tex.name) |
|
|
2436 | { |
|
|
2437 | self->tex [skey.tile].unused = 0; |
2428 | self->tex [skey.tile].unused = 0; |
2438 | |
2429 | |
2439 | glEnd (); |
2430 | glEnd (); |
2440 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2431 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2441 | glBegin (GL_QUADS); |
2432 | glBegin (GL_QUADS); |
2442 | } |
2433 | } |
2443 | |
2434 | |
2444 | if (border) |
2435 | if (border) |
2445 | { |
2436 | { |
2446 | float ox = border * dx; |
2437 | float ox = border * dx; |
2447 | |
2438 | |
2448 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2439 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2449 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
2440 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
2450 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
2441 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
2451 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
2442 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
2452 | } |
2443 | } |
2453 | |
2444 | |
2454 | if (corner) |
2445 | if (corner) |
2455 | { |
2446 | { |
2456 | float ox = corner * dx; |
2447 | float ox = corner * dx; |
2457 | |
2448 | |
2458 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2449 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2459 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
2450 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
2460 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
2451 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
2461 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
2452 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
2462 | } |
|
|
2463 | } |
|
|
2464 | } |
2453 | } |
2465 | } |
2454 | } |
2466 | } |
2455 | } |
2467 | } |
2456 | } |
2468 | |
2457 | |
2469 | glEnd (); |
2458 | glEnd (); |
2470 | glDisable (GL_TEXTURE_2D); |
2459 | glDisable (GL_TEXTURE_2D); |
2471 | key.texname = -1; |
2460 | key.texname = -1; |
2472 | } |
2461 | } |