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.

774 lines
28 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) Microsoft Corporation, 1998.
  3. //
  4. // reftnl.hpp
  5. //
  6. // Direct3D Reference Transform and Lighting - Main Header File
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _REFTNL_HPP
  10. #define _REFTNL_HPP
  11. #define MAX_REFERENCE_LIGHTS 128
  12. // Default color values that should be used when ther is no lighting and
  13. // color in vertices provided
  14. #define RR_DEFAULT_DIFFUSE 0xFFFFFFFF;
  15. #define RR_DEFAULT_SPECULAR 0;
  16. #define REF_GB_LEFT -32768.f
  17. #define REF_GB_TOP -32768.f
  18. #define REF_GB_RIGHT 32767.f
  19. #define REF_GB_BOTTOM 32767.f
  20. //----------------------------------------------------------------------------
  21. // FVF related macros
  22. //----------------------------------------------------------------------------
  23. const DWORD RRMAX_FVF_TEXCOORD = 8;
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Typedefs
  27. //
  28. //-----------------------------------------------------------------------------
  29. // Number of clipping planes
  30. #define RRMAX_USER_CLIPPLANES 6
  31. // Number of clipping planes
  32. #define RRMAX_CLIPPING_PLANES (6+RRMAX_USER_CLIPPLANES)
  33. // Number of world matrices
  34. #define RRMAX_WORLD_MATRICES 4
  35. // Space for vertices generated/copied while clipping one triangle
  36. #define RRMAX_CLIP_VERTICES (( 2 * RRMAX_CLIPPING_PLANES ) + 3 )
  37. // 3 verts. -> 1 tri, 4 v -> 2 t, N vertices -> (N - 2) triangles
  38. #define RRMAX_CLIP_TRIANGLES ( RRMAX_CLIP_VERTICES - 2 )
  39. // make smaller than guard band for easier clipping
  40. #define RRMAX_POINT_SIZE ( REF_GB_RIGHT )
  41. typedef DWORD RRCLIPCODE;
  42. typedef struct _RRCLIPVTX
  43. {
  44. D3DVALUE hx;
  45. D3DVALUE hy;
  46. D3DVALUE hz;
  47. D3DVALUE hw;
  48. DWORD clip;
  49. D3DCOLOR color;
  50. D3DCOLOR specular;
  51. D3DVALUE sx;
  52. D3DVALUE sy;
  53. D3DVALUE sz;
  54. D3DVALUE rhw;
  55. _RRCLIPVTX *next;
  56. D3DVALUE tex[RRMAX_FVF_TEXCOORD*4];
  57. D3DVALUE s;
  58. D3DVALUE eyenx;
  59. D3DVALUE eyeny;
  60. D3DVALUE eyenz;
  61. D3DVALUE eyex;
  62. D3DVALUE eyey;
  63. D3DVALUE eyez;
  64. } RRCLIPVTX;
  65. typedef struct _RRCLIPTRIANGLE
  66. {
  67. RRCLIPVTX *v[3];
  68. } RRCLIPTRIANGLE;
  69. typedef struct _RRUSERCLIPPLANE
  70. {
  71. RRVECTOR4 plane;
  72. BOOL bActive;
  73. } RRUSERCLIPPLANE, *LPRRUSERCLIPPLANE;
  74. //-----------------------------------------------------------------------------
  75. //
  76. // forward declarations, mostly from reftnli.hpp
  77. //
  78. //-----------------------------------------------------------------------------
  79. class RRMaterial;
  80. class RRLight;
  81. class RRTransform;
  82. //-----------------------------------------------------------------------------
  83. //
  84. // Base class for all RefTnL classes to use common allocation functions
  85. //
  86. //-----------------------------------------------------------------------------
  87. class RRAlloc
  88. {
  89. public:
  90. void* operator new(size_t s);
  91. void operator delete(void* p, size_t);
  92. };
  93. //-----------------------------------------------------------------------------
  94. //
  95. // RRVECTORH - Homogeneous vector
  96. //
  97. //-----------------------------------------------------------------------------
  98. typedef struct tagRRVECTORH
  99. {
  100. D3DVALUE x;
  101. D3DVALUE y;
  102. D3DVALUE z;
  103. D3DVALUE w;
  104. } RRVECTORH, *PRRVECTORH;
  105. //-----------------------------------------------------------------------------
  106. //
  107. // RRMATRIX - Matrix data-structure
  108. //
  109. //-----------------------------------------------------------------------------
  110. typedef enum tagRRMATRIXTYPE
  111. {
  112. RRMatrixIdentity,
  113. RRMatrixTranslate,
  114. RRMatrixRotateTranslate,
  115. RRMatrixAffine,
  116. RRMatrixGeneral
  117. } RRMATRIXTYPE;
  118. typedef D3DMATRIX RRMATRIX;
  119. //-----------------------------------------------------------------------------
  120. //
  121. // RRTRANSFORMDATA - Transformation data used by Refrence T&L implementation
  122. // to transform vertices.
  123. //
  124. //-----------------------------------------------------------------------------
  125. typedef struct tagRRTRANSFORMDATA
  126. {
  127. RRMATRIX m_PS; // Mproj * Mshift
  128. RRMATRIX m_VPS; // Mview * PS
  129. RRMATRIX m_VPSInv; // Inverse( Mview * PS )
  130. RRMATRIX m_CTMI; // Inverse current transformation matrix
  131. RRVECTORH m_frustum[6]; // Normalized plane equations for viewing
  132. // frustum in the model space
  133. DWORD m_dwFlags;
  134. } RRTRANSFORMDATA, *PRRTRANSFORMDATA;
  135. //---------------------------------------------------------------------
  136. // RRLIGHTING
  137. // All the lighting related state clubbed together
  138. //---------------------------------------------------------------------
  139. typedef struct {D3DVALUE r,g,b;} RRCOLOR;
  140. typedef struct _RRLIGHTING
  141. {
  142. // Active Light list
  143. RRLight *pActiveLights;
  144. // Temporary data used when computing lighting
  145. D3DVECTOR eye_in_eye; // eye position in eye space
  146. // It is (0, 0, 0)
  147. // Ma * La + Me (Ambient and Emissive) ------
  148. RRCOLOR ambEmiss;
  149. // ColorVertex stuff ------------------------
  150. RRCOLOR *pAmbientSrc;
  151. RRCOLOR *pDiffuseSrc;
  152. RRCOLOR *pSpecularSrc;
  153. RRCOLOR *pEmissiveSrc;
  154. // Diffuse ----------------------------------
  155. RRCOLOR vertexDiffuse; // Provided with a vertex, used if
  156. // COLORVERTEX is enabled and a diffuse
  157. // color is provided in the vertex
  158. RRCOLOR diffuse; // Diffuse accumulates here
  159. DWORD outDiffuse; // Diffuse color result of lighting
  160. // Specular --------------------------------
  161. RRCOLOR vertexSpecular;// Provided with a vertex, used if
  162. // COLORVERTEX is enabled and a specular
  163. // color is provided in the vertex
  164. RRCOLOR specular; // Specular accumulates here
  165. DWORD outSpecular; // Specular color result of lighting
  166. D3DVALUE specThreshold; // If the dot product is less than this
  167. // value, specular factor is zero
  168. // End of temporary data
  169. // RENDERSTATEAMBIENT --------------------------------------
  170. // Ambient color set by D3DRENDERSTATE_AMBIENT
  171. // They are all scaled to 0 - 1
  172. D3DVALUE ambient_red;
  173. D3DVALUE ambient_green;
  174. D3DVALUE ambient_blue;
  175. DWORD ambient_save; // Original unscaled color
  176. // Fog -----------------------------------------------------
  177. int fog_mode;
  178. D3DCOLOR fog_color;
  179. D3DVALUE fog_density;
  180. D3DVALUE fog_start;
  181. D3DVALUE fog_end;
  182. D3DVALUE fog_factor; // 255 / (fog_end - fog_start)
  183. D3DCOLORMODEL color_model;
  184. // Material ------------------------------------------------
  185. // For color material
  186. LPDWORD pDiffuseAlphaSrc;
  187. LPDWORD pSpecularAlphaSrc;
  188. DWORD materialDiffAlpha; // Current material diffuse
  189. // alpha (0-255) shifted left
  190. // by 24 bits
  191. DWORD materialSpecAlpha; // Current material specular
  192. // alpha (0-255) shifted left
  193. // by 24 bits
  194. DWORD vertexDiffAlpha; // Current material diffuse
  195. // alpha (0-255) shifted left
  196. // by 24 bits
  197. DWORD vertexSpecAlpha; // Current material specular
  198. // alpha (0-255) shifted left
  199. // by 24 bits
  200. D3DMATERIAL7 material; // Cached material data
  201. RRCOLOR matAmb;
  202. RRCOLOR matDiff;
  203. RRCOLOR matSpec;
  204. RRCOLOR matEmis;
  205. } RRLIGHTING;
  206. //-----------------------------------------------------------------------------
  207. //
  208. // RRLight - The light object used by the Reference T&L implementation
  209. // An array of these are instanced in the ReferenceRasterizer object.
  210. //
  211. //-----------------------------------------------------------------------------
  212. typedef struct _RRLIGHTI
  213. {
  214. DWORD flags;
  215. D3DVECTOR position_in_eye; // In the eye space
  216. D3DVECTOR direction_in_eye; // In the eye space
  217. //
  218. // Saved light colors scaled from 0 - 255, needed for COLORVERTEX
  219. //
  220. D3DCOLORVALUE La; // light ambient
  221. D3DCOLORVALUE Ld; // light diffuse
  222. D3DCOLORVALUE Ls; // light specular
  223. //
  224. // Precomputed colors scaled from 0 - 255,
  225. //
  226. D3DCOLORVALUE Ma_La; // Material ambient times light ambient
  227. D3DCOLORVALUE Md_Ld; // Material diffuse times light diffuse
  228. D3DCOLORVALUE Ms_Ls; // Material specular times light specular
  229. D3DVECTOR halfway;
  230. // Stuff for SpotLights
  231. D3DVALUE range_squared;
  232. D3DVALUE cos_theta_by_2;
  233. D3DVALUE cos_phi_by_2;
  234. D3DVALUE inv_theta_minus_phi;
  235. } RRLIGHTI;
  236. //-----------------------------------------------------------------------------
  237. // Function pointer to the functions that light a vertex
  238. //-----------------------------------------------------------------------------
  239. typedef void (*RRLIGHTVERTEXFN)( RRLIGHTING& LData, D3DLIGHT7 *pLight,
  240. RRLIGHTI *pLightI, D3DLIGHTINGELEMENT *in,
  241. DWORD dwFlags, DWORD dwFVFIn );
  242. //-----------------------------------------------------------------------------
  243. // Functions to compute lighting
  244. //-----------------------------------------------------------------------------
  245. typedef struct _RRLIGHTVERTEX_FUNC_TABLE
  246. {
  247. RRLIGHTVERTEXFN pfnDirectional;
  248. RRLIGHTVERTEXFN pfnParallelPoint;
  249. RRLIGHTVERTEXFN pfnSpot;
  250. RRLIGHTVERTEXFN pfnPoint;
  251. } RRLIGHTVERTEX_FUNC_TABLE;
  252. //-----------------------------------------------------------------------------
  253. //
  254. // RRLight - The light object used by the Reference T&L implementation
  255. // An array of these are instanced in the ReferenceRasterizer object.
  256. //
  257. //-----------------------------------------------------------------------------
  258. #define RRLIGHT_ENABLED 0x00000001 // Is the light active
  259. #define RRLIGHT_NEEDSPROCESSING 0x00000002 // Is the light data processed
  260. class RRLight : public RRAlloc
  261. {
  262. public:
  263. RRLight();
  264. BOOL IsEnabled() {return (m_dwFlags & RRLIGHT_ENABLED);}
  265. BOOL NeedsProcessing() {return (m_dwFlags & RRLIGHT_NEEDSPROCESSING);}
  266. HRESULT SetLight(LPD3DLIGHT7 pLight);
  267. HRESULT GetLight( LPD3DLIGHT7 pLight );
  268. void ProcessLight( D3DMATERIAL7 *mat, RRLIGHTVERTEX_FUNC_TABLE *pTbl);
  269. void XformLight( D3DMATRIX* mV );
  270. void Enable( RRLight **ppRoot );
  271. void Disable( RRLight **ppRoot );
  272. private:
  273. // Flags
  274. DWORD m_dwFlags;
  275. // Active List next element
  276. RRLight *m_Next;
  277. // Specific function to light the vertex
  278. RRLIGHTVERTEXFN m_pfnLightVertex;
  279. // Light data set by the runtime
  280. D3DLIGHT7 m_Light;
  281. // Light data computed by the driver
  282. RRLIGHTI m_LightI;
  283. friend class ReferenceRasterizer;
  284. friend class RRProcessVertices;
  285. };
  286. //-----------------------------------------------------------------------------
  287. //
  288. // RRMaterial - Class for materials data used for lighting by the driver
  289. //
  290. //-----------------------------------------------------------------------------
  291. class RRMaterial : public RRAlloc
  292. {
  293. public:
  294. RRMaterial();
  295. ~RRMaterial();
  296. HRESULT SetMaterial(LPD3DMATERIAL7);
  297. HRESULT GetMaterial(LPD3DMATERIAL7);
  298. private:
  299. // Data describing material
  300. D3DMATERIAL7 dmMaterial;
  301. };
  302. //---------------------------------------------------------------------
  303. // This class manages growing buffer, aligned to 32 byte boundary
  304. // Number if bytes should be power of 2.
  305. // D3DMalloc is used to allocate memory
  306. //---------------------------------------------------------------------
  307. class RefAlignedBuffer32
  308. {
  309. public:
  310. RefAlignedBuffer32() {m_size = 0; m_allocatedBuf = 0; m_alignedBuf = 0;}
  311. ~RefAlignedBuffer32() {if (m_allocatedBuf) free(m_allocatedBuf);}
  312. // Returns aligned buffer address
  313. LPVOID GetAddress() {return m_alignedBuf;}
  314. // Returns aligned buffer size
  315. DWORD GetSize() {return m_size;}
  316. HRESULT Grow(DWORD dwSize);
  317. HRESULT CheckAndGrow(DWORD dwSize)
  318. {
  319. if (dwSize > m_size)
  320. return Grow(dwSize + 1024);
  321. else
  322. return S_OK;
  323. }
  324. protected:
  325. LPVOID m_allocatedBuf;
  326. LPVOID m_alignedBuf;
  327. DWORD m_size;
  328. };
  329. //---------------------------------------------------------------------
  330. // Digested Viewport information
  331. // calculated from viewport settings
  332. //---------------------------------------------------------------------
  333. typedef struct _RR_VIEWPORTDATA
  334. {
  335. D3DVALUE dvX; // dwX
  336. D3DVALUE dvY; // dwY
  337. D3DVALUE dvWidth; // dwWidth
  338. D3DVALUE dvHeight; // dwHeight
  339. // Coefficients to compute screen coordinates from normalized window
  340. // coordinates
  341. D3DVALUE scaleX; // dvWidth/2
  342. D3DVALUE scaleY; // dvHeight/2
  343. D3DVALUE scaleZ; // (Viewport->dvMaxZ - Viewport->dvMinZ)
  344. D3DVALUE offsetX; // dvX + scaleX
  345. D3DVALUE offsetY; // dvY + scaleY
  346. D3DVALUE offsetZ; // Viewport->dvMinZ
  347. // Coefficients to compute screen coordinates from normalized window
  348. // coordinates
  349. D3DVALUE scaleXi; // Inverse of scaleX
  350. D3DVALUE scaleYi; // Inverse of scaleY
  351. D3DVALUE scaleZi; // Inverse of scaleZ
  352. // Min and max values for viewport window in pixels
  353. D3DVALUE minX; // offsetX - scaleX
  354. D3DVALUE minY; // offsetY - scaleY
  355. D3DVALUE maxX; // offsetX + scaleX
  356. D3DVALUE maxY; // offsetY + scaleY
  357. // Min and max window values with guard band in pixels
  358. D3DVALUE minXgb;
  359. D3DVALUE minYgb;
  360. D3DVALUE maxXgb;
  361. D3DVALUE maxYgb;
  362. // Coefficients to transform a vertex to perform the guard band clipping
  363. // x*gb11 + w*gb41
  364. // y*gb22 + w*gb42
  365. //
  366. D3DVALUE gb11;
  367. D3DVALUE gb22;
  368. D3DVALUE gb41;
  369. D3DVALUE gb42;
  370. // Coefficients to apply clipping rules for the guard band clipping
  371. // They are used by clipping routins
  372. // w*Kgbx1 < x < w*Kgbx2
  373. // w*Kgby1 < y < w*Kgby2
  374. //
  375. D3DVALUE Kgbx1;
  376. D3DVALUE Kgby1;
  377. D3DVALUE Kgbx2;
  378. D3DVALUE Kgby2;
  379. } RRVIEWPORTDATA;
  380. //---------------------------------------------------------------------
  381. // RRCLIPPING
  382. // Cached clipping data
  383. //---------------------------------------------------------------------
  384. typedef struct __RRCLIPPING
  385. {
  386. RefAlignedBuffer32 ClipBuf;
  387. RRCLIPVTX *clip_vbuf1[RRMAX_CLIP_VERTICES];
  388. RRCLIPVTX *clip_vbuf2[RRMAX_CLIP_VERTICES];
  389. RRCLIPVTX **current_vbuf; // clip_vbuf1 or clip_vbuf2
  390. RRCLIPVTX clip_vertices[RRMAX_CLIP_VERTICES];
  391. DWORD dwInterpolate;
  392. int clip_vertices_used;
  393. DWORD clip_color;
  394. DWORD clip_specular;
  395. } RRCLIPPING;
  396. // RRProcessVertices::m_dwTLState flags
  397. #define RRPV_DOLIGHTING 0x00000001
  398. #define RRPV_DOCLIPPING 0x00000002
  399. #define RRPV_GUARDBAND 0x00000004
  400. #define RRPV_DOFOG 0x00000008
  401. #define RRPV_DOSPECULAR 0x00000010
  402. #define RRPV_RANGEFOG 0x00000020
  403. #define RRPV_NORMALIZENORMALS 0x00000040
  404. #define RRPV_LOCALVIEWER 0x00000080
  405. #define RRPV_DOCOMPUTEPOINTSIZE 0x00000100
  406. #define RRPV_DOPASSEYENORMAL 0x00000200
  407. #define RRPV_DOPASSEYEXYZ 0x00000400
  408. // ColorVertexFlags
  409. #define RRPV_VERTEXDIFFUSENEEDED 0x00000800
  410. #define RRPV_VERTEXSPECULARNEEDED 0x00001000
  411. #define RRPV_COLORVERTEXAMB 0x00002000
  412. #define RRPV_COLORVERTEXDIFF 0x00004000
  413. #define RRPV_COLORVERTEXSPEC 0x00008000
  414. #define RRPV_COLORVERTEXEMIS 0x00010000
  415. #define RRPV_COLORVERTEXFLAGS (RRPV_VERTEXDIFFUSENEEDED | \
  416. RRPV_VERTEXSPECULARNEEDED | \
  417. RRPV_COLORVERTEXAMB | \
  418. RRPV_COLORVERTEXDIFF | \
  419. RRPV_COLORVERTEXSPEC | \
  420. RRPV_COLORVERTEXEMIS )
  421. // RRProcessVertices::m_dwDirtyFlags flags
  422. #define RRPV_DIRTY_PROJXFM 0x00000001
  423. #define RRPV_DIRTY_VIEWXFM 0x00000002
  424. #define RRPV_DIRTY_WORLDXFM 0x00000004
  425. #define RRPV_DIRTY_WORLD1XFM 0x00000008
  426. #define RRPV_DIRTY_WORLD2XFM 0x00000010
  427. #define RRPV_DIRTY_WORLD3XFM 0x00000020
  428. #define RRPV_DIRTY_VIEWRECT 0x00000040
  429. #define RRPV_DIRTY_ZRANGE 0x00000080
  430. #define RRPV_DIRTY_XFORM (RRPV_DIRTY_PROJXFM | \
  431. RRPV_DIRTY_VIEWXFM | \
  432. RRPV_DIRTY_VIEWRECT | \
  433. RRPV_DIRTY_WORLDXFM | \
  434. RRPV_DIRTY_WORLD1XFM | \
  435. RRPV_DIRTY_WORLD2XFM | \
  436. RRPV_DIRTY_WORLD3XFM | \
  437. RRPV_DIRTY_ZRANGE)
  438. #define RRPV_DIRTY_MATERIAL 0x00000100
  439. #define RRPV_DIRTY_SETLIGHT 0x00000200
  440. #define RRPV_DIRTY_NEEDXFMLIGHT 0x00000400
  441. #define RRPV_DIRTY_COLORVTX 0x00000800
  442. #define RRPV_DIRTY_LIGHTING (RRPV_DIRTY_MATERIAL | \
  443. RRPV_DIRTY_SETLIGHT | \
  444. RRPV_DIRTY_NEEDXFMLIGHT | \
  445. RRPV_DIRTY_COLORVTX)
  446. #define RRPV_DIRTY_FOG 0x00010000
  447. #define RRPV_DIRTY_CLIPPLANES 0x00020000
  448. #define RRPV_DIRTY_INVERSEWORLDVIEW 0x00040000
  449. //---------------------------------------------------------------------
  450. // Transform & Lighting related data is encapsulated here
  451. //---------------------------------------------------------------------
  452. class RRProcessVertices
  453. {
  454. protected:
  455. //-------------------------------------------------------------------------
  456. // Unprocessed state set by the DDI
  457. //-------------------------------------------------------------------------
  458. // Growable Light array
  459. RRLight *m_pLightArray;
  460. // RRLight *m_pLightArray;
  461. DWORD m_dwLightArraySize; // Size of the light array allocated
  462. // Current material to use for lighting
  463. D3DMATERIAL7 m_Material;
  464. // Vertex components
  465. // Note: position is used to store the vertex buffer in the non-strided
  466. // driver emulation mode
  467. D3DDP_PTRSTRIDE m_position;
  468. D3DDP_PTRSTRIDE m_normal;
  469. D3DDP_PTRSTRIDE m_specular;
  470. D3DDP_PTRSTRIDE m_diffuse;
  471. D3DDP_PTRSTRIDE m_tex0;
  472. D3DDP_PTRSTRIDE m_tex1;
  473. D3DDP_PTRSTRIDE m_tex2;
  474. D3DDP_PTRSTRIDE m_tex3;
  475. D3DDP_PTRSTRIDE m_tex4;
  476. D3DDP_PTRSTRIDE m_tex5;
  477. D3DDP_PTRSTRIDE m_tex6;
  478. D3DDP_PTRSTRIDE m_tex7;
  479. // Transformation state stored by the reference implementation
  480. RRMATRIX m_xfmProj;
  481. RRMATRIX m_xfmView;
  482. RRMATRIX m_xfmWorld[RRMAX_WORLD_MATRICES];
  483. // Viewport data
  484. D3DVIEWPORT7 m_Viewport;
  485. // User defined clipping planes
  486. RRVECTOR4 m_userClipPlanes[RRMAX_USER_CLIPPLANES];
  487. //-------------------------------------------------------------------------
  488. // Cached T&L related render-state info
  489. //-------------------------------------------------------------------------
  490. DWORD m_dwTLState; // RenderState related flags
  491. DWORD m_dwDirtyFlags; // Dirty flags
  492. //-------------------------------------------------------------------------
  493. // Transformation data
  494. //-------------------------------------------------------------------------
  495. // Buffer to store clip flags
  496. RefAlignedBuffer32 m_ClipFlagBuf;
  497. RRCLIPCODE *m_pClipBuf;
  498. // Buffer to store transformed vertices
  499. RefAlignedBuffer32 m_TLVBuf;
  500. LPVOID m_pvOut;
  501. // Current transformation matrix
  502. RRMATRIX m_xfmCurrent[RRMAX_WORLD_MATRICES]; // using WORLDi matrix
  503. RRMATRIX m_xfmToEye[RRMAX_WORLD_MATRICES]; // Transforms to camera
  504. // space (Mworld*Mview)
  505. RRMATRIX m_xfmToEyeInv[RRMAX_WORLD_MATRICES]; // and its Inverse
  506. D3DPRIMITIVETYPE m_primType; // Current primitive being drawn
  507. DWORD m_dwNumVertices; // Number of vertices to process
  508. DWORD m_dwNumIndices; // Number of indices for Indexed Prims
  509. LPWORD m_pIndices;
  510. DWORD m_dwFVFIn; // FVF of the input vertices
  511. UINT64 m_qwFVFOut; // Desired FVF for the output vertices
  512. DWORD m_dwOutputVtxSize; // Size of the output vertex
  513. DWORD m_dwNumTexCoords; // Number of the texture coordinate sets
  514. DWORD m_dwTexCoordSize[D3DDP_MAXTEXCOORD]; // Size of each one of them in
  515. // bytes
  516. DWORD m_dwTextureCoordSizeTotal; // In Bytes
  517. DWORD m_dwTexOffset; // Offsets in the input FVF vertex.
  518. DWORD m_dwDiffuseOffset; // Recomputed when FVF is changed.
  519. DWORD m_dwSpecularOffset;
  520. DWORD m_dwNormalOffset;
  521. int m_numVertexBlends;
  522. RRTRANSFORMDATA m_TransformData;
  523. RRVIEWPORTDATA m_ViewData; // Computed Viewport dependent info.
  524. FLOAT m_fPointSize;
  525. FLOAT m_fPointAttA;
  526. FLOAT m_fPointAttB;
  527. FLOAT m_fPointAttC;
  528. FLOAT m_fPointSizeMin;
  529. //-------------------------------------------------------------------------
  530. // Lighting data
  531. //-------------------------------------------------------------------------
  532. RRLIGHTVERTEX_FUNC_TABLE m_LightVertexTable;
  533. RRLIGHTING m_lighting; // Lighting state
  534. //-------------------------------------------------------------------------
  535. // Clipping data
  536. //-------------------------------------------------------------------------
  537. // Clipping related
  538. RRCLIPCODE m_clipUnion; // OR of all vertex clip flags
  539. RRCLIPCODE m_clipIntersection; // AND of all vertex clip flags
  540. RRCLIPPING m_clipping;
  541. // User clip planes transformed
  542. RRUSERCLIPPLANE m_xfmUserClipPlanes[RRMAX_USER_CLIPPLANES];
  543. ///////////////////////////////////////////////////////////////////////////
  544. // Methods
  545. ///////////////////////////////////////////////////////////////////////////
  546. HRESULT UpdateXformData();
  547. HRESULT UpdateLightingData();
  548. HRESULT UpdateFogData();
  549. HRESULT UpdateClippingData( DWORD dwClipPlanesEnable );
  550. RRCLIPCODE
  551. ComputeClipCodes(RRCLIPCODE* pclipIntersection, RRCLIPCODE* pclipUnion,
  552. FLOAT x_clip, FLOAT y_clip, FLOAT z_clip, FLOAT w_clip, FLOAT fPointSize);
  553. RRCLIPCODE ProcessVertices();
  554. HRESULT DoIPrim();
  555. HRESULT DoNIPrim();
  556. void SetupFVFData(BOOL bFogEnabled, BOOL bSpecularEnable);
  557. void LightVertex( D3DLIGHTINGELEMENT *le );
  558. void FogVertex ( D3DVECTOR &v, D3DLIGHTINGELEMENT *le,
  559. int numVertexBlends,
  560. float *pBlendFactors,
  561. BOOL bVertexInEyeSpace );
  562. void InitTLData();
  563. // DrawClippedPrimitive
  564. HRESULT DrawOneClippedIndexedPrimitive();
  565. HRESULT DrawOneClippedPrimitive();
  566. // Clipping Related
  567. void Interpolate(RRCLIPVTX *out, RRCLIPVTX *p1, RRCLIPVTX *p2,
  568. int code, D3DVALUE num, D3DVALUE denom);
  569. int ClipLeft( RRCLIPVTX **inv, RRCLIPVTX **outv, int count);
  570. int ClipRight( RRCLIPVTX **inv, RRCLIPVTX **outv, int count);
  571. int ClipTop( RRCLIPVTX **inv, RRCLIPVTX **outv, int count);
  572. int ClipBottom( RRCLIPVTX **inv, RRCLIPVTX **outv, int count);
  573. int ClipFront( RRCLIPVTX **inv, RRCLIPVTX **outv, int count);
  574. int ClipBack( RRCLIPVTX **inv, RRCLIPVTX **outv, int count);
  575. int ClipLeftGB( RRCLIPVTX **inv, RRCLIPVTX **outv, int count);
  576. int ClipRightGB( RRCLIPVTX **inv, RRCLIPVTX **outv, int count);
  577. int ClipTopGB( RRCLIPVTX **inv, RRCLIPVTX **outv, int count);
  578. int ClipBottomGB( RRCLIPVTX **inv, RRCLIPVTX **outv, int count);
  579. int ClipLineLeft( RRCLIPTRIANGLE *inv);
  580. int ClipLineRight( RRCLIPTRIANGLE *inv);
  581. int ClipLineTop( RRCLIPTRIANGLE *inv);
  582. int ClipLineBottom( RRCLIPTRIANGLE *inv);
  583. int ClipLineFront( RRCLIPTRIANGLE *inv);
  584. int ClipLineBack( RRCLIPTRIANGLE *inv);
  585. int ClipLineLeftGB( RRCLIPTRIANGLE *inv);
  586. int ClipLineRightGB( RRCLIPTRIANGLE *inv);
  587. int ClipLineTopGB( RRCLIPTRIANGLE *inv);
  588. int ClipLineBottomGB( RRCLIPTRIANGLE *inv);
  589. int ClipByPlane( RRCLIPVTX **inv, RRCLIPVTX **outv, RRVECTOR4 *plane,
  590. DWORD dwClipFlag, int count );
  591. int ClipLineByPlane( RRCLIPTRIANGLE *line, RRVECTOR4 *plane,
  592. DWORD dwClipBit);
  593. };
  594. // Vertex Lighting functions
  595. void RRLV_Directional( RRLIGHTING&, D3DLIGHT7 *, RRLIGHTI *,
  596. D3DLIGHTINGELEMENT *, DWORD, DWORD );
  597. void RRLV_PointAndSpot( RRLIGHTING&, D3DLIGHT7 *, RRLIGHTI *,
  598. D3DLIGHTINGELEMENT *, DWORD, DWORD );
  599. // For TL Refrast
  600. // Following primitive functions are shared by REF rasterizers
  601. HRESULT FASTCALL
  602. DoDrawOneIndexedPrimitive(ReferenceRasterizer * pCtx,
  603. UINT16 FvfStride,
  604. PUINT8 pVtx,
  605. LPWORD puIndices,
  606. D3DPRIMITIVETYPE PrimType,
  607. UINT cIndices);
  608. HRESULT FASTCALL
  609. DoDrawOnePrimitive(ReferenceRasterizer * pCtx,
  610. UINT16 FvfStride,
  611. PUINT8 pVtx,
  612. D3DPRIMITIVETYPE PrimType,
  613. UINT cVertices);
  614. HRESULT FASTCALL
  615. DoDrawOneEdgeFlagTriangleFan(ReferenceRasterizer * pCtx,
  616. UINT16 FvfStride,
  617. PUINT8 pVtx,
  618. UINT cVertices,
  619. UINT32 dwEdgeFlags);
  620. //---------------------------------------------------------------------
  621. // ComputeTextureCoordSize:
  622. // Computes the following device data
  623. // - bTextureCoordSizeTotal
  624. // - bTextureCoordSize[] array, based on the input FVF id
  625. //---------------------------------------------------------------------
  626. __inline void ComputeTextureCoordSize(DWORD dwFVF,
  627. LPDWORD pdwTexCoordSizeArray,
  628. LPDWORD pdwTexCoordSizeTotal)
  629. {
  630. // Texture formats size 00 01 10 11
  631. static BYTE bTextureSize[4] = {2*4, 3*4, 4*4, 4};
  632. DWORD dwNumTexCoord = FVF_TEXCOORD_NUMBER(dwFVF);
  633. // Compute texture coordinate size
  634. DWORD dwTextureFormats = dwFVF >> 16;
  635. if (dwTextureFormats == 0)
  636. {
  637. *pdwTexCoordSizeTotal = (BYTE)dwNumTexCoord * 2 * 4;
  638. for (DWORD i=0; i < dwNumTexCoord; i++)
  639. pdwTexCoordSizeArray[i] = 4*2;
  640. }
  641. else
  642. {
  643. *pdwTexCoordSizeTotal = 0;
  644. for (DWORD i=0; i < dwNumTexCoord; i++)
  645. {
  646. BYTE dwSize = bTextureSize[dwTextureFormats & 3];
  647. pdwTexCoordSizeArray[i] = dwSize;
  648. *pdwTexCoordSizeTotal += dwSize;
  649. dwTextureFormats >>= 2;
  650. }
  651. }
  652. return;
  653. }
  654. ///////////////////////////////////////////////////////////////////////////////
  655. #endif // _REFTNL_HPP