GOSVertex.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #include "MLRHeaders.hpp"
  5. Scalar
  6. GOSVertex::farClipReciprocal;
  7. Scalar
  8. ViewportScalars::MulX,
  9. ViewportScalars::MulY,
  10. ViewportScalars::AddX,
  11. ViewportScalars::AddY;
  12. #if FOG_HACK
  13. BYTE GOSVertex::fogTable[Limits::Max_Number_Of_FogStates][1024];
  14. #endif
  15. //#############################################################################
  16. //############################ GOSVertex #################################
  17. //#############################################################################
  18. GOSVertex::GOSVertex()
  19. {
  20. x = 0.0f;
  21. y = 0.0f;
  22. z = 0.0f;
  23. rhw = 1.0f;
  24. argb = 0xffffffff;
  25. u = 0.0f;
  26. v = 0.0f;
  27. frgb = 0xffffffff;
  28. }
  29. void
  30. GOSVertex::SetFogTableEntry(int entry, Scalar nearFog, Scalar farFog, Scalar fogDensity)
  31. {
  32. float Fog;
  33. Verify(farFog > nearFog);
  34. entry--;
  35. GOSVertex::fogTable[entry][0] = 0;
  36. for( int t1=0; t1<1024; t1++ )
  37. {
  38. if( 0.0f == fogDensity )
  39. {
  40. Fog=(farFog-t1)/(farFog-nearFog); // 0.0 = Linear fog table (from Start to End)
  41. }
  42. else
  43. {
  44. if( fogDensity<1.0f )
  45. {
  46. Fog=(float)exp(-fogDensity*t1); // 0.0->1.0 = FOG_EXP
  47. }
  48. else
  49. {
  50. Fog=(float)exp(-((fogDensity-1.0f)*t1)*((fogDensity-1.0f)*t1)); // 1.0->2.0 = FOG_EXP2
  51. }
  52. }
  53. if( Fog<0.0f )
  54. Fog=0.0f;
  55. if( Fog>1.0f )
  56. Fog=1.0f;
  57. GOSVertex::fogTable[entry][t1]=(BYTE)(255.9f*Fog);
  58. }
  59. }
  60. #if 0
  61. bool
  62. GOSCopyTriangleData
  63. ( GOSVertex *gos_vertices,
  64. Vector4D *coords,
  65. RGBAColor *colors,
  66. Vector2DScalar *texCoords,
  67. int offset0,
  68. int offset1,
  69. int offset2)
  70. {
  71. #if USE_ASSEMBLER_CODE
  72. _asm {
  73. ; gos_vertices[0].w = 1.0f/coords[offset0].w;
  74. mov ecx,dword ptr [coords]
  75. fld1
  76. mov edi,dword ptr [offset0]
  77. mov eax,edi
  78. shl eax,4
  79. fdiv dword ptr [eax+ecx+0Ch]
  80. add eax,ecx
  81. mov edx,dword ptr [gos_vertices]
  82. fst dword ptr [edx+0Ch]
  83. ; gos_vertices[0].x = coords[offset0].x * gos_vertices[0].w;
  84. fld st(0)
  85. fmul dword ptr [eax]
  86. fstp dword ptr [edx]
  87. ; gos_vertices[0].y = coords[offset0].y * gos_vertices[0].w;
  88. fld dword ptr [eax+4]
  89. fmul st,st(1)
  90. fstp dword ptr [edx+4]
  91. ; gos_vertices[0].z = coords[offset0].z * gos_vertices[0].w;
  92. fld dword ptr [eax+8]
  93. ; gos_vertices[1].w = 1.0f/coords[offset1].w;
  94. mov eax,dword ptr [offset1]
  95. fmul st,st(1)
  96. shl eax,4
  97. add eax,ecx
  98. fstp dword ptr [edx+8]
  99. fstp st(0)
  100. fld1
  101. fdiv dword ptr [eax+0Ch]
  102. fst dword ptr [edx+2Ch]
  103. ; gos_vertices[1].x = coords[offset1].x * gos_vertices[1].w;
  104. fld st(0)
  105. fmul dword ptr [eax]
  106. fstp dword ptr [edx+20h]
  107. ; gos_vertices[1].y = coords[offset1].y * gos_vertices[1].w;
  108. fld dword ptr [eax+4]
  109. fmul st,st(1)
  110. fstp dword ptr [edx+24h]
  111. ; gos_vertices[1].z = coords[offset1].z * gos_vertices[1].w;
  112. fld dword ptr [eax+8]
  113. ; gos_vertices[2].w = 1.0f/coords[offset2].w;
  114. mov eax,dword ptr [offset2]
  115. fmul st,st(1)
  116. shl eax,4
  117. add eax,ecx
  118. fstp dword ptr [edx+28h]
  119. fstp st(0)
  120. fld1
  121. fdiv dword ptr [eax+0Ch]
  122. fst dword ptr [edx+4Ch]
  123. ; gos_vertices[2].x = coords[offset2].x * gos_vertices[2].w;
  124. fld st(0)
  125. fmul dword ptr [eax]
  126. fstp dword ptr [edx+40h]
  127. ; gos_vertices[2].y = coords[offset2].y * gos_vertices[2].w;
  128. fld dword ptr [eax+4]
  129. fmul st,st(1)
  130. fstp dword ptr [edx+44h]
  131. ; gos_vertices[2].z = coords[offset2].z * gos_vertices[2].w;
  132. fld dword ptr [eax+8]
  133. fmul st,st(1)
  134. fstp dword ptr [edx+48h]
  135. fstp st(0)
  136. }
  137. #else
  138. gos_vertices[0].w = 1.0f/coords[offset0].w;
  139. gos_vertices[0].x = coords[offset0].x * gos_vertices[0].w;
  140. gos_vertices[0].y = coords[offset0].y * gos_vertices[0].w;
  141. gos_vertices[0].z = coords[offset0].z * gos_vertices[0].w;
  142. gos_vertices[1].w = 1.0f/coords[offset1].w;
  143. gos_vertices[1].x = coords[offset1].x * gos_vertices[1].w;
  144. gos_vertices[1].y = coords[offset1].y * gos_vertices[1].w;
  145. gos_vertices[1].z = coords[offset1].z * gos_vertices[1].w;
  146. gos_vertices[2].w = 1.0f/coords[offset2].w;
  147. gos_vertices[2].x = coords[offset2].x * gos_vertices[2].w;
  148. gos_vertices[2].y = coords[offset2].y * gos_vertices[2].w;
  149. gos_vertices[2].z = coords[offset2].z * gos_vertices[2].w;
  150. #endif
  151. // gos_vertices[0] = colors[offset0];
  152. // gos_vertices[1] = colors[offset1];
  153. // gos_vertices[2] = colors[offset2];
  154. Scalar f;
  155. #if USE_ASSEMBLER_CODE
  156. int argb;
  157. _asm {
  158. fld float_cheat
  159. mov esi, dword ptr [colors]
  160. mov eax, offset0
  161. shl eax, 4
  162. add esi, eax
  163. fld dword ptr [esi + 0Ch]
  164. mov ecx, dword ptr [esi + 0Ch]
  165. fadd st, st(1)
  166. rcl ecx, 1
  167. sbb eax, eax
  168. xor eax, -1
  169. fstp f
  170. xor ecx, ecx
  171. mov ebx, f
  172. and ebx, eax
  173. test ebx, 0000ff00h
  174. seta cl
  175. xor eax, eax
  176. sub eax, ecx
  177. or ebx, eax
  178. and ebx, 000000ffh
  179. mov argb, ebx
  180. fld dword ptr [esi]
  181. mov ecx, dword ptr [esi]
  182. fadd st, st(1)
  183. rcl ecx, 1
  184. sbb eax, eax
  185. xor eax, -1
  186. fstp f
  187. xor ecx, ecx
  188. mov ebx, f
  189. and ebx, eax
  190. test ebx, 0000ff00h
  191. seta cl
  192. xor eax, eax
  193. sub eax, ecx
  194. or ebx, eax
  195. and ebx, 000000ffh
  196. mov ecx, argb
  197. shl ecx, 8
  198. or ecx, ebx
  199. mov argb, ecx
  200. fld dword ptr [esi+4]
  201. mov ecx, dword ptr [esi+4]
  202. fadd st, st(1)
  203. rcl ecx, 1
  204. sbb eax, eax
  205. xor eax, -1
  206. fstp f
  207. xor ecx, ecx
  208. mov ebx, f
  209. and ebx, eax
  210. test ebx, 0000ff00h
  211. seta cl
  212. xor eax, eax
  213. sub eax, ecx
  214. or ebx, eax
  215. and ebx, 000000ffh
  216. mov ecx, argb
  217. shl ecx, 8
  218. or ecx, ebx
  219. mov argb, ecx
  220. fld dword ptr [esi+8]
  221. mov ecx, dword ptr [esi+8]
  222. fadd st, st(1)
  223. rcl ecx, 1
  224. sbb eax, eax
  225. xor eax, -1
  226. fstp f
  227. xor ecx, ecx
  228. mov ebx, f
  229. and ebx, eax
  230. test ebx, 0000ff00h
  231. seta cl
  232. xor eax, eax
  233. sub eax, ecx
  234. or ebx, eax
  235. and ebx, 000000ffh
  236. mov ecx, argb
  237. shl ecx, 8
  238. or ecx, ebx
  239. mov argb, ecx
  240. }
  241. gos_vertices[0].argb = argb;
  242. _asm {
  243. mov esi, dword ptr [colors]
  244. mov eax, offset1
  245. shl eax, 4
  246. add esi, eax
  247. fld dword ptr [esi + 0Ch]
  248. mov ecx, dword ptr [esi + 0Ch]
  249. fadd st, st(1)
  250. rcl ecx, 1
  251. sbb eax, eax
  252. xor eax, -1
  253. fstp f
  254. xor ecx, ecx
  255. mov ebx, f
  256. and ebx, eax
  257. test ebx, 0000ff00h
  258. seta cl
  259. xor eax, eax
  260. sub eax, ecx
  261. or ebx, eax
  262. and ebx, 000000ffh
  263. mov argb, ebx
  264. fld dword ptr [esi]
  265. mov ecx, dword ptr [esi]
  266. fadd st, st(1)
  267. rcl ecx, 1
  268. sbb eax, eax
  269. xor eax, -1
  270. fstp f
  271. xor ecx, ecx
  272. mov ebx, f
  273. and ebx, eax
  274. test ebx, 0000ff00h
  275. seta cl
  276. xor eax, eax
  277. sub eax, ecx
  278. or ebx, eax
  279. and ebx, 000000ffh
  280. mov ecx, argb
  281. shl ecx, 8
  282. or ecx, ebx
  283. mov argb, ecx
  284. fld dword ptr [esi+4]
  285. mov ecx, dword ptr [esi+4]
  286. fadd st, st(1)
  287. rcl ecx, 1
  288. sbb eax, eax
  289. xor eax, -1
  290. fstp f
  291. xor ecx, ecx
  292. mov ebx, f
  293. and ebx, eax
  294. test ebx, 0000ff00h
  295. seta cl
  296. xor eax, eax
  297. sub eax, ecx
  298. or ebx, eax
  299. and ebx, 000000ffh
  300. mov ecx, argb
  301. shl ecx, 8
  302. or ecx, ebx
  303. mov argb, ecx
  304. fld dword ptr [esi+8]
  305. mov ecx, dword ptr [esi+8]
  306. fadd st, st(1)
  307. rcl ecx, 1
  308. sbb eax, eax
  309. xor eax, -1
  310. fstp f
  311. xor ecx, ecx
  312. mov ebx, f
  313. and ebx, eax
  314. test ebx, 0000ff00h
  315. seta cl
  316. xor eax, eax
  317. sub eax, ecx
  318. or ebx, eax
  319. and ebx, 000000ffh
  320. mov ecx, argb
  321. shl ecx, 8
  322. or ecx, ebx
  323. mov argb, ecx
  324. }
  325. gos_vertices[1].argb = argb;
  326. _asm {
  327. mov esi, dword ptr [colors]
  328. mov eax, offset2
  329. shl eax, 4
  330. add esi, eax
  331. fld dword ptr [esi + 0Ch]
  332. mov ecx, dword ptr [esi + 0Ch]
  333. fadd st, st(1)
  334. rcl ecx, 1
  335. sbb eax, eax
  336. xor eax, -1
  337. fstp f
  338. xor ecx, ecx
  339. mov ebx, f
  340. and ebx, eax
  341. test ebx, 0000ff00h
  342. seta cl
  343. xor eax, eax
  344. sub eax, ecx
  345. or ebx, eax
  346. and ebx, 000000ffh
  347. mov argb, ebx
  348. fld dword ptr [esi]
  349. mov ecx, dword ptr [esi]
  350. fadd st, st(1)
  351. rcl ecx, 1
  352. sbb eax, eax
  353. xor eax, -1
  354. fstp f
  355. xor ecx, ecx
  356. mov ebx, f
  357. and ebx, eax
  358. test ebx, 0000ff00h
  359. seta cl
  360. xor eax, eax
  361. sub eax, ecx
  362. or ebx, eax
  363. and ebx, 000000ffh
  364. mov ecx, argb
  365. shl ecx, 8
  366. or ecx, ebx
  367. mov argb, ecx
  368. fld dword ptr [esi+4]
  369. mov ecx, dword ptr [esi+4]
  370. fadd st, st(1)
  371. rcl ecx, 1
  372. sbb eax, eax
  373. xor eax, -1
  374. fstp f
  375. xor ecx, ecx
  376. mov ebx, f
  377. and ebx, eax
  378. test ebx, 0000ff00h
  379. seta cl
  380. xor eax, eax
  381. sub eax, ecx
  382. or ebx, eax
  383. and ebx, 000000ffh
  384. mov ecx, argb
  385. shl ecx, 8
  386. or ecx, ebx
  387. mov argb, ecx
  388. fld dword ptr [esi+8]
  389. mov ecx, dword ptr [esi+8]
  390. faddp st(1), st
  391. rcl ecx, 1
  392. sbb eax, eax
  393. xor eax, -1
  394. fstp f
  395. xor ecx, ecx
  396. mov ebx, f
  397. and ebx, eax
  398. test ebx, 0000ff00h
  399. seta cl
  400. xor eax, eax
  401. sub eax, ecx
  402. or ebx, eax
  403. and ebx, 000000ffh
  404. mov ecx, argb
  405. shl ecx, 8
  406. or ecx, ebx
  407. mov argb, ecx
  408. }
  409. gos_vertices[2].argb = argb;
  410. #else
  411. f = colors[offset0].alpha * 255.99f;
  412. Clamp(f, 0.0f, 255.f);
  413. gos_vertices[0].argb = Positive_Float_To_Byte (f);
  414. f = colors[offset0].red * 255.99f;
  415. Clamp(f, 0.0f, 255.f);
  416. gos_vertices[0].argb = (gos_vertices[0].argb << 8) | Positive_Float_To_Byte (f);
  417. f = colors[offset0].green * 255.99f;
  418. Clamp(f, 0.0f, 255.f);
  419. gos_vertices[0].argb = (gos_vertices[0].argb << 8) | Positive_Float_To_Byte (f);
  420. f = colors[offset0].blue * 255.99f;
  421. Clamp(f, 0.0f, 255.f);
  422. gos_vertices[0].argb = (gos_vertices[0].argb << 8) | Positive_Float_To_Byte (f);
  423. f = colors[offset1].alpha * 255.99f;
  424. Clamp(f, 0.0f, 255.f);
  425. gos_vertices[1].argb = Positive_Float_To_Byte (f);
  426. f = colors[offset1].red * 255.99f;
  427. Clamp(f, 0.0f, 255.f);
  428. gos_vertices[1].argb = (gos_vertices[1].argb << 8) | Positive_Float_To_Byte (f);
  429. f = colors[offset1].green * 255.99f;
  430. Clamp(f, 0.0f, 255.f);
  431. gos_vertices[1].argb = (gos_vertices[1].argb << 8) | Positive_Float_To_Byte (f);
  432. f = colors[offset1].blue * 255.99f;
  433. Clamp(f, 0.0f, 255.f);
  434. gos_vertices[1].argb = (gos_vertices[1].argb << 8) | Positive_Float_To_Byte (f);
  435. f = colors[offset2].alpha * 255.99f;
  436. Clamp(f, 0.0f, 255.f);
  437. gos_vertices[2].argb = Positive_Float_To_Byte (f);
  438. f = colors[offset2].red * 255.99f;
  439. Clamp(f, 0.0f, 255.f);
  440. gos_vertices[2].argb = (gos_vertices[2].argb << 8) | Positive_Float_To_Byte (f);
  441. f = colors[offset2].green * 255.99f;
  442. Clamp(f, 0.0f, 255.f);
  443. gos_vertices[2].argb = (gos_vertices[2].argb << 8) | Positive_Float_To_Byte (f);
  444. f = colors[offset2].blue * 255.99f;
  445. Clamp(f, 0.0f, 255.f);
  446. gos_vertices[2].argb = (gos_vertices[2].argb << 8) | Positive_Float_To_Byte (f);
  447. #endif
  448. gos_vertices[0].u = texCoords[offset0][0];
  449. gos_vertices[0].v = texCoords[offset0][1];
  450. gos_vertices[1].u = texCoords[offset1][0];
  451. gos_vertices[1].v = texCoords[offset1][1];
  452. gos_vertices[2].u = texCoords[offset2][0];
  453. gos_vertices[2].v = texCoords[offset2][1];
  454. return true;
  455. }
  456. #endif