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.

412 lines
20 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // This file contains texture blending functions.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997.
  6. //
  7. //-----------------------------------------------------------------------------
  8. include(`m4hdr.mh')dnl
  9. #include "rgb_pch.h"
  10. #pragma hdrstop
  11. #include "ctxbd_mh.h"
  12. //-----------------------------------------------------------------------------
  13. //
  14. // TexBlend_Tex1_None
  15. //
  16. // cPix = cSrc
  17. // aPix = aSrc
  18. //
  19. //-----------------------------------------------------------------------------
  20. void C_TexBlend_Tex1_None(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  21. PD3DI_RASTSPAN pS)
  22. {
  23. pCtx->SI.uBB = pS->uB;
  24. pCtx->SI.uBG = pS->uG;
  25. pCtx->SI.uBR = pS->uR;
  26. pCtx->SI.uBA = pS->uA;
  27. pCtx->pfnTexBlendEnd(pCtx, pP, pS);
  28. }
  29. //-----------------------------------------------------------------------------
  30. //
  31. // TexBlend_Tex1_Decal
  32. //
  33. // cPix = cTex
  34. // aPix = aTex
  35. //
  36. //-----------------------------------------------------------------------------
  37. void C_TexBlend_Tex1_Decal(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  38. PD3DI_RASTSPAN pS)
  39. {
  40. pCtx->SI.uBB = (UINT16)(RGBA_GETBLUE(pCtx->SI.TexCol[0]) << COLOR_SHIFT);
  41. pCtx->SI.uBG = (UINT16)(RGBA_GETGREEN(pCtx->SI.TexCol[0])<< COLOR_SHIFT);
  42. pCtx->SI.uBR = (UINT16)(RGBA_GETRED(pCtx->SI.TexCol[0]) << COLOR_SHIFT);
  43. pCtx->SI.uBA = (UINT16)(RGBA_GETALPHA(pCtx->SI.TexCol[0])<< COLOR_SHIFT);
  44. pCtx->pfnTexBlendEnd(pCtx, pP, pS);
  45. }
  46. //-----------------------------------------------------------------------------
  47. //
  48. // TexBlend_Tex1_Modulate
  49. //
  50. // cPix = cSrc * cTex
  51. // aPix = aTex
  52. //
  53. //-----------------------------------------------------------------------------
  54. void C_TexBlend_Tex1_Modulate(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  55. PD3DI_RASTSPAN pS)
  56. {
  57. UINT16 uB = pS->uB>>COLOR_SHIFT;
  58. UINT16 uG = pS->uG>>COLOR_SHIFT;
  59. UINT16 uR = pS->uR>>COLOR_SHIFT;
  60. UINT16 uTB = (UINT16)(RGBA_GETBLUE(pCtx->SI.TexCol[0]));
  61. UINT16 uTG = (UINT16)(RGBA_GETGREEN(pCtx->SI.TexCol[0]));
  62. UINT16 uTR = (UINT16)(RGBA_GETRED(pCtx->SI.TexCol[0]));
  63. UINT16 uTA = (UINT16)(RGBA_GETALPHA(pCtx->SI.TexCol[0]));
  64. // this is a PMULLW, which works on unsigned 16 bit quantities
  65. pCtx->SI.uBB = uB*uTB;
  66. pCtx->SI.uBG = uG*uTG;
  67. pCtx->SI.uBR = uR*uTR;
  68. pCtx->SI.uBA = uTA<<COLOR_SHIFT;
  69. pCtx->pfnTexBlendEnd(pCtx, pP, pS);
  70. }
  71. //-----------------------------------------------------------------------------
  72. //
  73. // TexBlend_Tex1_ModulateAlphaOVR
  74. //
  75. // cPix = cSrc * cTex
  76. // aPix = aSrc
  77. //
  78. //-----------------------------------------------------------------------------
  79. void C_TexBlend_Tex1_ModulateAlphaOVR(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  80. PD3DI_RASTSPAN pS)
  81. {
  82. UINT16 uB = pS->uB>>COLOR_SHIFT;
  83. UINT16 uG = pS->uG>>COLOR_SHIFT;
  84. UINT16 uR = pS->uR>>COLOR_SHIFT;
  85. UINT16 uTB = (UINT16)(RGBA_GETBLUE(pCtx->SI.TexCol[0]));
  86. UINT16 uTG = (UINT16)(RGBA_GETGREEN(pCtx->SI.TexCol[0]));
  87. UINT16 uTR = (UINT16)(RGBA_GETRED(pCtx->SI.TexCol[0]));
  88. // this is a PMULLW, which works on unsigned 16 bit quantities
  89. pCtx->SI.uBB = uB*uTB;
  90. pCtx->SI.uBG = uG*uTG;
  91. pCtx->SI.uBR = uR*uTR;
  92. pCtx->SI.uBA = pS->uA;
  93. pCtx->pfnTexBlendEnd(pCtx, pP, pS);
  94. }
  95. //-----------------------------------------------------------------------------
  96. //
  97. // TexBlend_Tex1_Gen
  98. //
  99. // Calls first set of function pointers to do general texture blending.
  100. //
  101. //-----------------------------------------------------------------------------
  102. void C_TexBlend_Tex1_Gen(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  103. PD3DI_RASTSPAN pS)
  104. {
  105. // Initialize input to diffuse color (the default)
  106. D3DI_RASTCOLOR Input = *(D3DI_RASTCOLOR*)&pS->uB;
  107. D3DI_RASTCOLOR Arg1;
  108. D3DI_RASTCOLOR Arg2;
  109. pCtx->pfnTexBlendGetAlpha[0](&Arg1, &Arg2, &Input, pCtx, pS, 0);
  110. pCtx->pfnTexBlendOpAlpha[0]((D3DI_RASTCOLOR*)&pCtx->SI.uBB, &Arg1, &Arg2, pCtx, pS, 0);
  111. pCtx->pfnTexBlendGetColor[0](&Arg1, &Arg2, &Input, pCtx, pS, 0);
  112. pCtx->pfnTexBlendOpColor[0]((D3DI_RASTCOLOR*)&pCtx->SI.uBB, &Arg1, &Arg2, pCtx, pS, 0);
  113. pCtx->pfnTexBlendEnd(pCtx, pP, pS);
  114. }
  115. //-----------------------------------------------------------------------------
  116. //
  117. // TexBlend_TexM_Gen
  118. //
  119. // Does general multi-texture blending.
  120. //
  121. //-----------------------------------------------------------------------------
  122. void C_TexBlend_TexM_Gen(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  123. PD3DI_RASTSPAN pS)
  124. {
  125. // Initialize input to diffuse color (the default)
  126. D3DI_RASTCOLOR Input0 = *(D3DI_RASTCOLOR*)&pS->uB;
  127. D3DI_RASTCOLOR Input1;
  128. D3DI_RASTCOLOR Arg1;
  129. D3DI_RASTCOLOR Arg2;
  130. pCtx->pfnTexBlendGetAlpha[0](&Arg1, &Arg2, &Input0, pCtx, pS, 0);
  131. pCtx->pfnTexBlendOpAlpha[0](&Input1, &Arg1, &Arg2, pCtx, pS, 0);
  132. pCtx->pfnTexBlendGetColor[0](&Arg1, &Arg2, &Input0, pCtx, pS, 0);
  133. pCtx->pfnTexBlendOpColor[0](&Input1, &Arg1, &Arg2, pCtx, pS, 0);
  134. for (INT32 i = 1; i < (INT32)pCtx->cActBldStage; i++)
  135. {
  136. Input0 = Input1;
  137. pCtx->pfnTexBlendGetAlpha[i](&Arg1, &Arg2, &Input0, pCtx, pS, i);
  138. pCtx->pfnTexBlendOpAlpha[i](&Input1, &Arg1, &Arg2, pCtx, pS, i);
  139. pCtx->pfnTexBlendGetColor[i](&Arg1, &Arg2, &Input0, pCtx, pS, i);
  140. pCtx->pfnTexBlendOpColor[i](&Input1, &Arg1, &Arg2, pCtx, pS, i);
  141. }
  142. *((D3DI_RASTCOLOR*)&pCtx->SI.uBB) = Input1;
  143. pCtx->pfnTexBlendEnd(pCtx, pP, pS);
  144. }
  145. dnl
  146. dnl d_TexBlendGetAlpha
  147. dnl
  148. dnl Generates all the differentiated texture alpha blend gets.
  149. dnl
  150. dnl It takes 2 parameters.
  151. dnl
  152. dnl $1 is one of TextureAlpha, InvTextureAlpha
  153. dnl $2 is one of DiffuseAlpha, InputAlpha, FactorAlpha, InvDiffuseAlpha, InvInputAlpha, InvFactorAlpha,
  154. dnl SpecularAlpha, InvSpecularAlpha
  155. dnl
  156. dnl Assumes that the Arg1 and Arg2 are 8 bit colors, and that Input is a 8.8.
  157. dnl
  158. define(`d_TexBlendGetAlpha', `void C_TexBlend_Get_Alpha_$1_$2(PD3DI_RASTCOLOR pArg1, PD3DI_RASTCOLOR pArg2, PD3DI_RASTCOLOR pInput,
  159. PD3DI_RASTCTX pCtx, PD3DI_RASTSPAN pS, INT32 iTex)
  160. {
  161. ifelse(`$1', `TextureAlpha', `
  162. pArg1->uA = (UINT8)RGBA_GETALPHA(pCtx->SI.TexCol[iTex]);', `$1', `InvTextureAlpha', `
  163. pArg1->uA = (UINT8)~(RGBA_GETALPHA(pCtx->SI.TexCol[iTex]));')
  164. dnl
  165. ifelse(`$2', `DiffuseAlpha', `
  166. pArg2->uA = (UINT8)(pS->uA>>COLOR_SHIFT);', `$2', `InputAlpha', `
  167. pArg2->uA = (UINT8)(pInput->uA>>COLOR_SHIFT);', `$2', `FactorAlpha', `
  168. pArg2->uA = (UINT8)RGBA_GETALPHA(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]);', `$2', `InvDiffuseAlpha', `
  169. pArg2->uA = (UINT8)~((pS->uA>>COLOR_SHIFT));', `$2', `InvInputAlpha', `
  170. pArg2->uA = (UINT8)~((pInput->uA>>COLOR_SHIFT));', `$2', `InvFactorAlpha', `
  171. pArg2->uA = (UINT8)~(RGBA_GETALPHA(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]));', `$2', `SpecularAlpha', `
  172. pArg2->uA = (UINT8)(pS->uFog>>COLOR_SHIFT);', `$2', `InvSpecularAlpha', `
  173. pArg2->uA = (UINT8)~((pS->uFog>>COLOR_SHIFT));')
  174. }
  175. ')
  176. dnl
  177. d_RepStr(`d_RepStr(`d_TexBlendGetAlpha(AA, BB)',
  178. `AA', TextureAlpha, InvTextureAlpha)',
  179. `BB', DiffuseAlpha, InputAlpha, FactorAlpha, InvDiffuseAlpha, InvInputAlpha, InvFactorAlpha,
  180. SpecularAlpha, InvSpecularAlpha)
  181. dnl
  182. dnl
  183. dnl d_TexBlendOpAlpha
  184. dnl
  185. dnl Generates all the differentiated texture alpha operations.
  186. dnl
  187. dnl It takes 1 parameter.
  188. dnl
  189. dnl $1 is one of None, Copy, Modulate, Modulate2, Modulate4, Add, AddSigned, BlendDiffuseAlpha, BlendTextureAlpha, BlendFactorAlpha
  190. dnl
  191. dnl Assumes that the Arg1 and Arg2 are 8 bit colors. Produces 8.8 output.
  192. dnl
  193. define(`d_TexBlendOpAlpha', `void C_TexBlend_Op_Alpha_$1(PD3DI_RASTCOLOR pOut, PD3DI_RASTCOLOR pArg1, PD3DI_RASTCOLOR pArg2,
  194. PD3DI_RASTCTX pCtx, PD3DI_RASTSPAN pS, INT32 iTex)
  195. {
  196. ifelse(`$1', `None', `
  197. pOut->uA = pS->uA;', `$1', `CopyArg1', `
  198. pOut->uA = pArg1->uA<<COLOR_SHIFT;', `$1', `CopyArg2', `
  199. pOut->uA = pArg2->uA<<COLOR_SHIFT;', `$1', `Modulate', `
  200. pOut->uA = pArg1->uA*pArg2->uA;', `$1', `Modulate2', `
  201. pOut->uA = (UINT16)min< UINT32>(((UINT32)pArg1->uA*pArg2->uA)<<1, 0xffff);', `$1', `Modulate4', `
  202. pOut->uA = (UINT16)min< UINT32>(((UINT32)pArg1->uA*pArg2->uA)<<2, 0xffff);', `$1', `Add', `
  203. pOut->uA = (UINT16)min< UINT32>(((UINT32)pArg1->uA+pArg2->uA)<<COLOR_SHIFT, 0xffff);', `$1', `AddSigned', `
  204. pOut->uA = (UINT16)(min< UINT32>(max< UINT32>((INT32)pArg1->uA+pArg2->uA-128, 0x0), 0xff))<<COLOR_SHIFT;', `$1', `BlendDiffuseAlpha', `
  205. INT32 iA = pS->uA>>COLOR_SHIFT;
  206. pOut->uA = (UINT16)(iA*(pArg1->uA - pArg2->uA) + (pArg2->uA<<COLOR_SHIFT));', `$1', `BlendTextureAlpha', `
  207. INT32 iA = RGBA_GETALPHA(pCtx->SI.TexCol[iTex]);
  208. pOut->uA = (UINT16)(iA*(pArg1->uA - pArg2->uA) + (pArg2->uA<<COLOR_SHIFT));', `$1', `BlendFactorAlpha', `
  209. INT32 iA = RGBA_GETALPHA(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]);
  210. pOut->uA = (UINT16)(iA*(pArg1->uA - pArg2->uA) + (pArg2->uA<<COLOR_SHIFT));', `$1', `BlendTextureAlphaPM', `
  211. INT32 iA = 255 - RGBA_GETALPHA(pCtx->SI.TexCol[iTex]);
  212. pOut->uA = (UINT16)min< UINT32>((UINT32)((pArg1->uA<<COLOR_SHIFT) + iA*pArg2->uA), 0xffff);', `$1', `AddSigned2', `
  213. pOut->uA = (UINT16)(min< UINT32>(max< UINT32>(((INT32)pArg1->uA+pArg2->uA-128)<<1, 0x0), 0xff))<<COLOR_SHIFT;', `$1', `Subtract', `
  214. pOut->uA = (UINT16)(max< UINT32>(((INT32)pArg1->uA + pArg2->uA), 0x0))<<COLOR_SHIFT;', `$1', `AddSmooth', `
  215. pOut->uA = (UINT16)(min< UINT32>(max< UINT32>(((INT32)pArg1->uA<<COLOR_SHIFT)+(~(INT32)pArg1->uA)*pArg2->uA, 0x0), 0xffff));')
  216. }
  217. ')
  218. dnl
  219. dnl
  220. d_RepStr(`d_TexBlendOpAlpha(AA)',
  221. `AA', None, CopyArg1, CopyArg2, Modulate, Modulate2, Modulate4, Add, AddSigned,
  222. BlendDiffuseAlpha, BlendTextureAlpha, BlendFactorAlpha, BlendTextureAlphaPM,
  223. AddSigned2, Subtract, AddSmooth)
  224. dnl
  225. dnl d_TexBlendGetColor
  226. dnl
  227. dnl Generates all the differentiated texture color blend gets.
  228. dnl
  229. dnl It takes 2 parameters.
  230. dnl
  231. dnl $1 is one of Texure, InvTexture, TextureAlpha, InvTextureAlpha
  232. dnl $2 is one of DiffuseAlpha, InputAlpha, FactorAlpha, InvDiffuseAlpha, InvInputAlpha, InvFactorAlpha, Specular
  233. dnl
  234. dnl Assumes that the Arg1 and Arg2 are 8 bit colors, and that Input is a 8.8.
  235. dnl
  236. define(`d_TexBlendGetColor', `void C_TexBlend_Get_Color_$1_$2(PD3DI_RASTCOLOR pArg1, PD3DI_RASTCOLOR pArg2, PD3DI_RASTCOLOR pInput,
  237. PD3DI_RASTCTX pCtx, PD3DI_RASTSPAN pS, INT32 iTex)
  238. {
  239. ifelse(`$1', `Texture', `
  240. pArg1->uB = (UINT8)RGBA_GETBLUE(pCtx->SI.TexCol[iTex]);
  241. pArg1->uG = (UINT8)RGBA_GETGREEN(pCtx->SI.TexCol[iTex]);
  242. pArg1->uR = (UINT8)RGBA_GETRED(pCtx->SI.TexCol[iTex]);', `$1', `InvTexture', `
  243. pArg1->uB = (UINT8)~(RGBA_GETBLUE(pCtx->SI.TexCol[iTex]));
  244. pArg1->uG = (UINT8)~(RGBA_GETGREEN(pCtx->SI.TexCol[iTex]));
  245. pArg1->uR = (UINT8)~(RGBA_GETRED(pCtx->SI.TexCol[iTex]));', `$1', `TextureAlpha', `
  246. pArg1->uB = (UINT8)RGBA_GETALPHA(pCtx->SI.TexCol[iTex]);
  247. pArg1->uG = pArg1->uB;
  248. pArg1->uR = pArg1->uB;', `$1', `InvTextureAlpha', `
  249. pArg1->uB = (UINT8)~(RGBA_GETALPHA(pCtx->SI.TexCol[iTex]));
  250. pArg1->uG = pArg1->uB;
  251. pArg1->uR = pArg1->uB;')
  252. dnl
  253. ifelse(`$2', `Diffuse', `
  254. pArg2->uB = (UINT8)(pS->uB>>COLOR_SHIFT);
  255. pArg2->uG = (UINT8)(pS->uG>>COLOR_SHIFT);
  256. pArg2->uR = (UINT8)(pS->uR>>COLOR_SHIFT);', `$2', `Specular', `
  257. pArg2->uB = (UINT8)(pS->uBS>>COLOR_SHIFT);
  258. pArg2->uG = (UINT8)(pS->uGS>>COLOR_SHIFT);
  259. pArg2->uR = (UINT8)(pS->uRS>>COLOR_SHIFT);', `$2', `Input', `
  260. pArg2->uB = (UINT8)(pInput->uB>>COLOR_SHIFT);
  261. pArg2->uG = (UINT8)(pInput->uG>>COLOR_SHIFT);
  262. pArg2->uR = (UINT8)(pInput->uR>>COLOR_SHIFT);', `$2', `Factor', `
  263. pArg2->uB = (UINT8)RGBA_GETBLUE(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]);
  264. pArg2->uG = (UINT8)RGBA_GETGREEN(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]);
  265. pArg2->uR = (UINT8)RGBA_GETRED(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]);', `$2', `InvDiffuse', `
  266. pArg2->uB = (UINT8)~((pS->uB>>COLOR_SHIFT));
  267. pArg2->uG = (UINT8)~((pS->uG>>COLOR_SHIFT));
  268. pArg2->uR = (UINT8)~((pS->uR>>COLOR_SHIFT));', `$2', `InvSpecular', `
  269. pArg2->uB = (UINT8)~((pS->uBS>>COLOR_SHIFT));
  270. pArg2->uG = (UINT8)~((pS->uGS>>COLOR_SHIFT));
  271. pArg2->uR = (UINT8)~((pS->uRS>>COLOR_SHIFT));', `$2', `InvInput', `
  272. pArg2->uB = (UINT8)~((pInput->uB>>COLOR_SHIFT));
  273. pArg2->uG = (UINT8)~((pInput->uG>>COLOR_SHIFT));
  274. pArg2->uR = (UINT8)~((pInput->uR>>COLOR_SHIFT));', `$2', `InvFactor', `
  275. pArg2->uB = (UINT8)~(RGBA_GETBLUE(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]));
  276. pArg2->uG = (UINT8)~(RGBA_GETGREEN(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]));
  277. pArg2->uR = (UINT8)~(RGBA_GETRED(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]));', `$2', `DiffuseAlpha', `
  278. pArg2->uB = (UINT8)(pS->uA>>COLOR_SHIFT);
  279. pArg2->uG = pArg2->uB;
  280. pArg2->uR = pArg2->uB;', `$2', `SpecularAlpha', `
  281. pArg2->uB = (UINT8)(pS->uFog>>COLOR_SHIFT);
  282. pArg2->uG = pArg2->uB;
  283. pArg2->uR = pArg2->uB;', `$2', `InputAlpha', `
  284. pArg2->uB = (UINT8)(pInput->uA>>COLOR_SHIFT);
  285. pArg2->uG = pArg2->uB;
  286. pArg2->uR = pArg2->uB;', `$2', `FactorAlpha', `
  287. pArg2->uB = (UINT8)RGBA_GETALPHA(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]);
  288. pArg2->uG = pArg2->uB;
  289. pArg2->uR = pArg2->uB;', `$2', `InvDiffuseAlpha', `
  290. pArg2->uB = (UINT8)~((pS->uA>>COLOR_SHIFT));
  291. pArg2->uG = pArg2->uB;
  292. pArg2->uR = pArg2->uB;', `$2', `InvSpecularAlpha', `
  293. pArg2->uB = (UINT8)~((pS->uFog>>COLOR_SHIFT));
  294. pArg2->uG = pArg2->uB;
  295. pArg2->uR = pArg2->uB;', `$2', `InvInputAlpha', `
  296. pArg2->uB = (UINT8)~((pInput->uA>>COLOR_SHIFT));
  297. pArg2->uG = pArg2->uB;
  298. pArg2->uR = pArg2->uB;', `$2', `InvFactorAlpha', `
  299. pArg2->uB = (UINT8)~(RGBA_GETALPHA(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]));
  300. pArg2->uG = pArg2->uB;
  301. pArg2->uR = pArg2->uB;')
  302. }
  303. ')
  304. dnl
  305. d_RepStr(`d_RepStr(`d_TexBlendGetColor(AA, BB)',
  306. `AA', Texture, InvTexture, TextureAlpha, InvTextureAlpha)',
  307. `BB', Diffuse, Input, Factor, InvDiffuse, InvInput, InvFactor,
  308. DiffuseAlpha, InputAlpha, FactorAlpha, InvDiffuseAlpha, InvInputAlpha, InvFactorAlpha,
  309. Specular, InvSpecular, SpecularAlpha, InvSpecularAlpha)
  310. dnl
  311. dnl
  312. dnl d_TexBlendOpColor
  313. dnl
  314. dnl Generates all the differentiated texture color operations.
  315. dnl
  316. dnl It takes 1 parameter.
  317. dnl
  318. dnl $1 is one of None, Copy, Modulate, Modulate2, Modulate4, Add, AddSigned, BlendDiffuseAlpha, BlendTextureAlpha, BlendFactorAlpha
  319. dnl
  320. dnl Assumes that the inputs are 8 bit colors.
  321. dnl
  322. define(`d_TexBlendOpColor', `void C_TexBlend_Op_Color_$1(PD3DI_RASTCOLOR pOut, PD3DI_RASTCOLOR pArg1, PD3DI_RASTCOLOR pArg2,
  323. PD3DI_RASTCTX pCtx, PD3DI_RASTSPAN pS, INT32 iTex)
  324. {
  325. ifelse(`$1', `None', `
  326. pOut->uB = pS->uB;
  327. pOut->uG = pS->uG;
  328. pOut->uR = pS->uR;', `$1', `CopyArg1', `
  329. pOut->uB = pArg1->uB<<COLOR_SHIFT;
  330. pOut->uG = pArg1->uG<<COLOR_SHIFT;
  331. pOut->uR = pArg1->uR<<COLOR_SHIFT;', `$1', `CopyArg2', `
  332. pOut->uB = pArg2->uB<<COLOR_SHIFT;
  333. pOut->uG = pArg2->uG<<COLOR_SHIFT;
  334. pOut->uR = pArg2->uR<<COLOR_SHIFT;', `$1', `Modulate', `
  335. pOut->uB = pArg1->uB*pArg2->uB;
  336. pOut->uG = pArg1->uG*pArg2->uG;
  337. pOut->uR = pArg1->uR*pArg2->uR;', `$1', `Modulate2', `
  338. pOut->uB = (UINT16)min< UINT32>(((UINT32)pArg1->uB*pArg2->uB)<<1, 0xffff);
  339. pOut->uG = (UINT16)min< UINT32>(((UINT32)pArg1->uG*pArg2->uG)<<1, 0xffff);
  340. pOut->uR = (UINT16)min< UINT32>(((UINT32)pArg1->uR*pArg2->uR)<<1, 0xffff);', `$1', `Modulate4', `
  341. pOut->uB = (UINT16)min< UINT32>(((UINT32)pArg1->uB*pArg2->uB)<<2, 0xffff);
  342. pOut->uG = (UINT16)min< UINT32>(((UINT32)pArg1->uG*pArg2->uG)<<2, 0xffff);
  343. pOut->uR = (UINT16)min< UINT32>(((UINT32)pArg1->uR*pArg2->uR)<<2, 0xffff);', `$1', `Add', `
  344. pOut->uB = (UINT16)min< UINT32>(((UINT32)pArg1->uB+pArg2->uB)<<COLOR_SHIFT, 0xffff);
  345. pOut->uG = (UINT16)min< UINT32>(((UINT32)pArg1->uG+pArg2->uG)<<COLOR_SHIFT, 0xffff);
  346. pOut->uR = (UINT16)min< UINT32>(((UINT32)pArg1->uR+pArg2->uR)<<COLOR_SHIFT, 0xffff);', `$1', `AddSigned', `
  347. pOut->uB = (UINT16)(min< UINT32>(max< UINT32>((INT32)pArg1->uB+pArg2->uB-128, 0x0), 0xff))<<COLOR_SHIFT;
  348. pOut->uG = (UINT16)(min< UINT32>(max< UINT32>((INT32)pArg1->uG+pArg2->uG-128, 0x0), 0xff))<<COLOR_SHIFT;
  349. pOut->uR = (UINT16)(min< UINT32>(max< UINT32>((INT32)pArg1->uR+pArg2->uR-128, 0x0), 0xff))<<COLOR_SHIFT;', `$1', `BlendDiffuseAlpha', `
  350. INT32 iA = pS->uA>>COLOR_SHIFT;
  351. pOut->uB = (UINT16)(iA*(pArg1->uB - pArg2->uB) + (pArg2->uB<<COLOR_SHIFT));
  352. pOut->uG = (UINT16)(iA*(pArg1->uG - pArg2->uG) + (pArg2->uG<<COLOR_SHIFT));
  353. pOut->uR = (UINT16)(iA*(pArg1->uR - pArg2->uR) + (pArg2->uR<<COLOR_SHIFT));', `$1', `BlendTextureAlpha', `
  354. INT32 iA = RGBA_GETALPHA(pCtx->SI.TexCol[iTex]);
  355. pOut->uB = (UINT16)(iA*(pArg1->uB - pArg2->uB) + (pArg2->uB<<COLOR_SHIFT));
  356. pOut->uG = (UINT16)(iA*(pArg1->uG - pArg2->uG) + (pArg2->uG<<COLOR_SHIFT));
  357. pOut->uR = (UINT16)(iA*(pArg1->uR - pArg2->uR) + (pArg2->uR<<COLOR_SHIFT));', `$1', `BlendFactorAlpha', `
  358. INT32 iA = RGBA_GETALPHA(pCtx->pdwRenderState[D3DRS_TEXTUREFACTOR]);
  359. pOut->uB = (UINT16)(iA*(pArg1->uB - pArg2->uB) + (pArg2->uB<<COLOR_SHIFT));
  360. pOut->uG = (UINT16)(iA*(pArg1->uG - pArg2->uG) + (pArg2->uG<<COLOR_SHIFT));
  361. pOut->uR = (UINT16)(iA*(pArg1->uR - pArg2->uR) + (pArg2->uR<<COLOR_SHIFT));', `$1', `BlendTextureAlphaPM', `
  362. INT32 iA = 255 - RGBA_GETALPHA(pCtx->SI.TexCol[iTex]);
  363. pOut->uB = (UINT16)min< UINT32>((UINT32)((pArg1->uB<<COLOR_SHIFT) + iA*pArg2->uB), 0xffff);
  364. pOut->uG = (UINT16)min< UINT32>((UINT32)((pArg1->uG<<COLOR_SHIFT) + iA*pArg2->uG), 0xffff);
  365. pOut->uR = (UINT16)min< UINT32>((UINT32)((pArg1->uR<<COLOR_SHIFT) + iA*pArg2->uR), 0xffff);', `$1', `AddSigned2', `
  366. pOut->uB = (UINT16)(min< UINT32>(max< UINT32>(((INT32)pArg1->uB+pArg2->uB-128) << 1, 0x0), 0xff))<<COLOR_SHIFT;
  367. pOut->uG = (UINT16)(min< UINT32>(max< UINT32>(((INT32)pArg1->uG+pArg2->uG-128) << 1, 0x0), 0xff))<<COLOR_SHIFT;
  368. pOut->uR = (UINT16)(min< UINT32>(max< UINT32>(((INT32)pArg1->uR+pArg2->uR-128) << 1, 0x0), 0xff))<<COLOR_SHIFT;', `$1', `Subtract', `
  369. pOut->uB = (UINT16)max< UINT32>(((UINT32)pArg1->uB + pArg2->uB), 0x0)<<COLOR_SHIFT;
  370. pOut->uG = (UINT16)max< UINT32>(((UINT32)pArg1->uG + pArg2->uG), 0x0)<<COLOR_SHIFT;
  371. pOut->uR = (UINT16)max< UINT32>(((UINT32)pArg1->uR + pArg2->uR), 0x0)<<COLOR_SHIFT;', `$1', `AddSmooth', `
  372. pOut->uB = (UINT16)min< UINT32>(((pArg1->uB<<COLOR_SHIFT)+(~pArg1->uB)*pArg2->uB), 0xffff);
  373. pOut->uG = (UINT16)min< UINT32>(((pArg1->uG<<COLOR_SHIFT)+(~pArg1->uG)*pArg2->uG), 0xffff);
  374. pOut->uR = (UINT16)min< UINT32>(((pArg1->uR<<COLOR_SHIFT)+(~pArg1->uR)*pArg2->uR), 0xffff);', `$1', `ModulateAlphaAddColor', `
  375. pOut->uB = (UINT16)min< UINT32>(((pArg1->uB<<COLOR_SHIFT)+pArg1->uA*pArg2->uB), 0xffff);
  376. pOut->uG = (UINT16)min< UINT32>(((pArg1->uG<<COLOR_SHIFT)+pArg1->uA*pArg2->uG), 0xffff);
  377. pOut->uR = (UINT16)min< UINT32>(((pArg1->uR<<COLOR_SHIFT)+pArg1->uA*pArg2->uR), 0xffff);', `$1', `ModulateColorAddAlpha', `
  378. pOut->uB = (UINT16)min< UINT32>((pArg2->uB*pArg1->uB+(pArg1->uA<<COLOR_SHIFT)), 0xffff);
  379. pOut->uG = (UINT16)min< UINT32>((pArg2->uG*pArg1->uG+(pArg1->uA<<COLOR_SHIFT)), 0xffff);
  380. pOut->uR = (UINT16)min< UINT32>((pArg2->uR*pArg1->uR+(pArg1->uA<<COLOR_SHIFT)), 0xffff);')
  381. }
  382. ')
  383. dnl
  384. dnl
  385. d_RepStr(`d_TexBlendOpColor(AA)',
  386. `AA', None, CopyArg1, CopyArg2, Modulate, Modulate2, Modulate4, Add, AddSigned,
  387. BlendDiffuseAlpha, BlendTextureAlpha, BlendFactorAlpha, BlendTextureAlphaPM,
  388. AddSigned2, Subtract, AddSmooth, ModulateAlphaAddColor, ModulateColorAddAlpha)