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.

1128 lines
42 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) Microsoft Corporation, 2000.
  3. //
  4. // refdev.hpp
  5. //
  6. // Direct3D Reference Device - Main Header File
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _REFDEV_HPP
  10. #define _REFDEV_HPP
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <stdarg.h>
  14. #include <windows.h>
  15. #pragma warning( disable: 4056) // fp constant
  16. #pragma warning( disable: 4244) // fp DOUBLE->FLOAT
  17. #include <ddraw.h>
  18. #include <ddrawi.h>
  19. #include <d3dhal.h>
  20. #include "d3d8ddi.h"
  21. //@@BEGIN_MSINTERNAL
  22. #include "d3d8p.h"
  23. //@@END_MSINTERNAL
  24. #include <rdcomm.hpp>
  25. // forward declarations
  26. class RDSurfaceManager;
  27. class RDSurface2D;
  28. class RDSurface;
  29. class RDRenderTarget;
  30. class RDTextureStageState;
  31. class RDBSpline;
  32. class RDNPatch;
  33. class RefDev;
  34. #include <templarr.hpp>
  35. #include <vshader.h>
  36. #include <vstream.h>
  37. #include <reftnl.hpp>
  38. #include <refrast.hpp>
  39. #include <pshader.h>
  40. //-----------------------------------------------------------------------------
  41. //
  42. // A special legacy (pre-DX6) texture op we can't easily map into the new
  43. // texture ops.
  44. //
  45. //-----------------------------------------------------------------------------
  46. #define D3DTOP_LEGACY_ALPHAOVR (0x7fffffff)
  47. //-----------------------------------------------------------------------------
  48. //
  49. // Constants
  50. //
  51. //-----------------------------------------------------------------------------
  52. const DWORD RD_MAX_NUM_TEXTURE_FORMATS = 50;
  53. const DWORD RD_MAX_CLOD = 13*6; // base texture up to 4kx4k for 6 Cubemaps
  54. //-----------------------------------------------------------------------------
  55. //
  56. // RefRastSetMemif - Routine to set memory allocation interface for reference
  57. // rasterizer - takes pointers to functions to use for malloc, free, and realloc.
  58. //
  59. // These must be set prior to new'ing any RefDev objects.
  60. //
  61. //-----------------------------------------------------------------------------
  62. void
  63. RefRastSetMemif(
  64. LPVOID( _cdecl* pfnMemAlloc )( size_t ),
  65. void( _cdecl* pfnMemFree )( PVOID ),
  66. LPVOID( _cdecl* pfnMemReAlloc )( PVOID, size_t ) );
  67. //-----------------------------------------------------------------------------
  68. //
  69. // RDRenderTarget - Class which encompasses all information about rendering
  70. // target, including size, type/pointer/stride for color and depth/stencil
  71. // buffers, guard band clip info, W range info.
  72. //
  73. // Usage is to instantiate, fill out public members, and install into a
  74. // RefDev object via RefDev::SetRenderTarget.
  75. //
  76. //-----------------------------------------------------------------------------
  77. class RDRenderTarget : public RDAlloc
  78. {
  79. public:
  80. ///////////////////////////////////////////////////////////////////////////
  81. //
  82. // public interface
  83. //
  84. ///////////////////////////////////////////////////////////////////////////
  85. RDRenderTarget( void );
  86. ~RDRenderTarget( void );
  87. //
  88. // these need to be filled in by the user before installing in a
  89. // RefDev object
  90. //
  91. RECT m_Clip; // clipping bounds
  92. FLOAT m_fWRange[2]; // range of device W (W at near and far clip planes)
  93. RDSurface2D* m_pColor;
  94. RDSurface2D* m_pDepth;
  95. // This boolean indicates that the DDI used to set render target
  96. // is a pre-DX7. This is used by the destructor to free up the
  97. // color and depth buffers.
  98. BOOL m_bPreDX7DDI;
  99. ///////////////////////////////////////////////////////////////////////////
  100. //
  101. // internal state and methods
  102. //
  103. ///////////////////////////////////////////////////////////////////////////
  104. friend class RefDev;
  105. HRESULT Initialize( LPDDRAWI_DIRECTDRAW_LCL pDDLcl, DWORD dwColorHandle,
  106. DWORD dwDepthHandle );
  107. HRESULT Initialize( LPDDRAWI_DIRECTDRAW_LCL pDDLcl,
  108. LPDDRAWI_DDRAWSURFACE_LCL pLclColor,
  109. LPDDRAWI_DDRAWSURFACE_LCL pLclZ );
  110. HRESULT Initialize( LPDDRAWI_DDRAWSURFACE_LCL pLclColor,
  111. LPDDRAWI_DDRAWSURFACE_LCL pLclZ );
  112. // read/write specific sample
  113. void ReadPixelColor ( INT32 iX, INT32 iY, UINT Sample, RDColor& Color );
  114. void WritePixelColor ( INT32 iX, INT32 iY, UINT Sample, const RDColor& Color, BOOL bDither );
  115. void WritePixelDepth ( INT32 iX, INT32 iY, UINT Sample, const RDDepth& Depth );
  116. void ReadPixelDepth ( INT32 iX, INT32 iY, UINT Sample, RDDepth& Depth );
  117. void WritePixelStencil( INT32 iX, INT32 iY, UINT Sample, UINT8 uStencil );
  118. void ReadPixelStencil ( INT32 iX, INT32 iY, UINT Sample, UINT8& uStencil );
  119. // write all samples
  120. void WritePixelColor ( INT32 iX, INT32 iY, const RDColor& Color, BOOL bDither );
  121. void WritePixelDepth ( INT32 iX, INT32 iY, const RDDepth& Depth );
  122. void WritePixelStencil( INT32 iX, INT32 iY, UINT8 uStencil );
  123. void Clear ( RDColor fillColor, LPD3DHAL_DP2COMMAND pCmd );
  124. void ClearDepth ( RDDepth fillDepth, LPD3DHAL_DP2COMMAND pCmd );
  125. void ClearStencil ( UINT8 uStencil, LPD3DHAL_DP2COMMAND pCmd );
  126. void ClearDepthStencil( RDDepth fillDepth, UINT8 uStencil, LPD3DHAL_DP2COMMAND pCmd );
  127. };
  128. //-----------------------------------------------------------------------------
  129. //
  130. // RDTextureStageState - This holds the per-stage state for texture mapping.
  131. // An array of these are instanced in the RefDev object.
  132. //
  133. // Store texture matrix at the end of the texture stage state.
  134. //
  135. //-----------------------------------------------------------------------------
  136. class RDTextureStageState
  137. {
  138. public:
  139. union
  140. {
  141. DWORD m_dwVal[D3DTSS_MAX]; // state array (unsigned)
  142. FLOAT m_fVal[D3DTSS_MAX]; // state array (float)
  143. };
  144. };
  145. //-----------------------------------------------------------------------------
  146. //
  147. // RDSurface - Class instanced once per surface which encompasses information
  148. // about a chain of surfaces used either as a mipmap, cubemap, render-target,
  149. // depth-buffer, vertex buffer or an index buffer. Includes size and type
  150. // (assumed same for each level of detail) and pointer/stride for each LOD.
  151. //
  152. // Created by CreateSurfaceEx DDI call.
  153. //
  154. //-----------------------------------------------------------------------------
  155. // Surface type flags. Some combination of them are legal
  156. const DWORD RR_ST_UNKNOWN = 0;
  157. const DWORD RR_ST_TEXTURE = (1<<0);
  158. const DWORD RR_ST_RENDERTARGETCOLOR = (1<<2);
  159. const DWORD RR_ST_RENDERTARGETDEPTH = (1<<3);
  160. const DWORD RR_ST_VERTEXBUFFER = (1<<4);
  161. const DWORD RR_ST_INDEXBUFFER = (1<<5);
  162. // The following flags track the surface status
  163. const DWORD RRSURFACE_STATUS_INITCALLED = (1<<0);
  164. const DWORD RRSURFACE_STATUS_REFCREATED = (1<<1);
  165. const DWORD RRSURFACE_STATUS_ISLOCKED = (1<<2);
  166. class RDSurface
  167. {
  168. public:
  169. RDSurface()
  170. {
  171. m_dwStatus = 0;
  172. m_MemPool = D3DPOOL_FORCE_DWORD;
  173. m_SurfType = RR_ST_UNKNOWN;
  174. m_iLockCount = 0;
  175. }
  176. virtual HRESULT Initialize( LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl ) = 0;
  177. virtual ~RDSurface()
  178. {
  179. return;
  180. }
  181. BOOL IsInitialized(){ return (m_dwStatus & RRSURFACE_STATUS_INITCALLED); }
  182. void SetInitialized(){ m_dwStatus |= RRSURFACE_STATUS_INITCALLED; }
  183. BOOL IsRefCreated() { return (m_dwStatus & RRSURFACE_STATUS_REFCREATED); }
  184. void SetRefCreated(){ m_dwStatus |= RRSURFACE_STATUS_REFCREATED; }
  185. BOOL IsLocked() { return (m_dwStatus & RRSURFACE_STATUS_ISLOCKED); }
  186. void Lock() { m_iLockCount++; }
  187. void Unlock() { if( m_iLockCount > 0 ) m_iLockCount--; }
  188. DWORD GetSurfaceType() { return m_SurfType; }
  189. D3DPOOL GetMemPool() { return m_MemPool; }
  190. protected:
  191. D3DPOOL m_MemPool; // Where is this allocated
  192. DWORD m_SurfType; // the type of surface
  193. DWORD m_dwStatus;
  194. int m_iLockCount;
  195. };
  196. //-----------------------------------------------------------------------------
  197. //
  198. // RDCREATESURFPRIVATE
  199. // PrivateData stored in SurfaceGbl->dwReserved1 at CreateSurface call
  200. //
  201. //-----------------------------------------------------------------------------
  202. class RDCREATESURFPRIVATE
  203. {
  204. public:
  205. RDCREATESURFPRIVATE()
  206. {
  207. dwPitch = 0;
  208. dwLockCount = 0;
  209. pBits = NULL;
  210. wSamples = 1;
  211. dwMultiSamplePitch = 0;
  212. pMultiSampleBits = NULL;
  213. SurfaceFormat = RD_SF_NULL;
  214. }
  215. ~RDCREATESURFPRIVATE()
  216. {
  217. _ASSERT( dwLockCount == 0, "Surface being deleted has some"
  218. "outstanding locks" );
  219. delete [] pBits;
  220. delete [] pMultiSampleBits;
  221. }
  222. void Lock()
  223. {
  224. dwLockCount++;
  225. }
  226. void Unlock()
  227. {
  228. if( dwLockCount > 0)
  229. dwLockCount--;
  230. }
  231. DWORD dwLockCount;
  232. union
  233. {
  234. DWORD dwPitch;
  235. DWORD dwVBSize;
  236. };
  237. BYTE* pBits;
  238. WORD wSamples;
  239. DWORD dwMultiSamplePitch;
  240. BYTE* pMultiSampleBits;
  241. RDSurfaceFormat SurfaceFormat;
  242. };
  243. //---------------------------------------------------------------------------
  244. // RDDSurfaceArrayNode
  245. //
  246. // This is a node in the linked list of the growable array of RefSurfaces
  247. // maintained per ddraw lcl.
  248. //---------------------------------------------------------------------------
  249. struct RDSurfaceHandle
  250. {
  251. RDSurfaceHandle()
  252. {
  253. m_pSurf = NULL;
  254. #if DBG
  255. m_tag = 0;
  256. #endif
  257. }
  258. RDSurface* m_pSurf;
  259. #if DBG
  260. // Non zero means that it has been allocated
  261. DWORD m_tag;
  262. #endif
  263. };
  264. class RDSurfaceArrayNode : public RDListEntry
  265. {
  266. public:
  267. RDSurfaceArrayNode(LPDDRAWI_DIRECTDRAW_LCL pDDLcl);
  268. ~RDSurfaceArrayNode();
  269. HRESULT AddSurface( LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl,
  270. RDSurface** ppSurf );
  271. RDSurface* GetSurface( DWORD dwHandle );
  272. HRESULT RemoveSurface( DWORD dwHandle );
  273. private:
  274. LPDDRAWI_DIRECTDRAW_LCL m_pDDLcl;
  275. GArrayT<RDSurfaceHandle> m_SurfHandleArray;
  276. RDSurfaceArrayNode* m_pNext;
  277. friend class RDSurfaceManager;
  278. };
  279. //---------------------------------------------------------------------------
  280. // RDSurfaceManager
  281. //
  282. // This class maintains a linked list of all the
  283. // surface handle tables for each DD_LCL
  284. //---------------------------------------------------------------------------
  285. class RDSurfaceManager
  286. {
  287. public:
  288. RDSurfaceManager() {m_pFirstNode = NULL;}
  289. ~RDSurfaceManager()
  290. {
  291. RDSurfaceArrayNode *pNode = m_pFirstNode;
  292. while( pNode )
  293. {
  294. RDSurfaceArrayNode *pTmp = pNode;
  295. pNode = pNode->m_pNext;
  296. delete pTmp;
  297. }
  298. }
  299. RDSurfaceArrayNode* AddLclNode( LPDDRAWI_DIRECTDRAW_LCL pDDLcl );
  300. RDSurfaceArrayNode* GetLclNode( LPDDRAWI_DIRECTDRAW_LCL pDDLcl );
  301. HRESULT AddSurfToList( LPDDRAWI_DIRECTDRAW_LCL pDDLcl,
  302. LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl,
  303. RDSurface** ppSurf );
  304. RDSurface* GetSurfFromList( LPDDRAWI_DIRECTDRAW_LCL pDDLcl,
  305. DWORD dwHandle );
  306. HRESULT RemoveSurfFromList( LPDDRAWI_DIRECTDRAW_LCL pDDLcl,
  307. LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl);
  308. HRESULT RemoveSurfFromList( LPDDRAWI_DIRECTDRAW_LCL pDDLcl,
  309. DWORD dwHandle );
  310. private:
  311. RDSurfaceArrayNode *m_pFirstNode;
  312. };
  313. extern RDSurfaceManager g_SurfMgr;
  314. //-----------------------------------------------------------------------------
  315. //
  316. // RDVertexBuffer - The RefDev's representation of the VertexBuffer. It gets
  317. // created on a CreateSurfaceEx call.
  318. //
  319. //-----------------------------------------------------------------------------
  320. class RDVertexBuffer : public RDSurface
  321. {
  322. public:
  323. RDVertexBuffer()
  324. {
  325. m_pBits = NULL;
  326. m_cbSize = 0;
  327. m_FVF = 0;
  328. }
  329. virtual ~RDVertexBuffer() { return; }
  330. HRESULT Initialize( LPDDRAWI_DDRAWSURFACE_LCL pLcl );
  331. LPBYTE GetBits() { return m_pBits; }
  332. int GetFVF() { return m_FVF; }
  333. int GetSize() { return m_cbSize; }
  334. protected:
  335. DWORD m_FVF;
  336. BYTE* m_pBits;
  337. DWORD m_cbSize;
  338. };
  339. //-----------------------------------------------------------------------------
  340. //
  341. // RDPalette - Class for representing and managing palettes in RefDev
  342. //
  343. //-----------------------------------------------------------------------------
  344. class RDPalette
  345. {
  346. public:
  347. RDPalette()
  348. {
  349. m_dwFlags = 0;
  350. memset( m_Entries, 0, sizeof( m_Entries ) );
  351. }
  352. D3DCOLOR* GetEntries()
  353. {
  354. return m_Entries;
  355. }
  356. static const DWORD RDPAL_ALPHAINPALETTE;
  357. static const DWORD m_dwNumEntries;
  358. HRESULT Update( WORD StartIndex, WORD wNumEntries,
  359. PALETTEENTRY* pEntries );
  360. BOOL HasAlpha()
  361. {
  362. return (m_dwFlags & RDPAL_ALPHAINPALETTE);
  363. }
  364. DWORD m_dwFlags;
  365. D3DCOLOR m_Entries[256];
  366. };
  367. struct RDPaletteHandle
  368. {
  369. RDPaletteHandle()
  370. {
  371. m_pPal = NULL;
  372. #if DBG
  373. m_tag = 0;
  374. #endif
  375. }
  376. RDPalette* m_pPal;
  377. #if DBG
  378. // Non zero means that it has been allocated
  379. DWORD m_tag;
  380. #endif
  381. };
  382. //-----------------------------------------------------------------------------
  383. //
  384. // RDSurface2D - Class instanced once per 2D surface which could be either
  385. // texture, color render target or depth buffer information
  386. // about a chain of surfaces. Includes size and type
  387. // (assumed same for each level of detail) and pointer/stride for each LOD.
  388. //
  389. // Also includes pointer to palette, and colorkey value (legacy support only).
  390. //
  391. //-----------------------------------------------------------------------------
  392. class RDSurface2D : public RDSurface
  393. {
  394. public:
  395. ///////////////////////////////////////////////////////////////////////////
  396. //
  397. // public interface
  398. //
  399. ///////////////////////////////////////////////////////////////////////////
  400. RDSurface2D( void );
  401. ~RDSurface2D( void );
  402. friend class RefDev;
  403. class RefDev * m_pRefDev; // refdev which created this - used only when this is bound as a texture
  404. void SetRefDev( RefDev* pRefDev) { m_pRefDev = pRefDev; }
  405. DWORD m_uFlags; // RR_TEXTURE_* bitdefs
  406. // bit definitions for RDSurface2D::uFlags
  407. #define RR_TEXTURE_HAS_CK (1L<< 0) // set if texture has colorkey
  408. #define RR_TEXTURE_ALPHAINPALETTE (1L<< 1) // set if alpha channel in palette
  409. #define RR_TEXTURE_CUBEMAP (1L<< 2) // set if texture is Cubemap with 6 times the number of surfaces
  410. #define RR_TEXTURE_VOLUME (1L<< 4) // set if texture is volume
  411. // basic info
  412. UINT m_iSamples;
  413. int m_iWidth; // size of top-level map
  414. int m_iHeight;
  415. int m_iDepth; // depth of volume texture
  416. BYTE* m_pBits[RD_MAX_CLOD]; // pointer to surface bits
  417. int m_iPitch[RD_MAX_CLOD]; // pitch in bytes
  418. int m_iSlicePitch[RD_MAX_CLOD]; // slice pitch in bytes
  419. // for volume texture
  420. int m_cLOD; // 0..(n-1) count of LODs currently available
  421. RDSurfaceFormat m_SurfFormat; // format of pixel
  422. DWORD m_dwColorKey; // D3DCOLOR colorkey value
  423. DWORD m_dwEmptyFaceColor; // D3DCOLOR empty cubemap empty face value
  424. DWORD* m_pPalette; // pointer to D3DCOLOR palette (may be NULL)
  425. RDPalette* m_pPalObj;
  426. // DD surface pointers for locking/unlocking and GetSurf callback
  427. LPDDRAWI_DDRAWSURFACE_LCL m_pDDSLcl[RD_MAX_CLOD];
  428. int m_cLODDDS; // 0..(n-1) count of LODs actually in the pDDS array
  429. D3DTEXTUREHANDLE m_hTex; // texture handle
  430. ///////////////////////////////////////////////////////////////////////////
  431. //
  432. // internal state and methods
  433. //
  434. ///////////////////////////////////////////////////////////////////////////
  435. BOOL m_bHasAlpha; // TRUE if texture has an alpha channel
  436. int m_cDimension; // 1,2,3 for 1D,2D,3D textures
  437. int m_cTexels[RD_MAX_CLOD][3]; // integer number of texels in each dimension
  438. float m_fTexels[RD_MAX_CLOD][3]; // float number of texels in each dimension
  439. HRESULT Initialize( LPDDRAWI_DDRAWSURFACE_LCL pLcl );
  440. DWORD ComputePitch( LPDDRAWI_DDRAWSURFACE_LCL pLcl ) const;
  441. DWORD ComputePitch( LPDDRAWI_DDRAWSURFACE_LCL pLcl,
  442. RDSurfaceFormat SurfFormat,
  443. DWORD width, DWORD height ) const;
  444. void SetPalette( RDPalette* pPal )
  445. {
  446. m_pPalObj = pPal;
  447. }
  448. void UpdatePalette();
  449. BOOL Validate( void );
  450. void ReadColor( INT32 iX, INT32 iY, INT32 iZ, INT32 iLOD, RDColor& Texel, BOOL &bColorKeyKill );
  451. inline int GetPitch( DWORD level = 0 ) { return m_iPitch[level]; }
  452. inline LPBYTE GetBits( DWORD level = 0) { return m_pBits[level]; }
  453. inline int GetWidth() { return m_iWidth; }
  454. inline int GetHeight() { return m_iHeight; }
  455. inline int GetSamples() { return m_iSamples; }
  456. HRESULT SetLod( DWORD dwLOD )
  457. {
  458. return S_OK;
  459. }
  460. inline RDSurfaceFormat GetSurfaceFormat() { return m_SurfFormat; }
  461. friend class RDRenderTarget;
  462. };
  463. #define RD_STATESET_GROWDELTA 1
  464. #define RRSTATEOVERRIDE_DWORD_BITS 32
  465. #define RRSTATEOVERRIDE_DWORD_SHIFT 5
  466. typedef TemplArray<UINT8> StateSetData;
  467. typedef StateSetData *LPStateSetData;
  468. typedef HRESULT (*PFN_DP2REFOPERATION)(RefDev *pRefDev, LPD3DHAL_DP2COMMAND pCmd);
  469. typedef HRESULT (*PFN_DP2REFOPERATIONUPDATE)(RefDev *pRefDev, LPD3DHAL_DP2COMMAND* ppCmd);
  470. typedef HRESULT (*PFN_DP2REFSETRENDERSTATES)(RefDev *pRefDev,
  471. DWORD dwFvf,
  472. LPD3DHAL_DP2COMMAND pCmd,
  473. LPDWORD lpdwRuntimeRStates);
  474. typedef HRESULT (*PFN_DP2REFTEXTURESTAGESTATE)(RefDev *pRefDev,
  475. DWORD dwFvf,
  476. LPD3DHAL_DP2COMMAND pCmd);
  477. typedef HRESULT (*PFN_DP2REFSETLIGHT)(RefDev *pRefDev,
  478. LPD3DHAL_DP2COMMAND pCmd,
  479. LPDWORD pdwStride);
  480. typedef HRESULT (*PFN_DP2REFSETVERTEXSHADEDCONSTS)
  481. (RefDev *pRefDev, DWORD StartReg, DWORD dwCount,
  482. LPDWORD pData );
  483. typedef HRESULT (*PFN_DP2REFSETPIXELSHADEDCONSTS)
  484. (RefDev *pRefDev, DWORD StartReg, DWORD dwCount,
  485. LPDWORD pData );
  486. typedef struct _RD_STATESETFUNCTIONTBL
  487. {
  488. DWORD dwSize; // size of struct
  489. PFN_DP2REFSETRENDERSTATES pfnDp2SetRenderStates;
  490. PFN_DP2REFTEXTURESTAGESTATE pfnDp2TextureStageState;
  491. PFN_DP2REFOPERATION pfnDp2SetViewport;
  492. PFN_DP2REFOPERATION pfnDp2SetWRange;
  493. PFN_DP2REFOPERATION pfnDp2SetMaterial;
  494. PFN_DP2REFOPERATION pfnDp2SetZRange;
  495. PFN_DP2REFSETLIGHT pfnDp2SetLight;
  496. PFN_DP2REFOPERATION pfnDp2CreateLight;
  497. PFN_DP2REFOPERATION pfnDp2SetTransform;
  498. PFN_DP2REFOPERATION pfnDp2SetExtention;
  499. PFN_DP2REFOPERATION pfnDp2SetClipPlane;
  500. PFN_DP2REFOPERATION pfnDp2SetVertexShader;
  501. PFN_DP2REFSETVERTEXSHADEDCONSTS pfnDp2SetVertexShaderConsts;
  502. PFN_DP2REFOPERATION pfnDp2SetPixelShader;
  503. PFN_DP2REFSETPIXELSHADEDCONSTS pfnDp2SetPixelShaderConsts;
  504. PFN_DP2REFOPERATION pfnDp2SetStreamSource;
  505. PFN_DP2REFOPERATION pfnDp2SetIndices;
  506. PFN_DP2REFOPERATION pfnDp2MultiplyTransform;
  507. } RD_STATESETFUNCTIONTBL, *LPRD_STATESETFUNCTIONTBL;
  508. //
  509. // The device type that the RefDev should emulate
  510. //
  511. typedef enum {
  512. RDDDI_UNKNOWN = 0,
  513. RDDDI_OLDHAL = 1,
  514. RDDDI_DPHAL,
  515. RDDDI_DP2HAL, // DX6 HAL
  516. RDDDI_DX7HAL, // DX7 HAL w/out T&L, with state sets
  517. RDDDI_DX7TLHAL,
  518. RDDDI_DX8HAL,
  519. RDDDI_DX8TLHAL,
  520. RDDDI_FORCE_DWORD = 0xffffffff
  521. } RDDDITYPE;
  522. typedef struct _RRSTATEOVERRIDES
  523. {
  524. DWORD bits[D3DSTATE_OVERRIDE_BIAS >> RRSTATEOVERRIDE_DWORD_SHIFT];
  525. } RRSTATEOVERRIDES;
  526. struct RDHOCoeffs
  527. {
  528. RDHOCoeffs()
  529. {
  530. m_pNumSegs = 0;
  531. for(unsigned i = 0; i < RD_MAX_NUMSTREAMS; m_pData[i++] = 0);
  532. }
  533. ~RDHOCoeffs()
  534. {
  535. delete[] m_pNumSegs;
  536. for(unsigned i = 0; i < RD_MAX_NUMSTREAMS; delete[] m_pData[i++]);
  537. }
  538. RDHOCoeffs& operator=(const RDHOCoeffs &coeffs);
  539. UINT m_Width;
  540. UINT m_Height;
  541. UINT m_Stride;
  542. D3DBASISTYPE m_Basis;
  543. D3DORDERTYPE m_Order;
  544. FLOAT *m_pNumSegs;
  545. BYTE *m_pData[RD_MAX_NUMSTREAMS];
  546. UINT m_DataSize[RD_MAX_NUMSTREAMS];
  547. };
  548. //-----------------------------------------------------------------------------
  549. //
  550. // RefDev - Primary object for reference rasterizer. Each instance
  551. // of this corresponds to a D3D device.
  552. //
  553. // Usage is to instantiate, install RDRenderTarget (and optional RDSurface2D's),
  554. // and set state and draw primitives.
  555. //
  556. //-----------------------------------------------------------------------------
  557. class RefDev : public RDAlloc
  558. {
  559. public:
  560. friend class RDDebugMonitor;
  561. friend class RefRast;
  562. friend class RDPShader;
  563. ///////////////////////////////////////////////////////////////////////////
  564. //
  565. // public interface
  566. //
  567. ///////////////////////////////////////////////////////////////////////////
  568. RefDev( LPDDRAWI_DIRECTDRAW_LCL pDDLcl, DWORD dwInterfaceType,
  569. RDDDITYPE dwDDIType, D3DCAPS8* pCaps8 );
  570. ~RefDev( void );
  571. LPDDRAWI_DIRECTDRAW_LCL GetDDLcl() { return m_pDDLcl; }
  572. // Methods to get embedded objects
  573. RefVP& GetVP() { return m_RefVP; }
  574. RefVM& GetVM() { return m_RefVM; }
  575. RefClipper& GetClipper() { return m_Clipper; }
  576. RefRast& GetRast() { return m_Rast; }
  577. // DDI methods
  578. HRESULT DrawPrimitives2( PUINT8 pUMVtx, UINT16 dwStride, DWORD dwFvf,
  579. DWORD dwNumVertices, LPD3DHAL_DP2COMMAND *ppCmd,
  580. LPDWORD lpdwRStates );
  581. // Dp2 token handling functions
  582. HRESULT Dp2RecRenderStates(DWORD dwFvf, LPD3DHAL_DP2COMMAND pCmd, LPDWORD lpdwRuntimeRStates);
  583. HRESULT Dp2RecTextureStageState(DWORD dwFvf, LPD3DHAL_DP2COMMAND pCmd);
  584. HRESULT Dp2RecViewport(LPD3DHAL_DP2COMMAND pCmd);
  585. HRESULT Dp2RecWRange(LPD3DHAL_DP2COMMAND pCmd);
  586. HRESULT Dp2RecMaterial(LPD3DHAL_DP2COMMAND pCmd);
  587. HRESULT Dp2RecZRange(LPD3DHAL_DP2COMMAND pCmd);
  588. HRESULT Dp2RecSetLight(LPD3DHAL_DP2COMMAND pCmd, LPDWORD pdwStride);
  589. HRESULT Dp2RecCreateLight(LPD3DHAL_DP2COMMAND pCmd);
  590. HRESULT Dp2RecTransform(LPD3DHAL_DP2COMMAND pCmd);
  591. HRESULT Dp2RecExtention(LPD3DHAL_DP2COMMAND pCmd);
  592. HRESULT Dp2RecClipPlane(LPD3DHAL_DP2COMMAND pCmd);
  593. HRESULT Dp2RecSetVertexShader(LPD3DHAL_DP2COMMAND pCmd);
  594. HRESULT Dp2RecSetVertexShaderConsts(DWORD StartReg, DWORD dwCount,
  595. LPDWORD pData);
  596. HRESULT Dp2RecSetPixelShader(LPD3DHAL_DP2COMMAND pCmd);
  597. HRESULT Dp2RecSetPixelShaderConsts(DWORD StartReg, DWORD dwCount,
  598. LPDWORD pData);
  599. HRESULT Dp2RecSetStreamSource(LPD3DHAL_DP2COMMAND pCmd);
  600. HRESULT Dp2RecSetIndices(LPD3DHAL_DP2COMMAND pCmd);
  601. HRESULT Dp2SetRenderStates(DWORD dwFvf, LPD3DHAL_DP2COMMAND pCmd, LPDWORD lpdwRuntimeRStates);
  602. HRESULT Dp2SetTextureStageState(DWORD dwFvf, LPD3DHAL_DP2COMMAND pCmd);
  603. HRESULT Dp2SetViewport(LPD3DHAL_DP2COMMAND pCmd);
  604. HRESULT Dp2SetWRange(LPD3DHAL_DP2COMMAND pCmd);
  605. HRESULT Dp2SetMaterial(LPD3DHAL_DP2COMMAND pCmd);
  606. HRESULT Dp2SetZRange(LPD3DHAL_DP2COMMAND pCmd);
  607. HRESULT Dp2SetLight(LPD3DHAL_DP2COMMAND pCmd, PDWORD pdwStride);
  608. HRESULT Dp2CreateLight(LPD3DHAL_DP2COMMAND pCmd);
  609. HRESULT Dp2SetTransform(LPD3DHAL_DP2COMMAND pCmd);
  610. HRESULT Dp2MultiplyTransform(LPD3DHAL_DP2COMMAND pCmd);
  611. HRESULT Dp2SetExtention(LPD3DHAL_DP2COMMAND pCmd);
  612. HRESULT Dp2SetRenderTarget(LPD3DHAL_DP2COMMAND pCmd);
  613. HRESULT Dp2SetClipPlane(LPD3DHAL_DP2COMMAND pCmd);
  614. HRESULT Dp2DrawPrimitive(LPD3DHAL_DP2COMMAND pCmd);
  615. HRESULT Dp2DrawPrimitive2(LPD3DHAL_DP2COMMAND pCmd);
  616. HRESULT Dp2DrawIndexedPrimitive(LPD3DHAL_DP2COMMAND pCmd);
  617. HRESULT Dp2DrawIndexedPrimitive2(LPD3DHAL_DP2COMMAND pCmd);
  618. HRESULT Dp2DrawClippedTriFan(LPD3DHAL_DP2COMMAND pCmd);
  619. HRESULT Dp2CreateVertexShader(DWORD handle,
  620. DWORD dwDeclSize, LPDWORD pDecl,
  621. DWORD dwCodeSize, LPDWORD pCode);
  622. HRESULT Dp2DeleteVertexShader(LPD3DHAL_DP2COMMAND pCmd);
  623. HRESULT Dp2SetVertexShader(LPD3DHAL_DP2COMMAND pCmd);
  624. HRESULT Dp2SetVertexShaderConsts(DWORD StartReg, DWORD dwCount,
  625. LPDWORD pData);
  626. HRESULT Dp2SetStreamSource(LPD3DHAL_DP2COMMAND pCmd);
  627. HRESULT Dp2SetStreamSourceUM(LPD3DHAL_DP2COMMAND pCmd, PUINT8 pUMVtx );
  628. HRESULT Dp2SetIndices(LPD3DHAL_DP2COMMAND pCmd);
  629. HRESULT Dp2CreatePixelShader(DWORD handle,
  630. DWORD dwCodeSize, LPDWORD pCode);
  631. HRESULT Dp2DeletePixelShader(LPD3DHAL_DP2COMMAND pCmd);
  632. HRESULT Dp2SetPixelShader(LPD3DHAL_DP2COMMAND pCmd);
  633. HRESULT Dp2SetPixelShaderConsts(DWORD StartReg, DWORD dwCount,
  634. LPDWORD pData);
  635. HRESULT Dp2SetPalette(LPD3DHAL_DP2COMMAND pCmd);
  636. HRESULT Dp2UpdatePalette(LPD3DHAL_DP2UPDATEPALETTE pUP,
  637. PALETTEENTRY *pEntries);
  638. HRESULT Dp2SetTexLod(LPD3DHAL_DP2COMMAND pCmd);
  639. // StateSet related functions
  640. void SetRecStateFunctions(void);
  641. void SetSetStateFunctions(void);
  642. HRESULT BeginStateSet(DWORD dwHandle);
  643. HRESULT EndStateSet(void);
  644. HRESULT ExecuteStateSet(DWORD dwHandle);
  645. HRESULT DeleteStateSet(DWORD dwHandle);
  646. HRESULT CaptureStateSet(DWORD dwHandle);
  647. HRESULT CreateStateSet(DWORD dwHandle, D3DSTATEBLOCKTYPE sbType);
  648. HRESULT RecordAllState( DWORD dwHandle );
  649. HRESULT RecordVertexState( DWORD dwHandle );
  650. HRESULT RecordPixelState( DWORD dwHandle );
  651. HRESULT RecordStates(PUINT8 pData, DWORD dwSize);
  652. HRESULT RecordLastState(LPD3DHAL_DP2COMMAND pCmd, DWORD dwUnitSize);
  653. LPRD_STATESETFUNCTIONTBL pStateSetFuncTbl;
  654. // Interface style
  655. BOOL IsInterfaceDX6AndBefore() {return (m_dwInterfaceType <= 2);}
  656. BOOL IsInterfaceDX7AndBefore() {return (m_dwInterfaceType <= 3);}
  657. // DriverStyle
  658. BOOL IsDriverDX6AndBefore()
  659. {
  660. return ((m_dwDDIType <= RDDDI_DP2HAL) && (m_dwDDIType > 0));
  661. }
  662. BOOL IsDriverDX7AndBefore()
  663. {
  664. return ((m_dwDDIType <= RDDDI_DX7TLHAL) && (m_dwDDIType > 0));
  665. }
  666. RDDDITYPE GetDDIType()
  667. {
  668. return m_dwDDIType;
  669. }
  670. // Last Pixel State
  671. void StoreLastPixelState(BOOL bStore);
  672. // RenderTarget control
  673. void SetRenderTarget( RDRenderTarget* pRenderTarget );
  674. RDRenderTarget* GetRenderTarget( void );
  675. // state management functions
  676. void SetRenderState( DWORD dwState, DWORD dwValue );
  677. void SetTextureStageState( DWORD dwStage, DWORD dwStageState, DWORD dwValue );
  678. void SceneCapture( DWORD dwFlags );
  679. // texture management functions
  680. BOOL TextureCreate ( LPD3DTEXTUREHANDLE phTex, RDSurface2D** ppTexture );
  681. BOOL TextureDestroy ( D3DTEXTUREHANDLE hTex );
  682. DWORD TextureGetSurf( D3DTEXTUREHANDLE hTex );
  683. // rendering functions
  684. HRESULT Clear(LPD3DHAL_DP2COMMAND pCmd);
  685. HRESULT BeginRendering( void );
  686. HRESULT EndRendering( void );
  687. HRESULT UpdateRastState( void );
  688. DWORD m_dwRastFlags; // rasterizer-core specific flags
  689. #define RDRF_MULTISAMPLE_CHANGED (1L<<0)
  690. #define RDRF_PIXELSHADER_CHANGED (1L<<1)
  691. #define RDRF_LEGACYPIXELSHADER_CHANGED (1L<<2)
  692. #define RDRF_TEXTURESTAGESTATE_CHANGED (1L<<3)
  693. // Method to convert FVF vertices into the internal RDVertex. Used for
  694. // TLVertex rendering and legacy driver models.
  695. void FvfToRDVertex( PUINT8 pVtx, GArrayT<RDVertex>& dstArray, DWORD dwFvf,
  696. DWORD dwStride, UINT cVertices );
  697. // Rasterizer functions
  698. void DrawPoint( RDVertex* pvV0 );
  699. void DrawLine( RDVertex* pvV0, RDVertex* pvV1, RDVertex* pvVFlat = NULL );
  700. void DrawTriangle( RDVertex* pvV0, RDVertex* pvV1, RDVertex* pvV2,
  701. WORD wFlags = D3DTRIFLAG_EDGEENABLETRIANGLE );
  702. HRESULT DrawOnePrimitive( GArrayT<RDVertex>& VtxArray,
  703. DWORD dwStartVertex,
  704. D3DPRIMITIVETYPE PrimType,
  705. UINT cVertices );
  706. HRESULT DrawOneIndexedPrimitive( GArrayT<RDVertex>& VtxArray,
  707. int StartVertexIndex,
  708. LPWORD pIndices,
  709. DWORD StartIndex,
  710. UINT cIndices,
  711. D3DPRIMITIVETYPE PrimType );
  712. HRESULT DrawOneIndexedPrimitive( GArrayT<RDVertex>& VtxArray,
  713. int StartVertexIndex,
  714. LPDWORD pIndices,
  715. DWORD StartIndex,
  716. UINT cIndices,
  717. D3DPRIMITIVETYPE PrimType );
  718. HRESULT DrawOneEdgeFlagTriangleFan( GArrayT<RDVertex>& VtxArray,
  719. UINT cVertices,
  720. UINT32 dwEdgeFlags );
  721. //
  722. // these are used to facilitate the way refdev is used in the D3D runtime
  723. //
  724. // functions to manipulate current set of texture
  725. int GetCurrentTextureMaps( D3DTEXTUREHANDLE* phTex, RDSurface2D** pTex );
  726. BOOL SetTextureMap( D3DTEXTUREHANDLE hTex, RDSurface2D* pTex );
  727. //
  728. // T&L Hal specific functions
  729. //
  730. HRESULT ProcessPrimitive( D3DPRIMITIVETYPE primType,
  731. DWORD dwStartVertex,// Index of the start vertex
  732. DWORD cVertices,
  733. DWORD dwStartIndex,
  734. DWORD cIndices );
  735. HRESULT ProcessPrimitiveVVM( D3DPRIMITIVETYPE primType,
  736. DWORD dwStartVertex,
  737. DWORD cVertices,
  738. DWORD dwStartIndex,
  739. DWORD cIndices );
  740. HRESULT ProcessBSpline( DWORD dwOffW, DWORD dwOffH,
  741. DWORD dwWidth, DWORD dwHeight,
  742. DWORD dwStride, DWORD order,
  743. FLOAT *pPrimSegments);
  744. HRESULT ProcessBezier ( DWORD dwOffW, DWORD dwOffH,
  745. DWORD dwWidth, DWORD dwHeight,
  746. DWORD dwStride, DWORD order,
  747. FLOAT *pPrimSegments,
  748. bool bDegenerate );
  749. HRESULT ProcessCatRomSpline ( DWORD dwOffW, DWORD dwOffH,
  750. DWORD dwWidth, DWORD dwHeight,
  751. DWORD dwStride,
  752. FLOAT *pPrimSegments);
  753. HRESULT ProcessTessPrimitive( LPD3DHAL_DP2DRAWPRIMITIVE pDP );
  754. HRESULT ProcessTessIndexedPrimitive( LPD3DHAL_DP2DRAWINDEXEDPRIMITIVE pDP );
  755. HRESULT DrawTessQuad( const RDBSpline &Surf, DWORD dwOffW, DWORD dwOffH, DWORD dwStride,
  756. const unsigned *m, const unsigned *n,
  757. double u0, double v0, double u1, double v1,
  758. double tu0, double tv0, double tu1, double tv1,
  759. bool bDegenerate );
  760. HRESULT DrawTessTri( const RDBSpline &Surf, DWORD dwOffW, DWORD dwOffH, DWORD dwStride,
  761. const unsigned *m, const unsigned *n,
  762. double u0, double v0, double u1, double v1, double u2, double v2,
  763. double tu0, double tv0, double tu1, double tv1, double tu2, double tv2,
  764. bool bDegenerate0, bool bDegenerate1, bool bDegenerate2 );
  765. HRESULT DrawNPatch( const RDNPatch &Patch, DWORD dwStride,
  766. const unsigned *m, const unsigned *n, unsigned segs );
  767. HRESULT ConvertLinearTriBezierToRectBezier(DWORD dwDataType, const BYTE *B, DWORD dwStride, BYTE *Q);
  768. HRESULT ConvertCubicTriBezierToRectBezier(DWORD dwDataType, const BYTE *B, DWORD dwStride, BYTE *Q);
  769. HRESULT ConvertQuinticTriBezierToRectBezier(DWORD dwDataType, const BYTE *B, DWORD dwStride, BYTE *Q);
  770. HRESULT SetupStrides();
  771. HRESULT UpdateTLState();
  772. HRESULT UpdateClipper();
  773. HRESULT DrawDX8Prim( LPD3DHAL_DP2DRAWPRIMITIVE pDP );
  774. HRESULT DrawDX8Prim2( LPD3DHAL_DP2DRAWPRIMITIVE2 pDP );
  775. HRESULT DrawRectPatch( LPD3DHAL_DP2DRAWRECTPATCH pDP );
  776. HRESULT DrawTriPatch( LPD3DHAL_DP2DRAWTRIPATCH pDP );
  777. HRESULT DrawDX8IndexedPrim( LPD3DHAL_DP2DRAWINDEXEDPRIMITIVE pDIP );
  778. HRESULT DrawDX8IndexedPrim2( LPD3DHAL_DP2DRAWINDEXEDPRIMITIVE2 pDIP );
  779. HRESULT DrawDX8ClippedTriFan( LPD3DHAL_CLIPPEDTRIANGLEFAN pDIP );
  780. inline RDVStream& GetVStream( DWORD index )
  781. {
  782. return m_VStream[index];
  783. }
  784. inline HRESULT GrowTLVArray( DWORD dwNumVerts )
  785. {
  786. return m_TLVArray.Grow( dwNumVerts );
  787. }
  788. inline GArrayT<RDVertex>& GetTLVArray()
  789. {
  790. return m_TLVArray;
  791. }
  792. private:
  793. ///////////////////////////////////////////////////////////////////////////
  794. //
  795. // internal state and methods
  796. //
  797. ///////////////////////////////////////////////////////////////////////////
  798. //-------------------------------------------------------------------------
  799. // Embedded Objects
  800. //-------------------------------------------------------------------------
  801. RefVP m_RefVP; // The fixed function T&L object
  802. RefVM m_RefVM; // The programmable vertex machine object
  803. RefClipper m_Clipper; // Clipper object
  804. RefRast m_Rast; // Rasterizer object
  805. //-------------------------------------------------------------------------
  806. // state
  807. //-------------------------------------------------------------------------
  808. // Caps struct, potentially modified from static caps settings. Ref code
  809. // will behave according to settings of some of the caps in this struct.
  810. D3DCAPS8 m_Caps8;
  811. // DDraw Local, needed for the new texture handles from DX7 onwards
  812. LPDDRAWI_DIRECTDRAW_LCL m_pDDLcl;
  813. // This is obtained from CONTEXTCREATE->ddrval, indicates
  814. // what kind of emulation (DX3, DX5, DX6 or DX7) the driver should do.
  815. RDDDITYPE m_dwDDIType;
  816. // This is obtained from CONTEXTCREATE->dwhContext, indicates
  817. // which D3D Device interface called the driver.
  818. DWORD m_dwInterfaceType;
  819. // save area for floating point unit control
  820. WORD m_wSaveFP;
  821. // TRUE if in begin/end primitive sequence
  822. BOOL m_bInBegin;
  823. // TRUE if in rendering point sprite triangles
  824. BOOL m_bPointSprite;
  825. // render target (color & Z buffer)
  826. RDRenderTarget* m_pRenderTarget;
  827. FLOAT m_fWBufferNorm[2]; // { Wnear, 1/(Wfar-Wnear) } to normalize W buffer value
  828. // D3D renderstate
  829. union
  830. {
  831. DWORD m_dwRenderState[D3DHAL_MAX_RSTATES];
  832. FLOAT m_fRenderState[D3DHAL_MAX_RSTATES];
  833. };
  834. // State Override flags
  835. RRSTATEOVERRIDES m_renderstate_override;
  836. // Palette handles
  837. GArrayT<RDPaletteHandle> m_PaletteHandleArray;
  838. // texture state - per-stage state and pointer to associated texture
  839. int m_cActiveTextureStages; // count of active texture stages (range 0..D3DHAL_TSS_MAXSTAGES)
  840. DWORD m_ReferencedTexCoordMask; // which texture coordinate sets are referenced
  841. RDSurface2D* m_pTexture[D3DHAL_TSS_MAXSTAGES]; // texture maps associated with texture stages
  842. union
  843. {
  844. DWORD m_dwTextureStageState[D3DHAL_TSS_MAXSTAGES][D3DTSS_MAX]; // state array (unsigned)
  845. FLOAT m_fTextureStageState[D3DHAL_TSS_MAXSTAGES][D3DTSS_MAX]; // state array (float)
  846. RDTextureStageState m_TextureStageState[D3DHAL_TSS_MAXSTAGES];
  847. };
  848. DWORD* m_pTextureStageState[D3DHAL_TSS_MAXSTAGES]; // to speed GetTSS
  849. BOOL m_bOverrideTCI;
  850. DWORD m_dwTexArrayLength;
  851. // Vertex and Index streams
  852. // The extra VStream is for the Tesselator generated data.
  853. RDVStream m_VStream[RD_MAX_NUMSTREAMS + 1];
  854. RDIStream m_IndexStream;
  855. // Buffer to store transformed vertices
  856. GArrayT<RDVertex> m_TLVArray;
  857. // Vertex shader state
  858. GArrayT<RDVShaderHandle> m_VShaderHandleArray;
  859. RDVShader m_FVFShader; // Declaration for the legacy (FVF)
  860. // shader
  861. DWORD m_CurrentVShaderHandle;
  862. RDVShader* m_pCurrentVShader;
  863. UINT64 m_qwFVFOut; // Desired FVF for the output
  864. // vertices
  865. // Coefficient storage for HOS
  866. GArrayT<RDHOCoeffs> m_HOSCoeffs;
  867. // Primitive information
  868. D3DPRIMITIVETYPE m_primType; // Current primitive being drawn
  869. DWORD m_dwNumVertices; // Number of vertices to process
  870. DWORD m_dwStartVertex;
  871. DWORD m_dwNumIndices;
  872. DWORD m_dwStartIndex;
  873. // Last state
  874. DWORD m_LastState;
  875. // Array of StateSets, which are in turn implemented with TemplArray as
  876. // TemplArray<UINT8> StateSetData
  877. TemplArray<LPStateSetData> m_pStateSets;
  878. // pixel shader state
  879. DWORD m_CurrentPShaderHandle;
  880. GArrayT<RDPShaderHandle> m_PShaderHandleArray;
  881. // Buffer used to process clear rects
  882. GArrayT<BYTE> m_ClearRectBuffer;
  883. //-------------------------------------------------------------------------
  884. // methods
  885. //-------------------------------------------------------------------------
  886. // refrasti.cpp
  887. HRESULT GrowTexArray( DWORD dwHandle );
  888. HRESULT SetTextureHandle( int iStage, DWORD dwHandle );
  889. void MapTextureHandleToDevice( int iStage );
  890. void UpdateActiveTexStageCount( void );
  891. RDSurface2D* MapHandleToTexture( D3DTEXTUREHANDLE hTex );
  892. // MapLegcy.cpp
  893. void MapLegacyTextureBlend( void );
  894. void MapLegacyTextureFilter( void );
  895. // primfns.cpp
  896. HRESULT GrowLightArray(const DWORD dwIndex);
  897. // pixel shader handle manipulation
  898. inline RDPShader* GetPShader( DWORD dwHandle )
  899. {
  900. if( m_PShaderHandleArray.IsValidIndex( dwHandle ) )
  901. return m_PShaderHandleArray[dwHandle].m_pShader;
  902. return NULL;
  903. }
  904. // drawgrid.cpp
  905. HRESULT LinkTessellatorOutput();
  906. HRESULT LinkCachedTessellatorOutput(DWORD Handle, BYTE **pTempData);
  907. void UnlinkTessellatorOutput();
  908. void UnlinkCachedTessellatorOutput(BYTE **pTempData);
  909. public:
  910. ///////////////////////////////////////////////////////////////////////////
  911. //
  912. // methods used by refdev objects to get at device state
  913. //
  914. ///////////////////////////////////////////////////////////////////////////
  915. inline DWORD* GetRS( void ) { return m_dwRenderState; }
  916. inline FLOAT* GetRSf( void ) { return m_fRenderState; }
  917. inline DWORD* GetTSS( DWORD Stage ) { return m_pTextureStageState[Stage]; }
  918. inline FLOAT* GetTSSf( DWORD Stage ) { return (FLOAT*)m_pTextureStageState[Stage]; }
  919. inline BOOL ColorKeyEnabled( void )
  920. {
  921. return
  922. m_dwRenderState[D3DRENDERSTATE_COLORKEYENABLE] ||
  923. m_dwRenderState[D3DRENDERSTATE_COLORKEYBLENDENABLE];
  924. }
  925. inline D3DCAPS8* GetCaps8( void ) { return &m_Caps8; }
  926. };
  927. //-------------------------------------------------------------------------
  928. // DXTn compressed texture formats
  929. //-------------------------------------------------------------------------
  930. // number of DXT compression formats
  931. #define NUM_DXT_FORMATS 5
  932. // number of pixels in block
  933. #define DXT_BLOCK_PIXELS 16
  934. // DXT block size array
  935. extern int g_DXTBlkSize[];
  936. typedef struct {
  937. BYTE rgba[4];
  938. } DXT_COLOR;
  939. typedef WORD RGB565; // packed color
  940. typedef DWORD PIXBM; // 2 BPP bitmap
  941. typedef struct {
  942. RGB565 rgb0; // color for index 0
  943. RGB565 rgb1; // color for index 1
  944. PIXBM pixbm; // pixel bitmap
  945. } DXTBlockRGB;
  946. typedef struct {
  947. WORD alphabm[4]; // alpha bitmap at 4 BPP
  948. DXTBlockRGB rgb; // color block
  949. } DXTBlockAlpha4;
  950. typedef struct {
  951. BYTE alpha0; // alpha for index 0
  952. BYTE alpha1; // alpha for index 1
  953. BYTE alphabm[6]; // alpha bitmap at 3 BPP
  954. DXTBlockRGB rgb; // color block
  955. } DXTBlockAlpha3;
  956. void DecodeBlockRGB (DXTBlockRGB *pblockSrc,
  957. DXT_COLOR colorDst[DXT_BLOCK_PIXELS]);
  958. void DecodeBlockAlpha4(DXTBlockAlpha4 *pblockSrc,
  959. DXT_COLOR colorDst[DXT_BLOCK_PIXELS]);
  960. void DecodeBlockAlpha3(DXTBlockAlpha3 *pblockSrc,
  961. DXT_COLOR colorDst[DXT_BLOCK_PIXELS]);
  962. ///////////////////////////////////////////////////////////////////////////////
  963. #endif // _REFDEV_HPP