Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1450 lines
54 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995-1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: d3di.hpp
  6. * Content: Direct3D internal include file
  7. *
  8. * $Id:
  9. *
  10. * History:
  11. * Date By Reason
  12. * ==== == ======
  13. * 05/11/95 stevela Initial rev with this header.
  14. *
  15. ***************************************************************************/
  16. #ifndef _D3DI_HPP
  17. #define _D3DI_HPP
  18. #include "ddrawp.h"
  19. #include "d3dp.h"
  20. #include "d3dmem.h"
  21. #if !defined(BUILD_DDDDK)
  22. extern "C" {
  23. #include "ddrawi.h"
  24. };
  25. #include "object.h"
  26. #include "lists.hpp"
  27. #include <d3ditype.h>
  28. #include <d3dutil.h>
  29. #include <d3dfe.hpp>
  30. //--------------------------------------------------------------------
  31. const DWORD __INIT_VERTEX_NUMBER = 1024;// Initial number of vertices in TL and
  32. // clip flag buffers
  33. const DWORD __MAX_VERTEX_SIZE = 128; // Max size of FVF vertex in bytes
  34. //--------------------------------------------------------------------
  35. /*
  36. * Registry defines
  37. */
  38. #define RESPATH "Software\\Microsoft\\Direct3D\\Drivers"
  39. #define RESPATH_D3D "Software\\Microsoft\\Direct3D"
  40. extern HINSTANCE hGeometryDLL;
  41. /*
  42. * CPU family and features flags
  43. */
  44. extern DWORD dwCPUFamily, dwCPUFeatures;
  45. extern char szCPUString[];
  46. // MMX available
  47. #define D3DCPU_MMX 0x00000001L
  48. // FCOMI and CMOV are both supported
  49. #define D3DCPU_FCOMICMOV 0x00000002L
  50. // Reads block until satisfied
  51. #define D3DCPU_BLOCKINGREAD 0x00000004L
  52. // Extended 3D support available
  53. #define D3DCPU_X3D 0x00000008L
  54. // Pentium II CPU
  55. #define D3DCPU_PII 0x000000010L
  56. // Katmai CPU
  57. #define D3DCPU_KATMAI 0x000000020L
  58. #define IS_OVERRIDE(type) ((DWORD)(type) > D3DSTATE_OVERRIDE_BIAS)
  59. #define GET_OVERRIDE(type) ((DWORD)(type) - D3DSTATE_OVERRIDE_BIAS)
  60. #define MAX_STATE D3DSTATE_OVERRIDE_BIAS
  61. #define DEFAULT_GAMMA DTOVAL(1.4)
  62. /*
  63. INDEX_BATCH_SCALE is the constant which is used by DrawIndexedPrim
  64. to deterimine if the number of primitives being drawn is small
  65. relative to the number of vertices being passed. If it is then
  66. the prims are dereferenced in batches and sent to DrawPrim.
  67. */
  68. #define INDEX_BATCH_SCALE 2
  69. #endif // BUILD_DDDDK
  70. typedef ULONG_PTR D3DI_BUFFERHANDLE, *LPD3DI_BUFFERHANDLE;
  71. // AnanKan: This should ideally reside in d3dtypes.h, but since we are
  72. // pulling out OptSurface support in DX6 I kept it here (to keep the code
  73. // alive)
  74. typedef HRESULT (WINAPI* LPD3DENUMOPTTEXTUREFORMATSCALLBACK)(LPDDSURFACEDESC2 lpDdsd2, LPDDOPTSURFACEDESC lpDdOsd, LPVOID lpContext);
  75. /*
  76. * Internal version of executedata
  77. */
  78. typedef struct _D3DI_ExecuteData {
  79. DWORD dwSize;
  80. D3DI_BUFFERHANDLE dwHandle; /* Handle allocated by driver */
  81. DWORD dwVertexOffset;
  82. DWORD dwVertexCount;
  83. DWORD dwInstructionOffset;
  84. DWORD dwInstructionLength;
  85. DWORD dwHVertexOffset;
  86. D3DSTATUS dsStatus; /* Status after execute */
  87. } D3DI_EXECUTEDATA, *LPD3DI_EXECUTEDATA;
  88. #if !defined(BUILD_DDDDK)
  89. class DIRECT3DDEVICEI;
  90. class DIRECT3DVIEWPORTI;
  91. typedef class DIRECT3DI *LPDIRECT3DI;
  92. typedef class DIRECT3DDEVICEI *LPDIRECT3DDEVICEI;
  93. typedef class DIRECT3DEXECUTEBUFFERI *LPDIRECT3DEXECUTEBUFFERI;
  94. typedef class DIRECT3DLIGHTI *LPDIRECT3DLIGHTI;
  95. typedef class DIRECT3DMATERIALI *LPDIRECT3DMATERIALI;
  96. typedef class DIRECT3DTEXTUREI *LPDIRECT3DTEXTUREI;
  97. typedef class DIRECT3DVIEWPORTI *LPDIRECT3DVIEWPORTI;
  98. typedef class CDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFERI;
  99. class CDirect3DUnk : public IUnknown
  100. {
  101. public:
  102. unsigned refCnt; /* Reference count object */
  103. public:
  104. LPDIRECT3DI pD3DI;
  105. public:
  106. // IUnknown Methods
  107. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  108. ULONG D3DAPI AddRef();
  109. ULONG D3DAPI Release();
  110. };
  111. class CDirect3D : public IDirect3D
  112. {
  113. public:
  114. HRESULT D3DAPI EnumDevices(LPD3DENUMDEVICESCALLBACK, LPVOID);
  115. virtual HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK, LPVOID, DWORD, DWORD)=0;
  116. HRESULT D3DAPI FindDevice(LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT);
  117. virtual HRESULT FindDevice(LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT, DWORD)=0;
  118. };
  119. class CDirect3D2 : public IDirect3D2
  120. {
  121. public:
  122. HRESULT D3DAPI EnumDevices(LPD3DENUMDEVICESCALLBACK, LPVOID);
  123. virtual HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK, LPVOID, DWORD, DWORD)=0;
  124. HRESULT D3DAPI FindDevice(LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT);
  125. virtual HRESULT FindDevice(LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT, DWORD)=0;
  126. };
  127. class CDirect3D3 : public IDirect3D3
  128. {
  129. public:
  130. HRESULT D3DAPI EnumDevices(LPD3DENUMDEVICESCALLBACK, LPVOID);
  131. virtual HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK, LPVOID, DWORD, DWORD)=0;
  132. HRESULT D3DAPI FindDevice(LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT);
  133. virtual HRESULT FindDevice(LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT, DWORD)=0;
  134. };
  135. class DIRECT3DI : public CDirect3D,
  136. public CDirect3D2,
  137. public CDirect3D3,
  138. public CD3DAlloc
  139. {
  140. public: //Private Data
  141. /*** Object Relations ***/
  142. /* Devices */
  143. int numDevs;/* Number of devices */
  144. struct _devices { DIRECT3DDEVICEI* Root;} devices;
  145. /* Associated IDirect3DDevices */
  146. /* Viewports */
  147. int numViewports; /* Number of viewports */
  148. LIST_ROOT(_viewports, DIRECT3DVIEWPORTI) viewports;
  149. /* Created IDirect3DViewports */
  150. /* Lights */
  151. int numLights; /* Number of lights */
  152. LIST_ROOT(_lights, DIRECT3DLIGHTI) lights;
  153. /* Created IDirect3DLights */
  154. /* Materials */
  155. int numMaterials; /* Number of materials */
  156. LIST_ROOT(_materials, DIRECT3DMATERIALI) materials;
  157. /* Created IDirect3DMaterials */
  158. /* Vertex Buffers */
  159. int numVBufs; /* Number of vertex buffers */
  160. LIST_ROOT(_vbufs, CDirect3DVertexBuffer) vbufs;
  161. /* Created IDirect3DVertexBuffers */
  162. /*** Object Data ***/
  163. CDirect3DUnk mD3DUnk;
  164. unsigned long v_next; /* id of next viewport to be created */
  165. //RLDDIRegistry* lpReg; /* Registry */
  166. struct _D3DBUCKET *lpFreeList; /* Free linked list */
  167. struct _D3DBUCKET *lpBufferList;/* link list of headers of big chunks allocated*/
  168. class TextureCacheManager *lpTextureManager;
  169. /*
  170. * DirectDraw Interface
  171. */
  172. LPDIRECTDRAW lpDD;
  173. LPDIRECTDRAW4 lpDD4; /* needed for CreateSurface to get LPDIRECTDRAWSURFACE4 */
  174. // HACK. D3D needs a DD1 DDRAWI interface because it uses CreateSurface1 internally
  175. // for exebufs, among other things. But the D3DI object cannot keep a reference
  176. // to its parent DD object because it is aggegrated with the DD obj, so that would constitute
  177. // a circular reference that would prevent deletion. So QI for DD1 interface, copy it into D3DI
  178. // and release it, then point lpDD at the copy. (disgusting)
  179. // More disgusting still: These need to be large enough to hold ddrawex interface structs
  180. DDRAWI_DIRECTDRAW_INT DDInt_DD1;
  181. DDRAWI_DIRECTDRAW_INT DDInt_DD4;
  182. /*
  183. * The special IUnknown interface for the aggregate that does
  184. * not punt to the parent object.
  185. */
  186. LPUNKNOWN lpOwningIUnknown; /* The owning IUnknown */
  187. public: //Private methods
  188. DIRECT3DI(IUnknown* pUnkOuter, LPDDRAWI_DIRECTDRAW_INT pDDrawInt); // Constructor called Direct3DCreate()
  189. ~DIRECT3DI(); // Destructor called by CDirect3DUnk::Release()
  190. HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK, LPVOID, DWORD, DWORD);
  191. HRESULT FindDevice(LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT, DWORD);
  192. // Internal CreateVertexBuffer
  193. HRESULT CreateVertexBufferI(LPD3DVERTEXBUFFERDESC, LPDIRECT3DVERTEXBUFFER*, DWORD);
  194. // Device flushing
  195. HRESULT FlushDevicesExcept(LPDIRECT3DDEVICEI pDev);
  196. public:
  197. // IUnknown Methods
  198. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  199. ULONG D3DAPI AddRef();
  200. ULONG D3DAPI Release();
  201. // IDirect3D Methods
  202. HRESULT D3DAPI Initialize(REFCLSID);
  203. HRESULT D3DAPI CreateLight(LPDIRECT3DLIGHT*, IUnknown*);
  204. HRESULT D3DAPI CreateMaterial(LPDIRECT3DMATERIAL*, IUnknown*);
  205. HRESULT D3DAPI CreateViewport(LPDIRECT3DVIEWPORT*, IUnknown*);
  206. //IDirect3D2 Methods
  207. HRESULT D3DAPI CreateMaterial(LPDIRECT3DMATERIAL2*, IUnknown*);
  208. HRESULT D3DAPI CreateViewport(LPDIRECT3DVIEWPORT2*, IUnknown*);
  209. HRESULT D3DAPI CreateDevice(REFCLSID, LPDIRECTDRAWSURFACE, LPDIRECT3DDEVICE2*);
  210. //IDirect3D3 Methods
  211. HRESULT D3DAPI CreateMaterial(LPDIRECT3DMATERIAL3*, LPUNKNOWN);
  212. HRESULT D3DAPI CreateViewport(LPDIRECT3DVIEWPORT3*, LPUNKNOWN);
  213. HRESULT D3DAPI CreateDevice(REFCLSID, LPDIRECTDRAWSURFACE4, LPDIRECT3DDEVICE3*, LPUNKNOWN);
  214. HRESULT D3DAPI CreateVertexBuffer(LPD3DVERTEXBUFFERDESC, LPDIRECT3DVERTEXBUFFER*, DWORD, LPUNKNOWN);
  215. HRESULT D3DAPI EnumZBufferFormats(REFCLSID, LPD3DENUMPIXELFORMATSCALLBACK, LPVOID);
  216. HRESULT D3DAPI EnumOptTextureFormats(REFCLSID, LPD3DENUMOPTTEXTUREFORMATSCALLBACK, LPVOID); // not exposed by API (yet)
  217. HRESULT D3DAPI EvictManagedTextures();
  218. };
  219. typedef DIRECT3DI* LPDIRECT3DI;
  220. #include "d3dhal.h"
  221. #include "halprov.h"
  222. //---------------------------------------------------------------------
  223. typedef HRESULT (*PFNDRVSETRENDERTARGET)(LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4,
  224. LPDIRECTDRAWPALETTE, LPDIRECT3DDEVICEI);
  225. typedef HRESULT (*PFNDOFLUSHBEGINEND)(LPDIRECT3DDEVICEI);
  226. typedef HRESULT (*PFNDRAWPRIM)(LPDIRECT3DDEVICEI);
  227. typedef struct _D3DBUCKET
  228. {
  229. struct _D3DBUCKET *next;
  230. union
  231. {
  232. LPVOID lpD3DDevI;
  233. LPDDRAWI_DDRAWSURFACE_LCL lpLcl;
  234. LPVOID lpBuffer;
  235. LPDIRECT3DTEXTUREI lpD3DTexI;
  236. };
  237. unsigned int ticks;
  238. LPDIRECTDRAWSURFACE *lplpDDSZBuffer; //if not NULL, points to lpDDSZBuffer in Direct3DDeviceI
  239. } D3DBUCKET,*LPD3DBUCKET;
  240. typedef struct _D3DI_TEXTUREBLOCK
  241. {
  242. LIST_MEMBER(_D3DI_TEXTUREBLOCK) list;
  243. /* Next block in IDirect3DTexture */
  244. LIST_MEMBER(_D3DI_TEXTUREBLOCK) devList;
  245. /* Next block in IDirect3DDevice */
  246. LPDIRECT3DDEVICEI lpDevI;
  247. /* this texture block refers to either an
  248. * IDirect3DTexture/IDirect3DTexture2, so one of these pointers will
  249. * always be NULL
  250. */
  251. LPDIRECT3DTEXTUREI lpD3DTextureI;
  252. /* pointer to internal struct for IDirect3DTexture/IDirect3DTexture2 */
  253. D3DTEXTUREHANDLE hTex;
  254. /* texture handle */
  255. } D3DI_TEXTUREBLOCK;
  256. typedef struct _D3DI_TEXTUREBLOCK *LPD3DI_TEXTUREBLOCK;
  257. typedef struct _D3DI_MATERIALBLOCK
  258. {
  259. LIST_MEMBER(_D3DI_MATERIALBLOCK) list;
  260. /* Next block in IDirect3DMaterial */
  261. LIST_MEMBER(_D3DI_MATERIALBLOCK) devList;
  262. /* Next block in IDirect3DDevice */
  263. LPDIRECT3DDEVICEI lpDevI;
  264. LPDIRECT3DMATERIALI lpD3DMaterialI;
  265. D3DMATERIALHANDLE hMat;
  266. /* material handle */
  267. DWORD hMatDDI;
  268. /* driver handle (for hardware transform & light) */
  269. } D3DI_MATERIALBLOCK;
  270. typedef struct _D3DI_MATERIALBLOCK *LPD3DI_MATERIALBLOCK;
  271. typedef struct _D3DFE_MATERIAL
  272. {
  273. LIST_MEMBER(_D3DFE_MATERIAL) link;
  274. D3DMATERIAL mat;
  275. // RampRast material if necessary
  276. LPVOID pRmMat;
  277. } D3DFE_MATERIAL, *LPD3DFE_MATERIAL;
  278. // Function to compute lighting
  279. //
  280. typedef struct _LIGHT_VERTEX_FUNC_TABLE
  281. {
  282. LIGHT_VERTEX_FUNC directional1;
  283. LIGHT_VERTEX_FUNC directional2;
  284. LIGHT_VERTEX_FUNC spot1;
  285. LIGHT_VERTEX_FUNC spot2;
  286. LIGHT_VERTEX_FUNC point1;
  287. LIGHT_VERTEX_FUNC point2;
  288. } LIGHT_VERTEX_FUNC_TABLE;
  289. //---------------------------------------------------------------------
  290. //
  291. // Bits for D3DFRONTEND flags (dwFEFlags in DIRECT3DDEVICEI)
  292. //
  293. const DWORD D3DFE_VALID = 1 << 1;
  294. const DWORD D3DFE_TLVERTEX = 1 << 2;
  295. const DWORD D3DFE_REALHAL = 1 << 3;
  296. const DWORD D3DFE_VIEWPORT_DIRTY = 1 << 4;
  297. const DWORD D3DFE_PROJMATRIX_DIRTY = 1 << 5;
  298. const DWORD D3DFE_VIEWMATRIX_DIRTY = 1 << 6;
  299. const DWORD D3DFE_WORLDMATRIX_DIRTY = 1 << 7;
  300. const DWORD D3DFE_INVERSEMCLIP_DIRTY = 1 << 8;
  301. const DWORD D3DFE_MCLIP_IDENTITY = 1 << 9;
  302. const DWORD D3DFE_PROJ_PERSPECTIVE = 1 << 10;
  303. const DWORD D3DFE_AFFINE_WORLD = 1 << 11;
  304. const DWORD D3DFE_AFFINE_VIEW = 1 << 12;
  305. const DWORD D3DFE_AFFINE_WORLD_VIEW = 1 << 13;
  306. const DWORD D3DFE_NEED_TRANSFORM_LIGHTS = 1 << 14;
  307. const DWORD D3DFE_MATERIAL_DIRTY = 1 << 15;
  308. const DWORD D3DFE_NEED_TRANSFORM_EYE = 1 << 16;
  309. const DWORD D3DFE_FOG_DIRTY = 1 << 17;
  310. const DWORD D3DFE_LIGHTS_DIRTY = 1 << 18;
  311. // Set if D3DLIGHTSTATE_COLORVERTEX is TRUE
  312. const DWORD D3DFE_COLORVERTEX = 1 << 19;
  313. // Set if the Current Transformation Matrix has been changed
  314. // Reset when frustum planes in the model space have been computed
  315. const DWORD D3DFE_FRUSTUMPLANES_DIRTY = 1 << 20;
  316. const DWORD D3DFE_WORLDVIEWMATRIX_DIRTY = 1 << 21;
  317. // This bit is set if fog mode is not FOG_NONE and fog is enabled
  318. const DWORD D3DFE_FOGENABLED = 1 << 22;
  319. // This bit set if UpdateManagedTextures() needs to be called
  320. const DWORD D3DFE_NEED_TEXTURE_UPDATE = 1 << 23;
  321. // This bit set if mapping DX6 texture blend modes to renderstates is desired
  322. const DWORD D3DFE_MAP_TSS_TO_RS = 1 << 24;
  323. // This bit set if we have to compute specular highlights
  324. const DWORD D3DFE_COMPUTESPECULAR = 1 << 26;
  325. const DWORD D3DFE_LOSTSURFACES = 1 << 27;
  326. // This bit set if texturing is disabled
  327. const DWORD D3DFE_DISABLE_TEXTURES = 1 << 28;
  328. // This bit set when D3DTSS_TEXCOORDINDEX is changed
  329. const DWORD D3DFE_TSSINDEX_DIRTY = 1 << 29;
  330. const DWORD D3DFE_TRANSFORM_DIRTY = D3DFE_VIEWPORT_DIRTY |
  331. D3DFE_PROJMATRIX_DIRTY |
  332. D3DFE_VIEWMATRIX_DIRTY |
  333. D3DFE_WORLDMATRIX_DIRTY;
  334. //---------------------------------------------------------------------
  335. //
  336. // Bits for dwDebugFlags
  337. //
  338. // Set if DisableFVF key is not 0 in registry and driver supports FVF
  339. const DWORD D3DDEBUG_DISABLEFVF = 1 << 0;
  340. // Disable Draw Primitive DDI
  341. const DWORD D3DDEBUG_DISABLEDP = 1 << 1;
  342. // Disable Draw Primitive 2 DDI
  343. const DWORD D3DDEBUG_DISABLEDP2 = 1 << 2;
  344. #ifdef WIN95
  345. #define _D3D_FORCEDOUBLE 1
  346. #else //WIN95
  347. #define _D3D_FORCEDOUBLE 0
  348. #endif //WIN95
  349. #if _D3D_FORCEDOUBLE
  350. // Set if ForceDouble key is not 0 in the registry and driver is pre-DX6 REALHAL
  351. const DWORD D3DDEBUG_FORCEDOUBLE= 1 << 2;
  352. #endif //_D3D_FORCEDOUBLE
  353. //---------------------------------------------------------------------
  354. // Bits for transform.dwFlags
  355. //
  356. // Frastum plane equations are valid
  357. const DWORD D3DTRANS_VALIDFRUSTUM = 1 << 2;
  358. //---------------------------------------------------------------------
  359. typedef struct _D3DFE_TRANSFORM
  360. {
  361. LIST_ROOT(matlist, _D3DMATRIXI) matrices;
  362. D3DMATRIXI proj;
  363. D3DMATRIXI view;
  364. D3DMATRIXI world;
  365. D3DMATRIXI mPC; // Mproj * Mclip
  366. D3DMATRIXI mVPC; // Mview * PC
  367. D3DMATRIXHANDLE hProj;
  368. D3DMATRIXHANDLE hView;
  369. D3DMATRIXHANDLE hWorld;
  370. D3DMATRIXI mCTMI; // Inverse current transformation matrix
  371. D3DVECTORH frustum[6]; // Normalized plane equations for viewing frustum
  372. // in the model space
  373. DWORD dwFlags;
  374. } D3DFE_TRANSFORM;
  375. typedef void (*D3DFEDestroyProc)(LPDIRECT3DDEVICEI lpD3DDevI);
  376. #define D3D_RSTATEBUF_SIZE 128
  377. #define D3D_MAX_MMX_VERTICES 1024
  378. extern DWORD dwD3DTriBatchSize, dwTriBatchSize, dwLineBatchSize;
  379. extern DWORD dwHWBufferSize, dwHWMaxTris;
  380. extern DWORD dwHWFewVertices;
  381. typedef struct _D3DHAL_DRAWPRIMCOUNTS *LPD3DHAL_DRAWPRIMCOUNTS;
  382. // Legacy HAL batching is done with these structs.
  383. typedef struct _D3DI_HWCOUNTS {
  384. WORD wNumStateChanges; // Number of state changes batched
  385. WORD wNumVertices; // Number of vertices in tri list
  386. WORD wNumTriangles; // Number of triangles in tri list
  387. } D3DI_HWCOUNTS, *LPD3DI_HWCOUNTS;
  388. typedef struct _D3DHAL_EXDATA
  389. {
  390. LIST_MEMBER(_D3DHAL_EXDATA) link;
  391. D3DEXECUTEBUFFERDESC debDesc;
  392. LPDIRECTDRAWSURFACE lpDDS;
  393. } D3DHAL_EXDATA;
  394. typedef D3DHAL_EXDATA *LPD3DHAL_EXDATA;
  395. /*
  396. * Picking stuff.
  397. */
  398. typedef struct _D3DI_PICKDATA
  399. {
  400. D3DI_EXECUTEDATA* exe;
  401. D3DPICKRECORD* records;
  402. int pick_count;
  403. D3DRECT pick;
  404. } D3DI_PICKDATA, *LPD3DI_PICKDATA;
  405. #define DWORD_BITS 32
  406. #define DWORD_SHIFT 5
  407. typedef struct _D3DFE_STATESET
  408. {
  409. DWORD bits[MAX_STATE >> DWORD_SHIFT];
  410. } D3DFE_STATESET;
  411. #define STATESET_MASK(set, state) \
  412. (set).bits[((state) - 1) >> DWORD_SHIFT]
  413. #define STATESET_BIT(state) (1 << (((state) - 1) & (DWORD_BITS - 1)))
  414. #define STATESET_ISSET(set, state) \
  415. STATESET_MASK(set, state) & STATESET_BIT(state)
  416. #define STATESET_SET(set, state) \
  417. STATESET_MASK(set, state) |= STATESET_BIT(state)
  418. #define STATESET_CLEAR(set, state) \
  419. STATESET_MASK(set, state) &= ~STATESET_BIT(state)
  420. #define STATESET_INIT(set) memset(&(set), 0, sizeof(set))
  421. class CDirect3DDeviceUnk : public IUnknown
  422. {
  423. public:
  424. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  425. ULONG D3DAPI AddRef();
  426. ULONG D3DAPI Release();
  427. public:
  428. /* Reference count object */
  429. unsigned refCnt;
  430. /* Our Device type */
  431. LPDIRECT3DDEVICEI pDevI;
  432. };
  433. class CDirect3DDevice : public IDirect3DDevice
  434. {
  435. public:
  436. HRESULT D3DAPI GetCaps(LPD3DDEVICEDESC, LPD3DDEVICEDESC);
  437. virtual HRESULT GetCapsI(LPD3DDEVICEDESC, LPD3DDEVICEDESC)=0;
  438. public:
  439. DWORD dwVersion; // represents the version the device was created as (3==IDirect3DDevice3, etc)
  440. };
  441. typedef enum {
  442. D3DDEVTYPE_OLDHAL,
  443. D3DDEVTYPE_DPHAL,
  444. D3DDEVTYPE_DP2HAL,
  445. D3DDEVTYPE_DX7HAL
  446. } D3DDEVICETYPE;
  447. //---------------------------------------------------------------------
  448. typedef HRESULT (DIRECT3DDEVICEI::*PFN_DRAWPRIM)();
  449. //---------------------------------------------------------------------
  450. // This type is used to define operation for ProcessPrimitive
  451. //
  452. typedef enum
  453. {
  454. __PROCPRIMOP_INDEXEDPRIM, // Process indexed primitive
  455. __PROCPRIMOP_NONINDEXEDPRIM, // Process non-indexed primitive
  456. __PROCPRIMOP_PROCVERONLY, // Process vertices only
  457. } __PROCPRIMOP;
  458. //---------------------------------------------------------------------
  459. #ifdef _IA64_ // Removes IA64 compiler alignment warnings
  460. #pragma pack(16)
  461. #endif
  462. #ifdef _AXP64_ // Removes AXP64 compiler alignment warnings
  463. #pragma pack(16)
  464. #endif
  465. class DIRECT3DDEVICEI : public CDirect3DDevice,
  466. public IDirect3DDevice2,
  467. public IDirect3DDevice3,
  468. public CD3DAlloc,
  469. public D3DFE_PROCESSVERTICES
  470. {
  471. public: // Private Data
  472. HRESULT (*pfnFlushStates)(LPDIRECT3DDEVICEI);
  473. #define D3DDEVBOOL_HINTFLAGS_INSCENE (0x00000001L) // Are we between Begin/End?
  474. #define D3DDEVBOOL_HINTFLAGS_INBEGIN (0x00000002L) // Are we in a scene?
  475. #define D3DDEVBOOL_HINTFLAGS_INBEGIN_FIRST_FLUSH (0x00000004L) // Set when first flush occurs
  476. // Set when indexed begin/end primitive is flushed several times
  477. #define D3DDEVBOOL_HINTFLAGS_INBEGIN_BIG_PRIM (0x00000020L)
  478. #define D3DDEVBOOL_HINTFLAGS_INBEGIN_ALL (D3DDEVBOOL_HINTFLAGS_INBEGIN | \
  479. D3DDEVBOOL_HINTFLAGS_INBEGIN_FIRST_FLUSH | \
  480. D3DDEVBOOL_HINTFLAGS_INBEGIN_BIG_PRIM)
  481. #define D3DDEVBOOL_HINTFLAGS_INTERNAL_BEGIN_END (0x00000008L) // Is this an internal (tex fill)
  482. // begin/end
  483. #define D3DDEVBOOL_HINTFLAGS_MULTITHREADED (0x00000010L) // multithreaded device
  484. /* Should be cache line aligned. Now it is not !!! 0f04*/
  485. DWORD dwHintFlags;
  486. // Cache last input->output FVF mapping
  487. DWORD dwFVFLastIn;
  488. DWORD dwFVFLastOut;
  489. DWORD dwFVFLastTexCoord;
  490. DWORD dwFVFLastOutputSize;
  491. DWORD dwFVFLastInSize;
  492. DWORD dwFEFlags;
  493. /*Should be cache line aligned. Now it is not*/
  494. // Pointer to the PV funcs that we need to call
  495. LPD3DFE_PVFUNCS pGeometryFuncs;
  496. // buffers for TL and H vertices
  497. CAlignedBuffer32 HVbuf; // Used for clip flags
  498. CBufferVB TLVbuf;
  499. /*Should be cache line aligned. Now it is not*/
  500. PFN_DRAWPRIM pfnDrawPrim; // Used by clipper to call HAL
  501. PFN_DRAWPRIM pfnDrawIndexedPrim; // Used by clipper to call HAL
  502. /* Viewports */
  503. unsigned long v_id; /* ID of last viewport rendered */
  504. /* Associated IDirect3DViewports */
  505. LPDIRECT3DVIEWPORTI lpCurrentViewport;
  506. /* Device Type */
  507. D3DDEVICETYPE deviceType;
  508. D3DSTATS D3DStats;
  509. /*** Object Relations ***/
  510. LPDIRECT3DI lpDirect3DI; /* parent */
  511. LIST_MEMBER(DIRECT3DDEVICEI)list; /* Next device IDirect3D */
  512. /* Textures */
  513. LIST_ROOT(_dmtextures, _D3DI_TEXTUREBLOCK) texBlocks;
  514. /* Ref to created IDirect3DTextures */
  515. /* Execute buffers */
  516. LIST_ROOT(_buffers, DIRECT3DEXECUTEBUFFERI) buffers;
  517. /* Created IDirect3DExecuteBuffers */
  518. /* Viewports */
  519. int numViewports;
  520. CIRCLE_QUEUE_ROOT(_dviewports, DIRECT3DVIEWPORTI) viewports;
  521. /* Materials */
  522. LIST_ROOT(_dmmaterials, _D3DI_MATERIALBLOCK) matBlocks;
  523. /* Ref to associated IDirect3DMaterials */
  524. /*** Object Data ***/
  525. CDirect3DDeviceUnk mDevUnk;
  526. // for DX3-style devices aggregated onto ddraw, guid should be IID_IDirect3DRGBDevice,
  527. // IID_IDirect3DHALDevice, etc. for DX5 and beyond, guid is IID_IDirect3DDevice,
  528. // IID_IDirect3DDevice2, etc
  529. GUID guid;
  530. LPD3DHAL_CALLBACKS lpD3DHALCallbacks; /* HW specific */
  531. LPD3DHAL_GLOBALDRIVERDATA lpD3DHALGlobalDriverData; /* HW specific */
  532. LPD3DHAL_CALLBACKS2 lpD3DHALCallbacks2; /* HW specific */
  533. LPD3DHAL_CALLBACKS3 lpD3DHALCallbacks3; /* DX6 DDI */
  534. /* DirectDraw objects that we are holding references to */
  535. LPDIRECTDRAW lpDD; // DirectDraw object
  536. LPDDRAWI_DIRECTDRAW_GBL lpDDGbl; //
  537. LPDIRECTDRAWSURFACE lpDDSTarget; // Render target
  538. LPDIRECTDRAWSURFACE lpDDSZBuffer; // Z buffer
  539. LPDIRECTDRAWPALETTE lpDDPalTarget; // Palette for render target (if any)
  540. // these are saved for use by new GetRenderTarget and anything else that requires DDS4 functionality
  541. LPDIRECTDRAWSURFACE4 lpDDSTarget_DDS4;
  542. LPDIRECTDRAWSURFACE4 lpDDSZBuffer_DDS4;
  543. DWORD dwWidth, dwHeight; // dimensions of render target
  544. // Front end data
  545. D3DFE_TRANSFORM transform;
  546. ULONG_PTR dwhContext;
  547. LIST_ROOT(eblist, _D3DHAL_EXDATA) bufferHandles;
  548. // RenderTarget/ZBuf bit depth info used by Clear to Blt
  549. DWORD red_mask;
  550. DWORD red_scale;
  551. DWORD red_shift;
  552. DWORD green_mask;
  553. DWORD green_scale;
  554. DWORD green_shift;
  555. DWORD blue_mask;
  556. DWORD blue_scale;
  557. DWORD blue_shift;
  558. DWORD zmask_shift,stencilmask_shift;
  559. BOOL bDDSTargetIsPalettized; // true if 4 or 8 bit rendertarget
  560. // Picking info.
  561. D3DI_PICKDATA pick_data;
  562. LPBYTE lpbClipIns_base;
  563. DWORD dwClipIns_offset;
  564. // Pipeline state info
  565. D3DFE_STATESET renderstate_overrides;
  566. D3DFE_STATESET transformstate_overrides;
  567. D3DFE_STATESET lightstate_overrides;
  568. int iClipStatus;
  569. DWORD dwDebugFlags; // See debug bits above
  570. #ifndef WIN95
  571. ULONG_PTR hSurfaceTarget;
  572. #else
  573. DWORD hSurfaceTarget;
  574. #endif
  575. #ifdef TRACK_HAL_CALLS
  576. DWORD hal_calls;
  577. #endif
  578. //--------------- Lights start -----------------------
  579. int numLights; // This indicates the maximum number of lights
  580. // that have been set in the device.
  581. LIST_ROOT(name10,_SpecularTable) specular_tables;
  582. SpecularTable* specular_table;
  583. LIST_ROOT(mtllist, _D3DFE_MATERIAL) materials;
  584. LIGHT_VERTEX_FUNC_TABLE *lightVertexFuncTable;
  585. //--------------- Lights end -----------------------
  586. /* Provider backing this driver */
  587. IHalProvider* pHalProv;
  588. HINSTANCE hDllProv;
  589. /*
  590. * Pointers to functions used by DrawPrim&Begin/End
  591. */
  592. PFNDOFLUSHBEGINEND pfnDoFlushBeginEnd;
  593. /* Device description */
  594. D3DDEVICEDESC d3dHWDevDesc;
  595. D3DDEVICEDESC d3dHELDevDesc;
  596. /*
  597. * The special IUnknown interface for the aggregate that does
  598. * not punt to the parent object.
  599. */
  600. LPUNKNOWN lpOwningIUnknown; /* The owning IUnknown */
  601. /*
  602. * Pointer to texture objects for currently installed textures. NULL indicates
  603. * that the texture is either not set (rstate NULL) or that the handle to tex3 pointer
  604. * mapping is not done. This mapping is expensive, so it is deferred until needed.
  605. *
  606. * This is needed for finding the WRAPU,V mode for texture index clipping (since
  607. * the WRAPU,V state is part of the device).
  608. */
  609. LPDIRECT3DTEXTUREI lpD3DMappedTexI[D3DHAL_TSS_MAXSTAGES];
  610. LPD3DI_TEXTUREBLOCK lpD3DMappedBlock[D3DHAL_TSS_MAXSTAGES];
  611. LPDIRECTDRAWCLIPPER lpClipper;
  612. //---------- Begin-End data start --------------
  613. char *lpcCurrentPtr; // Current ptr to place next vertex
  614. CRITICAL_SECTION BeginEndCSect;
  615. // max number of vertices
  616. #define BEGIN_DATA_BLOCK_SIZE 256
  617. // size of internal vertex memory pool
  618. #define BEGIN_DATA_BLOCK_MEM_SIZE BEGIN_DATA_BLOCK_SIZE*__MAX_VERTEX_SIZE
  619. LPVOID lpvVertexBatch;
  620. WORD *lpIndexBatch;
  621. LPVOID lpvVertexData; // if lpvVertexData is non-NULL if we are
  622. // insize Begin-End and indexed.
  623. DWORD dwBENumVertices;
  624. DWORD dwMaxVertexCount; // current number of vertices there is space for
  625. WORD *lpVertexIndices;
  626. DWORD dwBENumIndices;
  627. DWORD dwMaxIndexCount; // current number of indices there is space for
  628. WORD wFlushed;
  629. //---------- Begin-End data end --------------
  630. /*
  631. * DrawPrimitives batching
  632. */
  633. // Buffer to put DrawPrimitives stuff into
  634. // Used for both legacy and DrawPrimitive HALs
  635. struct _D3DBUCKET *lpTextureBatched;
  636. WORD *lpwDPBuffer;
  637. WORD *lpwDPBufferAlloced;
  638. #ifndef WIN95
  639. DWORD dwDPBufferSize;
  640. #endif
  641. DWORD dwCurrentBatchVID; // Current FVF type in the batch buffer
  642. /* Legacy HALs */
  643. // pointer to current prim counts struct
  644. LPD3DHAL_DRAWPRIMCOUNTS lpDPPrimCounts;
  645. // Buffer of counts structures that keep track of the
  646. // number of render states and vertices buffered
  647. LPD3DI_HWCOUNTS lpHWCounts;
  648. // Buffer of triangle structures.
  649. LPD3DTRIANGLE lpHWTris;
  650. // Buffer of interleaved render states and primitives.
  651. LPD3DTLVERTEX lpHWVertices;
  652. // Byte offset into lpHWVertices. This gets incremented
  653. // by 8 when a render state is batched and by 32*dwNumVertices
  654. // when a primitive is batched.
  655. DWORD dwHWOffset;
  656. // Max value of dwHWOffset. Used to decide whether to flush.
  657. DWORD dwHWMaxOffset;
  658. // Index into lpHWTris.
  659. DWORD dwHWTriIndex;
  660. // Number of counts structures used so far. This actually
  661. // gives the number of primitives batched and the index of
  662. // the counts structure to batch render states into.
  663. DWORD dwHWNumCounts;
  664. /* DrawPrimitive-aware HALs */
  665. // Byte offset into buffer (we are currently
  666. // using the device's wTriIndex)
  667. DWORD dwDPOffset;
  668. // Maximum offset. If dwDPOffset exceeds this, it is
  669. // time to flush.
  670. DWORD dwDPMaxOffset;
  671. WORD *wTriIndex;
  672. LPD3DHAL_D3DEXTENDEDCAPS lpD3DExtendedCaps; /* HW specific */
  673. LPDWORD rstates;
  674. // Runtime copy of texture stage states
  675. DWORD tsstates[D3DHAL_TSS_MAXSTAGES][D3DHAL_TSS_STATESPERSTAGE];
  676. DWORD dwMaxTextureBlendStages; // Max number of blend stages supported by a driver
  677. // This is a function provided by ramp rasterizer. It is called to inform
  678. // ramp about any material changes. The function pointer and service types
  679. // are defined in halprov.h
  680. // It should be NULL except for ramp rasterizer.
  681. PFN_RASTRAMPSERVICE pfnRampService;
  682. // This is a function provided by sw rasterizers.
  683. // Currently, its only function is to provide an RGB8 clear color.
  684. // It should be non-NULL for anything that supports an 8 bit RGB output
  685. // type.
  686. PFN_RASTSERVICE pfnRastService;
  687. //
  688. // Begin DP2 HAL section
  689. //
  690. //
  691. // End DP2 HAL section
  692. //
  693. public: // methods
  694. virtual ~DIRECT3DDEVICEI() { }; // Dummy virtual destructor to ensure the real one gets called
  695. HRESULT GetCapsI(LPD3DDEVICEDESC, LPD3DDEVICEDESC);
  696. HRESULT stateInitialize(BOOL bZEnable);
  697. HRESULT checkDeviceSurface(LPDIRECTDRAWSURFACE lpDDS, LPDIRECTDRAWSURFACE lpZbuffer, LPGUID pGuid);
  698. HRESULT hookDeviceToD3D(LPDIRECT3DI lpD3DI);
  699. HRESULT unhookDeviceFromD3D();
  700. void DIRECT3DDEVICEI::DestroyDevice();
  701. virtual HRESULT Init(REFCLSID riid, LPDIRECT3DI lpD3DI, LPDIRECTDRAWSURFACE lpDDS,
  702. IUnknown* pUnkOuter, LPUNKNOWN* lplpD3DDevice, DWORD dwVersion);
  703. HRESULT hookViewportToDevice(LPDIRECT3DVIEWPORTI lpD3DView);
  704. virtual HRESULT DrawPrim()=0; // Use to pass non-indexed primitives to the driver
  705. virtual HRESULT DrawIndexPrim()=0; // Use to pass indexed primitives to driver
  706. virtual HRESULT FlushStates()=0; // Use to flush current batch to the driver
  707. virtual HRESULT ExecuteI(LPD3DI_EXECUTEDATA lpExData, DWORD flags)=0;
  708. virtual HRESULT DrawExeBuf() { return D3D_OK; };
  709. virtual HRESULT ProcessPrimitive(__PROCPRIMOP op = __PROCPRIMOP_NONINDEXEDPRIM);
  710. virtual HRESULT CheckSurfaces(); // Check if the surfaces necessary for rendering are lost
  711. HRESULT PickExeBuf(); // Called by the clipper for execute buffer API
  712. HRESULT UpdateTextures();
  713. // Function to download viewport info to the driver
  714. virtual HRESULT UpdateDrvViewInfo(LPD3DVIEWPORT2 lpVwpData) { return D3D_OK; };
  715. virtual HRESULT UpdateDrvWInfo() { return D3D_OK; };
  716. #if DBG
  717. #define PROF_EXECUTE 0x0000
  718. #define PROF_BEGIN 0x0001
  719. #define PROF_BEGININDEXED 0x0002
  720. #define PROF_DRAWPRIMITIVEDEVICE2 0x0003
  721. #define PROF_DRAWINDEXEDPRIMITIVEDEVICE2 0x0004
  722. #define PROF_DRAWPRIMITIVESTRIDED 0x0005
  723. #define PROF_DRAWINDEXEDPRIMITIVESTRIDED 0x0006
  724. #define PROF_DRAWPRIMITIVEDEVICE3 0x0007
  725. #define PROF_DRAWINDEXEDPRIMITIVEDEVICE3 0x0008
  726. #define PROF_DRAWPRIMITIVEVB 0x0009
  727. #define PROF_DRAWINDEXEDPRIMITIVEVB 0x000a
  728. DWORD dwCaller;
  729. DWORD dwPrimitiveType[PROF_DRAWINDEXEDPRIMITIVEVB+1];
  730. DWORD dwVertexType1[PROF_DRAWINDEXEDPRIMITIVEVB+1];
  731. DWORD dwVertexType2[PROF_DRAWINDEXEDPRIMITIVEVB+1];
  732. void Profile(DWORD, D3DPRIMITIVETYPE, DWORD);
  733. #else
  734. #define Profile(a,b,c)
  735. #endif
  736. public:
  737. // IUnknown Methods
  738. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  739. ULONG D3DAPI AddRef();
  740. ULONG D3DAPI Release();
  741. // IDirect3DDevice Methods
  742. HRESULT D3DAPI Initialize(LPDIRECT3D, LPGUID, LPD3DDEVICEDESC);
  743. HRESULT D3DAPI GetCaps(LPD3DDEVICEDESC, LPD3DDEVICEDESC);
  744. HRESULT D3DAPI SwapTextureHandles(LPDIRECT3DTEXTURE, LPDIRECT3DTEXTURE);
  745. HRESULT D3DAPI CreateExecuteBuffer(LPD3DEXECUTEBUFFERDESC, LPDIRECT3DEXECUTEBUFFER*, IUnknown*);
  746. HRESULT D3DAPI GetStats(LPD3DSTATS);
  747. HRESULT D3DAPI Execute(LPDIRECT3DEXECUTEBUFFER, LPDIRECT3DVIEWPORT, DWORD);
  748. HRESULT D3DAPI AddViewport(LPDIRECT3DVIEWPORT);
  749. HRESULT D3DAPI DeleteViewport(LPDIRECT3DVIEWPORT);
  750. HRESULT D3DAPI NextViewport(LPDIRECT3DVIEWPORT, LPDIRECT3DVIEWPORT*, DWORD);
  751. HRESULT D3DAPI Pick(LPDIRECT3DEXECUTEBUFFER, LPDIRECT3DVIEWPORT, DWORD, LPD3DRECT);
  752. HRESULT D3DAPI GetPickRecords(LPDWORD, LPD3DPICKRECORD);
  753. HRESULT D3DAPI EnumTextureFormats(LPD3DENUMTEXTUREFORMATSCALLBACK, LPVOID);
  754. HRESULT D3DAPI CreateMatrix(LPD3DMATRIXHANDLE);
  755. HRESULT D3DAPI SetMatrix(D3DMATRIXHANDLE, const LPD3DMATRIX);
  756. HRESULT D3DAPI GetMatrix(D3DMATRIXHANDLE, LPD3DMATRIX);
  757. HRESULT D3DAPI DeleteMatrix(D3DMATRIXHANDLE);
  758. HRESULT D3DAPI BeginScene();
  759. HRESULT D3DAPI EndScene();
  760. HRESULT D3DAPI GetDirect3D(LPDIRECT3D*);
  761. // IDirect3DDevice2 Methods
  762. HRESULT D3DAPI SwapTextureHandles(LPDIRECT3DTEXTURE2, LPDIRECT3DTEXTURE2);
  763. HRESULT D3DAPI AddViewport(LPDIRECT3DVIEWPORT2);
  764. HRESULT D3DAPI DeleteViewport(LPDIRECT3DVIEWPORT2);
  765. HRESULT D3DAPI NextViewport(LPDIRECT3DVIEWPORT2, LPDIRECT3DVIEWPORT2*, DWORD);
  766. HRESULT D3DAPI GetDirect3D(LPDIRECT3D2*);
  767. HRESULT D3DAPI SetCurrentViewport(LPDIRECT3DVIEWPORT2);
  768. HRESULT D3DAPI GetCurrentViewport(LPDIRECT3DVIEWPORT2 *);
  769. HRESULT D3DAPI SetRenderTarget(LPDIRECTDRAWSURFACE, DWORD);
  770. HRESULT D3DAPI GetRenderTarget(LPDIRECTDRAWSURFACE *);
  771. HRESULT D3DAPI Begin(D3DPRIMITIVETYPE, D3DVERTEXTYPE, DWORD);
  772. HRESULT D3DAPI BeginIndexed(D3DPRIMITIVETYPE, D3DVERTEXTYPE, LPVOID, DWORD, DWORD);
  773. HRESULT D3DAPI Vertex(LPVOID);
  774. HRESULT D3DAPI Index(WORD);
  775. HRESULT D3DAPI End(DWORD);
  776. HRESULT D3DAPI GetRenderState(D3DRENDERSTATETYPE, LPDWORD);
  777. HRESULT D3DAPI SetRenderState(D3DRENDERSTATETYPE, DWORD);
  778. virtual HRESULT D3DAPI SetRenderStateI(D3DRENDERSTATETYPE, DWORD) = 0;
  779. HRESULT D3DAPI GetLightState(D3DLIGHTSTATETYPE, LPDWORD);
  780. HRESULT D3DAPI SetLightState(D3DLIGHTSTATETYPE, DWORD);
  781. HRESULT D3DAPI SetTransform(D3DTRANSFORMSTATETYPE, LPD3DMATRIX);
  782. HRESULT D3DAPI GetTransform(D3DTRANSFORMSTATETYPE, LPD3DMATRIX);
  783. HRESULT D3DAPI MultiplyTransform(D3DTRANSFORMSTATETYPE, LPD3DMATRIX);
  784. HRESULT D3DAPI DrawPrimitive(D3DPRIMITIVETYPE, D3DVERTEXTYPE, LPVOID, DWORD, DWORD);
  785. HRESULT D3DAPI DrawIndexedPrimitive(D3DPRIMITIVETYPE, D3DVERTEXTYPE, LPVOID, DWORD, LPWORD, DWORD, DWORD);
  786. HRESULT D3DAPI SetClipStatus(LPD3DCLIPSTATUS);
  787. HRESULT D3DAPI GetClipStatus(LPD3DCLIPSTATUS);
  788. // IDirect3DDevice3 Methods
  789. HRESULT D3DAPI AddViewport(LPDIRECT3DVIEWPORT3);
  790. HRESULT D3DAPI DeleteViewport(LPDIRECT3DVIEWPORT3);
  791. HRESULT D3DAPI NextViewport(LPDIRECT3DVIEWPORT3, LPDIRECT3DVIEWPORT3*, DWORD);
  792. HRESULT D3DAPI EnumTextureFormats(LPD3DENUMPIXELFORMATSCALLBACK, LPVOID);
  793. HRESULT D3DAPI GetDirect3D(LPDIRECT3D3*);
  794. HRESULT D3DAPI SetCurrentViewport(LPDIRECT3DVIEWPORT3);
  795. HRESULT D3DAPI GetCurrentViewport(LPDIRECT3DVIEWPORT3 *);
  796. HRESULT D3DAPI SetRenderTarget(LPDIRECTDRAWSURFACE4, DWORD);
  797. HRESULT D3DAPI GetRenderTarget(LPDIRECTDRAWSURFACE4 *);
  798. HRESULT D3DAPI DrawPrimitiveStrided(D3DPRIMITIVETYPE, DWORD, LPD3DDRAWPRIMITIVESTRIDEDDATA, DWORD, DWORD);
  799. HRESULT D3DAPI DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE, DWORD, LPD3DDRAWPRIMITIVESTRIDEDDATA, DWORD, LPWORD, DWORD, DWORD);
  800. HRESULT D3DAPI DrawPrimitive(D3DPRIMITIVETYPE, DWORD, LPVOID, DWORD, DWORD);
  801. HRESULT D3DAPI DrawIndexedPrimitive(D3DPRIMITIVETYPE, DWORD, LPVOID, DWORD, LPWORD, DWORD, DWORD);
  802. HRESULT D3DAPI Begin(D3DPRIMITIVETYPE, DWORD, DWORD);
  803. HRESULT D3DAPI BeginIndexed(D3DPRIMITIVETYPE, DWORD, LPVOID, DWORD, DWORD);
  804. HRESULT D3DAPI DrawPrimitiveVB(D3DPRIMITIVETYPE, LPDIRECT3DVERTEXBUFFER, DWORD, DWORD, DWORD);
  805. HRESULT D3DAPI DrawIndexedPrimitiveVB(D3DPRIMITIVETYPE, LPDIRECT3DVERTEXBUFFER, LPWORD, DWORD, DWORD);
  806. HRESULT D3DAPI ComputeSphereVisibility(LPD3DVECTOR, LPD3DVALUE, DWORD, DWORD, LPDWORD);
  807. HRESULT D3DAPI GetTexture(DWORD, LPDIRECT3DTEXTURE2 *);
  808. HRESULT D3DAPI SetTexture(DWORD, LPDIRECT3DTEXTURE2);
  809. HRESULT D3DAPI GetTextureStageState(DWORD dwStage,
  810. D3DTEXTURESTAGESTATETYPE dwState,
  811. LPDWORD pdwValue);
  812. virtual HRESULT D3DAPI SetTextureStageState(DWORD dwStage,
  813. D3DTEXTURESTAGESTATETYPE dwState,
  814. DWORD dwValue) = 0;
  815. virtual HRESULT D3DAPI ValidateDevice(LPDWORD lpdwNumPasses) = 0;
  816. };
  817. class CDirect3DDeviceIHW : public DIRECT3DDEVICEI
  818. {
  819. private: // Data
  820. /* data members of DIRECT3DDEVICEI that are specific to DX3 Legacy HAL drivers
  821. should go here */
  822. public:
  823. inline CDirect3DDeviceIHW() { deviceType = D3DDEVTYPE_OLDHAL; }
  824. inline ~CDirect3DDeviceIHW() { DestroyDevice(); }; // Called by CDirect3DDeviceUnk::Release()
  825. HRESULT D3DAPI SetRenderStateI(D3DRENDERSTATETYPE, DWORD);
  826. HRESULT DrawPrim();
  827. HRESULT DrawIndexPrim();
  828. HRESULT FlushStates();
  829. HRESULT DrawExeBuf(); // Called by the clipper for execute buffer API
  830. HRESULT ExecuteI(LPD3DI_EXECUTEDATA lpExData, DWORD flags);
  831. HRESULT D3DAPI SetTextureStageState(DWORD dwStage,
  832. D3DTEXTURESTAGESTATETYPE dwState,
  833. DWORD dwValue);
  834. HRESULT D3DAPI ValidateDevice(LPDWORD lpdwNumPasses);
  835. HRESULT MapTSSToRS();
  836. };
  837. class CDirect3DDeviceIDP : public CDirect3DDeviceIHW
  838. {
  839. private: // Data
  840. /* data members of DIRECT3DDEVICEI that are specific to DX5 DrawPrimitive HAL drivers
  841. should go here */
  842. public:
  843. CDirect3DDeviceIDP() { deviceType = D3DDEVTYPE_DPHAL; }
  844. HRESULT D3DAPI SetRenderStateI(D3DRENDERSTATETYPE, DWORD);
  845. HRESULT DrawPrim();
  846. HRESULT DrawIndexPrim();
  847. HRESULT FlushStates();
  848. };
  849. // Flags passed by the runtime to the DDI batching code via PV structure
  850. // to enable new DDI batching to be done efficiently. These flags are
  851. // marked as reserved in d3dfe.hpp
  852. const DWORD D3DPV_WITHINPRIMITIVE = D3DPV_RESERVED1; // This flags that the flush has occured
  853. // within an primitive. This indicates
  854. // that we should not flush the vertex buffer
  855. // If execute buffer is currently processed
  856. const DWORD D3DPV_INSIDEEXECUTE = D3DPV_RESERVED2;
  857. // If the vertices are in user memory
  858. const DWORD D3DPV_USERMEMVERTICES = D3DPV_RESERVED3;
  859. //---------------------------------------------------------------------
  860. class CDirect3DDeviceIDP2 : public DIRECT3DDEVICEI
  861. {
  862. public: // data
  863. static const DWORD dwD3DDefaultVertexBatchSize;
  864. static const DWORD dwD3DDefaultCommandBatchSize;
  865. // The buffer we currently batch into
  866. LPDIRECTDRAWSURFACE4 lpDDSCB1;
  867. // Pointer to the actual data in CB1
  868. LPVOID lpvDP2Commands;
  869. //Pointer to the current position the CB1 buffer
  870. LPD3DHAL_DP2COMMAND lpDP2CurrCommand;
  871. D3DHAL_DRAWPRIMITIVES2DATA dp2data;
  872. DWORD dwDP2CommandLength;
  873. DWORD dwDP2CommandBufSize;
  874. BYTE bDP2CurrCmdOP; // Mirror of Opcode of the current command
  875. WORD wDP2CurrCmdCnt; // Mirror of Count field if the current command
  876. // Flags specific to DP2 device
  877. DWORD dwDP2Flags;
  878. private: // methods
  879. inline void CDirect3DDeviceIDP2::ClearBatch();
  880. HRESULT Init(REFCLSID riid, LPDIRECT3DI lpD3DI, LPDIRECTDRAWSURFACE lpDDS,
  881. IUnknown* pUnkOuter, LPUNKNOWN* lplpD3DDevice, DWORD dwVersion);
  882. HRESULT GrowCommandBuffer(LPDIRECT3DI lpD3DI, DWORD dwSize);
  883. public:
  884. CDirect3DDeviceIDP2() { deviceType = D3DDEVTYPE_DP2HAL; }
  885. ~CDirect3DDeviceIDP2(); // Called by CDirect3DDeviceUnk::Release()
  886. HRESULT FlushStates();
  887. HRESULT FlushStates(DWORD dwReqSize);
  888. HRESULT D3DAPI SetRenderStateI(D3DRENDERSTATETYPE, DWORD);
  889. HRESULT DrawPrim();
  890. HRESULT DrawIndexPrim();
  891. HRESULT ExecuteI(LPD3DI_EXECUTEDATA lpExData, DWORD flags);
  892. HRESULT D3DAPI SetTextureStageState(DWORD dwStage,
  893. D3DTEXTURESTAGESTATETYPE dwState,
  894. DWORD dwValue);
  895. HRESULT D3DAPI ValidateDevice(LPDWORD lpdwNumPasses);
  896. HRESULT SetTSSI(DWORD, D3DTEXTURESTAGESTATETYPE, DWORD);
  897. // Called from DrawPrimitiveVB if a vertex buffer or TL buffer is used for rendering
  898. HRESULT StartPrimVB(LPDIRECT3DVERTEXBUFFERI vb, DWORD dwStartVertex);
  899. // Called if user memory buffer is used for rendering
  900. HRESULT StartPrimUserMem(LPVOID memory);
  901. // Called if TL buffer of used memory was used for rendering
  902. HRESULT EndPrim(DWORD dwVertexPoolSize);
  903. HRESULT CheckSurfaces();
  904. // This is the VB interface corresponding to the dp2data.lpDDVertex
  905. // This is kept so that the VB can be released when done
  906. // which cannot be done from just the LCL pointer which is lpDDVertex
  907. CDirect3DVertexBuffer* lpDP2CurrBatchVBI;
  908. HRESULT UpdateDrvViewInfo(LPD3DVIEWPORT2 lpVwpData);
  909. HRESULT UpdateDrvWInfo();
  910. HRESULT UpdatePalette(DWORD,DWORD,DWORD,LPPALETTEENTRY);
  911. HRESULT SetPalette(DWORD,DWORD,DWORD);
  912. void SetRenderTargetI(LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE);
  913. void ClearI(DWORD, DWORD, LPD3DRECT, D3DCOLOR, D3DVALUE, DWORD);
  914. };
  915. // macros to characterize device
  916. #define IS_DP2HAL_DEVICE(lpDevI) ((lpDevI)->deviceType >= D3DDEVTYPE_DP2HAL)
  917. #define IS_DX7HAL_DEVICE(lpDevI) ((lpDevI)->deviceType >= D3DDEVTYPE_DX7HAL)
  918. #define IS_DX5_COMPATIBLE_DEVICE(lpDevI) ((lpDevI)->dwVersion >= 2)
  919. #define IS_PRE_DX5_DEVICE(lpDevI) ((lpDevI)->dwVersion < 2)
  920. #define IS_MT_DEVICE(lpDevI) ( (lpDevI)->dwHintFlags & D3DDEVBOOL_HINTFLAGS_MULTITHREADED )
  921. #define IS_HW_DEVICE(lpDevI) ((lpDevI)->dwFEFlags & D3DFE_REALHAL)
  922. /*
  923. * Internal version of Direct3DExecuteBuffer object;
  924. * it has data after the vtable
  925. */
  926. class DIRECT3DEXECUTEBUFFERI : public IDirect3DExecuteBuffer,
  927. public CD3DAlloc
  928. {
  929. public:
  930. int refCnt; /* Reference count */
  931. /*** Object Relations ***/
  932. LPDIRECT3DDEVICEI lpDevI; /* Parent */
  933. LIST_MEMBER(DIRECT3DEXECUTEBUFFERI)list;
  934. /* Next buffer in IDirect3D */
  935. /*** Object Data ***/
  936. DWORD pid; /* Process locking execute buffer */
  937. D3DEXECUTEBUFFERDESC debDesc;
  938. /* Description of the buffer */
  939. D3DEXECUTEDATA exData; /* Execute Data */
  940. bool locked; /* Is the buffer locked */
  941. D3DI_BUFFERHANDLE hBuf; /* Execute buffer handle */
  942. public:
  943. DIRECT3DEXECUTEBUFFERI();
  944. ~DIRECT3DEXECUTEBUFFERI();
  945. // IUnknown Methods
  946. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  947. ULONG D3DAPI AddRef();
  948. ULONG D3DAPI Release();
  949. // IDirect3DExecuteBuffer Methods
  950. HRESULT D3DAPI Initialize(LPDIRECT3DDEVICE, LPD3DEXECUTEBUFFERDESC);
  951. HRESULT D3DAPI Lock(LPD3DEXECUTEBUFFERDESC);
  952. HRESULT D3DAPI Unlock();
  953. HRESULT D3DAPI SetExecuteData(LPD3DEXECUTEDATA);
  954. HRESULT D3DAPI GetExecuteData(LPD3DEXECUTEDATA);
  955. HRESULT D3DAPI Validate(LPDWORD, LPD3DVALIDATECALLBACK, LPVOID, DWORD);
  956. HRESULT D3DAPI Optimize(DWORD);
  957. };
  958. /*
  959. * Internal version of Direct3DLight object;
  960. * it has data after the vtable
  961. */
  962. class DIRECT3DLIGHTI : public IDirect3DLight,
  963. public CD3DAlloc
  964. {
  965. public:
  966. int refCnt; /* Reference count */
  967. /*** Object Relations ***/
  968. LPDIRECT3DI lpDirect3DI; /* Parent */
  969. LIST_MEMBER(DIRECT3DLIGHTI)list;
  970. /* Next light in IDirect3D */
  971. LPDIRECT3DVIEWPORTI lpD3DViewportI; /* Guardian */
  972. CIRCLE_QUEUE_MEMBER(DIRECT3DLIGHTI)light_list;
  973. /* Next light in IDirect3DViewport */
  974. /*** Object Data ***/
  975. D3DLIGHT2 dlLight; // Data describing light
  976. D3DI_LIGHT diLightData; // Internal representation of light
  977. public:
  978. DIRECT3DLIGHTI();
  979. ~DIRECT3DLIGHTI();
  980. public:
  981. // IUnknown Methods
  982. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  983. ULONG D3DAPI AddRef();
  984. ULONG D3DAPI Release();
  985. // IDirect3DLight Methods
  986. HRESULT D3DAPI Initialize(LPDIRECT3D);
  987. HRESULT D3DAPI SetLight(LPD3DLIGHT);
  988. HRESULT D3DAPI GetLight(LPD3DLIGHT);
  989. };
  990. /*
  991. * Internal version of Direct3DMaterial object;
  992. * it has data after the vtable
  993. */
  994. class DIRECT3DMATERIALI : public IDirect3DMaterial,
  995. public IDirect3DMaterial2,
  996. public IDirect3DMaterial3,
  997. public CD3DAlloc
  998. {
  999. public:
  1000. int refCnt; /* Reference count */
  1001. /*** Object Relations ***/
  1002. LPDIRECT3DI lpDirect3DI; /* Parent */
  1003. LIST_MEMBER(DIRECT3DMATERIALI)list;
  1004. /* Next MATERIAL in IDirect3D */
  1005. LIST_ROOT(_mblocks, _D3DI_MATERIALBLOCK)blocks;
  1006. /* devices we're associated with */
  1007. /*** Object Data ***/
  1008. D3DMATERIAL dmMaterial; /* Data describing material */
  1009. bool bRes; /* Is this material reserved in the driver */
  1010. public:
  1011. DIRECT3DMATERIALI();
  1012. ~DIRECT3DMATERIALI();
  1013. public:
  1014. // IUnknown Methods
  1015. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  1016. ULONG D3DAPI AddRef();
  1017. ULONG D3DAPI Release();
  1018. // IDirect3DMaterial Methods
  1019. HRESULT D3DAPI Initialize(LPDIRECT3D);
  1020. HRESULT D3DAPI SetMaterial(LPD3DMATERIAL);
  1021. HRESULT D3DAPI GetMaterial(LPD3DMATERIAL);
  1022. HRESULT D3DAPI GetHandle(LPDIRECT3DDEVICE, LPD3DMATERIALHANDLE);
  1023. HRESULT D3DAPI Reserve();
  1024. HRESULT D3DAPI Unreserve();
  1025. // IDirect3DMaterial2 Methods
  1026. HRESULT D3DAPI GetHandle(LPDIRECT3DDEVICE2, LPD3DMATERIALHANDLE);
  1027. // IDirect3DMaterial3 Methods
  1028. HRESULT D3DAPI GetHandle(LPDIRECT3DDEVICE3, LPD3DMATERIALHANDLE);
  1029. };
  1030. /*
  1031. * If we have an aggreate Direct3DTexture we need a structure
  1032. * to represent an unknown interface distinct from the underlying
  1033. * object. This is that structure.
  1034. */
  1035. class CDirect3DTextureUnk : public IUnknown
  1036. {
  1037. public:
  1038. /* Reference count object */
  1039. unsigned refCnt;
  1040. public:
  1041. LPDIRECT3DTEXTUREI pTexI;
  1042. public:
  1043. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  1044. ULONG D3DAPI AddRef();
  1045. ULONG D3DAPI Release();
  1046. };
  1047. /*
  1048. * Internal version of Direct3DTexture object; it has data after the vtable
  1049. */
  1050. class DIRECT3DTEXTUREI : public IDirect3DTexture,
  1051. public IDirect3DTexture2,
  1052. public CD3DAlloc
  1053. {
  1054. public:
  1055. /*** Object Relations ***/
  1056. LIST_ROOT(_blocks, _D3DI_TEXTUREBLOCK) blocks;
  1057. /* Devices we're associated with */
  1058. /*** Object Data ***/
  1059. CDirect3DTextureUnk mTexUnk;
  1060. DDRAWI_DDRAWSURFACE_INT DDSInt4;
  1061. LPDIRECTDRAWSURFACE lpDDS1Tex; //we need to keep the legacy
  1062. LPDIRECTDRAWSURFACE4 lpDDS;
  1063. LPDIRECTDRAWSURFACE lpDDSSys1Tex; //we need to keep the legacy
  1064. LPDIRECTDRAWSURFACE4 lpDDSSys;
  1065. struct _D3DBUCKET *lpTMBucket;
  1066. DDSURFACEDESC2 ddsd;
  1067. int LogTexSize;
  1068. /*
  1069. * The special IUnknown interface for the aggregate that does
  1070. * not punt to the parent object.
  1071. */
  1072. LPUNKNOWN lpOwningIUnknown; /* The owning IUnknown */
  1073. bool bIsPalettized;
  1074. bool bInUse;
  1075. BOOL bDirty;
  1076. public:
  1077. DIRECT3DTEXTUREI(LPUNKNOWN);
  1078. ~DIRECT3DTEXTUREI();
  1079. // IUnknown Methods
  1080. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  1081. ULONG D3DAPI AddRef();
  1082. ULONG D3DAPI Release();
  1083. // IDirect3DTexture Methods
  1084. HRESULT D3DAPI Initialize(LPDIRECT3DDEVICE, LPDIRECTDRAWSURFACE);
  1085. HRESULT D3DAPI GetHandle(LPDIRECT3DDEVICE, LPD3DTEXTUREHANDLE);
  1086. HRESULT D3DAPI PaletteChanged(DWORD, DWORD);
  1087. HRESULT D3DAPI Load(LPDIRECT3DTEXTURE);
  1088. HRESULT D3DAPI Unload();
  1089. // IDirect3DTexture2 Methods
  1090. HRESULT D3DAPI GetHandle(LPDIRECT3DDEVICE2, LPD3DTEXTUREHANDLE);
  1091. HRESULT D3DAPI Load(LPDIRECT3DTEXTURE2);
  1092. };
  1093. /*
  1094. * Internal version of Direct3DViewport object; it has data after the vtable
  1095. */
  1096. class DIRECT3DVIEWPORTI : public IDirect3DViewport3,
  1097. public CD3DAlloc
  1098. {
  1099. public:
  1100. int refCnt; /* Reference count */
  1101. /*** Object Relations */
  1102. LPDIRECT3DI lpDirect3DI; /* Parent */
  1103. LIST_MEMBER(DIRECT3DVIEWPORTI)list;
  1104. /* Next viewport in IDirect3D */
  1105. LPDIRECT3DDEVICEI lpDevI; /* Guardian */
  1106. CIRCLE_QUEUE_MEMBER(DIRECT3DVIEWPORTI) vw_list;
  1107. /* Next viewport in IDirect3DDevice */
  1108. /* Lights */
  1109. int numLights;
  1110. CIRCLE_QUEUE_ROOT(_dlights, DIRECT3DLIGHTI) lights;
  1111. /* Associated IDirect3DLights */
  1112. /*** Object Data ***/
  1113. unsigned long v_id; /* Id for this viewport */
  1114. D3DVIEWPORT2 v_data;
  1115. BOOL v_data_is_set;
  1116. // Background Material
  1117. BOOL bHaveBackgndMat;
  1118. D3DMATERIALHANDLE hBackgndMat;
  1119. // Background Depth Surface
  1120. LPDIRECTDRAWSURFACE lpDDSBackgndDepth;
  1121. // need to save this version of interface for DX6 GetBackgroundDepth
  1122. LPDIRECTDRAWSURFACE4 lpDDSBackgndDepth_DDS4;
  1123. /* Have the lights changed since they
  1124. were last collected? */
  1125. BOOL bLightsChanged;
  1126. DWORD clrCount; /* Number of rects allocated */
  1127. LPD3DRECT clrRects; /* Rects used for clearing */
  1128. public:
  1129. DIRECT3DVIEWPORTI(LPDIRECT3DI lpD3DI);
  1130. ~DIRECT3DVIEWPORTI();
  1131. public:
  1132. // IUnknown Methods
  1133. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  1134. ULONG D3DAPI AddRef();
  1135. ULONG D3DAPI Release();
  1136. // IDirect3DViewport Methods
  1137. HRESULT D3DAPI Initialize(LPDIRECT3D);
  1138. HRESULT D3DAPI GetViewport(LPD3DVIEWPORT);
  1139. HRESULT D3DAPI SetViewport(LPD3DVIEWPORT);
  1140. HRESULT D3DAPI TransformVertices(DWORD, LPD3DTRANSFORMDATA, DWORD, LPDWORD);
  1141. HRESULT D3DAPI LightElements(DWORD, LPD3DLIGHTDATA);
  1142. HRESULT D3DAPI SetBackground(D3DMATERIALHANDLE);
  1143. HRESULT D3DAPI GetBackground(LPD3DMATERIALHANDLE, LPBOOL);
  1144. HRESULT D3DAPI SetBackgroundDepth(LPDIRECTDRAWSURFACE);
  1145. HRESULT D3DAPI GetBackgroundDepth(LPDIRECTDRAWSURFACE*, LPBOOL);
  1146. HRESULT D3DAPI SetBackgroundDepth2(LPDIRECTDRAWSURFACE4);
  1147. HRESULT D3DAPI GetBackgroundDepth2(LPDIRECTDRAWSURFACE4*, LPBOOL);
  1148. HRESULT D3DAPI Clear(DWORD, LPD3DRECT, DWORD);
  1149. HRESULT D3DAPI AddLight(LPDIRECT3DLIGHT);
  1150. HRESULT D3DAPI DeleteLight(LPDIRECT3DLIGHT);
  1151. HRESULT D3DAPI NextLight(LPDIRECT3DLIGHT, LPDIRECT3DLIGHT*, DWORD);
  1152. // IDirect3DViewport2 Methods
  1153. HRESULT D3DAPI GetViewport2(LPD3DVIEWPORT2);
  1154. HRESULT D3DAPI SetViewport2(LPD3DVIEWPORT2);
  1155. // IDirect3DViewport3 Methods
  1156. HRESULT D3DAPI Clear2(DWORD, LPD3DRECT, DWORD, D3DCOLOR, D3DVALUE, DWORD);
  1157. };
  1158. // Internal VB create flag:
  1159. #define D3DVBFLAGS_CREATEMULTIBUFFER 0x80000000L
  1160. class CDirect3DVertexBuffer : public IDirect3DVertexBuffer,
  1161. public CD3DAlloc
  1162. {
  1163. private:
  1164. HRESULT CreateMemoryBuffer(LPDIRECT3DI lpD3DI,
  1165. LPDIRECTDRAWSURFACE4 *lplpSurface4,
  1166. LPDIRECTDRAWSURFACE *lplpS,
  1167. LPVOID *lplpMemory,
  1168. DWORD dwBufferSize,
  1169. DWORD dwFlags);
  1170. int refCnt; /* Reference count */
  1171. /*** Object Relations */
  1172. LPDIRECT3DI lpDirect3DI; /* Parent */
  1173. LIST_MEMBER(CDirect3DVertexBuffer)list; /* Next vertex buffer in IDirect3D */
  1174. // Internal data
  1175. DWORD dwCaps;
  1176. DWORD dwNumVertices;
  1177. DWORD dwLockCnt;
  1178. DWORD dwMemType;
  1179. DWORD srcVOP, dstVOP;
  1180. D3DVERTEXTYPE legacyVertexType;
  1181. DWORD dwPVFlags;
  1182. DWORD nTexCoord;
  1183. /* position.lpData = start of vertex buffer data
  1184. * position.dwStride = Number of bytes per vertex
  1185. */
  1186. union {
  1187. D3DDP_PTRSTRIDE position;
  1188. D3DDP_PTRSTRIDE SOA;
  1189. };
  1190. DWORD fvf; // Used in Input and Output
  1191. D3DFE_CLIPCODE* clipCodes;
  1192. LPDIRECTDRAWSURFACE4 lpDDSVB; // DDraw Surface containing the actual VB memory
  1193. LPDIRECTDRAWSURFACE lpDDS1VB; // same dds, legacy interface for legacy hal.
  1194. BOOL bReallyOptimized; // VB could have OPTIMIZED caps set, but be
  1195. // not optimized
  1196. LPDIRECT3DDEVICEI lpDevIBatched; // Is this VB batched in a device ? If so we need to flush the device
  1197. // on Lock
  1198. // Friends
  1199. friend void hookVertexBufferToD3D(LPDIRECT3DI, LPDIRECT3DVERTEXBUFFERI);
  1200. friend class DIRECT3DDEVICEI;
  1201. public:
  1202. CDirect3DVertexBuffer(LPDIRECT3DI);
  1203. ~CDirect3DVertexBuffer();
  1204. HRESULT Init(LPDIRECT3DI, LPD3DVERTEXBUFFERDESC, DWORD);
  1205. LPDIRECTDRAWSURFACE GetDDS() { return lpDDS1VB; }
  1206. HRESULT Restore() { return lpDDSVB->Restore(); }
  1207. // IUnknown Methods
  1208. HRESULT D3DAPI QueryInterface(REFIID riid, LPVOID* ppvObj);
  1209. ULONG D3DAPI AddRef();
  1210. ULONG D3DAPI Release();
  1211. // IDirect3DVertexBuffer Methods
  1212. HRESULT D3DAPI Lock(DWORD, LPVOID*, LPDWORD);
  1213. HRESULT D3DAPI Unlock();
  1214. HRESULT D3DAPI ProcessVertices(DWORD, DWORD, DWORD, LPDIRECT3DVERTEXBUFFER, DWORD, LPDIRECT3DDEVICE3, DWORD);
  1215. HRESULT D3DAPI GetVertexBufferDesc(LPD3DVERTEXBUFFERDESC);
  1216. HRESULT D3DAPI Optimize(LPDIRECT3DDEVICE3 lpDevI, DWORD dwFlags);
  1217. protected:
  1218. // Internal Lock
  1219. HRESULT D3DAPI LockI(DWORD, LPVOID*, LPDWORD);
  1220. };
  1221. // Now that LPDIRECT3DVERTEXBUFFERI is defined...
  1222. inline CDirect3DVertexBuffer* CBufferVB::GetVBI()
  1223. {
  1224. return static_cast<CDirect3DVertexBuffer*>(allocatedBuf);
  1225. }
  1226. inline LPDIRECTDRAWSURFACE CBufferVB::GetDDS()
  1227. {
  1228. return GetVBI()->GetDDS();
  1229. }
  1230. // The instance of the class providing a guaranteed implementation
  1231. // This is defined / instantiated in pipeln\helxfrm.cpp
  1232. extern D3DFE_PVFUNCS GeometryFuncsGuaranteed;
  1233. extern void
  1234. D3DDeviceDescConvert(LPD3DDEVICEDESC lpOut,
  1235. LPD3DDEVICEDESC_V1 lpV1,
  1236. LPD3DHAL_D3DEXTENDEDCAPS lpExt);
  1237. #endif
  1238. // @@END_MSINTERNAL
  1239. #endif /* _D3DI_H */