GOSPoint.cpp 10 KB

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