]> icculus.org git repositories - taylor/freespace2.git/blob - include/vd3di.h
Initial revision
[taylor/freespace2.git] / include / vd3di.h
1 /*==========================================================================;
2  *
3  *  Copyright (C) 1995-1997 Microsoft Corporation.  All Rights Reserved.
4  *
5  *  File:       d3di.h
6  *  Content:    Direct3D internal include file
7  *@@BEGIN_MSINTERNAL
8  * 
9  *  $Id$
10  *
11  *  History:
12  *   Date       By      Reason
13  *   ====       ==      ======
14  *   05/11/95   stevela Initial rev with this header.
15  *   11/11/95   stevela Light code changed.
16  *   21/11/95   colinmc Made Direct3D aggregatable
17  *                      (so it can be QI'd off DirectDraw).
18  *   23/11/95   colinmc Made Direct3D textures and devices aggregatable
19  *                      (QI'd off DirectDrawSurfaces).
20  *   07/12/95   stevela Merged in Colin's changes.
21  *   10/12/95   stevela Removed AGGREGATE_D3D.
22  *                      Removed Validate macros from here. Now in d3dpr.h
23  *   02/03/96   colinmc Minor build fix
24  *   17/04/96   stevela Use ddraw.h externally and ddrawp.h internally
25  *@@END_MSINTERNAL
26  *
27  ***************************************************************************/
28
29 #ifndef _D3DI_H
30 #define _D3DI_H
31
32 //@@BEGIN_MSINTERNAL
33 #include "vddrawp.h"
34 #if 0
35 //@@END_MSINTERNAL
36 #include "vddraw.h"
37 //@@BEGIN_MSINTERNAL
38 #endif
39 //@@END_MSINTERNAL
40 #include "vd3d.h"
41
42 // @@BEGIN_MSINTERNAL
43 #if !defined(BUILD_RLAPI) && !defined(BUILD_DDDDK)
44 #include "vddrawi.h"
45
46 #include "rlreg.h"
47 #include "lists.h"
48 #include "object.h"
49
50
51 /*
52         INDEX_BATCH_SCALE is the constant which is used by DrawIndexedPrim
53         to deterimine if the number of primitives being drawn is small 
54         relative to the number of vertices being passed.  If it is then
55         the prims are dereferenced in batches and sent to DrawPrim.
56 */
57 #define INDEX_BATCH_SCALE       2
58
59 /*
60 typedef D3DCOLORMODEL D3DCOLORMODEL;
61
62 #define D3DCOLOR_RAMP D3DCOLOR_RAMP
63 #define D3DCOLOR_RGB D3DCOLOR_RGB
64 #define D3D_COLORMODEL D3D_COLORMODEL
65 */
66 #endif /* !BUILD_RLAPI */
67 // @@END_MSINTERNAL
68
69 typedef DWORD D3DI_BUFFERHANDLE, *LPD3DI_BUFFERHANDLE;
70
71 /*
72  * Internal version of executedata
73  */
74 typedef struct _D3DI_ExecuteData {
75     DWORD       dwSize;
76     D3DI_BUFFERHANDLE dwHandle;         /* Handle allocated by driver */
77     DWORD       dwVertexOffset;
78     DWORD       dwVertexCount;
79     DWORD       dwInstructionOffset;
80     DWORD       dwInstructionLength;
81     DWORD       dwHVertexOffset;
82     D3DSTATUS   dsStatus;               /* Status after execute */
83 } D3DI_EXECUTEDATA, *LPD3DI_EXECUTEDATA;
84
85 /*
86  * Internal version of lightdata and constants for flags
87  */
88
89 #define D3DLIGHTI_ATT0_IS_NONZERO       (0x00010000)    
90 #define D3DLIGHTI_ATT1_IS_NONZERO       (0x00020000)
91 #define D3DLIGHTI_ATT2_IS_NONZERO       (0x00040000)
92 #define D3DLIGHTI_LINEAR_FALLOFF        (0x00080000)
93 #define D3DLIGHTI_UNIT_SCALE            (0x00100000)
94 #define D3DLIGHTI_LIGHT_AT_EYE          (0x00200000)
95
96 typedef struct _D3DI_LIGHT {
97     D3DLIGHTTYPE        type;
98         DWORD                   version;        /* matches number on D3DLIGHT struct */
99     BOOL                        valid;
100     D3DVALUE            red, green, blue, shade;
101     D3DVECTOR           position;
102     D3DVECTOR           model_position;
103     D3DVECTOR           direction;
104     D3DVECTOR           model_direction;
105     D3DVECTOR           halfway;
106         D3DVECTOR               model_eye;              /* direction from eye in model space */
107         D3DVECTOR               model_scale;    /* model scale for proper range computations */
108     D3DVALUE            range;
109     D3DVALUE            range_squared;
110     D3DVALUE            falloff;
111     D3DVALUE            attenuation0;
112     D3DVALUE            attenuation1;
113     D3DVALUE            attenuation2;
114     D3DVALUE            cos_theta_by_2;
115     D3DVALUE            cos_phi_by_2;
116         DWORD                   flags;
117 } D3DI_LIGHT, *LPD3DI_LIGHT;
118
119 // @@BEGIN_MSINTERNAL
120 #if !defined(BUILD_RLAPI) && !defined(BUILD_DDDDK)
121 #ifndef BUILD_HEL
122 #ifdef BUILD_D3D_LAYER
123 #include "driver.h"
124 #endif
125
126 typedef struct IUnknownVtbl D3DUNKNOWNCALLBACKS, *LPD3DUNKNOWNCALLBACKS;
127 typedef struct ID3DObjectVtbl D3DOBJECTVTBL, *LPD3DOBJECTVTBL;
128 typedef struct IDirect3DVtbl DIRECT3DCALLBACKS, *LPDIRECT3DCALLBACKS;
129 typedef struct IDirect3D2Vtbl DIRECT3D2CALLBACKS, *LPDIRECT3D2CALLBACKS;
130 typedef struct IDirect3DDeviceVtbl DIRECT3DDEVICECALLBACKS, *LPDIRECT3DDEVICECALLBACKS;
131 typedef struct IDirect3DDevice2Vtbl DIRECT3DDEVICE2CALLBACKS, *LPDIRECT3DDEVICE2CALLBACKS;
132 typedef struct IDirect3DExecuteBufferVtbl DIRECT3DEXECUTEBUFFERCALLBACKS, *LPDIRECT3DEXECUTEBUFFERCALLBACKS;
133 typedef struct IDirect3DLightVtbl DIRECT3DLIGHTCALLBACKS, *LPDIRECT3DLIGHTCALLBACKS;
134 typedef struct IDirect3DMaterialVtbl DIRECT3DMATERIALCALLBACKS, *LPDIRECT3DMATERIALCALLBACKS;
135 typedef struct IDirect3DMaterial2Vtbl DIRECT3DMATERIAL2CALLBACKS, *LPDIRECT3DMATERIAL2CALLBACKS;
136 typedef struct IDirect3DTextureVtbl DIRECT3DTEXTURECALLBACKS, *LPDIRECT3DTEXTURECALLBACKS;
137 typedef struct IDirect3DTexture2Vtbl DIRECT3DTEXTURE2CALLBACKS, *LPDIRECT3DTEXTURE2CALLBACKS;
138 typedef struct IDirect3DViewport2Vtbl DIRECT3DVIEWPORT2CALLBACKS, *LPDIRECT3DVIEWPORT2CALLBACKS;
139
140 #ifdef __cplusplus
141 extern "C" {
142 #endif
143
144 typedef struct _DIRECT3DI *LPDIRECT3DI;
145 typedef struct _DIRECT3DDEVICEI *LPDIRECT3DDEVICEI;
146 typedef struct _DIRECT3DEXECUTEBUFFERI *LPDIRECT3DEXECUTEBUFFERI;
147 typedef struct _DIRECT3DLIGHTI *LPDIRECT3DLIGHTI;
148 typedef struct _DIRECT3DMATERIALI *LPDIRECT3DMATERIALI;
149 typedef struct _DIRECT3DTEXTUREI *LPDIRECT3DTEXTUREI;
150 typedef struct _DIRECT3DVIEWPORTI *LPDIRECT3DVIEWPORTI;
151
152 /*
153  * If we have an aggregate Direct3D we need a structure to
154  * represent an interface distinct from the underlying
155  * object. This is that structure. None of this would be necessary
156  * in C++
157  */
158 typedef struct _DIRECT3DUNKNOWNI
159 {
160     LPD3DUNKNOWNCALLBACKS       lpVtbl;
161     LPDIRECT3DI                lpObj;
162 } DIRECT3DUNKNOWNI;
163 typedef struct _DIRECT3DUNKNOWNI *LPDIRECT3DUNKNOWNI;
164
165 typedef struct _DIRECT3DOLDI
166 {
167         LPDIRECT3DCALLBACKS lpVtbl;
168         LPDIRECT3DI lpObj;
169 } DIRECT3DOLDI;
170 typedef struct _DIRECT3DOLDI *LPDIRECT3DOLDI;
171
172 /*
173  * Internal version of Direct3D object; it has data after the vtable
174  */
175 typedef struct _DIRECT3DI
176 {
177     /*** Object Interface ***/
178     LPDIRECT3D2CALLBACKS        lpVtbl; /* Pointer to callbacks */
179     int                         refCnt; /* Reference count object */
180
181     /*** Object Relations ***/
182     /* Devices */
183     int                         numDevs;/* Number of devices */
184     LIST_ROOT(_devices, _DIRECT3DDEVICEI) devices;
185                                         /* Associated IDirect3DDevices */
186
187     /* Viewports */
188     int                         numViewports; /* Number of viewports */
189     LIST_ROOT(_viewports, _DIRECT3DVIEWPORTI) viewports;
190                                         /* Created IDirect3DViewports */
191                                         
192     /* Lights */
193     int                         numLights; /* Number of lights */
194     LIST_ROOT(_lights, _DIRECT3DLIGHTI) lights;
195                                         /* Created IDirect3DLights */
196
197     /* Materials */
198     int                         numMaterials; /* Number of materials */
199     LIST_ROOT(_materials, _DIRECT3DMATERIALI) materials;
200                                         /* Created IDirect3DMaterials */
201
202     /*** Object Data ***/
203     unsigned long               v_next; /* id of next viewport to be created */
204     RLDDIRegistry*              lpReg;  /* Registry */
205
206     /*
207      * DirectDraw Interface
208      */
209     LPDDRAWI_DIRECTDRAW_INT     lpDDInt;
210
211     /*
212      * The special IUnknown interface for the aggregate that does
213      * not punt to the parent object.
214      */
215     LPUNKNOWN                   lpOwningIUnknown; /* The owning IUnknown    */
216     DIRECT3DUNKNOWNI            lpThisIUnknown;   /* Our IUnknown interface */
217         DIRECT3DOLDI                            lpThisIDirect3D;   /* Our IDirect3D interface */
218
219     DWORD                       dwVersion;      /* 1 for legacy D3D, 2 for D3D2 */
220 } DIRECT3DI;
221
222 /*
223  * If we have an aggreate Direct3DDevice we need a structure to
224  * represent an interface distinct from the underlying
225  * object. This is that structure. 
226  */
227 typedef struct _DIRECT3DDEVICEUNKNOWNI
228 {
229     LPDIRECT3DDEVICE2CALLBACKS   lpVtbl;
230     LPDIRECT3DDEVICEI           lpObj;
231 } DIRECT3DDEVICEUNKNOWNI;
232 typedef struct _DIRECT3DDEVICEUNKNOWNI *LPDIRECT3DDEVICEUNKNOWNI;
233
234 typedef struct _DIRECT3DDEVICEOLDI
235 {
236     LPDIRECT3DDEVICECALLBACKS   lpVtbl;
237     LPDIRECT3DDEVICEI           lpObj;
238 } DIRECT3DDEVICEOLDI;
239 typedef struct _DIRECT3DDEVICEOLDI *LPDIRECT3DDEVICEOLDI;
240
241 /*
242  * Internal version of Direct3DDevice object; it has data after the vtable
243  */
244
245 #include "vd3dhal.h"
246
247 typedef RLDDIDriver*  (*RLDDIDDrawCreateDriverFn)(
248                                         LPDDRAWI_DIRECTDRAW_INT lpDDInt,
249                                         LPDIRECTDRAWSURFACE lpDDS,
250                                         LPDIRECTDRAWSURFACE lpZ,
251                                         LPDIRECTDRAWPALETTE lpPal,
252                                         LPDIRECT3DDEVICEI);
253
254 typedef HRESULT (*RLDDIGetCapsFn)(LPD3DDEVICEDESC*, LPD3DDEVICEDESC*);
255 typedef void (*RLDDIInitFn)(RLDDIMallocFn, RLDDIReallocFn, RLDDIFreeFn, RLDDIRaiseFn, RLDDIValue**, int, int);
256 typedef void (*RLDDIPushDriverFn)(RLDDIDriverStack*, RLDDIDriver*);
257 typedef void (*RLDDIPopDriverFn)(RLDDIDriverStack*);
258
259 struct _RLDDIGenRasDriver;
260 typedef struct _RLDDIGenRasDriver* LPRLDDIGENRASDRIVER;
261 struct _RLDDIDDrawDriver;
262 typedef struct _RLDDIDDrawDriver* LPRLDDIDDRAWDRIVER;
263
264 struct _RLDDITransformDriver;
265 typedef struct _RLDDITransformDriver* LPRLDDITRANSFORMDRIVER;
266
267 typedef HRESULT (*PFNLOCKTEXTURE)(LPRLDDIGENRASDRIVER driver);
268 typedef void (*PFNUNLOCKTEXTURE)(LPRLDDIGENRASDRIVER driver);
269 typedef int (*PFNSETFILLPARAMS)(LPRLDDIGENRASDRIVER driver, D3DSTATE* in_params,
270                           int count);
271 typedef HRESULT (*PFNREALLOCALIGNED)(void** p_inout, size_t size);
272 typedef HRESULT (*PFNMALLOCALIGNED)(void** p_inout, size_t size);
273 typedef HRESULT (*PFNFREEALIGNED)(void* p_inout);
274 typedef HRESULT (*PFNDRVSETRENDERTARGET)(LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE, 
275                                                                                  LPDIRECTDRAWPALETTE, LPDIRECT3DDEVICEI);
276 typedef HRESULT (*PFNDOFLUSHBEGINEND)(LPDIRECT3DDEVICE2, DWORD);
277 typedef HRESULT (*PFNDRAWPRIMITIVES)(LPDIRECT3DDEVICEI, LPD3DTLVERTEX, LPVOID, LPD3DINSTRUCTION, DWORD);
278
279
280 typedef struct _D3DI_TEXTUREBLOCK
281 {
282     LIST_MEMBER(_D3DI_TEXTUREBLOCK)     list;
283                                         /* Next block in IDirect3DTexture */
284     LIST_MEMBER(_D3DI_TEXTUREBLOCK)     devList;
285                                         /* Next block in IDirect3DDevice */
286     LPDIRECT3DDEVICEI                   lpD3DDeviceI;
287     LPDIRECT3DTEXTUREI                  lpD3DTextureI;
288     D3DTEXTUREHANDLE                    hTex;
289                                         /* texture handle */
290 } D3DI_TEXTUREBLOCK;
291 typedef struct _D3DI_TEXTUREBLOCK *LPD3DI_TEXTUREBLOCK;
292
293 typedef struct _D3DI_MATERIALBLOCK
294 {
295     LIST_MEMBER(_D3DI_MATERIALBLOCK)    list;
296                                         /* Next block in IDirect3DMaterial */
297     LIST_MEMBER(_D3DI_MATERIALBLOCK)    devList;
298                                         /* Next block in IDirect3DDevice */
299     LPDIRECT3DDEVICEI                   lpD3DDeviceI;
300     LPDIRECT3DMATERIALI                 lpD3DMaterialI;
301     D3DMATERIALHANDLE                   hMat;
302                                         /* material handle */
303 } D3DI_MATERIALBLOCK;
304 typedef struct _D3DI_MATERIALBLOCK *LPD3DI_MATERIALBLOCK;
305
306 #define D3D_RSTATEBUF_SIZE 128
307 #define D3D_MAX_RSTATES 96 /* Last render state ID + 1 */
308 #define D3D_MAX_MMX_VERTICES 1024
309
310 extern DWORD dwD3DTriBatchSize, dwTriBatchSize, dwLineBatchSize;
311 extern DWORD dwHWBufferSize, dwHWMaxTris;
312 extern DWORD dwHWFewVertices;
313
314 typedef struct _D3DHAL_DRAWPRIMCOUNTS *LPD3DHAL_DRAWPRIMCOUNTS;
315
316 // Legacy HAL batching is done with these structs.
317 typedef struct _D3DI_HWCOUNTS {
318     WORD wNumStateChanges;      // Number of state changes batched
319     WORD wNumVertices;          // Number of vertices in tri list
320     WORD wNumTriangles;         // Number of triangles in tri list
321 } D3DI_HWCOUNTS, *LPD3DI_HWCOUNTS;
322
323 typedef struct _DIRECT3DDEVICEI
324 {
325     /*** Object Interface ***/
326     LPDIRECT3DDEVICE2CALLBACKS  lpVtbl; /* Pointer to callbacks */
327     int                         refCnt; /* Reference count */
328
329     /*** Object Relations ***/
330     LPDIRECT3DI                lpDirect3DI; /* parent */
331     LIST_MEMBER(_DIRECT3DDEVICEI)list;  /* Next device IDirect3D */
332
333     /* Textures */
334     LIST_ROOT(_textures, _D3DI_TEXTUREBLOCK) texBlocks;
335                                         /* Ref to created IDirect3DTextures */
336
337     /* Execute buffers */
338     LIST_ROOT(_buffers, _DIRECT3DEXECUTEBUFFERI) buffers;
339                                         /* Created IDirect3DExecuteBuffers */
340
341     /* Viewports */
342     int                         numViewports;
343     CIRCLE_QUEUE_ROOT(_dviewports, _DIRECT3DVIEWPORTI) viewports;
344                                         /* Associated IDirect3DViewports */
345     LPDIRECT3DVIEWPORT2 lpCurrentViewport;
346
347     /* Materials */
348     LIST_ROOT(_dmmaterials, _D3DI_MATERIALBLOCK) matBlocks;
349                                         /* Ref to associated IDirect3DMaterials */
350
351     /*** Object Data ***/
352     /* Private interfaces */
353     LPD3DOBJECTVTBL             lpClassVtbl; /* Private Vtbl */
354     LPD3DOBJECTVTBL             lpObjVtbl; /* Private Vtbl */
355
356     LPD3DHAL_CALLBACKS          lpD3DHALCallbacks; /* HW specific */
357     LPD3DHAL_GLOBALDRIVERDATA   lpD3DHALGlobalDriverData; /* HW specific */
358
359     /* Viewports */
360     unsigned long               v_id;   /* ID of last viewport rendered */
361
362     /* Lights */
363     int                         numLights;
364                                         /* This indicates the maximum number
365                                            of lights that have been set in
366                                            the device. */
367
368     /* Device characteristics */
369     int                         age;
370     int                         width;
371     int                         height;
372     int                         depth;
373     unsigned long               red_mask, green_mask, blue_mask;
374
375     int                         dither;
376     int                         ramp_size; /* SW specific */
377     D3DCOLORMODEL               color_model;
378     int                         wireframe_options;
379     D3DTEXTUREFILTER            texture_quality;
380     D3DVALUE                    gamma;
381     unsigned char               gamma_table[256];
382     int                         aspectx, aspecty;
383     D3DVALUE                    perspective_tolerance;
384
385     /* Library information */
386 #ifdef WIN32
387     HINSTANCE           hDrvDll;
388     char                dllname[MAXPATH];
389     char                base[256];
390 #endif
391 #ifdef SHLIB
392     void*               so;
393 #endif
394
395     /* Are we in a scene? */
396     BOOL                bInScene;
397
398     /* Our Device type */
399     GUID                guid;
400
401     /* GetCaps function from the library */
402     RLDDIGetCapsFn      GetCapsFn;
403
404     /* Functions required to build driver */
405     RLDDIInitFn         RLDDIInit;
406     RLDDIPushDriverFn   RLDDIPushDriver;
407     RLDDIPopDriverFn    RLDDIPopDriver;
408     RLDDIDDrawCreateDriverFn    RLDDIDDrawCreateDriver;
409
410     /* Device description */
411     D3DDEVICEDESC       d3dHWDevDesc;
412     D3DDEVICEDESC       d3dHELDevDesc;
413
414     /* Driver stack */
415     RLDDIDriverStack*   stack;
416
417     /*
418      * The special IUnknown interface for the aggregate that does
419      * not punt to the parent object.
420      */
421     LPUNKNOWN                   lpOwningIUnknown; /* The owning IUnknown    */
422     DIRECT3DDEVICEUNKNOWNI      lpThisIUnknown;   /* Our IUnknown interface */
423     DIRECT3DDEVICEOLDI                  lpThisID3DDev;   /* Our IDirect3DDevice interface */
424
425     LPD3DHAL_CALLBACKS2         lpD3DHALCallbacks2; /* HW specific */
426
427         /*
428          * Renderstate cache for DrawPrimitive
429          */
430         WORD wRStateBufLevel;
431         D3DSTATE renStateBuf[D3D_RSTATEBUF_SIZE];
432
433         /* Pointers to drivers used by DrawPrimitive */
434         LPRLDDIGENRASDRIVER rasDriver; /* SW specific */
435         LPRLDDITRANSFORMDRIVER xfmDriver; /* Assumed to be NULL for HW */
436         LPRLDDIDDRAWDRIVER drawDriver; /* Assumed to be NULL for HW */
437
438         /*
439          * Pointers to functions used by DrawPrim&Begin/End
440          */
441
442         PFNLOCKTEXTURE pfnLockTexture; /* SW specific */
443         PFNUNLOCKTEXTURE pfnUnlockTexture; /* SW specific */
444         PFNSETFILLPARAMS pfnSetFillParams; /* SW specific */
445         PFNREALLOCALIGNED pfnReallocAligned; /* SW specific */
446         PFNDRVSETRENDERTARGET pfnDrvSetRenderTarget; /* SW specific */
447         HRESULT (*pfnFlushStates)(struct _DIRECT3DDEVICEI*);
448     PFNDOFLUSHBEGINEND pfnDoFlushBeginEnd;
449         PFNDRAWPRIMITIVES pfnDrawPrimitives;
450
451     /* Are we between Begin/End? */
452     BOOL                                bInBegin;
453     D3DVERTEXTYPE               vtVertexType;
454     D3DPRIMITIVETYPE    ptPrimitiveType;
455         CRITICAL_SECTION        BeginEndCSect;
456
457         // max number of vertices
458     #define BEGIN_DATA_BLOCK_SIZE   256
459
460     LPVOID      lpvVertexBatch;
461         WORD    *lpIndexBatch;
462
463     // lpvVertexData is non-NULL if we are InBegin and indexed.
464     LPVOID      lpvVertexData;
465     DWORD       dwNumVertices;
466         DWORD   dwMaxVertexCount;       // current number of vertices there is space for
467     WORD        *lpVertexIndices;
468     DWORD       dwNumIndices;
469         DWORD   dwMaxIndexCount;        // current number of indices there is space for
470
471     DWORD       dwFlags;
472     WORD        wFlushed;
473
474     /*
475      * DrawPrimitives batching
476      */
477
478
479         // Buffer to put DrawPrimitives stuff into
480         // Used for both legacy and DrawPrimitive HALs
481          WORD *lpwDPBuffer; 
482          WORD *lpwDPBufferAlloced;
483
484     /* Legacy HALs */
485         // pointer to current prim counts struct
486         LPD3DHAL_DRAWPRIMCOUNTS lpDPPrimCounts;
487
488         // Buffer of counts structures that keep track of the
489         // number of render states and vertices buffered
490         LPD3DI_HWCOUNTS lpHWCounts;
491
492         // Buffer of triangle structures.
493         LPD3DTRIANGLE lpHWTris;
494
495         // Buffer of interleaved render states and primitives.
496         LPD3DTLVERTEX lpHWVertices;
497
498         // Byte offset into lpHWVertices. This gets incremented
499         // by 8 when a render state is batched and by 32*dwNumVertices
500         // when a primitive is batched.
501         DWORD dwHWOffset;
502
503         // Max value of dwHWOffset. Used to decide whether to flush.
504         DWORD dwHWMaxOffset;
505
506         // Index into lpHWTris.
507         DWORD dwHWTriIndex;
508
509         // Number of counts structures used so far. This actually
510         // gives the number of primitives batched and the index of
511         // the counts structure to batch render states into.
512         DWORD dwHWNumCounts;
513
514     /* DrawPrimitive-aware HALs */
515
516         // Byte offset into buffer (we are currently
517         // using the device's wTriIndex)
518         DWORD dwDPOffset;
519
520         // Maximum offset. If dwDPOffset exceeds this, it is
521         // time to flush.
522         DWORD dwDPMaxOffset;
523
524         WORD *wTriIndex;
525
526         // buffers for TL and H vertices
527         LPD3DTLVERTEX   lpTLVbuf;
528         LPD3DHVERTEX    lpHVbuf;
529         DWORD                   dwVbufSize;
530
531     LPD3DHAL_D3DEXTENDEDCAPS lpD3DExtendedCaps;  /* HW specific */
532
533 } DIRECT3DDEVICEI;
534
535 /*
536  * Internal version of Direct3DExecuteBuffer object;
537  * it has data after the vtable
538  */
539 typedef struct _DIRECT3DEXECUTEBUFFERI
540 {
541     /*** Object Interface ***/
542     LPDIRECT3DEXECUTEBUFFERCALLBACKS    lpVtbl; /* Pointer to callbacks */
543     int                         refCnt; /* Reference count */
544
545     /*** Object Relations ***/
546     LPDIRECT3DDEVICEI           lpD3DDeviceI; /* Parent */
547     LIST_MEMBER(_DIRECT3DEXECUTEBUFFERI)list;
548                                         /* Next buffer in IDirect3D */
549
550     /*** Object Data ***/
551     DWORD                       pid;    /* Process locking execute buffer */
552     D3DEXECUTEBUFFERDESC        debDesc;
553                                         /* Description of the buffer */
554     D3DEXECUTEDATA              exData; /* Execute Data */
555     BOOL                        locked; /* Is the buffer locked */
556
557     D3DI_BUFFERHANDLE           hBuf;
558                                         /* Execute buffer handle */
559 } DIRECT3DEXECUTEBUFFERI;
560
561 /*
562  * Internal version of Direct3DLight object;
563  * it has data after the vtable
564  */
565 typedef struct _DIRECT3DLIGHTI
566 {
567     /*** Object Interface ***/
568     LPDIRECT3DLIGHTCALLBACKS    lpVtbl; /* Pointer to callbacks */
569     int                         refCnt; /* Reference count */
570
571     /*** Object Relations ***/
572     LPDIRECT3DI                lpDirect3DI; /* Parent */
573     LIST_MEMBER(_DIRECT3DLIGHTI)list;
574                                         /* Next light in IDirect3D */
575
576     LPDIRECT3DVIEWPORTI         lpD3DViewportI; /* Guardian */
577     CIRCLE_QUEUE_MEMBER(_DIRECT3DLIGHTI)light_list;
578                                         /* Next light in IDirect3DViewport */
579
580     /*** Object Data ***/
581     D3DLIGHT2                   dlLight;/* Data describing light */
582     D3DI_LIGHT                  diLightData;
583                                         /* Internal representation of light */
584 } DIRECT3DLIGHTI;
585
586 typedef struct _DIRECT3DMATERIALOLDI
587 {
588         LPDIRECT3DMATERIALCALLBACKS lpVtbl;
589         LPDIRECT3DMATERIALI lpObj;
590 } DIRECT3DMATERIALOLDI, *LPDIRECT3DMATERIALOLDI;
591
592 /*
593  * Internal version of Direct3DMaterial object;
594  * it has data after the vtable
595  */
596 typedef struct _DIRECT3DMATERIALI
597 {
598     /*** Object Interface ***/
599     LPDIRECT3DMATERIAL2CALLBACKS        lpVtbl; /* Pointer to callbacks */
600     int                         refCnt; /* Reference count */
601
602     /*** Object Relations ***/
603     LPDIRECT3DI                lpDirect3DI; /* Parent */
604         DIRECT3DMATERIALOLDI lpThisID3DMat; /* Our IDirect3DMaterial interface */
605     LIST_MEMBER(_DIRECT3DMATERIALI)list;
606                                         /* Next MATERIAL in IDirect3D */
607
608     LIST_ROOT(_mblocks, _D3DI_MATERIALBLOCK)blocks;
609                                         /* devices we're associated with */
610
611     /*** Object Data ***/
612     D3DMATERIAL                 dmMaterial; /* Data describing material */
613     BOOL                        bRes;   /* Is this material reserved in the driver */
614 } DIRECT3DMATERIALI;
615
616 /*
617  * If we have an aggreate Direct3DTexture we need a structure
618  * to represent an unknown interface distinct from the underlying
619  * object. This is that structure. 
620  */
621 typedef struct _DIRECT3DTEXTUREUNKNOWNI
622 {
623     LPDIRECT3DTEXTURECALLBACKS  lpVtbl;
624     LPDIRECT3DTEXTUREI          lpObj;
625 } DIRECT3DTEXTUREUNKNOWNI;
626 typedef struct _DIRECT3DTEXTUREUNKNOWNI *LPDIRECT3DTEXTUREUNKNOWNI;
627
628 typedef struct _DIRECT3DTEXTUREOLDI
629 {
630         LPDIRECT3DTEXTURECALLBACKS lpVtbl;
631         LPDIRECT3DTEXTUREI lpObj;
632 } DIRECT3DTEXTUREOLDI, *LPDIRECT3DTEXTUREOLDI;
633
634 /*
635  * Internal version of Direct3DTexture object; it has data after the vtable
636  */
637 typedef struct _DIRECT3DTEXTUREI
638 {
639     /*** Object Interface ***/
640     LPDIRECT3DTEXTURE2CALLBACKS lpVtbl; /* Pointer to callbacks */
641     int                         refCnt; /* Reference count */
642
643
644     /*** Object Relations ***/
645     LIST_ROOT(_blocks, _D3DI_TEXTUREBLOCK) blocks;
646                                         /* Devices we're associated with */
647
648     /*** Object Data ***/
649     LPDIRECTDRAWSURFACE         lpDDS;
650
651     /*
652      * The special IUnknown interface for the aggregate that does
653      * not punt to the parent object.
654      */
655     LPUNKNOWN                   lpOwningIUnknown; /* The owning IUnknown    */
656     DIRECT3DTEXTUREUNKNOWNI     lpThisIUnknown;   /* Our IUnknown interface */
657     DIRECT3DTEXTUREOLDI     lpThisID3DTex;   /* Our IDirect3DTexture interface */
658     BOOL                        bIsPalettized;
659
660 } DIRECT3DTEXTUREI;
661
662 /*
663  * Internal version of Direct3DViewport object; it has data after the vtable
664  */
665 typedef struct _DIRECT3DVIEWPORTI
666 {
667     /*** Object Interface ***/
668     LPDIRECT3DVIEWPORT2CALLBACKS        lpVtbl; /* Pointer to callbacks */
669     int                         refCnt; /* Reference count */
670
671     /*** Object Relations */
672     LPDIRECT3DI                 lpDirect3DI; /* Parent */
673     LIST_MEMBER(_DIRECT3DVIEWPORTI)list;
674                                         /* Next viewport in IDirect3D */
675
676     LPDIRECT3DDEVICEI           lpD3DDeviceI; /* Guardian */
677     CIRCLE_QUEUE_MEMBER(_DIRECT3DVIEWPORTI)vw_list;
678                                         /* Next viewport in IDirect3DDevice */
679                                         
680     /* Lights */
681     int                         numLights;
682     CIRCLE_QUEUE_ROOT(_dlights, _DIRECT3DLIGHTI) lights;
683                                         /* Associated IDirect3DLights */
684
685     /*** Object Data ***/
686     unsigned long               v_id;   /* Id for this viewport */
687     D3DVIEWPORT2                        v_data;
688     BOOL                v_data_is_set;
689
690     BOOL                        have_background;
691     D3DMATERIALHANDLE           background;
692                                         /* Background material */
693     BOOL                        have_depth;
694     LPDIRECTDRAWSURFACE         depth;  /* Background depth */
695     
696     BOOL                        bLightsChanged;
697                                         /* Have the lights changed since they
698                                            were last collected? */
699     DWORD                       clrCount; /* Number of rects allocated */
700     LPD3DRECT                   clrRects; /* Rects used for clearing */
701 } DIRECT3DVIEWPORTI;
702
703 /*
704  * Picking stuff.
705  */
706 typedef struct _D3DI_PICKDATA {
707     D3DI_EXECUTEDATA*   exe;
708     D3DPICKRECORD*      records;
709     int                 pick_count;
710     D3DRECT             pick;
711 } D3DI_PICKDATA, *LPD3DI_PICKDATA;
712
713 /*
714  * Direct3D memory allocation
715  */
716
717 /*
718  * Register a set of functions to be used in place of malloc, realloc
719  * and free for memory allocation.  The functions D3DMalloc, D3DRealloc
720  * and D3DFree will use these functions.  The default is to use the
721  * ANSI C library routines malloc, realloc and free.
722  */
723 typedef LPVOID (*D3DMALLOCFUNCTION)(size_t);
724 typedef LPVOID (*D3DREALLOCFUNCTION)(LPVOID, size_t);
725 typedef VOID (*D3DFREEFUNCTION)(LPVOID);
726
727 /*
728  * Allocate size bytes of memory and return a pointer to it in *p_return.
729  * Returns D3DERR_BADALLOC with *p_return unchanged if the allocation fails.
730  */
731 extern __declspec (dllexport) HRESULT D3DAPI            D3DMalloc(LPVOID* p_return, size_t size);
732
733 /*
734  * Change the size of an allocated block of memory.  A pointer to the
735  * block is passed in in *p_inout.  If *p_inout is NULL then a new
736  * block is allocated.  If the reallocation is successful, *p_inout is
737  * changed to point to the new block.  If the allocation fails,
738  * *p_inout is unchanged and D3DERR_BADALLOC is returned.
739  */
740 HRESULT D3DAPI          D3DRealloc(LPVOID* p_inout, size_t size);
741
742 /*
743  * Free a block of memory previously allocated with D3DMalloc or
744  * D3DRealloc.
745  */
746 extern __declspec (dllexport) VOID D3DAPI               D3DFree(LPVOID p);
747
748 /*
749  * Used for raising errors from the driver.
750  */
751 HRESULT D3DAPI D3DRaise(HRESULT);
752
753 /*
754  * Convert RLDDI error codes to D3D error codes
755  */
756 #define RLDDITOD3DERR(_errcode) (RLDDIToD3DErrors[_errcode])
757 extern HRESULT RLDDIToD3DErrors[];
758
759 /*
760  * maths
761  */
762 #if 1 /* defined(STACK_CALL) && defined(__WATCOMC__) */
763 D3DVALUE D3DIPow(D3DVALUE, D3DVALUE);
764 #else
765 #define D3DIPow(v,p)    DTOVAL(pow(VALTOD(v), VALTOD(p)))
766 #endif
767
768 /*
769  * Light utils
770  */
771 void D3DI_DeviceMarkLightEnd(LPDIRECT3DDEVICEI, int);
772 void D3DI_UpdateLightInternal(LPDIRECT3DLIGHTI);
773 void D3DI_VectorNormalise12(LPD3DVECTOR v);
774 D3DTEXTUREHANDLE D3DI_FindTextureHandle(LPDIRECT3DTEXTUREI, LPDIRECT3DDEVICEI);
775 void D3DI_SetTextureHandle(LPDIRECT3DTEXTUREI, LPDIRECT3DDEVICEI, D3DTEXTUREHANDLE);
776 void D3DI_RemoveTextureBlock(LPD3DI_TEXTUREBLOCK);
777 void D3DI_RemoveMaterialBlock(LPD3DI_MATERIALBLOCK);
778
779 extern BOOL D3DI_isHALValid(LPD3DHAL_CALLBACKS);
780
781 #ifdef BUILD_D3D_LAYER
782 extern RLDDIValue* RLDDIFInvSqrtTable;
783 #endif
784
785 #ifdef __cplusplus
786 };
787 #endif
788
789 #endif /* BUILD_HEL */
790 #endif /* !BUILD_RLAPI */
791 // @@END_MSINTERNAL
792
793 #endif /* _D3DI_H */
794