Authors: Michael Lin <mlin@corvu.com.au>, Michael Jung <mjung@iss.tu-darmstadt.de>
[wine] / dlls / wined3d / wined3d_private.h
1 /*
2  * Direct3D wine internal private include file
3  *
4  * Copyright 2002-2003 The wine-d3d team
5  * Copyright 2002-2003 Raphael Junqueira
6  * Copyright 2004 Jason Edmeades
7  * Copyright 2005 Oliver Stieber
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #ifndef __WINE_WINED3D_PRIVATE_H
25 #define __WINE_WINED3D_PRIVATE_H
26
27 #include <stdarg.h>
28 #include <math.h>
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
31 #define COBJMACROS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winreg.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
39
40 #include "d3d9.h"
41 #include "d3d9types.h"
42 #include "wine/wined3d_interface.h"
43 #include "wine/wined3d_gl.h"
44
45 /* Device caps */
46 #define MAX_PALETTES      256
47 #define MAX_STREAMS       16
48 #define MAX_TEXTURES      8
49 #define MAX_SAMPLERS      16
50 #define MAX_ACTIVE_LIGHTS 8
51 #define MAX_CLIPPLANES    D3DMAXUSERCLIPPLANES
52 #define MAX_LEVELS        256
53
54 /* Swap chains */
55 #define MAX_SWAPCHAINS 256
56
57 /* Used for CreateStateBlock */
58 #define NUM_SAVEDPIXELSTATES_R     35
59 #define NUM_SAVEDPIXELSTATES_T     18
60 #define NUM_SAVEDPIXELSTATES_S     12
61 #define NUM_SAVEDVERTEXSTATES_R    31
62 #define NUM_SAVEDVERTEXSTATES_T    2
63 #define NUM_SAVEDVERTEXSTATES_S    1
64
65 extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
66 extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
67 extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
68 extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
69 extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
70 extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
71
72 /* vertex and pixel shader modes */
73 extern int vs_mode;
74 #define VS_NONE 0
75 #define VS_HW   1
76 #define VS_SW   2
77
78 extern int ps_mode;
79 #define PS_NONE 0
80 #define PS_HW   1
81
82 /* X11 locking */
83
84 extern void (*wine_tsx11_lock_ptr)(void);
85 extern void (*wine_tsx11_unlock_ptr)(void);
86
87 /* As GLX relies on X, this is needed */
88 extern int num_lock;
89
90 #if 0
91 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
92 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
93 #else
94 #define ENTER_GL() wine_tsx11_lock_ptr()
95 #define LEAVE_GL() wine_tsx11_unlock_ptr()
96 #endif
97
98 /*****************************************************************************
99  * Defines
100  */
101
102 /* GL related defines */
103 /* ------------------ */
104 #define GL_SUPPORT(ExtName)           (GLINFO_LOCATION.supported[ExtName] != 0)
105 #define GL_LIMITS(ExtName)            (GLINFO_LOCATION.max_##ExtName)
106 #define GL_EXTCALL(FuncName)          (GLINFO_LOCATION.FuncName)
107
108 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
109 #define D3DCOLOR_G(dw) (((float) (((dw) >>  8) & 0xFF)) / 255.0f)
110 #define D3DCOLOR_B(dw) (((float) (((dw) >>  0) & 0xFF)) / 255.0f)
111 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
112
113 #define D3DCOLORTOGLFLOAT4(dw, vec) \
114   (vec)[0] = D3DCOLOR_R(dw); \
115   (vec)[1] = D3DCOLOR_G(dw); \
116   (vec)[2] = D3DCOLOR_B(dw); \
117   (vec)[3] = D3DCOLOR_A(dw);
118   
119 /* Note: The following is purely to keep the source code as clear from #ifdefs as possible */
120 #if defined(GL_VERSION_1_3)
121 #define GLACTIVETEXTURE(textureNo)                          \
122             glActiveTexture(GL_TEXTURE0 + textureNo);       \
123             checkGLcall("glActiveTexture");      
124 #define GLCLIENTACTIVETEXTURE(textureNo)                    \
125             glClientActiveTexture(GL_TEXTURE0 + textureNo);
126 #define GLMULTITEXCOORD1F(a,b)                              \
127             glMultiTexCoord1f(GL_TEXTURE0 + a, b);
128 #define GLMULTITEXCOORD2F(a,b,c)                            \
129             glMultiTexCoord2f(GL_TEXTURE0 + a, b, c);
130 #define GLMULTITEXCOORD3F(a,b,c,d)                          \
131             glMultiTexCoord3f(GL_TEXTURE0 + a, b, c, d);
132 #define GLMULTITEXCOORD4F(a,b,c,d,e)                        \
133             glMultiTexCoord4f(GL_TEXTURE0 + a, b, c, d, e);
134 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP
135 #else 
136 #define GLACTIVETEXTURE(textureNo)                             \
137             glActiveTextureARB(GL_TEXTURE0_ARB + textureNo);   \
138             checkGLcall("glActiveTextureARB");
139 #define GLCLIENTACTIVETEXTURE(textureNo)                    \
140             glClientActiveTextureARB(GL_TEXTURE0_ARB + textureNo);
141 #define GLMULTITEXCOORD1F(a,b)                                 \
142             glMultiTexCoord1fARB(GL_TEXTURE0_ARB + a, b);
143 #define GLMULTITEXCOORD2F(a,b,c)                               \
144             glMultiTexCoord2fARB(GL_TEXTURE0_ARB + a, b, c);
145 #define GLMULTITEXCOORD3F(a,b,c,d)                             \
146             glMultiTexCoord3fARB(GL_TEXTURE0_ARB + a, b, c, d);
147 #define GLMULTITEXCOORD4F(a,b,c,d,e)                           \
148             glMultiTexCoord4fARB(GL_TEXTURE0_ARB + a, b, c, d, e);
149 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP_ARB
150 #endif
151
152 /* DirectX Device Limits */
153 /* --------------------- */
154 #define MAX_LEVELS  256  /* Maximum number of mipmap levels. Guessed at 256 */
155
156 #define MAX_STREAMS  16  /* Maximum possible streams - used for fixed size arrays
157                             See MaxStreams in MSDN under GetDeviceCaps */
158                          /* Maximum number of constants provided to the shaders */
159 #define HIGHEST_TRANSFORMSTATE 512 
160                          /* Highest value in D3DTRANSFORMSTATETYPE */
161 #define HIGHEST_TEXTURE_STATE   D3DTSS_CONSTANT
162                          /* Highest D3DTSS_ value                  */
163 #define HIGHEST_SAMPLER_STATE   D3DSAMP_DMAPOFFSET
164                          /* Maximum number of constants provided to the shaders */
165 #define MAX_CLIPPLANES  D3DMAXUSERCLIPPLANES
166
167 #define MAX_PALETTES      256
168
169 /* Checking of API calls */
170 /* --------------------- */
171 #define checkGLcall(A) \
172 { \
173     GLint err = glGetError();   \
174     if (err != GL_NO_ERROR) { \
175        FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
176     } else { \
177        TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
178     } \
179 }
180
181 /* Trace routines / diagnostics */
182 /* ---------------------------- */
183
184 /* Dump out a matrix and copy it */
185 #define conv_mat(mat,gl_mat)                                                                \
186 do {                                                                                        \
187     TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
188     TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
189     TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
190     TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
191     memcpy(gl_mat, (mat), 16 * sizeof(float));                                              \
192 } while (0)
193
194 /* Macro to dump out the current state of the light chain */
195 #define DUMP_LIGHT_CHAIN()                    \
196 {                                             \
197   PLIGHTINFOEL *el = This->stateBlock->lights;\
198   while (el) {                                \
199     TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
200     el = el->next;                            \
201   }                                           \
202 }
203
204 /* Trace vector and strided data information */
205 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
206 #define TRACE_STRIDED(sd,name) TRACE( #name "=(data:%p, stride:%ld, type:%ld)\n", sd->u.s.name.lpData, sd->u.s.name.dwStride, sd->u.s.name.dwType);
207
208 /* Defines used for optimizations */
209
210 /*    Only reapply what is necessary */
211 #define REAPPLY_ALPHAOP  0x0001
212 #define REAPPLY_ALL      0xFFFF
213
214 /* Advance declaration of structures to satisfy compiler */
215 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
216 typedef struct IWineD3DSurfaceImpl    IWineD3DSurfaceImpl;
217
218 /* Global variables */
219 extern const float identity[16];
220
221 /*****************************************************************************
222  * Compilable extra diagnostics
223  */
224
225 /* Trace information per-vertex: (extremely high amount of trace) */
226 #if 0 /* NOTE: Must be 0 in cvs */
227 # define VTRACE(A) TRACE A
228 #else 
229 # define VTRACE(A) 
230 #endif
231
232 /* Checking of per-vertex related GL calls */
233 #define vcheckGLcall(A) \
234 { \
235     GLint err = glGetError();   \
236     if (err != GL_NO_ERROR) { \
237        FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
238     } else { \
239        VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
240     } \
241 }
242
243 /* TODO: Confirm each of these works when wined3d move completed */
244 #if 0 /* NOTE: Must be 0 in cvs */
245   /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
246      of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
247      is enabled, and if it doesn't exists it is disabled.                                           */
248 # define FRAME_DEBUGGING
249   /*  Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
250       the file is deleted                                                                            */
251 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
252 #  define SINGLE_FRAME_DEBUGGING
253 # endif  
254   /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
255      It can only be enabled when FRAME_DEBUGGING is also enabled                               
256      The contents of the back buffer are written into /tmp/backbuffer_* after each primitive 
257      array is drawn.                                                                            */
258 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */                                                                                       
259 #  define SHOW_FRAME_MAKEUP 1
260 # endif  
261   /* The following, when enabled, lets you see the makeup of the all the textures used during each
262      of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
263      The contents of the textures assigned to each stage are written into 
264      /tmp/texture_*_<Stage>.ppm after each primitive array is drawn.                            */
265 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
266 #  define SHOW_TEXTURE_MAKEUP 0
267 # endif  
268 extern BOOL isOn;
269 extern BOOL isDumpingFrames;
270 extern LONG primCounter;
271 #endif
272
273 /*****************************************************************************
274  * Prototypes
275  */
276
277 /* Routine common to the draw primitive and draw indexed primitive routines */
278 void drawPrimitive(IWineD3DDevice *iface,
279                     int PrimitiveType,
280                     long NumPrimitives,
281
282                     /* for Indexed: */
283                     long  StartVertexIndex,
284                     long  StartIdx,
285                     short idxBytes,
286                     const void *idxData,
287                     int   minIndex);
288
289 /*****************************************************************************
290  * Structures required to draw primitives 
291  */
292
293 typedef struct Direct3DStridedData {
294     BYTE     *lpData;        /* Pointer to start of data               */
295     DWORD     dwStride;      /* Stride between occurances of this data */
296     DWORD     dwType;        /* Type (as in D3DVSDT_TYPE)              */
297 } Direct3DStridedData;
298
299 typedef struct Direct3DVertexStridedData {
300     union {
301         struct {
302              Direct3DStridedData  position;
303              Direct3DStridedData  blendWeights;
304              Direct3DStridedData  blendMatrixIndices;
305              Direct3DStridedData  normal;
306              Direct3DStridedData  pSize;
307              Direct3DStridedData  diffuse;
308              Direct3DStridedData  specular;
309              Direct3DStridedData  texCoords[MAX_TEXTURES];
310         } s;
311         Direct3DStridedData input[16];  /* Indexed by constants in D3DVSDE_REGISTER */
312     } u;
313 } Direct3DVertexStridedData;
314
315 /*****************************************************************************
316  * Internal representation of a light
317  */
318 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
319 struct PLIGHTINFOEL {
320     WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
321     DWORD        OriginalIndex;
322     LONG         glIndex;
323     BOOL         lightEnabled;
324     BOOL         changed;
325     BOOL         enabledChanged;
326
327     /* Converted parms to speed up swapping lights */
328     float                         lightPosn[4];
329     float                         lightDirn[4];
330     float                         exponent;
331     float                         cutoff;
332
333     PLIGHTINFOEL *next;
334     PLIGHTINFOEL *prev;
335 };
336
337 /*****************************************************************************
338  * IWineD3D implementation structure
339  */
340 typedef struct IWineD3DImpl
341 {
342     /* IUnknown fields */
343     const IWineD3DVtbl     *lpVtbl;
344     DWORD                   ref;     /* Note: Ref counting not required */
345
346     /* WineD3D Information */
347     IUnknown               *parent;
348     UINT                    dxVersion;
349
350     /* GL Information */
351     BOOL                    isGLInfoValid;
352     WineD3D_GL_Info         gl_info;
353 } IWineD3DImpl;
354
355 extern const IWineD3DVtbl IWineD3D_Vtbl;
356
357 /*****************************************************************************
358  * IWineD3DDevice implementation structure
359  */
360 typedef struct IWineD3DDeviceImpl
361 {
362     /* IUnknown fields      */
363     const IWineD3DDeviceVtbl *lpVtbl;
364     DWORD                   ref;     /* Note: Ref counting not required */
365
366     /* WineD3D Information  */
367     IUnknown               *parent;
368     IWineD3D               *wineD3D;
369
370     /* X and GL Information */
371     GLint                   maxConcurrentLights;
372
373     /* Optimization */
374     BOOL                    modelview_valid;
375     BOOL                    proj_valid;
376     BOOL                    view_ident;        /* true iff view matrix is identity                */
377     BOOL                    last_was_rhw;      /* true iff last draw_primitive was in xyzrhw mode */
378     GLenum                  tracking_parm;     /* Which source is tracking current colour         */
379     LONG                    tracking_color;    /* used iff GL_COLOR_MATERIAL was enabled          */
380 #define                         DISABLED_TRACKING  0  /* Disabled                                 */
381 #define                         IS_TRACKING        1  /* tracking_parm is tracking diffuse color  */
382 #define                         NEEDS_TRACKING     2  /* Tracking needs to be enabled when needed */
383 #define                         NEEDS_DISABLE      3  /* Tracking needs to be disabled when needed*/
384     UINT                    srcBlend;
385     UINT                    dstBlend;
386     UINT                    alphafunc;
387     UINT                    stencilfunc;
388     BOOL                    texture_shader_active;  /* TODO: Confirm use is correct */
389
390     /* State block related */
391     BOOL                    isRecordingState;
392     IWineD3DStateBlockImpl *stateBlock;
393     IWineD3DStateBlockImpl *updateStateBlock;
394
395     /* Internal use fields  */
396     D3DDEVICE_CREATION_PARAMETERS   createParms;
397     D3DPRESENT_PARAMETERS           presentParms;
398     UINT                            adapterNo;
399     D3DDEVTYPE                      devType;
400
401     /* TODO: Replace with a linked list */
402     IWineD3DSwapChain      *swapchains[MAX_SWAPCHAINS]; /* no-one wil ever need more that MAX_SWAPCHAINS swapchains */
403     int                     numberOfSwapChains;
404
405     /* Render Target Support */
406     IWineD3DSurface        *frontBuffer;
407     IWineD3DSurface        *backBuffer;
408     IWineD3DSurface        *depthStencilBuffer;
409
410     IWineD3DSurface        *renderTarget;
411     IWineD3DSurface        *stencilBufferTarget;
412
413     /* palettes texture management */
414     PALETTEENTRY            palettes[MAX_PALETTES][256];
415     UINT                    currentPalette;
416
417     /* For rendering to a texture using glCopyTexImage */
418     BOOL                    renderUpsideDown;
419
420     /* Cursor management */
421     BOOL                    bCursorVisible;
422     UINT                    xHotSpot;
423     UINT                    yHotSpot;
424     UINT                    xScreenSpace;
425     UINT                    yScreenSpace;
426
427     /* Textures for when no other textures are mapped */
428     UINT                          dummyTextureName[MAX_TEXTURES];
429
430     /* Debug stream management */
431     BOOL                     debug;
432
433 } IWineD3DDeviceImpl;
434
435 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
436
437 /*****************************************************************************
438  * IWineD3DResource implementation structure
439  */
440 typedef struct IWineD3DResourceClass
441 {
442     /* IUnknown fields */
443     DWORD                   ref;     /* Note: Ref counting not required */
444
445     /* WineD3DResource Information */
446     IUnknown               *parent;
447     D3DRESOURCETYPE         resourceType;
448     IWineD3DDeviceImpl     *wineD3DDevice;
449     D3DPOOL                 pool;
450     UINT                    size;
451     DWORD                   usage;
452     WINED3DFORMAT           format;
453     BYTE                   *allocatedMemory;
454
455 } IWineD3DResourceClass;
456
457 typedef struct IWineD3DResourceImpl
458 {
459     /* IUnknown & WineD3DResource Information     */
460     const IWineD3DResourceVtbl *lpVtbl;
461     IWineD3DResourceClass   resource;
462 } IWineD3DResourceImpl;
463
464
465 /*****************************************************************************
466  * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
467  */
468 typedef struct IWineD3DVertexBufferImpl
469 {
470     /* IUnknown & WineD3DResource Information     */
471     const IWineD3DVertexBufferVtbl *lpVtbl;
472     IWineD3DResourceClass     resource;
473
474     /* WineD3DVertexBuffer specifics */
475     DWORD                     FVF;
476
477 } IWineD3DVertexBufferImpl;
478
479 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
480
481
482 /*****************************************************************************
483  * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
484  */
485 typedef struct IWineD3DIndexBufferImpl
486 {
487     /* IUnknown & WineD3DResource Information     */
488     const IWineD3DIndexBufferVtbl *lpVtbl;
489     IWineD3DResourceClass     resource;
490
491     /* WineD3DVertexBuffer specifics */
492 } IWineD3DIndexBufferImpl;
493
494 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
495
496 /*****************************************************************************
497  * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
498  */
499 typedef struct IWineD3DBaseTextureClass
500 {
501     UINT                    levels;
502     BOOL                    dirty;
503     D3DFORMAT               format;
504     DWORD                   usage;
505     UINT                    textureName;    
506     UINT                    LOD;
507     D3DTEXTUREFILTERTYPE    filterType;
508
509 } IWineD3DBaseTextureClass;
510
511 typedef struct IWineD3DBaseTextureImpl
512 {
513     /* IUnknown & WineD3DResource Information     */
514     const IWineD3DBaseTextureVtbl *lpVtbl;
515     IWineD3DResourceClass     resource;
516     IWineD3DBaseTextureClass  baseTexture;
517
518 } IWineD3DBaseTextureImpl;
519
520 /*****************************************************************************
521  * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
522  */
523 typedef struct IWineD3DTextureImpl
524 {
525     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
526     const IWineD3DTextureVtbl *lpVtbl;
527     IWineD3DResourceClass     resource;
528     IWineD3DBaseTextureClass  baseTexture;
529
530     /* IWineD3DTexture */
531     IWineD3DSurface          *surfaces[MAX_LEVELS];
532     
533     UINT                      width;
534     UINT                      height;
535
536 } IWineD3DTextureImpl;
537
538 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
539
540 /*****************************************************************************
541  * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
542  */
543 typedef struct IWineD3DCubeTextureImpl
544 {
545     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
546     const IWineD3DCubeTextureVtbl *lpVtbl;
547     IWineD3DResourceClass     resource;
548     IWineD3DBaseTextureClass  baseTexture;
549
550     /* IWineD3DCubeTexture */
551     IWineD3DSurface          *surfaces[6][MAX_LEVELS];
552
553     UINT                      edgeLength;
554
555 } IWineD3DCubeTextureImpl;
556
557 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
558
559 /*****************************************************************************
560  * IWineD3DVolume implementation structure (extends IUnknown)
561  */
562 typedef struct IWineD3DVolumeImpl
563 {
564     /* IUnknown & WineD3DResource fields */
565     const IWineD3DVolumeVtbl  *lpVtbl;
566     IWineD3DResourceClass      resource;
567
568     /* WineD3DVolume Information */
569     D3DVOLUME_DESC          currentDesc;
570     IUnknown               *container;
571     UINT                    bytesPerPixel;
572
573     BOOL                    lockable;
574     BOOL                    locked;
575     D3DBOX                  lockedBox;
576     D3DBOX                  dirtyBox;
577     BOOL                    dirty;
578
579
580 } IWineD3DVolumeImpl;
581
582 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
583
584 /*****************************************************************************
585  * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
586  */
587 typedef struct IWineD3DVolumeTextureImpl
588 {
589     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
590     const IWineD3DVolumeTextureVtbl *lpVtbl;
591     IWineD3DResourceClass     resource;
592     IWineD3DBaseTextureClass  baseTexture;
593
594     /* IWineD3DVolumeTexture */
595     IWineD3DVolume           *volumes[MAX_LEVELS];
596
597     UINT                      width;
598     UINT                      height;
599     UINT                      depth;
600 } IWineD3DVolumeTextureImpl;
601
602 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
603
604 typedef struct _WINED3DSURFACET_DESC
605 {
606     UINT                Level;
607     D3DMULTISAMPLE_TYPE MultiSampleType;
608     DWORD               MultiSampleQuality;
609     UINT                Width;
610     UINT                Height;
611 } WINED3DSURFACET_DESC;
612
613 /*****************************************************************************
614  * IWineD3DSurface implementation structure
615  */
616 struct IWineD3DSurfaceImpl
617 {
618     /* IUnknown & IWineD3DResource Information     */
619     const IWineD3DSurfaceVtbl *lpVtbl;
620     IWineD3DResourceClass     resource;
621
622     /* IWineD3DSurface fields */
623     IUnknown                 *container;
624     WINED3DSURFACET_DESC      currentDesc;
625
626     UINT                      textureName;
627     UINT                      bytesPerPixel;
628     
629     BOOL                      lockable;
630     BOOL                      discard;
631     BOOL                      locked;
632     
633     RECT                      lockedRect;
634     RECT                      dirtyRect;
635     BOOL                      Dirty;
636     
637     BOOL                      inTexture;
638     BOOL                      inPBuffer;
639 };
640
641 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
642
643 /*****************************************************************************
644  * IWineD3DVertexDeclaration implementation structure
645  */
646 typedef struct IWineD3DVertexDeclarationImpl {
647  /* IUnknown  Information     */
648   const IWineD3DVertexDeclarationVtbl *lpVtbl;
649   DWORD                   ref;     /* Note: Ref counting not required */
650
651   IUnknown               *parent;
652   /** precomputed fvf if simple declaration */
653   IWineD3DDeviceImpl     *wineD3DDevice;
654   DWORD   fvf[MAX_STREAMS];
655   DWORD   allFVF;
656
657   /** dx8 compatible Declaration fields */
658   DWORD*  pDeclaration8;
659   DWORD   declaration8Length;
660
661   /** dx9+ */
662   D3DVERTEXELEMENT9* pDeclaration9;
663   UINT               declaration9NumElements;
664 } IWineD3DVertexDeclarationImpl;
665
666 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
667
668 /*****************************************************************************
669  * IWineD3DStateBlock implementation structure
670  */
671
672 /* Internal state Block for Begin/End/Capture/Create/Apply info  */
673 /*   Note: Very long winded but gl Lists are not flexible enough */
674 /*   to resolve everything we need, so doing it manually for now */
675 typedef struct SAVEDSTATES {
676         BOOL                      indices;
677         BOOL                      material;
678         BOOL                      fvf;
679         BOOL                      streamSource[MAX_STREAMS];
680         BOOL                      streamFreq[MAX_STREAMS];
681         BOOL                      textures[MAX_TEXTURES];
682         BOOL                      transform[HIGHEST_TRANSFORMSTATE + 1];
683         BOOL                      viewport;
684         BOOL                      renderState[WINEHIGHEST_RENDER_STATE + 1];
685         BOOL                      textureState[MAX_TEXTURES][HIGHEST_TEXTURE_STATE + 1];
686         BOOL                      clipplane[MAX_CLIPPLANES];
687         BOOL                      samplerState[MAX_SAMPLERS][HIGHEST_SAMPLER_STATE + 1];
688         BOOL                      vertexDecl;
689         BOOL                      pixelShader;
690         BOOL                      vertexShader;
691 } SAVEDSTATES;
692
693 struct IWineD3DStateBlockImpl
694 {
695     /* IUnknown fields */
696     const IWineD3DStateBlockVtbl *lpVtbl;
697     DWORD                     ref;     /* Note: Ref counting not required */
698
699     /* IWineD3DStateBlock information */
700     IUnknown                 *parent;
701     IWineD3DDeviceImpl       *wineD3DDevice;
702     D3DSTATEBLOCKTYPE         blockType;
703
704     /* Array indicating whether things have been set or changed */
705     SAVEDSTATES               changed;
706     SAVEDSTATES               set;
707
708     /* Drawing - Vertex Shader or FVF related */
709     DWORD                     fvf;
710     /* Vertex Shader Declaration */
711     IWineD3DVertexDeclaration* vertexDecl;
712
713     void                     *vertexShader; /* @TODO: Replace void * with IWineD3DVertexShader * */
714
715     /* Stream Source */
716     BOOL                      streamIsUP;
717     UINT                      streamStride[MAX_STREAMS];
718     UINT                      streamOffset[MAX_STREAMS];
719     IWineD3DVertexBuffer     *streamSource[MAX_STREAMS];
720     UINT                      streamFreq[MAX_STREAMS];
721     UINT                      streamFlags[MAX_STREAMS];     /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA  */
722
723     /* Indices */
724     IWineD3DIndexBuffer*      pIndexData;
725     UINT                      baseVertexIndex; /* Note: only used for d3d8 */
726
727     /* Transform */
728     D3DMATRIX                 transforms[HIGHEST_TRANSFORMSTATE + 1];
729
730     /* Lights */
731     PLIGHTINFOEL             *lights; /* NOTE: active GL lights must be front of the chain */
732
733     /* Clipping */
734     double                    clipplane[MAX_CLIPPLANES][4];
735     WINED3DCLIPSTATUS         clip_status;
736
737     /* ViewPort */
738     WINED3DVIEWPORT           viewport;
739
740     /* Material */
741     WINED3DMATERIAL           material;
742
743     /* Pixel Shader */
744     void                     *pixelShader; /* TODO: Replace void * with IWineD3DPixelShader * */
745
746     /* Indexed Vertex Blending */
747     D3DVERTEXBLENDFLAGS       vertex_blend;
748     FLOAT                     tween_factor;
749
750     /* RenderState */
751     DWORD                     renderState[WINEHIGHEST_RENDER_STATE + 1];
752
753     /* Texture */
754     IWineD3DBaseTexture      *textures[MAX_TEXTURES];
755     int                       textureDimensions[MAX_SAMPLERS];
756
757     /* Texture State Stage */
758     DWORD                     textureState[MAX_TEXTURES][HIGHEST_TEXTURE_STATE + 1];
759     /* Sampler States */
760     DWORD                     samplerState[MAX_SAMPLERS][HIGHEST_SAMPLER_STATE + 1];
761
762 };
763
764 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
765
766 /*****************************************************************************
767  * IWineD3DQueryImpl implementation structure (extends IUnknown)
768  */
769 typedef struct IWineD3DQueryImpl
770 {
771     const IWineD3DQueryVtbl  *lpVtbl;
772     DWORD                     ref;     /* Note: Ref counting not required */
773     
774     IUnknown                 *parent;
775     /*TODO: replace with iface usage */
776 #if 0
777     IWineD3DDevice         *wineD3DDevice;
778 #else
779     IWineD3DDeviceImpl       *wineD3DDevice;
780 #endif
781     /* IWineD3DQuery fields */
782
783     D3DQUERYTYPE              type;
784     void                     *extendedData;
785     
786   
787 } IWineD3DQueryImpl;
788
789 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
790
791 /*****************************************************************************
792  * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
793  */
794
795 typedef struct IWineD3DSwapChainImpl
796 {
797     /*IUnknown part*/
798     IWineD3DSwapChainVtbl    *lpVtbl;
799     DWORD                     ref;     /* Note: Ref counting not required */
800
801     IUnknown                 *parent;
802     IWineD3DDeviceImpl       *wineD3DDevice;
803
804     /* IWineD3DSwapChain fields */
805     IWineD3DSurface          *backBuffer;
806     IWineD3DSurface          *frontBuffer;
807     BOOL                      wantsDepthStencilBuffer;
808     D3DPRESENT_PARAMETERS     presentParms;
809
810     /* TODO: move everything upto drawable off into a context manager
811       and store the 'data' in the contextManagerData interface.
812     IUnknown                  *contextManagerData;
813     */
814
815     HWND                    win_handle;
816     Window                  win;
817     Display                *display;
818
819     GLXContext              glCtx;
820     XVisualInfo            *visInfo;
821     GLXContext              render_ctx;
822     /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
823     Drawable                drawable;
824 } IWineD3DSwapChainImpl;
825
826 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
827
828 /*****************************************************************************
829  * Utility function prototypes 
830  */
831
832 /* Trace routines */
833 const char* debug_d3dformat(D3DFORMAT fmt);
834 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
835 const char* debug_d3dresourcetype(D3DRESOURCETYPE res);
836 const char* debug_d3dusage(DWORD usage);
837 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
838 const char* debug_d3drenderstate(DWORD state);
839 const char* debug_d3dtexturestate(DWORD state);
840 const char* debug_d3dpool(D3DPOOL pool);
841
842 /* Routines for GL <-> D3D values */
843 GLenum StencilOp(DWORD op);
844 void   set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
845 void   set_texture_matrix(const float *smat, DWORD flags);
846 void   GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
847
848 SHORT  D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
849 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
850 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
851 GLint  D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
852
853 /*****************************************************************************
854  * To enable calling of inherited functions, requires prototypes 
855  *
856  * Note: Only require classes which are subclassed, ie resource, basetexture, 
857  */
858     /*** IUnknown methods ***/
859     extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
860     extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
861     extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
862     /*** IWineD3DResource methods ***/
863     extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
864     extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
865     extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
866     extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
867     extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID  refguid);
868     extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD  PriorityNew);
869     extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
870     extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
871     extern D3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
872     /*** class static members ***/
873     void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
874
875     /*** IUnknown methods ***/
876     extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
877     extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
878     extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
879     /*** IWineD3DResource methods ***/
880     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
881     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
882     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
883     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
884     extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid);
885     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD  PriorityNew);
886     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
887     extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
888     extern D3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
889     /*** IWineD3DBaseTexture methods ***/
890     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
891     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
892     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
893     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, D3DTEXTUREFILTERTYPE FilterType);
894     extern D3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
895     extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
896     extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
897     extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
898     extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
899     extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
900     /*** class static members ***/
901     void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
902
903 /*****************************************************************************
904  * IDirect3DVertexShader implementation structure
905  */
906 typedef struct IWineD3DVertexShaderImpl {
907     /* IUnknown parts*/   
908     const IWineD3DVertexShaderVtbl *lpVtbl;
909     DWORD                       ref;     /* Note: Ref counting not required */
910
911     IUnknown                    *parent;
912     IWineD3DDeviceImpl          *wineD3DDevice;
913
914     /* IWineD3DVertexShaderImpl*/
915     CONST DWORD                 *function;
916     UINT                         functionLength;
917
918 #if 0 /* needs reworking */
919     DWORD usage;
920     DWORD version;
921     /* run time datas */
922     VSHADERDATA* data;
923     VSHADERINPUTDATA input;
924     VSHADEROUTPUTDATA output;
925 #endif
926 } IWineD3DVertexShaderImpl;
927 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
928
929 /*****************************************************************************
930  * IDirect3DPixelShader implementation structure
931  */
932 typedef struct IWineD3DPixelShaderImpl {
933     /* IUnknown parts*/   
934     const IWineD3DPixelShaderVtbl *lpVtbl;
935     DWORD                       ref;     /* Note: Ref counting not required */
936     
937     IUnknown                   *parent;
938     IWineD3DDeviceImpl         *wineD3DDevice;
939
940     
941     /* IWineD3DPixelShaderImpl*/
942     CONST DWORD                *function;
943     UINT                        functionLength;
944
945 #if 0 /* needs reworking */
946     UINT functionLength;
947     DWORD version;
948     /* run time datas */
949     PSHADERDATA* data;
950     PSHADERINPUTDATA input;
951     PSHADEROUTPUTDATA output;
952 #endif
953 } IWineD3DPixelShaderImpl;
954
955 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
956 #endif