int fillt(int x, int base, int from, int to, int flg) { int sw = width(outbuf + from, to - from); /* Width of source */ int dw = lwidth - x; /* Width of destination */ int ad = dw - sw; /* Amount of additional space needed */ int su = (to - from) - 1; /* No. spaces we can add space */ if (flg) { if (nad) pad /= nad, psu /= nad, pad = pad * su / psu; else pad = 0; if (pad < ad) ad = pad; } else pad += ad, psu += su, ++nad; if (ad > 0) { int q; int acc = ad; for (q = from; q != to; ++q) { int w = width(outbuf + q, 1); tgen(x, base, q, q + 1); while ((acc -= su) >= 0) ++x; acc += su + ad; x += w; } } else tgen(x, base, from, to); }
static inline void GetTextureCoordinates(const VertexData& v0, const VertexData& v1, const VertexData& v2, int w0, int w1, int w2, float& s, float& t) { if (gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_COORDS || gstate.getUVGenMode() == GE_TEXMAP_UNKNOWN || gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP) { // TODO: What happens if vertex has no texture coordinates? // Note that for environment mapping, texture coordinates have been calculated during lighting float q0 = 1.f / v0.clippos.w; float q1 = 1.f / v1.clippos.w; float q2 = 1.f / v2.clippos.w; float q = q0 * w0 + q1 * w1 + q2 * w2; s = (v0.texturecoords.s() * q0 * w0 + v1.texturecoords.s() * q1 * w1 + v2.texturecoords.s() * q2 * w2) / q; t = (v0.texturecoords.t() * q0 * w0 + v1.texturecoords.t() * q1 * w1 + v2.texturecoords.t() * q2 * w2) / q; } else if (gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX) { // projection mapping, TODO: Move this code to TransformUnit! Vec3<float> source; if (gstate.getUVProjMode() == GE_PROJMAP_POSITION) { source = ((v0.modelpos * w0 + v1.modelpos * w1 + v2.modelpos * w2) / (w0+w1+w2)); } else { ERROR_LOG(G3D, "Unsupported UV projection mode %x", gstate.getUVProjMode()); } Mat3x3<float> tgen(gstate.tgenMatrix); Vec3<float> stq = tgen * source + Vec3<float>(gstate.tgenMatrix[9], gstate.tgenMatrix[10], gstate.tgenMatrix[11]); s = stq.x/stq.z; t = stq.y/stq.z; } else { ERROR_LOG(G3D, "Unsupported texture mapping mode %x!", gstate.getUVGenMode()); } }
void outtext() { int x; int flg = 0; for (x = 0; x != outx; ++x) if ((outbuf[x] & 255) == '~') flg = 1; if (flg) { int l = 0, r = outx; int b = maxabove(outbuf, outx); int h = maxheight(outbuf, outx); int ll; if ((outbuf[0] & 255) != '~') { for (l = 0; (outbuf[l] & 255) != '~'; ++l); tgen(0, b, 0, l); } if ((outbuf[outx - 1] & 255) != '~') { for (r = outx; (outbuf[r - 1] & 255) != '~'; --r); tgen(lwidth - width(outbuf + r, outx - r), b, r, outx); } for (x = l, flg = 0; x != r; ++x) if ((outbuf[x] & 255) == '~') ++flg; if (flg > 1) { ll = lwidth / flg; for (x = 0; x != flg - 1; ++x) { int zz; ++l; for (zz = l; (outbuf[zz] & 255) != '~'; ++zz); cntrit(ll, l, zz, b); l = zz; ll += lwidth / flg; } } y += h; } else if (mode == 2); else { int start = 0; nad = 0; psu = 0; pad = 0; while (start != outx) { int lz, w, z = start, ow; if (start) w = width(outbuf, ind); else w = 0; do { lz = z; ow = w; while (z != outx && (outbuf[z] & 0xFF) == 32) w += width(outbuf + z++, 1); while (z != outx && (outbuf[z] & 0xFF) != 32) w += width(outbuf + z++, 1); } while (w <= lwidth && z != outx); if (w <= lwidth) lz = z; if (lz != start) { int b = maxabove(outbuf + start, lz - start); int h = maxheight(outbuf + start, lz - start); if (!fillmode) if (start) tgen(width(outbuf, ind), b, start, lz); else tgen(0, b, start, lz); else if (start) fillt(width(outbuf, ind), b, start, lz, lz == outx); else fillt(0, b, start, lz, lz == outx); y += h; } while (lz != outx && (outbuf[lz] & 0xFF) == 32) ++lz; start = lz; } } outx = 0; ind = 2; mode = 0; fillmode = 0; }
void cntrit(int m, int from, int to, int b) { int w = width(outbuf + from, to - from); tgen(m - w / 2, b, from, to); }