PF_TEX.C 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /******************************************************************************
  2. Plush Version 1.2
  3. pf_tex.c
  4. Affine Texture Mapping Rasterizers
  5. Copyright (c) 1996-2000, Justin Frankel
  6. ******************************************************************************/
  7. #include "plush.h"
  8. #include "putface.h"
  9. void plPF_TexEnv(pl_Cam *cam, pl_Face *TriFace) {
  10. pl_uChar i0, i1, i2;
  11. pl_uChar *gmem = cam->frameBuffer;
  12. pl_uChar *remap;
  13. pl_ZBuffer *zbuf = cam->zBuffer;
  14. pl_sInt32 MappingU1, MappingU2, MappingU3;
  15. pl_sInt32 MappingV1, MappingV2, MappingV3;
  16. pl_sInt32 MappingU_AND, MappingV_AND;
  17. pl_sInt32 eMappingU1, eMappingU2, eMappingU3;
  18. pl_sInt32 eMappingV1, eMappingV2, eMappingV3;
  19. pl_sInt32 eMappingU_AND, eMappingV_AND;
  20. pl_uChar *texture, *environment;
  21. pl_uChar vshift;
  22. pl_uChar evshift;
  23. pl_uInt16 *addtable;
  24. pl_Texture *Texture, *Environment;
  25. pl_uChar stat;
  26. pl_Bool zb = (zbuf&&TriFace->Material->zBufferable) ? 1 : 0;
  27. pl_sInt32 U1, V1, U2, V2, dU1=0, dU2=0, dV1=0, dV2=0, dUL=0, dVL=0, UL, VL;
  28. pl_sInt32 eU1, eV1, eU2, eV2, edU1=0, edU2=0, edV1=0,
  29. edV2=0, edUL=0, edVL=0, eUL, eVL;
  30. pl_sInt32 X1, X2, dX1=0, dX2=0, XL1, XL2;
  31. pl_Float Z1, ZL, dZ1=0, dZ2=0, dZL=0, Z2;
  32. pl_sInt32 Y1, Y2, Y0, dY;
  33. Environment = TriFace->Material->Environment;
  34. Texture = TriFace->Material->Texture;
  35. if (!Texture || !Environment) return;
  36. texture = Texture->Data;
  37. environment = Environment->Data;
  38. addtable = TriFace->Material->_AddTable;
  39. remap = TriFace->Material->_ReMapTable;
  40. MappingV_AND = ((1<<Texture->Height)-1)<<Texture->Width;
  41. MappingU_AND = (1<<Texture->Width)-1;
  42. vshift = 16 - Texture->Width;
  43. eMappingV_AND = ((1<<Environment->Height)-1)<<Environment->Width;
  44. eMappingU_AND = (1<<Environment->Width)-1;
  45. evshift = 16 - Environment->Width;
  46. PUTFACE_SORT_TEX();
  47. eMappingU1=(pl_sInt32) (TriFace->eMappingU[i0]*Environment->uScale*TriFace->Material->EnvScaling);
  48. eMappingV1=(pl_sInt32) (TriFace->eMappingV[i0]*Environment->vScale*TriFace->Material->EnvScaling);
  49. eMappingU2=(pl_sInt32) (TriFace->eMappingU[i1]*Environment->uScale*TriFace->Material->EnvScaling);
  50. eMappingV2=(pl_sInt32) (TriFace->eMappingV[i1]*Environment->vScale*TriFace->Material->EnvScaling);
  51. eMappingU3=(pl_sInt32) (TriFace->eMappingU[i2]*Environment->uScale*TriFace->Material->EnvScaling);
  52. eMappingV3=(pl_sInt32) (TriFace->eMappingV[i2]*Environment->vScale*TriFace->Material->EnvScaling);
  53. U1 = U2 = MappingU1;
  54. V1 = V2 = MappingV1;
  55. eU1 = eU2 = eMappingU1;
  56. eV1 = eV2 = eMappingV1;
  57. X2 = X1 = TriFace->Scrx[i0];
  58. Z2 = Z1 = TriFace->Scrz[i0];
  59. Y0 = (TriFace->Scry[i0]+(1<<19))>>20;
  60. Y1 = (TriFace->Scry[i1]+(1<<19))>>20;
  61. Y2 = (TriFace->Scry[i2]+(1<<19))>>20;
  62. dY = Y2 - Y0;
  63. if (dY) {
  64. dU2 = (MappingU3 - U1) / dY;
  65. dV2 = (MappingV3 - V1) / dY;
  66. edU2 = (eMappingU3 - eU1) / dY;
  67. edV2 = (eMappingV3 - eV1) / dY;
  68. dX2 = (TriFace->Scrx[i2] - X1) / dY;
  69. dZ2 = (TriFace->Scrz[i2] - Z1) / dY;
  70. }
  71. dY = Y1-Y0;
  72. if (dY) {
  73. dX1 = (TriFace->Scrx[i1] - X1) / dY;
  74. dU1 = (MappingU2 - U1) / dY;
  75. dV1 = (MappingV2 - V1) / dY;
  76. edU1 = (eMappingU2 - eU1) / dY;
  77. edV1 = (eMappingV2 - eV1) / dY;
  78. dZ1 = (TriFace->Scrz[i1] - Z1) / dY;
  79. if (dX2 < dX1) {
  80. dX2 ^= dX1; dX1 ^= dX2; dX2 ^= dX1;
  81. dU2 ^= dU1; dU1 ^= dU2; dU2 ^= dU1;
  82. dV2 ^= dV1; dV1 ^= dV2; dV2 ^= dV1;
  83. edU2 ^= edU1; edU1 ^= edU2; edU2 ^= edU1;
  84. edV2 ^= edV1; edV1 ^= edV2; edV2 ^= edV1;
  85. dZL = dZ1; dZ1 = dZ2; dZ2 = dZL;
  86. stat = 2;
  87. } else stat = 1;
  88. } else {
  89. if (TriFace->Scrx[i1] > X1) {
  90. X2 = TriFace->Scrx[i1];
  91. Z2 = TriFace->Scrz[i1];
  92. U2 = MappingU2;
  93. V2 = MappingV2;
  94. eU2 = eMappingU2;
  95. eV2 = eMappingV2;
  96. stat = 2|4;
  97. } else {
  98. X1 = TriFace->Scrx[i1];
  99. Z1 = TriFace->Scrz[i1];
  100. U1 = MappingU2;
  101. V1 = MappingV2;
  102. eU1 = eMappingU2;
  103. eV1 = eMappingV2;
  104. stat = 1|8;
  105. }
  106. }
  107. gmem += (Y0 * cam->ScreenWidth);
  108. zbuf += (Y0 * cam->ScreenWidth);
  109. XL1 = (((dX1-dX2)*dY+(1<<19))>>20);
  110. if (XL1) {
  111. dUL = ((dU1-dU2)*dY)/XL1;
  112. dVL = ((dV1-dV2)*dY)/XL1;
  113. edUL = ((edU1-edU2)*dY)/XL1;
  114. edVL = ((edV1-edV2)*dY)/XL1;
  115. dZL = ((dZ1-dZ2)*dY)/XL1;
  116. } else {
  117. XL1 = ((X2-X1+(1<<19))>>20);
  118. if (XL1) {
  119. edUL = (eU2-eU1)/XL1;
  120. edVL = (eV2-eV1)/XL1;
  121. dUL = (U2-U1)/XL1;
  122. dVL = (V2-V1)/XL1;
  123. dZL = (Z2-Z1)/XL1;
  124. }
  125. }
  126. while (Y0 < Y2) {
  127. if (Y0 == Y1) {
  128. dY = Y2 - ((TriFace->Scry[i1]+(1<<19))>>20);
  129. if (dY) {
  130. if (stat & 1) {
  131. X1 = TriFace->Scrx[i1];
  132. dX1 = (TriFace->Scrx[i2]-TriFace->Scrx[i1])/dY;
  133. }
  134. if (stat & 2) {
  135. X2 = TriFace->Scrx[i1];
  136. dX2 = (TriFace->Scrx[i2]-TriFace->Scrx[i1])/dY;
  137. }
  138. if (stat & 4) {
  139. X1 = TriFace->Scrx[i0];
  140. dX1 = (TriFace->Scrx[i2]-TriFace->Scrx[i0])/dY;
  141. }
  142. if (stat & 8) {
  143. X2 = TriFace->Scrx[i0];
  144. dX2 = (TriFace->Scrx[i2]-TriFace->Scrx[i0])/dY;
  145. }
  146. dZ1 = (TriFace->Scrz[i2]-Z1)/dY;
  147. dV1 = (MappingV3 - V1) / dY;
  148. dU1 = (MappingU3 - U1) / dY;
  149. edV1 = (eMappingV3 - eV1) / dY;
  150. edU1 = (eMappingU3 - eU1) / dY;
  151. }
  152. }
  153. XL1 = (X1+(1<<19))>>20;
  154. XL2 = (X2+(1<<19))>>20;
  155. ZL = Z1;
  156. UL = U1;
  157. VL = V1;
  158. eUL = eU1;
  159. eVL = eV1;
  160. if ((XL2-XL1) > 0) {
  161. XL2 -= XL1;
  162. gmem += XL1;
  163. zbuf += XL1;
  164. XL1 += XL2;
  165. if (zb) do {
  166. if (*zbuf < ZL) {
  167. *zbuf = ZL;
  168. *gmem = remap[addtable[environment[
  169. ((eUL>>16)&eMappingU_AND)+((eVL>>evshift)&eMappingV_AND)]] +
  170. texture[((UL>>16)&MappingU_AND) +
  171. ((VL>>vshift)&MappingV_AND)]];
  172. }
  173. zbuf++;
  174. gmem++;
  175. ZL += dZL;
  176. UL += dUL;
  177. VL += dVL;
  178. eUL += edUL;
  179. eVL += edVL;
  180. } while (--XL2);
  181. else do {
  182. *gmem++ = remap[addtable[environment[
  183. ((eUL>>16)&eMappingU_AND)+((eVL>>evshift)&eMappingV_AND)]] +
  184. texture[((UL>>16)&MappingU_AND) +
  185. ((VL>>vshift)&MappingV_AND)]];
  186. UL += dUL;
  187. VL += dVL;
  188. eUL += edUL;
  189. eVL += edVL;
  190. } while (--XL2);
  191. gmem -= XL1;
  192. zbuf -= XL1;
  193. }
  194. zbuf += cam->ScreenWidth;
  195. gmem += cam->ScreenWidth;
  196. Z1 += dZ1;
  197. X1 += dX1;
  198. X2 += dX2;
  199. U1 += dU1;
  200. V1 += dV1;
  201. eU1 += edU1;
  202. eV1 += edV1;
  203. Y0++;
  204. }
  205. }
  206. void plPF_TexF(pl_Cam *cam, pl_Face *TriFace) {
  207. pl_uChar i0, i1, i2;
  208. pl_uChar *gmem = cam->frameBuffer;
  209. pl_ZBuffer *zbuf = cam->zBuffer;
  210. pl_sInt32 MappingU1, MappingU2, MappingU3;
  211. pl_sInt32 MappingV1, MappingV2, MappingV3;
  212. pl_sInt32 MappingU_AND, MappingV_AND;
  213. pl_uChar *texture;
  214. pl_uChar vshift;
  215. pl_uInt bc;
  216. pl_uChar *remap;
  217. pl_Texture *Texture;
  218. pl_uChar stat;
  219. pl_ZBuffer Z1, ZL, dZ1=0, dZL=0, Z2, dZ2=0;
  220. pl_sInt32 dU1=0, dV1=0, dU2=0, dV2=0, U1, V1, U2, V2;
  221. pl_sInt32 dUL=0, dVL=0, UL, VL;
  222. pl_sInt32 X1, X2, dX1=0, dX2=0, XL1, XL2;
  223. pl_sInt32 Y1, Y2, Y0, dY;
  224. pl_Bool zb = (zbuf&&TriFace->Material->zBufferable) ? 1 : 0;
  225. pl_sInt shade;
  226. if (TriFace->Material->Environment) Texture = TriFace->Material->Environment;
  227. else Texture = TriFace->Material->Texture;
  228. if (!Texture) return;
  229. remap = TriFace->Material->_ReMapTable;
  230. if (TriFace->Material->_AddTable)
  231. {
  232. shade=(pl_sInt)(TriFace->fShade*255.0f);
  233. if (shade < 0) shade=0;
  234. if (shade > 255) shade=255;
  235. bc = TriFace->Material->_AddTable[shade];
  236. }
  237. else bc=0;
  238. texture = Texture->Data;
  239. vshift = 16 - Texture->Width;
  240. MappingV_AND = ((1<<Texture->Height)-1)<<Texture->Width;
  241. MappingU_AND = (1<<Texture->Width)-1;
  242. if (TriFace->Material->Environment) {
  243. PUTFACE_SORT_ENV();
  244. } else {
  245. PUTFACE_SORT_TEX();
  246. }
  247. U1 = U2 = MappingU1;
  248. V1 = V2 = MappingV1;
  249. X2 = X1 = TriFace->Scrx[i0];
  250. Z2 = Z1 = TriFace->Scrz[i0];
  251. Y0 = (TriFace->Scry[i0]+(1<<19))>>20;
  252. Y1 = (TriFace->Scry[i1]+(1<<19))>>20;
  253. Y2 = (TriFace->Scry[i2]+(1<<19))>>20;
  254. dY = Y2 - Y0;
  255. if (dY) {
  256. dX2 = (TriFace->Scrx[i2] - X1) / dY;
  257. dV2 = (MappingV3 - V1) / dY;
  258. dU2 = (MappingU3 - U1) / dY;
  259. dZ2 = (TriFace->Scrz[i2] - Z1) / dY;
  260. }
  261. dY = Y1-Y0;
  262. if (dY) {
  263. dX1 = (TriFace->Scrx[i1] - X1) / dY;
  264. dZ1 = (TriFace->Scrz[i1] - Z1) / dY;
  265. dU1 = (MappingU2 - U1) / dY;
  266. dV1 = (MappingV2 - V1) / dY;
  267. if (dX2 < dX1) {
  268. dX2 ^= dX1; dX1 ^= dX2; dX2 ^= dX1;
  269. dU2 ^= dU1; dU1 ^= dU2; dU2 ^= dU1;
  270. dV2 ^= dV1; dV1 ^= dV2; dV2 ^= dV1;
  271. dZL = dZ1; dZ1 = dZ2; dZ2 = dZL;
  272. stat = 2;
  273. } else stat = 1;
  274. } else {
  275. if (TriFace->Scrx[i1] > X1) {
  276. X2 = TriFace->Scrx[i1];
  277. Z2 = TriFace->Scrz[i1];
  278. U2 = MappingU2;
  279. V2 = MappingV2;
  280. stat = 2|4;
  281. } else {
  282. X1 = TriFace->Scrx[i1];
  283. Z1 = TriFace->Scrz[i1];
  284. U1 = MappingU2;
  285. V1 = MappingV2;
  286. stat = 1|8;
  287. }
  288. }
  289. gmem += (Y0 * cam->ScreenWidth);
  290. zbuf += (Y0 * cam->ScreenWidth);
  291. XL1 = (((dX1-dX2)*dY+(1<<19))>>20);
  292. if (XL1) {
  293. dUL = ((dU1-dU2)*dY)/XL1;
  294. dVL = ((dV1-dV2)*dY)/XL1;
  295. dZL = ((dZ1-dZ2)*dY)/XL1;
  296. } else {
  297. XL1 = ((X2-X1+(1<<19))>>20);
  298. if (XL1) {
  299. dUL = (U2-U1)/XL1;
  300. dVL = (V2-V1)/XL1;
  301. dZL = (Z2-Z1)/XL1;
  302. }
  303. }
  304. while (Y0 < Y2) {
  305. if (Y0 == Y1) {
  306. dY = Y2 - ((TriFace->Scry[i1]+(1<<19))>>20);
  307. if (dY) {
  308. if (stat & 1) {
  309. X1 = TriFace->Scrx[i1];
  310. dX1 = (TriFace->Scrx[i2]-TriFace->Scrx[i1])/dY;
  311. }
  312. if (stat & 2) {
  313. X2 = TriFace->Scrx[i1];
  314. dX2 = (TriFace->Scrx[i2]-TriFace->Scrx[i1])/dY;
  315. }
  316. if (stat & 4) {
  317. X1 = TriFace->Scrx[i0];
  318. dX1 = (TriFace->Scrx[i2]-TriFace->Scrx[i0])/dY;
  319. }
  320. if (stat & 8) {
  321. X2 = TriFace->Scrx[i0];
  322. dX2 = (TriFace->Scrx[i2]-TriFace->Scrx[i0])/dY;
  323. }
  324. dZ1 = (TriFace->Scrz[i2]-Z1) / dY;
  325. dV1 = (MappingV3 - V1) / dY;
  326. dU1 = (MappingU3 - U1) / dY;
  327. }
  328. }
  329. XL1 = (X1+(1<<19))>>20;
  330. XL2 = (X2+(1<<19))>>20;
  331. ZL = Z1;
  332. UL = U1;
  333. VL = V1;
  334. if ((XL2-XL1) > 0) {
  335. XL2 -= XL1;
  336. gmem += XL1;
  337. zbuf += XL1;
  338. XL1 += XL2;
  339. if (zb) do {
  340. if (*zbuf < ZL) {
  341. *zbuf = ZL;
  342. *gmem = remap[bc + texture[((UL >> 16)&MappingU_AND) +
  343. ((VL>>vshift)&MappingV_AND)]];
  344. }
  345. zbuf++;
  346. gmem++;
  347. ZL += dZL;
  348. UL += dUL;
  349. VL += dVL;
  350. } while (--XL2);
  351. else do {
  352. *gmem++ = remap[bc + texture[((UL >> 16)&MappingU_AND) +
  353. ((VL>>vshift)&MappingV_AND)]];
  354. UL += dUL;
  355. VL += dVL;
  356. } while (--XL2);
  357. gmem -= XL1;
  358. zbuf -= XL1;
  359. }
  360. zbuf += cam->ScreenWidth;
  361. gmem += cam->ScreenWidth;
  362. X1 += dX1;
  363. X2 += dX2;
  364. U1 += dU1;
  365. V1 += dV1;
  366. Z1 += dZ1;
  367. Y0++;
  368. }
  369. }
  370. void plPF_TexG(pl_Cam *cam, pl_Face *TriFace) {
  371. pl_uChar i0, i1, i2;
  372. pl_uChar *gmem = cam->frameBuffer;
  373. pl_ZBuffer *zbuf = cam->zBuffer;
  374. pl_sInt32 MappingU1, MappingU2, MappingU3;
  375. pl_sInt32 MappingV1, MappingV2, MappingV3;
  376. pl_sInt32 MappingU_AND, MappingV_AND;
  377. pl_uChar *texture;
  378. pl_uChar *remap;
  379. pl_uChar vshift;
  380. pl_uInt16 *addtable;
  381. pl_Texture *Texture;
  382. pl_sInt32 U1, V1, U2, V2, dU1=0, dU2=0, dV1=0, dV2=0, dUL=0, dVL=0, UL, VL;
  383. pl_sInt32 X1, X2, dX1=0, dX2=0, XL1, XL2;
  384. pl_sInt32 C1, C2, dC1=0, dC2=0, CL, dCL=0;
  385. pl_ZBuffer Z1, ZL, dZ1=0, dZ2=0, dZL=0, Z2;
  386. pl_sInt32 Y1, Y2, Y0, dY;
  387. pl_uChar stat;
  388. pl_Bool zb = (zbuf&&TriFace->Material->zBufferable) ? 1 : 0;
  389. if (TriFace->Material->Environment) Texture = TriFace->Material->Environment;
  390. else Texture = TriFace->Material->Texture;
  391. if (!Texture) return;
  392. remap = TriFace->Material->_ReMapTable;
  393. texture = Texture->Data;
  394. addtable = TriFace->Material->_AddTable;
  395. vshift = 16 - Texture->Width;
  396. MappingV_AND = ((1<<Texture->Height)-1)<<Texture->Width;
  397. MappingU_AND = (1<<Texture->Width)-1;
  398. if (TriFace->Material->Environment) {
  399. PUTFACE_SORT_ENV();
  400. } else {
  401. PUTFACE_SORT_TEX();
  402. }
  403. C1 = C2 = TriFace->Shades[i0]*65535.0f;
  404. U1 = U2 = MappingU1;
  405. V1 = V2 = MappingV1;
  406. X2 = X1 = TriFace->Scrx[i0];
  407. Z2 = Z1 = TriFace->Scrz[i0];
  408. Y0 = (TriFace->Scry[i0]+(1<<19))>>20;
  409. Y1 = (TriFace->Scry[i1]+(1<<19))>>20;
  410. Y2 = (TriFace->Scry[i2]+(1<<19))>>20;
  411. dY = Y2 - Y0;
  412. if (dY) {
  413. dX2 = (TriFace->Scrx[i2] - X1) / dY;
  414. dZ2 = (TriFace->Scrz[i2] - Z1) / dY;
  415. dC2 = (TriFace->Shades[i2]*65535.0f - C1) / dY;
  416. dU2 = (MappingU3 - U1) / dY;
  417. dV2 = (MappingV3 - V1) / dY;
  418. }
  419. dY = Y1-Y0;
  420. if (dY) {
  421. dX1 = (TriFace->Scrx[i1] - X1) / dY;
  422. dZ1 = (TriFace->Scrz[i1] - Z1) / dY;
  423. dC1 = (TriFace->Shades[i1]*65535.0f - C1) / dY;
  424. dU1 = (MappingU2 - U1) / dY;
  425. dV1 = (MappingV2 - V1) / dY;
  426. if (dX2 < dX1) {
  427. dX2 ^= dX1; dX1 ^= dX2; dX2 ^= dX1;
  428. dU2 ^= dU1; dU1 ^= dU2; dU2 ^= dU1;
  429. dV2 ^= dV1; dV1 ^= dV2; dV2 ^= dV1;
  430. dC2 ^= dC1; dC1 ^= dC2; dC2 ^= dC1;
  431. dZL = dZ1; dZ1 = dZ2; dZ2 = dZL;
  432. stat = 2;
  433. } else stat = 1;
  434. } else {
  435. if (TriFace->Scrx[i1] > X1) {
  436. X2 = TriFace->Scrx[i1];
  437. Z2 = TriFace->Scrz[i1];
  438. C2 = TriFace->Shades[i1]*65535.0f;
  439. U2 = MappingU2;
  440. V2 = MappingV2;
  441. stat = 2|4;
  442. } else {
  443. X1 = TriFace->Scrx[i1];
  444. Z1 = TriFace->Scrz[i1];
  445. C1 = TriFace->Shades[i1]*65535.0f;
  446. U1 = MappingU2;
  447. V1 = MappingV2;
  448. stat = 1|8;
  449. }
  450. }
  451. gmem += (Y0 * cam->ScreenWidth);
  452. zbuf += (Y0 * cam->ScreenWidth);
  453. XL1 = (((dX1-dX2)*dY+(1<<19))>>20);
  454. if (XL1) {
  455. dUL = ((dU1-dU2)*dY)/XL1;
  456. dVL = ((dV1-dV2)*dY)/XL1;
  457. if (zb) dZL = ((dZ1-dZ2)*dY)/XL1;
  458. dCL = ((dC1-dC2)*dY)/XL1;
  459. } else {
  460. XL1 = ((X2-X1+(1<<19))>>20);
  461. if (XL1) {
  462. dUL = (U2-U1)/XL1;
  463. dVL = (V2-V1)/XL1;
  464. if (zb) dZL = (Z2-Z1)/XL1;
  465. dCL = (C2-C1)/(XL1);
  466. }
  467. }
  468. while (Y0 < Y2) {
  469. if (Y0 == Y1) {
  470. dY = Y2 - ((TriFace->Scry[i1]+(1<<19))>>20);
  471. if (dY) {
  472. if (stat & 1) {
  473. X1 = TriFace->Scrx[i1];
  474. dX1 = (TriFace->Scrx[i2]-TriFace->Scrx[i1])/dY;
  475. }
  476. if (stat & 2) {
  477. X2 = TriFace->Scrx[i1];
  478. dX2 = (TriFace->Scrx[i2]-TriFace->Scrx[i1])/dY;
  479. }
  480. if (stat & 4) {
  481. X1 = TriFace->Scrx[i0];
  482. dX1 = (TriFace->Scrx[i2]-TriFace->Scrx[i0])/dY;
  483. }
  484. if (stat & 8) {
  485. X2 = TriFace->Scrx[i0];
  486. dX2 = (TriFace->Scrx[i2]-TriFace->Scrx[i0])/dY;
  487. }
  488. dZ1 = (TriFace->Scrz[i2]-Z1)/dY;
  489. dV1 = (MappingV3 - V1) / dY;
  490. dU1 = (MappingU3 - U1) / dY;
  491. dC1 = (TriFace->Shades[i2]*65535.0f-C1)/dY;
  492. }
  493. }
  494. XL1 = (X1+(1<<19))>>20;
  495. XL2 = (X2+(1<<19))>>20;
  496. CL = C1;
  497. ZL = Z1;
  498. UL = U1;
  499. VL = V1;
  500. if ((XL2-XL1) > 0) {
  501. XL2 -= XL1;
  502. gmem += XL1;
  503. zbuf += XL1;
  504. XL1 += XL2;
  505. if (zb) do {
  506. if (*zbuf < ZL) {
  507. int av;
  508. if (CL < 0) av=addtable[0];
  509. else if (CL > (255<<8)) av=addtable[255];
  510. else av=addtable[CL>>8];
  511. *zbuf = ZL;
  512. *gmem = remap[av +
  513. texture[((UL>>16)&MappingU_AND) +
  514. ((VL>>vshift)&MappingV_AND)]];
  515. }
  516. zbuf++;
  517. gmem++;
  518. ZL += dZL;
  519. CL += dCL;
  520. UL += dUL;
  521. VL += dVL;
  522. } while (--XL2);
  523. else do {
  524. int av;
  525. if (CL < 0) av=addtable[0];
  526. else if (CL > (255<<8)) av=addtable[255];
  527. else av=addtable[CL>>8];
  528. *gmem++ = remap[av +
  529. texture[((UL>>16)&MappingU_AND) +
  530. ((VL>>vshift)&MappingV_AND)]];
  531. CL += dCL;
  532. UL += dUL;
  533. VL += dVL;
  534. } while (--XL2);
  535. gmem -= XL1;
  536. zbuf -= XL1;
  537. }
  538. zbuf += cam->ScreenWidth;
  539. gmem += cam->ScreenWidth;
  540. Z1 += dZ1;
  541. X1 += dX1;
  542. X2 += dX2;
  543. C1 += dC1;
  544. U1 += dU1;
  545. V1 += dV1;
  546. Y0++;
  547. }
  548. }