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.

1420 lines
53 KiB

  1. //================ Copyright (c) 1996-2012 Valve Corporation. All Rights Reserved. =================
  2. //
  3. // dxabstract.h
  4. //
  5. //==================================================================================================
  6. #ifndef DXABSTRACT_H
  7. #define DXABSTRACT_H
  8. #ifdef DX_TO_GL_ABSTRACTION
  9. #include "togl/rendermechanism.h"
  10. #include "tier0/platform.h"
  11. #include "tier0/dbg.h"
  12. #include "tier1/utlmap.h"
  13. // turn this on to get refcount logging from IUnknown
  14. #define IUNKNOWN_ALLOC_SPEW 0
  15. #define IUNKNOWN_ALLOC_SPEW_MARK_ALL 0
  16. TOGL_INTERFACE void toglGetClientRect( VD3DHWND hWnd, RECT *destRect );
  17. struct TOGL_CLASS IUnknown
  18. {
  19. int m_refcount[2];
  20. bool m_mark;
  21. IUnknown()
  22. {
  23. m_refcount[0] = 1;
  24. m_refcount[1] = 0;
  25. m_mark = (IUNKNOWN_ALLOC_SPEW_MARK_ALL != 0); // either all are marked, or only the ones that have SetMark(true) called on them
  26. #if IUNKNOWN_ALLOC_SPEW
  27. if (m_mark)
  28. {
  29. GLMPRINTF(("-A- IUnew (%08x) refc -> (%d,%d) ",this,m_refcount[0],m_refcount[1]));
  30. }
  31. #endif
  32. };
  33. virtual ~IUnknown()
  34. {
  35. #if IUNKNOWN_ALLOC_SPEW
  36. if (m_mark)
  37. {
  38. GLMPRINTF(("-A- IUdel (%08x) ",this ));
  39. }
  40. #endif
  41. };
  42. void AddRef( int which=0, char *comment = NULL )
  43. {
  44. Assert( which >= 0 );
  45. Assert( which < 2 );
  46. m_refcount[which]++;
  47. #if IUNKNOWN_ALLOC_SPEW
  48. if (m_mark)
  49. {
  50. GLMPRINTF(("-A- IUAddRef (%08x,%d) refc -> (%d,%d) [%s]",this,which,m_refcount[0],m_refcount[1],comment?comment:"...")) ;
  51. if (!comment)
  52. {
  53. GLMPRINTF(("")) ; // place to hang a breakpoint
  54. }
  55. }
  56. #endif
  57. };
  58. ULONG __stdcall Release( int which=0, char *comment = NULL )
  59. {
  60. Assert( which >= 0 );
  61. Assert( which < 2 );
  62. //int oldrefcs[2] = { m_refcount[0], m_refcount[1] };
  63. bool deleting = false;
  64. m_refcount[which]--;
  65. if ( (!m_refcount[0]) && (!m_refcount[1]) )
  66. {
  67. deleting = true;
  68. }
  69. #if IUNKNOWN_ALLOC_SPEW
  70. if (m_mark)
  71. {
  72. GLMPRINTF(("-A- IURelease (%08x,%d) refc -> (%d,%d) [%s] %s",this,which,m_refcount[0],m_refcount[1],comment?comment:"...",deleting?"->DELETING":""));
  73. if (!comment)
  74. {
  75. GLMPRINTF(("")) ; // place to hang a breakpoint
  76. }
  77. }
  78. #endif
  79. if (deleting)
  80. {
  81. if (m_mark)
  82. {
  83. GLMPRINTF(("")) ; // place to hang a breakpoint
  84. }
  85. delete this;
  86. return 0;
  87. }
  88. else
  89. {
  90. return m_refcount[0];
  91. }
  92. };
  93. void SetMark( bool markValue, char *comment=NULL )
  94. {
  95. #if IUNKNOWN_ALLOC_SPEW
  96. if (!m_mark && markValue) // leading edge detect
  97. {
  98. // print the same thing that the constructor would have printed if it had been marked from the beginning
  99. // i.e. it's anticipated that callers asking for marking will do so right at create time
  100. GLMPRINTF(("-A- IUSetMark (%08x) refc -> (%d,%d) (%s) ",this,m_refcount[0],m_refcount[1],comment?comment:"..."));
  101. }
  102. #endif
  103. m_mark = markValue;
  104. }
  105. };
  106. // ------------------------------------------------------------------------------------------------------------------------------ //
  107. // INTERFACES
  108. // ------------------------------------------------------------------------------------------------------------------------------ //
  109. struct TOGL_CLASS IDirect3DResource9 : public IUnknown
  110. {
  111. IDirect3DDevice9 *m_device; // parent device
  112. D3DRESOURCETYPE m_restype;
  113. DWORD SetPriority(DWORD PriorityNew);
  114. };
  115. struct TOGL_CLASS IDirect3DBaseTexture9 : public IDirect3DResource9 // "A Texture.."
  116. {
  117. D3DSURFACE_DESC m_descZero; // desc of top level.
  118. CGLMTex *m_tex; // a CGLMTex can represent all forms of tex
  119. virtual ~IDirect3DBaseTexture9();
  120. D3DRESOURCETYPE TOGLMETHODCALLTYPE GetType();
  121. DWORD TOGLMETHODCALLTYPE GetLevelCount();
  122. HRESULT TOGLMETHODCALLTYPE GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc);
  123. };
  124. struct TOGL_CLASS IDirect3DTexture9 : public IDirect3DBaseTexture9 // "Texture 2D"
  125. {
  126. IDirect3DSurface9 *m_surfZero; // surf of top level.
  127. virtual ~IDirect3DTexture9();
  128. HRESULT TOGLMETHODCALLTYPE LockRect(UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags);
  129. HRESULT TOGLMETHODCALLTYPE UnlockRect(UINT Level);
  130. HRESULT TOGLMETHODCALLTYPE GetSurfaceLevel(UINT Level,IDirect3DSurface9** ppSurfaceLevel);
  131. };
  132. struct TOGL_CLASS IDirect3DCubeTexture9 : public IDirect3DBaseTexture9 // "Texture Cube Map"
  133. {
  134. IDirect3DSurface9 *m_surfZero[6]; // surfs of top level.
  135. virtual ~IDirect3DCubeTexture9();
  136. HRESULT TOGLMETHODCALLTYPE GetCubeMapSurface(D3DCUBEMAP_FACES FaceType,UINT Level,IDirect3DSurface9** ppCubeMapSurface);
  137. HRESULT TOGLMETHODCALLTYPE GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc);
  138. };
  139. struct TOGL_CLASS IDirect3DVolumeTexture9 : public IDirect3DBaseTexture9 // "Texture 3D"
  140. {
  141. IDirect3DSurface9 *m_surfZero; // surf of top level.
  142. D3DVOLUME_DESC m_volDescZero; // volume desc top level
  143. virtual ~IDirect3DVolumeTexture9();
  144. HRESULT TOGLMETHODCALLTYPE LockBox(UINT Level,D3DLOCKED_BOX* pLockedVolume,CONST D3DBOX* pBox,DWORD Flags);
  145. HRESULT TOGLMETHODCALLTYPE UnlockBox(UINT Level);
  146. HRESULT TOGLMETHODCALLTYPE GetLevelDesc( UINT level, D3DVOLUME_DESC *pDesc );
  147. };
  148. // for the moment, a "D3D surface" is modeled as a GLM tex, a face, and a mip.
  149. // no Create method, these are filled in by the various create surface methods.
  150. struct TOGL_CLASS IDirect3DSurface9 : public IDirect3DResource9
  151. {
  152. virtual ~IDirect3DSurface9();
  153. HRESULT TOGLMETHODCALLTYPE LockRect(D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags);
  154. HRESULT TOGLMETHODCALLTYPE UnlockRect();
  155. HRESULT TOGLMETHODCALLTYPE GetDesc(D3DSURFACE_DESC *pDesc);
  156. D3DSURFACE_DESC m_desc;
  157. CGLMTex *m_tex;
  158. int m_face;
  159. int m_mip;
  160. };
  161. struct TOGL_CLASS IDirect3D9 : public IUnknown
  162. {
  163. virtual ~IDirect3D9();
  164. UINT TOGLMETHODCALLTYPE GetAdapterCount();
  165. HRESULT TOGLMETHODCALLTYPE GetDeviceCaps (UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps);
  166. HRESULT TOGLMETHODCALLTYPE GetAdapterIdentifier (UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier);
  167. HRESULT TOGLMETHODCALLTYPE CheckDeviceFormat (UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat);
  168. UINT TOGLMETHODCALLTYPE GetAdapterModeCount (UINT Adapter,D3DFORMAT Format);
  169. HRESULT TOGLMETHODCALLTYPE EnumAdapterModes (UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode);
  170. HRESULT TOGLMETHODCALLTYPE CheckDeviceType (UINT Adapter,D3DDEVTYPE DevType,D3DFORMAT AdapterFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed);
  171. HRESULT TOGLMETHODCALLTYPE GetAdapterDisplayMode (UINT Adapter,D3DDISPLAYMODE* pMode);
  172. HRESULT TOGLMETHODCALLTYPE CheckDepthStencilMatch (UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat);
  173. HRESULT TOGLMETHODCALLTYPE CheckDeviceMultiSampleType (UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels);
  174. HRESULT TOGLMETHODCALLTYPE CreateDevice (UINT Adapter,D3DDEVTYPE DeviceType,VD3DHWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface);
  175. };
  176. struct TOGL_CLASS IDirect3DVertexDeclaration9 : public IUnknown
  177. {
  178. IDirect3DDevice9 *m_device;
  179. uint m_elemCount;
  180. D3DVERTEXELEMENT9_GL m_elements[ MAX_D3DVERTEXELEMENTS ];
  181. uint8 m_VertexAttribDescToStreamIndex[256];
  182. virtual ~IDirect3DVertexDeclaration9();
  183. };
  184. struct TOGL_CLASS IDirect3DQuery9 : public IDirect3DResource9 //was IUnknown
  185. {
  186. D3DQUERYTYPE m_type; // D3DQUERYTYPE_OCCLUSION or D3DQUERYTYPE_EVENT
  187. GLMContext *m_ctx;
  188. CGLMQuery *m_query;
  189. uint m_nIssueStartThreadID, m_nIssueEndThreadID;
  190. uint m_nIssueStartDrawCallIndex, m_nIssueEndDrawCallIndex;
  191. uint m_nIssueStartFrameIndex, m_nIssueEndFrameIndex;
  192. uint m_nIssueStartQueryCreationCounter, m_nIssueEndQueryCreationCounter;
  193. virtual ~IDirect3DQuery9();
  194. HRESULT Issue(DWORD dwIssueFlags);
  195. HRESULT GetData(void* pData,DWORD dwSize,DWORD dwGetDataFlags);
  196. };
  197. struct TOGL_CLASS IDirect3DVertexBuffer9 : public IDirect3DResource9 //was IUnknown
  198. {
  199. GLMContext *m_ctx;
  200. CGLMBuffer *m_vtxBuffer;
  201. D3DVERTEXBUFFER_DESC m_vtxDesc; // to satisfy GetDesc
  202. virtual ~IDirect3DVertexBuffer9();
  203. HRESULT Lock(UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags);
  204. HRESULT Unlock();
  205. void UnlockActualSize( uint nActualSize, const void *pActualData = NULL );
  206. };
  207. struct TOGL_CLASS IDirect3DIndexBuffer9 : public IDirect3DResource9 //was IUnknown
  208. {
  209. GLMContext *m_ctx;
  210. CGLMBuffer *m_idxBuffer;
  211. D3DINDEXBUFFER_DESC m_idxDesc; // to satisfy GetDesc
  212. virtual ~IDirect3DIndexBuffer9();
  213. HRESULT Lock(UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags);
  214. HRESULT Unlock();
  215. void UnlockActualSize( uint nActualSize, const void *pActualData = NULL );
  216. HRESULT GetDesc(D3DINDEXBUFFER_DESC *pDesc);
  217. };
  218. struct TOGL_CLASS IDirect3DPixelShader9 : public IDirect3DResource9 //was IUnknown
  219. {
  220. CGLMProgram *m_pixProgram;
  221. uint m_pixHighWater; // count of active constant slots referenced by shader.
  222. uint m_pixSamplerMask; // (1<<n) mask of samplers referemnced by this pixel shader
  223. // this can help FlushSamplers avoid SRGB flipping on textures not being referenced...
  224. uint m_pixSamplerTypes; // SAMPLER_TYPE_2D, etc.
  225. uint m_pixFragDataMask; // (1<<n) mask of gl_FragData[n] referenced by this pixel shader
  226. virtual ~IDirect3DPixelShader9();
  227. };
  228. struct TOGL_CLASS IDirect3DVertexShader9 : public IDirect3DResource9 //was IUnknown
  229. {
  230. CGLMProgram *m_vtxProgram;
  231. uint m_vtxHighWater; // count of active constant slots referenced by shader.
  232. uint m_vtxHighWaterBone;
  233. unsigned char m_vtxAttribMap[16]; // high nibble is usage, low nibble is usageindex, array position is attrib number
  234. uint m_maxVertexAttrs;
  235. virtual ~IDirect3DVertexShader9();
  236. };
  237. #ifdef _MSC_VER
  238. typedef class TOGL_CLASS CUtlMemory<D3DMATRIX> CD3DMATRIXAllocator;
  239. typedef class TOGL_CLASS CUtlVector<D3DMATRIX, CD3DMATRIXAllocator> CD3DMATRIXStack;
  240. #else
  241. typedef class CUtlMemory<D3DMATRIX> CD3DMATRIXAllocator;
  242. typedef class CUtlVector<D3DMATRIX, CD3DMATRIXAllocator> CD3DMATRIXStack;
  243. #endif
  244. struct TOGL_CLASS ID3DXMatrixStack //: public IUnknown
  245. {
  246. int m_refcount[2];
  247. bool m_mark;
  248. CD3DMATRIXStack m_stack;
  249. int m_stackTop; // top of stack is at the highest index, this is that index. push increases, pop decreases.
  250. ID3DXMatrixStack();
  251. void AddRef( int which=0, char *comment = NULL );
  252. ULONG Release( int which=0, char *comment = NULL );
  253. HRESULT Create( void );
  254. D3DXMATRIX* GetTop();
  255. void Push();
  256. void Pop();
  257. void LoadIdentity();
  258. void LoadMatrix( const D3DXMATRIX *pMat );
  259. void MultMatrix( const D3DXMATRIX *pMat );
  260. void MultMatrixLocal( const D3DXMATRIX *pMat );
  261. HRESULT ScaleLocal(FLOAT x, FLOAT y, FLOAT z);
  262. // Left multiply the current matrix with the computed rotation
  263. // matrix, counterclockwise about the given axis with the given angle.
  264. // (rotation is about the local origin of the object)
  265. HRESULT RotateAxisLocal(CONST D3DXVECTOR3* pV, FLOAT Angle);
  266. // Left multiply the current matrix with the computed translation
  267. // matrix. (transformation is about the local origin of the object)
  268. HRESULT TranslateLocal(FLOAT x, FLOAT y, FLOAT z);
  269. };
  270. typedef ID3DXMatrixStack* LPD3DXMATRIXSTACK;
  271. struct RenderTargetState_t
  272. {
  273. void clear() { V_memset( this, 0, sizeof( *this ) ); }
  274. CGLMTex *m_pRenderTargets[4];
  275. CGLMTex *m_pDepthStencil;
  276. inline bool RefersTo( CGLMTex * pSurf ) const
  277. {
  278. for ( uint i = 0; i < 4; i++ )
  279. if ( m_pRenderTargets[i] == pSurf )
  280. return true;
  281. if ( m_pDepthStencil == pSurf )
  282. return true;
  283. return false;
  284. }
  285. static inline bool LessFunc( const RenderTargetState_t &lhs, const RenderTargetState_t &rhs )
  286. {
  287. uint64 lhs0 = reinterpret_cast<const uint64 *>(lhs.m_pRenderTargets)[0];
  288. uint64 rhs0 = reinterpret_cast<const uint64 *>(rhs.m_pRenderTargets)[0];
  289. if ( lhs0 < rhs0 )
  290. return true;
  291. else if ( lhs0 == rhs0 )
  292. {
  293. uint64 lhs1 = reinterpret_cast<const uint64 *>(lhs.m_pRenderTargets)[1];
  294. uint64 rhs1 = reinterpret_cast<const uint64 *>(rhs.m_pRenderTargets)[1];
  295. if ( lhs1 < rhs1 )
  296. return true;
  297. else if ( lhs1 == rhs1 )
  298. {
  299. return lhs.m_pDepthStencil < rhs.m_pDepthStencil;
  300. }
  301. }
  302. return false;
  303. }
  304. inline bool operator < ( const RenderTargetState_t &rhs ) const
  305. {
  306. return LessFunc( *this, rhs );
  307. }
  308. };
  309. typedef CUtlMap< RenderTargetState_t, CGLMFBO *> CGLMFBOMap;
  310. class simple_bitmap;
  311. struct TOGL_CLASS IDirect3DDevice9 : public IUnknown
  312. {
  313. friend class GLMContext;
  314. friend struct IDirect3DBaseTexture9;
  315. friend struct IDirect3DTexture9;
  316. friend struct IDirect3DCubeTexture9;
  317. friend struct IDirect3DVolumeTexture9;
  318. friend struct IDirect3DSurface9;
  319. friend struct IDirect3DVertexBuffer9;
  320. friend struct IDirect3DIndexBuffer9;
  321. friend struct IDirect3DPixelShader9;
  322. friend struct IDirect3DVertexShader9;
  323. friend struct IDirect3DQuery9;
  324. friend struct IDirect3DVertexDeclaration9;
  325. IDirect3DDevice9();
  326. virtual ~IDirect3DDevice9();
  327. // Create call invoked from IDirect3D9
  328. HRESULT TOGLMETHODCALLTYPE Create( IDirect3DDevice9Params *params );
  329. //
  330. // Basics
  331. //
  332. HRESULT TOGLMETHODCALLTYPE Reset(D3DPRESENT_PARAMETERS* pPresentationParameters);
  333. HRESULT TOGLMETHODCALLTYPE SetViewport(CONST D3DVIEWPORT9* pViewport);
  334. HRESULT TOGLMETHODCALLTYPE GetViewport(D3DVIEWPORT9* pViewport);
  335. HRESULT TOGLMETHODCALLTYPE BeginScene();
  336. HRESULT TOGLMETHODCALLTYPE Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil);
  337. HRESULT TOGLMETHODCALLTYPE EndScene();
  338. HRESULT TOGLMETHODCALLTYPE Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,VD3DHWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
  339. // textures
  340. HRESULT TOGLMETHODCALLTYPE CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,VD3DHANDLE* pSharedHandle, char *debugLabel=NULL);
  341. HRESULT TOGLMETHODCALLTYPE CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,VD3DHANDLE* pSharedHandle, char *debugLabel=NULL);
  342. HRESULT TOGLMETHODCALLTYPE CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,VD3DHANDLE* pSharedHandle, char *debugLabel=NULL);
  343. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetTexture(DWORD Stage,IDirect3DBaseTexture9* pTexture);
  344. HRESULT TOGLMETHODCALLTYPE SetTextureNonInline(DWORD Stage,IDirect3DBaseTexture9* pTexture);
  345. HRESULT TOGLMETHODCALLTYPE GetTexture(DWORD Stage,IDirect3DBaseTexture9** ppTexture);
  346. // render targets, color and depthstencil, surfaces, blit
  347. HRESULT TOGLMETHODCALLTYPE CreateRenderTarget(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Lockable,IDirect3DSurface9** ppSurface,VD3DHANDLE* pSharedHandle, char *debugLabel=NULL);
  348. HRESULT TOGLMETHODCALLTYPE SetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget);
  349. HRESULT TOGLMETHODCALLTYPE GetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9** ppRenderTarget);
  350. HRESULT TOGLMETHODCALLTYPE CreateOffscreenPlainSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DPOOL Pool,IDirect3DSurface9** ppSurface,VD3DHANDLE* pSharedHandle);
  351. HRESULT TOGLMETHODCALLTYPE CreateDepthStencilSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Discard,IDirect3DSurface9** ppSurface,VD3DHANDLE* pSharedHandle);
  352. HRESULT TOGLMETHODCALLTYPE SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil);
  353. HRESULT TOGLMETHODCALLTYPE GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface);
  354. HRESULT TOGLMETHODCALLTYPE GetRenderTargetData(IDirect3DSurface9* pRenderTarget,IDirect3DSurface9* pDestSurface); // ? is anyone using this ?
  355. HRESULT TOGLMETHODCALLTYPE GetFrontBufferData(UINT iSwapChain,IDirect3DSurface9* pDestSurface);
  356. HRESULT TOGLMETHODCALLTYPE StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect,D3DTEXTUREFILTERTYPE Filter);
  357. // pixel shaders
  358. HRESULT TOGLMETHODCALLTYPE CreatePixelShader(CONST DWORD* pFunction,IDirect3DPixelShader9** ppShader, const char *pShaderName, char *debugLabel = NULL, const uint32 *pCentroidMask = NULL );
  359. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetPixelShader(IDirect3DPixelShader9* pShader);
  360. HRESULT TOGLMETHODCALLTYPE SetPixelShaderNonInline(IDirect3DPixelShader9* pShader);
  361. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
  362. HRESULT TOGLMETHODCALLTYPE SetPixelShaderConstantFNonInline(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
  363. HRESULT TOGLMETHODCALLTYPE SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
  364. HRESULT TOGLMETHODCALLTYPE SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
  365. // vertex shaders
  366. HRESULT TOGLMETHODCALLTYPE CreateVertexShader(CONST DWORD* pFunction,IDirect3DVertexShader9** ppShader, const char *pShaderName, char *debugLabel = NULL);
  367. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetVertexShader(IDirect3DVertexShader9* pShader);
  368. HRESULT TOGLMETHODCALLTYPE SetVertexShaderNonInline(IDirect3DVertexShader9* pShader);
  369. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
  370. HRESULT TOGLMETHODCALLTYPE SetVertexShaderConstantFNonInline(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
  371. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
  372. HRESULT TOGLMETHODCALLTYPE SetVertexShaderConstantBNonInline(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
  373. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
  374. HRESULT TOGLMETHODCALLTYPE SetVertexShaderConstantINonInline(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
  375. // POSIX only - preheating for a specific vertex/pixel shader pair - trigger GLSL link inside GLM
  376. HRESULT TOGLMETHODCALLTYPE LinkShaderPair( IDirect3DVertexShader9* vs, IDirect3DPixelShader9* ps );
  377. HRESULT TOGLMETHODCALLTYPE ValidateShaderPair( IDirect3DVertexShader9* vs, IDirect3DPixelShader9* ps );
  378. HRESULT TOGLMETHODCALLTYPE QueryShaderPair( int index, GLMShaderPairInfo *infoOut );
  379. // vertex buffers
  380. HRESULT TOGLMETHODCALLTYPE CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements,IDirect3DVertexDeclaration9** ppDecl);
  381. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl);
  382. HRESULT TOGLMETHODCALLTYPE SetVertexDeclarationNonInline(IDirect3DVertexDeclaration9* pDecl);
  383. HRESULT TOGLMETHODCALLTYPE SetFVF(DWORD FVF); // we might not be using these ?
  384. HRESULT TOGLMETHODCALLTYPE GetFVF(DWORD* pFVF);
  385. HRESULT CreateVertexBuffer(UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer9** ppVertexBuffer,VD3DHANDLE* pSharedHandle);
  386. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride);
  387. HRESULT SetStreamSourceNonInline(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride);
  388. // index buffers
  389. HRESULT TOGLMETHODCALLTYPE CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer9** ppIndexBuffer,VD3DHANDLE* pSharedHandle);
  390. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetIndices(IDirect3DIndexBuffer9* pIndexData);
  391. HRESULT TOGLMETHODCALLTYPE SetIndicesNonInline(IDirect3DIndexBuffer9* pIndexData);
  392. // State management.
  393. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetRenderStateInline(D3DRENDERSTATETYPE State,DWORD Value);
  394. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetRenderStateConstInline(D3DRENDERSTATETYPE State,DWORD Value);
  395. HRESULT TOGLMETHODCALLTYPE SetRenderState(D3DRENDERSTATETYPE State,DWORD Value);
  396. FORCEINLINE HRESULT TOGLMETHODCALLTYPE SetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value);
  397. HRESULT TOGLMETHODCALLTYPE SetSamplerStateNonInline(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value);
  398. FORCEINLINE void TOGLMETHODCALLTYPE SetSamplerStates(DWORD Sampler, DWORD AddressU, DWORD AddressV, DWORD AddressW, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter );
  399. void TOGLMETHODCALLTYPE SetSamplerStatesNonInline(DWORD Sampler, DWORD AddressU, DWORD AddressV, DWORD AddressW, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter );
  400. #ifdef OSX
  401. // required for 10.6 support
  402. HRESULT TOGLMETHODCALLTYPE FlushIndexBindings(void); // push index buffer (set index ptr)
  403. HRESULT TOGLMETHODCALLTYPE FlushVertexBindings(uint baseVertexIndex); // push vertex streams (set attrib ptrs)
  404. #endif
  405. // Draw.
  406. HRESULT TOGLMETHODCALLTYPE DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount);
  407. HRESULT TOGLMETHODCALLTYPE DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
  408. HRESULT TOGLMETHODCALLTYPE DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
  409. // misc
  410. BOOL TOGLMETHODCALLTYPE ShowCursor(BOOL bShow);
  411. HRESULT TOGLMETHODCALLTYPE ValidateDevice(DWORD* pNumPasses);
  412. HRESULT TOGLMETHODCALLTYPE SetMaterial(CONST D3DMATERIAL9* pMaterial);
  413. HRESULT TOGLMETHODCALLTYPE LightEnable(DWORD Index,BOOL Enable);
  414. HRESULT TOGLMETHODCALLTYPE SetScissorRect(CONST RECT* pRect);
  415. HRESULT TOGLMETHODCALLTYPE CreateQuery(D3DQUERYTYPE Type,IDirect3DQuery9** ppQuery);
  416. HRESULT TOGLMETHODCALLTYPE GetDeviceCaps(D3DCAPS9* pCaps);
  417. HRESULT TOGLMETHODCALLTYPE TestCooperativeLevel();
  418. HRESULT TOGLMETHODCALLTYPE EvictManagedResources();
  419. HRESULT TOGLMETHODCALLTYPE SetLight(DWORD Index,CONST D3DLIGHT9*);
  420. void TOGLMETHODCALLTYPE SetGammaRamp(UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp);
  421. void TOGLMETHODCALLTYPE SaveGLState();
  422. void TOGLMETHODCALLTYPE RestoreGLState();
  423. // Talk to JasonM about this one. It's tricky in GL.
  424. HRESULT TOGLMETHODCALLTYPE SetClipPlane(DWORD Index,CONST float* pPlane);
  425. //
  426. //
  427. // **** FIXED FUNCTION STUFF - None of this stuff needs support in GL.
  428. //
  429. //
  430. HRESULT TOGLMETHODCALLTYPE SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix);
  431. HRESULT TOGLMETHODCALLTYPE SetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value);
  432. void TOGLMETHODCALLTYPE AcquireThreadOwnership( );
  433. void TOGLMETHODCALLTYPE ReleaseThreadOwnership( );
  434. inline ThreadId_t TOGLMETHODCALLTYPE GetCurrentOwnerThreadId() const { return m_ctx->m_nCurOwnerThreadId; }
  435. FORCEINLINE void TOGLMETHODCALLTYPE SetMaxUsedVertexShaderConstantsHint( uint nMaxReg );
  436. void TOGLMETHODCALLTYPE SetMaxUsedVertexShaderConstantsHintNonInline( uint nMaxReg );
  437. void DumpStatsToConsole( const CCommand *pArgs );
  438. #if GLMDEBUG
  439. void DumpTextures( const CCommand *pArgs );
  440. #endif
  441. private:
  442. IDirect3DDevice9( const IDirect3DDevice9& );
  443. IDirect3DDevice9& operator= ( const IDirect3DDevice9& );
  444. // Flushing changes to GL
  445. void FlushClipPlaneEquation();
  446. void InitStates();
  447. void FullFlushStates();
  448. void UpdateBoundFBO();
  449. void ResetFBOMap();
  450. void ScrubFBOMap( CGLMTex *pTex );
  451. // response to retired objects (when refcount goes to zero and they self-delete..)
  452. void ReleasedVertexDeclaration( IDirect3DVertexDeclaration9 *pDecl );
  453. void ReleasedTexture( IDirect3DBaseTexture9 *baseTex ); // called from texture destructor - need to scrub samplers
  454. void ReleasedCGLMTex( CGLMTex *pTex );
  455. void ReleasedSurface( IDirect3DSurface9 *surface ); // called from any surface destructor - need to scrub RT table if an RT
  456. void ReleasedPixelShader( IDirect3DPixelShader9 *pixelShader ); // called from IDirect3DPixelShader9 destructor
  457. void ReleasedVertexShader( IDirect3DVertexShader9 *vertexShader ); // called from IDirect3DVertexShader9 destructor
  458. void ReleasedVertexBuffer( IDirect3DVertexBuffer9 *vertexBuffer ); // called from IDirect3DVertexBuffer9 destructor
  459. void ReleasedIndexBuffer( IDirect3DIndexBuffer9 *indexBuffer ); // called from IDirect3DIndexBuffer9 destructor
  460. void ReleasedQuery( IDirect3DQuery9 *query ); // called from IDirect3DQuery9 destructor
  461. // Member variables
  462. DWORD m_nValidMarker;
  463. public:
  464. IDirect3DDevice9Params m_params; // mirror of the creation inputs
  465. private:
  466. // D3D flavor stuff
  467. IDirect3DSurface9 *m_pRenderTargets[4];
  468. IDirect3DSurface9 *m_pDepthStencil;
  469. IDirect3DSurface9 *m_pDefaultColorSurface; // default color surface.
  470. IDirect3DSurface9 *m_pDefaultDepthStencilSurface; // queried by GetDepthStencilSurface.
  471. IDirect3DVertexDeclaration9 *m_pVertDecl; // Set by SetVertexDeclaration...
  472. D3DStreamDesc m_streams[ D3D_MAX_STREAMS ]; // Set by SetStreamSource..
  473. CGLMBuffer *m_vtx_buffers[ D3D_MAX_STREAMS ];
  474. CGLMBuffer *m_pDummy_vtx_buffer;
  475. D3DIndexDesc m_indices; // Set by SetIndices..
  476. IDirect3DVertexShader9 *m_vertexShader; // Set by SetVertexShader...
  477. IDirect3DPixelShader9 *m_pixelShader; // Set by SetPixelShader...
  478. IDirect3DBaseTexture9 *m_textures[GLM_SAMPLER_COUNT]; // set by SetTexture... NULL if stage inactive
  479. // GLM flavor stuff
  480. GLMContext *m_ctx;
  481. CGLMFBOMap *m_pFBOs;
  482. bool m_bFBODirty;
  483. struct ObjectStats_t
  484. {
  485. int m_nTotalFBOs;
  486. int m_nTotalVertexShaders;
  487. int m_nTotalPixelShaders;
  488. int m_nTotalVertexDecls;
  489. int m_nTotalIndexBuffers;
  490. int m_nTotalVertexBuffers;
  491. int m_nTotalRenderTargets;
  492. int m_nTotalTextures;
  493. int m_nTotalSurfaces;
  494. int m_nTotalQueries;
  495. void clear() { V_memset( this, 0, sizeof(* this ) ); }
  496. ObjectStats_t &operator -= ( const ObjectStats_t &rhs )
  497. {
  498. m_nTotalFBOs -= rhs.m_nTotalFBOs;
  499. m_nTotalVertexShaders -= rhs.m_nTotalVertexShaders;
  500. m_nTotalPixelShaders -= rhs.m_nTotalPixelShaders;
  501. m_nTotalVertexDecls -= rhs.m_nTotalVertexDecls;
  502. m_nTotalIndexBuffers -= rhs.m_nTotalIndexBuffers;
  503. m_nTotalVertexBuffers -= rhs.m_nTotalVertexBuffers;
  504. m_nTotalRenderTargets -= rhs.m_nTotalRenderTargets;
  505. m_nTotalTextures -= rhs.m_nTotalTextures;
  506. m_nTotalSurfaces -= rhs.m_nTotalSurfaces;
  507. m_nTotalQueries -= m_nTotalQueries;
  508. return *this;
  509. }
  510. };
  511. ObjectStats_t m_ObjectStats;
  512. ObjectStats_t m_PrevObjectStats;
  513. void PrintObjectStats( const ObjectStats_t &stats );
  514. // GL state
  515. struct
  516. {
  517. // render state buckets
  518. GLAlphaTestEnable_t m_AlphaTestEnable;
  519. GLAlphaTestFunc_t m_AlphaTestFunc;
  520. GLAlphaToCoverageEnable_t m_AlphaToCoverageEnable;
  521. GLDepthTestEnable_t m_DepthTestEnable;
  522. GLDepthMask_t m_DepthMask;
  523. GLDepthFunc_t m_DepthFunc;
  524. GLClipPlaneEnable_t m_ClipPlaneEnable[kGLMUserClipPlanes];
  525. GLClipPlaneEquation_t m_ClipPlaneEquation[kGLMUserClipPlanes];
  526. GLColorMaskSingle_t m_ColorMaskSingle;
  527. GLColorMaskMultiple_t m_ColorMaskMultiple;
  528. GLCullFaceEnable_t m_CullFaceEnable;
  529. GLCullFrontFace_t m_CullFrontFace;
  530. GLPolygonMode_t m_PolygonMode;
  531. GLDepthBias_t m_DepthBias;
  532. GLScissorEnable_t m_ScissorEnable;
  533. GLScissorBox_t m_ScissorBox;
  534. GLViewportBox_t m_ViewportBox;
  535. GLViewportDepthRange_t m_ViewportDepthRange;
  536. GLBlendEnable_t m_BlendEnable;
  537. GLBlendFactor_t m_BlendFactor;
  538. GLBlendEquation_t m_BlendEquation;
  539. GLBlendColor_t m_BlendColor;
  540. GLBlendEnableSRGB_t m_BlendEnableSRGB;
  541. GLStencilTestEnable_t m_StencilTestEnable;
  542. GLStencilFunc_t m_StencilFunc;
  543. GLStencilOp_t m_StencilOp;
  544. GLStencilWriteMask_t m_StencilWriteMask;
  545. GLClearColor_t m_ClearColor;
  546. GLClearDepth_t m_ClearDepth;
  547. GLClearStencil_t m_ClearStencil;
  548. bool m_FogEnable; // not really pushed to GL, just latched here
  549. // samplers
  550. //GLMTexSamplingParams m_samplers[GLM_SAMPLER_COUNT];
  551. } gl;
  552. #if GL_BATCH_PERF_ANALYSIS
  553. simple_bitmap *m_pBatch_vis_bitmap;
  554. uint m_nBatchVisY;
  555. uint m_nBatchVisFrameIndex, m_nBatchVisFileIdx;
  556. uint m_nNumProgramChanges;
  557. uint m_nTotalD3DCalls;
  558. double m_flTotalD3DTime;
  559. uint m_nTotalGLCalls;
  560. double m_flTotalGLTime;
  561. uint m_nTotalPrims;
  562. uint m_nOverallProgramChanges;
  563. uint m_nOverallDraws;
  564. uint m_nOverallPrims;
  565. uint m_nOverallD3DCalls;
  566. double m_flOverallD3DTime;
  567. uint m_nOverallGLCalls;
  568. double m_flOverallGLTime;
  569. double m_flOverallPresentTime;
  570. double m_flOverallPresentTimeSquared;
  571. double m_flOverallSwapWindowTime;
  572. double m_flOverallSwapWindowTimeSquared;
  573. uint m_nOverallPresents;
  574. #endif
  575. };
  576. FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetSamplerState( DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value )
  577. {
  578. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  579. return SetSamplerStateNonInline( Sampler, Type, Value );
  580. #else
  581. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  582. Assert( Sampler < GLM_SAMPLER_COUNT );
  583. m_ctx->SetSamplerDirty( Sampler );
  584. switch( Type )
  585. {
  586. case D3DSAMP_ADDRESSU:
  587. m_ctx->SetSamplerAddressU( Sampler, Value );
  588. break;
  589. case D3DSAMP_ADDRESSV:
  590. m_ctx->SetSamplerAddressV( Sampler, Value );
  591. break;
  592. case D3DSAMP_ADDRESSW:
  593. m_ctx->SetSamplerAddressW( Sampler, Value );
  594. break;
  595. case D3DSAMP_BORDERCOLOR:
  596. m_ctx->SetSamplerBorderColor( Sampler, Value );
  597. break;
  598. case D3DSAMP_MAGFILTER:
  599. m_ctx->SetSamplerMagFilter( Sampler, Value );
  600. break;
  601. case D3DSAMP_MIPFILTER:
  602. m_ctx->SetSamplerMipFilter( Sampler, Value );
  603. break;
  604. case D3DSAMP_MINFILTER:
  605. m_ctx->SetSamplerMinFilter( Sampler, Value );
  606. break;
  607. case D3DSAMP_MIPMAPLODBIAS:
  608. m_ctx->SetSamplerMipMapLODBias( Sampler, Value );
  609. break;
  610. case D3DSAMP_MAXMIPLEVEL:
  611. m_ctx->SetSamplerMaxMipLevel( Sampler, Value);
  612. break;
  613. case D3DSAMP_MAXANISOTROPY:
  614. m_ctx->SetSamplerMaxAnisotropy( Sampler, Value);
  615. break;
  616. case D3DSAMP_SRGBTEXTURE:
  617. //m_samplers[ Sampler ].m_srgb = Value;
  618. m_ctx->SetSamplerSRGBTexture(Sampler, Value);
  619. break;
  620. case D3DSAMP_SHADOWFILTER:
  621. m_ctx->SetShadowFilter(Sampler, Value);
  622. break;
  623. default: DXABSTRACT_BREAK_ON_ERROR(); break;
  624. }
  625. return S_OK;
  626. #endif
  627. }
  628. FORCEINLINE void TOGLMETHODCALLTYPE IDirect3DDevice9::SetSamplerStates(
  629. DWORD Sampler, DWORD AddressU, DWORD AddressV, DWORD AddressW,
  630. DWORD MinFilter, DWORD MagFilter, DWORD MipFilter )
  631. {
  632. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  633. SetSamplerStatesNonInline( Sampler, AddressU, AddressV, AddressW, MinFilter, MagFilter, MipFilter );
  634. #else
  635. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  636. Assert( Sampler < GLM_SAMPLER_COUNT);
  637. m_ctx->SetSamplerDirty( Sampler );
  638. m_ctx->SetSamplerStates( Sampler, AddressU, AddressV, AddressW, MinFilter, MagFilter, MipFilter );
  639. #endif
  640. }
  641. FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetTexture(DWORD Stage,IDirect3DBaseTexture9* pTexture)
  642. {
  643. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  644. return SetTextureNonInline( Stage, pTexture );
  645. #else
  646. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  647. Assert( Stage < GLM_SAMPLER_COUNT );
  648. m_textures[Stage] = pTexture;
  649. m_ctx->SetSamplerTex( Stage, pTexture ? pTexture->m_tex : NULL );
  650. return S_OK;
  651. #endif
  652. }
  653. inline GLenum D3DCompareFuncToGL( DWORD function )
  654. {
  655. switch ( function )
  656. {
  657. case D3DCMP_NEVER : return GL_NEVER; // Always fail the test.
  658. case D3DCMP_LESS : return GL_LESS; // Accept the new pixel if its value is less than the value of the current pixel.
  659. case D3DCMP_EQUAL : return GL_EQUAL; // Accept the new pixel if its value equals the value of the current pixel.
  660. case D3DCMP_LESSEQUAL : return GL_LEQUAL; // Accept the new pixel if its value is less than or equal to the value of the current pixel. **
  661. case D3DCMP_GREATER : return GL_GREATER; // Accept the new pixel if its value is greater than the value of the current pixel.
  662. case D3DCMP_NOTEQUAL : return GL_NOTEQUAL; // Accept the new pixel if its value does not equal the value of the current pixel.
  663. case D3DCMP_GREATEREQUAL: return GL_GEQUAL; // Accept the new pixel if its value is greater than or equal to the value of the current pixel.
  664. case D3DCMP_ALWAYS : return GL_ALWAYS; // Always pass the test.
  665. default : DXABSTRACT_BREAK_ON_ERROR(); return 0xFFFFFFFF;
  666. }
  667. }
  668. FORCEINLINE GLenum D3DBlendOperationToGL( DWORD operation )
  669. {
  670. switch (operation)
  671. {
  672. case D3DBLENDOP_ADD : return GL_FUNC_ADD; // The result is the destination added to the source. Result = Source + Destination
  673. case D3DBLENDOP_SUBTRACT : return GL_FUNC_SUBTRACT; // The result is the destination subtracted from to the source. Result = Source - Destination
  674. case D3DBLENDOP_REVSUBTRACT : return GL_FUNC_REVERSE_SUBTRACT; // The result is the source subtracted from the destination. Result = Destination - Source
  675. case D3DBLENDOP_MIN : return GL_MIN; // The result is the minimum of the source and destination. Result = MIN(Source, Destination)
  676. case D3DBLENDOP_MAX : return GL_MAX; // The result is the maximum of the source and destination. Result = MAX(Source, Destination)
  677. default:
  678. DXABSTRACT_BREAK_ON_ERROR();
  679. return 0xFFFFFFFF;
  680. break;
  681. }
  682. }
  683. FORCEINLINE GLenum D3DBlendFactorToGL( DWORD equation )
  684. {
  685. switch (equation)
  686. {
  687. case D3DBLEND_ZERO : return GL_ZERO; // Blend factor is (0, 0, 0, 0).
  688. case D3DBLEND_ONE : return GL_ONE; // Blend factor is (1, 1, 1, 1).
  689. case D3DBLEND_SRCCOLOR : return GL_SRC_COLOR; // Blend factor is (Rs, Gs, Bs, As).
  690. case D3DBLEND_INVSRCCOLOR : return GL_ONE_MINUS_SRC_COLOR; // Blend factor is (1 - Rs, 1 - Gs, 1 - Bs, 1 - As).
  691. case D3DBLEND_SRCALPHA : return GL_SRC_ALPHA; // Blend factor is (As, As, As, As).
  692. case D3DBLEND_INVSRCALPHA : return GL_ONE_MINUS_SRC_ALPHA; // Blend factor is ( 1 - As, 1 - As, 1 - As, 1 - As).
  693. case D3DBLEND_DESTALPHA : return GL_DST_ALPHA; // Blend factor is (Ad Ad Ad Ad).
  694. case D3DBLEND_INVDESTALPHA : return GL_ONE_MINUS_DST_ALPHA; // Blend factor is (1 - Ad 1 - Ad 1 - Ad 1 - Ad).
  695. case D3DBLEND_DESTCOLOR : return GL_DST_COLOR; // Blend factor is (Rd, Gd, Bd, Ad).
  696. case D3DBLEND_INVDESTCOLOR : return GL_ONE_MINUS_DST_COLOR; // Blend factor is (1 - Rd, 1 - Gd, 1 - Bd, 1 - Ad).
  697. case D3DBLEND_SRCALPHASAT : return GL_SRC_ALPHA_SATURATE; // Blend factor is (f, f, f, 1); where f = min(As, 1 - Ad).
  698. /*
  699. // these are weird.... break if we hit them
  700. case D3DBLEND_BOTHSRCALPHA : Assert(0); return GL_ZERO; // Obsolete. Starting with DirectX 6, you can achieve the same effect by setting the source and destination blend factors to D3DBLEND_SRCALPHA and D3DBLEND_INVSRCALPHA in separate calls.
  701. case D3DBLEND_BOTHINVSRCALPHA: Assert(0); return GL_ZERO; // Source blend factor is (1 - As, 1 - As, 1 - As, 1 - As), and destination blend factor is (As, As, As, As); the destination blend selection is overridden. This blend mode is supported only for the D3DRS_SRCBLEND render state.
  702. case D3DBLEND_BLENDFACTOR : Assert(0); return GL_ZERO; // Constant color blending factor used by the frame-buffer blender. This blend mode is supported only if D3DPBLENDCAPS_BLENDFACTOR is set in the SrcBlendCaps or DestBlendCaps members of D3DCAPS9.
  703. dxabstract.h has not heard of these, so let them hit the debugger if they come through
  704. case D3DBLEND_INVBLENDFACTOR: //Inverted constant color-blending factor used by the frame-buffer blender. This blend mode is supported only if the D3DPBLENDCAPS_BLENDFACTOR bit is set in the SrcBlendCaps or DestBlendCaps members of D3DCAPS9.
  705. case D3DBLEND_SRCCOLOR2: // Blend factor is (PSOutColor[1]r, PSOutColor[1]g, PSOutColor[1]b, not used). This flag is available in Direct3D 9Ex only.
  706. case D3DBLEND_INVSRCCOLOR2: // Blend factor is (1 - PSOutColor[1]r, 1 - PSOutColor[1]g, 1 - PSOutColor[1]b, not used)). This flag is available in Direct3D 9Ex only.
  707. */
  708. default:
  709. DXABSTRACT_BREAK_ON_ERROR();
  710. return 0xFFFFFFFF;
  711. break;
  712. }
  713. }
  714. FORCEINLINE GLenum D3DStencilOpToGL( DWORD operation )
  715. {
  716. switch( operation )
  717. {
  718. case D3DSTENCILOP_KEEP : return GL_KEEP;
  719. case D3DSTENCILOP_ZERO : return GL_ZERO;
  720. case D3DSTENCILOP_REPLACE : return GL_REPLACE;
  721. case D3DSTENCILOP_INCRSAT : return GL_INCR;
  722. case D3DSTENCILOP_DECRSAT : return GL_DECR;
  723. case D3DSTENCILOP_INVERT : return GL_INVERT;
  724. case D3DSTENCILOP_INCR : return GL_INCR_WRAP_EXT;
  725. case D3DSTENCILOP_DECR : return GL_DECR_WRAP_EXT;
  726. default : DXABSTRACT_BREAK_ON_ERROR(); return 0xFFFFFFFF;
  727. }
  728. }
  729. FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetRenderStateInline( D3DRENDERSTATETYPE State, DWORD Value )
  730. {
  731. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  732. return SetRenderState( State, Value );
  733. #else
  734. TOGL_NULL_DEVICE_CHECK;
  735. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  736. switch (State)
  737. {
  738. case D3DRS_ZENABLE: // kGLDepthTestEnable
  739. {
  740. gl.m_DepthTestEnable.enable = Value;
  741. m_ctx->WriteDepthTestEnable( &gl.m_DepthTestEnable );
  742. break;
  743. }
  744. case D3DRS_ZWRITEENABLE: // kGLDepthMask
  745. {
  746. gl.m_DepthMask.mask = Value;
  747. m_ctx->WriteDepthMask( &gl.m_DepthMask );
  748. break;
  749. }
  750. case D3DRS_ZFUNC:
  751. {
  752. // kGLDepthFunc
  753. GLenum func = D3DCompareFuncToGL( Value );
  754. gl.m_DepthFunc.func = func;
  755. m_ctx->WriteDepthFunc( &gl.m_DepthFunc );
  756. break;
  757. }
  758. case D3DRS_COLORWRITEENABLE: // kGLColorMaskSingle
  759. {
  760. gl.m_ColorMaskSingle.r = ((Value & D3DCOLORWRITEENABLE_RED) != 0) ? 0xFF : 0x00;
  761. gl.m_ColorMaskSingle.g = ((Value & D3DCOLORWRITEENABLE_GREEN)!= 0) ? 0xFF : 0x00;
  762. gl.m_ColorMaskSingle.b = ((Value & D3DCOLORWRITEENABLE_BLUE) != 0) ? 0xFF : 0x00;
  763. gl.m_ColorMaskSingle.a = ((Value & D3DCOLORWRITEENABLE_ALPHA)!= 0) ? 0xFF : 0x00;
  764. m_ctx->WriteColorMaskSingle( &gl.m_ColorMaskSingle );
  765. break;
  766. }
  767. case D3DRS_CULLMODE: // kGLCullFaceEnable / kGLCullFrontFace
  768. {
  769. switch (Value)
  770. {
  771. case D3DCULL_NONE:
  772. {
  773. gl.m_CullFaceEnable.enable = false;
  774. gl.m_CullFrontFace.value = GL_CCW; //doesn't matter
  775. m_ctx->WriteCullFaceEnable( &gl.m_CullFaceEnable );
  776. m_ctx->WriteCullFrontFace( &gl.m_CullFrontFace );
  777. break;
  778. }
  779. case D3DCULL_CW:
  780. {
  781. gl.m_CullFaceEnable.enable = true;
  782. gl.m_CullFrontFace.value = GL_CW; //origGL_CCW;
  783. m_ctx->WriteCullFaceEnable( &gl.m_CullFaceEnable );
  784. m_ctx->WriteCullFrontFace( &gl.m_CullFrontFace );
  785. break;
  786. }
  787. case D3DCULL_CCW:
  788. {
  789. gl.m_CullFaceEnable.enable = true;
  790. gl.m_CullFrontFace.value = GL_CCW; //origGL_CW;
  791. m_ctx->WriteCullFaceEnable( &gl.m_CullFaceEnable );
  792. m_ctx->WriteCullFrontFace( &gl.m_CullFrontFace );
  793. break;
  794. }
  795. default:
  796. {
  797. DXABSTRACT_BREAK_ON_ERROR();
  798. break;
  799. }
  800. }
  801. break;
  802. }
  803. //-------------------------------------------------------------------------------------------- alphablend stuff
  804. case D3DRS_ALPHABLENDENABLE: // kGLBlendEnable
  805. {
  806. gl.m_BlendEnable.enable = Value;
  807. m_ctx->WriteBlendEnable( &gl.m_BlendEnable );
  808. break;
  809. }
  810. case D3DRS_BLENDOP: // kGLBlendEquation // D3D blend-op ==> GL blend equation
  811. {
  812. GLenum equation = D3DBlendOperationToGL( Value );
  813. gl.m_BlendEquation.equation = equation;
  814. m_ctx->WriteBlendEquation( &gl.m_BlendEquation );
  815. break;
  816. }
  817. case D3DRS_SRCBLEND: // kGLBlendFactor // D3D blend-factor ==> GL blend factor
  818. case D3DRS_DESTBLEND: // kGLBlendFactor
  819. {
  820. GLenum factor = D3DBlendFactorToGL( Value );
  821. if (State==D3DRS_SRCBLEND)
  822. {
  823. gl.m_BlendFactor.srcfactor = factor;
  824. }
  825. else
  826. {
  827. gl.m_BlendFactor.dstfactor = factor;
  828. }
  829. m_ctx->WriteBlendFactor( &gl.m_BlendFactor );
  830. break;
  831. }
  832. case D3DRS_SRGBWRITEENABLE: // kGLBlendEnableSRGB
  833. {
  834. gl.m_BlendEnableSRGB.enable = Value;
  835. m_ctx->WriteBlendEnableSRGB( &gl.m_BlendEnableSRGB );
  836. break;
  837. }
  838. //-------------------------------------------------------------------------------------------- alphatest stuff
  839. case D3DRS_ALPHATESTENABLE:
  840. {
  841. gl.m_AlphaTestEnable.enable = Value;
  842. m_ctx->WriteAlphaTestEnable( &gl.m_AlphaTestEnable );
  843. break;
  844. }
  845. case D3DRS_ALPHAREF:
  846. {
  847. gl.m_AlphaTestFunc.ref = Value / 255.0f;
  848. m_ctx->WriteAlphaTestFunc( &gl.m_AlphaTestFunc );
  849. break;
  850. }
  851. case D3DRS_ALPHAFUNC:
  852. {
  853. GLenum func = D3DCompareFuncToGL( Value );;
  854. gl.m_AlphaTestFunc.func = func;
  855. m_ctx->WriteAlphaTestFunc( &gl.m_AlphaTestFunc );
  856. break;
  857. }
  858. //-------------------------------------------------------------------------------------------- stencil stuff
  859. case D3DRS_STENCILENABLE: // GLStencilTestEnable_t
  860. {
  861. gl.m_StencilTestEnable.enable = Value;
  862. m_ctx->WriteStencilTestEnable( &gl.m_StencilTestEnable );
  863. break;
  864. }
  865. case D3DRS_STENCILFAIL: // GLStencilOp_t "what do you do if stencil test fails"
  866. {
  867. GLenum stencilop = D3DStencilOpToGL( Value );
  868. gl.m_StencilOp.sfail = stencilop;
  869. m_ctx->WriteStencilOp( &gl.m_StencilOp,0 );
  870. m_ctx->WriteStencilOp( &gl.m_StencilOp,1 ); // ********* need to recheck this
  871. break;
  872. }
  873. case D3DRS_STENCILZFAIL: // GLStencilOp_t "what do you do if stencil test passes *but* depth test fails, if depth test happened"
  874. {
  875. GLenum stencilop = D3DStencilOpToGL( Value );
  876. gl.m_StencilOp.dpfail = stencilop;
  877. m_ctx->WriteStencilOp( &gl.m_StencilOp,0 );
  878. m_ctx->WriteStencilOp( &gl.m_StencilOp,1 ); // ********* need to recheck this
  879. break;
  880. }
  881. case D3DRS_STENCILPASS: // GLStencilOp_t "what do you do if stencil test and depth test both pass"
  882. {
  883. GLenum stencilop = D3DStencilOpToGL( Value );
  884. gl.m_StencilOp.dppass = stencilop;
  885. m_ctx->WriteStencilOp( &gl.m_StencilOp,0 );
  886. m_ctx->WriteStencilOp( &gl.m_StencilOp,1 ); // ********* need to recheck this
  887. break;
  888. }
  889. case D3DRS_STENCILFUNC: // GLStencilFunc_t
  890. {
  891. GLenum stencilfunc = D3DCompareFuncToGL( Value );
  892. gl.m_StencilFunc.frontfunc = gl.m_StencilFunc.backfunc = stencilfunc;
  893. m_ctx->WriteStencilFunc( &gl.m_StencilFunc );
  894. break;
  895. }
  896. case D3DRS_STENCILREF: // GLStencilFunc_t
  897. {
  898. gl.m_StencilFunc.ref = Value;
  899. m_ctx->WriteStencilFunc( &gl.m_StencilFunc );
  900. break;
  901. }
  902. case D3DRS_STENCILMASK: // GLStencilFunc_t
  903. {
  904. gl.m_StencilFunc.mask = Value;
  905. m_ctx->WriteStencilFunc( &gl.m_StencilFunc );
  906. break;
  907. }
  908. case D3DRS_STENCILWRITEMASK: // GLStencilWriteMask_t
  909. {
  910. gl.m_StencilWriteMask.mask = Value;
  911. m_ctx->WriteStencilWriteMask( &gl.m_StencilWriteMask );
  912. break;
  913. }
  914. case D3DRS_FOGENABLE: // none of these are implemented yet... erk
  915. {
  916. gl.m_FogEnable = (Value != 0);
  917. GLMPRINTF(("-D- fogenable = %d",Value ));
  918. break;
  919. }
  920. case D3DRS_SCISSORTESTENABLE: // kGLScissorEnable
  921. {
  922. gl.m_ScissorEnable.enable = Value;
  923. m_ctx->WriteScissorEnable( &gl.m_ScissorEnable );
  924. break;
  925. }
  926. case D3DRS_DEPTHBIAS: // kGLDepthBias
  927. {
  928. // the value in the dword is actually a float
  929. float fvalue = *(float*)&Value;
  930. gl.m_DepthBias.units = fvalue;
  931. m_ctx->WriteDepthBias( &gl.m_DepthBias );
  932. break;
  933. }
  934. // good ref on these: http://aras-p.info/blog/2008/06/12/depth-bias-and-the-power-of-deceiving-yourself/
  935. case D3DRS_SLOPESCALEDEPTHBIAS:
  936. {
  937. // the value in the dword is actually a float
  938. float fvalue = *(float*)&Value;
  939. gl.m_DepthBias.factor = fvalue;
  940. m_ctx->WriteDepthBias( &gl.m_DepthBias );
  941. break;
  942. }
  943. // Alpha to coverage
  944. case D3DRS_ADAPTIVETESS_Y:
  945. {
  946. gl.m_AlphaToCoverageEnable.enable = Value;
  947. m_ctx->WriteAlphaToCoverageEnable( &gl.m_AlphaToCoverageEnable );
  948. break;
  949. }
  950. case D3DRS_CLIPPLANEENABLE: // kGLClipPlaneEnable
  951. {
  952. // d3d packs all the enables into one word.
  953. // we break that out so we don't do N glEnable calls to sync -
  954. // GLM is tracking one unique enable per plane.
  955. for( int i=0; i<kGLMUserClipPlanes; i++)
  956. {
  957. gl.m_ClipPlaneEnable[i].enable = (Value & (1<<i)) != 0;
  958. }
  959. for( int x=0; x<kGLMUserClipPlanes; x++)
  960. m_ctx->WriteClipPlaneEnable( &gl.m_ClipPlaneEnable[x], x );
  961. break;
  962. }
  963. //-------------------------------------------------------------------------------------------- polygon/fill mode
  964. case D3DRS_FILLMODE:
  965. {
  966. GLuint mode = 0;
  967. switch(Value)
  968. {
  969. case D3DFILL_POINT: mode = GL_POINT; break;
  970. case D3DFILL_WIREFRAME: mode = GL_LINE; break;
  971. case D3DFILL_SOLID: mode = GL_FILL; break;
  972. default: DXABSTRACT_BREAK_ON_ERROR(); break;
  973. }
  974. gl.m_PolygonMode.values[0] = gl.m_PolygonMode.values[1] = mode;
  975. m_ctx->WritePolygonMode( &gl.m_PolygonMode );
  976. break;
  977. }
  978. }
  979. return S_OK;
  980. #endif
  981. }
  982. FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetRenderStateConstInline( D3DRENDERSTATETYPE State, DWORD Value )
  983. {
  984. // State is a compile time constant - luckily no need to do anything special to get the compiler to optimize this case.
  985. return SetRenderStateInline( State, Value );
  986. }
  987. FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetIndices(IDirect3DIndexBuffer9* pIndexData)
  988. {
  989. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  990. return SetIndicesNonInline( pIndexData );
  991. #else
  992. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  993. // just latch it.
  994. m_indices.m_idxBuffer = pIndexData;
  995. return S_OK;
  996. #endif
  997. }
  998. FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride)
  999. {
  1000. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  1001. return SetStreamSourceNonInline( StreamNumber, pStreamData, OffsetInBytes, Stride );
  1002. #else
  1003. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  1004. Assert( StreamNumber < D3D_MAX_STREAMS );
  1005. Assert( ( Stride & 3 ) == 0 ); // we support non-DWORD aligned strides, but on some drivers (like AMD's) perf goes off a cliff
  1006. // perfectly legal to see a vertex buffer of NULL get passed in here.
  1007. // so we need an array to track these.
  1008. // OK, we are being given the stride, we don't need to calc it..
  1009. GLMPRINTF(("-X- IDirect3DDevice9::SetStreamSource setting stream #%d to D3D buf %p (GL name %d); offset %d, stride %d", StreamNumber, pStreamData, (pStreamData) ? pStreamData->m_vtxBuffer->m_name: -1, OffsetInBytes, Stride));
  1010. if ( !pStreamData )
  1011. {
  1012. OffsetInBytes = 0;
  1013. Stride = 0;
  1014. m_vtx_buffers[ StreamNumber ] = m_pDummy_vtx_buffer;
  1015. }
  1016. else
  1017. {
  1018. // We do not support strides of 0
  1019. Assert( Stride > 0 );
  1020. m_vtx_buffers[ StreamNumber ] = pStreamData->m_vtxBuffer;
  1021. }
  1022. m_streams[ StreamNumber ].m_vtxBuffer = pStreamData;
  1023. m_streams[ StreamNumber ].m_offset = OffsetInBytes;
  1024. m_streams[ StreamNumber ].m_stride = Stride;
  1025. return S_OK;
  1026. #endif
  1027. }
  1028. FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount) // groups of 4 floats!
  1029. {
  1030. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  1031. return SetVertexShaderConstantFNonInline( StartRegister, pConstantData, Vector4fCount );
  1032. #else
  1033. TOGL_NULL_DEVICE_CHECK;
  1034. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  1035. m_ctx->SetProgramParametersF( kGLMVertexProgram, StartRegister, (float *)pConstantData, Vector4fCount );
  1036. return S_OK;
  1037. #endif
  1038. }
  1039. FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount)
  1040. {
  1041. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  1042. return SetVertexShaderConstantBNonInline( StartRegister, pConstantData, BoolCount );
  1043. #else
  1044. TOGL_NULL_DEVICE_CHECK;
  1045. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  1046. m_ctx->SetProgramParametersB( kGLMVertexProgram, StartRegister, (int *)pConstantData, BoolCount );
  1047. return S_OK;
  1048. #endif
  1049. }
  1050. FORCEINLINE HRESULT IDirect3DDevice9::SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount) // groups of 4 ints!
  1051. {
  1052. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  1053. return SetVertexShaderConstantINonInline( StartRegister, pConstantData, Vector4iCount );
  1054. #else
  1055. TOGL_NULL_DEVICE_CHECK;
  1056. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  1057. m_ctx->SetProgramParametersI( kGLMVertexProgram, StartRegister, (int *)pConstantData, Vector4iCount );
  1058. return S_OK;
  1059. #endif
  1060. }
  1061. FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount)
  1062. {
  1063. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  1064. return SetPixelShaderConstantFNonInline(StartRegister, pConstantData, Vector4fCount);
  1065. #else
  1066. TOGL_NULL_DEVICE_CHECK;
  1067. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  1068. m_ctx->SetProgramParametersF( kGLMFragmentProgram, StartRegister, (float *)pConstantData, Vector4fCount );
  1069. return S_OK;
  1070. #endif
  1071. }
  1072. HRESULT IDirect3DDevice9::SetVertexShader(IDirect3DVertexShader9* pShader)
  1073. {
  1074. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  1075. return SetVertexShaderNonInline(pShader);
  1076. #else
  1077. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  1078. m_ctx->SetVertexProgram( pShader ? pShader->m_vtxProgram : NULL );
  1079. m_vertexShader = pShader;
  1080. return S_OK;
  1081. #endif
  1082. }
  1083. FORCEINLINE HRESULT TOGLMETHODCALLTYPE IDirect3DDevice9::SetPixelShader(IDirect3DPixelShader9* pShader)
  1084. {
  1085. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  1086. return SetPixelShaderNonInline(pShader);
  1087. #else
  1088. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  1089. m_ctx->SetFragmentProgram( pShader ? pShader->m_pixProgram : NULL );
  1090. m_pixelShader = pShader;
  1091. return S_OK;
  1092. #endif
  1093. }
  1094. FORCEINLINE HRESULT IDirect3DDevice9::SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl)
  1095. {
  1096. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  1097. return SetVertexDeclarationNonInline(pDecl);
  1098. #else
  1099. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  1100. m_pVertDecl = pDecl;
  1101. return S_OK;
  1102. #endif
  1103. }
  1104. FORCEINLINE void IDirect3DDevice9::SetMaxUsedVertexShaderConstantsHint( uint nMaxReg )
  1105. {
  1106. #if GLMDEBUG || GL_BATCH_PERF_ANALYSIS
  1107. return SetMaxUsedVertexShaderConstantsHintNonInline( nMaxReg );
  1108. #else
  1109. Assert( GetCurrentOwnerThreadId() == ThreadGetCurrentId() );
  1110. m_ctx->SetMaxUsedVertexShaderConstantsHint( nMaxReg );
  1111. #endif
  1112. }
  1113. // ------------------------------------------------------------------------------------------------------------------------------ //
  1114. // D3DX
  1115. // ------------------------------------------------------------------------------------------------------------------------------ //
  1116. struct ID3DXInclude
  1117. {
  1118. virtual HRESULT Open(D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes);
  1119. virtual HRESULT Close(LPCVOID pData);
  1120. };
  1121. typedef ID3DXInclude* LPD3DXINCLUDE;
  1122. struct TOGL_CLASS ID3DXBuffer : public IUnknown
  1123. {
  1124. void* GetBufferPointer();
  1125. DWORD GetBufferSize();
  1126. };
  1127. typedef ID3DXBuffer* LPD3DXBUFFER;
  1128. class ID3DXConstantTable : public IUnknown
  1129. {
  1130. };
  1131. typedef ID3DXConstantTable* LPD3DXCONSTANTTABLE;
  1132. TOGL_INTERFACE const char* D3DXGetPixelShaderProfile( IDirect3DDevice9 *pDevice );
  1133. TOGL_INTERFACE D3DXMATRIX* D3DXMatrixMultiply( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
  1134. TOGL_INTERFACE D3DXVECTOR3* D3DXVec3TransformCoord( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  1135. TOGL_INTERFACE HRESULT D3DXCreateMatrixStack( DWORD Flags, LPD3DXMATRIXSTACK* ppStack);
  1136. TOGL_INTERFACE void D3DXMatrixIdentity( D3DXMATRIX * );
  1137. TOGL_INTERFACE D3DXINLINE D3DXVECTOR3* D3DXVec3Subtract( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1138. {
  1139. pOut->x = pV1->x - pV2->x;
  1140. pOut->y = pV1->y - pV2->y;
  1141. pOut->z = pV1->z - pV2->z;
  1142. return pOut;
  1143. }
  1144. TOGL_INTERFACE D3DXINLINE D3DXVECTOR3* D3DXVec3Cross( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1145. {
  1146. D3DXVECTOR3 v;
  1147. v.x = pV1->y * pV2->z - pV1->z * pV2->y;
  1148. v.y = pV1->z * pV2->x - pV1->x * pV2->z;
  1149. v.z = pV1->x * pV2->y - pV1->y * pV2->x;
  1150. *pOut = v;
  1151. return pOut;
  1152. }
  1153. TOGL_INTERFACE D3DXINLINE FLOAT D3DXVec3Dot( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  1154. {
  1155. return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z;
  1156. }
  1157. TOGL_INTERFACE D3DXMATRIX* D3DXMatrixInverse( D3DXMATRIX *pOut, FLOAT *pDeterminant, CONST D3DXMATRIX *pM );
  1158. TOGL_INTERFACE D3DXMATRIX* D3DXMatrixTranspose( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM );
  1159. TOGL_INTERFACE D3DXPLANE* D3DXPlaneNormalize( D3DXPLANE *pOut, CONST D3DXPLANE *pP);
  1160. TOGL_INTERFACE D3DXVECTOR4* D3DXVec4Transform( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, CONST D3DXMATRIX *pM );
  1161. TOGL_INTERFACE D3DXVECTOR4* D3DXVec4Normalize( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV );
  1162. TOGL_INTERFACE D3DXMATRIX* D3DXMatrixTranslation( D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z );
  1163. // Build an ortho projection matrix. (right-handed)
  1164. TOGL_INTERFACE D3DXMATRIX* D3DXMatrixOrthoOffCenterRH( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,FLOAT zf );
  1165. TOGL_INTERFACE D3DXMATRIX* D3DXMatrixPerspectiveRH( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  1166. TOGL_INTERFACE D3DXMATRIX* D3DXMatrixPerspectiveOffCenterRH( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, FLOAT zf );
  1167. // Transform a plane by a matrix. The vector (a,b,c) must be normal.
  1168. // M should be the inverse transpose of the transformation desired.
  1169. TOGL_INTERFACE D3DXPLANE* D3DXPlaneTransform( D3DXPLANE *pOut, CONST D3DXPLANE *pP, CONST D3DXMATRIX *pM );
  1170. TOGL_INTERFACE IDirect3D9 *Direct3DCreate9(UINT SDKVersion);
  1171. TOGL_INTERFACE void D3DPERF_SetOptions( DWORD dwOptions );
  1172. TOGL_INTERFACE HRESULT D3DXCompileShader(
  1173. LPCSTR pSrcData,
  1174. UINT SrcDataLen,
  1175. CONST D3DXMACRO* pDefines,
  1176. LPD3DXINCLUDE pInclude,
  1177. LPCSTR pFunctionName,
  1178. LPCSTR pProfile,
  1179. DWORD Flags,
  1180. LPD3DXBUFFER* ppShader,
  1181. LPD3DXBUFFER* ppErrorMsgs,
  1182. LPD3DXCONSTANTTABLE* ppConstantTable);
  1183. // fake D3D usage constant for SRGB tex creation
  1184. #define D3DUSAGE_TEXTURE_SRGB (0x80000000L)
  1185. #else
  1186. //USE_ACTUAL_DX
  1187. #ifndef WIN32
  1188. #error sorry man
  1189. #endif
  1190. #ifdef _X360
  1191. #include "d3d9.h"
  1192. #include "d3dx9.h"
  1193. #else
  1194. #include <windows.h>
  1195. #include "../../dx9sdk/include/d3d9.h"
  1196. #include "../../dx9sdk/include/d3dx9.h"
  1197. #endif
  1198. typedef HWND VD3DHWND;
  1199. #endif // DX_TO_GL_ABSTRACTION
  1200. #endif // DXABSTRACT_H