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.

1293 lines
39 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 DPFRR RDDebugPrintfL
  579. #define DPFM( _level, _mask, _message) \
  580. if ((g_iDPFLevel >= (_level)) && (g_uDPFMask & (_DPF_##_mask))) { \
  581. RDDebugPrintf ## _message; \
  582. }
  583. #define DPFINFO RDDebugPrintf
  584. #else
  585. #pragma warning(disable:4002)
  586. #define DPFRR()
  587. #define DPFM( _level, _mask, _message)
  588. #define DPFINFO
  589. #endif
  590. #define DPFERR RDErrorPrintf
  591. //-----------------------------------------------------------------------------
  592. //
  593. // assert macros and reporting functions
  594. //
  595. //-----------------------------------------------------------------------------
  596. // ASSERT with simple string
  597. #undef _ASSERT
  598. #define _ASSERT( value, string ) \
  599. if ( !(value) ) { \
  600. RDAssertReport( string, __FILE__, __LINE__ ); \
  601. }
  602. // ASSERT with formatted string - note extra parenthesis on report
  603. // usage: _ASSERTf(foo,("foo is %d",foo))
  604. #undef _ASSERTf
  605. #define _ASSERTf(value,report) \
  606. if (!(value)) { \
  607. char __sz__FILE__[] = __FILE__; \
  608. RDAssertReportPrefix(__sz__FILE__,__LINE__); \
  609. RDAssertReportMessage ## report; \
  610. }
  611. // ASSERT with action field
  612. #undef _ASSERTa
  613. #define _ASSERTa(value,string,action) \
  614. if (!(value)) { \
  615. RDAssertReport(string,__FILE__,__LINE__); \
  616. action \
  617. }
  618. // ASSERTf with action field
  619. #undef _ASSERTfa
  620. #define _ASSERTfa(value,report,action) \
  621. if (!(value)) { \
  622. RDAssertReportPrefix(__FILE__,__LINE__); \
  623. RDAssertReportMessage ## report; \
  624. action \
  625. }
  626. extern void RDAssertReport( const char* pszString, const char* pszFile, int iLine );
  627. extern void RDAssertReportPrefix( const char* pszFile, int iLine );
  628. extern void RDAssertReportMessage( const char* pszFormat, ... );
  629. //-----------------------------------------------------------------------------
  630. //
  631. // bit twiddling utilities
  632. //
  633. //-----------------------------------------------------------------------------
  634. extern INT32 CountSetBits( UINT32 uVal, INT32 nBits );
  635. extern INT32 FindFirstSetBit( UINT32 uVal, INT32 nBits );
  636. extern INT32 FindMostSignificantSetBit( UINT32 uVal, INT32 nBits );
  637. extern INT32 FindLastSetBit( UINT32 uVal, INT32 nBits );
  638. // TRUE if integer is a power of 2
  639. inline BOOL IsPowerOf2( INT32 i )
  640. {
  641. if ( i <= 0 ) return 0;
  642. return ( 0x0 == ( i & (i-1) ) );
  643. }
  644. //-----------------------------------------------------------------------------
  645. //
  646. // multiply/add routines & macros for unsigned 8 bit values, signed 16 bit values
  647. //
  648. // These are not currently used, but the Mult8x8Scl is an interesting routine
  649. // for hardware designers to look at. This does a 8x8 multiply combined with
  650. // a 256/255 scale which accurately solves the "0xff * value = value" issue.
  651. // There are refinements on this (involving half-adders) which are not easily
  652. // representable in C. Credits to Steve Gabriel and Jim Blinn.
  653. //
  654. //-----------------------------------------------------------------------------
  655. // straight 8x8 unsigned multiply returning 8 bits, tossing fractional
  656. // bits (no rounding)
  657. inline UINT8 Mult8x8( const UINT8 uA, const UINT8 uB )
  658. {
  659. UINT16 uA16 = (UINT16)uA;
  660. UINT16 uB16 = (UINT16)uB;
  661. UINT16 uRes16 = uA16*uB16;
  662. UINT8 uRes8 = (UINT8)(uRes16>>8);
  663. return uRes8;
  664. }
  665. // 8x8 unsigned multiply with ff*val = val scale adjustment (scale by (256/255))
  666. inline UINT8 Mult8x8Scl( const UINT8 uA, const UINT8 uB )
  667. {
  668. UINT16 uA16 = (UINT16)uA;
  669. UINT16 uB16 = (UINT16)uB;
  670. UINT16 uRes16 = uA16*uB16;
  671. uRes16 += 0x0080;
  672. uRes16 += (uRes16>>8);
  673. UINT8 uRes8 = (UINT8)(uRes16>>8);
  674. return uRes8;
  675. }
  676. // 8x8 saturated addition - result > 0xff returns 0xff
  677. inline UINT8 SatAdd8x8( const UINT8 uA, const UINT8 uB )
  678. {
  679. UINT16 uA16 = (UINT16)uA;
  680. UINT16 uB16 = (UINT16)uB;
  681. UINT16 uRes16 = uA16+uB16;
  682. UINT8 uRes8 = (uRes16 > 0xff) ? (0xff) : ((UINT8)uRes16);
  683. return uRes8;
  684. }
  685. //----------------------------------------------------------------------------
  686. //
  687. // IntLog2
  688. //
  689. // Do a quick, integer log2 for exact powers of 2.
  690. //
  691. //----------------------------------------------------------------------------
  692. inline UINT32 FASTCALL
  693. IntLog2(UINT32 x)
  694. {
  695. UINT32 y = 0;
  696. x >>= 1;
  697. while(x != 0)
  698. {
  699. x >>= 1;
  700. y++;
  701. }
  702. return y;
  703. }
  704. //////////////////////////////////////////////////////////////////////////////
  705. // FVF related macros
  706. //////////////////////////////////////////////////////////////////////////////
  707. #define FVF_TRANSFORMED(dwFVF) ((dwFVF & D3DFVF_POSITION_MASK) == D3DFVF_XYZRHW)
  708. #define FVF_TEXCOORD_NUMBER(dwFVF) \
  709. (((dwFVF) & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
  710. //////////////////////////////////////////////////////////////////////////////
  711. // State Override Macros
  712. //////////////////////////////////////////////////////////////////////////////
  713. #define IS_OVERRIDE(type) ((DWORD)(type) > D3DSTATE_OVERRIDE_BIAS)
  714. #define GET_OVERRIDE(type) ((DWORD)(type) - D3DSTATE_OVERRIDE_BIAS)
  715. #define STATESET_MASK(set, state) \
  716. (set).bits[((state) - 1) >> RRSTATEOVERRIDE_DWORD_SHIFT]
  717. #define STATESET_BIT(state) (1 << (((state) - 1) & (RRSTATEOVERRIDE_DWORD_BITS - 1)))
  718. #define STATESET_ISSET(set, state) \
  719. STATESET_MASK(set, state) & STATESET_BIT(state)
  720. #define STATESET_SET(set, state) \
  721. STATESET_MASK(set, state) |= STATESET_BIT(state)
  722. #define STATESET_CLEAR(set, state) \
  723. STATESET_MASK(set, state) &= ~STATESET_BIT(state)
  724. #define STATESET_INIT(set) memset(&(set), 0, sizeof(set))
  725. //---------------------------------------------------------------------
  726. // GetVertexCount
  727. //---------------------------------------------------------------------
  728. __inline DWORD
  729. GetVertexCount( D3DPRIMITIVETYPE primType, DWORD cPrims )
  730. {
  731. switch( primType )
  732. {
  733. case D3DPT_POINTLIST:
  734. return cPrims;
  735. case D3DPT_LINELIST:
  736. return cPrims * 2;
  737. case D3DPT_LINESTRIP:
  738. return cPrims + 1;
  739. case D3DPT_TRIANGLELIST:
  740. return cPrims * 3;
  741. case D3DPT_TRIANGLESTRIP:
  742. return cPrims + 2;
  743. case D3DPT_TRIANGLEFAN:
  744. return cPrims + 2;
  745. }
  746. return 0;
  747. }
  748. //---------------------------------------------------------------------
  749. // GetTexCoordDim:
  750. // Computes the dimensionality of the given TexCoord in an FVF
  751. //---------------------------------------------------------------------
  752. #ifndef D3DFVF_GETTEXCOORDSIZE
  753. #define D3DFVF_GETTEXCOORDSIZE(FVF, CoordIndex) ((FVF >> (CoordIndex*2 + 16)) & 0x3)
  754. #endif
  755. inline DWORD GetTexCoordDim( UINT64 FVF, DWORD Index)
  756. {
  757. DWORD dwFVF = (DWORD)FVF;
  758. DWORD numTex = FVF_TEXCOORD_NUMBER(dwFVF);
  759. if( (numTex == 0) || (Index >= numTex ) ) return 0;
  760. switch( D3DFVF_GETTEXCOORDSIZE(FVF, Index) )
  761. {
  762. case D3DFVF_TEXTUREFORMAT1: return 1; break;
  763. case D3DFVF_TEXTUREFORMAT2: return 2; break;
  764. case D3DFVF_TEXTUREFORMAT3: return 3; break;
  765. case D3DFVF_TEXTUREFORMAT4: return 4; break;
  766. }
  767. return 0;
  768. }
  769. //---------------------------------------------------------------------
  770. // GetFVFVertexSize:
  771. // Computes total vertex size in bytes for given fvf
  772. // including the texture coordinates
  773. //---------------------------------------------------------------------
  774. __inline DWORD
  775. GetFVFVertexSize( UINT64 qwFVF )
  776. {
  777. // Texture formats size 00 01 10 11
  778. static DWORD dwTextureSize[4] = {2*4, 3*4, 4*4, 4};
  779. DWORD dwSize = 3 << 2;
  780. switch( qwFVF & D3DFVF_POSITION_MASK )
  781. {
  782. case D3DFVF_XYZRHW: dwSize += 4; break;
  783. case D3DFVF_XYZB1: dwSize += 1*4; break;
  784. case D3DFVF_XYZB2: dwSize += 2*4; break;
  785. case D3DFVF_XYZB3: dwSize += 3*4; break;
  786. case D3DFVF_XYZB4: dwSize += 4*4; break;
  787. case D3DFVF_XYZB5: dwSize += 5*4; break;
  788. }
  789. if (qwFVF & D3DFVF_NORMAL)
  790. dwSize += 3*4;
  791. if (qwFVF & D3DFVF_PSIZE)
  792. dwSize += 4;
  793. if (qwFVF & D3DFVF_DIFFUSE)
  794. dwSize += 4;
  795. if (qwFVF & D3DFVF_SPECULAR)
  796. dwSize += 4;
  797. if (qwFVF & D3DFVF_FOG)
  798. dwSize += 4;
  799. // Texture coordinates
  800. DWORD dwNumTexCoord = (DWORD)(FVF_TEXCOORD_NUMBER(qwFVF));
  801. DWORD dwTextureFormats = (DWORD)qwFVF >> 16;
  802. if (dwTextureFormats == 0)
  803. {
  804. dwSize += dwNumTexCoord * 2 * 4;
  805. }
  806. else
  807. {
  808. for (DWORD i=0; i < dwNumTexCoord; i++)
  809. {
  810. // dwSize += GetTexCoordDim( qwFVF, i ) * sizeof( float);
  811. dwSize += dwTextureSize[dwTextureFormats & 3];
  812. dwTextureFormats >>= 2;
  813. }
  814. }
  815. return dwSize;
  816. }
  817. #if 0
  818. //---------------------------------------------------------------------
  819. // ComputeTextureCoordSize:
  820. // Computes the following device data
  821. // - bTextureCoordSizeTotal
  822. // - bTextureCoordSize[] array, based on the input FVF id
  823. //---------------------------------------------------------------------
  824. __inline void ComputeTextureCoordInfo( DWORD dwFVF,
  825. LPDWORD pdwNumTexCoord,
  826. LPDWORD pdwTexCoordSizeArray )
  827. {
  828. // Texture formats size 00 01 10 11
  829. static BYTE bTextureSize[4] = {2*4, 3*4, 4*4, 4};
  830. DWORD dwNumTexCoord = FVF_TEXCOORD_NUMBER(dwFVF);
  831. *pdwNumTexCoord = dwNumTexCoord;
  832. // Compute texture coordinate size
  833. DWORD dwTextureFormats = dwFVF >> 16;
  834. if (dwTextureFormats == 0)
  835. {
  836. for (DWORD i=0; i < dwNumTexCoord; i++)
  837. pdwTexCoordSizeArray[i] = 4*2;
  838. }
  839. else
  840. {
  841. for (DWORD i=0; i < dwNumTexCoord; i++)
  842. {
  843. BYTE dwSize = bTextureSize[dwTextureFormats & 3];
  844. pdwTexCoordSizeArray[i] = dwSize;
  845. dwTextureFormats >>= 2;
  846. }
  847. }
  848. return;
  849. }
  850. #endif
  851. HRESULT
  852. RDFVFCheckAndStride( DWORD dwFVF, DWORD* pdwStride );
  853. ///////////////////////////////////////////////////////////////////////////////
  854. // Matrix and Vector routines
  855. ///////////////////////////////////////////////////////////////////////////////
  856. inline void
  857. ReverseVector(const RDVECTOR3 &in, RDVECTOR3 &out)
  858. {
  859. out.x = -in.x;
  860. out.y = -in.y;
  861. out.z = -in.z;
  862. }
  863. inline void
  864. AddVector(const RDVECTOR3 &v1, const RDVECTOR3 &v2, RDVECTOR3 &out)
  865. {
  866. out.x = v1.x + v2.x;
  867. out.y = v1.y + v2.y;
  868. out.z = v1.z + v2.z;
  869. }
  870. inline void
  871. SubtractVector(const RDVECTOR3 &v1, const RDVECTOR3 &v2, RDVECTOR3 &out)
  872. {
  873. out.x = v1.x - v2.x;
  874. out.y = v1.y - v2.y;
  875. out.z = v1.z - v2.z;
  876. }
  877. inline RDVECTOR3&
  878. ScaleVector(RDVECTOR3 &v, FLOAT scale)
  879. {
  880. v.x = v.x * scale;
  881. v.y = v.y * scale;
  882. v.z = v.z * scale;
  883. return v;
  884. }
  885. inline void
  886. SetIdentity(D3DMATRIX &m)
  887. {
  888. m._11 = m._22 = m._33 = m._44 = 1.0f;
  889. m._12 = m._13 = m._14 = 0.0f;
  890. m._21 = m._23 = m._24 = 0.0f;
  891. m._31 = m._32 = m._34 = 0.0f;
  892. m._41 = m._42 = m._43 = 0.0f;
  893. }
  894. inline void
  895. SetNull(D3DMATRIX &m)
  896. {
  897. m._11 = m._22 = m._33 = m._44 = 0.0f;
  898. m._12 = m._13 = m._14 = 0.0f;
  899. m._21 = m._23 = m._24 = 0.0f;
  900. m._31 = m._32 = m._34 = 0.0f;
  901. m._41 = m._42 = m._43 = 0.0f;
  902. }
  903. inline void
  904. CopyMatrix(D3DMATRIX &s, D3DMATRIX &d)
  905. {
  906. d._11 = s._11;
  907. d._12 = s._12;
  908. d._13 = s._13;
  909. d._14 = s._14;
  910. d._21 = s._21;
  911. d._22 = s._22;
  912. d._23 = s._23;
  913. d._24 = s._24;
  914. d._31 = s._31;
  915. d._32 = s._32;
  916. d._33 = s._33;
  917. d._34 = s._34;
  918. d._41 = s._41;
  919. d._42 = s._42;
  920. d._43 = s._43;
  921. d._44 = s._44;
  922. }
  923. inline D3DVALUE
  924. SquareMagnitude (const RDVECTOR3& v)
  925. {
  926. return v.x*v.x + v.y*v.y + v.z*v.z;
  927. }
  928. inline D3DVALUE
  929. Magnitude (const RDVECTOR3& v)
  930. {
  931. return (D3DVALUE) sqrt(SquareMagnitude(v));
  932. }
  933. inline RDVECTOR3
  934. Normalize (const RDVECTOR3& v)
  935. {
  936. RDVECTOR3 nv;
  937. D3DVALUE mag = Magnitude(v);
  938. if( FLOAT_NEZ( mag ) )
  939. {
  940. nv.x = v.x/mag;
  941. nv.y = v.y/mag;
  942. nv.z = v.z/mag;
  943. }
  944. return nv;
  945. }
  946. inline void
  947. Normalize (RDVECTOR3& v)
  948. {
  949. D3DVALUE mag = Magnitude(v);
  950. if( FLOAT_NEZ( mag ) )
  951. {
  952. v.x = v.x/mag;
  953. v.y = v.y/mag;
  954. v.z = v.z/mag;
  955. }
  956. else
  957. {
  958. v.x = v.y = v.z = 0.0f;
  959. }
  960. return;
  961. }
  962. inline RDVECTOR3
  963. CrossProduct (const RDVECTOR3& v1, const RDVECTOR3& v2)
  964. {
  965. RDVECTOR3 result;
  966. result.x = v1.y*v2.z - v1.z*v2.y;
  967. result.y = v1.z*v2.x - v1.x*v2.z;
  968. result.z = v1.x*v2.y - v1.y*v2.x;
  969. return result;
  970. }
  971. inline D3DVALUE
  972. DotProduct (const RDVECTOR3& v1, const RDVECTOR3& v2)
  973. {
  974. return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
  975. }
  976. //---------------------------------------------------------------------
  977. // Multiplies vector (x,y,z,w) by a 4x4 matrix transposed,
  978. // producing a homogeneous vector
  979. //
  980. // res and v should not be the same
  981. //---------------------------------------------------------------------
  982. inline void
  983. XformPlaneBy4x4Transposed(RDVECTOR4 *v, D3DMATRIX *m, RDVECTOR4 *res)
  984. {
  985. res->x = v->x*m->_11 + v->y*m->_12 + v->z*m->_13 + v->w*m->_14;
  986. res->y = v->x*m->_21 + v->y*m->_22 + v->z*m->_23 + v->w*m->_24;
  987. res->z = v->x*m->_31 + v->y*m->_32 + v->z*m->_33 + v->w*m->_34;
  988. res->w = v->x*m->_41 + v->y*m->_42 + v->z*m->_43 + v->w*m->_44;
  989. }
  990. //---------------------------------------------------------------------
  991. // Multiplies vector (x,y,z,w) by 4x4 matrix, producing a homogeneous vector
  992. //
  993. // res and v should not be the same
  994. //---------------------------------------------------------------------
  995. inline void
  996. XformPlaneBy4x4(RDVECTOR4 *v, D3DMATRIX *m, RDVECTOR4 *res)
  997. {
  998. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31 + v->w*m->_41;
  999. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32 + v->w*m->_42;
  1000. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33 + v->w*m->_43;
  1001. res->w = v->x*m->_14 + v->y*m->_24 + v->z*m->_34 + v->w*m->_44;
  1002. }
  1003. //---------------------------------------------------------------------
  1004. // Multiplies vector (x,y,z,1) by 4x4 matrix, producing a homogeneous vector
  1005. //
  1006. // res and v should not be the same
  1007. //---------------------------------------------------------------------
  1008. inline void
  1009. XformBy4x4(RDVECTOR3 *v, D3DMATRIX *m, RDVECTOR4 *res)
  1010. {
  1011. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31 + m->_41;
  1012. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32 + m->_42;
  1013. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33 + m->_43;
  1014. res->w = v->x*m->_14 + v->y*m->_24 + v->z*m->_34 + m->_44;
  1015. }
  1016. //---------------------------------------------------------------------
  1017. // Multiplies vector (x,y,z,1) by 4x3 matrix
  1018. //
  1019. // res and v should not be the same
  1020. //---------------------------------------------------------------------
  1021. inline void
  1022. XformBy4x3(RDVECTOR3 *v, D3DMATRIX *m, RDVECTOR3 *res)
  1023. {
  1024. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31 + m->_41;
  1025. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32 + m->_42;
  1026. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33 + m->_43;
  1027. }
  1028. //---------------------------------------------------------------------
  1029. // Multiplies vector (x,y,z) by 3x3 matrix
  1030. //
  1031. // res and v should not be the same
  1032. //---------------------------------------------------------------------
  1033. inline void
  1034. Xform3VecBy3x3(RDVECTOR3 *v, D3DMATRIX *m, RDVECTOR3 *res)
  1035. {
  1036. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31;
  1037. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32;
  1038. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33;
  1039. }
  1040. //---------------------------------------------------------------------
  1041. // This function uses Cramer's Rule to calculate the matrix inverse.
  1042. // See nt\private\windows\opengl\serever\soft\so_math.c
  1043. //
  1044. // Returns:
  1045. // 0 - if success
  1046. // -1 - if input matrix is singular
  1047. //---------------------------------------------------------------------
  1048. int Inverse4x4(D3DMATRIX *src, D3DMATRIX *inverse);
  1049. //---------------------------------------------------------------------
  1050. // Make RDCOLOR3 from a Packed DWORD
  1051. //---------------------------------------------------------------------
  1052. inline void MakeRDCOLOR3( RDCOLOR3 *out, DWORD inputColor )
  1053. {
  1054. out->r = (D3DVALUE)RGBA_GETRED( inputColor );
  1055. out->g = (D3DVALUE)RGBA_GETGREEN( inputColor );
  1056. out->b = (D3DVALUE)RGBA_GETBLUE( inputColor );
  1057. }
  1058. //---------------------------------------------------------------------
  1059. // Make RDCOLOR4 from a Packed DWORD
  1060. //---------------------------------------------------------------------
  1061. inline void MakeRDCOLOR4( RDCOLOR4 *out, DWORD inputColor )
  1062. {
  1063. out->a = (D3DVALUE)RGBA_GETALPHA( inputColor )/255.0f;
  1064. out->r = (D3DVALUE)RGBA_GETRED ( inputColor )/255.0f;
  1065. out->g = (D3DVALUE)RGBA_GETGREEN( inputColor )/255.0f;
  1066. out->b = (D3DVALUE)RGBA_GETBLUE ( inputColor )/255.0f;
  1067. }
  1068. ////////////////////////////////////////////////////////////////////////
  1069. //
  1070. // Macros used to access DDRAW surface info.
  1071. //
  1072. ////////////////////////////////////////////////////////////////////////
  1073. #define DDSurf_Width(lpLcl) ( (lpLcl)->lpGbl->wWidth )
  1074. #define DDSurf_Pitch(lpLcl) ( (lpLcl)->lpGbl->lPitch )
  1075. #define DDSurf_Height(lpLcl) ( (lpLcl)->lpGbl->wHeight )
  1076. #define DDSurf_BitDepth(lpLcl) \
  1077. ( (lpLcl->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? \
  1078. (lpLcl->lpGbl->ddpfSurface.dwRGBBitCount) : \
  1079. (lpLcl->lpGbl->lpDD->vmiData.ddpfDisplay.dwRGBBitCount) \
  1080. )
  1081. #define DDSurf_PixFmt(lpLcl) \
  1082. ( ((lpLcl)->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? \
  1083. ((lpLcl)->lpGbl->ddpfSurface) : \
  1084. ((lpLcl)->lpGbl->lpDD->vmiData.ddpfDisplay) \
  1085. )
  1086. #define VIDEO_MEMORY(pDDSLcl) \
  1087. (!((pDDSLcl)->lpGbl->dwGlobalFlags & DDRAWISURFGBL_SYSMEMREQUESTED))
  1088. #define SURFACE_LOCKED(pDDSLcl) \
  1089. ((pDDSLcl)->lpGbl->dwUsageCount > 0)
  1090. #define SURFACE_MEMORY(surfLcl) \
  1091. (LPVOID)((surfLcl)->lpGbl->fpVidMem)
  1092. //---------------------------------------------------------------------
  1093. // DDraw extern functions
  1094. //---------------------------------------------------------------------
  1095. extern "C" HRESULT WINAPI
  1096. DDInternalLock( LPDDRAWI_DDRAWSURFACE_LCL this_lcl, LPVOID* lpBits );
  1097. extern "C" HRESULT WINAPI
  1098. DDInternalUnlock( LPDDRAWI_DDRAWSURFACE_LCL this_lcl );
  1099. HRESULT DDGetAttachedSurfaceLcl(
  1100. LPDDRAWI_DDRAWSURFACE_LCL this_lcl,
  1101. LPDDSCAPS2 lpDDSCaps,
  1102. LPDDRAWI_DDRAWSURFACE_LCL *lplpDDAttachedSurfaceLcl);
  1103. extern "C" LPDDRAWI_DDRAWSURFACE_LCL WINAPI
  1104. GetDDSurfaceLocal( LPDDRAWI_DIRECTDRAW_LCL this_lcl, DWORD handle, BOOL* isnew );
  1105. //---------------------------------------------------------------------
  1106. // RDListEntry:
  1107. //
  1108. // To support singly linked lists with no deletion of entries. Useful
  1109. // for active lists (Active Lights etc.)
  1110. //---------------------------------------------------------------------
  1111. struct RDListEntry
  1112. {
  1113. RDListEntry(){m_pNext = NULL;}
  1114. virtual ~RDListEntry(){}
  1115. // Seek to the end of the chain and append
  1116. void Append(RDListEntry* p)
  1117. {
  1118. if( m_pNext == NULL )
  1119. {
  1120. m_pNext = p;
  1121. return;
  1122. }
  1123. RDListEntry* c = m_pNext;
  1124. while( c->m_pNext ) c = c->m_pNext;
  1125. c->m_pNext = p;
  1126. }
  1127. RDListEntry *Next() { return m_pNext; }
  1128. RDListEntry * m_pNext;
  1129. };
  1130. //---------------------------------------------------------------------
  1131. // Registry access
  1132. //---------------------------------------------------------------------
  1133. #define RESPATH_D3D "Software\\Microsoft\\Direct3D"
  1134. #define RESPATH_D3DREF RESPATH_D3D "\\ReferenceDevice"
  1135. BOOL GetD3DRegValue(DWORD type, char *valueName, LPVOID value, DWORD dwSize);
  1136. BOOL GetD3DRefRegValue(DWORD type, char *valueName, LPVOID value, DWORD dwSize);
  1137. ///////////////////////////////////////////////////////////////////////////////
  1138. #endif // _RDCOMM_HPP