Correct crypt context init in CryptProtectData/CryptUnprotectData.
[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     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 IWineD3DVtbl IWineD3D_Vtbl;
327
328 /*****************************************************************************
329  * IWineD3DDevice implementation structure
330  */
331 typedef struct IWineD3DDeviceImpl
332 {
333     /* IUnknown fields      */
334     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 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     IWineD3DResourceVtbl   *lpVtbl;
435     IWineD3DResourceClass   resource;
436 } IWineD3DResourceImpl;
437
438 extern IWineD3DResourceVtbl IWineD3DResource_Vtbl;
439
440 /*****************************************************************************
441  * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
442  */
443 typedef struct IWineD3DVertexBufferImpl
444 {
445     /* IUnknown & WineD3DResource Information     */
446     IWineD3DVertexBufferVtbl *lpVtbl;
447     IWineD3DResourceClass     resource;
448
449     /* WineD3DVertexBuffer specifics */
450     DWORD                     FVF;
451
452 } IWineD3DVertexBufferImpl;
453
454 extern IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
455
456
457 /*****************************************************************************
458  * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
459  */
460 typedef struct IWineD3DIndexBufferImpl
461 {
462     /* IUnknown & WineD3DResource Information     */
463     IWineD3DIndexBufferVtbl *lpVtbl;
464     IWineD3DResourceClass     resource;
465
466     /* WineD3DVertexBuffer specifics */
467 } IWineD3DIndexBufferImpl;
468
469 extern IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
470
471 /*****************************************************************************
472  * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
473  */
474 typedef struct IWineD3DBaseTextureClass
475 {
476     UINT                    levels;
477     BOOL                    dirty;
478     D3DFORMAT               format;
479     DWORD                   usage;
480     UINT                    textureName;    
481     UINT                    LOD;
482     D3DTEXTUREFILTERTYPE    filterType;
483
484 } IWineD3DBaseTextureClass;
485
486 typedef struct IWineD3DBaseTextureImpl
487 {
488     /* IUnknown & WineD3DResource Information     */
489     IWineD3DBaseTextureVtbl  *lpVtbl;
490     IWineD3DResourceClass     resource;
491     IWineD3DBaseTextureClass  baseTexture;
492
493 } IWineD3DBaseTextureImpl;
494
495 extern IWineD3DBaseTextureVtbl IWineD3DBaseTexture_Vtbl;
496
497 /*****************************************************************************
498  * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
499  */
500 typedef struct IWineD3DTextureImpl
501 {
502     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
503     IWineD3DTextureVtbl      *lpVtbl;
504     IWineD3DResourceClass     resource;
505     IWineD3DBaseTextureClass  baseTexture;
506
507     /* IWineD3DTexture */
508     IWineD3DSurface          *surfaces[MAX_LEVELS];
509     
510     UINT                      width;
511     UINT                      height;
512
513 } IWineD3DTextureImpl;
514
515 extern IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
516
517 /*****************************************************************************
518  * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
519  */
520 typedef struct IWineD3DCubeTextureImpl
521 {
522     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
523     IWineD3DCubeTextureVtbl  *lpVtbl;
524     IWineD3DResourceClass     resource;
525     IWineD3DBaseTextureClass  baseTexture;
526
527     /* IWineD3DCubeTexture */
528     IWineD3DSurface          *surfaces[6][MAX_LEVELS];
529
530     UINT                      edgeLength;
531
532 } IWineD3DCubeTextureImpl;
533
534 extern IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
535
536 /*****************************************************************************
537  * IWineD3DVolume implementation structure (extends IUnknown)
538  */
539 typedef struct IWineD3DVolumeImpl
540 {
541     /* IUnknown & WineD3DResource fields */
542     IWineD3DVolumeVtbl        *lpVtbl;
543     IWineD3DResourceClass      resource;
544
545     /* WineD3DVolume Information */
546     D3DVOLUME_DESC          currentDesc;
547     IUnknown               *container;
548     UINT                    bytesPerPixel;
549
550     BOOL                    lockable;
551     BOOL                    locked;
552     D3DBOX                  lockedBox;
553     D3DBOX                  dirtyBox;
554     BOOL                    dirty;
555
556
557 } IWineD3DVolumeImpl;
558
559 extern IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
560
561 /*****************************************************************************
562  * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
563  */
564 typedef struct IWineD3DVolumeTextureImpl
565 {
566     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
567     IWineD3DVolumeTextureVtbl *lpVtbl;
568     IWineD3DResourceClass     resource;
569     IWineD3DBaseTextureClass  baseTexture;
570
571     /* IWineD3DVolumeTexture */
572     IWineD3DVolume           *volumes[MAX_LEVELS];
573
574     UINT                      width;
575     UINT                      height;
576     UINT                      depth;
577 } IWineD3DVolumeTextureImpl;
578
579 extern IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
580
581 typedef struct _WINED3DSURFACET_DESC
582 {
583     UINT                Level;
584     D3DMULTISAMPLE_TYPE MultiSampleType;
585     DWORD               MultiSampleQuality;
586     UINT                Width;
587     UINT                Height;
588 } WINED3DSURFACET_DESC;
589
590 /*****************************************************************************
591  * IWineD3DSurface implementation structure
592  */
593 struct IWineD3DSurfaceImpl
594 {
595     /* IUnknown & IWineD3DResource Information     */
596     IWineD3DSurfaceVtbl      *lpVtbl;
597     IWineD3DResourceClass     resource;
598
599     /* IWineD3DSurface fields */
600     IUnknown                 *container;
601     WINED3DSURFACET_DESC      currentDesc;
602
603     UINT                      textureName;
604     UINT                      bytesPerPixel;
605     
606     BOOL                      lockable;
607     BOOL                      discard;
608     BOOL                      locked;
609     
610     RECT                      lockedRect;
611     RECT                      dirtyRect;
612     BOOL                      Dirty;
613     
614     BOOL                      inTexture;
615     BOOL                      inPBuffer;
616 };
617
618 extern IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
619
620 /*****************************************************************************
621  * IWineD3DVertexDeclaration implementation structure
622  */
623 typedef struct IWineD3DVertexDeclarationImpl {
624  /* IUnknown  Information     */
625   IWineD3DVertexDeclarationVtbl *lpVtbl;
626   DWORD                   ref;     /* Note: Ref counting not required */
627
628   IUnknown               *parent;
629   /** precomputed fvf if simple declaration */
630   IWineD3DDeviceImpl     *wineD3DDevice;
631   DWORD   fvf[MAX_STREAMS];
632   DWORD   allFVF;
633
634   /** dx8 compatible Declaration fields */
635   DWORD*  pDeclaration8;
636   DWORD   declaration8Length;
637
638   /** dx9+ */
639   D3DVERTEXELEMENT9* pDeclaration9;
640   UINT               declaration9NumElements;
641 } IWineD3DVertexDeclarationImpl;
642
643 extern IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
644
645 /*****************************************************************************
646  * IWineD3DStateBlock implementation structure
647  */
648
649 /* Internal state Block for Begin/End/Capture/Create/Apply info  */
650 /*   Note: Very long winded but gl Lists are not flexible enough */
651 /*   to resolve everything we need, so doing it manually for now */
652 typedef struct SAVEDSTATES {
653         BOOL                      indices;
654         BOOL                      material;
655         BOOL                      fvf;
656         BOOL                      stream_source[MAX_STREAMS];
657         BOOL                      textures[8];
658         BOOL                      transform[HIGHEST_TRANSFORMSTATE];
659         BOOL                      viewport;
660         BOOL                      renderState[WINEHIGHEST_RENDER_STATE];
661         BOOL                      textureState[8][HIGHEST_TEXTURE_STATE];
662         BOOL                      clipplane[MAX_CLIPPLANES];
663         BOOL                      vertexDecl;
664         BOOL                      pixelShader;
665         BOOL                      vertexShader;        
666 } SAVEDSTATES;
667
668 struct IWineD3DStateBlockImpl
669 {
670     /* IUnknown fields */
671     IWineD3DStateBlockVtbl   *lpVtbl;
672     DWORD                     ref;     /* Note: Ref counting not required */
673     
674     /* IWineD3DStateBlock information */
675     IUnknown                 *parent;
676     IWineD3DDeviceImpl       *wineD3DDevice;
677     D3DSTATEBLOCKTYPE         blockType;
678
679     /* Array indicating whether things have been set or changed */
680     SAVEDSTATES               changed;
681     SAVEDSTATES               set;
682   
683     /* Drawing - Vertex Shader or FVF related */
684     DWORD                     fvf;
685     /* Vertex Shader Declaration */
686     IWineD3DVertexDeclaration* vertexDecl;
687
688     void                     *vertexShader; /* @TODO: Replace void * with IWineD3DVertexShader * */
689
690     /* Stream Source */
691     BOOL                      streamIsUP;
692     UINT                      stream_stride[MAX_STREAMS];
693     UINT                      stream_offset[MAX_STREAMS];
694     IWineD3DVertexBuffer     *stream_source[MAX_STREAMS];
695
696     /* Indices */
697     IWineD3DIndexBuffer*      pIndexData;
698     UINT                      baseVertexIndex; /* Note: only used for d3d8 */
699
700     /* Transform */
701     D3DMATRIX                 transforms[HIGHEST_TRANSFORMSTATE];
702
703     /* Lights */
704     PLIGHTINFOEL             *lights; /* NOTE: active GL lights must be front of the chain */
705     
706     /* Clipping */
707     double                    clipplane[MAX_CLIPPLANES][4];
708     WINED3DCLIPSTATUS         clip_status;
709
710     /* ViewPort */
711     WINED3DVIEWPORT           viewport;
712
713     /* Material */
714     WINED3DMATERIAL           material;
715
716     /* Indexed Vertex Blending */
717     D3DVERTEXBLENDFLAGS       vertex_blend;
718     FLOAT                     tween_factor;
719
720     /* RenderState */
721     DWORD                     renderState[WINEHIGHEST_RENDER_STATE];
722
723     /* Texture */
724     IWineD3DBaseTexture      *textures[8];
725     int                       textureDimensions[8];
726
727     /* Texture State Stage */
728     DWORD                     textureState[8][HIGHEST_TEXTURE_STATE];
729
730 };
731
732 extern IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
733
734 /*****************************************************************************
735  * IWineD3DQueryImpl implementation structure (extends IUnknown)
736  */
737 typedef struct IWineD3DQueryImpl
738 {
739     IWineD3DQueryVtbl        *lpVtbl;
740     DWORD                     ref;     /* Note: Ref counting not required */
741     
742     IUnknown                 *parent;
743     /*TODO: replace with iface usage */
744 #if 0
745     IWineD3DDevice         *wineD3DDevice;
746 #else
747     IWineD3DDeviceImpl       *wineD3DDevice;
748 #endif
749     /* IWineD3DQuery fields */
750
751     D3DQUERYTYPE              type;
752     void                     *extendedData;
753     
754   
755 } IWineD3DQueryImpl;
756
757 extern IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
758
759 /*****************************************************************************
760  * Utility function prototypes 
761  */
762
763 /* Trace routines */
764 const char* debug_d3dformat(D3DFORMAT fmt);
765 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
766 const char* debug_d3dresourcetype(D3DRESOURCETYPE res);
767 const char* debug_d3dusage(DWORD usage);
768 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
769 const char* debug_d3drenderstate(DWORD state);
770 const char* debug_d3dtexturestate(DWORD state);
771 const char* debug_d3dpool(D3DPOOL pool);
772
773 /* Routines for GL <-> D3D values */
774 GLenum StencilOp(DWORD op);
775 void   set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
776 void   set_texture_matrix(const float *smat, DWORD flags);
777 void   GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
778
779 SHORT  D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
780 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
781 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
782 GLint  D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
783
784 /*****************************************************************************
785  * To enable calling of inherited functions, requires prototypes 
786  *
787  * Note: Only require classes which are subclassed, ie resource, basetexture, 
788  */
789     /*** IUnknown methods ***/
790     extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
791     extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
792     extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
793     /*** IWineD3DResource methods ***/
794     extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
795     extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
796     extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
797     extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
798     extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID  refguid);
799     extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD  PriorityNew);
800     extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
801     extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
802     extern D3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
803     /*** class static members ***/
804     void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
805
806     /*** IUnknown methods ***/
807     extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
808     extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
809     extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
810     /*** IWineD3DResource methods ***/
811     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
812     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
813     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
814     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
815     extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid);
816     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD  PriorityNew);
817     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
818     extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
819     extern D3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
820     /*** IWineD3DBaseTexture methods ***/
821     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
822     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
823     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
824     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, D3DTEXTUREFILTERTYPE FilterType);
825     extern D3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
826     extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
827     extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
828     extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
829     extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
830     extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
831     /*** class static members ***/
832     void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
833
834 /*****************************************************************************
835  * IDirect3DVertexShader implementation structure
836  */
837 typedef struct IWineD3DVertexShaderImpl {
838     /* IUnknown parts*/   
839     IWineD3DVertexShaderVtbl    *lpVtbl;
840     DWORD                       ref;     /* Note: Ref counting not required */
841
842     IUnknown                    *parent;
843     IWineD3DDeviceImpl          *wineD3DDevice;
844
845     /* IWineD3DVertexShaderImpl*/
846     CONST DWORD                 *function;
847     UINT                         functionLength;
848
849 #if 0 /* needs reworking */
850     DWORD usage;
851     DWORD version;
852     /* run time datas */
853     VSHADERDATA* data;
854     VSHADERINPUTDATA input;
855     VSHADEROUTPUTDATA output;
856 #endif
857 } IWineD3DVertexShaderImpl;
858 extern IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
859
860 /*****************************************************************************
861  * IDirect3DPixelShader implementation structure
862  */
863 typedef struct IWineD3DPixelShaderImpl {
864     /* IUnknown parts*/   
865     IWineD3DPixelShaderVtbl    *lpVtbl;
866     DWORD                       ref;     /* Note: Ref counting not required */
867     
868     IUnknown                   *parent;
869     IWineD3DDeviceImpl         *wineD3DDevice;
870
871     
872     /* IWineD3DPixelShaderImpl*/
873     CONST DWORD                *function;
874     UINT                        functionLength;
875
876 #if 0 /* needs reworking */
877     UINT functionLength;
878     DWORD version;
879     /* run time datas */
880     PSHADERDATA* data;
881     PSHADERINPUTDATA input;
882     PSHADEROUTPUTDATA output;
883 #endif
884 } IWineD3DPixelShaderImpl;
885
886 extern IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
887 #endif