Source code of Windows XP (NT5)
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.

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