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