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.

233 lines
8.2 KiB

  1. /******************************Module*Header*********************************\
  2. *
  3. * *******************
  4. * * D3D SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: d3dcntxt.h
  8. *
  9. * Content: D3D Context management related definitions and macros
  10. *
  11. * Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #ifdef __DCONTEXT
  15. #pragma message ("FILE : "__FILE__" : Multiple inclusion")
  16. #endif
  17. #define __DCONTEXT
  18. #ifndef __SOFTCOPY
  19. #include "d3dsoft.h"
  20. #endif
  21. #ifndef __TEXTURES
  22. #include "d3dtext.h"
  23. #endif
  24. //-----------------------------------------------------------------------------
  25. // Context indexing structure
  26. //-----------------------------------------------------------------------------
  27. #define MAX_CONTEXT_NUM 200
  28. extern UINT_PTR ContextSlots[];
  29. //-----------------------------------------------------------------------------
  30. // Context validation macros
  31. //-----------------------------------------------------------------------------
  32. #define RC_MAGIC_DISABLE 0xd3d00000
  33. #define RC_MAGIC_NO 0xd3d00100
  34. #define IS_D3DCONTEXT_VALID(ptr) \
  35. ( ((ptr) != NULL) && ((ptr)->Hdr.MagicNo == RC_MAGIC_NO) )
  36. #define CHK_CONTEXT(pCtxt, retVar, funcname) \
  37. if (!IS_D3DCONTEXT_VALID(pCtxt)) { \
  38. retVar = D3DHAL_CONTEXT_BAD; \
  39. DBG_D3D((0,"Context not valid in %s",funcname)); \
  40. return (DDHAL_DRIVER_HANDLED); \
  41. }
  42. // Defines for the dwDirtyFlags field of our context
  43. #define CONTEXT_DIRTY_ALPHABLEND 2
  44. #define CONTEXT_DIRTY_ZBUFFER 4
  45. #define CONTEXT_DIRTY_TEXTURE 8
  46. #define CONTEXT_DIRTY_MULTITEXTURE 16
  47. #define DIRTY_ALPHABLEND pContext->dwDirtyFlags |= CONTEXT_DIRTY_ALPHABLEND;
  48. #define DIRTY_TEXTURE pContext->dwDirtyFlags |= CONTEXT_DIRTY_TEXTURE;
  49. #define DIRTY_ZBUFFER pContext->dwDirtyFlags |= CONTEXT_DIRTY_ZBUFFER;
  50. #define DIRTY_MULTITEXTURE pContext->dwDirtyFlags |= CONTEXT_DIRTY_MULTITEXTURE;
  51. //-----------------------------------------------------------------------------
  52. // Context rendering state tracking
  53. //-----------------------------------------------------------------------------
  54. // Flags to keep track of various rendering states or conditions in a D3D context
  55. // these are tracked in the Hdr.Flags field
  56. #define CTXT_HAS_GOURAUD_ENABLED (1 << 0)
  57. #define CTXT_HAS_ZBUFFER_ENABLED (1 << 1)
  58. #define CTXT_HAS_SPECULAR_ENABLED (1 << 2)
  59. #define CTXT_HAS_FOGGING_ENABLED (1 << 3)
  60. #define CTXT_HAS_PERSPECTIVE_ENABLED (1 << 4)
  61. #define CTXT_HAS_TEXTURE_ENABLED (1 << 5)
  62. #define CTXT_HAS_ALPHABLEND_ENABLED (1 << 6)
  63. #define CTXT_HAS_MONO_ENABLED (1 << 7)
  64. #define CTXT_HAS_WRAPU_ENABLED (1 << 8)
  65. #define CTXT_HAS_WRAPV_ENABLED (1 << 9)
  66. // Use the alpha value to calculate a stipple pattern
  67. #define CTXT_HAS_ALPHASTIPPLE_ENABLED (1 << 10)
  68. #define CTXT_HAS_ZWRITE_ENABLED (1 << 11)
  69. // Enable last point on lines
  70. #define CTXT_HAS_LASTPIXEL_ENABLED (1 << 12)
  71. #if D3D_STATEBLOCKS
  72. //-----------------------------------------------------------------------------
  73. // State sets structure definitions
  74. //-----------------------------------------------------------------------------
  75. #define FLAG DWORD
  76. #define FLAG_SIZE (8*sizeof(DWORD))
  77. typedef struct _P2StateSetRec {
  78. DWORD dwHandle;
  79. DWORD bCompressed;
  80. union {
  81. struct {
  82. // Stored state block info (uncompressed)
  83. DWORD RenderStates[MAX_STATE];
  84. DWORD TssStates[D3DTSS_TEXTURETRANSFORMFLAGS+1];
  85. FLAG bStoredRS[(MAX_STATE + FLAG_SIZE)/ FLAG_SIZE];
  86. FLAG bStoredTSS[(D3DTSS_TEXTURETRANSFORMFLAGS + FLAG_SIZE) / FLAG_SIZE];
  87. } uc;
  88. struct {
  89. // Stored state block info (compressed)
  90. DWORD dwNumRS;
  91. DWORD dwNumTSS;
  92. struct {
  93. DWORD dwType;
  94. DWORD dwValue;
  95. } pair[1];
  96. } cc;
  97. } u;
  98. } P2StateSetRec;
  99. #define SSPTRS_PERPAGE (4096/sizeof(P2StateSetRec *))
  100. #define FLAG_SET(flag, number) \
  101. flag[ (number) / FLAG_SIZE ] |= (1 << ((number) % FLAG_SIZE))
  102. #define IS_FLAG_SET(flag, number) \
  103. (flag[ (number) / FLAG_SIZE ] & (1 << ((number) % FLAG_SIZE) ))
  104. #endif //D3D_STATEBLOCKS
  105. //-----------------------------------------------------------------------------
  106. // Context structure definitions
  107. //-----------------------------------------------------------------------------
  108. typedef struct _D3DContextHeader {
  109. unsigned long MagicNo; // Magic number to verify validity of pointer
  110. UINT_PTR pSelf; // 32 Bit pointer to this structure
  111. unsigned long Flags;
  112. unsigned long FillMode;
  113. // Software copy of Registers for permedia
  114. __P2RegsSoftwareCopy SoftCopyP2Regs;
  115. } D3DCONTEXTHEADER;
  116. typedef struct _TextureCacheManager *PTextureCacheManager;
  117. typedef struct _permedia_d3dcontext {
  118. // The magic number MUST come at the start of the structure
  119. D3DCONTEXTHEADER Hdr;
  120. // Stored surface info
  121. UINT_PTR RenderSurfaceHandle;
  122. UINT_PTR ZBufferHandle;
  123. ULONG ulPackedPP;
  124. // handle on Permedia register state context
  125. P2CtxtPtr hPermediaContext;
  126. PPDev ppdev; // The card we are running on.
  127. BOOL bCanChromaKey;
  128. // Stippling state
  129. BOOL bKeptStipple;
  130. DWORD LastAlpha;
  131. BYTE CurrentStipple[8];
  132. DWORD RenderCommand;
  133. DWORD RenderStates[MAX_STATE];
  134. DWORD TssStates[D3DTSS_TEXTURETRANSFORMFLAGS+1]; // D3D DX6 TSS States
  135. DWORD dwWrap[8]; // D3D DX6 Wrap flags
  136. DWORD dwDirtyFlags;
  137. // Texture filtering modes
  138. BOOL bMagFilter; // Filter the magnified textures
  139. BOOL bMinFilter; // Filter the minified textures
  140. // Misc. state
  141. D3DCULL CullMode;
  142. DWORD FakeBlendNum;
  143. D3DStateSet overrides; // To overide states in rendering
  144. // Texture data & sizes (for Permedia setup) of our CurrentTextureHandle
  145. FLOAT DeltaHeightScale;
  146. FLOAT DeltaWidthScale;
  147. DWORD MaxTextureXi;
  148. FLOAT MaxTextureXf;
  149. DWORD MaxTextureYi;
  150. FLOAT MaxTextureYf;
  151. DWORD CurrentTextureHandle;
  152. //@@BEGIN_DDKSPLIT
  153. #if D3D_POINTSPRITES
  154. // Point sprite support
  155. BOOL bPointSpriteEnabled;
  156. FLOAT fPointSize;
  157. #endif // D3D_POINTSPRITES
  158. //@@END_DDKSPLIT
  159. #if D3D_STATEBLOCKS
  160. BOOL bStateRecMode; // Toggle for executing or recording states
  161. P2StateSetRec *pCurrSS; // Ptr to SS currently being recorded
  162. P2StateSetRec **pIndexTableSS; // Pointer to table of indexes
  163. DWORD dwMaxSSIndex; // size of table of indexes
  164. #endif
  165. DWORD PixelOffset; // Offset in pixels to start of the rendering buffer
  166. DWORD LowerChromaColor; // Last lower bound chroma key for this context
  167. DWORD UpperChromaColor; // Last upper bound chroma key for this context
  168. PTextureCacheManager pTextureManager;
  169. LPDWLIST pHandleList;
  170. LPVOID pDDLcl; // Local surface pointer used as a ID
  171. } PERMEDIA_D3DCONTEXT ;
  172. //-----------------------------------------------------------------------------
  173. // Context switching
  174. //-----------------------------------------------------------------------------
  175. // Code to do a context switch. If we aren't DMAing we need to resend the
  176. // registers on each context switch to work around the Permedia bug. In the
  177. // DMA case, these registers will be inserted at the start of the buffer.
  178. #define SET_CURRENT_D3D_CONTEXT(ctxt) \
  179. if(ctxt != ppdev->permediaInfo->pCurrentCtxt) \
  180. { \
  181. P2SwitchContext(ppdev, ctxt); \
  182. }
  183. HRESULT
  184. SetupPermediaRenderTarget(PERMEDIA_D3DCONTEXT* pContext);