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.

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