Counter Strike : Global Offensive Source Code
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.

2377 lines
91 KiB

  1. //================ Copyright (c) 1996-2009 Valve Corporation. All Rights Reserved. =================
  2. //
  3. //
  4. //
  5. //==================================================================================================
  6. #ifdef _PS3
  7. // Delegate to the correct dxabstract,
  8. // code in other files seem to include dxabstract
  9. // in a lot of places without platform specialization
  10. #include "../ps3gcm/dxabstract.h"
  11. #include "ps3/dxabstract_gcm_shared.h"
  12. #else
  13. #ifndef DXABSTRACT_H
  14. #define DXABSTRACT_H
  15. #ifdef _WIN32
  16. #pragma once
  17. #endif
  18. #include "materialsystem/IShader.h"
  19. // Uncomment this on Windows if you want to compile the Windows GL version.
  20. // #undef USE_ACTUAL_DX
  21. #ifdef USE_ACTUAL_DX
  22. #ifndef WIN32
  23. #error sorry man
  24. #endif
  25. #ifdef _X360
  26. #include "d3d9.h"
  27. #include "d3dx9.h"
  28. #else
  29. #include <windows.h>
  30. #include "../../dx9sdk/include/d3d9.h"
  31. #include "../../dx9sdk/include/d3dx9.h"
  32. #endif
  33. typedef HWND VD3DHWND;
  34. #else
  35. #ifdef WIN32
  36. #error Gl on win32?
  37. #endif
  38. #include "tier0/platform.h"
  39. #define DX_TO_GL_ABSTRACTION
  40. #include "bitmap/imageformat.h"
  41. #include "glmgr/glmgr.h"
  42. extern "C" void Debugger(void);
  43. // ------------------------------------------------------------------------------------------------------------------------------ //
  44. // DEFINES
  45. // ------------------------------------------------------------------------------------------------------------------------------ //
  46. typedef void* VD3DHWND;
  47. typedef void* VD3DHANDLE;
  48. //
  49. //
  50. // Stuff that would be in windows.h
  51. //
  52. //
  53. #ifdef _WINNT_
  54. #error "No interoperability with windows.h!"
  55. #else
  56. typedef int INT;
  57. typedef unsigned long ULONG;
  58. typedef long LONG;
  59. typedef float FLOAT;
  60. typedef unsigned int DWORD;
  61. typedef unsigned short WORD;
  62. typedef long long LONGLONG;
  63. typedef unsigned int UINT;
  64. typedef long HRESULT;
  65. typedef unsigned char BYTE;
  66. #define CONST const
  67. typedef unsigned long ULONG_PTR;
  68. typedef ULONG_PTR SIZE_T;
  69. typedef const char* LPCSTR;
  70. typedef char* LPSTR;
  71. typedef DWORD* LPDWORD;
  72. #define ZeroMemory RtlZeroMemory
  73. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  74. typedef union _LARGE_INTEGER {
  75. struct {
  76. DWORD LowPart;
  77. LONG HighPart;
  78. };
  79. struct {
  80. DWORD LowPart;
  81. LONG HighPart;
  82. } u;
  83. LONGLONG QuadPart;
  84. } LARGE_INTEGER;
  85. typedef struct _GUID {
  86. bool operator==( const struct _GUID &other ) const;
  87. unsigned long Data1;
  88. unsigned short Data2;
  89. unsigned short Data3;
  90. unsigned char Data4[ 8 ];
  91. } GUID;
  92. typedef struct _RECT {
  93. int left;
  94. int top;
  95. int right;
  96. int bottom;
  97. } RECT;
  98. // turn this on to get refcount logging from IUnknown
  99. #define IUNKNOWN_ALLOC_SPEW 0
  100. #define IUNKNOWN_ALLOC_SPEW_MARK_ALL 0
  101. struct IUnknown
  102. {
  103. public:
  104. int m_refcount[2];
  105. bool m_mark;
  106. IUnknown( void )
  107. {
  108. m_refcount[0] = 1;
  109. m_refcount[1] = 0;
  110. m_mark = (IUNKNOWN_ALLOC_SPEW_MARK_ALL != 0); // either all are marked, or only the ones that have SetMark(true) called on them
  111. #if IUNKNOWN_ALLOC_SPEW
  112. if (m_mark)
  113. {
  114. GLMPRINTF(("-A- IUnew (%08x) refc -> (%d,%d) ",this,m_refcount[0],m_refcount[1]));
  115. }
  116. #endif
  117. };
  118. virtual ~IUnknown( void )
  119. {
  120. #if IUNKNOWN_ALLOC_SPEW
  121. if (m_mark)
  122. {
  123. GLMPRINTF(("-A- IUdel (%08x) ",this ));
  124. }
  125. #endif
  126. };
  127. void AddRef( int which=0, char *comment = NULL )
  128. {
  129. Assert( which >= 0 );
  130. Assert( which < 2 );
  131. m_refcount[which]++;
  132. #if IUNKNOWN_ALLOC_SPEW
  133. if (m_mark)
  134. {
  135. GLMPRINTF(("-A- IUAddRef (%08x,%d) refc -> (%d,%d) [%s]",this,which,m_refcount[0],m_refcount[1],comment?comment:"...")) ;
  136. if (!comment)
  137. {
  138. GLMPRINTF(("")) ; // place to hang a breakpoint
  139. }
  140. }
  141. #endif
  142. };
  143. ULONG __stdcall Release( int which=0, char *comment = NULL )
  144. {
  145. Assert( which >= 0 );
  146. Assert( which < 2 );
  147. //int oldrefcs[2] = { m_refcount[0], m_refcount[1] };
  148. bool deleting = false;
  149. m_refcount[which]--;
  150. if ( (!m_refcount[0]) && (!m_refcount[1]) )
  151. {
  152. deleting = true;
  153. }
  154. #if IUNKNOWN_ALLOC_SPEW
  155. if (m_mark)
  156. {
  157. GLMPRINTF(("-A- IURelease (%08x,%d) refc -> (%d,%d) [%s] %s",this,which,m_refcount[0],m_refcount[1],comment?comment:"...",deleting?"->DELETING":""));
  158. if (!comment)
  159. {
  160. GLMPRINTF(("")) ; // place to hang a breakpoint
  161. }
  162. }
  163. #endif
  164. if (deleting)
  165. {
  166. if (m_mark)
  167. {
  168. GLMPRINTF(("")) ; // place to hang a breakpoint
  169. }
  170. delete this;
  171. return 0;
  172. }
  173. else
  174. {
  175. return m_refcount[0];
  176. }
  177. };
  178. void SetMark( bool markValue, char *comment=NULL )
  179. {
  180. #if IUNKNOWN_ALLOC_SPEW
  181. if (!m_mark && markValue) // leading edge detect
  182. {
  183. // print the same thing that the constructor would have printed if it had been marked from the beginning
  184. // i.e. it's anticipated that callers asking for marking will do so right at create time
  185. GLMPRINTF(("-A- IUSetMark (%08x) refc -> (%d,%d) (%s) ",this,m_refcount[0],m_refcount[1],comment?comment:"..."));
  186. }
  187. #endif
  188. m_mark = markValue;
  189. }
  190. };
  191. typedef struct tagPOINT
  192. {
  193. LONG x;
  194. LONG y;
  195. } POINT, *PPOINT, *LPPOINT;
  196. typedef struct _MEMORYSTATUS {
  197. DWORD dwLength;
  198. SIZE_T dwTotalPhys;
  199. } MEMORYSTATUS, *LPMEMORYSTATUS;
  200. typedef DWORD COLORREF;
  201. #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))
  202. #define MAKE_HRESULT(sev,fac,code) \
  203. ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
  204. #define S_FALSE ((HRESULT)0x00000001L)
  205. #define S_OK 0
  206. #define E_OUTOFMEMORY ((HRESULT)(0x8007000EL))
  207. #define FAILED(hr) ((HRESULT)(hr) < 0)
  208. #define SUCCEEDED(hr) ((HRESULT)(hr) >= 0)
  209. #define MAKEFOURCC(ch0, ch1, ch2, ch3) \
  210. ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
  211. ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))
  212. struct RGNDATA
  213. {
  214. public:
  215. };
  216. void Sleep( unsigned int ms );
  217. bool IsIconic( VD3DHWND hWnd );
  218. void GetClientRect( VD3DHWND hWnd, RECT *destRect );
  219. BOOL ClientToScreen( VD3DHWND hWnd, LPPOINT pPoint );
  220. typedef const void* LPCVOID;
  221. void* GetCurrentThread();
  222. void SetThreadAffinityMask( void *hThread, int nMask );
  223. void GlobalMemoryStatus( MEMORYSTATUS *pOut );
  224. #endif
  225. #define D3DSI_OPCODE_MASK 0x0000FFFF
  226. #define D3DSP_TEXTURETYPE_MASK 0x78000000
  227. #define D3DUSAGE_AUTOGENMIPMAP (0x00000400L)
  228. #define D3DSP_DCL_USAGE_MASK 0x0000000f
  229. #define D3DSP_OPCODESPECIFICCONTROL_MASK 0x00ff0000
  230. #define D3DSP_OPCODESPECIFICCONTROL_SHIFT 16
  231. /* Flags to construct D3DRS_COLORWRITEENABLE */
  232. #define D3DCOLORWRITEENABLE_RED (1L<<0)
  233. #define D3DCOLORWRITEENABLE_GREEN (1L<<1)
  234. #define D3DCOLORWRITEENABLE_BLUE (1L<<2)
  235. #define D3DCOLORWRITEENABLE_ALPHA (1L<<3)
  236. #define D3DSGR_NO_CALIBRATION 0x00000000L
  237. #define D3DXINLINE inline
  238. #define D3D_SDK_VERSION 32
  239. #define _FACD3D 0x876
  240. #define MAKE_D3DHRESULT( code ) MAKE_HRESULT( 1, _FACD3D, code )
  241. #define D3DERR_NOTFOUND MAKE_D3DHRESULT(2150)
  242. #define D3DERR_DEVICELOST MAKE_D3DHRESULT(2152)
  243. #define D3DERR_NOTAVAILABLE MAKE_D3DHRESULT(2154)
  244. #define D3DERR_DEVICENOTRESET MAKE_D3DHRESULT(2153)
  245. #define D3DERR_INVALIDCALL MAKE_D3DHRESULT(2156)
  246. #define D3DERR_DRIVERINTERNALERROR MAKE_D3DHRESULT(2087)
  247. #define D3DERR_OUTOFVIDEOMEMORY MAKE_D3DHRESULT(380)
  248. #define D3D_OK S_OK
  249. #define D3DPRESENT_RATE_DEFAULT 0x00000000
  250. //
  251. // DevCaps
  252. //
  253. // we need to see who in Source land is interested in these values, as dxabstract is currently reporting zero for the whole Caps word
  254. #define D3DDEVCAPS_EXECUTESYSTEMMEMORY 0x00000010L /* Device can use execute buffers from system memory */
  255. #define D3DDEVCAPS_TLVERTEXSYSTEMMEMORY 0x00000040L /* Device can use TL buffers from system memory */
  256. #define D3DDEVCAPS_TLVERTEXVIDEOMEMORY 0x00000080L /* Device can use TL buffers from video memory */
  257. #define D3DDEVCAPS_TEXTURESYSTEMMEMORY 0x00000100L /* Device can texture from system memory */
  258. #define D3DDEVCAPS_TEXTUREVIDEOMEMORY 0x00000200L /* Device can texture from device memory */
  259. #define D3DDEVCAPS_DRAWPRIMTLVERTEX 0x00000400L /* Device can draw TLVERTEX primitives */
  260. #define D3DDEVCAPS_CANRENDERAFTERFLIP 0x00000800L /* Device can render without waiting for flip to complete */
  261. #define D3DDEVCAPS_TEXTURENONLOCALVIDMEM 0x00001000L /* Device can texture from nonlocal video memory */
  262. #define D3DDEVCAPS_SEPARATETEXTUREMEMORIES 0x00004000L /* Device is texturing from separate memory pools */
  263. #define D3DDEVCAPS_HWTRANSFORMANDLIGHT 0x00010000L /* Device can support transformation and lighting in hardware and DRAWPRIMITIVES2EX must be also */
  264. #define D3DDEVCAPS_CANBLTSYSTONONLOCAL 0x00020000L /* Device supports a Tex Blt from system memory to non-local vidmem */
  265. #define D3DDEVCAPS_HWRASTERIZATION 0x00080000L /* Device has HW acceleration for rasterization */
  266. #define D3DDEVCAPS_PUREDEVICE 0x00100000L /* Device supports D3DCREATE_PUREDEVICE */
  267. #define D3DDEVCAPS_QUINTICRTPATCHES 0x00200000L /* Device supports quintic Beziers and BSplines */
  268. #define D3DDEVCAPS_RTPATCHHANDLEZERO 0x00800000L /* Indicates that RT Patches may be drawn efficiently using handle 0 */
  269. #define D3DDEVCAPS_NPATCHES 0x01000000L /* Device supports N-Patches */
  270. //
  271. // PrimitiveMiscCaps
  272. //
  273. #define D3DPMISCCAPS_MASKZ 0x00000002L
  274. #define D3DPMISCCAPS_CULLNONE 0x00000010L
  275. #define D3DPMISCCAPS_CULLCW 0x00000020L
  276. #define D3DPMISCCAPS_CULLCCW 0x00000040L
  277. #define D3DPMISCCAPS_COLORWRITEENABLE 0x00000080L
  278. #define D3DPMISCCAPS_CLIPPLANESCALEDPOINTS 0x00000100L /* Device correctly clips scaled points to clip planes */
  279. #define D3DPMISCCAPS_CLIPTLVERTS 0x00000200L /* device will clip post-transformed vertex primitives */
  280. #define D3DPMISCCAPS_TSSARGTEMP 0x00000400L /* device supports D3DTA_TEMP for temporary register */
  281. #define D3DPMISCCAPS_BLENDOP 0x00000800L /* device supports D3DRS_BLENDOP */
  282. #define D3DPMISCCAPS_NULLREFERENCE 0x00001000L /* Reference Device that doesnt render */
  283. #define D3DPMISCCAPS_PERSTAGECONSTANT 0x00008000L /* Device supports per-stage constants */
  284. #define D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS 0x00040000L /* Device supports different bit depths for MRT */
  285. #define D3DPMISCCAPS_FOGVERTEXCLAMPED 0x00100000L /* Device clamps fog blend factor per vertex */
  286. // Flags field for Issue
  287. #define D3DISSUE_END (1 << 0) // Tells the runtime to issue the end of a query, changing it's state to "non-signaled".
  288. #define D3DISSUE_BEGIN (1 << 1) // Tells the runtime to issue the beginng of a query.
  289. #define D3DPRESENT_INTERVAL_ONE 0x00000001L
  290. #define D3DPRESENT_INTERVAL_IMMEDIATE 0x80000000L
  291. /*
  292. * Options for clearing
  293. */
  294. #define D3DCLEAR_TARGET 0x00000001l /* Clear target surface */
  295. #define D3DCLEAR_ZBUFFER 0x00000002l /* Clear target z buffer */
  296. #define D3DCLEAR_STENCIL 0x00000004l /* Clear stencil planes */
  297. #define D3DENUM_WHQL_LEVEL 0x00000002L
  298. #define D3DPTEXTURECAPS_NOPROJECTEDBUMPENV 0x00200000L /* Device does not support projected bump env lookup operation
  299. in programmable and fixed function pixel shaders */
  300. #define D3DDEVCAPS2_STREAMOFFSET 0x00000001L /* Device supports offsets in streams. Must be set by DX9 drivers */
  301. #define D3DDEVCAPS_PUREDEVICE 0x00100000L /* Device supports D3DCREATE_PUREDEVICE */
  302. #define D3DCREATE_PUREDEVICE 0x00000010L
  303. #define D3DCREATE_SOFTWARE_VERTEXPROCESSING 0x00000020L
  304. #define D3DCREATE_HARDWARE_VERTEXPROCESSING 0x00000040L
  305. #define D3DCREATE_FPU_PRESERVE 0x00000002L
  306. #define D3DPRASTERCAPS_FOGRANGE 0x00010000L
  307. #define D3DPRASTERCAPS_FOGTABLE 0x00000100L
  308. #define D3DPRASTERCAPS_FOGVERTEX 0x00000080L
  309. #define D3DPRASTERCAPS_WFOG 0x00100000L
  310. #define D3DPRASTERCAPS_ZFOG 0x00200000L
  311. #define D3DPRASTERCAPS_MIPMAPLODBIAS 0x00002000L
  312. #define D3DPRASTERCAPS_WBUFFER 0x00040000L
  313. #define D3DPRASTERCAPS_ZTEST 0x00000010L
  314. //
  315. // Caps2
  316. //
  317. #define D3DCAPS2_CANCALIBRATEGAMMA 0x00100000L
  318. #define D3DPRASTERCAPS_SCISSORTEST 0x01000000L
  319. #define D3DPTEXTURECAPS_MIPCUBEMAP 0x00010000L /* Device can do mipmapped cube maps */
  320. #define D3DPTEXTURECAPS_ALPHA 0x00000004L /* Alpha in texture pixels is supported */
  321. #define D3DPTEXTURECAPS_SQUAREONLY 0x00000020L /* Only square textures are supported */
  322. #define D3DCREATE_MULTITHREADED 0x00000004L
  323. #define D3DDEVCAPS_HWTRANSFORMANDLIGHT 0x00010000L /* Device can support transformation and lighting in hardware and DRAWPRIMITIVES2EX must be also */
  324. #define D3DPTFILTERCAPS_MINFANISOTROPIC 0x00000400L
  325. #define D3DPTFILTERCAPS_MAGFANISOTROPIC 0x04000000L
  326. #define D3DPTEXTURECAPS_CUBEMAP 0x00000800L /* Device can do cubemap textures */
  327. #define D3DPTEXTURECAPS_POW2 0x00000002L /* Power-of-2 texture dimensions are required - applies to non-Cube/Volume textures only. */
  328. #define D3DPTEXTURECAPS_NONPOW2CONDITIONAL 0x00000100L
  329. #define D3DPTEXTURECAPS_PROJECTED 0x00000400L /* Device can do D3DTTFF_PROJECTED */
  330. #define D3DTEXOPCAPS_ADD 0x00000040L
  331. #define D3DTEXOPCAPS_MODULATE2X 0x00000010L
  332. #define D3DPRASTERCAPS_DEPTHBIAS 0x04000000L
  333. #define D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS 0x02000000L
  334. #define D3DVTXPCAPS_TEXGEN_SPHEREMAP 0x00000100L /* device supports D3DTSS_TCI_SPHEREMAP */
  335. #define D3DCAPS2_DYNAMICTEXTURES 0x20000000L
  336. // The following usages are valid only for querying CheckDeviceFormat
  337. #define D3DUSAGE_QUERY_SRGBREAD (0x00010000L)
  338. #define D3DUSAGE_QUERY_FILTER (0x00020000L)
  339. #define D3DUSAGE_QUERY_SRGBWRITE (0x00040000L)
  340. #define D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING (0x00080000L)
  341. #define D3DUSAGE_QUERY_VERTEXTEXTURE (0x00100000L)
  342. /* Usages for Vertex/Index buffers */
  343. #define D3DUSAGE_WRITEONLY (0x00000008L)
  344. #define D3DUSAGE_SOFTWAREPROCESSING (0x00000010L)
  345. #define D3DUSAGE_DONOTCLIP (0x00000020L)
  346. #define D3DUSAGE_POINTS (0x00000040L)
  347. #define D3DUSAGE_RTPATCHES (0x00000080L)
  348. #define D3DUSAGE_NPATCHES (0x00000100L)
  349. // Flags field for GetData
  350. #define D3DGETDATA_FLUSH (1 << 0) // Tells the runtime to flush if the query is outstanding.
  351. #define D3DFVF_XYZ 0x002
  352. #define D3DTA_SELECTMASK 0x0000000f // mask for arg selector
  353. #define D3DTA_DIFFUSE 0x00000000 // select diffuse color (read only)
  354. #define D3DTA_CURRENT 0x00000001 // select stage destination register (read/write)
  355. #define D3DTA_TEXTURE 0x00000002 // select texture color (read only)
  356. #define D3DTA_TFACTOR 0x00000003 // select D3DRS_TEXTUREFACTOR (read only)
  357. #define D3DTA_SPECULAR 0x00000004 // select specular color (read only)
  358. #define D3DTA_TEMP 0x00000005 // select temporary register color (read/write)
  359. #define D3DTA_CONSTANT 0x00000006 // select texture stage constant
  360. #define D3DTA_COMPLEMENT 0x00000010 // take 1.0 - x (read modifier)
  361. #define D3DTA_ALPHAREPLICATE 0x00000020 // replicate alpha to color components (read modifier)
  362. #define D3DUSAGE_RENDERTARGET (0x00000001L)
  363. #define D3DUSAGE_QUERY_VERTEXTEXTURE (0x00100000L)
  364. #define D3DUSAGE_QUERY_FILTER (0x00020000L)
  365. #define D3DUSAGE_DEPTHSTENCIL (0x00000002L)
  366. #define D3DUSAGE_WRITEONLY (0x00000008L)
  367. #define D3DUSAGE_SOFTWAREPROCESSING (0x00000010L)
  368. #define D3DUSAGE_DYNAMIC (0x00000200L)
  369. #define D3DSI_INSTLENGTH_MASK 0x0F000000
  370. #define D3DSI_INSTLENGTH_SHIFT 24
  371. #define D3DSP_TEXTURETYPE_SHIFT 27
  372. #define D3DSP_REGTYPE_SHIFT 28
  373. #define D3DSP_REGTYPE_SHIFT2 8
  374. #define D3DSP_REGTYPE_MASK 0x70000000
  375. #define D3DSP_REGTYPE_MASK2 0x00001800
  376. #define D3DSP_REGNUM_MASK 0x000007FF
  377. #define D3DSP_DSTMOD_SHIFT 20
  378. #define D3DSP_DSTMOD_MASK 0x00F00000
  379. #define D3DSPDM_MSAMPCENTROID (4<<D3DSP_DSTMOD_SHIFT) // Relevant to multisampling only:
  380. // When the pixel center is not covered, sample
  381. // attribute or compute gradients/LOD
  382. // using multisample "centroid" location.
  383. // "Centroid" is some location within the covered
  384. // region of the pixel.
  385. #define D3DXSHADER_DEBUG (1 << 0)
  386. #define D3DXSHADER_AVOID_FLOW_CONTROL (1 << 9)
  387. #define D3DLOCK_READONLY 0x00000010L
  388. #define D3DLOCK_DISCARD 0x00002000L
  389. #define D3DLOCK_NOOVERWRITE 0x00001000L
  390. #define D3DLOCK_NOSYSLOCK 0x00000800L
  391. #define D3DLOCK_NO_DIRTY_UPDATE 0x00008000L
  392. #define D3DDMAPSAMPLER 256
  393. #define D3DVERTEXTEXTURESAMPLER0 (D3DDMAPSAMPLER+1)
  394. #define D3DSP_SRCMOD_SHIFT 24
  395. #define D3DCOLOR_ARGB(a,r,g,b) \
  396. ((D3DCOLOR)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
  397. #define D3DCOLOR_RGBA(r,g,b,a) D3DCOLOR_ARGB(a,r,g,b)
  398. #define D3DCOLOR_XRGB(r,g,b) D3DCOLOR_ARGB(0xff,r,g,b)
  399. // maps floating point channels (0.f to 1.f range) to D3DCOLOR
  400. #define D3DCOLOR_COLORVALUE(r,g,b,a) \
  401. D3DCOLOR_RGBA((DWORD)((r)*255.f),(DWORD)((g)*255.f),(DWORD)((b)*255.f),(DWORD)((a)*255.f))
  402. #define D3DDECL_END() {0xFF,0,D3DDECLTYPE_UNUSED,0,0,0}
  403. #define D3DSP_DCL_USAGEINDEX_SHIFT 16
  404. #define D3DSP_DCL_USAGEINDEX_MASK 0x000f0000
  405. // Bit masks for destination parameter modifiers
  406. #define D3DSPDM_NONE (0<<D3DSP_DSTMOD_SHIFT) // nop
  407. #define D3DSPDM_SATURATE (1<<D3DSP_DSTMOD_SHIFT) // clamp to 0. to 1. range
  408. #define D3DSPDM_PARTIALPRECISION (2<<D3DSP_DSTMOD_SHIFT) // Partial precision hint
  409. #define D3DSPDM_MSAMPCENTROID (4<<D3DSP_DSTMOD_SHIFT) // Relevant to multisampling only:
  410. // When the pixel center is not covered, sample
  411. // attribute or compute gradients/LOD
  412. // using multisample "centroid" location.
  413. // "Centroid" is some location within the covered
  414. // region of the pixel.
  415. // Value when there is no swizzle (X is taken from X, Y is taken from Y,
  416. // Z is taken from Z, W is taken from W
  417. //
  418. #define D3DVS_NOSWIZZLE (D3DVS_X_X | D3DVS_Y_Y | D3DVS_Z_Z | D3DVS_W_W)
  419. // extract major/minor from version cap
  420. #define D3DSHADER_VERSION_MAJOR(_Version) (((_Version)>>8)&0xFF)
  421. #define D3DSHADER_VERSION_MINOR(_Version) (((_Version)>>0)&0xFF)
  422. #define D3DSHADER_ADDRESSMODE_SHIFT 13
  423. #define D3DSHADER_ADDRESSMODE_MASK (1 << D3DSHADER_ADDRESSMODE_SHIFT)
  424. #define D3DPS_END() 0x0000FFFF
  425. // ps_2_0 texld controls
  426. #define D3DSI_TEXLD_PROJECT (0x01 << D3DSP_OPCODESPECIFICCONTROL_SHIFT)
  427. #define D3DSI_TEXLD_BIAS (0x02 << D3DSP_OPCODESPECIFICCONTROL_SHIFT)
  428. // destination parameter write mask
  429. #define D3DSP_WRITEMASK_0 0x00010000 // Component 0 (X;Red)
  430. #define D3DSP_WRITEMASK_1 0x00020000 // Component 1 (Y;Green)
  431. #define D3DSP_WRITEMASK_2 0x00040000 // Component 2 (Z;Blue)
  432. #define D3DSP_WRITEMASK_3 0x00080000 // Component 3 (W;Alpha)
  433. #define D3DSP_WRITEMASK_ALL 0x000F0000 // All Components
  434. #define D3DVS_SWIZZLE_SHIFT 16
  435. #define D3DVS_SWIZZLE_MASK 0x00FF0000
  436. // The following bits define where to take component X from:
  437. #define D3DVS_X_X (0 << D3DVS_SWIZZLE_SHIFT)
  438. #define D3DVS_X_Y (1 << D3DVS_SWIZZLE_SHIFT)
  439. #define D3DVS_X_Z (2 << D3DVS_SWIZZLE_SHIFT)
  440. #define D3DVS_X_W (3 << D3DVS_SWIZZLE_SHIFT)
  441. // The following bits define where to take component Y from:
  442. #define D3DVS_Y_X (0 << (D3DVS_SWIZZLE_SHIFT + 2))
  443. #define D3DVS_Y_Y (1 << (D3DVS_SWIZZLE_SHIFT + 2))
  444. #define D3DVS_Y_Z (2 << (D3DVS_SWIZZLE_SHIFT + 2))
  445. #define D3DVS_Y_W (3 << (D3DVS_SWIZZLE_SHIFT + 2))
  446. // The following bits define where to take component Z from:
  447. #define D3DVS_Z_X (0 << (D3DVS_SWIZZLE_SHIFT + 4))
  448. #define D3DVS_Z_Y (1 << (D3DVS_SWIZZLE_SHIFT + 4))
  449. #define D3DVS_Z_Z (2 << (D3DVS_SWIZZLE_SHIFT + 4))
  450. #define D3DVS_Z_W (3 << (D3DVS_SWIZZLE_SHIFT + 4))
  451. // The following bits define where to take component W from:
  452. #define D3DVS_W_X (0 << (D3DVS_SWIZZLE_SHIFT + 6))
  453. #define D3DVS_W_Y (1 << (D3DVS_SWIZZLE_SHIFT + 6))
  454. #define D3DVS_W_Z (2 << (D3DVS_SWIZZLE_SHIFT + 6))
  455. #define D3DVS_W_W (3 << (D3DVS_SWIZZLE_SHIFT + 6))
  456. // source parameter modifiers
  457. #define D3DSP_SRCMOD_SHIFT 24
  458. #define D3DSP_SRCMOD_MASK 0x0F000000
  459. struct IDirect3DSurface9;
  460. struct IDirect3DDevice9;
  461. struct IDirect3DCubeTexture9;
  462. struct IDirect3DVertexDeclaration9;
  463. struct IDirect3DQuery9;
  464. // ------------------------------------------------------------------------------------------------------------------------------ //
  465. // ENUMS
  466. // ------------------------------------------------------------------------------------------------------------------------------ //
  467. typedef enum _D3DSHADER_PARAM_SRCMOD_TYPE
  468. {
  469. D3DSPSM_NONE = 0<<D3DSP_SRCMOD_SHIFT, // nop
  470. D3DSPSM_NEG = 1<<D3DSP_SRCMOD_SHIFT, // negate
  471. D3DSPSM_BIAS = 2<<D3DSP_SRCMOD_SHIFT, // bias
  472. D3DSPSM_BIASNEG = 3<<D3DSP_SRCMOD_SHIFT, // bias and negate
  473. D3DSPSM_SIGN = 4<<D3DSP_SRCMOD_SHIFT, // sign
  474. D3DSPSM_SIGNNEG = 5<<D3DSP_SRCMOD_SHIFT, // sign and negate
  475. D3DSPSM_COMP = 6<<D3DSP_SRCMOD_SHIFT, // complement
  476. D3DSPSM_X2 = 7<<D3DSP_SRCMOD_SHIFT, // *2
  477. D3DSPSM_X2NEG = 8<<D3DSP_SRCMOD_SHIFT, // *2 and negate
  478. D3DSPSM_DZ = 9<<D3DSP_SRCMOD_SHIFT, // divide through by z component
  479. D3DSPSM_DW = 10<<D3DSP_SRCMOD_SHIFT, // divide through by w component
  480. D3DSPSM_ABS = 11<<D3DSP_SRCMOD_SHIFT, // abs()
  481. D3DSPSM_ABSNEG = 12<<D3DSP_SRCMOD_SHIFT, // -abs()
  482. D3DSPSM_NOT = 13<<D3DSP_SRCMOD_SHIFT, // for predicate register: "!p0"
  483. D3DSPSM_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
  484. } D3DSHADER_PARAM_SRCMOD_TYPE;
  485. typedef enum _D3DSAMPLER_TEXTURE_TYPE
  486. {
  487. D3DSTT_UNKNOWN = 0<<D3DSP_TEXTURETYPE_SHIFT, // uninitialized value
  488. D3DSTT_2D = 2<<D3DSP_TEXTURETYPE_SHIFT, // dcl_2d s# (for declaring a 2-D texture)
  489. D3DSTT_CUBE = 3<<D3DSP_TEXTURETYPE_SHIFT, // dcl_cube s# (for declaring a cube texture)
  490. D3DSTT_VOLUME = 4<<D3DSP_TEXTURETYPE_SHIFT, // dcl_volume s# (for declaring a volume texture)
  491. D3DSTT_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
  492. } D3DSAMPLER_TEXTURE_TYPE;
  493. typedef enum _D3DSHADER_INSTRUCTION_OPCODE_TYPE
  494. {
  495. D3DSIO_NOP = 0,
  496. D3DSIO_MOV ,
  497. D3DSIO_ADD ,
  498. D3DSIO_SUB ,
  499. D3DSIO_MAD ,
  500. D3DSIO_MUL ,
  501. D3DSIO_RCP ,
  502. D3DSIO_RSQ ,
  503. D3DSIO_DP3 ,
  504. D3DSIO_DP4 ,
  505. D3DSIO_MIN , //10
  506. D3DSIO_MAX ,
  507. D3DSIO_SLT ,
  508. D3DSIO_SGE ,
  509. D3DSIO_EXP ,
  510. D3DSIO_LOG ,
  511. D3DSIO_LIT ,
  512. D3DSIO_DST ,
  513. D3DSIO_LRP ,
  514. D3DSIO_FRC ,
  515. D3DSIO_M4x4 , //20
  516. D3DSIO_M4x3 ,
  517. D3DSIO_M3x4 ,
  518. D3DSIO_M3x3 ,
  519. D3DSIO_M3x2 ,
  520. D3DSIO_CALL ,
  521. D3DSIO_CALLNZ ,
  522. D3DSIO_LOOP ,
  523. D3DSIO_RET ,
  524. D3DSIO_ENDLOOP ,
  525. D3DSIO_LABEL , //30
  526. D3DSIO_DCL ,
  527. D3DSIO_POW ,
  528. D3DSIO_CRS ,
  529. D3DSIO_SGN ,
  530. D3DSIO_ABS ,
  531. D3DSIO_NRM ,
  532. D3DSIO_SINCOS ,
  533. D3DSIO_REP ,
  534. D3DSIO_ENDREP ,
  535. D3DSIO_IF , //40
  536. D3DSIO_IFC ,
  537. D3DSIO_ELSE ,
  538. D3DSIO_ENDIF ,
  539. D3DSIO_BREAK ,
  540. D3DSIO_BREAKC ,
  541. D3DSIO_MOVA ,
  542. D3DSIO_DEFB ,
  543. D3DSIO_DEFI ,
  544. D3DSIO_TEXCOORD = 64,
  545. D3DSIO_TEXKILL ,
  546. D3DSIO_TEX ,
  547. D3DSIO_TEXBEM ,
  548. D3DSIO_TEXBEML ,
  549. D3DSIO_TEXREG2AR ,
  550. D3DSIO_TEXREG2GB ,
  551. D3DSIO_TEXM3x2PAD ,
  552. D3DSIO_TEXM3x2TEX ,
  553. D3DSIO_TEXM3x3PAD ,
  554. D3DSIO_TEXM3x3TEX ,
  555. D3DSIO_RESERVED0 ,
  556. D3DSIO_TEXM3x3SPEC ,
  557. D3DSIO_TEXM3x3VSPEC ,
  558. D3DSIO_EXPP ,
  559. D3DSIO_LOGP ,
  560. D3DSIO_CND ,
  561. D3DSIO_DEF ,
  562. D3DSIO_TEXREG2RGB ,
  563. D3DSIO_TEXDP3TEX ,
  564. D3DSIO_TEXM3x2DEPTH ,
  565. D3DSIO_TEXDP3 ,
  566. D3DSIO_TEXM3x3 ,
  567. D3DSIO_TEXDEPTH ,
  568. D3DSIO_CMP ,
  569. D3DSIO_BEM ,
  570. D3DSIO_DP2ADD ,
  571. D3DSIO_DSX ,
  572. D3DSIO_DSY ,
  573. D3DSIO_TEXLDD ,
  574. D3DSIO_SETP ,
  575. D3DSIO_TEXLDL ,
  576. D3DSIO_BREAKP ,
  577. D3DSIO_PHASE = 0xFFFD,
  578. D3DSIO_COMMENT = 0xFFFE,
  579. D3DSIO_END = 0xFFFF,
  580. D3DSIO_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
  581. } D3DSHADER_INSTRUCTION_OPCODE_TYPE;
  582. typedef enum _D3DVS_RASTOUT_OFFSETS
  583. {
  584. D3DSRO_POSITION = 0,
  585. D3DSRO_FOG,
  586. D3DSRO_POINT_SIZE,
  587. D3DSRO_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
  588. } D3DVS_RASTOUT_OFFSETS;
  589. /* SwapEffects */
  590. typedef enum _D3DSWAPEFFECT
  591. {
  592. D3DSWAPEFFECT_DISCARD = 1,
  593. D3DSWAPEFFECT_COPY = 3,
  594. D3DSWAPEFFECT_FORCE_DWORD = 0x7fffffff
  595. } D3DSWAPEFFECT;
  596. typedef enum _D3DRESOURCETYPE {
  597. D3DRTYPE_SURFACE = 1,
  598. D3DRTYPE_TEXTURE = 3,
  599. D3DRTYPE_VOLUMETEXTURE = 4,
  600. D3DRTYPE_CUBETEXTURE = 5,
  601. D3DRTYPE_VERTEXBUFFER = 6,
  602. D3DRTYPE_INDEXBUFFER = 7,
  603. D3DRTYPE_FORCE_DWORD = 0x7fffffff
  604. } D3DRESOURCETYPE;
  605. typedef enum _D3DDEVTYPE
  606. {
  607. D3DDEVTYPE_HAL = 1,
  608. D3DDEVTYPE_REF = 2,
  609. D3DDEVTYPE_FORCE_DWORD = 0x7fffffff
  610. } D3DDEVTYPE;
  611. typedef enum _D3DSTENCILOP {
  612. D3DSTENCILOP_KEEP = 1,
  613. D3DSTENCILOP_ZERO = 2,
  614. D3DSTENCILOP_REPLACE = 3,
  615. D3DSTENCILOP_INCRSAT = 4,
  616. D3DSTENCILOP_DECRSAT = 5,
  617. D3DSTENCILOP_INVERT = 6,
  618. D3DSTENCILOP_INCR = 7,
  619. D3DSTENCILOP_DECR = 8,
  620. D3DSTENCILOP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  621. } D3DSTENCILOP;
  622. typedef enum _D3DPATCHEDGESTYLE
  623. {
  624. D3DPATCHEDGE_DISCRETE = 0,
  625. D3DPATCHEDGE_CONTINUOUS = 1,
  626. D3DPATCHEDGE_FORCE_DWORD = 0x7fffffff,
  627. } D3DPATCHEDGESTYLE;
  628. /* Debug monitor tokens (DEBUG only)
  629. Note that if D3DRS_DEBUGMONITORTOKEN is set, the call is treated as
  630. passing a token to the debug monitor. For example, if, after passing
  631. D3DDMT_ENABLE/DISABLE to D3DRS_DEBUGMONITORTOKEN other token values
  632. are passed in, the enabled/disabled state of the debug
  633. monitor will still persist.
  634. The debug monitor defaults to enabled.
  635. Calling GetRenderState on D3DRS_DEBUGMONITORTOKEN is not of any use.
  636. */
  637. typedef enum _D3DDEBUGMONITORTOKENS {
  638. D3DDMT_ENABLE = 0, // enable debug monitor
  639. } D3DDEBUGMONITORTOKENS;
  640. typedef enum _D3DDEGREETYPE
  641. {
  642. D3DDEGREE_LINEAR = 1,
  643. D3DDEGREE_QUADRATIC = 2,
  644. D3DDEGREE_CUBIC = 3,
  645. D3DDEGREE_FORCE_DWORD = 0x7fffffff,
  646. } D3DDEGREETYPE;
  647. typedef enum _D3DBLENDOP {
  648. D3DBLENDOP_ADD = 1,
  649. D3DBLENDOP_SUBTRACT = 2,
  650. D3DBLENDOP_REVSUBTRACT = 3,
  651. D3DBLENDOP_MIN = 4,
  652. D3DBLENDOP_MAX = 5,
  653. D3DBLENDOP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  654. } D3DBLENDOP;
  655. typedef enum _D3DMULTISAMPLE_TYPE
  656. {
  657. D3DMULTISAMPLE_NONE = 0,
  658. D3DMULTISAMPLE_NONMASKABLE = 1,
  659. D3DMULTISAMPLE_2_SAMPLES = 2,
  660. D3DMULTISAMPLE_3_SAMPLES = 3,
  661. D3DMULTISAMPLE_4_SAMPLES = 4,
  662. D3DMULTISAMPLE_5_SAMPLES = 5,
  663. D3DMULTISAMPLE_6_SAMPLES = 6,
  664. D3DMULTISAMPLE_7_SAMPLES = 7,
  665. D3DMULTISAMPLE_8_SAMPLES = 8,
  666. D3DMULTISAMPLE_9_SAMPLES = 9,
  667. D3DMULTISAMPLE_10_SAMPLES = 10,
  668. D3DMULTISAMPLE_11_SAMPLES = 11,
  669. D3DMULTISAMPLE_12_SAMPLES = 12,
  670. D3DMULTISAMPLE_13_SAMPLES = 13,
  671. D3DMULTISAMPLE_14_SAMPLES = 14,
  672. D3DMULTISAMPLE_15_SAMPLES = 15,
  673. D3DMULTISAMPLE_16_SAMPLES = 16,
  674. D3DMULTISAMPLE_FORCE_DWORD = 0x7fffffff
  675. } D3DMULTISAMPLE_TYPE;
  676. /* Pool types */
  677. typedef enum _D3DPOOL {
  678. D3DPOOL_DEFAULT = 0,
  679. D3DPOOL_MANAGED = 1,
  680. D3DPOOL_SYSTEMMEM = 2,
  681. D3DPOOL_SCRATCH = 3,
  682. D3DPOOL_FORCE_DWORD = 0x7fffffff
  683. } D3DPOOL;
  684. typedef enum _D3DQUERYTYPE {
  685. D3DQUERYTYPE_RESOURCEMANAGER = 5, /* D3DISSUE_END */
  686. D3DQUERYTYPE_EVENT = 8, /* D3DISSUE_END */
  687. D3DQUERYTYPE_OCCLUSION = 9, /* D3DISSUE_BEGIN, D3DISSUE_END */
  688. D3DQUERYTYPE_TIMESTAMP = 10, /* D3DISSUE_END */
  689. D3DQUERYTYPE_TIMESTAMPFREQ = 12, /* D3DISSUE_END */
  690. D3DQUERYTYPE_INTERFACETIMINGS = 14, /* D3DISSUE_BEGIN, D3DISSUE_END */
  691. D3DQUERYTYPE_PIXELTIMINGS = 16, /* D3DISSUE_BEGIN, D3DISSUE_END */
  692. D3DQUERYTYPE_CACHEUTILIZATION = 18, /* D3DISSUE_BEGIN, D3DISSUE_END */
  693. } D3DQUERYTYPE;
  694. typedef enum _D3DRENDERSTATETYPE {
  695. D3DRS_ZENABLE = 7, /* D3DZBUFFERTYPE (or TRUE/FALSE for legacy) */
  696. D3DRS_FILLMODE = 8, /* D3DFILLMODE */
  697. D3DRS_SHADEMODE = 9, /* D3DSHADEMODE */
  698. D3DRS_ZWRITEENABLE = 14, /* TRUE to enable z writes */
  699. D3DRS_ALPHATESTENABLE = 15, /* TRUE to enable alpha tests */
  700. D3DRS_LASTPIXEL = 16, /* TRUE for last-pixel on lines */
  701. D3DRS_SRCBLEND = 19, /* D3DBLEND */
  702. D3DRS_DESTBLEND = 20, /* D3DBLEND */
  703. D3DRS_CULLMODE = 22, /* D3DCULL */
  704. D3DRS_ZFUNC = 23, /* D3DCMPFUNC */
  705. D3DRS_ALPHAREF = 24, /* D3DFIXED */
  706. D3DRS_ALPHAFUNC = 25, /* D3DCMPFUNC */
  707. D3DRS_DITHERENABLE = 26, /* TRUE to enable dithering */
  708. D3DRS_ALPHABLENDENABLE = 27, /* TRUE to enable alpha blending */
  709. D3DRS_FOGENABLE = 28, /* TRUE to enable fog blending */
  710. D3DRS_SPECULARENABLE = 29, /* TRUE to enable specular */
  711. D3DRS_FOGCOLOR = 34, /* D3DCOLOR */
  712. D3DRS_FOGTABLEMODE = 35, /* D3DFOGMODE */
  713. D3DRS_FOGSTART = 36, /* Fog start (for both vertex and pixel fog) */
  714. D3DRS_FOGEND = 37, /* Fog end */
  715. D3DRS_FOGDENSITY = 38, /* Fog density */
  716. D3DRS_RANGEFOGENABLE = 48, /* Enables range-based fog */
  717. D3DRS_STENCILENABLE = 52, /* BOOL enable/disable stenciling */
  718. D3DRS_STENCILFAIL = 53, /* D3DSTENCILOP to do if stencil test fails */
  719. D3DRS_STENCILZFAIL = 54, /* D3DSTENCILOP to do if stencil test passes and Z test fails */
  720. D3DRS_STENCILPASS = 55, /* D3DSTENCILOP to do if both stencil and Z tests pass */
  721. D3DRS_STENCILFUNC = 56, /* D3DCMPFUNC fn. Stencil Test passes if ((ref & mask) stencilfn (stencil & mask)) is true */
  722. D3DRS_STENCILREF = 57, /* Reference value used in stencil test */
  723. D3DRS_STENCILMASK = 58, /* Mask value used in stencil test */
  724. D3DRS_STENCILWRITEMASK = 59, /* Write mask applied to values written to stencil buffer */
  725. D3DRS_TEXTUREFACTOR = 60, /* D3DCOLOR used for multi-texture blend */
  726. D3DRS_WRAP0 = 128, /* wrap for 1st texture coord. set */
  727. D3DRS_WRAP1 = 129, /* wrap for 2nd texture coord. set */
  728. D3DRS_WRAP2 = 130, /* wrap for 3rd texture coord. set */
  729. D3DRS_WRAP3 = 131, /* wrap for 4th texture coord. set */
  730. D3DRS_WRAP4 = 132, /* wrap for 5th texture coord. set */
  731. D3DRS_WRAP5 = 133, /* wrap for 6th texture coord. set */
  732. D3DRS_WRAP6 = 134, /* wrap for 7th texture coord. set */
  733. D3DRS_WRAP7 = 135, /* wrap for 8th texture coord. set */
  734. D3DRS_CLIPPING = 136,
  735. D3DRS_LIGHTING = 137,
  736. D3DRS_AMBIENT = 139,
  737. D3DRS_FOGVERTEXMODE = 140,
  738. D3DRS_COLORVERTEX = 141,
  739. D3DRS_LOCALVIEWER = 142,
  740. D3DRS_NORMALIZENORMALS = 143,
  741. D3DRS_DIFFUSEMATERIALSOURCE = 145,
  742. D3DRS_SPECULARMATERIALSOURCE = 146,
  743. D3DRS_AMBIENTMATERIALSOURCE = 147,
  744. D3DRS_EMISSIVEMATERIALSOURCE = 148,
  745. D3DRS_VERTEXBLEND = 151,
  746. D3DRS_CLIPPLANEENABLE = 152,
  747. D3DRS_POINTSIZE = 154, /* float point size */
  748. D3DRS_POINTSIZE_MIN = 155, /* float point size min threshold */
  749. D3DRS_POINTSPRITEENABLE = 156, /* BOOL point texture coord control */
  750. D3DRS_POINTSCALEENABLE = 157, /* BOOL point size scale enable */
  751. D3DRS_POINTSCALE_A = 158, /* float point attenuation A value */
  752. D3DRS_POINTSCALE_B = 159, /* float point attenuation B value */
  753. D3DRS_POINTSCALE_C = 160, /* float point attenuation C value */
  754. D3DRS_MULTISAMPLEANTIALIAS = 161, // BOOL - set to do FSAA with multisample buffer
  755. D3DRS_MULTISAMPLEMASK = 162, // DWORD - per-sample enable/disable
  756. D3DRS_PATCHEDGESTYLE = 163, // Sets whether patch edges will use float style tessellation
  757. D3DRS_DEBUGMONITORTOKEN = 165, // DEBUG ONLY - token to debug monitor
  758. D3DRS_POINTSIZE_MAX = 166, /* float point size max threshold */
  759. D3DRS_INDEXEDVERTEXBLENDENABLE = 167,
  760. D3DRS_COLORWRITEENABLE = 168, // per-channel write enable
  761. D3DRS_TWEENFACTOR = 170, // float tween factor
  762. D3DRS_BLENDOP = 171, // D3DBLENDOP setting
  763. D3DRS_POSITIONDEGREE = 172, // NPatch position interpolation degree. D3DDEGREE_LINEAR or D3DDEGREE_CUBIC (default)
  764. D3DRS_NORMALDEGREE = 173, // NPatch normal interpolation degree. D3DDEGREE_LINEAR (default) or D3DDEGREE_QUADRATIC
  765. D3DRS_SCISSORTESTENABLE = 174,
  766. D3DRS_SLOPESCALEDEPTHBIAS = 175,
  767. D3DRS_ANTIALIASEDLINEENABLE = 176,
  768. D3DRS_MINTESSELLATIONLEVEL = 178,
  769. D3DRS_MAXTESSELLATIONLEVEL = 179,
  770. D3DRS_ADAPTIVETESS_X = 180,
  771. D3DRS_ADAPTIVETESS_Y = 181,
  772. D3DRS_ADAPTIVETESS_Z = 182,
  773. D3DRS_ADAPTIVETESS_W = 183,
  774. D3DRS_ENABLEADAPTIVETESSELLATION = 184,
  775. D3DRS_TWOSIDEDSTENCILMODE = 185, /* BOOL enable/disable 2 sided stenciling */
  776. D3DRS_CCW_STENCILFAIL = 186, /* D3DSTENCILOP to do if ccw stencil test fails */
  777. D3DRS_CCW_STENCILZFAIL = 187, /* D3DSTENCILOP to do if ccw stencil test passes and Z test fails */
  778. D3DRS_CCW_STENCILPASS = 188, /* D3DSTENCILOP to do if both ccw stencil and Z tests pass */
  779. D3DRS_CCW_STENCILFUNC = 189, /* D3DCMPFUNC fn. ccw Stencil Test passes if ((ref & mask) stencilfn (stencil & mask)) is true */
  780. D3DRS_COLORWRITEENABLE1 = 190, /* Additional ColorWriteEnables for the devices that support D3DPMISCCAPS_INDEPENDENTWRITEMASKS */
  781. D3DRS_COLORWRITEENABLE2 = 191, /* Additional ColorWriteEnables for the devices that support D3DPMISCCAPS_INDEPENDENTWRITEMASKS */
  782. D3DRS_COLORWRITEENABLE3 = 192, /* Additional ColorWriteEnables for the devices that support D3DPMISCCAPS_INDEPENDENTWRITEMASKS */
  783. D3DRS_BLENDFACTOR = 193, /* D3DCOLOR used for a constant blend factor during alpha blending for devices that support D3DPBLENDCAPS_BLENDFACTOR */
  784. D3DRS_SRGBWRITEENABLE = 194, /* Enable rendertarget writes to be DE-linearized to SRGB (for formats that expose D3DUSAGE_QUERY_SRGBWRITE) */
  785. D3DRS_DEPTHBIAS = 195,
  786. D3DRS_WRAP8 = 198, /* Additional wrap states for vs_3_0+ attributes with D3DDECLUSAGE_TEXCOORD */
  787. D3DRS_WRAP9 = 199,
  788. D3DRS_WRAP10 = 200,
  789. D3DRS_WRAP11 = 201,
  790. D3DRS_WRAP12 = 202,
  791. D3DRS_WRAP13 = 203,
  792. D3DRS_WRAP14 = 204,
  793. D3DRS_WRAP15 = 205,
  794. D3DRS_SEPARATEALPHABLENDENABLE = 206, /* TRUE to enable a separate blending function for the alpha channel */
  795. D3DRS_SRCBLENDALPHA = 207, /* SRC blend factor for the alpha channel when D3DRS_SEPARATEDESTALPHAENABLE is TRUE */
  796. D3DRS_DESTBLENDALPHA = 208, /* DST blend factor for the alpha channel when D3DRS_SEPARATEDESTALPHAENABLE is TRUE */
  797. D3DRS_BLENDOPALPHA = 209, /* Blending operation for the alpha channel when D3DRS_SEPARATEDESTALPHAENABLE is TRUE */
  798. D3DRS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  799. } D3DRENDERSTATETYPE;
  800. typedef enum _D3DCULL {
  801. D3DCULL_NONE = 1,
  802. D3DCULL_CW = 2,
  803. D3DCULL_CCW = 3,
  804. D3DCULL_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  805. } D3DCULL;
  806. typedef enum _D3DTEXTUREFILTERTYPE
  807. {
  808. D3DTEXF_NONE = 0, // filtering disabled (valid for mip filter only)
  809. D3DTEXF_POINT = 1, // nearest
  810. D3DTEXF_LINEAR = 2, // linear interpolation
  811. D3DTEXF_ANISOTROPIC = 3, // anisotropic
  812. D3DTEXF_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
  813. } D3DTEXTUREFILTERTYPE;
  814. typedef enum _D3DBACKBUFFER_TYPE
  815. {
  816. D3DBACKBUFFER_TYPE_MONO = 0,
  817. D3DBACKBUFFER_TYPE_FORCE_DWORD = 0x7fffffff
  818. } D3DBACKBUFFER_TYPE;
  819. #define D3DTS_WORLDMATRIX(index) (D3DTRANSFORMSTATETYPE)(index + 256)
  820. #define D3DTS_WORLD D3DTS_WORLDMATRIX(0)
  821. #define D3DTS_WORLD1 D3DTS_WORLDMATRIX(1)
  822. #define D3DTS_WORLD2 D3DTS_WORLDMATRIX(2)
  823. #define D3DTS_WORLD3 D3DTS_WORLDMATRIX(3)
  824. typedef enum _D3DCMPFUNC {
  825. D3DCMP_NEVER = 1,
  826. D3DCMP_LESS = 2,
  827. D3DCMP_EQUAL = 3,
  828. D3DCMP_LESSEQUAL = 4,
  829. D3DCMP_GREATER = 5,
  830. D3DCMP_NOTEQUAL = 6,
  831. D3DCMP_GREATEREQUAL = 7,
  832. D3DCMP_ALWAYS = 8,
  833. D3DCMP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  834. } D3DCMPFUNC;
  835. typedef enum _D3DZBUFFERTYPE {
  836. D3DZB_FALSE = 0,
  837. D3DZB_TRUE = 1, // Z buffering
  838. D3DZB_USEW = 2, // W buffering
  839. D3DZB_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  840. } D3DZBUFFERTYPE;
  841. typedef enum _D3DFILLMODE {
  842. D3DFILL_POINT = 1,
  843. D3DFILL_WIREFRAME = 2,
  844. D3DFILL_SOLID = 3,
  845. D3DFILL_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  846. } D3DFILLMODE;
  847. typedef enum _D3DBLEND {
  848. D3DBLEND_ZERO = 1,
  849. D3DBLEND_ONE = 2,
  850. D3DBLEND_SRCCOLOR = 3,
  851. D3DBLEND_INVSRCCOLOR = 4,
  852. D3DBLEND_SRCALPHA = 5,
  853. D3DBLEND_INVSRCALPHA = 6,
  854. D3DBLEND_DESTALPHA = 7,
  855. D3DBLEND_INVDESTALPHA = 8,
  856. D3DBLEND_DESTCOLOR = 9,
  857. D3DBLEND_INVDESTCOLOR = 10,
  858. D3DBLEND_SRCALPHASAT = 11,
  859. D3DBLEND_BOTHSRCALPHA = 12,
  860. D3DBLEND_BOTHINVSRCALPHA = 13,
  861. D3DBLEND_BLENDFACTOR = 14, /* Only supported if D3DPBLENDCAPS_BLENDFACTOR is on */
  862. D3DBLEND_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  863. } D3DBLEND;
  864. // Values for material source
  865. typedef enum _D3DMATERIALCOLORSOURCE
  866. {
  867. D3DMCS_MATERIAL = 0, // Color from material is used
  868. D3DMCS_COLOR1 = 1, // Diffuse vertex color is used
  869. D3DMCS_COLOR2 = 2, // Specular vertex color is used
  870. D3DMCS_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
  871. } D3DMATERIALCOLORSOURCE;
  872. typedef enum _D3DCUBEMAP_FACES
  873. {
  874. D3DCUBEMAP_FACE_POSITIVE_Z = 4,
  875. D3DCUBEMAP_FACE_FORCE_DWORD = 0x7fffffff
  876. } D3DCUBEMAP_FACES;
  877. typedef enum _D3DTEXTURETRANSFORMFLAGS {
  878. D3DTTFF_DISABLE = 0, // texture coordinates are passed directly
  879. D3DTTFF_COUNT3 = 3, // rasterizer should expect 3-D texture coords
  880. D3DTTFF_PROJECTED = 256, // texcoords to be divided by COUNTth element
  881. D3DTTFF_FORCE_DWORD = 0x7fffffff,
  882. } D3DTEXTURETRANSFORMFLAGS;
  883. typedef enum _D3DTEXTUREADDRESS {
  884. D3DTADDRESS_WRAP = 1,
  885. D3DTADDRESS_CLAMP = 3,
  886. D3DTADDRESS_BORDER = 4,
  887. D3DTADDRESS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  888. } D3DTEXTUREADDRESS;
  889. typedef enum _D3DSHADEMODE {
  890. D3DSHADE_FLAT = 1,
  891. D3DSHADE_GOURAUD = 2,
  892. D3DSHADE_PHONG = 3,
  893. D3DSHADE_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  894. } D3DSHADEMODE;
  895. typedef enum _D3DFOGMODE {
  896. D3DFOG_NONE = 0,
  897. D3DFOG_LINEAR = 3,
  898. D3DFOG_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  899. } D3DFOGMODE;
  900. typedef struct _D3DRECT {
  901. LONG x1;
  902. LONG y1;
  903. LONG x2;
  904. LONG y2;
  905. } D3DRECT;
  906. typedef enum _D3DSHADER_PARAM_REGISTER_TYPE
  907. {
  908. D3DSPR_TEMP = 0, // Temporary Register File
  909. D3DSPR_INPUT = 1, // Input Register File
  910. D3DSPR_CONST = 2, // Constant Register File
  911. D3DSPR_ADDR = 3, // Address Register (VS)
  912. D3DSPR_TEXTURE = 3, // Texture Register File (PS)
  913. D3DSPR_RASTOUT = 4, // Rasterizer Register File
  914. D3DSPR_ATTROUT = 5, // Attribute Output Register File
  915. D3DSPR_TEXCRDOUT = 6, // Texture Coordinate Output Register File
  916. D3DSPR_OUTPUT = 6, // Output register file for VS3.0+
  917. D3DSPR_CONSTINT = 7, // Constant Integer Vector Register File
  918. D3DSPR_COLOROUT = 8, // Color Output Register File
  919. D3DSPR_DEPTHOUT = 9, // Depth Output Register File
  920. D3DSPR_SAMPLER = 10, // Sampler State Register File
  921. D3DSPR_CONST2 = 11, // Constant Register File 2048 - 4095
  922. D3DSPR_CONST3 = 12, // Constant Register File 4096 - 6143
  923. D3DSPR_CONST4 = 13, // Constant Register File 6144 - 8191
  924. D3DSPR_CONSTBOOL = 14, // Constant Boolean register file
  925. D3DSPR_LOOP = 15, // Loop counter register file
  926. D3DSPR_TEMPFLOAT16 = 16, // 16-bit float temp register file
  927. D3DSPR_MISCTYPE = 17, // Miscellaneous (single) registers.
  928. D3DSPR_LABEL = 18, // Label
  929. D3DSPR_PREDICATE = 19, // Predicate register
  930. D3DSPR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
  931. } D3DSHADER_PARAM_REGISTER_TYPE;
  932. typedef struct _D3DMATRIX {
  933. union {
  934. struct {
  935. float _11, _12, _13, _14;
  936. float _21, _22, _23, _24;
  937. float _31, _32, _33, _34;
  938. float _41, _42, _43, _44;
  939. };
  940. float m[4][4];
  941. };
  942. } D3DMATRIX;
  943. typedef struct _D3DVERTEXBUFFER_DESC
  944. {
  945. D3DFORMAT Format;
  946. D3DRESOURCETYPE Type;
  947. DWORD Usage;
  948. D3DPOOL Pool;
  949. UINT Size;
  950. DWORD FVF;
  951. } D3DVERTEXBUFFER_DESC;
  952. class D3DXMATRIX : public D3DMATRIX
  953. {
  954. public:
  955. D3DXMATRIX operator*( const D3DXMATRIX &o ) const;
  956. operator FLOAT* ();
  957. float& operator()( int row, int column );
  958. const float& operator()( int row, int column ) const;
  959. };
  960. typedef DWORD D3DCOLOR;
  961. typedef enum _D3DSAMPLERSTATETYPE
  962. {
  963. D3DSAMP_ADDRESSU = 1, /* D3DTEXTUREADDRESS for U coordinate */
  964. D3DSAMP_ADDRESSV = 2, /* D3DTEXTUREADDRESS for V coordinate */
  965. D3DSAMP_ADDRESSW = 3, /* D3DTEXTUREADDRESS for W coordinate */
  966. D3DSAMP_BORDERCOLOR = 4, /* D3DCOLOR */
  967. D3DSAMP_MAGFILTER = 5, /* D3DTEXTUREFILTER filter to use for magnification */
  968. D3DSAMP_MINFILTER = 6, /* D3DTEXTUREFILTER filter to use for minification */
  969. D3DSAMP_MIPFILTER = 7, /* D3DTEXTUREFILTER filter to use between mipmaps during minification */
  970. D3DSAMP_MIPMAPLODBIAS = 8, /* float Mipmap LOD bias */
  971. D3DSAMP_MAXMIPLEVEL = 9, /* DWORD 0..(n-1) LOD index of largest map to use (0 == largest) */
  972. D3DSAMP_MAXANISOTROPY = 10, /* DWORD maximum anisotropy */
  973. D3DSAMP_SRGBTEXTURE = 11, /* Default = 0 (which means Gamma 1.0,
  974. no correction required.) else correct for
  975. Gamma = 2.2 */
  976. D3DSAMP_SHADOWFILTER = 12, /* Tells the sampler that it should be doing shadow compares */
  977. D3DSAMP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  978. } D3DSAMPLERSTATETYPE;
  979. typedef enum _D3DDECLTYPE
  980. {
  981. D3DDECLTYPE_FLOAT1 = 0, // 1D float expanded to (value, 0., 0., 1.)
  982. D3DDECLTYPE_FLOAT2 = 1, // 2D float expanded to (value, value, 0., 1.)
  983. D3DDECLTYPE_FLOAT3 = 2, // 3D float expanded to (value, value, value, 1.)
  984. D3DDECLTYPE_FLOAT4 = 3, // 4D float
  985. D3DDECLTYPE_D3DCOLOR = 4, // 4D packed unsigned bytes mapped to 0. to 1. range
  986. // Input is in D3DCOLOR format (ARGB) expanded to (R, G, B, A)
  987. D3DDECLTYPE_UBYTE4 = 5, // 4D unsigned byte
  988. D3DDECLTYPE_SHORT2 = 6, // 2D signed short expanded to (value, value, 0., 1.)
  989. D3DDECLTYPE_SHORT4 = 7, // 4D signed short
  990. // The following types are valid only with vertex shaders >= 2.0
  991. D3DDECLTYPE_UBYTE4N = 8, // Each of 4 bytes is normalized by dividing to 255.0
  992. D3DDECLTYPE_SHORT2N = 9, // 2D signed short normalized (v[0]/32767.0,v[1]/32767.0,0,1)
  993. D3DDECLTYPE_SHORT4N = 10, // 4D signed short normalized (v[0]/32767.0,v[1]/32767.0,v[2]/32767.0,v[3]/32767.0)
  994. D3DDECLTYPE_USHORT2N = 11, // 2D unsigned short normalized (v[0]/65535.0,v[1]/65535.0,0,1)
  995. D3DDECLTYPE_USHORT4N = 12, // 4D unsigned short normalized (v[0]/65535.0,v[1]/65535.0,v[2]/65535.0,v[3]/65535.0)
  996. D3DDECLTYPE_UDEC3 = 13, // 3D unsigned 10 10 10 format expanded to (value, value, value, 1)
  997. D3DDECLTYPE_DEC3N = 14, // 3D signed 10 10 10 format normalized and expanded to (v[0]/511.0, v[1]/511.0, v[2]/511.0, 1)
  998. D3DDECLTYPE_FLOAT16_2 = 15, // Two 16-bit floating point values, expanded to (value, value, 0, 1)
  999. D3DDECLTYPE_FLOAT16_4 = 16, // Four 16-bit floating point values
  1000. D3DDECLTYPE_UNUSED = 17, // When the type field in a decl is unused.
  1001. } D3DDECLTYPE;
  1002. typedef enum _D3DDECLMETHOD
  1003. {
  1004. D3DDECLMETHOD_DEFAULT = 0,
  1005. D3DDECLMETHOD_PARTIALU,
  1006. D3DDECLMETHOD_PARTIALV,
  1007. D3DDECLMETHOD_CROSSUV, // Normal
  1008. D3DDECLMETHOD_UV,
  1009. D3DDECLMETHOD_LOOKUP, // Lookup a displacement map
  1010. D3DDECLMETHOD_LOOKUPPRESAMPLED, // Lookup a pre-sampled displacement map
  1011. } D3DDECLMETHOD;
  1012. typedef enum _D3DDECLUSAGE
  1013. {
  1014. D3DDECLUSAGE_POSITION = 0,
  1015. D3DDECLUSAGE_BLENDWEIGHT = 1,
  1016. D3DDECLUSAGE_BLENDINDICES = 2,
  1017. D3DDECLUSAGE_NORMAL = 3,
  1018. D3DDECLUSAGE_PSIZE = 4,
  1019. D3DDECLUSAGE_TEXCOORD = 5,
  1020. D3DDECLUSAGE_TANGENT = 6,
  1021. D3DDECLUSAGE_BINORMAL = 7,
  1022. D3DDECLUSAGE_TESSFACTOR = 8,
  1023. D3DDECLUSAGE_PLUGH = 9, // mystery value
  1024. D3DDECLUSAGE_COLOR = 10,
  1025. D3DDECLUSAGE_FOG = 11,
  1026. D3DDECLUSAGE_DEPTH = 12,
  1027. D3DDECLUSAGE_SAMPLE = 13,
  1028. } D3DDECLUSAGE;
  1029. typedef enum _D3DPRIMITIVETYPE {
  1030. D3DPT_POINTLIST = 1,
  1031. D3DPT_LINELIST = 2,
  1032. D3DPT_TRIANGLELIST = 4,
  1033. D3DPT_TRIANGLESTRIP = 5,
  1034. D3DPT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  1035. } D3DPRIMITIVETYPE;
  1036. // ------------------------------------------------------------------------------------------------------------------------------ //
  1037. // STRUCTURES
  1038. // ------------------------------------------------------------------------------------------------------------------------------ //
  1039. typedef struct D3DXPLANE
  1040. {
  1041. float& operator[]( int i );
  1042. bool operator==( const D3DXPLANE &o );
  1043. bool operator!=( const D3DXPLANE &o );
  1044. operator float*();
  1045. operator const float*() const;
  1046. float a, b, c, d;
  1047. } D3DXPLANE;
  1048. typedef enum _D3DVERTEXBLENDFLAGS
  1049. {
  1050. D3DVBF_DISABLE = 0, // Disable vertex blending
  1051. D3DVBF_1WEIGHTS = 1, // 2 matrix blending
  1052. D3DVBF_2WEIGHTS = 2, // 3 matrix blending
  1053. D3DVBF_3WEIGHTS = 3, // 4 matrix blending
  1054. D3DVBF_TWEENING = 255, // blending using D3DRS_TWEENFACTOR
  1055. D3DVBF_0WEIGHTS = 256, // one matrix is used with weight 1.0
  1056. D3DVBF_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
  1057. } D3DVERTEXBLENDFLAGS;
  1058. typedef struct _D3DINDEXBUFFER_DESC
  1059. {
  1060. D3DFORMAT Format;
  1061. D3DRESOURCETYPE Type;
  1062. DWORD Usage;
  1063. D3DPOOL Pool;
  1064. UINT Size;
  1065. } D3DINDEXBUFFER_DESC;
  1066. typedef struct _D3DVERTEXELEMENT9
  1067. {
  1068. WORD Stream; // Stream index
  1069. WORD Offset; // Offset in the stream in bytes
  1070. BYTE Type; // Data type
  1071. BYTE Method; // Processing method
  1072. BYTE Usage; // Semantics
  1073. BYTE UsageIndex; // Semantic index
  1074. } D3DVERTEXELEMENT9, *LPD3DVERTEXELEMENT9;
  1075. #define MAX_DEVICE_IDENTIFIER_STRING 512
  1076. typedef struct _D3DADAPTER_IDENTIFIER9
  1077. {
  1078. char Driver[MAX_DEVICE_IDENTIFIER_STRING];
  1079. char Description[MAX_DEVICE_IDENTIFIER_STRING];
  1080. char DeviceName[32]; /* Device name for GDI (ex. \\.\DISPLAY1) */
  1081. LARGE_INTEGER DriverVersion; /* Defined for 32 bit components */
  1082. DWORD VendorId;
  1083. DWORD DeviceId;
  1084. DWORD SubSysId;
  1085. DWORD Revision;
  1086. DWORD VideoMemory;
  1087. } D3DADAPTER_IDENTIFIER9;
  1088. typedef struct _D3DCOLORVALUE {
  1089. float r;
  1090. float g;
  1091. float b;
  1092. float a;
  1093. } D3DCOLORVALUE;
  1094. typedef struct _D3DMATERIAL9 {
  1095. D3DCOLORVALUE Diffuse; /* Diffuse color RGBA */
  1096. D3DCOLORVALUE Ambient; /* Ambient color RGB */
  1097. D3DCOLORVALUE Specular; /* Specular 'shininess' */
  1098. D3DCOLORVALUE Emissive; /* Emissive color RGB */
  1099. float Power; /* Sharpness if specular highlight */
  1100. } D3DMATERIAL9;
  1101. typedef struct _D3DVOLUME_DESC
  1102. {
  1103. D3DFORMAT Format;
  1104. D3DRESOURCETYPE Type;
  1105. DWORD Usage;
  1106. D3DPOOL Pool;
  1107. UINT Width;
  1108. UINT Height;
  1109. UINT Depth;
  1110. } D3DVOLUME_DESC;
  1111. typedef struct _D3DVIEWPORT9 {
  1112. DWORD X;
  1113. DWORD Y; /* Viewport Top left */
  1114. DWORD Width;
  1115. DWORD Height; /* Viewport Dimensions */
  1116. float MinZ; /* Min/max of clip Volume */
  1117. float MaxZ;
  1118. } D3DVIEWPORT9;
  1119. typedef struct _D3DPSHADERCAPS2_0
  1120. {
  1121. DWORD Caps;
  1122. INT DynamicFlowControlDepth;
  1123. INT NumTemps;
  1124. INT StaticFlowControlDepth;
  1125. INT NumInstructionSlots;
  1126. } D3DPSHADERCAPS2_0;
  1127. typedef struct _D3DCAPS9
  1128. {
  1129. /* Device Info */
  1130. D3DDEVTYPE DeviceType;
  1131. /* Caps from DX7 Draw */
  1132. DWORD Caps;
  1133. DWORD Caps2;
  1134. /* Cursor Caps */
  1135. DWORD CursorCaps;
  1136. /* 3D Device Caps */
  1137. DWORD DevCaps;
  1138. DWORD PrimitiveMiscCaps;
  1139. DWORD RasterCaps;
  1140. DWORD TextureCaps;
  1141. DWORD TextureFilterCaps; // D3DPTFILTERCAPS for IDirect3DTexture9's
  1142. DWORD MaxTextureWidth, MaxTextureHeight;
  1143. DWORD MaxVolumeExtent;
  1144. DWORD MaxTextureAspectRatio;
  1145. DWORD MaxAnisotropy;
  1146. DWORD TextureOpCaps;
  1147. DWORD MaxTextureBlendStages;
  1148. DWORD MaxSimultaneousTextures;
  1149. DWORD VertexProcessingCaps;
  1150. DWORD MaxActiveLights;
  1151. DWORD MaxUserClipPlanes;
  1152. DWORD MaxVertexBlendMatrices;
  1153. DWORD MaxVertexBlendMatrixIndex;
  1154. DWORD MaxPrimitiveCount; // max number of primitives per DrawPrimitive call
  1155. DWORD MaxStreams;
  1156. DWORD VertexShaderVersion;
  1157. DWORD MaxVertexShaderConst; // number of vertex shader constant registers
  1158. DWORD PixelShaderVersion;
  1159. // Here are the DX9 specific ones
  1160. DWORD DevCaps2;
  1161. D3DPSHADERCAPS2_0 PS20Caps;
  1162. DWORD NumSimultaneousRTs; // Will be at least 1
  1163. DWORD MaxVertexShader30InstructionSlots;
  1164. DWORD MaxPixelShader30InstructionSlots;
  1165. // only on Mac Posix/GL
  1166. #if ( defined ( PLATFORM_OSX ) )
  1167. DWORD FakeSRGBWrite; // 1 for parts which can't support SRGB writes due to driver issues - 0 for others
  1168. DWORD MixedSizeTargets; // 1 for parts which can mix attachment sizes (RT's color vs depth)
  1169. DWORD CanDoSRGBReadFromRTs; // 0 when we're on Leopard, 1 when on Snow Leopard
  1170. DWORD SRGBDecode;
  1171. #endif
  1172. } D3DCAPS9;
  1173. typedef struct _D3DDISPLAYMODE
  1174. {
  1175. UINT Width;
  1176. UINT Height;
  1177. UINT RefreshRate;
  1178. D3DFORMAT Format;
  1179. } D3DDISPLAYMODE;
  1180. typedef struct _D3DGAMMARAMP
  1181. {
  1182. WORD red [256];
  1183. WORD green[256];
  1184. WORD blue [256];
  1185. } D3DGAMMARAMP;
  1186. /* Resize Optional Parameters */
  1187. typedef struct _D3DPRESENT_PARAMETERS_
  1188. {
  1189. UINT BackBufferWidth;
  1190. UINT BackBufferHeight;
  1191. D3DFORMAT BackBufferFormat;
  1192. UINT BackBufferCount;
  1193. D3DMULTISAMPLE_TYPE MultiSampleType;
  1194. DWORD MultiSampleQuality;
  1195. D3DSWAPEFFECT SwapEffect;
  1196. VD3DHWND hDeviceWindow;
  1197. BOOL Windowed;
  1198. BOOL EnableAutoDepthStencil;
  1199. D3DFORMAT AutoDepthStencilFormat;
  1200. DWORD Flags;
  1201. /* FullScreen_RefreshRateInHz must be zero for Windowed mode */
  1202. UINT FullScreen_RefreshRateInHz;
  1203. UINT PresentationInterval;
  1204. } D3DPRESENT_PARAMETERS;
  1205. typedef struct _D3DDEVICE_CREATION_PARAMETERS
  1206. {
  1207. UINT AdapterOrdinal;
  1208. D3DDEVTYPE DeviceType;
  1209. VD3DHWND hFocusWindow;
  1210. DWORD BehaviorFlags;
  1211. } D3DDEVICE_CREATION_PARAMETERS;
  1212. /* Structures for LockBox */
  1213. typedef struct _D3DBOX
  1214. {
  1215. UINT Left;
  1216. UINT Top;
  1217. UINT Right;
  1218. UINT Bottom;
  1219. UINT Front;
  1220. UINT Back;
  1221. } D3DBOX;
  1222. typedef struct _D3DLOCKED_BOX
  1223. {
  1224. INT RowPitch;
  1225. INT SlicePitch;
  1226. void* pBits;
  1227. } D3DLOCKED_BOX;
  1228. typedef struct _D3DSURFACE_DESC
  1229. {
  1230. D3DFORMAT Format;
  1231. D3DRESOURCETYPE Type;
  1232. DWORD Usage;
  1233. D3DPOOL Pool;
  1234. D3DMULTISAMPLE_TYPE MultiSampleType;
  1235. DWORD MultiSampleQuality;
  1236. UINT Width;
  1237. UINT Height;
  1238. } D3DSURFACE_DESC;
  1239. typedef struct _D3DLOCKED_RECT
  1240. {
  1241. INT Pitch;
  1242. void* pBits;
  1243. } D3DLOCKED_RECT;
  1244. typedef struct _D3DRASTER_STATUS
  1245. {
  1246. BOOL InVBlank;
  1247. UINT ScanLine;
  1248. } D3DRASTER_STATUS;
  1249. typedef enum _D3DLIGHTTYPE {
  1250. D3DLIGHT_POINT = 1,
  1251. D3DLIGHT_SPOT = 2,
  1252. D3DLIGHT_DIRECTIONAL = 3,
  1253. D3DLIGHT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  1254. } D3DLIGHTTYPE;
  1255. typedef struct _D3DVECTOR {
  1256. float x;
  1257. float y;
  1258. float z;
  1259. } D3DVECTOR;
  1260. class D3DXVECTOR2
  1261. {
  1262. public:
  1263. operator FLOAT* ();
  1264. operator CONST FLOAT* () const;
  1265. float x,y;
  1266. };
  1267. class D3DXVECTOR3 : public D3DVECTOR
  1268. {
  1269. public:
  1270. D3DXVECTOR3() {}
  1271. D3DXVECTOR3( float a, float b, float c );
  1272. operator FLOAT* ();
  1273. operator CONST FLOAT* () const;
  1274. };
  1275. typedef enum _D3DXINCLUDE_TYPE
  1276. {
  1277. D3DXINC_LOCAL,
  1278. // force 32-bit size enum
  1279. D3DXINC_FORCE_DWORD = 0x7fffffff
  1280. } D3DXINCLUDE_TYPE;
  1281. typedef struct _D3DLIGHT9 {
  1282. D3DLIGHTTYPE Type; /* Type of light source */
  1283. D3DCOLORVALUE Diffuse; /* Diffuse color of light */
  1284. D3DCOLORVALUE Specular; /* Specular color of light */
  1285. D3DCOLORVALUE Ambient; /* Ambient color of light */
  1286. D3DVECTOR Position; /* Position in world space */
  1287. D3DVECTOR Direction; /* Direction in world space */
  1288. float Range; /* Cutoff range */
  1289. float Falloff; /* Falloff */
  1290. float Attenuation0; /* Constant attenuation */
  1291. float Attenuation1; /* Linear attenuation */
  1292. float Attenuation2; /* Quadratic attenuation */
  1293. float Theta; /* Inner angle of spotlight cone */
  1294. float Phi; /* Outer angle of spotlight cone */
  1295. } D3DLIGHT9;
  1296. class D3DXVECTOR4
  1297. {
  1298. public:
  1299. D3DXVECTOR4() {}
  1300. D3DXVECTOR4( float a, float b, float c, float d );
  1301. float x,y,z,w;
  1302. };
  1303. //----------------------------------------------------------------------------
  1304. // D3DXMACRO:
  1305. // ----------
  1306. // Preprocessor macro definition. The application pass in a NULL-terminated
  1307. // array of this structure to various D3DX APIs. This enables the application
  1308. // to #define tokens at runtime, before the file is parsed.
  1309. //----------------------------------------------------------------------------
  1310. typedef struct _D3DXMACRO
  1311. {
  1312. LPCSTR Name;
  1313. LPCSTR Definition;
  1314. } D3DXMACRO, *LPD3DXMACRO;
  1315. // ------------------------------------------------------------------------------------------------------------------------------ //
  1316. // ------------------------------------------------------------------------------------------------------------------------------ //
  1317. // **** FIXED FUNCTION STUFF - None of this stuff needs support in GL.
  1318. //
  1319. // Also look for any functions marked with "**** FIXED FUNCTION STUFF"
  1320. //
  1321. // It's only laying around here so we don't have to chop up the shader system a lot to strip out the fixed function code paths.
  1322. // ------------------------------------------------------------------------------------------------------------------------------ //
  1323. // ------------------------------------------------------------------------------------------------------------------------------ //
  1324. // **** FIXED FUNCTION STUFF - None of this stuff needs support in GL.
  1325. typedef enum _D3DTRANSFORMSTATETYPE {
  1326. D3DTS_VIEW = 2,
  1327. D3DTS_PROJECTION = 3,
  1328. D3DTS_TEXTURE0 = 16,
  1329. D3DTS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  1330. } D3DTRANSFORMSTATETYPE;
  1331. // **** FIXED FUNCTION STUFF - None of this stuff needs support in GL.
  1332. typedef enum _D3DTEXTUREOP
  1333. {
  1334. // Control
  1335. D3DTOP_DISABLE = 1, // disables stage
  1336. D3DTOP_SELECTARG1 = 2, // the default
  1337. D3DTOP_SELECTARG2 = 3,
  1338. // Modulate
  1339. D3DTOP_MODULATE = 4, // multiply args together
  1340. D3DTOP_MODULATE2X = 5, // multiply and 1 bit
  1341. D3DTOP_MODULATE4X = 6, // multiply and 2 bits
  1342. // Add
  1343. D3DTOP_ADD = 7, // add arguments together
  1344. D3DTOP_ADDSIGNED = 8, // add with -0.5 bias
  1345. D3DTOP_ADDSIGNED2X = 9, // as above but left 1 bit
  1346. D3DTOP_SUBTRACT = 10, // Arg1 - Arg2, with no saturation
  1347. D3DTOP_ADDSMOOTH = 11, // add 2 args, subtract product
  1348. // Arg1 + Arg2 - Arg1*Arg2
  1349. // = Arg1 + (1-Arg1)*Arg2
  1350. // Linear alpha blend: Arg1*(Alpha) + Arg2*(1-Alpha)
  1351. D3DTOP_BLENDDIFFUSEALPHA = 12, // iterated alpha
  1352. D3DTOP_BLENDTEXTUREALPHA = 13, // texture alpha
  1353. D3DTOP_BLENDFACTORALPHA = 14, // alpha from D3DRS_TEXTUREFACTOR
  1354. // Linear alpha blend with pre-multiplied arg1 input: Arg1 + Arg2*(1-Alpha)
  1355. D3DTOP_BLENDTEXTUREALPHAPM = 15, // texture alpha
  1356. D3DTOP_BLENDCURRENTALPHA = 16, // by alpha of current color
  1357. // Specular mapping
  1358. D3DTOP_PREMODULATE = 17, // modulate with next texture before use
  1359. D3DTOP_MODULATEALPHA_ADDCOLOR = 18, // Arg1.RGB + Arg1.A*Arg2.RGB
  1360. // COLOROP only
  1361. D3DTOP_MODULATECOLOR_ADDALPHA = 19, // Arg1.RGB*Arg2.RGB + Arg1.A
  1362. // COLOROP only
  1363. D3DTOP_MODULATEINVALPHA_ADDCOLOR = 20, // (1-Arg1.A)*Arg2.RGB + Arg1.RGB
  1364. // COLOROP only
  1365. D3DTOP_MODULATEINVCOLOR_ADDALPHA = 21, // (1-Arg1.RGB)*Arg2.RGB + Arg1.A
  1366. // COLOROP only
  1367. // Bump mapping
  1368. D3DTOP_BUMPENVMAP = 22, // per pixel env map perturbation
  1369. D3DTOP_BUMPENVMAPLUMINANCE = 23, // with luminance channel
  1370. // This can do either diffuse or specular bump mapping with correct input.
  1371. // Performs the function (Arg1.R*Arg2.R + Arg1.G*Arg2.G + Arg1.B*Arg2.B)
  1372. // where each component has been scaled and offset to make it signed.
  1373. // The result is replicated into all four (including alpha) channels.
  1374. // This is a valid COLOROP only.
  1375. D3DTOP_DOTPRODUCT3 = 24,
  1376. // Triadic ops
  1377. D3DTOP_MULTIPLYADD = 25, // Arg0 + Arg1*Arg2
  1378. D3DTOP_LERP = 26, // (Arg0)*Arg1 + (1-Arg0)*Arg2
  1379. D3DTOP_FORCE_DWORD = 0x7fffffff,
  1380. } D3DTEXTUREOP;
  1381. // **** FIXED FUNCTION STUFF - None of this stuff needs support in GL.
  1382. typedef enum _D3DTEXTURESTAGESTATETYPE
  1383. {
  1384. D3DTSS_COLOROP = 1, /* D3DTEXTUREOP - per-stage blending controls for color channels */
  1385. D3DTSS_COLORARG1 = 2, /* D3DTA_* (texture arg) */
  1386. D3DTSS_COLORARG2 = 3, /* D3DTA_* (texture arg) */
  1387. D3DTSS_ALPHAOP = 4, /* D3DTEXTUREOP - per-stage blending controls for alpha channel */
  1388. D3DTSS_ALPHAARG1 = 5, /* D3DTA_* (texture arg) */
  1389. D3DTSS_ALPHAARG2 = 6, /* D3DTA_* (texture arg) */
  1390. D3DTSS_BUMPENVMAT00 = 7, /* float (bump mapping matrix) */
  1391. D3DTSS_BUMPENVMAT01 = 8, /* float (bump mapping matrix) */
  1392. D3DTSS_BUMPENVMAT10 = 9, /* float (bump mapping matrix) */
  1393. D3DTSS_BUMPENVMAT11 = 10, /* float (bump mapping matrix) */
  1394. D3DTSS_TEXCOORDINDEX = 11, /* identifies which set of texture coordinates index this texture */
  1395. D3DTSS_BUMPENVLOFFSET = 23, /* float offset for bump map luminance */
  1396. D3DTSS_TEXTURETRANSFORMFLAGS = 24, /* D3DTEXTURETRANSFORMFLAGS controls texture transform */
  1397. D3DTSS_COLORARG0 = 26, /* D3DTA_* third arg for triadic ops */
  1398. D3DTSS_RESULTARG = 28, /* D3DTA_* arg for result (CURRENT or TEMP) */
  1399. D3DTSS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  1400. } D3DTEXTURESTAGESTATETYPE;
  1401. // ------------------------------------------------------------------------------------------------------------------------------ //
  1402. // INTERFACES
  1403. // ------------------------------------------------------------------------------------------------------------------------------ //
  1404. struct IDirect3DResource9 : public IUnknown
  1405. {
  1406. IDirect3DDevice9 *m_device; // parent device
  1407. D3DRESOURCETYPE m_restype;
  1408. DWORD SetPriority(DWORD PriorityNew);
  1409. };
  1410. struct IDirect3DBaseTexture9 : public IDirect3DResource9 // "A Texture.."
  1411. {
  1412. D3DSURFACE_DESC m_descZero; // desc of top level.
  1413. CGLMTex *m_tex; // a CGLMTex can represent all forms of tex
  1414. int m_srgbFlipCount;
  1415. virtual ~IDirect3DBaseTexture9();
  1416. D3DRESOURCETYPE GetType();
  1417. DWORD GetLevelCount();
  1418. HRESULT GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc);
  1419. };
  1420. struct IDirect3DTexture9 : public IDirect3DBaseTexture9 // "Texture 2D"
  1421. {
  1422. IDirect3DSurface9 *m_surfZero; // surf of top level.
  1423. virtual ~IDirect3DTexture9();
  1424. HRESULT LockRect(UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags);
  1425. HRESULT UnlockRect(UINT Level);
  1426. HRESULT GetSurfaceLevel(UINT Level,IDirect3DSurface9** ppSurfaceLevel);
  1427. };
  1428. struct IDirect3DCubeTexture9 : public IDirect3DBaseTexture9 // "Texture Cube Map"
  1429. {
  1430. IDirect3DSurface9 *m_surfZero[6]; // surfs of top level.
  1431. virtual ~IDirect3DCubeTexture9();
  1432. HRESULT GetCubeMapSurface(D3DCUBEMAP_FACES FaceType,UINT Level,IDirect3DSurface9** ppCubeMapSurface);
  1433. HRESULT GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc);
  1434. };
  1435. struct IDirect3DVolumeTexture9 : public IDirect3DBaseTexture9 // "Texture 3D"
  1436. {
  1437. IDirect3DSurface9 *m_surfZero; // surf of top level.
  1438. D3DVOLUME_DESC m_volDescZero; // volume desc top level
  1439. virtual ~IDirect3DVolumeTexture9();
  1440. HRESULT LockBox(UINT Level,D3DLOCKED_BOX* pLockedVolume,CONST D3DBOX* pBox,DWORD Flags);
  1441. HRESULT UnlockBox(UINT Level);
  1442. HRESULT GetLevelDesc( UINT level, D3DVOLUME_DESC *pDesc );
  1443. };
  1444. // for the moment, a "D3D surface" is modeled as a GLM tex, a face, and a mip.
  1445. // no Create method, these are filled in by the various create surface methods.
  1446. struct IDirect3DSurface9 : public IDirect3DResource9
  1447. {
  1448. virtual ~IDirect3DSurface9();
  1449. HRESULT LockRect(D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags);
  1450. HRESULT UnlockRect();
  1451. HRESULT GetDesc(D3DSURFACE_DESC *pDesc);
  1452. D3DSURFACE_DESC m_desc;
  1453. CGLMTex *m_tex;
  1454. int m_face;
  1455. int m_mip;
  1456. };
  1457. struct IDirect3D9 : public IUnknown
  1458. {
  1459. public:
  1460. virtual ~IDirect3D9();
  1461. UINT GetAdapterCount(); //cheese: returns 1
  1462. HRESULT GetDeviceCaps (UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps);
  1463. HRESULT GetAdapterIdentifier (UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier);
  1464. HRESULT CheckDeviceFormat (UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat);
  1465. UINT GetAdapterModeCount (UINT Adapter,D3DFORMAT Format);
  1466. HRESULT EnumAdapterModes (UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode);
  1467. HRESULT CheckDeviceType (UINT Adapter,D3DDEVTYPE DevType,D3DFORMAT AdapterFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed);
  1468. HRESULT GetAdapterDisplayMode (UINT Adapter,D3DDISPLAYMODE* pMode);
  1469. HRESULT CheckDepthStencilMatch (UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat);
  1470. HRESULT CheckDeviceMultiSampleType (UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels);
  1471. HRESULT CreateDevice (UINT Adapter,D3DDEVTYPE DeviceType,VD3DHWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface);
  1472. };
  1473. struct IDirect3DSwapChain9 : public IUnknown
  1474. {
  1475. };
  1476. // typedef enum D3DDECLUSAGE
  1477. // {
  1478. // D3DDECLUSAGE_POSITION = 0,
  1479. // D3DDECLUSAGE_BLENDWEIGHT = 1,
  1480. // D3DDECLUSAGE_BLENDINDICES = 2,
  1481. // D3DDECLUSAGE_NORMAL = 3,
  1482. // D3DDECLUSAGE_PSIZE = 4,
  1483. // D3DDECLUSAGE_TEXCOORD = 5,
  1484. // D3DDECLUSAGE_TANGENT = 6,
  1485. // D3DDECLUSAGE_BINORMAL = 7,
  1486. // D3DDECLUSAGE_TESSFACTOR = 8,
  1487. // D3DDECLUSAGE_POSITIONT = 9,
  1488. // D3DDECLUSAGE_COLOR = 10,
  1489. // D3DDECLUSAGE_FOG = 11,
  1490. // D3DDECLUSAGE_DEPTH = 12,
  1491. // D3DDECLUSAGE_SAMPLE = 13,
  1492. // } D3DDECLUSAGE, *LPD3DDECLUSAGE;
  1493. // Constants
  1494. //
  1495. // D3DDECLUSAGE_POSITION
  1496. // Position data ranging from (-1,-1) to (1,1). Use D3DDECLUSAGE_POSITION with
  1497. // a usage index of 0 to specify untransformed position for fixed function
  1498. // vertex processing and the n-patch tessellator. Use D3DDECLUSAGE_POSITION
  1499. // with a usage index of 1 to specify untransformed position in the fixed
  1500. // function vertex shader for vertex tweening.
  1501. //
  1502. // D3DDECLUSAGE_BLENDWEIGHT
  1503. // Blending weight data. Use D3DDECLUSAGE_BLENDWEIGHT with a usage index of 0
  1504. // to specify the blend weights used in indexed and nonindexed vertex
  1505. // blending.
  1506. //
  1507. // D3DDECLUSAGE_BLENDINDICES
  1508. // Blending indices data. Use D3DDECLUSAGE_BLENDINDICES with a usage index of
  1509. // 0 to specify matrix indices for indexed paletted skinning.
  1510. //
  1511. // D3DDECLUSAGE_NORMAL
  1512. // Vertex normal data. Use D3DDECLUSAGE_NORMAL with a usage index of 0 to
  1513. // specify vertex normals for fixed function vertex processing and the n-patch
  1514. // tessellator. Use D3DDECLUSAGE_NORMAL with a usage index of 1 to specify
  1515. // vertex normals for fixed function vertex processing for vertex tweening.
  1516. //
  1517. // D3DDECLUSAGE_PSIZE
  1518. // Point size data. Use D3DDECLUSAGE_PSIZE with a usage index of 0 to specify
  1519. // the point-size attribute used by the setup engine of the rasterizer to
  1520. // expand a point into a quad for the point-sprite functionality.
  1521. //
  1522. // D3DDECLUSAGE_TEXCOORD
  1523. // Texture coordinate data. Use D3DDECLUSAGE_TEXCOORD, n to specify texture
  1524. // coordinates in fixed function vertex processing and in pixel shaders prior
  1525. // to ps_3_0. These can be used to pass user defined data.
  1526. //
  1527. // D3DDECLUSAGE_TANGENT
  1528. // Vertex tangent data.
  1529. //
  1530. // D3DDECLUSAGE_BINORMAL
  1531. // Vertex binormal data.
  1532. //
  1533. // D3DDECLUSAGE_TESSFACTOR
  1534. // Single positive floating point value. Use D3DDECLUSAGE_TESSFACTOR with a
  1535. // usage index of 0 to specify a tessellation factor used in the tessellation
  1536. // unit to control the rate of tessellation. For more information about the
  1537. // data type, see D3DDECLTYPE_FLOAT1.
  1538. //
  1539. // D3DDECLUSAGE_POSITIONT
  1540. // Vertex data contains transformed position data ranging from (0,0) to
  1541. // (viewport width, viewport height). Use D3DDECLUSAGE_POSITIONT with a usage
  1542. // index of 0 to specify transformed position. When a declaration containing
  1543. // this is set, the pipeline does not perform vertex processing.
  1544. //
  1545. // D3DDECLUSAGE_COLOR
  1546. // Vertex data contains diffuse or specular color. Use D3DDECLUSAGE_COLOR with
  1547. // a usage index of 0 to specify the diffuse color in the fixed function
  1548. // vertex shader and pixel shaders prior to ps_3_0. Use D3DDECLUSAGE_COLOR
  1549. // with a usage index of 1 to specify the specular color in the fixed function
  1550. // vertex shader and pixel shaders prior to ps_3_0.
  1551. //
  1552. // D3DDECLUSAGE_FOG
  1553. // Vertex data contains fog data. Use D3DDECLUSAGE_FOG with a usage index of 0
  1554. // to specify a fog blend value used after pixel shading finishes. This
  1555. // applies to pixel shaders prior to version ps_3_0.
  1556. //
  1557. // D3DDECLUSAGE_DEPTH
  1558. // Vertex data contains depth data.
  1559. //
  1560. // D3DDECLUSAGE_SAMPLE
  1561. // Vertex data contains sampler data. Use D3DDECLUSAGE_SAMPLE with a usage
  1562. // index of 0 to specify the displacement value to look up. It can be used
  1563. // only with D3DDECLUSAGE_LOOKUPPRESAMPLED or D3DDECLUSAGE_LOOKUP.
  1564. //note the form of the list terminator..
  1565. // #define D3DDECL_END() {0xFF,0,D3DDECLTYPE_UNUSED,0,0,0}
  1566. // typedef struct _D3DVERTEXELEMENT9
  1567. // {
  1568. // WORD Stream; // Stream index
  1569. // WORD Offset; // Offset in the stream in bytes
  1570. // BYTE Type; // Data type
  1571. // BYTE Method; // Processing method
  1572. // BYTE Usage; // Semantics
  1573. // BYTE UsageIndex; // Semantic index
  1574. // } D3DVERTEXELEMENT9, *LPD3DVERTEXELEMENT9;
  1575. #define MAX_D3DVERTEXELEMENTS 16
  1576. struct D3DVERTEXELEMENT9_GL
  1577. {
  1578. // fields right out of the original decl element (copied)
  1579. D3DVERTEXELEMENT9 m_dxdecl; // d3d info
  1580. // WORD Stream; // Stream index
  1581. // WORD Offset; // Offset in the stream in bytes
  1582. // BYTE Type; // Data type
  1583. // BYTE Method; // Processing method
  1584. // BYTE Usage; // Semantics
  1585. // BYTE UsageIndex; // Semantic index
  1586. GLMVertexAttributeDesc m_gldecl;
  1587. // CGLMBuffer *m_buffer; // late-dropped from selected stream desc (left NULL, will replace with stream source buffer at sync time)
  1588. // GLuint m_datasize; // component count (1,2,3,4) of the attrib
  1589. // GLenum m_datatype; // data type of the attribute (GL_FLOAT et al)
  1590. // GLuint m_stride; // late-dropped from stream desc
  1591. // GLuint m_offset; // net offset to attribute 'zero' within the stream data. Add the stream offset before passing to GL.
  1592. // GLuint m_normalized; // net offset to attribute 'zero' within the stream data. Add the stream offset before passing to GL.
  1593. };
  1594. struct IDirect3DVertexDeclaration9 : public IUnknown
  1595. {
  1596. //public:
  1597. uint m_elemCount;
  1598. D3DVERTEXELEMENT9_GL m_elements[ MAX_D3DVERTEXELEMENTS ];
  1599. virtual ~IDirect3DVertexDeclaration9();
  1600. };
  1601. struct IDirect3DQuery9 : public IDirect3DResource9 //was IUnknown
  1602. {
  1603. //public:
  1604. D3DQUERYTYPE m_type; // D3DQUERYTYPE_OCCLUSION or D3DQUERYTYPE_EVENT
  1605. GLMContext *m_ctx;
  1606. CGLMQuery *m_query;
  1607. virtual ~IDirect3DQuery9();
  1608. HRESULT Issue(DWORD dwIssueFlags);
  1609. HRESULT GetData(void* pData,DWORD dwSize,DWORD dwGetDataFlags);
  1610. };
  1611. struct IDirect3DVertexBuffer9 : public IDirect3DResource9 //was IUnknown
  1612. {
  1613. //public:
  1614. GLMContext *m_ctx;
  1615. CGLMBuffer *m_vtxBuffer;
  1616. D3DVERTEXBUFFER_DESC m_vtxDesc; // to satisfy GetDesc
  1617. virtual ~IDirect3DVertexBuffer9();
  1618. HRESULT Lock(UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags);
  1619. HRESULT Unlock();
  1620. };
  1621. struct IDirect3DIndexBuffer9 : public IDirect3DResource9 //was IUnknown
  1622. {
  1623. //public:
  1624. GLMContext *m_ctx;
  1625. CGLMBuffer *m_idxBuffer;
  1626. D3DINDEXBUFFER_DESC m_idxDesc; // to satisfy GetDesc
  1627. virtual ~IDirect3DIndexBuffer9();
  1628. HRESULT Lock(UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags);
  1629. HRESULT Unlock();
  1630. HRESULT GetDesc(D3DINDEXBUFFER_DESC *pDesc);
  1631. };
  1632. struct IDirect3DPixelShader9 : public IDirect3DResource9 //was IUnknown
  1633. {
  1634. //public:
  1635. CGLMProgram *m_pixProgram;
  1636. uint m_pixHighWater; // count of active constant slots referenced by shader.
  1637. uint m_pixSamplerMask; // (1<<n) mask of samplers referemnced by this pixel shader
  1638. // this can help FlushSamplers avoid SRGB flipping on textures not being referenced...
  1639. virtual ~IDirect3DPixelShader9();
  1640. };
  1641. struct IDirect3DVertexShader9 : public IDirect3DResource9 //was IUnknown
  1642. {
  1643. //public:
  1644. CGLMProgram *m_vtxProgram;
  1645. uint m_vtxHighWater; // count of active constant slots referenced by shader.
  1646. unsigned char m_vtxAttribMap[16]; // high nibble is usage, low nibble is usageindex, array position is attrib number
  1647. virtual ~IDirect3DVertexShader9();
  1648. };
  1649. struct ID3DXMatrixStack : public IUnknown
  1650. {
  1651. //public:
  1652. CUtlVector<D3DMATRIX> m_stack;
  1653. int m_stackTop; // top of stack is at the highest index, this is that index. push increases, pop decreases.
  1654. HRESULT Create( void );
  1655. D3DXMATRIX* GetTop();
  1656. void Push();
  1657. void Pop();
  1658. void LoadIdentity();
  1659. void LoadMatrix( const D3DXMATRIX *pMat );
  1660. void MultMatrix( const D3DXMATRIX *pMat );
  1661. void MultMatrixLocal( const D3DXMATRIX *pMat );
  1662. HRESULT ScaleLocal(FLOAT x, FLOAT y, FLOAT z);
  1663. // Left multiply the current matrix with the computed rotation
  1664. // matrix, counterclockwise about the given axis with the given angle.
  1665. // (rotation is about the local origin of the object)
  1666. HRESULT RotateAxisLocal(CONST D3DXVECTOR3* pV, FLOAT Angle);
  1667. // Left multiply the current matrix with the computed translation
  1668. // matrix. (transformation is about the local origin of the object)
  1669. HRESULT TranslateLocal(FLOAT x, FLOAT y, FLOAT z);
  1670. };
  1671. typedef ID3DXMatrixStack* LPD3DXMATRIXSTACK;
  1672. struct IDirect3DDevice9Params
  1673. {
  1674. UINT m_adapter;
  1675. D3DDEVTYPE m_deviceType;
  1676. VD3DHWND m_focusWindow;
  1677. DWORD m_behaviorFlags;
  1678. D3DPRESENT_PARAMETERS m_presentationParameters;
  1679. };
  1680. #define D3D_MAX_STREAMS 16
  1681. struct D3DStreamDesc
  1682. {
  1683. IDirect3DVertexBuffer9 *m_vtxBuffer;
  1684. uint m_offset;
  1685. uint m_stride;
  1686. };
  1687. struct D3DIndexDesc
  1688. {
  1689. IDirect3DIndexBuffer9 *m_idxBuffer;
  1690. };
  1691. // we latch sampler values until draw time and then convert them all to GL form
  1692. // note these are similar in name to the fields of a GLMTexSamplingParams but contents are not
  1693. // particularly in the texture filtering area
  1694. struct D3DSamplerDesc
  1695. {
  1696. D3DTEXTUREADDRESS m_addressModes[3]; // D3DTEXTUREADDRESS modes for S,T,R
  1697. DWORD m_borderColor; // DWORD bordercolor
  1698. D3DTEXTUREFILTERTYPE m_magFilter; // mag filter
  1699. D3DTEXTUREFILTERTYPE m_minFilter; // min filter
  1700. D3DTEXTUREFILTERTYPE m_mipFilter; // mip filter
  1701. float m_mipmapBias; // float: mipmap bias
  1702. DWORD m_maxMipLevel; // DWORD 0..(n-1) LOD index of largest map to use (0 == largest)
  1703. DWORD m_maxAniso; // D3DSAMP_MAXANISOTROPY max aniso
  1704. DWORD m_srgb; // D3DSAMP_SRGBTEXTURE 0 = no SRGB sampling
  1705. DWORD m_shadowFilter; // D3DSAMP_SHADOWFILTER
  1706. };
  1707. struct IDirect3DDevice9 : public IUnknown
  1708. {
  1709. public:
  1710. // members
  1711. IDirect3DDevice9Params m_params; // mirror of the creation inputs
  1712. // D3D flavor stuff
  1713. IDirect3DSurface9 *m_rtSurfaces[16]; // current color RT surfaces. [0] is initially == m_defaultColorSurface
  1714. IDirect3DSurface9 *m_dsSurface; // current DS RT surface. can be changed!
  1715. IDirect3DSurface9 *m_defaultColorSurface; // default color surface.
  1716. IDirect3DSurface9 *m_defaultDepthStencilSurface; // queried by GetDepthStencilSurface.
  1717. IDirect3DVertexDeclaration9 *m_vertDecl; // Set by SetVertexDeclaration...
  1718. D3DStreamDesc m_streams[ D3D_MAX_STREAMS ]; // Set by SetStreamSource..
  1719. D3DIndexDesc m_indices; // Set by SetIndices..
  1720. IDirect3DVertexShader9 *m_vertexShader; // Set by SetVertexShader...
  1721. IDirect3DPixelShader9 *m_pixelShader; // Set by SetPixelShader...
  1722. IDirect3DBaseTexture9 *m_textures[16]; // set by SetTexture... NULL if stage inactive
  1723. D3DSamplerDesc m_samplers[16]; // set by SetSamplerState..
  1724. // GLM flavor stuff
  1725. GLMContext *m_ctx;
  1726. CGLMFBO *m_drawableFBO; // this FBO should have all the attachments set to match m_rtSurfaces and m_dsSurface.
  1727. // GL state
  1728. struct
  1729. {
  1730. // render state buckets
  1731. GLAlphaTestEnable_t m_AlphaTestEnable;
  1732. GLAlphaTestFunc_t m_AlphaTestFunc;
  1733. GLDepthTestEnable_t m_DepthTestEnable;
  1734. GLDepthMask_t m_DepthMask;
  1735. GLDepthFunc_t m_DepthFunc;
  1736. GLClipPlaneEnable_t m_ClipPlaneEnable[kGLMUserClipPlanes];
  1737. GLClipPlaneEquation_t m_ClipPlaneEquation[kGLMUserClipPlanes];
  1738. GLColorMaskSingle_t m_ColorMaskSingle;
  1739. GLColorMaskMultiple_t m_ColorMaskMultiple;
  1740. GLCullFaceEnable_t m_CullFaceEnable;
  1741. GLCullFrontFace_t m_CullFrontFace;
  1742. GLPolygonMode_t m_PolygonMode;
  1743. GLDepthBias_t m_DepthBias;
  1744. GLScissorEnable_t m_ScissorEnable;
  1745. GLScissorBox_t m_ScissorBox;
  1746. GLViewportBox_t m_ViewportBox;
  1747. GLViewportDepthRange_t m_ViewportDepthRange;
  1748. GLBlendEnable_t m_BlendEnable;
  1749. GLBlendFactor_t m_BlendFactor;
  1750. GLBlendEquation_t m_BlendEquation;
  1751. GLBlendColor_t m_BlendColor;
  1752. GLBlendEnableSRGB_t m_BlendEnableSRGB;
  1753. GLStencilTestEnable_t m_StencilTestEnable;
  1754. GLStencilFunc_t m_StencilFunc;
  1755. GLStencilOp_t m_StencilOp;
  1756. GLStencilWriteMask_t m_StencilWriteMask;
  1757. GLClearColor_t m_ClearColor;
  1758. GLClearDepth_t m_ClearDepth;
  1759. GLClearStencil_t m_ClearStencil;
  1760. bool m_FogEnable; // not really pushed to GL, just latched here
  1761. // samplers
  1762. GLMTexSamplingParams m_samplers[ 16 ];
  1763. // bindings...hmmm...
  1764. // dirty-bits
  1765. uint m_stateDirtyMask; // covers the state blocks, indexed by 1<<n, n = EGLMStateBlockType
  1766. uint m_samplerDirtyMask; // covers the samplers, indexed 1<<n, n = sampler index
  1767. } gl;
  1768. // methods
  1769. public:
  1770. virtual ~IDirect3DDevice9();
  1771. // Create call invoked from IDirect3D9
  1772. HRESULT Create( IDirect3DDevice9Params *params );
  1773. //
  1774. // Basics
  1775. //
  1776. HRESULT Reset(D3DPRESENT_PARAMETERS* pPresentationParameters);
  1777. HRESULT SetViewport(CONST D3DVIEWPORT9* pViewport);
  1778. HRESULT BeginScene();
  1779. HRESULT Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil);
  1780. HRESULT EndScene();
  1781. HRESULT Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,VD3DHWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
  1782. // textures
  1783. HRESULT CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,VD3DHANDLE* pSharedHandle, char *debugLabel=NULL);
  1784. HRESULT CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,VD3DHANDLE* pSharedHandle, char *debugLabel=NULL);
  1785. HRESULT CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,VD3DHANDLE* pSharedHandle, char *debugLabel=NULL);
  1786. HRESULT SetTexture(DWORD Stage,IDirect3DBaseTexture9* pTexture);
  1787. HRESULT GetTexture(DWORD Stage,IDirect3DBaseTexture9** ppTexture);
  1788. // render targets, color and depthstencil, surfaces, blit
  1789. HRESULT CreateRenderTarget(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Lockable,IDirect3DSurface9** ppSurface,VD3DHANDLE* pSharedHandle, char *debugLabel=NULL);
  1790. HRESULT SetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget);
  1791. HRESULT GetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9** ppRenderTarget);
  1792. HRESULT CreateOffscreenPlainSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DPOOL Pool,IDirect3DSurface9** ppSurface,VD3DHANDLE* pSharedHandle);
  1793. HRESULT CreateDepthStencilSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Discard,IDirect3DSurface9** ppSurface,VD3DHANDLE* pSharedHandle);
  1794. HRESULT SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil);
  1795. HRESULT GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface);
  1796. HRESULT GetRenderTargetData(IDirect3DSurface9* pRenderTarget,IDirect3DSurface9* pDestSurface); // ? is anyone using this ?
  1797. HRESULT GetFrontBufferData(UINT iSwapChain,IDirect3DSurface9* pDestSurface);
  1798. HRESULT StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect,D3DTEXTUREFILTERTYPE Filter);
  1799. // pixel shaders
  1800. HRESULT CreatePixelShader(CONST DWORD* pFunction,IDirect3DPixelShader9** ppShader, const char *pShaderName, char *debugLabel = NULL);
  1801. HRESULT SetPixelShader(IDirect3DPixelShader9* pShader);
  1802. HRESULT SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
  1803. HRESULT SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
  1804. HRESULT SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
  1805. // vertex shaders
  1806. HRESULT CreateVertexShader(CONST DWORD* pFunction,IDirect3DVertexShader9** ppShader, const char *pShaderName, char *debugLabel = NULL);
  1807. HRESULT SetVertexShader(IDirect3DVertexShader9* pShader);
  1808. HRESULT SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
  1809. HRESULT SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
  1810. HRESULT SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
  1811. HRESULT LinkShaderPair( IDirect3DVertexShader9* vs, IDirect3DPixelShader9* ps );
  1812. HRESULT QueryShaderPair( int index, GLMShaderPairInfo *infoOut );
  1813. // vertex buffers
  1814. HRESULT CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements,IDirect3DVertexDeclaration9** ppDecl);
  1815. HRESULT SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl);
  1816. HRESULT SetFVF(DWORD FVF); // we might not be using these ?
  1817. HRESULT GetFVF(DWORD* pFVF);
  1818. HRESULT CreateVertexBuffer(UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer9** ppVertexBuffer,VD3DHANDLE* pSharedHandle);
  1819. HRESULT SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride);
  1820. // index buffers
  1821. HRESULT CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer9** ppIndexBuffer,VD3DHANDLE* pSharedHandle);
  1822. HRESULT SetIndices(IDirect3DIndexBuffer9* pIndexData);
  1823. // response to retired objects (when refcount goes to zero and they self-delete..)
  1824. void ReleasedTexture ( IDirect3DBaseTexture9 *baseTex ); // called from texture destructor - need to scrub samplers
  1825. void ReleasedSurface ( IDirect3DSurface9 *surface ); // called from any surface destructor - need to scrub RT table if an RT
  1826. void ReleasedPixelShader ( IDirect3DPixelShader9 *pixelShader ); // called from IDirect3DPixelShader9 destructor
  1827. void ReleasedVertexShader ( IDirect3DVertexShader9 *vertexShader ); // called from IDirect3DVertexShader9 destructor
  1828. void ReleasedVertexBuffer ( IDirect3DVertexBuffer9 *vertexBuffer ); // called from IDirect3DVertexBuffer9 destructor
  1829. void ReleasedIndexBuffer ( IDirect3DIndexBuffer9 *indexBuffer ); // called from IDirect3DIndexBuffer9 destructor
  1830. void ReleasedQuery ( IDirect3DQuery9 *query ); // called from IDirect3DQuery9 destructor
  1831. // State management.
  1832. HRESULT SetRenderState(D3DRENDERSTATETYPE State,DWORD Value);
  1833. HRESULT SetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value);
  1834. // Flushing changes to GL
  1835. HRESULT FlushStates( uint mask );
  1836. HRESULT FlushSamplers(); // push SetRenderState and SetSamplerState changes
  1837. HRESULT FlushIndexBindings( void ); // push index buffer (set index ptr)
  1838. HRESULT FlushVertexBindings( uint baseVertexIndex ); // push vertex streams (set attrib ptrs)
  1839. HRESULT FlushGLM( void );
  1840. // Draw.
  1841. HRESULT DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount);
  1842. HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
  1843. HRESULT DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
  1844. // misc
  1845. BOOL ShowCursor(BOOL bShow);
  1846. HRESULT ValidateDevice(DWORD* pNumPasses);
  1847. HRESULT SetMaterial(CONST D3DMATERIAL9* pMaterial);
  1848. HRESULT LightEnable(DWORD Index,BOOL Enable);
  1849. HRESULT SetScissorRect(CONST RECT* pRect);
  1850. HRESULT CreateQuery(D3DQUERYTYPE Type,IDirect3DQuery9** ppQuery);
  1851. HRESULT GetDeviceCaps(D3DCAPS9* pCaps);
  1852. HRESULT TestCooperativeLevel();
  1853. HRESULT EvictManagedResources();
  1854. HRESULT SetLight(DWORD Index,CONST D3DLIGHT9*);
  1855. void SetGammaRamp(UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp);
  1856. // Talk to JasonM about this one. It's tricky in GL.
  1857. HRESULT SetClipPlane(DWORD Index,CONST float* pPlane);
  1858. //
  1859. //
  1860. // **** FIXED FUNCTION STUFF - None of this stuff needs support in GL.
  1861. //
  1862. //
  1863. HRESULT SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix);
  1864. HRESULT SetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value);
  1865. };
  1866. struct ID3DXInclude
  1867. {
  1868. virtual HRESULT Open(D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes) = 0;
  1869. virtual HRESULT Close(LPCVOID pData) = 0;
  1870. };
  1871. typedef ID3DXInclude* LPD3DXINCLUDE;
  1872. struct ID3DXBuffer : public IUnknown
  1873. {
  1874. void* GetBufferPointer();
  1875. DWORD GetBufferSize();
  1876. };
  1877. typedef ID3DXBuffer* LPD3DXBUFFER;
  1878. class ID3DXConstantTable : public IUnknown
  1879. {
  1880. };
  1881. typedef ID3DXConstantTable* LPD3DXCONSTANTTABLE;
  1882. // ------------------------------------------------------------------------------------------------------------------------------ //
  1883. // D3DX stuff.
  1884. // ------------------------------------------------------------------------------------------------------------------------------ //
  1885. const char* D3DXGetPixelShaderProfile( IDirect3DDevice9 *pDevice );
  1886. D3DXMATRIX* D3DXMatrixMultiply( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
  1887. D3DXVECTOR3* D3DXVec3TransformCoord( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  1888. HRESULT D3DXCreateMatrixStack( DWORD Flags, LPD3DXMATRIXSTACK* ppStack);
  1889. void D3DXMatrixIdentity( D3DXMATRIX * );
  1890. D3DXINLINE D3DXVECTOR3* D3DXVec3Subtract( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1891. {
  1892. pOut->x = pV1->x - pV2->x;
  1893. pOut->y = pV1->y - pV2->y;
  1894. pOut->z = pV1->z - pV2->z;
  1895. return pOut;
  1896. }
  1897. D3DXINLINE D3DXVECTOR3* D3DXVec3Cross( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1898. {
  1899. D3DXVECTOR3 v;
  1900. v.x = pV1->y * pV2->z - pV1->z * pV2->y;
  1901. v.y = pV1->z * pV2->x - pV1->x * pV2->z;
  1902. v.z = pV1->x * pV2->y - pV1->y * pV2->x;
  1903. *pOut = v;
  1904. return pOut;
  1905. }
  1906. D3DXINLINE FLOAT D3DXVec3Dot( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1907. {
  1908. return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z;
  1909. }
  1910. D3DXMATRIX* D3DXMatrixInverse( D3DXMATRIX *pOut, FLOAT *pDeterminant, CONST D3DXMATRIX *pM );
  1911. D3DXMATRIX* D3DXMatrixTranspose( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM );
  1912. D3DXPLANE* D3DXPlaneNormalize( D3DXPLANE *pOut, CONST D3DXPLANE *pP);
  1913. D3DXVECTOR4* D3DXVec4Transform( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, CONST D3DXMATRIX *pM );
  1914. D3DXVECTOR4* D3DXVec4Normalize( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV );
  1915. D3DXMATRIX* D3DXMatrixTranslation( D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z );
  1916. // Build an ortho projection matrix. (right-handed)
  1917. D3DXMATRIX* D3DXMatrixOrthoOffCenterRH( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,FLOAT zf );
  1918. D3DXMATRIX* D3DXMatrixPerspectiveRH( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  1919. D3DXMATRIX* D3DXMatrixPerspectiveOffCenterRH( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, FLOAT zf );
  1920. // Transform a plane by a matrix. The vector (a,b,c) must be normal.
  1921. // M should be the inverse transpose of the transformation desired.
  1922. D3DXPLANE* D3DXPlaneTransform( D3DXPLANE *pOut, CONST D3DXPLANE *pP, CONST D3DXMATRIX *pM );
  1923. IDirect3D9 *Direct3DCreate9(UINT SDKVersion);
  1924. void D3DPERF_SetOptions( DWORD dwOptions );
  1925. HRESULT D3DXCompileShader(
  1926. LPCSTR pSrcData,
  1927. UINT SrcDataLen,
  1928. CONST D3DXMACRO* pDefines,
  1929. LPD3DXINCLUDE pInclude,
  1930. LPCSTR pFunctionName,
  1931. LPCSTR pProfile,
  1932. DWORD Flags,
  1933. LPD3DXBUFFER* ppShader,
  1934. LPD3DXBUFFER* ppErrorMsgs,
  1935. LPD3DXCONSTANTTABLE* ppConstantTable);
  1936. #endif // USE_ACTUAL_DX
  1937. // fake D3D usage constant for SRGB tex creation
  1938. #define D3DUSAGE_TEXTURE_SRGB (0x80000000L)
  1939. // fake D3D usage constant for deferred tex bits allocation
  1940. #define D3DUSAGE_TEXTURE_NOD3DMEMORY (0x40000000L)
  1941. #endif // DXABSTRACT_H
  1942. #endif // PS3