Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

957 lines
41 KiB

  1. dnl/*==========================================================================
  2. dnl *
  3. dnl * Copyright (C) 1998 Microsoft Corporation. All Rights Reserved.
  4. dnl *
  5. dnl * File: pvvid.h
  6. dnl * Content: Common defines for the geometry inner loop
  7. dnl *
  8. dnl ***************************************************************************/
  9. #define NEXT(pointer, stride, type) pointer = (type*)((char*)pointer + stride);
  10. dnl
  11. dnl//--------------------------------------------------------------------------
  12. dnl d_forloop
  13. dnl FOR loop
  14. dnl
  15. dnl Arguments:
  16. dnl $1 - loop variable
  17. dnl $2 - start value
  18. dnl $3 - end value
  19. dnl $4 - loop body
  20. dnl
  21. define(`d_forloop',
  22. `pushdef(`$1', `$2')d_forloopi(`$1', `$2', `$3', `$4')popdef(`$1')')dnl
  23. define(`d_forloopi', `$4`'ifelse($1, `$3', ,
  24. `define(`$1', incr($1))d_forloopi(`$1', `$2', `$3', `$4')')')dnl
  25. dnl//--------------------------------------------------------------------------
  26. dnl d_margin
  27. dnl
  28. dnl Repeats spaces ($1)*4 times
  29. dnl Arguments:
  30. dnl $1 - margin
  31. dnl
  32. define(`d_margin',`d_forloop(`i',1,eval(($1)*4),` ')')dnl
  33. dnl
  34. dnl//--------------------------------------------------------------------------
  35. define(`d_empty_',`')dnl
  36. dnl//--------------------------------------------------------------------------
  37. dnl// d_TransformVertex
  38. dnl//
  39. dnl// $1 - margin count
  40. dnl// $2 - input vector (D3DVECTOR*)
  41. dnl// $3 - matrix (D3DMATRIX*)
  42. dnl// $4 - output x
  43. dnl// $5 - output y
  44. dnl// $6 - output z
  45. dnl// $7 - output w
  46. dnl//
  47. define(`d_TransformVertex',`dnl
  48. d_empty_($1)$4 = $2->x*$3->_11 + $2->y*$3->_21 + $2->z*$3->_31 + $3->_41;
  49. d_margin($1)$5 = $2->x*$3->_12 + $2->y*$3->_22 + $2->z*$3->_32 + $3->_42;
  50. d_margin($1)$6 = $2->x*$3->_13 + $2->y*$3->_23 + $2->z*$3->_33 + $3->_43;
  51. d_margin($1)$7 = $2->x*$3->_14 + $2->y*$3->_24 + $2->z*$3->_34 + $3->_44;
  52. d_margin($1)if (pv->dwNumVerBlends)
  53. d_margin($1){
  54. d_margin($1) D3DVALUE* pWeight = (D3DVALUE*)((char*)($2) + 3*sizeof(D3DVALUE));
  55. d_margin($1) D3DVALUE weight = 0;
  56. d_margin($1) D3DVALUE xx, yy, zz, ww;
  57. d_margin($1) xx = $4;
  58. d_margin($1) yy = $5;
  59. d_margin($1) zz = $6;
  60. d_margin($1) ww = $7;
  61. d_margin($1) $4 = 0;
  62. d_margin($1) $5 = 0;
  63. d_margin($1) $6 = 0;
  64. d_margin($1) $7 = 0;
  65. d_margin($1) for (DWORD i=0; i < pv->dwNumVerBlends; i++)
  66. d_margin($1) {
  67. d_margin($1) D3DVALUE t = pWeight[i];
  68. d_margin($1) $4 += xx*t;
  69. d_margin($1) $5 += yy*t;
  70. d_margin($1) $6 += zz*t;
  71. d_margin($1) $7 += ww*t;
  72. d_margin($1) weight += t;
  73. d_margin($1) D3DMATRIXI *m = &pv->mCTM2[i];
  74. d_margin($1) xx = $2->x*m->_11 + $2->y*m->_21 + $2->z*m->_31 + m->_41;
  75. d_margin($1) yy = $2->x*m->_12 + $2->y*m->_22 + $2->z*m->_32 + m->_42;
  76. d_margin($1) zz = $2->x*m->_13 + $2->y*m->_23 + $2->z*m->_33 + m->_43;
  77. d_margin($1) ww = $2->x*m->_14 + $2->y*m->_24 + $2->z*m->_34 + m->_44;
  78. d_margin($1) }
  79. d_margin($1) weight = D3DVAL(1) - weight;
  80. d_margin($1) $4 += xx*weight;
  81. d_margin($1) $5 += yy*weight;
  82. d_margin($1) $6 += zz*weight;
  83. d_margin($1) $7 += ww*weight;
  84. d_margin($1)}') dnl
  85. dnl//--------------------------------------------------------------------------
  86. dnl// d_ComputeClipCode
  87. dnl// Arguments:
  88. dnl// $1 - margin count
  89. dnl// x,y,z,w should be defined as float
  90. dnl// Output:
  91. dnl// clip should be defined as int
  92. dnl//
  93. define(`d_ComputeClipCode',`dnl
  94. d_empty_($1){
  95. d_margin($1) D3DVALUE xx = w - x;
  96. d_margin($1) D3DVALUE yy = w - y;
  97. d_margin($1) D3DVALUE zz = w - z;
  98. d_margin($1) clip =((ASINT32(x) & 0x80000000) >> (32-D3DCLIP_LEFTBIT)) |
  99. d_margin($1) ((ASINT32(y) & 0x80000000) >> (32-D3DCLIP_BOTTOMBIT)) |
  100. d_margin($1) ((ASINT32(z) & 0x80000000) >> (32-D3DCLIP_FRONTBIT)) |
  101. d_margin($1) ((ASINT32(xx) & 0x80000000) >> (32-D3DCLIP_RIGHTBIT)) |
  102. d_margin($1) ((ASINT32(yy) & 0x80000000) >> (32-D3DCLIP_TOPBIT)) |
  103. d_margin($1) ((ASINT32(zz) & 0x80000000) >> (32-D3DCLIP_BACKBIT));
  104. d_margin($1) if (pv->dwMaxUserClipPlanes)
  105. d_margin($1) {
  106. d_margin($1) DWORD dwClipBit = D3DCLIP_GEN0;
  107. d_margin($1) for (DWORD i=0; i < pv->dwMaxUserClipPlanes; i++)
  108. d_margin($1) {
  109. d_margin($1) if (x*pv->userClipPlane[i].x +
  110. d_margin($1) y*pv->userClipPlane[i].y +
  111. d_margin($1) z*pv->userClipPlane[i].z +
  112. d_margin($1) w*pv->userClipPlane[i].w < 0)
  113. d_margin($1) {
  114. d_margin($1) clip |= dwClipBit;
  115. d_margin($1) }
  116. d_margin($1) dwClipBit <<= 1;
  117. d_margin($1) }
  118. d_margin($1) }
  119. d_margin($1)}') dnl
  120. dnl//--------------------------------------------------------------------------
  121. dnl// d_ComputeClipCodeGB
  122. dnl//
  123. dnl// Arguments:
  124. dnl// $1 - margin count
  125. dnl// x,y,z,w should be defined as float
  126. dnl// Output:
  127. dnl// clip should be defined as int
  128. define(`d_ComputeClipCodeGB',`dnl
  129. d_empty_($1)// We do guardband check in the projection space, so
  130. d_margin($1)// we transform X and Y of the vertex there
  131. d_margin($1)D3DVALUE xnew = x * pv->vcache.gb11 + w * pv->vcache.gb41;
  132. d_margin($1)D3DVALUE ynew = y * pv->vcache.gb22 + w * pv->vcache.gb42;
  133. d_margin($1)D3DVALUE xx1 = w - xnew;
  134. d_margin($1)D3DVALUE yy1 = w - ynew;
  135. d_margin($1)clip |= ((ASINT32(xnew) & 0x80000000) >> (32-D3DCLIPGB_LEFTBIT)) |
  136. d_margin($1) ((ASINT32(ynew) & 0x80000000) >> (32-D3DCLIPGB_BOTTOMBIT)) |
  137. d_margin($1) ((ASINT32(xx1) & 0x80000000) >> (32-D3DCLIPGB_RIGHTBIT)) |
  138. d_margin($1) ((ASINT32(yy1) & 0x80000000) >> (32-D3DCLIPGB_TOPBIT));') dnl
  139. dnl//--------------------------------------------------------------------------
  140. dnl// d_TransformVertexToCameraSpace
  141. dnl//
  142. dnl// This part of code transforms vertex and normal to the camera space to do
  143. dnl// lighting there
  144. dnl//
  145. dnl// Input:
  146. dnl// $1 - margin count
  147. dnl// $2 - pointer to the vertex coordinates (D3DVERTEX*)
  148. dnl// $3 - pointer to the output vertex (D3DVERTEX*)
  149. dnl//
  150. define(`d_TransformVertexToCameraSpace',`dnl
  151. d_empty_($1)// Transform vertex position to the eye space
  152. d_margin($1)$3->x = $2->x*pv->mWV._11 +
  153. d_margin($1) $2->y*pv->mWV._21 +
  154. d_margin($1) $2->z*pv->mWV._31 + pv->mWV._41;
  155. d_margin($1)$3->y = $2->x*pv->mWV._12 +
  156. d_margin($1) $2->y*pv->mWV._22 +
  157. d_margin($1) $2->z*pv->mWV._32 + pv->mWV._42;
  158. d_margin($1)$3->z = $2->x*pv->mWV._13 +
  159. d_margin($1) $2->y*pv->mWV._23 +
  160. d_margin($1) $2->z*pv->mWV._33 + pv->mWV._43;
  161. d_margin($1)if (pv->dwNumVerBlends)
  162. d_margin($1){
  163. d_margin($1) D3DVALUE* pWeight = (D3DVALUE*)((char*)($2) + 3*sizeof(D3DVALUE));
  164. d_margin($1) D3DVALUE weight = 0;
  165. d_margin($1) D3DVALUE xx, yy, zz;
  166. d_margin($1) xx = $3->x;
  167. d_margin($1) yy = $3->y;
  168. d_margin($1) zz = $3->z;
  169. d_margin($1) $3->x = 0;
  170. d_margin($1) $3->y = 0;
  171. d_margin($1) $3->z = 0;
  172. d_margin($1) for (DWORD i=0; i < pv->dwNumVerBlends; i++)
  173. d_margin($1) {
  174. d_margin($1) D3DVALUE t = pWeight[i];
  175. d_margin($1) $3->x += xx*t;
  176. d_margin($1) $3->y += yy*t;
  177. d_margin($1) $3->z += zz*t;
  178. d_margin($1) weight += t;
  179. d_margin($1) D3DMATRIXI *m = &pv->mWV2[i];
  180. d_margin($1) xx = $2->x*m->_11 + $2->y*m->_21 + $2->z*m->_31 + m->_41;
  181. d_margin($1) yy = $2->x*m->_12 + $2->y*m->_22 + $2->z*m->_32 + m->_42;
  182. d_margin($1) zz = $2->x*m->_13 + $2->y*m->_23 + $2->z*m->_33 + m->_43;
  183. d_margin($1) }
  184. d_margin($1) weight = D3DVAL(1) - weight;
  185. d_margin($1) $3->x += xx*weight;
  186. d_margin($1) $3->y += yy*weight;
  187. d_margin($1) $3->z += zz*weight;
  188. d_margin($1)}') dnl
  189. dnl//--------------------------------------------------------------------------
  190. dnl// d_TransformNormalToCameraSpace
  191. dnl//
  192. dnl// This part of code transforms vertex and normal to the camera space to do
  193. dnl// lighting there
  194. dnl//
  195. dnl// Input:
  196. dnl// $1 - margin count
  197. dnl// $2 - pointer to the normal (D3DVECTOR*)
  198. dnl// $3 - pointer to the output normal (D3DVECTOR*)
  199. dnl// $4 - pointer to the input coordinates (needed for the vertex blending)
  200. dnl//
  201. define(`d_TransformNormalToCameraSpace',`dnl
  202. d_margin($1)// Transform vertex normal to the eye space
  203. d_margin($1)// We use inverse transposed matrix
  204. d_margin($1)$3->x = $2->x*pv->mWVI._11 + $2->y*pv->mWVI._12 + $2->z*pv->mWVI._13;
  205. d_margin($1)$3->y = $2->x*pv->mWVI._21 + $2->y*pv->mWVI._22 + $2->z*pv->mWVI._23;
  206. d_margin($1)$3->z = $2->x*pv->mWVI._31 + $2->y*pv->mWVI._32 + $2->z*pv->mWVI._33;
  207. d_margin($1)if (pv->dwNumVerBlends)
  208. d_margin($1){
  209. d_margin($1) D3DVALUE* pWeight = (D3DVALUE*)((char*)($4) + 3*sizeof(D3DVALUE));
  210. d_margin($1) D3DVALUE weight = 0;
  211. d_margin($1) D3DVALUE xx, yy, zz;
  212. d_margin($1) xx = $3->x;
  213. d_margin($1) yy = $3->y;
  214. d_margin($1) zz = $3->z;
  215. d_margin($1) $3->x = 0;
  216. d_margin($1) $3->y = 0;
  217. d_margin($1) $3->z = 0;
  218. d_margin($1) for (DWORD i=0; i < pv->dwNumVerBlends; i++)
  219. d_margin($1) {
  220. d_margin($1) D3DVALUE t = pWeight[i];
  221. d_margin($1) $3->x += xx*t;
  222. d_margin($1) $3->y += yy*t;
  223. d_margin($1) $3->z += zz*t;
  224. d_margin($1) weight += t;
  225. d_margin($1) D3DMATRIXI *m = &pv->mWVI2[i];
  226. d_margin($1) xx = $2->x*m->_11 + $2->y*m->_12 + $2->z*m->_13;
  227. d_margin($1) yy = $2->x*m->_21 + $2->y*m->_22 + $2->z*m->_23;
  228. d_margin($1) zz = $2->x*m->_31 + $2->y*m->_32 + $2->z*m->_33;
  229. d_margin($1) }
  230. d_margin($1) weight = D3DVAL(1) - weight;
  231. d_margin($1) $3->x += xx*weight;
  232. d_margin($1) $3->y += yy*weight;
  233. d_margin($1) $3->z += zz*weight;
  234. d_margin($1)}
  235. d_margin($1)if (pv->dwDeviceFlags & D3DDEV_NORMALIZENORMALS)
  236. d_margin($1) VecNormalizeFast(*$3);') dnl
  237. dnl//--------------------------------------------------------------------------
  238. dnl// d_ComputeScreenCoordinatesNoOutput
  239. dnl//
  240. dnl// Computes screen coordinates and output them to the
  241. dnl// Arguments:
  242. dnl// $1 - margin count
  243. dnl// $2 - x in the clipping space
  244. dnl// $3 - y in the clipping space
  245. dnl// $4 - z in the clipping space
  246. dnl// $5 - 1/w in the clipping space
  247. dnl// $6 - output1 x
  248. dnl// $7 - output1 y
  249. dnl// $8 - output1 z
  250. dnl//
  251. dnl// Local variables x,y,z should be declared as float
  252. dnl//
  253. define(`d_ComputeScreenCoordinatesNoOutput',`dnl
  254. d_empty_($1)$6 = $2 * $5 * pv->vcache.scaleX + pv->vcache.offsetX;
  255. d_margin($1)$7 = $3 * $5 * pv->vcache.scaleY + pv->vcache.offsetY;
  256. d_margin($1)if (!(pv->dwDeviceFlags & D3DDEV_DONOTUPDATEEXTENTS))
  257. d_margin($1){
  258. d_margin($1) if ($6 < pv->rExtents.x1) pv->rExtents.x1 = $6;
  259. d_margin($1) if ($6 > pv->rExtents.x2) pv->rExtents.x2 = $6;
  260. d_margin($1) if ($7 < pv->rExtents.y1) pv->rExtents.y1 = $7;
  261. d_margin($1) if ($7 > pv->rExtents.y2) pv->rExtents.y2 = $7;
  262. d_margin($1)}
  263. d_margin($1)$8 = $4*pv->vcache.scaleZ*$5 + pv->vcache.offsetZ;') dnl
  264. dnl//--------------------------------------------------------------------------
  265. dnl// d_ComputeScreenCoordinates
  266. dnl//
  267. dnl// Computes screen coordinates and output them to the
  268. dnl// Arguments:
  269. dnl// $1 - margin count
  270. dnl// $2 - x in the clipping space
  271. dnl// $3 - y in the clipping space
  272. dnl// $4 - z in the clipping space
  273. dnl// $5 - 1/w in the clipping space
  274. dnl// $6 - pointer to the D3DTLVERTEX (sx, sy, sz, rhw will be set
  275. dnl//
  276. dnl// Local variables x,y,z should be declared as float
  277. dnl//
  278. define(`d_ComputeScreenCoordinates',`dnl
  279. d_empty_($1)d_ComputeScreenCoordinatesNoOutput($1,$2,$3,$4,$5,x,y,z)
  280. d_margin($1)$6->sx = x;
  281. d_margin($1)$6->sy = y;
  282. d_margin($1)$6->sz = z;
  283. d_margin($1)$6->rhw = $5;') dnl
  284. dnl//---------------------------------------------------------------------
  285. dnl// d_MakeOutputColors
  286. dnl//
  287. dnl// - Finishes computing of diffuse color, by computing emissive and ambient
  288. dnl// scene colors
  289. dnl// - Converts diffuse and specular colors to DWORDs and writes them to the
  290. dnl// d_dwOutDiffuse and d_dwOutSpecular
  291. dnl//
  292. dnl// $1 - margin count
  293. dnl// d_LightingFlags - DWORD
  294. dnl// d_OutDiffuse - temporary output diffuse color, (D3DFE_COLOR)
  295. dnl// d_OutSpecular - temporary output specular color, (D3DFE_COLOR)
  296. dnl// d_dwOutDiffuse - output diffuse color, (DWORD)
  297. dnl// d_dwOutSpecular - output specular color, (DWORD)
  298. dnl//
  299. define(`d_MakeOutputColors',`dnl
  300. d_empty_($1)if (pv->dwFlags & (D3DPV_COLORVERTEX_A | D3DPV_COLORVERTEX_E))
  301. d_margin($1){
  302. d_margin($1) if (!(d_LightingFlags & __LIGHT_DIFFUSECOMPUTED))
  303. d_margin($1) {
  304. d_margin($1) d_OutDiffuse.r = 0;
  305. d_margin($1) d_OutDiffuse.g = 0;
  306. d_margin($1) d_OutDiffuse.b = 0;
  307. d_margin($1) }
  308. d_margin($1) if (pv->dwFlags & D3DPV_COLORVERTEX_A)
  309. d_margin($1) {
  310. d_margin($1) DWORD color = **ppAmbientSource;
  311. d_margin($1) d_OutDiffuse.r += RGBA_GETRED (color) * pv->lighting.ambientScene.r;
  312. d_margin($1) d_OutDiffuse.g += RGBA_GETGREEN(color) * pv->lighting.ambientScene.g;
  313. d_margin($1) d_OutDiffuse.b += RGBA_GETBLUE (color) * pv->lighting.ambientScene.b;
  314. d_margin($1) }
  315. d_margin($1) else
  316. d_margin($1) {
  317. d_margin($1) d_OutDiffuse.r += pv->lighting.ambientSceneScaled.r * pv->lighting.material.ambient.r;
  318. d_margin($1) d_OutDiffuse.g += pv->lighting.ambientSceneScaled.g * pv->lighting.material.ambient.g;
  319. d_margin($1) d_OutDiffuse.b += pv->lighting.ambientSceneScaled.b * pv->lighting.material.ambient.b;
  320. d_margin($1) }
  321. d_margin($1) if (pv->dwFlags & D3DPV_COLORVERTEX_E)
  322. d_margin($1) {
  323. d_margin($1) DWORD color = **ppEmissiveSource;
  324. d_margin($1) d_OutDiffuse.r += RGBA_GETRED (color);
  325. d_margin($1) d_OutDiffuse.g += RGBA_GETGREEN(color);
  326. d_margin($1) d_OutDiffuse.b += RGBA_GETBLUE (color);
  327. d_margin($1) }
  328. d_margin($1) else
  329. d_margin($1) {
  330. d_margin($1) d_OutDiffuse.r += pv->lighting.material.emissive.r * D3DVAL(255);
  331. d_margin($1) d_OutDiffuse.g += pv->lighting.material.emissive.g * D3DVAL(255);
  332. d_margin($1) d_OutDiffuse.b += pv->lighting.material.emissive.b * D3DVAL(255);
  333. d_margin($1) }
  334. d_margin($1) d_LightingFlags |= __LIGHT_DIFFUSECOMPUTED;
  335. d_margin($1)}
  336. d_margin($1)if (d_LightingFlags & __LIGHT_DIFFUSECOMPUTED)
  337. d_margin($1){
  338. d_margin($1) if (!(pv->dwFlags & (D3DPV_COLORVERTEX_A | D3DPV_COLORVERTEX_E)))
  339. d_margin($1) {
  340. d_margin($1) d_OutDiffuse.r += pv->lighting.diffuse0.r;
  341. d_margin($1) d_OutDiffuse.g += pv->lighting.diffuse0.g;
  342. d_margin($1) d_OutDiffuse.b += pv->lighting.diffuse0.b;
  343. d_margin($1) }
  344. d_margin($1) int r = FTOI(d_OutDiffuse.r);
  345. d_margin($1) int g = FTOI(d_OutDiffuse.g);
  346. d_margin($1) int b = FTOI(d_OutDiffuse.b);
  347. d_margin($1) if (r < 0) r = 0; else if (r > 255) r = 255;
  348. d_margin($1) if (g < 0) g = 0; else if (g > 255) g = 255;
  349. d_margin($1) if (b < 0) b = 0; else if (b > 255) b = 255;
  350. d_margin($1) if (!(pv->dwFlags & D3DPV_COLORVERTEX_D))
  351. d_margin($1) d_dwOutDiffuse = pv->lighting.alpha + (r<<16) + (g<<8) + b;
  352. d_margin($1) else
  353. d_margin($1) d_dwOutDiffuse = (**ppDiffuseSource & 0xFF000000) + (r<<16) + (g<<8) + b;
  354. d_margin($1)}
  355. d_margin($1)else
  356. d_margin($1){
  357. d_margin($1) if (!(pv->dwFlags & D3DPV_COLORVERTEX_D))
  358. d_margin($1) d_dwOutDiffuse = pv->lighting.alpha + pv->lighting.dwDiffuse0;
  359. d_margin($1) else
  360. d_margin($1) d_dwOutDiffuse = pv->lighting.dwDiffuse0 + (**ppDiffuseSource & 0xFF000000);
  361. d_margin($1)}
  362. d_margin($1)
  363. d_margin($1)if (d_LightingFlags & __LIGHT_SPECULARCOMPUTED)
  364. d_margin($1){
  365. d_margin($1) int r = FTOI(d_OutSpecular.r);
  366. d_margin($1) int g = FTOI(d_OutSpecular.g);
  367. d_margin($1) int b = FTOI(d_OutSpecular.b);
  368. d_margin($1) if (r < 0) r = 0; else if (r > 255) r = 255;
  369. d_margin($1) if (g < 0) g = 0; else if (g > 255) g = 255;
  370. d_margin($1) if (b < 0) b = 0; else if (b > 255) b = 255;
  371. d_margin($1) if (!(pv->dwFlags & D3DPV_COLORVERTEX_S))
  372. d_margin($1) d_dwOutSpecular = pv->lighting.alphaSpecular + (r<<16) + (g<<8) + b;
  373. d_margin($1) else
  374. d_margin($1) d_dwOutSpecular = (**ppSpecularSource & 0xFF000000) + (r<<16) + (g<<8) + b;
  375. d_margin($1)}
  376. d_margin($1)else
  377. d_margin($1)if (!(pv->dwFlags & D3DPV_DONOTCOPYSPECULAR))
  378. d_margin($1){
  379. d_margin($1) if (!(pv->dwDeviceFlags & D3DDEV_SPECULARENABLE))
  380. d_margin($1) if (pv->dwVIDIn & D3DFVF_SPECULAR)
  381. d_margin($1) d_dwOutSpecular = *inSpecular;
  382. d_margin($1) else
  383. d_margin($1) d_dwOutSpecular = __DEFAULT_SPECULAR;
  384. d_margin($1) else
  385. d_margin($1) if (!(pv->dwFlags & D3DPV_COLORVERTEX_S))
  386. d_margin($1) d_dwOutSpecular = pv->lighting.alphaSpecular;
  387. d_margin($1) else
  388. d_margin($1) d_dwOutSpecular = (**ppSpecularSource & 0xFF000000);
  389. d_margin($1)}')
  390. dnl//---------------------------------------------------------------------
  391. dnl// d_MakeOutputColorsNoColorVertex
  392. dnl//
  393. dnl// - Finishes computing of diffuse color, by computing emissive and ambient
  394. dnl// scene colors
  395. dnl// - Converts diffuse and specular colors to DWORDs and writes them to the
  396. dnl// d_dwOutDiffuse and d_dwOutSpecular
  397. dnl//
  398. dnl// $1 - margin count
  399. dnl// d_LightingFlags - DWORD
  400. dnl// d_OutDiffuse - temporary output diffuse color, (D3DFE_COLOR)
  401. dnl// d_OutSpecular - temporary output specular color, (D3DFE_COLOR)
  402. dnl// d_dwOutDiffuse - output diffuse color, (DWORD)
  403. dnl// d_dwOutSpecular - output specular color, (DWORD)
  404. dnl//
  405. define(`d_MakeOutputColorsNoColorVertex',`dnl
  406. d_margin($1)if (d_LightingFlags & __LIGHT_DIFFUSECOMPUTED)
  407. d_margin($1){
  408. d_margin($1) d_OutDiffuse.r += pv->lighting.diffuse0.r;
  409. d_margin($1) d_OutDiffuse.g += pv->lighting.diffuse0.g;
  410. d_margin($1) d_OutDiffuse.b += pv->lighting.diffuse0.b;
  411. d_margin($1) int r = FTOI(d_OutDiffuse.r);
  412. d_margin($1) int g = FTOI(d_OutDiffuse.g);
  413. d_margin($1) int b = FTOI(d_OutDiffuse.b);
  414. d_margin($1) if (r < 0) r = 0; else if (r > 255) r = 255;
  415. d_margin($1) if (g < 0) g = 0; else if (g > 255) g = 255;
  416. d_margin($1) if (b < 0) b = 0; else if (b > 255) b = 255;
  417. d_margin($1) d_dwOutDiffuse = pv->lighting.alpha + (r<<16) + (g<<8) + b;
  418. d_margin($1)}
  419. d_margin($1)else
  420. d_margin($1){
  421. d_margin($1) d_dwOutDiffuse = pv->lighting.alpha + pv->lighting.dwDiffuse0;
  422. d_margin($1)}
  423. d_margin($1)
  424. d_margin($1)if (d_LightingFlags & __LIGHT_SPECULARCOMPUTED)
  425. d_margin($1){
  426. d_margin($1) int r = FTOI(d_OutSpecular.r);
  427. d_margin($1) int g = FTOI(d_OutSpecular.g);
  428. d_margin($1) int b = FTOI(d_OutSpecular.b);
  429. d_margin($1) if (r < 0) r = 0; else if (r > 255) r = 255;
  430. d_margin($1) if (g < 0) g = 0; else if (g > 255) g = 255;
  431. d_margin($1) if (b < 0) b = 0; else if (b > 255) b = 255;
  432. d_margin($1) d_dwOutSpecular = pv->lighting.alphaSpecular + (r<<16) + (g<<8) + b;
  433. d_margin($1)}
  434. d_margin($1)else
  435. d_margin($1)if (!(pv->dwFlags & D3DPV_DONOTCOPYSPECULAR))
  436. d_margin($1){
  437. d_margin($1) if (!(pv->dwDeviceFlags & D3DDEV_SPECULARENABLE))
  438. d_margin($1) if (pv->dwVIDIn & D3DFVF_SPECULAR)
  439. d_margin($1) d_dwOutSpecular = *inSpecular;
  440. d_margin($1) else
  441. d_margin($1) d_dwOutSpecular = __DEFAULT_SPECULAR;
  442. d_margin($1) else
  443. d_margin($1) d_dwOutSpecular = pv->lighting.alphaSpecular;
  444. d_margin($1)}')
  445. dnl//--------------------------------------------------------------------------
  446. dnl// d_ComputeOutputColors
  447. dnl//
  448. dnl// Compute lighting and fog for a vertex
  449. dnl//
  450. dnl// Arguments:
  451. dnl// $1 - margin count
  452. dnl// $2 - pointer to the vertex coordinates
  453. dnl// $3 - pointer to the vertex normal
  454. dnl// $4 - pointer to the diffuse vertex color (used when there is no lighting)
  455. dnl// $5 - pointer to the specular vertex color (used when there is no lighting)
  456. dnl// Output:
  457. dnl// vertex diffuse and specular colors in the pv->lighting
  458. dnl//
  459. dnl
  460. define(`d_dwOutDiffuse',pv->lighting.outDiffuse)dnl
  461. define(`d_dwOutSpecular',pv->lighting.outSpecular)dnl
  462. define(`d_OutDiffuse',pv->lighting.diffuse)dnl
  463. define(`d_OutSpecular',pv->lighting.specular)dnl
  464. define(`d_LightingFlags',pv->lighting.dwLightingFlags)dnl
  465. dnl
  466. define(`d_ComputeOutputColors',`dnl
  467. d_empty_($1)pv->lighting.dwLightingFlags = 0;
  468. d_margin($1)if (pv->dwDeviceFlags & D3DDEV_POSITIONINCAMERASPACE)
  469. d_margin($1){
  470. d_margin($1) d_TransformVertexToCameraSpace($1+1, $2, ((D3DVERTEX*)&EyeSpaceData.dvPosition))
  471. d_margin($1) pv->lighting.dwLightingFlags |= __LIGHT_VERTEXTRANSFORMED;
  472. d_margin($1)}
  473. d_margin($1)if (pv->dwDeviceFlags & D3DDEV_NORMALINCAMERASPACE)
  474. d_margin($1){
  475. d_margin($1) d_TransformNormalToCameraSpace($1+1, inNormal, ((D3DVECTOR*)&EyeSpaceData.dvNormal), $2)
  476. d_margin($1) pv->lighting.dwLightingFlags |= __LIGHT_NORMALTRANSFORMED;
  477. d_margin($1)}
  478. d_margin($1)if (pv->dwFlags & D3DPV_LIGHTING)
  479. d_margin($1){
  480. d_margin($1) pv->lighting.diffuse.r = 0;
  481. d_margin($1) pv->lighting.diffuse.g = 0;
  482. d_margin($1) pv->lighting.diffuse.b = 0;
  483. d_margin($1) pv->lighting.specular.r = 0;
  484. d_margin($1) pv->lighting.specular.g = 0;
  485. d_margin($1) pv->lighting.specular.b = 0;
  486. d_margin($1) if (pv->dwFlags & D3DPV_DOCOLORVERTEX)
  487. d_margin($1) {
  488. d_margin($1) if (pv->dwFlags & D3DPV_COLORVERTEX_A)
  489. d_margin($1) pv->lighting.vertexAmbient = **ppAmbientSource;
  490. d_margin($1) if (pv->dwFlags & D3DPV_COLORVERTEX_D)
  491. d_margin($1) pv->lighting.vertexDiffuse = **ppDiffuseSource;
  492. d_margin($1) if (pv->dwFlags & D3DPV_COLORVERTEX_S)
  493. d_margin($1) pv->lighting.vertexSpecular = **ppSpecularSource;
  494. d_margin($1) }
  495. d_margin($1) D3DI_LIGHT *light = pv->lighting.activeLights;
  496. d_margin($1) while (light)
  497. d_margin($1) {
  498. d_margin($1) (*light->lightVertexFunc)(pv, light, (D3DVERTEX*)$2, $3, &EyeSpaceData);
  499. d_margin($1) light = light->next;
  500. d_margin($1) }
  501. d_margin($1) d_MakeOutputColors($1+1)
  502. d_margin($1)}
  503. d_margin($1)else
  504. d_margin($1)if (pv->dwVIDIn & (D3DFVF_DIFFUSE | D3DFVF_SPECULAR))
  505. d_margin($1){
  506. d_margin($1) if (pv->dwVIDIn & D3DFVF_DIFFUSE)
  507. d_margin($1) pv->lighting.outDiffuse = *(DWORD*)($4);
  508. d_margin($1) if (pv->dwVIDIn & D3DFVF_SPECULAR)
  509. d_margin($1) pv->lighting.outSpecular = *(DWORD*)($5);
  510. d_margin($1)}
  511. d_margin($1)if (pv->dwFlags & D3DPV_FOG)
  512. d_margin($1){
  513. d_margin($1) ComputeFog(pv, *(D3DVECTOR*)($2), &EyeSpaceData);
  514. d_margin($1)}') dnl
  515. dnl//--------------------------------------------------------------------------
  516. dnl// d_DoLightingAndFog
  517. dnl//
  518. dnl// Arguments:
  519. dnl// $1 - margin count
  520. dnl// $2 - pointer to the vertex coordinates
  521. dnl// $3 - pointer to the vertex normal
  522. dnl// $4 - pointer to the diffuse vertex color (used when there is no lighting)
  523. dnl// $5 - pointer to the specular vertex color (used when there is no lighting)
  524. dnl// $6 - pointer to output vertex
  525. dnl// Output:
  526. dnl// vertex diffuse and specular colors in the pv->lighting
  527. dnl// Pointer to the output will be moved to the next DWORD
  528. dnl//
  529. define(`d_DoLightingAndFog',`dnl
  530. d_empty_($1)d_ComputeOutputColors($1, $2, $3, $4, $5, $6)
  531. d_margin($1)if (!(pv->dwFlags & D3DPV_DONOTCOPYDIFFUSE))
  532. d_margin($1) *(DWORD*)((BYTE*)$6 + pv->diffuseOffsetOut) = pv->lighting.outDiffuse;
  533. d_margin($1)if (!(pv->dwFlags & D3DPV_DONOTCOPYSPECULAR))
  534. d_margin($1) *(DWORD*)((BYTE*)$6 + pv->specularOffsetOut) = pv->lighting.outSpecular;') dnl
  535. dnl//--------------------------------------------------------------------------
  536. dnl// d_UpdateExtents
  537. dnl//
  538. define(`d_UpdateExtents',`
  539. if (!(pv->dwDeviceFlags & D3DDEV_DONOTUPDATEEXTENTS))
  540. {
  541. // Adjust exstents
  542. pv->rExtents.x2 += pv->dvExtentsAdjust;
  543. pv->rExtents.y2 += pv->dvExtentsAdjust;
  544. pv->rExtents.x1 -= pv->dvExtentsAdjust;
  545. pv->rExtents.y1 -= pv->dvExtentsAdjust;
  546. // Clamp to viewport
  547. if (pv->rExtents.x1 < pv->vcache.minX)
  548. pv->rExtents.x1 = pv->vcache.minX;
  549. if (pv->rExtents.y1 < pv->vcache.minY)
  550. pv->rExtents.y1 = pv->vcache.minY;
  551. if (pv->rExtents.x2 > pv->vcache.maxX)
  552. pv->rExtents.x2 = pv->vcache.maxX;
  553. if (pv->rExtents.y2 > pv->vcache.maxY)
  554. pv->rExtents.y2 = pv->vcache.maxY;
  555. }') dnl
  556. dnl//--------------------------------------------------------------------------
  557. dnl// d_CopyTextureCoordStrided
  558. dnl//
  559. dnl// Copies texture coordinates from input to the output
  560. dnl// $1 - margin count
  561. dnl// $2 - pointer to the output texture
  562. dnl//
  563. define(`d_CopyTextureCoordStrided',`dnl
  564. d_empty_($1)D3DVALUE *_pOut = (D3DVALUE*)$2;
  565. d_margin($1)if (!(dwDeviceFlags & D3DDEV_NOFVFANDNOTEXTURE))
  566. d_margin($1){
  567. d_margin($1) if (!(pv->dwDeviceFlags & (D3DDEV_TEXTURETRANSFORM | D3DDEV_REMAPTEXTUREINDICES)))
  568. d_margin($1) {
  569. d_margin($1) for (DWORD k=0; k < pv->nOutTexCoord; k++)
  570. d_margin($1) {
  571. d_margin($1) const DWORD dwSize = pv->dwTextureCoordSize[k];
  572. d_margin($1) memcpy(_pOut, inTexture[k], dwSize);
  573. d_margin($1) NEXT(_pOut, dwSize, D3DVALUE);
  574. d_margin($1) }
  575. d_margin($1) }
  576. d_margin($1) else
  577. d_margin($1) if (!(pv->dwDeviceFlags & D3DDEV_REMAPTEXTUREINDICES))
  578. d_margin($1) {
  579. d_margin($1) for (DWORD k=0; k < pv->nOutTexCoord; k++)
  580. d_margin($1) {
  581. d_margin($1) const DWORD dwSize = pv->dwTextureCoordSize[k];
  582. d_margin($1) const DWORD dwInpSize = pv->dwInpTextureCoordSize[k];
  583. d_margin($1) if (pv->pmTexture[k] == 0)
  584. d_margin($1) memcpy(_pOut, inTexture[k], dwSize);
  585. d_margin($1) else
  586. d_margin($1) {
  587. d_margin($1) const DWORD m = dwInpSize >> 2; // Number of input tex. coord.
  588. d_margin($1) const DWORD n = dwSize >> 2; // Number of output tex. coord.
  589. d_margin($1) (*(g_pfnTextureTransform[MakeTexTransformFuncIndex(m ,n)]))
  590. d_margin($1) (inTexture[k], _pOut, pv->pmTexture[k]);
  591. d_margin($1) }
  592. d_margin($1) NEXT(_pOut, dwSize, D3DVALUE);
  593. d_margin($1) }
  594. d_margin($1) }
  595. d_margin($1) else
  596. d_margin($1) {
  597. d_margin($1) D3DVALUE *_pOut = (D3DVALUE*)$2;
  598. d_margin($1) D3DVECTOR reflectionVector;
  599. d_margin($1) for (DWORD i=0; i < pv->dwNumTextureStages; i++)
  600. d_margin($1) {
  601. d_margin($1) LPD3DFE_TEXTURESTAGE pStage = &pv->textureStage[i];
  602. d_margin($1) DWORD dwInpIndex = pStage->dwInpCoordIndex;
  603. d_margin($1) D3DVALUE *_pIn;
  604. d_margin($1) if (pStage->dwTexGenMode == 0)
  605. d_margin($1) _pIn = inTexture[dwInpIndex];
  606. d_margin($1) else
  607. d_margin($1) if (pStage->dwTexGenMode == D3DTSS_TCI_CAMERASPACEPOSITION)
  608. d_margin($1) _pIn = (D3DVALUE*)&EyeSpaceData.dvPosition;
  609. d_margin($1) else
  610. d_margin($1) if (pStage->dwTexGenMode == D3DTSS_TCI_CAMERASPACENORMAL)
  611. d_margin($1) _pIn = (D3DVALUE*)&EyeSpaceData.dvNormal;
  612. d_margin($1) else // D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR
  613. d_margin($1) {
  614. d_margin($1) if (pv->dwDeviceFlags & D3DDEV_LOCALVIEWER)
  615. d_margin($1) ComputeReflectionVector((D3DVECTOR*)&EyeSpaceData.dvPosition,
  616. d_margin($1) (D3DVECTOR*)&EyeSpaceData.dvNormal,
  617. d_margin($1) &reflectionVector);
  618. d_margin($1) else
  619. d_margin($1) ComputeReflectionVectorInfiniteViewer((D3DVECTOR*)&EyeSpaceData.dvNormal,
  620. d_margin($1) &reflectionVector);
  621. d_margin($1)
  622. d_margin($1) _pIn = (D3DVALUE*)&reflectionVector;
  623. d_margin($1) }
  624. d_margin($1) DWORD dwSize = pv->dwTextureCoordSize[i];
  625. d_margin($1) if (pStage->pmTextureTransform)
  626. d_margin($1) {
  627. d_margin($1) (*(g_pfnTextureTransform[pStage->dwTexTransformFuncIndex]))(_pIn, _pOut,
  628. d_margin($1) pStage->pmTextureTransform);
  629. d_margin($1) }
  630. d_margin($1) else
  631. d_margin($1) {
  632. d_margin($1) memcpy(_pOut, _pIn, dwSize);
  633. d_margin($1) }
  634. d_margin($1) NEXT(_pOut, dwSize, D3DVALUE);
  635. d_margin($1) }
  636. d_margin($1) }
  637. d_margin($1)}
  638. d_margin($1)else
  639. d_margin($1){
  640. d_margin($1) _pOut[0] = 0;
  641. d_margin($1) _pOut[1] = 0;
  642. d_margin($1)}') dnl
  643. dnl//--------------------------------------------------------------------------
  644. dnl// d_CopyTextureCoordFVF
  645. dnl//
  646. dnl// Copies texture coordinates from input to the output
  647. dnl// $1 - margin count
  648. dnl// $2 - pointer to the output vertex
  649. dnl//
  650. define(`d_CopyTextureCoordFVF',`dnl
  651. d_empty_($1)if (!(dwDeviceFlags & D3DDEV_NOFVFANDNOTEXTURE))
  652. d_margin($1){
  653. d_margin($1) if (!(pv->dwDeviceFlags & (D3DDEV_TEXTURETRANSFORM | D3DDEV_REMAPTEXTUREINDICES)))
  654. d_margin($1) memcpy($2, inTexture[0], pv->dwTextureCoordSizeTotal);
  655. d_margin($1) else
  656. d_margin($1) if (!(pv->dwDeviceFlags & D3DDEV_REMAPTEXTUREINDICES))
  657. d_margin($1) {
  658. d_margin($1) D3DVALUE *_pIn = inTexture[0];
  659. d_margin($1) D3DVALUE *_pOut = (D3DVALUE*)$2;
  660. d_margin($1) for (DWORD i=0; i < pv->nOutTexCoord; i++)
  661. d_margin($1) {
  662. d_margin($1) const DWORD dwSize = pv->dwTextureCoordSize[i];
  663. d_margin($1) const DWORD dwInpSize = pv->dwInpTextureCoordSize[i];
  664. d_margin($1) if (pv->pmTexture[i])
  665. d_margin($1) {
  666. d_margin($1) const DWORD m = dwInpSize >> 2; // Number of input tex. coord.
  667. d_margin($1) const DWORD n = dwSize >> 2; // Number of output tex. coord.
  668. d_margin($1) (*(g_pfnTextureTransform[MakeTexTransformFuncIndex(m, n)]))
  669. d_margin($1) (_pIn, _pOut, pv->pmTexture[i]);
  670. d_margin($1) }
  671. d_margin($1) else
  672. d_margin($1) memcpy(_pOut, _pIn, dwSize);
  673. d_margin($1) NEXT(_pIn, dwInpSize, D3DVALUE);
  674. d_margin($1) NEXT(_pOut, dwSize, D3DVALUE);
  675. d_margin($1) }
  676. d_margin($1) }
  677. d_margin($1) else
  678. d_margin($1) {
  679. d_margin($1) D3DVALUE *_pOut = (D3DVALUE*)$2;
  680. d_margin($1) D3DVECTOR reflectionVector;
  681. d_margin($1) for (DWORD i=0; i < pv->dwNumTextureStages; i++)
  682. d_margin($1) {
  683. d_margin($1) LPD3DFE_TEXTURESTAGE pStage = &pv->textureStage[i];
  684. d_margin($1) D3DVALUE *_pIn;
  685. d_margin($1) if (pStage->dwTexGenMode == 0)
  686. d_margin($1) _pIn = (D3DVALUE*)((BYTE*)inTexture[0] + pStage->dwInpOffset);
  687. d_margin($1) else
  688. d_margin($1) if (pStage->dwTexGenMode == D3DTSS_TCI_CAMERASPACEPOSITION)
  689. d_margin($1) _pIn = (D3DVALUE*)&EyeSpaceData.dvPosition;
  690. d_margin($1) else
  691. d_margin($1) if (pStage->dwTexGenMode == D3DTSS_TCI_CAMERASPACENORMAL)
  692. d_margin($1) _pIn = (D3DVALUE*)&EyeSpaceData.dvNormal;
  693. d_margin($1) else // D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR
  694. d_margin($1) {
  695. d_margin($1) if (pv->dwDeviceFlags & D3DDEV_LOCALVIEWER)
  696. d_margin($1) ComputeReflectionVector((D3DVECTOR*)&EyeSpaceData.dvPosition,
  697. d_margin($1) (D3DVECTOR*)&EyeSpaceData.dvNormal,
  698. d_margin($1) &reflectionVector);
  699. d_margin($1) else
  700. d_margin($1) ComputeReflectionVectorInfiniteViewer((D3DVECTOR*)&EyeSpaceData.dvNormal,
  701. d_margin($1) &reflectionVector);
  702. d_margin($1) _pIn = (D3DVALUE*)&reflectionVector;
  703. d_margin($1) }
  704. d_margin($1) DWORD dwSize = pv->dwTextureCoordSize[i];
  705. d_margin($1) if (pStage->pmTextureTransform)
  706. d_margin($1) {
  707. d_margin($1) (*(g_pfnTextureTransform[pStage->dwTexTransformFuncIndex]))
  708. d_margin($1) (_pIn, _pOut, pStage->pmTextureTransform);
  709. d_margin($1) }
  710. d_margin($1) else
  711. d_margin($1) {
  712. d_margin($1) memcpy(_pOut, _pIn, dwSize);
  713. d_margin($1) }
  714. d_margin($1) NEXT(_pOut, dwSize, D3DVALUE);
  715. d_margin($1) }
  716. d_margin($1) }
  717. d_margin($1)}
  718. d_margin($1)else
  719. d_margin($1){
  720. d_margin($1) ((D3DVALUE*)$2)[0] = 0;
  721. d_margin($1) ((D3DVALUE*)$2)[1] = 0;
  722. d_margin($1)}') dnl
  723. dnl//--------------------------------------------------------------------------
  724. dnl// d_CopyTextureCoord
  725. dnl//
  726. dnl// Copies texture coordinates from input to the output
  727. dnl// $1 - margin count
  728. dnl// $2 - pointer to the output vertex
  729. dnl//
  730. define(`d_CopyTextureCoord',`dnl
  731. d_empty_($1)if (!(pv->dwFlags & D3DPV_DONOTCOPYTEXTURE))
  732. d_margin($1){
  733. d_margin($1) if (pv->dwDeviceFlags & D3DDEV_STRIDE)
  734. d_margin($1) {
  735. d_margin($1) d_CopyTextureCoordStrided($1+2, $2)
  736. d_margin($1) }
  737. d_margin($1) else
  738. d_margin($1) {
  739. d_margin($1) d_CopyTextureCoordFVF($1+2, $2)
  740. d_margin($1) }
  741. d_margin($1)}') dnl
  742. dnl//------------------------------------------------------------------
  743. dnl// Setup pointers and flags before processing a primitive or vertices
  744. dnl//
  745. dnl//
  746. define(`d_Setup',`
  747. DWORD dwOutVerSize = pv->dwOutputSize;
  748. DWORD dwClipIntersection;
  749. DWORD dwClipUnion;
  750. DWORD inVID = pv->dwVIDIn;
  751. DWORD outVID = pv->dwVIDOut;
  752. DWORD dwDeviceFlags = pv->dwDeviceFlags;
  753. D3DVECTOR *in; // Input position pointer
  754. D3DVECTOR *inNormal;
  755. DWORD *inDiffuse; // inDiffuse and inSpecular should be in his order !!!
  756. DWORD *inSpecular;
  757. DWORD dwInpVerSize; // Position stride
  758. D3DVALUE *inTexture[8];
  759. DWORD **ppEmissiveSource; // Used when COLORVERTEX_E is set
  760. DWORD **ppAmbientSource; // Used when COLORVERTEX_A is set
  761. DWORD **ppDiffuseSource; // Used when COLORVERTEX_D is set
  762. DWORD **ppSpecularSource; // Used when COLORVERTEX_S is set
  763. in = (D3DVECTOR*)pv->position.lpvData;
  764. dwInpVerSize = pv->position.dwStride;
  765. inTexture[0] = (D3DVALUE*)in; // For DONOTSTRIPELEMENTS we will copy XYZ to
  766. // the output texture coordinates, but it does not matter
  767. if (!(dwDeviceFlags & D3DDEV_STRIDE))
  768. {
  769. inNormal = (D3DVECTOR*) ((char*)in + pv->normalOffset);
  770. inDiffuse = (DWORD*) ((char*)in + pv->diffuseOffset);
  771. inSpecular = (DWORD*) ((char*)in + pv->specularOffset);
  772. if (pv->nTexCoord)
  773. inTexture[0] = (D3DVALUE*) ((char*)in + pv->texOffset);
  774. }
  775. else
  776. {
  777. inNormal = (D3DVECTOR*)pv->normal.lpvData;
  778. inDiffuse = (DWORD*)pv->diffuse.lpvData;
  779. inSpecular = (DWORD*)pv->specular.lpvData;
  780. if (dwDeviceFlags & D3DDEV_FVF || pv->dwFlags & D3DPV_VBCALL)
  781. {
  782. for (DWORD i=0; i < pv->nTexCoord; i++)
  783. inTexture[i] = (D3DVALUE*)pv->textures[i].lpvData;
  784. }
  785. else
  786. {
  787. if (pv->nTexCoord)
  788. inTexture[0] = (D3DVALUE*)pv->textures[pv->dwTextureIndexToCopy].lpvData;
  789. }
  790. }
  791. pv->lighting.outDiffuse = __DEFAULT_DIFFUSE;
  792. pv->lighting.outSpecular = __DEFAULT_SPECULAR;
  793. pv->lighting.dwLightingFlags = 0;
  794. if (pv->dwFlags & D3DPV_LIGHTING)
  795. {
  796. pv->lighting.diffuse = pv->lighting.diffuse0;
  797. pv->lighting.specular.r = D3DVAL(0);
  798. pv->lighting.specular.g = D3DVAL(0);
  799. pv->lighting.specular.b = D3DVAL(0);
  800. if (pv->dwDeviceFlags & D3DDEV_COLORVERTEX)
  801. {
  802. if (pv->dwVIDIn & D3DFVF_DIFFUSE)
  803. {
  804. if(pv->lighting.dwEmissiveSrcIndex == 0)
  805. {
  806. pv->dwFlags |= D3DPV_COLORVERTEX_E | D3DPV_DOCOLORVERTEX;
  807. ppEmissiveSource = &inDiffuse;
  808. }
  809. if(pv->lighting.dwDiffuseSrcIndex == 0)
  810. {
  811. pv->dwFlags |= D3DPV_COLORVERTEX_D | D3DPV_DOCOLORVERTEX;
  812. ppDiffuseSource = &inDiffuse;
  813. }
  814. if(pv->lighting.dwAmbientSrcIndex == 0)
  815. {
  816. pv->dwFlags |= D3DPV_COLORVERTEX_A | D3DPV_DOCOLORVERTEX;
  817. ppAmbientSource = &inDiffuse;
  818. }
  819. if(pv->lighting.dwSpecularSrcIndex == 0)
  820. {
  821. pv->dwFlags |= D3DPV_COLORVERTEX_S | D3DPV_DOCOLORVERTEX;
  822. ppSpecularSource = &inDiffuse;
  823. }
  824. }
  825. if (pv->dwVIDIn & D3DFVF_SPECULAR)
  826. {
  827. if(pv->lighting.dwEmissiveSrcIndex == 1)
  828. {
  829. pv->dwFlags |= D3DPV_COLORVERTEX_E | D3DPV_DOCOLORVERTEX;
  830. ppEmissiveSource = &inSpecular;
  831. }
  832. if(pv->lighting.dwDiffuseSrcIndex == 1)
  833. {
  834. pv->dwFlags |= D3DPV_COLORVERTEX_D | D3DPV_DOCOLORVERTEX;
  835. ppDiffuseSource = &inSpecular;
  836. }
  837. if(pv->lighting.dwAmbientSrcIndex == 1)
  838. {
  839. pv->dwFlags |= D3DPV_COLORVERTEX_A | D3DPV_DOCOLORVERTEX;
  840. ppAmbientSource = &inSpecular;
  841. }
  842. if(pv->lighting.dwSpecularSrcIndex == 1)
  843. {
  844. pv->dwFlags |= D3DPV_COLORVERTEX_S | D3DPV_DOCOLORVERTEX;
  845. ppSpecularSource = &inSpecular;
  846. }
  847. }
  848. }
  849. }
  850. dwClipUnion = 0;
  851. dwClipIntersection = 0;
  852. if (!(dwDeviceFlags & D3DDEV_DONOTCLIP))
  853. dwClipIntersection = ~0;') dnl
  854. dnl//------------------------------------------------------------------
  855. dnl// d_UpdateInputPointersStrided
  856. dnl//
  857. dnl// Updates input pointers
  858. dnl//
  859. dnl// Arguments:
  860. dnl// $1 - margin counter
  861. dnl//
  862. dnl// Notes:
  863. dnl// Output pointer is changed
  864. dnl//
  865. define(`d_UpdateInputPointersStrided',`dnl
  866. d_empty_($1){
  867. d_margin($1) NEXT(in, dwInpVerSize, D3DVECTOR);
  868. d_margin($1) // This speeds up the xform only case
  869. d_margin($1) if (!(pv->dwFlags & D3DPV_TRANSFORMONLY))
  870. d_margin($1) {
  871. d_margin($1) NEXT(inNormal, pv->normal.dwStride, D3DVECTOR);
  872. d_margin($1) NEXT(inDiffuse, pv->diffuse.dwStride, DWORD);
  873. d_margin($1) NEXT(inSpecular, pv->specular.dwStride, DWORD);
  874. d_margin($1) {
  875. d_margin($1) for (DWORD j=0; j < pv->nTexCoord; j++)
  876. d_margin($1) NEXT(inTexture[j], pv->textures[j].dwStride, D3DVALUE);
  877. d_margin($1) }
  878. d_margin($1) }
  879. d_margin($1)}') dnl
  880. dnl//------------------------------------------------------------------
  881. dnl// d_UpdateInputPointersFVF
  882. dnl//
  883. dnl// Updates input pointers
  884. dnl//
  885. dnl// Arguments:
  886. dnl// $1 - margin counter
  887. dnl// $2 - how many vertices to skip
  888. dnl//
  889. dnl// Notes:
  890. dnl// Output pointer is changed
  891. dnl//
  892. define(`d_UpdateInputPointersFVF',`dnl
  893. d_empty_($1){
  894. d_margin($1) NEXT(in, dwInpVerSize, D3DVECTOR);
  895. d_margin($1) // This speeds up the xform only case
  896. d_margin($1) if (!(pv->dwFlags & D3DPV_TRANSFORMONLY))
  897. d_margin($1) {
  898. d_margin($1) NEXT(inNormal, dwInpVerSize, D3DVECTOR);
  899. d_margin($1) NEXT(inDiffuse, dwInpVerSize, DWORD);
  900. d_margin($1) NEXT(inSpecular, dwInpVerSize, DWORD);
  901. d_margin($1) NEXT(inTexture[0], dwInpVerSize, D3DVALUE);
  902. d_margin($1) }
  903. d_margin($1)}') dnl
  904. dnl//------------------------------------------------------------------
  905. dnl// d_CopyTextureCoordUpdateInputPointers
  906. dnl//
  907. dnl// Copies texture coordinates to the output and updates input pointers
  908. dnl//
  909. dnl// Arguments:
  910. dnl// $1 - margin counter
  911. dnl// $2 - pointer to the output texture
  912. dnl//
  913. dnl// Notes:
  914. dnl// Output pointer is changed
  915. dnl//
  916. define(`d_CopyTextureCoordUpdateInputPointers',`dnl
  917. d_empty_($1)if (pv->dwDeviceFlags & D3DDEV_STRIDE)
  918. d_margin($1){
  919. d_margin($1) if (!(pv->dwFlags & D3DPV_DONOTCOPYTEXTURE))
  920. d_margin($1) {
  921. d_margin($1) d_CopyTextureCoordStrided($1+2, $2)
  922. d_margin($1) }
  923. d_margin($1) d_UpdateInputPointersStrided($1+1)
  924. d_margin($1)}
  925. d_margin($1)else
  926. d_margin($1){
  927. d_margin($1) if (!(pv->dwFlags & D3DPV_DONOTCOPYTEXTURE))
  928. d_margin($1) {
  929. d_margin($1) d_CopyTextureCoordFVF($1+2, $2)
  930. d_margin($1) }
  931. d_margin($1) d_UpdateInputPointersFVF($1+1)
  932. d_margin($1)}') dnl
  933. dnl//------------------------------------------------------------------
  934. dnl// d_UpdateInputPointers
  935. dnl//
  936. dnl// Updates input pointers
  937. dnl//
  938. dnl// Arguments:
  939. dnl// $1 - margin counter
  940. dnl//
  941. dnl// Notes:
  942. dnl// Output pointer is changed
  943. dnl//
  944. define(`d_UpdateInputPointers',`dnl
  945. d_empty_($1)if (pv->dwDeviceFlags & D3DDEV_STRIDE)
  946. d_margin($1){
  947. d_margin($1) d_UpdateInputPointersStrided($1+1)
  948. d_margin($1)}
  949. d_margin($1)else
  950. d_margin($1){
  951. d_margin($1) d_UpdateInputPointersFVF($1+1)
  952. d_margin($1)}') dnl