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.

268 lines
12 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * D3D SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: d3dtext.h
  8. *
  9. * Content: D3D Texture 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 __TEXTURES
  15. #pragma message ("FILE : "__FILE__" : Multiple Inclusion");
  16. #endif
  17. #define __TEXTURES
  18. //-----------------------------------------------------------------------------
  19. // Texture validation macros
  20. //-----------------------------------------------------------------------------
  21. #define TC_MAGIC_DISABLE 0xd3d10000
  22. #define TC_MAGIC_NO 0xd3d10100
  23. #define CHECK_D3DSURFACE_VALIDITY(ptr) \
  24. ((ptr) != NULL && (ptr)->MagicNo == TC_MAGIC_NO)
  25. #define CHECK_TEXTURESTRUCT_VALIDITY(ptr) \
  26. ( ((ptr) != NULL) && \
  27. ( ((ptr)->MagicNo == TC_MAGIC_NO) || \
  28. ((ptr)->MagicNo == TC_MAGIC_DISABLE) ) \
  29. )
  30. //-----------------------------------------------------------------------------
  31. // Texture structure definitions
  32. //-----------------------------------------------------------------------------
  33. // We only handle one single mipmap on this sample driver since the P2 doesn't
  34. // natively support them
  35. #if D3D_MIPMAPPING
  36. #define MAX_MIP_LEVELS 12
  37. #else
  38. #define MAX_MIP_LEVELS 1
  39. #endif // D3D_MIPMAPPING
  40. // stores information needed to quickly setup a mipmap level on
  41. // the chip. At the moment this is Partial Products and widths/heights
  42. typedef struct tagMIPTEXTURE {
  43. // Widths and heights for this mip level
  44. INT logWidth;
  45. INT logHeight;
  46. // Partial products for this mip level
  47. ULONG ulPackedPP;
  48. // Offset in pixels to start of the texture
  49. // for the current miplevel
  50. DWORD PixelOffset;
  51. } MIPTEXTURE;
  52. typedef struct _permedia_d3dtexture
  53. {
  54. // Magic number to verify validity of pointer
  55. ULONG MagicNo ;
  56. // the following four memebers are exact replicates
  57. // of those in DDRAWI_DDRAWSURFACE_GBL
  58. DWORD dwCaps;
  59. DWORD dwCaps2;
  60. FLATPTR fpVidMem; // pointer to video memory
  61. LONG lPitch; // pitch of surface
  62. DWORD dwRGBBitCount;
  63. UINT_PTR lSurfaceOffset;
  64. // Width and Height of texture
  65. WORD wWidth;
  66. WORD wHeight;
  67. // The AGP that the last texture came from
  68. DWORD dwGARTDevLast;
  69. BOOL bMipMap;
  70. DWORD m_dwBytes;
  71. DWORD m_dwPriority;
  72. DWORD m_dwTicks;
  73. DWORD m_dwHeapIndex;
  74. ULONG HandleListIndex; // indicating which list it's with
  75. // For setting up MipMaps
  76. MIPTEXTURE MipLevels[MAX_MIP_LEVELS];
  77. DWORD dwFlags;
  78. DWORD dwKeyLow;
  79. DWORD dwKeyHigh;
  80. PermediaSurfaceData* pTextureSurface;
  81. DWORD dwPaletteHandle;
  82. // The number of mipmap levels this texture should have
  83. int iMipLevels;
  84. } PERMEDIA_D3DTEXTURE, *PPERMEDIA_D3DTEXTURE;
  85. //-----------------------------------------------------------------------------
  86. // DX7 Texture management definitions
  87. //-----------------------------------------------------------------------------
  88. typedef struct _permedia_d3dpalette
  89. {
  90. DWORD dwFlags;
  91. WORD wStartIndex;
  92. WORD wNumEntries;
  93. PALETTEENTRY ColorTable[256]; // array of palette entries, could be dynamic later
  94. } PERMEDIA_D3DPALETTE, *PPERMEDIA_D3DPALETTE;
  95. #define LISTGROWSIZE 1024
  96. typedef struct _DWLIST
  97. {
  98. PPERMEDIA_D3DTEXTURE *dwSurfaceList; // array to hold handles,
  99. // dynamically allocated
  100. // dwSurfaceList[0] is the number
  101. // of entries in dwSurfaceList
  102. // if allocated
  103. PPERMEDIA_D3DPALETTE *dwPaletteList; // array to hold handles,
  104. // dynamically allocated
  105. // dwPaletteList[0] is the number
  106. // of entries in dwPaletteList
  107. // if allocated
  108. LPVOID pDDLcl; // owning ddraw pointer as a key
  109. } DWLIST;
  110. typedef DWLIST FAR* LPDWLIST;
  111. extern DWLIST HandleList[];
  112. extern LPDWLIST GetSurfaceHandleList(LPVOID);
  113. void ReleaseSurfaceHandleList(LPVOID);
  114. PERMEDIA_D3DPALETTE *PaletteHandleToPtr(UINT_PTR phandle,
  115. PERMEDIA_D3DCONTEXT* pContext);
  116. //-----------------------------------------------------------------------------
  117. // Texture debugging
  118. //-----------------------------------------------------------------------------
  119. // Tracing/Debugging functions
  120. void DumpTexture(PPDev ppdev,
  121. PERMEDIA_D3DTEXTURE* pTexture,
  122. DDPIXELFORMAT* pPixelFormat);
  123. #ifdef DBG
  124. #define DISPTEXTURE(arg) DumpTexture arg
  125. #else
  126. #define DISPTEXTURE(arg)
  127. #endif
  128. //-----------------------------------------------------------------------------
  129. // Texture hash table definitions
  130. //-----------------------------------------------------------------------------
  131. #define TEXTURE_HASH_SIZE 256 // these many entries in the hash table
  132. void InitTextureHashTable(PERMEDIA_D3DCONTEXT *pContext);
  133. // Then the hash funtion is just an 'and'
  134. #define TEXTURE_HASH_OF(i) ((i) & 0xff)
  135. PERMEDIA_D3DTEXTURE *TextureHandleToPtr(UINT_PTR thandle,
  136. PERMEDIA_D3DCONTEXT* pContext);
  137. void StorePermediaLODLevel(PPDev ppdev,
  138. PERMEDIA_D3DTEXTURE* pTexture,
  139. LPDDRAWI_DDRAWSURFACE_LCL pSurf,
  140. int LOD);
  141. //-----------------------------------------------------------------------------
  142. // Texture coordinate wrapping macros
  143. //-----------------------------------------------------------------------------
  144. #define FLUSH_DUE_TO_WRAP(par)
  145. #define DONT_FLUSH_DUE_TO_WRAP(par)
  146. #define WRAP(par, wrapit) if(wrapit) { \
  147. float elp; \
  148. float erp; \
  149. float emp; \
  150. elp = (float)fabs(par##1 - par##0); \
  151. erp = (float)fabs(par##2 - par##1); \
  152. emp = (float)fabs(par##0 - par##2); \
  153. if( (elp > (float)0.5) && (erp > (float)0.5) ) \
  154. { \
  155. if (par##1 < par##2) { par##1 += 1.0; } \
  156. else { par##2 += 1.0; par##0 += 1.0; } \
  157. FLUSH_DUE_TO_WRAP(par); \
  158. } \
  159. else if( (erp > (float)0.5) && (emp > (float)0.5) ) \
  160. { \
  161. if (par##2 < par##0) { par##2 += 1.0; } \
  162. else { par##0 += 1.0; par##1 += 1.0; } \
  163. FLUSH_DUE_TO_WRAP(par); \
  164. } \
  165. else if( (emp > (float)0.5) && (elp > (float)0.5) ) \
  166. { \
  167. if(par##0 < par##1) { par##0 += 1.0; } \
  168. else { par##1 += 1.0; par##2 += 1.0; } \
  169. FLUSH_DUE_TO_WRAP(par); \
  170. } \
  171. else \
  172. { \
  173. DONT_FLUSH_DUE_TO_WRAP(par); \
  174. } \
  175. } else { \
  176. DONT_FLUSH_DUE_TO_WRAP(par); \
  177. }
  178. #define WRAP_LINE(par, wrapit) if(wrapit) { \
  179. float elp; \
  180. elp = (float)fabs(par##1 - par##0); \
  181. if(elp > (float)0.5) \
  182. { \
  183. if (par##1 < par##0) { par##1 += 1.0; } \
  184. else { par##0 += 1.0;} \
  185. FLUSH_DUE_TO_WRAP(par); \
  186. } \
  187. else \
  188. { \
  189. DONT_FLUSH_DUE_TO_WRAP(par); \
  190. } \
  191. } else { \
  192. DONT_FLUSH_DUE_TO_WRAP(par); \
  193. }
  194. //-----------------------------------------------------------------------------
  195. // Texture coordinate recentering macros
  196. //-----------------------------------------------------------------------------
  197. // Keeps the texture coordinates centered around 0
  198. // and avoid exceeding the texel wrapping limit.
  199. #define RECENTER_TEX_COORDS(Maxf, Maxi, fTC0, fTC1, fTC2) \
  200. { \
  201. long tcmax; \
  202. unsigned long tcmin; \
  203. int i; \
  204. \
  205. tcmax = LONG_AT(fTC0); \
  206. if (tcmax < LONG_AT(fTC1)) tcmax = LONG_AT(fTC1); \
  207. if (tcmax < LONG_AT(fTC2)) tcmax = LONG_AT(fTC2); \
  208. if (tcmax >= *(long *)&Maxf) \
  209. { \
  210. myFtoi(&i, *(float *)&tcmax); \
  211. i -= Maxi; \
  212. fTC0 -= i; \
  213. fTC1 -= i; \
  214. fTC2 -= i; \
  215. } \
  216. else \
  217. { \
  218. tcmin = ULONG_AT(fTC0); \
  219. if (tcmin < ULONG_AT(fTC1)) tcmin = ULONG_AT(fTC1); \
  220. if (tcmin < ULONG_AT(fTC2)) tcmin = ULONG_AT(fTC2); \
  221. if (*(float *)&tcmin <= -Maxf) \
  222. { \
  223. myFtoi(&i, *(float *)&tcmin); \
  224. i += Maxi; \
  225. fTC0 -= i; \
  226. fTC1 -= i; \
  227. fTC2 -= i; \
  228. } \
  229. } \
  230. }