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.

1294 lines
40 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) Microsoft Corporation, 1998.
  3. //
  4. // rdcomm.hpp
  5. //
  6. // Direct3D Reference Device - Common Header
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _RDCOMM_HPP
  10. #define _RDCOMM_HPP
  11. #include <math.h>
  12. #ifndef FASTCALL
  13. #ifdef _X86_
  14. #define FASTCALL __fastcall
  15. #else
  16. #define FASTCALL
  17. #endif
  18. #endif
  19. #ifndef CDECL
  20. #ifdef _X86_
  21. #define CDECL __cdecl
  22. #else
  23. #define CDECL
  24. #endif
  25. #endif
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // //
  28. // Globals //
  29. // //
  30. ///////////////////////////////////////////////////////////////////////////////
  31. // memory allocation callbacks
  32. extern LPVOID (__cdecl *g_pfnMemAlloc)( size_t size );
  33. extern void (__cdecl *g_pfnMemFree)( LPVOID lptr );
  34. extern LPVOID (__cdecl *g_pfnMemReAlloc)( LPVOID ptr, size_t size );
  35. // debug print controls
  36. extern int g_iDPFLevel;
  37. extern unsigned long g_uDPFMask;
  38. ///////////////////////////////////////////////////////////////////////////////
  39. // //
  40. // Typedefs //
  41. // //
  42. ///////////////////////////////////////////////////////////////////////////////
  43. #ifndef DllExport
  44. #define DllExport __declspec( dllexport )
  45. #endif
  46. // width-specific typedefs for basic types
  47. //@@BEGIN_MSINTERNAL
  48. #ifndef _BASETSD_H_
  49. //@@END_MSINTERNAL
  50. typedef signed char INT8, *PINT8;
  51. typedef short int INT16, *PINT16;
  52. typedef int INT32, *PINT32;
  53. typedef __int64 INT64, *PINT64;
  54. typedef unsigned char UINT8, *PUINT8;
  55. typedef unsigned short int UINT16, *PUINT16;
  56. typedef unsigned int UINT32, *PUINT32;
  57. typedef unsigned __int64 UINT64, *PUINT64;
  58. //@@BEGIN_MSINTERNAL
  59. #endif
  60. //@@END_MSINTERNAL
  61. typedef float FLOAT;
  62. typedef double DOUBLE;
  63. typedef int BOOL;
  64. typedef FLOAT *PFLOAT;
  65. typedef DOUBLE *PDOUBLE;
  66. struct RDVECTOR4
  67. {
  68. RDVECTOR4()
  69. {
  70. memset( this, 0, sizeof( *this ) );
  71. }
  72. union
  73. {
  74. struct
  75. {
  76. union
  77. {
  78. D3DVALUE x;
  79. D3DVALUE r;
  80. };
  81. union
  82. {
  83. D3DVALUE y;
  84. D3DVALUE g;
  85. };
  86. union
  87. {
  88. D3DVALUE z;
  89. D3DVALUE b;
  90. };
  91. union
  92. {
  93. D3DVALUE w;
  94. D3DVALUE a;
  95. };
  96. };
  97. D3DVALUE v[4];
  98. };
  99. };
  100. struct RDVECTOR3
  101. {
  102. RDVECTOR3()
  103. {
  104. memset( this, 0, sizeof( *this ) );
  105. }
  106. union
  107. {
  108. struct
  109. {
  110. D3DVALUE x;
  111. D3DVALUE y;
  112. D3DVALUE z;
  113. };
  114. D3DVALUE v[3];
  115. };
  116. };
  117. struct RDCOLOR3
  118. {
  119. // 0 - 255
  120. D3DVALUE r,g,b;
  121. };
  122. struct RDCOLOR4
  123. {
  124. // Normalized 0 - 1
  125. D3DVALUE r,g,b,a;
  126. };
  127. struct RDLIGHTINGELEMENT
  128. {
  129. RDVECTOR3 dvPosition;
  130. RDVECTOR3 dvNormal;
  131. };
  132. //-----------------------------------------------------------------------------
  133. //
  134. // Surface formats for rendering surfaces and textures. Different subsets are
  135. // supported for render targets and for textures.
  136. //
  137. //-----------------------------------------------------------------------------
  138. typedef enum _RDSurfaceFormat
  139. {
  140. RD_SF_NULL = 0,
  141. RD_SF_B8G8R8 = 1,
  142. RD_SF_B8G8R8A8 = 2,
  143. RD_SF_B8G8R8X8 = 3,
  144. RD_SF_B5G6R5 = 4,
  145. RD_SF_B5G5R5A1 = 5,
  146. RD_SF_B5G5R5X1 = 6,
  147. RD_SF_PALETTE4 = 7,
  148. RD_SF_PALETTE8 = 8,
  149. RD_SF_B4G4R4A4 = 9,
  150. RD_SF_B4G4R4X4 =10,
  151. RD_SF_L8 =11, // 8 bit luminance-only
  152. RD_SF_L8A8 =12, // 16 bit alpha-luminance
  153. RD_SF_U8V8 =13, // 16 bit bump map format
  154. RD_SF_U5V5L6 =14, // 16 bit bump map format with luminance
  155. RD_SF_U8V8L8X8 =15, // 32 bit bump map format with luminance
  156. RD_SF_UYVY =16, // UYVY format (PC98 compliance)
  157. RD_SF_YUY2 =17, // YUY2 format (PC98 compliance)
  158. RD_SF_DXT1 =18, // DXT texture compression technique 1
  159. RD_SF_DXT2 =19, // DXT texture compression technique 2
  160. RD_SF_DXT3 =20, // DXT texture compression technique 3
  161. RD_SF_DXT4 =21, // DXT texture compression technique 4
  162. RD_SF_DXT5 =22, // DXT texture compression technique 5
  163. RD_SF_B2G3R3 =23, // 8 bit RGB texture format
  164. RD_SF_L4A4 =24, // 8 bit alpha-luminance
  165. RD_SF_B2G3R3A8 =25, // 16 bit alpha-rgb
  166. RD_SF_U16V16 =26, // 32 bit bump map format
  167. RD_SF_U10V11W11=27, // 32 bit signed format for custom data
  168. RD_SF_U8V8W8Q8 =28, // 32 bit signed format for custom data
  169. RD_SF_A8 =29, // 8 bit alpha only
  170. RD_SF_P8A8 =30, // 8 bit alpha + 8 bit palette
  171. // The following have been introduced in DX 8.1
  172. // The byte ordering is opposite to that in the D3DFORMAT_*
  173. // definition, so RD_SF_R8G8B8A8 here corresponds to D3DFORMAT_A8B8G8R8
  174. // hence the DWORD contains AAAAAAAABBBBBBBBGGGGGGGGRRRRRRRR
  175. // This is not true for the Depth formats.
  176. RD_SF_R10G10B10A2 = 31,
  177. RD_SF_R8G8B8A8 = 32,
  178. RD_SF_R8G8B8X8 = 33,
  179. RD_SF_R16G16 = 34,
  180. RD_SF_U11V11W10 = 35,
  181. RD_SF_U10V10W10A2 = 36,
  182. RD_SF_U8V8X8A8 = 37,
  183. RD_SF_U8V8X8L8 = 38,
  184. RD_SF_Z16S0 =70,
  185. RD_SF_Z24S8 =71,
  186. RD_SF_Z24X8 =72,
  187. RD_SF_Z15S1 =73,
  188. RD_SF_Z32S0 =74,
  189. RD_SF_S1Z15 =75,
  190. RD_SF_S8Z24 =76,
  191. RD_SF_X8Z24 =77,
  192. RD_SF_Z24X4S4 =78,
  193. RD_SF_X4S4Z24 =79,
  194. } RDSurfaceFormat;
  195. // compute pixel address from x,y location, sample number, and surface info
  196. char*
  197. PixelAddress( int iX, int iY, int iZ, BYTE* pBits, int iYPitch, int iZPitch, RDSurfaceFormat SType );
  198. class RDSurface2D;
  199. char*
  200. PixelAddress( int iX, int iY, int iZ, int iSample, RDSurface2D* pRT );
  201. // The most general pixel address calculation
  202. char*
  203. PixelAddress( int iX, int iY, int iZ, int iSample, BYTE* pBits, int iYPitch, int iZPitch, int cSamples,
  204. RDSurfaceFormat SType );
  205. //---------------------------------------------------------------------
  206. // Inline functions to answer various questions about surface formats.
  207. //---------------------------------------------------------------------
  208. inline BOOL
  209. IsDXTn( DWORD dwFourCC )
  210. {
  211. return ((dwFourCC == MAKEFOURCC('D', 'X', 'T', '1')) ||
  212. (dwFourCC == MAKEFOURCC('D', 'X', 'T', '2')) ||
  213. (dwFourCC == MAKEFOURCC('D', 'X', 'T', '3')) ||
  214. (dwFourCC == MAKEFOURCC('D', 'X', 'T', '4')) ||
  215. (dwFourCC == MAKEFOURCC('D', 'X', 'T', '5')));
  216. }
  217. inline BOOL
  218. IsYUV( DWORD dwFourCC )
  219. {
  220. return ((dwFourCC == MAKEFOURCC('U', 'Y', 'V', 'Y')) ||
  221. (dwFourCC == MAKEFOURCC('Y', 'U', 'Y', '2')));
  222. }
  223. //---------------------------------------------------------------------
  224. // This class manages growing buffer, aligned to 32 byte boundary
  225. // Number if bytes should be power of 2.
  226. // D3DMalloc is used to allocate memory
  227. //---------------------------------------------------------------------
  228. class RefAlignedBuffer32
  229. {
  230. public:
  231. RefAlignedBuffer32() {m_size = 0; m_allocatedBuf = 0; m_alignedBuf = 0;}
  232. ~RefAlignedBuffer32() {if (m_allocatedBuf) free(m_allocatedBuf);}
  233. // Returns aligned buffer address
  234. LPVOID GetAddress() {return m_alignedBuf;}
  235. // Returns aligned buffer size
  236. DWORD GetSize() {return m_size;}
  237. HRESULT Grow(DWORD dwSize);
  238. HRESULT CheckAndGrow(DWORD dwSize)
  239. {
  240. if (dwSize > m_size)
  241. return Grow(dwSize + 1024);
  242. else
  243. return S_OK;
  244. }
  245. protected:
  246. LPVOID m_allocatedBuf;
  247. LPVOID m_alignedBuf;
  248. DWORD m_size;
  249. };
  250. //-----------------------------------------------------------------------------
  251. //
  252. // Private FVF flags
  253. //
  254. //-----------------------------------------------------------------------------
  255. #define D3DFVFP_FOG ((UINT64)1<<32) // Fog is present
  256. #define D3DFVFP_CLIP ((UINT64)1<<33) // Clip coordinates are present
  257. #define D3DFVFP_POSITION2 ((UINT64)1<<34) // Position2 present (tweening)
  258. #define D3DFVFP_NORMAL2 ((UINT64)1<<35) // Normal2 present (tweening)
  259. #define D3DFVFP_BLENDINDICES ((UINT64)1<<36) // Blend Indices present.
  260. ///////////////////////////////////////////////////////////////////////////////
  261. // //
  262. // Macros //
  263. // //
  264. ///////////////////////////////////////////////////////////////////////////////
  265. #ifndef TRUE
  266. #define TRUE 1
  267. #endif
  268. #ifndef FALSE
  269. #define FALSE 0
  270. #endif
  271. #ifndef NULL
  272. #define NULL 0
  273. #endif
  274. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  275. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  276. #define ABS(a) (((a) < 0) ? (-(a)) : (a))
  277. // Check the return value and return if something wrong.
  278. // Assume hr has been declared
  279. #define HR_RET(exp) \
  280. { \
  281. hr = (exp); \
  282. if (hr != S_OK) \
  283. { \
  284. return hr; \
  285. } \
  286. }
  287. //-----------------------------------------------------------------------------
  288. // macros for converting n-bit signed integers to floats clamped to [-1.0, 1.0]
  289. //
  290. // e.g. For an 8 bit number, if it is -128, it gets clamped to -127.
  291. // Then the number is divided by 127.
  292. //
  293. //-----------------------------------------------------------------------------
  294. inline FLOAT CLAMP_SIGNED16(INT16 i)
  295. {
  296. return (-32768 == i ? -1.f : (FLOAT)i/32767.f);
  297. }
  298. inline FLOAT CLAMP_SIGNED11(INT16 i) //only looks at bottom 11 bits
  299. {
  300. // sign extend to 16 bits
  301. i <<= 5; i >>= 5;
  302. return (-1024 == i ? -1.f : (FLOAT)i/1023.f);
  303. }
  304. inline FLOAT CLAMP_SIGNED10(INT16 i) //only looks at bottom 10 bits
  305. {
  306. // sign extend to 16 bits
  307. i <<= 6; i >>= 6;
  308. return (-512 == i ? -1.f : (FLOAT)i/511.f);
  309. }
  310. inline FLOAT CLAMP_SIGNED8(INT8 i)
  311. {
  312. return (-128 == i ? -1.f : (FLOAT)i/127.f);
  313. }
  314. inline FLOAT CLAMP_SIGNED6(INT8 i) //only looks at bottom 6 bits
  315. {
  316. // sign extend to 8 bits
  317. i <<= 2; i >>= 2;
  318. return (-32 == i ? -1.f : (FLOAT)i/31.f);
  319. }
  320. inline FLOAT CLAMP_SIGNED5(INT8 i) //only looks at bottom 5 bits
  321. {
  322. // sign extend to 8 bits
  323. i <<= 3; i >>= 3;
  324. return (-16 == i ? -1.f : (FLOAT)i/15.f);
  325. }
  326. inline FLOAT CLAMP_SIGNED4(INT8 i) //only looks at bottom 4 bits
  327. {
  328. // sign extend to 8 bits
  329. i <<= 4; i >>= 4;
  330. return (-8 == i ? -1.f : (FLOAT)i/7.f);
  331. }
  332. //-----------------------------------------------------------------------------
  333. //
  334. // macros for accessing floating point data as 32 bit integers and vice versa
  335. //
  336. // This is used primarily to do floating point to fixed point conversion with
  337. // the unbiased nearest-even rounding that IEEE floating point does internally
  338. // between operations. Adding a big number slides the mantissa down to where
  339. // the fixed point equivalent is aligned to the LSB. IEEE applies a nearest-
  340. // even round to the bits it lops off before storing. The mantissa can then
  341. // be grabbed by the AS_INT* operations. Note that the sign and exponent are
  342. // still there, so the easiest thing is to do it with doubles and grab the low
  343. // 32 bits.
  344. //
  345. // The snap values (i.e. the "big number") is the sum of 2**n and 2**(n-1),
  346. // which makes the trick return signed numbers (at least within the mantissa).
  347. //
  348. //-----------------------------------------------------------------------------
  349. #if 0
  350. // NOTE: vc5 optimizing compiler bug breaks this pointer casting technique
  351. #define AS_FLOAT(i) ( *(FLOAT*)&(i) )
  352. #define AS_INT32(f) ( *(INT32*)&(f) )
  353. #define AS_INT16(f) ( *(INT16*)&(f) )
  354. #define AS_UINT32(f) ( *(UINT32*)&(f) )
  355. #else
  356. // workaround using union
  357. typedef union { float f; UINT32 u; INT32 i; } VAL32;
  358. typedef union { double d; UINT64 u; INT64 i; } VAL64;
  359. inline FLOAT AS_FLOAT( long int iVal ) { VAL32 v; v.i = iVal; return v.f; }
  360. inline FLOAT AS_FLOAT( unsigned long int uVal ) { VAL32 v; v.u = uVal; return v.f; }
  361. inline INT32 AS_INT32( FLOAT fVal ) { VAL32 v; v.f = fVal; return v.i; }
  362. inline INT32 AS_INT32( DOUBLE dVal ) { VAL64 v; v.d = dVal; return (INT32)(v.u & 0xffffffff); }
  363. inline INT16 AS_INT16( FLOAT fVal ) { VAL32 v; v.f = fVal; return (INT16)(v.u & 0xffff); }
  364. inline INT16 AS_INT16( DOUBLE dVal ) { VAL64 v; v.d = dVal; return (INT16)(v.u & 0xffff); }
  365. inline INT32 AS_UINT32( FLOAT fVal ) { VAL32 v; v.f = fVal; return v.u; }
  366. #endif
  367. //-----------------------------------------------------------------------------
  368. //
  369. // Some common FP values as constants
  370. // point values
  371. //
  372. //-----------------------------------------------------------------------------
  373. #define g_fZero (0.0f)
  374. #define g_fOne (1.0f)
  375. // Integer representation of 1.0f.
  376. #define INT32_FLOAT_ONE 0x3f800000
  377. const D3DVALUE __HUGE_PWR2 = 1024.0f*1024.0f*2.0f;
  378. //-----------------------------------------------------------------------------
  379. //
  380. // these are handy to form 'magic' constants to snap real values to fixed
  381. // point values
  382. //
  383. //-----------------------------------------------------------------------------
  384. #define C2POW0 1
  385. #define C2POW1 2
  386. #define C2POW2 4
  387. #define C2POW3 8
  388. #define C2POW4 16
  389. #define C2POW5 32
  390. #define C2POW6 64
  391. #define C2POW7 128
  392. #define C2POW8 256
  393. #define C2POW9 512
  394. #define C2POW10 1024
  395. #define C2POW11 2048
  396. #define C2POW12 4096
  397. #define C2POW13 8192
  398. #define C2POW14 16384
  399. #define C2POW15 32768
  400. #define C2POW16 65536
  401. #define C2POW17 131072
  402. #define C2POW18 262144
  403. #define C2POW19 524288
  404. #define C2POW20 1048576
  405. #define C2POW21 2097152
  406. #define C2POW22 4194304
  407. #define C2POW23 8388608
  408. #define C2POW24 16777216
  409. #define C2POW25 33554432
  410. #define C2POW26 67108864
  411. #define C2POW27 134217728
  412. #define C2POW28 268435456
  413. #define C2POW29 536870912
  414. #define C2POW30 1073741824
  415. #define C2POW31 2147483648
  416. #define C2POW32 4294967296
  417. #define C2POW33 8589934592
  418. #define C2POW34 17179869184
  419. #define C2POW35 34359738368
  420. #define C2POW36 68719476736
  421. #define C2POW37 137438953472
  422. #define C2POW38 274877906944
  423. #define C2POW39 549755813888
  424. #define C2POW40 1099511627776
  425. #define C2POW41 2199023255552
  426. #define C2POW42 4398046511104
  427. #define C2POW43 8796093022208
  428. #define C2POW44 17592186044416
  429. #define C2POW45 35184372088832
  430. #define C2POW46 70368744177664
  431. #define C2POW47 140737488355328
  432. #define C2POW48 281474976710656
  433. #define C2POW49 562949953421312
  434. #define C2POW50 1125899906842624
  435. #define C2POW51 2251799813685248
  436. #define C2POW52 4503599627370496
  437. #define FLOAT_0_SNAP (FLOAT)(C2POW23+C2POW22)
  438. #define FLOAT_4_SNAP (FLOAT)(C2POW19+C2POW18)
  439. #define FLOAT_5_SNAP (FLOAT)(C2POW18+C2POW17)
  440. #define FLOAT_8_SNAP (FLOAT)(C2POW15+C2POW14)
  441. #define FLOAT_17_SNAP (FLOAT)(C2POW6 +C2POW5 )
  442. #define FLOAT_18_SNAP (FLOAT)(C2POW5 +C2POW4 )
  443. #define DOUBLE_0_SNAP (DOUBLE)(C2POW52+C2POW51)
  444. #define DOUBLE_4_SNAP (DOUBLE)(C2POW48+C2POW47)
  445. #define DOUBLE_5_SNAP (DOUBLE)(C2POW47+C2POW46)
  446. #define DOUBLE_8_SNAP (DOUBLE)(C2POW44+C2POW43)
  447. #define DOUBLE_17_SNAP (DOUBLE)(C2POW35+C2POW34)
  448. #define DOUBLE_18_SNAP (DOUBLE)(C2POW34+C2POW33)
  449. //-----------------------------------------------------------------------------
  450. //
  451. // Floating point related macros
  452. //
  453. //-----------------------------------------------------------------------------
  454. #define COSF(fV) ((FLOAT)cos((double)(fV)))
  455. #define SINF(fV) ((FLOAT)sin((double)(fV)))
  456. #define SQRTF(fV) ((FLOAT)sqrt((double)(fV)))
  457. #define POWF(fV, fE) ((FLOAT)pow((double)(fV), (double)(fE)))
  458. #ifdef _X86_
  459. #define FLOAT_CMP_POS(fa, op, fb) (AS_INT32(fa) op AS_INT32(fb))
  460. #define FLOAT_CMP_PONE(flt, op) (AS_INT32(flt) op INT32_FLOAT_ONE)
  461. __inline int FLOAT_GTZ(FLOAT f)
  462. {
  463. VAL32 fi;
  464. fi.f = f;
  465. return fi.i > 0;
  466. }
  467. __inline int FLOAT_LTZ(FLOAT f)
  468. {
  469. VAL32 fi;
  470. fi.f = f;
  471. return fi.u > 0x80000000;
  472. }
  473. __inline int FLOAT_GEZ(FLOAT f)
  474. {
  475. VAL32 fi;
  476. fi.f = f;
  477. return fi.u <= 0x80000000;
  478. }
  479. __inline int FLOAT_LEZ(FLOAT f)
  480. {
  481. VAL32 fi;
  482. fi.f = f;
  483. return fi.i <= 0;
  484. }
  485. __inline int FLOAT_EQZ(FLOAT f)
  486. {
  487. VAL32 fi;
  488. fi.f = f;
  489. return (fi.u & 0x7fffffff) == 0;
  490. }
  491. __inline int FLOAT_NEZ(FLOAT f)
  492. {
  493. VAL32 fi;
  494. fi.f = f;
  495. return (fi.u & 0x7fffffff) != 0;
  496. }
  497. // Strip sign bit in integer.
  498. __inline FLOAT
  499. ABSF(FLOAT f)
  500. {
  501. VAL32 fi;
  502. fi.f = f;
  503. fi.u &= 0x7fffffff;
  504. return fi.f;
  505. }
  506. // Requires chop rounding.
  507. __inline INT
  508. FTOI(FLOAT f)
  509. {
  510. LARGE_INTEGER i;
  511. __asm
  512. {
  513. fld f
  514. fistp i
  515. }
  516. return i.LowPart;
  517. }
  518. #else
  519. #define FLOAT_GTZ(flt) ((flt) > g_fZero)
  520. #define FLOAT_LTZ(flt) ((flt) < g_fZero)
  521. #define FLOAT_GEZ(flt) ((flt) >= g_fZero)
  522. #define FLOAT_LEZ(flt) ((flt) <= g_fZero)
  523. #define FLOAT_EQZ(flt) ((flt) == g_fZero)
  524. #define FLOAT_NEZ(flt) ((flt) != g_fZero)
  525. #define FLOAT_CMP_POS(fa, op, fb) ((fa) op (fb))
  526. #define FLOAT_CMP_PONE(flt, op) ((flt) op g_fOne)
  527. #define ABSF(f) ((FLOAT)fabs((double)(f)))
  528. #define FTOI(f) ((INT)(f))
  529. #endif // _X86_
  530. //-----------------------------------------------------------------------------
  531. //
  532. // macro wrappers for memory allocation - wrapped around global function ptrs
  533. // set by RefRastSetMemif
  534. //
  535. //-----------------------------------------------------------------------------
  536. #define MEMALLOC(_size) ((*g_pfnMemAlloc)(_size))
  537. #define MEMFREE(_ptr) { if (NULL != (_ptr)) { ((*g_pfnMemFree)(_ptr)); } }
  538. #define MEMREALLOC(_ptr,_size) ((*g_pfnMemReAlloc)((_ptr),(_size)))
  539. //////////////////////////////////////////////////////////////////////////////////
  540. // //
  541. // Utility Functions //
  542. // //
  543. //////////////////////////////////////////////////////////////////////////////////
  544. //-----------------------------------------------------------------------------
  545. //
  546. // Base class for all RefTnL classes to use common allocation functions
  547. //
  548. //-----------------------------------------------------------------------------
  549. class RDAlloc
  550. {
  551. public:
  552. void* operator new(size_t s);
  553. void operator delete(void* p, size_t);
  554. };
  555. //-----------------------------------------------------------------------------
  556. //
  557. // debug printf support
  558. //
  559. //-----------------------------------------------------------------------------
  560. void RDDebugPrintfL( int iLevel, const char* pszFormat, ... );
  561. void RDDebugPrintf( const char* pszFormat, ... );
  562. void RDErrorPrintf( const char* pszFormat, ... );
  563. #define _DPF_IF 0x0001
  564. #define _DPF_INPUT 0x0002
  565. #define _DPF_SETUP 0x0004
  566. #define _DPF_RAST 0x0008
  567. #define _DPF_TEX 0x0010
  568. #define _DPF_PIX 0x0020
  569. #define _DPF_FRAG 0x0040
  570. #define _DPF_STATS 0x0080
  571. #define _DPF_DRV 0x0100
  572. #define _DPF_TNL 0x0200
  573. #define _DPF_VS 0x0400
  574. #define _DPF_VVM 0x0800
  575. #define _DPF_ANY 0xffff
  576. #define _DPF_TEMP 0x8000
  577. #ifdef DBG
  578. #define DPFERR RDErrorPrintf
  579. #define DPFRR RDDebugPrintfL
  580. #define DPFM( _level, _mask, _message) \
  581. if ((g_iDPFLevel >= (_level)) && (g_uDPFMask & (_DPF_##_mask))) { \
  582. RDDebugPrintf ## _message; \
  583. }
  584. #define DPFINFO RDDebugPrintf
  585. #else
  586. #pragma warning(disable:4002)
  587. #define DPFERR
  588. #define DPFRR()
  589. #define DPFM( _level, _mask, _message)
  590. #define DPFINFO
  591. #endif
  592. //-----------------------------------------------------------------------------
  593. //
  594. // assert macros and reporting functions
  595. //
  596. //-----------------------------------------------------------------------------
  597. // ASSERT with simple string
  598. #undef _ASSERT
  599. #define _ASSERT( value, string ) \
  600. if ( !(value) ) { \
  601. RDAssertReport( string, __FILE__, __LINE__ ); \
  602. }
  603. // ASSERT with formatted string - note extra parenthesis on report
  604. // usage: _ASSERTf(foo,("foo is %d",foo))
  605. #undef _ASSERTf
  606. #define _ASSERTf(value,report) \
  607. if (!(value)) { \
  608. char __sz__FILE__[] = __FILE__; \
  609. RDAssertReportPrefix(__sz__FILE__,__LINE__); \
  610. RDAssertReportMessage ## report; \
  611. }
  612. // ASSERT with action field
  613. #undef _ASSERTa
  614. #define _ASSERTa(value,string,action) \
  615. if (!(value)) { \
  616. RDAssertReport(string,__FILE__,__LINE__); \
  617. action \
  618. }
  619. // ASSERTf with action field
  620. #undef _ASSERTfa
  621. #define _ASSERTfa(value,report,action) \
  622. if (!(value)) { \
  623. RDAssertReportPrefix(__FILE__,__LINE__); \
  624. RDAssertReportMessage ## report; \
  625. action \
  626. }
  627. extern void RDAssertReport( const char* pszString, const char* pszFile, int iLine );
  628. extern void RDAssertReportPrefix( const char* pszFile, int iLine );
  629. extern void RDAssertReportMessage( const char* pszFormat, ... );
  630. //-----------------------------------------------------------------------------
  631. //
  632. // bit twiddling utilities
  633. //
  634. //-----------------------------------------------------------------------------
  635. extern INT32 CountSetBits( UINT32 uVal, INT32 nBits );
  636. extern INT32 FindFirstSetBit( UINT32 uVal, INT32 nBits );
  637. extern INT32 FindMostSignificantSetBit( UINT32 uVal, INT32 nBits );
  638. extern INT32 FindLastSetBit( UINT32 uVal, INT32 nBits );
  639. // TRUE if integer is a power of 2
  640. inline BOOL IsPowerOf2( INT32 i )
  641. {
  642. if ( i <= 0 ) return 0;
  643. return ( 0x0 == ( i & (i-1) ) );
  644. }
  645. //-----------------------------------------------------------------------------
  646. //
  647. // multiply/add routines & macros for unsigned 8 bit values, signed 16 bit values
  648. //
  649. // These are not currently used, but the Mult8x8Scl is an interesting routine
  650. // for hardware designers to look at. This does a 8x8 multiply combined with
  651. // a 256/255 scale which accurately solves the "0xff * value = value" issue.
  652. // There are refinements on this (involving half-adders) which are not easily
  653. // representable in C. Credits to Steve Gabriel and Jim Blinn.
  654. //
  655. //-----------------------------------------------------------------------------
  656. // straight 8x8 unsigned multiply returning 8 bits, tossing fractional
  657. // bits (no rounding)
  658. inline UINT8 Mult8x8( const UINT8 uA, const UINT8 uB )
  659. {
  660. UINT16 uA16 = (UINT16)uA;
  661. UINT16 uB16 = (UINT16)uB;
  662. UINT16 uRes16 = uA16*uB16;
  663. UINT8 uRes8 = (UINT8)(uRes16>>8);
  664. return uRes8;
  665. }
  666. // 8x8 unsigned multiply with ff*val = val scale adjustment (scale by (256/255))
  667. inline UINT8 Mult8x8Scl( const UINT8 uA, const UINT8 uB )
  668. {
  669. UINT16 uA16 = (UINT16)uA;
  670. UINT16 uB16 = (UINT16)uB;
  671. UINT16 uRes16 = uA16*uB16;
  672. uRes16 += 0x0080;
  673. uRes16 += (uRes16>>8);
  674. UINT8 uRes8 = (UINT8)(uRes16>>8);
  675. return uRes8;
  676. }
  677. // 8x8 saturated addition - result > 0xff returns 0xff
  678. inline UINT8 SatAdd8x8( const UINT8 uA, const UINT8 uB )
  679. {
  680. UINT16 uA16 = (UINT16)uA;
  681. UINT16 uB16 = (UINT16)uB;
  682. UINT16 uRes16 = uA16+uB16;
  683. UINT8 uRes8 = (uRes16 > 0xff) ? (0xff) : ((UINT8)uRes16);
  684. return uRes8;
  685. }
  686. //----------------------------------------------------------------------------
  687. //
  688. // IntLog2
  689. //
  690. // Do a quick, integer log2 for exact powers of 2.
  691. //
  692. //----------------------------------------------------------------------------
  693. inline UINT32 FASTCALL
  694. IntLog2(UINT32 x)
  695. {
  696. UINT32 y = 0;
  697. x >>= 1;
  698. while(x != 0)
  699. {
  700. x >>= 1;
  701. y++;
  702. }
  703. return y;
  704. }
  705. //////////////////////////////////////////////////////////////////////////////
  706. // FVF related macros
  707. //////////////////////////////////////////////////////////////////////////////
  708. #define FVF_TRANSFORMED(dwFVF) ((dwFVF & D3DFVF_POSITION_MASK) == D3DFVF_XYZRHW)
  709. #define FVF_TEXCOORD_NUMBER(dwFVF) \
  710. (((dwFVF) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
  711. //////////////////////////////////////////////////////////////////////////////
  712. // State Override Macros
  713. //////////////////////////////////////////////////////////////////////////////
  714. #define IS_OVERRIDE(type) ((DWORD)(type) > D3DSTATE_OVERRIDE_BIAS)
  715. #define GET_OVERRIDE(type) ((DWORD)(type) - D3DSTATE_OVERRIDE_BIAS)
  716. #define STATESET_MASK(set, state) \
  717. (set).bits[((state) - 1) >> RRSTATEOVERRIDE_DWORD_SHIFT]
  718. #define STATESET_BIT(state) (1 << (((state) - 1) & (RRSTATEOVERRIDE_DWORD_BITS - 1)))
  719. #define STATESET_ISSET(set, state) \
  720. STATESET_MASK(set, state) & STATESET_BIT(state)
  721. #define STATESET_SET(set, state) \
  722. STATESET_MASK(set, state) |= STATESET_BIT(state)
  723. #define STATESET_CLEAR(set, state) \
  724. STATESET_MASK(set, state) &= ~STATESET_BIT(state)
  725. #define STATESET_INIT(set) memset(&(set), 0, sizeof(set))
  726. //---------------------------------------------------------------------
  727. // GetVertexCount
  728. //---------------------------------------------------------------------
  729. __inline DWORD
  730. GetVertexCount( D3DPRIMITIVETYPE primType, DWORD cPrims )
  731. {
  732. switch( primType )
  733. {
  734. case D3DPT_POINTLIST:
  735. return cPrims;
  736. case D3DPT_LINELIST:
  737. return cPrims * 2;
  738. case D3DPT_LINESTRIP:
  739. return cPrims + 1;
  740. case D3DPT_TRIANGLELIST:
  741. return cPrims * 3;
  742. case D3DPT_TRIANGLESTRIP:
  743. return cPrims + 2;
  744. case D3DPT_TRIANGLEFAN:
  745. return cPrims + 2;
  746. }
  747. return 0;
  748. }
  749. //---------------------------------------------------------------------
  750. // GetTexCoordDim:
  751. // Computes the dimensionality of the given TexCoord in an FVF
  752. //---------------------------------------------------------------------
  753. #ifndef D3DFVF_GETTEXCOORDSIZE
  754. #define D3DFVF_GETTEXCOORDSIZE(FVF, CoordIndex) ((FVF >> (CoordIndex*2 + 16)) & 0x3)
  755. #endif
  756. inline DWORD GetTexCoordDim( UINT64 FVF, DWORD Index)
  757. {
  758. DWORD dwFVF = (DWORD)FVF;
  759. DWORD numTex = FVF_TEXCOORD_NUMBER(dwFVF);
  760. if( (numTex == 0) || (Index >= numTex ) ) return 0;
  761. switch( D3DFVF_GETTEXCOORDSIZE(FVF, Index) )
  762. {
  763. case D3DFVF_TEXTUREFORMAT1: return 1; break;
  764. case D3DFVF_TEXTUREFORMAT2: return 2; break;
  765. case D3DFVF_TEXTUREFORMAT3: return 3; break;
  766. case D3DFVF_TEXTUREFORMAT4: return 4; break;
  767. }
  768. return 0;
  769. }
  770. //---------------------------------------------------------------------
  771. // GetFVFVertexSize:
  772. // Computes total vertex size in bytes for given fvf
  773. // including the texture coordinates
  774. //---------------------------------------------------------------------
  775. __inline DWORD
  776. GetFVFVertexSize( UINT64 qwFVF )
  777. {
  778. // Texture formats size 00 01 10 11
  779. static DWORD dwTextureSize[4] = {2*4, 3*4, 4*4, 4};
  780. DWORD dwSize = 3 << 2;
  781. switch( qwFVF & D3DFVF_POSITION_MASK )
  782. {
  783. case D3DFVF_XYZRHW: dwSize += 4; break;
  784. case D3DFVF_XYZB1: dwSize += 1*4; break;
  785. case D3DFVF_XYZB2: dwSize += 2*4; break;
  786. case D3DFVF_XYZB3: dwSize += 3*4; break;
  787. case D3DFVF_XYZB4: dwSize += 4*4; break;
  788. case D3DFVF_XYZB5: dwSize += 5*4; break;
  789. }
  790. if (qwFVF & D3DFVF_NORMAL)
  791. dwSize += 3*4;
  792. if (qwFVF & D3DFVF_PSIZE)
  793. dwSize += 4;
  794. if (qwFVF & D3DFVF_DIFFUSE)
  795. dwSize += 4;
  796. if (qwFVF & D3DFVF_SPECULAR)
  797. dwSize += 4;
  798. if (qwFVF & D3DFVF_FOG)
  799. dwSize += 4;
  800. // Texture coordinates
  801. DWORD dwNumTexCoord = (DWORD)(FVF_TEXCOORD_NUMBER(qwFVF));
  802. DWORD dwTextureFormats = (DWORD)qwFVF >> 16;
  803. if (dwTextureFormats == 0)
  804. {
  805. dwSize += dwNumTexCoord * 2 * 4;
  806. }
  807. else
  808. {
  809. for (DWORD i=0; i < dwNumTexCoord; i++)
  810. {
  811. // dwSize += GetTexCoordDim( qwFVF, i ) * sizeof( float);
  812. dwSize += dwTextureSize[dwTextureFormats & 3];
  813. dwTextureFormats >>= 2;
  814. }
  815. }
  816. return dwSize;
  817. }
  818. #if 0
  819. //---------------------------------------------------------------------
  820. // ComputeTextureCoordSize:
  821. // Computes the following device data
  822. // - bTextureCoordSizeTotal
  823. // - bTextureCoordSize[] array, based on the input FVF id
  824. //---------------------------------------------------------------------
  825. __inline void ComputeTextureCoordInfo( DWORD dwFVF,
  826. LPDWORD pdwNumTexCoord,
  827. LPDWORD pdwTexCoordSizeArray )
  828. {
  829. // Texture formats size 00 01 10 11
  830. static BYTE bTextureSize[4] = {2*4, 3*4, 4*4, 4};
  831. DWORD dwNumTexCoord = FVF_TEXCOORD_NUMBER(dwFVF);
  832. *pdwNumTexCoord = dwNumTexCoord;
  833. // Compute texture coordinate size
  834. DWORD dwTextureFormats = dwFVF >> 16;
  835. if (dwTextureFormats == 0)
  836. {
  837. for (DWORD i=0; i < dwNumTexCoord; i++)
  838. pdwTexCoordSizeArray[i] = 4*2;
  839. }
  840. else
  841. {
  842. for (DWORD i=0; i < dwNumTexCoord; i++)
  843. {
  844. BYTE dwSize = bTextureSize[dwTextureFormats & 3];
  845. pdwTexCoordSizeArray[i] = dwSize;
  846. dwTextureFormats >>= 2;
  847. }
  848. }
  849. return;
  850. }
  851. #endif
  852. HRESULT
  853. RDFVFCheckAndStride( DWORD dwFVF, DWORD* pdwStride );
  854. ///////////////////////////////////////////////////////////////////////////////
  855. // Matrix and Vector routines
  856. ///////////////////////////////////////////////////////////////////////////////
  857. inline void
  858. ReverseVector(const RDVECTOR3 &in, RDVECTOR3 &out)
  859. {
  860. out.x = -in.x;
  861. out.y = -in.y;
  862. out.z = -in.z;
  863. }
  864. inline void
  865. AddVector(const RDVECTOR3 &v1, const RDVECTOR3 &v2, RDVECTOR3 &out)
  866. {
  867. out.x = v1.x + v2.x;
  868. out.y = v1.y + v2.y;
  869. out.z = v1.z + v2.z;
  870. }
  871. inline void
  872. SubtractVector(const RDVECTOR3 &v1, const RDVECTOR3 &v2, RDVECTOR3 &out)
  873. {
  874. out.x = v1.x - v2.x;
  875. out.y = v1.y - v2.y;
  876. out.z = v1.z - v2.z;
  877. }
  878. inline RDVECTOR3&
  879. ScaleVector(RDVECTOR3 &v, FLOAT scale)
  880. {
  881. v.x = v.x * scale;
  882. v.y = v.y * scale;
  883. v.z = v.z * scale;
  884. return v;
  885. }
  886. inline void
  887. SetIdentity(D3DMATRIX &m)
  888. {
  889. m._11 = m._22 = m._33 = m._44 = 1.0f;
  890. m._12 = m._13 = m._14 = 0.0f;
  891. m._21 = m._23 = m._24 = 0.0f;
  892. m._31 = m._32 = m._34 = 0.0f;
  893. m._41 = m._42 = m._43 = 0.0f;
  894. }
  895. inline void
  896. SetNull(D3DMATRIX &m)
  897. {
  898. m._11 = m._22 = m._33 = m._44 = 0.0f;
  899. m._12 = m._13 = m._14 = 0.0f;
  900. m._21 = m._23 = m._24 = 0.0f;
  901. m._31 = m._32 = m._34 = 0.0f;
  902. m._41 = m._42 = m._43 = 0.0f;
  903. }
  904. inline void
  905. CopyMatrix(D3DMATRIX &s, D3DMATRIX &d)
  906. {
  907. d._11 = s._11;
  908. d._12 = s._12;
  909. d._13 = s._13;
  910. d._14 = s._14;
  911. d._21 = s._21;
  912. d._22 = s._22;
  913. d._23 = s._23;
  914. d._24 = s._24;
  915. d._31 = s._31;
  916. d._32 = s._32;
  917. d._33 = s._33;
  918. d._34 = s._34;
  919. d._41 = s._41;
  920. d._42 = s._42;
  921. d._43 = s._43;
  922. d._44 = s._44;
  923. }
  924. inline D3DVALUE
  925. SquareMagnitude (const RDVECTOR3& v)
  926. {
  927. return v.x*v.x + v.y*v.y + v.z*v.z;
  928. }
  929. inline D3DVALUE
  930. Magnitude (const RDVECTOR3& v)
  931. {
  932. return (D3DVALUE) sqrt(SquareMagnitude(v));
  933. }
  934. inline RDVECTOR3
  935. Normalize (const RDVECTOR3& v)
  936. {
  937. RDVECTOR3 nv;
  938. D3DVALUE mag = Magnitude(v);
  939. if( FLOAT_NEZ( mag ) )
  940. {
  941. nv.x = v.x/mag;
  942. nv.y = v.y/mag;
  943. nv.z = v.z/mag;
  944. }
  945. return nv;
  946. }
  947. inline void
  948. Normalize (RDVECTOR3& v)
  949. {
  950. D3DVALUE mag = Magnitude(v);
  951. if( FLOAT_NEZ( mag ) )
  952. {
  953. v.x = v.x/mag;
  954. v.y = v.y/mag;
  955. v.z = v.z/mag;
  956. }
  957. else
  958. {
  959. v.x = v.y = v.z = 0.0f;
  960. }
  961. return;
  962. }
  963. inline RDVECTOR3
  964. CrossProduct (const RDVECTOR3& v1, const RDVECTOR3& v2)
  965. {
  966. RDVECTOR3 result;
  967. result.x = v1.y*v2.z - v1.z*v2.y;
  968. result.y = v1.z*v2.x - v1.x*v2.z;
  969. result.z = v1.x*v2.y - v1.y*v2.x;
  970. return result;
  971. }
  972. inline D3DVALUE
  973. DotProduct (const RDVECTOR3& v1, const RDVECTOR3& v2)
  974. {
  975. return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
  976. }
  977. //---------------------------------------------------------------------
  978. // Multiplies vector (x,y,z,w) by a 4x4 matrix transposed,
  979. // producing a homogeneous vector
  980. //
  981. // res and v should not be the same
  982. //---------------------------------------------------------------------
  983. inline void
  984. XformPlaneBy4x4Transposed(RDVECTOR4 *v, D3DMATRIX *m, RDVECTOR4 *res)
  985. {
  986. res->x = v->x*m->_11 + v->y*m->_12 + v->z*m->_13 + v->w*m->_14;
  987. res->y = v->x*m->_21 + v->y*m->_22 + v->z*m->_23 + v->w*m->_24;
  988. res->z = v->x*m->_31 + v->y*m->_32 + v->z*m->_33 + v->w*m->_34;
  989. res->w = v->x*m->_41 + v->y*m->_42 + v->z*m->_43 + v->w*m->_44;
  990. }
  991. //---------------------------------------------------------------------
  992. // Multiplies vector (x,y,z,w) by 4x4 matrix, producing a homogeneous vector
  993. //
  994. // res and v should not be the same
  995. //---------------------------------------------------------------------
  996. inline void
  997. XformPlaneBy4x4(RDVECTOR4 *v, D3DMATRIX *m, RDVECTOR4 *res)
  998. {
  999. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31 + v->w*m->_41;
  1000. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32 + v->w*m->_42;
  1001. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33 + v->w*m->_43;
  1002. res->w = v->x*m->_14 + v->y*m->_24 + v->z*m->_34 + v->w*m->_44;
  1003. }
  1004. //---------------------------------------------------------------------
  1005. // Multiplies vector (x,y,z,1) by 4x4 matrix, producing a homogeneous vector
  1006. //
  1007. // res and v should not be the same
  1008. //---------------------------------------------------------------------
  1009. inline void
  1010. XformBy4x4(RDVECTOR3 *v, D3DMATRIX *m, RDVECTOR4 *res)
  1011. {
  1012. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31 + m->_41;
  1013. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32 + m->_42;
  1014. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33 + m->_43;
  1015. res->w = v->x*m->_14 + v->y*m->_24 + v->z*m->_34 + m->_44;
  1016. }
  1017. //---------------------------------------------------------------------
  1018. // Multiplies vector (x,y,z,1) by 4x3 matrix
  1019. //
  1020. // res and v should not be the same
  1021. //---------------------------------------------------------------------
  1022. inline void
  1023. XformBy4x3(RDVECTOR3 *v, D3DMATRIX *m, RDVECTOR3 *res)
  1024. {
  1025. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31 + m->_41;
  1026. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32 + m->_42;
  1027. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33 + m->_43;
  1028. }
  1029. //---------------------------------------------------------------------
  1030. // Multiplies vector (x,y,z) by 3x3 matrix
  1031. //
  1032. // res and v should not be the same
  1033. //---------------------------------------------------------------------
  1034. inline void
  1035. Xform3VecBy3x3(RDVECTOR3 *v, D3DMATRIX *m, RDVECTOR3 *res)
  1036. {
  1037. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31;
  1038. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32;
  1039. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33;
  1040. }
  1041. //---------------------------------------------------------------------
  1042. // This function uses Cramer's Rule to calculate the matrix inverse.
  1043. // See nt\private\windows\opengl\serever\soft\so_math.c
  1044. //
  1045. // Returns:
  1046. // 0 - if success
  1047. // -1 - if input matrix is singular
  1048. //---------------------------------------------------------------------
  1049. int Inverse4x4(D3DMATRIX *src, D3DMATRIX *inverse);
  1050. //---------------------------------------------------------------------
  1051. // Make RDCOLOR3 from a Packed DWORD
  1052. //---------------------------------------------------------------------
  1053. inline void MakeRDCOLOR3( RDCOLOR3 *out, DWORD inputColor )
  1054. {
  1055. out->r = (D3DVALUE)RGBA_GETRED( inputColor );
  1056. out->g = (D3DVALUE)RGBA_GETGREEN( inputColor );
  1057. out->b = (D3DVALUE)RGBA_GETBLUE( inputColor );
  1058. }
  1059. //---------------------------------------------------------------------
  1060. // Make RDCOLOR4 from a Packed DWORD
  1061. //---------------------------------------------------------------------
  1062. inline void MakeRDCOLOR4( RDCOLOR4 *out, DWORD inputColor )
  1063. {
  1064. out->a = (D3DVALUE)RGBA_GETALPHA( inputColor )/255.0f;
  1065. out->r = (D3DVALUE)RGBA_GETRED ( inputColor )/255.0f;
  1066. out->g = (D3DVALUE)RGBA_GETGREEN( inputColor )/255.0f;
  1067. out->b = (D3DVALUE)RGBA_GETBLUE ( inputColor )/255.0f;
  1068. }
  1069. ////////////////////////////////////////////////////////////////////////
  1070. //
  1071. // Macros used to access DDRAW surface info.
  1072. //
  1073. ////////////////////////////////////////////////////////////////////////
  1074. #define DDSurf_Width(lpLcl) ( (lpLcl)->lpGbl->wWidth )
  1075. #define DDSurf_Pitch(lpLcl) ( (lpLcl)->lpGbl->lPitch )
  1076. #define DDSurf_Height(lpLcl) ( (lpLcl)->lpGbl->wHeight )
  1077. #define DDSurf_BitDepth(lpLcl) \
  1078. ( (lpLcl->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? \
  1079. (lpLcl->lpGbl->ddpfSurface.dwRGBBitCount) : \
  1080. (lpLcl->lpGbl->lpDD->vmiData.ddpfDisplay.dwRGBBitCount) \
  1081. )
  1082. #define DDSurf_PixFmt(lpLcl) \
  1083. ( ((lpLcl)->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? \
  1084. ((lpLcl)->lpGbl->ddpfSurface) : \
  1085. ((lpLcl)->lpGbl->lpDD->vmiData.ddpfDisplay) \
  1086. )
  1087. #define VIDEO_MEMORY(pDDSLcl) \
  1088. (!((pDDSLcl)->lpGbl->dwGlobalFlags & DDRAWISURFGBL_SYSMEMREQUESTED))
  1089. #define SURFACE_LOCKED(pDDSLcl) \
  1090. ((pDDSLcl)->lpGbl->dwUsageCount > 0)
  1091. #define SURFACE_MEMORY(surfLcl) \
  1092. (LPVOID)((surfLcl)->lpGbl->fpVidMem)
  1093. //---------------------------------------------------------------------
  1094. // DDraw extern functions
  1095. //---------------------------------------------------------------------
  1096. extern "C" HRESULT WINAPI
  1097. DDInternalLock( LPDDRAWI_DDRAWSURFACE_LCL this_lcl, LPVOID* lpBits );
  1098. extern "C" HRESULT WINAPI
  1099. DDInternalUnlock( LPDDRAWI_DDRAWSURFACE_LCL this_lcl );
  1100. HRESULT DDGetAttachedSurfaceLcl(
  1101. LPDDRAWI_DDRAWSURFACE_LCL this_lcl,
  1102. LPDDSCAPS2 lpDDSCaps,
  1103. LPDDRAWI_DDRAWSURFACE_LCL *lplpDDAttachedSurfaceLcl);
  1104. extern "C" LPDDRAWI_DDRAWSURFACE_LCL WINAPI
  1105. GetDDSurfaceLocal( LPDDRAWI_DIRECTDRAW_LCL this_lcl, DWORD handle, BOOL* isnew );
  1106. //---------------------------------------------------------------------
  1107. // RDListEntry:
  1108. //
  1109. // To support singly linked lists with no deletion of entries. Useful
  1110. // for active lists (Active Lights etc.)
  1111. //---------------------------------------------------------------------
  1112. struct RDListEntry
  1113. {
  1114. RDListEntry(){m_pNext = NULL;}
  1115. virtual ~RDListEntry(){}
  1116. // Seek to the end of the chain and append
  1117. void Append(RDListEntry* p)
  1118. {
  1119. if( m_pNext == NULL )
  1120. {
  1121. m_pNext = p;
  1122. return;
  1123. }
  1124. RDListEntry* c = m_pNext;
  1125. while( c->m_pNext ) c = c->m_pNext;
  1126. c->m_pNext = p;
  1127. }
  1128. RDListEntry *Next() { return m_pNext; }
  1129. RDListEntry * m_pNext;
  1130. };
  1131. //---------------------------------------------------------------------
  1132. // Registry access
  1133. //---------------------------------------------------------------------
  1134. #define RESPATH_D3D "Software\\Microsoft\\Direct3D"
  1135. #define RESPATH_D3DREF RESPATH_D3D "\\ReferenceDevice"
  1136. BOOL GetD3DRegValue(DWORD type, char *valueName, LPVOID value, DWORD dwSize);
  1137. BOOL GetD3DRefRegValue(DWORD type, char *valueName, LPVOID value, DWORD dwSize);
  1138. ///////////////////////////////////////////////////////////////////////////////
  1139. #endif // _RDCOMM_HPP