wined3d: Improve Sampler support on 2.0 and 3.0 shaders.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 "ddraw.h"
43 #include "wine/wined3d_interface.h"
44 #include "wine/wined3d_gl.h"
45 #include "wine/list.h"
46
47 /* Device caps */
48 #define MAX_PALETTES      256
49 #define MAX_STREAMS       16
50 #define MAX_TEXTURES      8
51 #define MAX_SAMPLERS      16
52 #define MAX_ACTIVE_LIGHTS 8
53 #define MAX_CLIPPLANES    D3DMAXUSERCLIPPLANES
54 #define MAX_LEVELS        256
55
56 #define MAX_VSHADER_CONSTANTS 96
57 #define MAX_PSHADER_CONSTANTS 32
58
59 /* Used for CreateStateBlock */
60 #define NUM_SAVEDPIXELSTATES_R     35
61 #define NUM_SAVEDPIXELSTATES_T     18
62 #define NUM_SAVEDPIXELSTATES_S     12
63 #define NUM_SAVEDVERTEXSTATES_R    31
64 #define NUM_SAVEDVERTEXSTATES_T    2
65 #define NUM_SAVEDVERTEXSTATES_S    1
66
67 extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
68 extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
69 extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
70 extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
71 extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
72 extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
73
74 typedef enum _WINELOOKUP {
75     WINELOOKUP_WARPPARAM = 0,
76     WINELOOKUP_MAGFILTER = 1,
77     MAX_LOOKUPS          = 2
78 } WINELOOKUP;
79
80 extern int minLookup[MAX_LOOKUPS];
81 extern int maxLookup[MAX_LOOKUPS];
82 extern DWORD *stateLookup[MAX_LOOKUPS];
83
84 extern DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
85
86 typedef struct _WINED3DGLTYPE {
87     int         d3dType;
88     GLint       size;
89     GLenum      glType;
90     GLboolean   normalized;
91     int         typesize;
92 } WINED3DGLTYPE;
93
94 /* NOTE: Make sure these are in the correct numerical order. (see /include/d3d9types.h typedef enum _D3DDECLTYPE) */
95 WINED3DGLTYPE static const glTypeLookup[D3DDECLTYPE_UNUSED] = {
96                                   {D3DDECLTYPE_FLOAT1,    1, GL_FLOAT           , GL_FALSE ,sizeof(float)},
97                                   {D3DDECLTYPE_FLOAT2,    2, GL_FLOAT           , GL_FALSE ,sizeof(float)},
98                                   {D3DDECLTYPE_FLOAT3,    3, GL_FLOAT           , GL_FALSE ,sizeof(float)},
99                                   {D3DDECLTYPE_FLOAT4,    4, GL_FLOAT           , GL_FALSE ,sizeof(float)},
100                                   {D3DDECLTYPE_D3DCOLOR,  4, GL_UNSIGNED_BYTE   , GL_TRUE  ,sizeof(BYTE)},
101                                   {D3DDECLTYPE_UBYTE4,    4, GL_UNSIGNED_BYTE   , GL_FALSE ,sizeof(BYTE)},
102                                   {D3DDECLTYPE_SHORT2,    2, GL_SHORT           , GL_FALSE ,sizeof(short int)},
103                                   {D3DDECLTYPE_SHORT4,    4, GL_SHORT           , GL_FALSE ,sizeof(short int)},
104                                   {D3DDECLTYPE_UBYTE4N,   4, GL_UNSIGNED_BYTE   , GL_FALSE ,sizeof(BYTE)},
105                                   {D3DDECLTYPE_SHORT2N,   2, GL_SHORT           , GL_FALSE ,sizeof(short int)},
106                                   {D3DDECLTYPE_SHORT4N,   4, GL_SHORT           , GL_FALSE ,sizeof(short int)},
107                                   {D3DDECLTYPE_USHORT2N,  2, GL_UNSIGNED_SHORT  , GL_FALSE ,sizeof(short int)},
108                                   {D3DDECLTYPE_USHORT4N,  4, GL_UNSIGNED_SHORT  , GL_FALSE ,sizeof(short int)},
109                                   {D3DDECLTYPE_UDEC3,     3, GL_UNSIGNED_SHORT  , GL_FALSE ,sizeof(short int)},
110                                   {D3DDECLTYPE_DEC3N,     3, GL_SHORT           , GL_FALSE ,sizeof(short int)},
111                                   {D3DDECLTYPE_FLOAT16_2, 2, GL_FLOAT           , GL_FALSE ,sizeof(short int)},
112                                   {D3DDECLTYPE_FLOAT16_4, 4, GL_FLOAT           , GL_FALSE ,sizeof(short int)}};
113
114 #define WINED3D_ATR_TYPE(_attribute)          glTypeLookup[sd->u.s._attribute.dwType].d3dType
115 #define WINED3D_ATR_SIZE(_attribute)          glTypeLookup[sd->u.s._attribute.dwType].size
116 #define WINED3D_ATR_GLTYPE(_attribute)        glTypeLookup[sd->u.s._attribute.dwType].glType
117 #define WINED3D_ATR_NORMALIZED(_attribute)    glTypeLookup[sd->u.s._attribute.dwType].normalized
118 #define WINED3D_ATR_TYPESIZE(_attribute)      glTypeLookup[sd->u.s._attribute.dwType].typesize
119
120 /**
121  * Settings 
122  */
123 #define VS_NONE    0
124 #define VS_HW      1
125 #define VS_SW      2
126
127 #define PS_NONE    0
128 #define PS_HW      1
129
130 #define VBO_NONE   0
131 #define VBO_HW     1
132
133 #define NP2_NONE   0
134 #define NP2_REPACK 1
135
136 #define SHADER_SW   0
137 #define SHADER_ARB  1
138 #define SHADER_GLSL 2
139
140 typedef struct wined3d_settings_s {
141 /* vertex and pixel shader modes */
142   int vs_mode;
143   int ps_mode;
144   int vbo_mode;
145 /* Ideally, we don't want the user to have to request GLSL.  If the hardware supports GLSL,
146     we should use it.  However, until it's fully implemented, we'll leave it as a registry
147     setting for developers. */
148   BOOL glslRequested;
149   int shader_mode;
150 /* nonpower 2 function */
151   int nonpower2_mode;
152 } wined3d_settings_t;
153
154 extern wined3d_settings_t wined3d_settings;
155
156 /* X11 locking */
157
158 extern void (*wine_tsx11_lock_ptr)(void);
159 extern void (*wine_tsx11_unlock_ptr)(void);
160
161 /* As GLX relies on X, this is needed */
162 extern int num_lock;
163
164 #if 0
165 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
166 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
167 #else
168 #define ENTER_GL() wine_tsx11_lock_ptr()
169 #define LEAVE_GL() wine_tsx11_unlock_ptr()
170 #endif
171
172 /*****************************************************************************
173  * Defines
174  */
175
176 /* GL related defines */
177 /* ------------------ */
178 #define GL_SUPPORT(ExtName)           (GLINFO_LOCATION.supported[ExtName] != 0)
179 #define GL_LIMITS(ExtName)            (GLINFO_LOCATION.max_##ExtName)
180 #define GL_EXTCALL(FuncName)          (GLINFO_LOCATION.FuncName)
181 #define GL_VEND(_VendName)            (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
182
183 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
184 #define D3DCOLOR_B_G(dw) (((dw) >>  8) & 0xFF)
185 #define D3DCOLOR_B_B(dw) (((dw) >>  0) & 0xFF)
186 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
187
188 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
189 #define D3DCOLOR_G(dw) (((float) (((dw) >>  8) & 0xFF)) / 255.0f)
190 #define D3DCOLOR_B(dw) (((float) (((dw) >>  0) & 0xFF)) / 255.0f)
191 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
192
193 #define D3DCOLORTOGLFLOAT4(dw, vec) \
194   (vec)[0] = D3DCOLOR_R(dw); \
195   (vec)[1] = D3DCOLOR_G(dw); \
196   (vec)[2] = D3DCOLOR_B(dw); \
197   (vec)[3] = D3DCOLOR_A(dw);
198
199 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP_ARB
200
201 /* DirectX Device Limits */
202 /* --------------------- */
203 #define MAX_LEVELS  256  /* Maximum number of mipmap levels. Guessed at 256 */
204
205 #define MAX_STREAMS  16  /* Maximum possible streams - used for fixed size arrays
206                             See MaxStreams in MSDN under GetDeviceCaps */
207                          /* Maximum number of constants provided to the shaders */
208 #define HIGHEST_TRANSFORMSTATE 512 
209                          /* Highest value in D3DTRANSFORMSTATETYPE */
210 #define MAX_CLIPPLANES  D3DMAXUSERCLIPPLANES
211
212 #define MAX_PALETTES      256
213
214 /* Checking of API calls */
215 /* --------------------- */
216 #define checkGLcall(A)                                          \
217 {                                                               \
218     GLint err = glGetError();                                   \
219     if (err == GL_NO_ERROR) {                                   \
220        TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__);    \
221                                                                 \
222     } else do {                                                 \
223        FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n",        \
224                 err, A, __FILE__, __LINE__);                    \
225        err = glGetError();                                      \
226     } while (err != GL_NO_ERROR);                               \
227
228
229 /* Trace routines / diagnostics */
230 /* ---------------------------- */
231
232 /* Dump out a matrix and copy it */
233 #define conv_mat(mat,gl_mat)                                                                \
234 do {                                                                                        \
235     TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
236     TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
237     TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
238     TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
239     memcpy(gl_mat, (mat), 16 * sizeof(float));                                              \
240 } while (0)
241
242 /* Macro to dump out the current state of the light chain */
243 #define DUMP_LIGHT_CHAIN()                    \
244 {                                             \
245   PLIGHTINFOEL *el = This->stateBlock->lights;\
246   while (el) {                                \
247     TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
248     el = el->next;                            \
249   }                                           \
250 }
251
252 /* Trace vector and strided data information */
253 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
254 #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);
255
256 /* Defines used for optimizations */
257
258 /*    Only reapply what is necessary */
259 #define REAPPLY_ALPHAOP  0x0001
260 #define REAPPLY_ALL      0xFFFF
261
262 /* Advance declaration of structures to satisfy compiler */
263 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
264 typedef struct IWineD3DSurfaceImpl    IWineD3DSurfaceImpl;
265 typedef struct IWineD3DPaletteImpl    IWineD3DPaletteImpl;
266
267 /* Tracking */
268
269 /* TODO: Move some of this to the device */
270 long globalChangeGlRam(long glram);
271
272 /* Memory and object tracking */
273
274 /*Structure for holding information on all direct3d objects
275 useful for making sure tracking is ok and when release is called on a device!
276 and probably quite handy for debugging and dumping states out
277 */
278 typedef struct WineD3DGlobalStatistics {
279     int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
280 } WineD3DGlobalStatistics;
281
282 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
283
284 /* Global variables */
285 extern const float identity[16];
286
287 /*****************************************************************************
288  * Compilable extra diagnostics
289  */
290
291 /* Trace information per-vertex: (extremely high amount of trace) */
292 #if 0 /* NOTE: Must be 0 in cvs */
293 # define VTRACE(A) TRACE A
294 #else 
295 # define VTRACE(A) 
296 #endif
297
298 /* Checking of per-vertex related GL calls */
299 /* --------------------- */
300 #define vcheckGLcall(A)                                         \
301 {                                                               \
302     GLint err = glGetError();                                   \
303     if (err == GL_NO_ERROR) {                                   \
304        VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
305                                                                 \
306     } else do {                                                 \
307        FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n",        \
308                 err, A, __FILE__, __LINE__);                    \
309        err = glGetError();                                      \
310     } while (err != GL_NO_ERROR);                               \
311 }
312
313 /* TODO: Confirm each of these works when wined3d move completed */
314 #if 0 /* NOTE: Must be 0 in cvs */
315   /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
316      of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
317      is enabled, and if it doesn't exists it is disabled.                                           */
318 # define FRAME_DEBUGGING
319   /*  Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
320       the file is deleted                                                                            */
321 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
322 #  define SINGLE_FRAME_DEBUGGING
323 # endif  
324   /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
325      It can only be enabled when FRAME_DEBUGGING is also enabled                               
326      The contents of the back buffer are written into /tmp/backbuffer_* after each primitive 
327      array is drawn.                                                                            */
328 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */                                                                                       
329 #  define SHOW_FRAME_MAKEUP 1
330 # endif  
331   /* The following, when enabled, lets you see the makeup of the all the textures used during each
332      of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
333      The contents of the textures assigned to each stage are written into 
334      /tmp/texture_*_<Stage>.ppm after each primitive array is drawn.                            */
335 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
336 #  define SHOW_TEXTURE_MAKEUP 0
337 # endif  
338 extern BOOL isOn;
339 extern BOOL isDumpingFrames;
340 extern LONG primCounter;
341 #endif
342
343 /*****************************************************************************
344  * Prototypes
345  */
346
347 /* Routine common to the draw primitive and draw indexed primitive routines */
348 void drawPrimitive(IWineD3DDevice *iface,
349                     int PrimitiveType,
350                     long NumPrimitives,
351                     /* for Indexed: */
352                     long  StartVertexIndex,
353                     UINT  numberOfVertices,
354                     long  StartIdx,
355                     short idxBytes,
356                     const void *idxData,
357                     int   minIndex,
358                     WineDirect3DVertexStridedData *DrawPrimStrideData);
359
360 void primitiveConvertToStridedData(IWineD3DDevice *iface,
361                                    WineDirect3DVertexStridedData *strided,
362                                    LONG BaseVertexIndex);
363
364 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
365
366 #define eps 1e-8
367
368 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
369     (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
370
371 /* Routine to fill gl caps for swapchains and IWineD3D */
372 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info,
373                              Display* display);
374
375 /*****************************************************************************
376  * Internal representation of a light
377  */
378 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
379 struct PLIGHTINFOEL {
380     WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
381     DWORD        OriginalIndex;
382     LONG         glIndex;
383     BOOL         lightEnabled;
384     BOOL         changed;
385     BOOL         enabledChanged;
386
387     /* Converted parms to speed up swapping lights */
388     float                         lightPosn[4];
389     float                         lightDirn[4];
390     float                         exponent;
391     float                         cutoff;
392
393     PLIGHTINFOEL *next;
394     PLIGHTINFOEL *prev;
395 };
396
397 /* The default light parameters */
398 extern const WINED3DLIGHT WINED3D_default_light;
399
400 /*****************************************************************************
401  * IWineD3D implementation structure
402  */
403 typedef struct IWineD3DImpl
404 {
405     /* IUnknown fields */
406     const IWineD3DVtbl     *lpVtbl;
407     LONG                    ref;     /* Note: Ref counting not required */
408
409     /* WineD3D Information */
410     IUnknown               *parent;
411     UINT                    dxVersion;
412
413     /* GL Information */
414     BOOL                    isGLInfoValid;
415     WineD3D_GL_Info         gl_info;
416 } IWineD3DImpl;
417
418 extern const IWineD3DVtbl IWineD3D_Vtbl;
419
420 /** Hacked out start of a context manager!! **/
421 typedef struct glContext {
422     int Width;
423     int Height;
424     int usedcount;
425     GLXContext context;
426
427     Drawable drawable;
428     IWineD3DSurface *pSurface;
429 #if 0 /* TODO: someway to represent the state of the context */
430     IWineD3DStateBlock *pStateBlock;
431 #endif
432 /* a few other things like format */
433 } glContext;
434
435 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
436 (since it will break quite a few things until contexts are managed properly!) */
437 extern BOOL pbuffer_support;
438 /* allocate one pbuffer per surface */
439 extern BOOL pbuffer_per_surface;
440
441 /* Maximum number of contexts/pbuffers to keep in cache,
442 set to 100 because ATI's drivers don't support deleting pBuffers properly
443 this needs to be migrated to a list and some option availalbe for controle the cache size.
444 */
445 #define CONTEXT_CACHE 100
446
447 typedef struct ResourceList {
448     IWineD3DResource         *resource;
449     struct ResourceList      *next;
450 } ResourceList;
451
452 /* A helper function that dumps a resource list */
453 void dumpResources(ResourceList *resources);
454
455 /*****************************************************************************
456  * IWineD3DDevice implementation structure
457  */
458 typedef struct IWineD3DDeviceImpl
459 {
460     /* IUnknown fields      */
461     const IWineD3DDeviceVtbl *lpVtbl;
462     LONG                    ref;     /* Note: Ref counting not required */
463
464     /* WineD3D Information  */
465     IUnknown               *parent;
466     IWineD3D               *wineD3D;
467
468     /* X and GL Information */
469     GLint                   maxConcurrentLights;
470
471     /* Optimization */
472     BOOL                    modelview_valid;
473     BOOL                    proj_valid;
474     BOOL                    view_ident;        /* true iff view matrix is identity                */
475     BOOL                    last_was_rhw;      /* true iff last draw_primitive was in xyzrhw mode */
476     BOOL                    viewport_changed;  /* Was the viewport changed since the last draw?   */
477     GLenum                  tracking_parm;     /* Which source is tracking current colour         */
478     LONG                    tracking_color;    /* used iff GL_COLOR_MATERIAL was enabled          */
479 #define                         DISABLED_TRACKING  0  /* Disabled                                 */
480 #define                         IS_TRACKING        1  /* tracking_parm is tracking diffuse color  */
481 #define                         NEEDS_TRACKING     2  /* Tracking needs to be enabled when needed */
482 #define                         NEEDS_DISABLE      3  /* Tracking needs to be disabled when needed*/
483     UINT                    srcBlend;
484     UINT                    dstBlend;
485     UINT                    alphafunc;
486     BOOL                    texture_shader_active;  /* TODO: Confirm use is correct */
487     BOOL                    last_was_notclipped;
488
489     /* State block related */
490     BOOL                    isRecordingState;
491     IWineD3DStateBlockImpl *stateBlock;
492     IWineD3DStateBlockImpl *updateStateBlock;
493
494     /* Internal use fields  */
495     WINED3DDEVICE_CREATION_PARAMETERS createParms;
496     UINT                            adapterNo;
497     D3DDEVTYPE                      devType;
498
499     IWineD3DSwapChain     **swapchains;
500     uint                    NumberOfSwapChains;
501
502     ResourceList           *resources; /* a linked list to track resources created by the device */
503
504     /* Render Target Support */
505     IWineD3DSurface        *depthStencilBuffer;
506
507     IWineD3DSurface        *renderTarget;
508     IWineD3DSurface        *stencilBufferTarget;
509
510     /* palettes texture management */
511     PALETTEENTRY            palettes[MAX_PALETTES][256];
512     UINT                    currentPalette;
513
514     /* For rendering to a texture using glCopyTexImage */
515     BOOL                    renderUpsideDown;
516
517     /* Cursor management */
518     BOOL                    bCursorVisible;
519     UINT                    xHotSpot;
520     UINT                    yHotSpot;
521     UINT                    xScreenSpace;
522     UINT                    yScreenSpace;
523
524     /* Textures for when no other textures are mapped */
525     UINT                          dummyTextureName[MAX_TEXTURES];
526
527     /* Debug stream management */
528     BOOL                     debug;
529
530     /* Device state management */
531     HRESULT                 state;
532     BOOL                    d3d_initialized;
533
534     /* Screen buffer resources */
535     glContext contextCache[CONTEXT_CACHE];
536
537     /* A flag to check if endscene has been called before changing the render tartet */
538     BOOL sceneEnded;
539
540     /* process vertex shaders using software or hardware */
541     BOOL softwareVertexProcessing;
542
543     /* DirectDraw stuff */
544     HWND ddraw_window;
545     IWineD3DSurface *ddraw_primary;
546     DWORD ddraw_width, ddraw_height;
547     WINED3DFORMAT ddraw_format;
548
549     /* List of GLSL shader programs and their associated vertex & pixel shaders */
550     struct list glsl_shader_progs;
551
552 } IWineD3DDeviceImpl;
553
554 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
555
556 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
557  * anybody uses it for much so a good implementation is optional. */
558 typedef struct PrivateData
559 {
560     struct PrivateData* next;
561
562     GUID tag;
563     DWORD flags; /* DDSPD_* */
564     DWORD uniqueness_value;
565
566     union
567     {
568         LPVOID data;
569         LPUNKNOWN object;
570     } ptr;
571
572     DWORD size;
573 } PrivateData;
574
575 void d3ddevice_set_ortho(IWineD3DDeviceImpl *This);
576
577 /*****************************************************************************
578  * IWineD3DResource implementation structure
579  */
580 typedef struct IWineD3DResourceClass
581 {
582     /* IUnknown fields */
583     LONG                    ref;     /* Note: Ref counting not required */
584
585     /* WineD3DResource Information */
586     IUnknown               *parent;
587     WINED3DRESOURCETYPE     resourceType;
588     IWineD3DDeviceImpl     *wineD3DDevice;
589     WINED3DPOOL             pool;
590     UINT                    size;
591     DWORD                   usage;
592     WINED3DFORMAT           format;
593     BYTE                   *allocatedMemory;
594     PrivateData            *privateData;
595
596 } IWineD3DResourceClass;
597
598 typedef struct IWineD3DResourceImpl
599 {
600     /* IUnknown & WineD3DResource Information     */
601     const IWineD3DResourceVtbl *lpVtbl;
602     IWineD3DResourceClass   resource;
603 } IWineD3DResourceImpl;
604
605
606 /*****************************************************************************
607  * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
608  */
609 typedef struct IWineD3DVertexBufferImpl
610 {
611     /* IUnknown & WineD3DResource Information     */
612     const IWineD3DVertexBufferVtbl *lpVtbl;
613     IWineD3DResourceClass     resource;
614
615     /* WineD3DVertexBuffer specifics */
616     DWORD                     fvf;
617
618 } IWineD3DVertexBufferImpl;
619
620 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
621
622
623 /*****************************************************************************
624  * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
625  */
626 typedef struct IWineD3DIndexBufferImpl
627 {
628     /* IUnknown & WineD3DResource Information     */
629     const IWineD3DIndexBufferVtbl *lpVtbl;
630     IWineD3DResourceClass     resource;
631
632     /* WineD3DVertexBuffer specifics */
633 } IWineD3DIndexBufferImpl;
634
635 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
636
637 /*****************************************************************************
638  * IWineD3DBaseTexture D3D- > openGL state map lookups
639  */
640 #define WINED3DFUNC_NOTSUPPORTED  -2
641 #define WINED3DFUNC_UNIMPLEMENTED -1
642
643 typedef enum winetexturestates {
644     WINED3DTEXSTA_ADDRESSU       = 0,
645     WINED3DTEXSTA_ADDRESSV       = 1,
646     WINED3DTEXSTA_ADDRESSW       = 2,
647     WINED3DTEXSTA_BORDERCOLOR    = 3,
648     WINED3DTEXSTA_MAGFILTER      = 4,
649     WINED3DTEXSTA_MINFILTER      = 5,
650     WINED3DTEXSTA_MIPFILTER      = 6,
651     WINED3DTEXSTA_MAXMIPLEVEL    = 7,
652     WINED3DTEXSTA_MAXANISOTROPY  = 8,
653     WINED3DTEXSTA_SRGBTEXTURE    = 9,
654     WINED3DTEXSTA_ELEMENTINDEX   = 10,
655     WINED3DTEXSTA_DMAPOFFSET     = 11,
656     WINED3DTEXSTA_TSSADDRESSW    = 12,
657     MAX_WINETEXTURESTATES        = 13,
658 } winetexturestates;
659
660 typedef struct Wined3dTextureStateMap {
661     CONST int state;
662     int function;
663 } Wined3dTextureStateMap;
664
665 /*****************************************************************************
666  * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
667  */
668 typedef struct IWineD3DBaseTextureClass
669 {
670     UINT                    levels;
671     BOOL                    dirty;
672     D3DFORMAT               format;
673     DWORD                   usage;
674     UINT                    textureName;
675     UINT                    LOD;
676     WINED3DTEXTUREFILTERTYPE filterType;
677     DWORD                   states[MAX_WINETEXTURESTATES];
678
679 } IWineD3DBaseTextureClass;
680
681 typedef struct IWineD3DBaseTextureImpl
682 {
683     /* IUnknown & WineD3DResource Information     */
684     const IWineD3DBaseTextureVtbl *lpVtbl;
685     IWineD3DResourceClass     resource;
686     IWineD3DBaseTextureClass  baseTexture;
687
688 } IWineD3DBaseTextureImpl;
689
690 /*****************************************************************************
691  * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
692  */
693 typedef struct IWineD3DTextureImpl
694 {
695     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
696     const IWineD3DTextureVtbl *lpVtbl;
697     IWineD3DResourceClass     resource;
698     IWineD3DBaseTextureClass  baseTexture;
699
700     /* IWineD3DTexture */
701     IWineD3DSurface          *surfaces[MAX_LEVELS];
702     
703     UINT                      width;
704     UINT                      height;
705     float                     pow2scalingFactorX;
706     float                     pow2scalingFactorY;
707
708 } IWineD3DTextureImpl;
709
710 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
711
712 /*****************************************************************************
713  * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
714  */
715 typedef struct IWineD3DCubeTextureImpl
716 {
717     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
718     const IWineD3DCubeTextureVtbl *lpVtbl;
719     IWineD3DResourceClass     resource;
720     IWineD3DBaseTextureClass  baseTexture;
721
722     /* IWineD3DCubeTexture */
723     IWineD3DSurface          *surfaces[6][MAX_LEVELS];
724
725     UINT                      edgeLength;
726     float                     pow2scalingFactor;
727
728 } IWineD3DCubeTextureImpl;
729
730 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
731
732 typedef struct _WINED3DVOLUMET_DESC
733 {
734     UINT                    Width;
735     UINT                    Height;
736     UINT                    Depth;
737 } WINED3DVOLUMET_DESC;
738
739 /*****************************************************************************
740  * IWineD3DVolume implementation structure (extends IUnknown)
741  */
742 typedef struct IWineD3DVolumeImpl
743 {
744     /* IUnknown & WineD3DResource fields */
745     const IWineD3DVolumeVtbl  *lpVtbl;
746     IWineD3DResourceClass      resource;
747
748     /* WineD3DVolume Information */
749     WINED3DVOLUMET_DESC      currentDesc;
750     IWineD3DBase            *container;
751     UINT                    bytesPerPixel;
752
753     BOOL                    lockable;
754     BOOL                    locked;
755     WINED3DBOX              lockedBox;
756     WINED3DBOX              dirtyBox;
757     BOOL                    dirty;
758
759
760 } IWineD3DVolumeImpl;
761
762 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
763
764 /*****************************************************************************
765  * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
766  */
767 typedef struct IWineD3DVolumeTextureImpl
768 {
769     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
770     const IWineD3DVolumeTextureVtbl *lpVtbl;
771     IWineD3DResourceClass     resource;
772     IWineD3DBaseTextureClass  baseTexture;
773
774     /* IWineD3DVolumeTexture */
775     IWineD3DVolume           *volumes[MAX_LEVELS];
776
777     UINT                      width;
778     UINT                      height;
779     UINT                      depth;
780 } IWineD3DVolumeTextureImpl;
781
782 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
783
784 typedef struct _WINED3DSURFACET_DESC
785 {
786     WINED3DMULTISAMPLE_TYPE MultiSampleType;
787     DWORD                   MultiSampleQuality;
788     UINT                    Width;
789     UINT                    Height;
790 } WINED3DSURFACET_DESC;
791
792 /*****************************************************************************
793  * Structure for DIB Surfaces (GetDC and GDI surfaces)
794  */
795 typedef struct wineD3DSurface_DIB {
796     HBITMAP DIBsection;
797     void* bitmap_data;
798     HGDIOBJ holdbitmap;
799     BOOL client_memory;
800 } wineD3DSurface_DIB;
801
802 /*****************************************************************************
803  * IWineD3DSurface implementation structure
804  */
805 struct IWineD3DSurfaceImpl
806 {
807     /* IUnknown & IWineD3DResource Information     */
808     const IWineD3DSurfaceVtbl *lpVtbl;
809     IWineD3DResourceClass     resource;
810
811     /* IWineD3DSurface fields */
812     IWineD3DBase              *container;
813     WINED3DSURFACET_DESC      currentDesc;
814     IWineD3DPaletteImpl      *palette;
815
816     UINT                      textureName;
817     UINT                      bytesPerPixel;
818
819     /* TODO: move this off into a management class(maybe!) */
820     WORD                      Flags;
821
822     UINT                      pow2Width;
823     UINT                      pow2Height;
824     UINT                      pow2Size;
825
826     /* Oversized texture */
827     RECT                      glRect;
828
829 #if 0
830     /* precalculated x and y scalings for texture coords */
831     float                     pow2scalingFactorX; /* =  (Width  / pow2Width ) */
832     float                     pow2scalingFactorY; /* =  (Height / pow2Height) */
833 #endif
834
835     RECT                      lockedRect;
836     RECT                      dirtyRect;
837
838     glDescriptor              glDescription;
839
840     /* For GetDC */
841     wineD3DSurface_DIB        dib;
842     HDC                       hDC;
843
844     /* Color keys for DDraw */
845     DDCOLORKEY                DestBltCKey;
846     DDCOLORKEY                DestOverlayCKey;
847     DDCOLORKEY                SrcOverlayCKey;
848     DDCOLORKEY                SrcBltCKey;
849     DWORD                     CKeyFlags;
850
851 };
852
853 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
854 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
855
856 /* Predeclare the shared Surface functions */
857 HRESULT WINAPI IWineD3DSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
858 ULONG WINAPI IWineD3DSurfaceImpl_AddRef(IWineD3DSurface *iface);
859 ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface);
860 HRESULT WINAPI IWineD3DSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
861 HRESULT WINAPI IWineD3DSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
862 HRESULT WINAPI IWineD3DSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
863 HRESULT WINAPI IWineD3DSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
864 HRESULT WINAPI IWineD3DSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
865 DWORD   WINAPI IWineD3DSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
866 DWORD   WINAPI IWineD3DSurfaceImpl_GetPriority(IWineD3DSurface *iface);
867 void    WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface);
868 WINED3DRESOURCETYPE WINAPI IWineD3DSurfaceImpl_GetType(IWineD3DSurface *iface);
869 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainerParent(IWineD3DSurface* iface, IUnknown **ppContainerParent);
870 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
871 HRESULT WINAPI IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
872 HRESULT WINAPI IWineD3DSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
873 HRESULT WINAPI IWineD3DSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
874 HRESULT WINAPI IWineD3DSurfaceImpl_IsLost(IWineD3DSurface *iface);
875 HRESULT WINAPI IWineD3DSurfaceImpl_Restore(IWineD3DSurface *iface);
876 HRESULT WINAPI IWineD3DSurfaceImpl_SetPixelFormat(IWineD3DSurface *iface, WINED3DFORMAT Format, BYTE *Surface, DWORD Size);
877 HRESULT WINAPI IWineD3DSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
878 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
879 HRESULT WINAPI IWineD3DSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, DDCOLORKEY *CKey);
880 HRESULT WINAPI IWineD3DSurfaceImpl_CleanDirtyRect(IWineD3DSurface *iface);
881 extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect);
882 HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
883 HRESULT WINAPI IWineD3DSurfaceImpl_SetPBufferState(IWineD3DSurface *iface, BOOL inPBuffer, BOOL  inTexture);
884 void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target);
885 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription);
886 const void *WINAPI IWineD3DSurfaceImpl_GetData(IWineD3DSurface *iface);
887 HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
888 HRESULT WINAPI IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx);
889 HRESULT WINAPI IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty, IWineD3DSurface *Source, RECT *rsrc, DWORD trans);
890 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
891 HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC);
892 HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC);
893 DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface);
894 HRESULT WINAPI IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
895
896 /* Surface flags: */
897 #define SFLAG_OVERSIZE    0x0001 /* Surface is bigger than gl size, blts only */
898 #define SFLAG_CONVERTED   0x0002 /* Converted for color keying or Palettized */
899 #define SFLAG_DIBSECTION  0x0004 /* Has a DIB section attached for getdc */
900 #define SFLAG_DIRTY       0x0008 /* Surface was locked by the app */
901 #define SFLAG_LOCKABLE    0x0010 /* Surface can be locked */
902 #define SFLAG_DISCARD     0x0020 /* ??? */
903 #define SFLAG_LOCKED      0x0040 /* Surface is locked atm */
904 #define SFLAG_ACTIVELOCK  0x0080 /* Not locked, but surface memory is needed */
905 #define SFLAG_INTEXTURE   0x0100 /* ??? */
906 #define SFLAG_INPBUFFER   0x0200 /* ??? */
907 #define SFLAG_NONPOW2     0x0400 /* Surface sizes are not a power of 2 */
908 #define SFLAG_DYNLOCK     0x0800 /* Surface is often locked by the app */
909 #define SFLAG_DYNCHANGE   0x1800 /* Surface contents are changed very often, implies DYNLOCK */
910 #define SFLAG_DCINUSE     0x2000 /* Set between GetDC and ReleaseDC calls */
911 #define SFLAG_GLDIRTY     0x4000 /* The opengl texture is more up to date than the surface mem */
912 #define SFLAG_LOST        0x8000 /* Surface lost flag for DDraw */
913
914 /* In some conditions the surface memory must not be freed:
915  * SFLAG_OVERSIZE: Not all data can be kept in GL
916  * SFLAG_CONVERTED: Converting the data back would take too long
917  * SFLAG_DIBSECTION: The dib code manages the memory
918  * SFLAG_DIRTY: GL surface isn't up to date
919  * SFLAG_LOCKED: The app requires access to the surface data
920  * SFLAG_ACTIVELOCK: Some wined3d code needs the memory
921  * SFLAG_DYNLOCK: Avoid freeing the data for performance
922  * SFLAG_DYNCHANGE: Same reason as DYNLOCK
923  */
924 #define SFLAG_DONOTFREE  (SFLAG_OVERSIZE   | \
925                           SFLAG_CONVERTED  | \
926                           SFLAG_DIBSECTION | \
927                           SFLAG_DIRTY      | \
928                           SFLAG_LOCKED     | \
929                           SFLAG_ACTIVELOCK | \
930                           SFLAG_DYNLOCK    | \
931                           SFLAG_DYNCHANGE    )
932
933 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
934
935 /*****************************************************************************
936  * IWineD3DVertexDeclaration implementation structure
937  */
938 typedef struct IWineD3DVertexDeclarationImpl {
939  /* IUnknown  Information     */
940   const IWineD3DVertexDeclarationVtbl *lpVtbl;
941   LONG                    ref;     /* Note: Ref counting not required */
942
943   IUnknown               *parent;
944   /** precomputed fvf if simple declaration */
945   IWineD3DDeviceImpl     *wineD3DDevice;
946   DWORD   fvf[MAX_STREAMS];
947   DWORD   allFVF;
948
949   /** dx8 compatible Declaration fields */
950   DWORD*  pDeclaration8;
951   DWORD   declaration8Length;
952
953   /** dx9+ */
954   D3DVERTEXELEMENT9 *pDeclaration9;
955   UINT               declaration9NumElements;
956
957   WINED3DVERTEXELEMENT  *pDeclarationWine;
958   UINT                   declarationWNumElements;
959   
960   float                 *constants;
961   
962 } IWineD3DVertexDeclarationImpl;
963
964 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
965
966 /*****************************************************************************
967  * IWineD3DStateBlock implementation structure
968  */
969
970 /* Internal state Block for Begin/End/Capture/Create/Apply info  */
971 /*   Note: Very long winded but gl Lists are not flexible enough */
972 /*   to resolve everything we need, so doing it manually for now */
973 typedef struct SAVEDSTATES {
974         BOOL                      indices;
975         BOOL                      material;
976         BOOL                      fvf;
977         BOOL                      streamSource[MAX_STREAMS];
978         BOOL                      streamFreq[MAX_STREAMS];
979         BOOL                      textures[MAX_TEXTURES];
980         BOOL                      transform[HIGHEST_TRANSFORMSTATE + 1];
981         BOOL                      viewport;
982         BOOL                      renderState[WINEHIGHEST_RENDER_STATE + 1];
983         BOOL                      textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
984         BOOL                      samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
985         BOOL                      clipplane[MAX_CLIPPLANES];
986         BOOL                      vertexDecl;
987         BOOL                      pixelShader;
988         BOOL                      pixelShaderConstantsB[MAX_PSHADER_CONSTANTS];
989         BOOL                      pixelShaderConstantsI[MAX_PSHADER_CONSTANTS];
990         BOOL                      pixelShaderConstantsF[MAX_PSHADER_CONSTANTS];
991         BOOL                      vertexShader;
992         BOOL                      vertexShaderConstantsB[MAX_VSHADER_CONSTANTS];
993         BOOL                      vertexShaderConstantsI[MAX_VSHADER_CONSTANTS];
994         BOOL                      vertexShaderConstantsF[MAX_VSHADER_CONSTANTS];
995 } SAVEDSTATES;
996
997 struct IWineD3DStateBlockImpl
998 {
999     /* IUnknown fields */
1000     const IWineD3DStateBlockVtbl *lpVtbl;
1001     LONG                      ref;     /* Note: Ref counting not required */
1002
1003     /* IWineD3DStateBlock information */
1004     IUnknown                 *parent;
1005     IWineD3DDeviceImpl       *wineD3DDevice;
1006     WINED3DSTATEBLOCKTYPE     blockType;
1007
1008     /* Array indicating whether things have been set or changed */
1009     SAVEDSTATES               changed;
1010     SAVEDSTATES               set;
1011
1012     /* Drawing - Vertex Shader or FVF related */
1013     DWORD                     fvf;
1014     /* Vertex Shader Declaration */
1015     IWineD3DVertexDeclaration *vertexDecl;
1016
1017     IWineD3DVertexShader      *vertexShader;
1018
1019     /* Vertex Shader Constants */
1020     BOOL                       vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
1021     INT                        vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
1022     float                      vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
1023
1024     /* Stream Source */
1025     BOOL                      streamIsUP;
1026     UINT                      streamStride[MAX_STREAMS];
1027     UINT                      streamOffset[MAX_STREAMS];
1028     IWineD3DVertexBuffer     *streamSource[MAX_STREAMS];
1029     UINT                      streamFreq[MAX_STREAMS];
1030     UINT                      streamFlags[MAX_STREAMS];     /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA  */
1031
1032     /* Indices */
1033     IWineD3DIndexBuffer*      pIndexData;
1034     UINT                      baseVertexIndex; /* Note: only used for d3d8 */
1035
1036     /* Transform */
1037     D3DMATRIX                 transforms[HIGHEST_TRANSFORMSTATE + 1];
1038
1039     /* Lights */
1040     PLIGHTINFOEL             *lights; /* NOTE: active GL lights must be front of the chain */
1041
1042     /* Clipping */
1043     double                    clipplane[MAX_CLIPPLANES][4];
1044     WINED3DCLIPSTATUS         clip_status;
1045
1046     /* ViewPort */
1047     WINED3DVIEWPORT           viewport;
1048
1049     /* Material */
1050     WINED3DMATERIAL           material;
1051
1052     /* Pixel Shader */
1053     IWineD3DPixelShader      *pixelShader;
1054
1055     /* Pixel Shader Constants */
1056     BOOL                       pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
1057     INT                        pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
1058     float                      pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
1059
1060     /* Indexed Vertex Blending */
1061     D3DVERTEXBLENDFLAGS       vertex_blend;
1062     FLOAT                     tween_factor;
1063
1064     /* RenderState */
1065     DWORD                     renderState[WINEHIGHEST_RENDER_STATE + 1];
1066
1067     /* Texture */
1068     IWineD3DBaseTexture      *textures[MAX_TEXTURES];
1069     int                       textureDimensions[MAX_SAMPLERS];
1070
1071     /* Texture State Stage */
1072     DWORD                     textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1073     /* Sampler States */
1074     DWORD                     samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1075
1076     /* Current GLSL Shader Program */
1077     GLhandleARB               shaderPrgId;
1078 };
1079
1080 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1081
1082 /*****************************************************************************
1083  * IWineD3DQueryImpl implementation structure (extends IUnknown)
1084  */
1085 typedef struct IWineD3DQueryImpl
1086 {
1087     const IWineD3DQueryVtbl  *lpVtbl;
1088     LONG                      ref;     /* Note: Ref counting not required */
1089     
1090     IUnknown                 *parent;
1091     /*TODO: replace with iface usage */
1092 #if 0
1093     IWineD3DDevice         *wineD3DDevice;
1094 #else
1095     IWineD3DDeviceImpl       *wineD3DDevice;
1096 #endif
1097     /* IWineD3DQuery fields */
1098
1099     D3DQUERYTYPE              type;
1100     /* TODO: Think about using a IUnknown instead of a void* */
1101     void                     *extendedData;
1102     
1103   
1104 } IWineD3DQueryImpl;
1105
1106 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1107
1108 /* Datastructures for IWineD3DQueryImpl.extendedData */
1109 typedef struct  WineQueryOcclusionData {
1110        unsigned int queryId;
1111 } WineQueryOcclusionData;
1112
1113
1114 /*****************************************************************************
1115  * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1116  */
1117
1118 typedef struct IWineD3DSwapChainImpl
1119 {
1120     /*IUnknown part*/
1121     IWineD3DSwapChainVtbl    *lpVtbl;
1122     LONG                      ref;     /* Note: Ref counting not required */
1123
1124     IUnknown                 *parent;
1125     IWineD3DDeviceImpl       *wineD3DDevice;
1126
1127     /* IWineD3DSwapChain fields */
1128     IWineD3DSurface          *backBuffer;
1129     IWineD3DSurface          *frontBuffer;
1130     BOOL                      wantsDepthStencilBuffer;
1131     D3DPRESENT_PARAMETERS     presentParms;
1132
1133     /* TODO: move everything up to drawable off into a context manager
1134       and store the 'data' in the contextManagerData interface.
1135     IUnknown                  *contextManagerData;
1136     */
1137
1138     HWND                    win_handle;
1139     Window                  win;
1140     Display                *display;
1141
1142     GLXContext              glCtx;
1143     XVisualInfo            *visInfo;
1144     GLXContext              render_ctx;
1145     /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1146     Drawable                drawable;
1147 } IWineD3DSwapChainImpl;
1148
1149 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1150
1151 /*****************************************************************************
1152  * Utility function prototypes 
1153  */
1154
1155 /* Trace routines */
1156 const char* debug_d3dformat(WINED3DFORMAT fmt);
1157 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1158 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1159 const char* debug_d3dusage(DWORD usage);
1160 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1161 const char* debug_d3drenderstate(DWORD state);
1162 const char* debug_d3dsamplerstate(DWORD state);
1163 const char* debug_d3dtexturestate(DWORD state);
1164 const char* debug_d3dpool(WINED3DPOOL pool);
1165
1166 /* Routines for GL <-> D3D values */
1167 GLenum StencilOp(DWORD op);
1168 GLenum StencilFunc(DWORD func);
1169 void   set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1170 void   set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1171
1172 SHORT  D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1173 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1174 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
1175 GLint  D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1176
1177 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1178
1179 /* Math utils */
1180 void multiply_matrix(D3DMATRIX *dest, D3DMATRIX *src1, D3DMATRIX *src2);
1181
1182 /*****************************************************************************
1183  * To enable calling of inherited functions, requires prototypes 
1184  *
1185  * Note: Only require classes which are subclassed, ie resource, basetexture, 
1186  */
1187     /*** IUnknown methods ***/
1188     extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1189     extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1190     extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1191     /*** IWineD3DResource methods ***/
1192     extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1193     extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1194     extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1195     extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1196     extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID  refguid);
1197     extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD  PriorityNew);
1198     extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1199     extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1200     extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1201     /*** class static members ***/
1202     void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1203
1204     /*** IUnknown methods ***/
1205     extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1206     extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1207     extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1208     /*** IWineD3DResource methods ***/
1209     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1210     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1211     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1212     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1213     extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid);
1214     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD  PriorityNew);
1215     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1216     extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1217     extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1218     /*** IWineD3DBaseTexture methods ***/
1219     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1220     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1221     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1222     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1223     extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1224     extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1225     extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1226     extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1227
1228     extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset);
1229     extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1230     extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1231     extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1232     extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1233     /*** class static members ***/
1234     void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1235
1236 struct SHADER_OPCODE_ARG;
1237 typedef void (*shader_fct_t)();
1238 typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
1239
1240 /* Struct to maintain a list of GLSL shader programs and their associated pixel and
1241  * vertex shaders.  A list of this type is maintained on the DeviceImpl, and is only
1242  * used if the user is using GLSL shaders. */
1243 struct glsl_shader_prog_link {
1244     struct list             entry;
1245     GLhandleARB             programId;
1246     IWineD3DVertexShader*   vertexShader;
1247     IWineD3DPixelShader*    pixelShader;
1248 };
1249
1250 /* TODO: Make this dynamic, based on shader limits ? */
1251 #define MAX_REG_ADDR 1
1252 #define MAX_REG_TEMP 32
1253 #define MAX_REG_TEXCRD 8
1254 #define MAX_REG_INPUT 12
1255 #define MAX_REG_OUTPUT 12
1256 #define MAX_ATTRIBS 16
1257 #define MAX_CONST_F 256
1258
1259 typedef struct shader_reg_maps {
1260
1261     char texcoord[MAX_REG_TEXCRD];          /* pixel < 3.0 */
1262     char temporary[MAX_REG_TEMP];           /* pixel, vertex */
1263     char address[MAX_REG_ADDR];             /* vertex */
1264     char packed_input[MAX_REG_INPUT];       /* pshader >= 3.0 */
1265     char packed_output[MAX_REG_OUTPUT];     /* vertex >= 3.0 */
1266     char attributes[MAX_ATTRIBS];           /* vertex */
1267
1268     char constantsF[MAX_CONST_F];           /* pixel, vertex */
1269     /* TODO: Integer and bool constants */
1270
1271     /* Semantics maps (semantic -> reg_token)
1272      * Use 0 as default (bit 31 is always 1 on a valid token) */
1273     DWORD* semantics_in;                    /* vertex, pixel */
1274     DWORD* semantics_out;                   /* vertex */
1275
1276     /* Sampler usage tokens 
1277      * Use 0 as default (bit 31 is always 1 on a valid token) */
1278     DWORD samplers[MAX_SAMPLERS];
1279
1280 } shader_reg_maps;
1281
1282 #define SHADER_PGMSIZE 65535
1283 typedef struct SHADER_BUFFER {
1284     char* buffer;
1285     size_t bsize;
1286     unsigned int lineNo;
1287 } SHADER_BUFFER;
1288
1289 typedef struct SHADER_OPCODE {
1290     unsigned int  opcode;
1291     const char*   name;
1292     const char*   glname;
1293     CONST UINT    num_params;
1294     shader_fct_t  soft_fct;
1295     SHADER_HANDLER hw_fct;
1296     SHADER_HANDLER hw_glsl_fct;
1297     DWORD         min_version;
1298     DWORD         max_version;
1299 } SHADER_OPCODE;
1300
1301 typedef struct SHADER_OPCODE_ARG {
1302     IWineD3DBaseShader* shader;
1303     shader_reg_maps* reg_maps;
1304     CONST SHADER_OPCODE* opcode;
1305     DWORD dst;
1306     DWORD dst_addr;
1307     DWORD predicate;
1308     DWORD src[4];
1309     DWORD src_addr[4];
1310     SHADER_BUFFER* buffer;
1311 } SHADER_OPCODE_ARG;
1312
1313 typedef struct SHADER_LIMITS {
1314     unsigned int temporary;
1315     unsigned int texcoord;
1316     unsigned int sampler;
1317     unsigned int constant_int;
1318     unsigned int constant_float;
1319     unsigned int constant_bool;
1320     unsigned int address;
1321     unsigned int packed_output;
1322     unsigned int packed_input;
1323     unsigned int attributes;
1324 } SHADER_LIMITS;
1325
1326 /** Keeps track of details for TEX_M#x# shader opcodes which need to 
1327     maintain state information between multiple codes */
1328 typedef struct SHADER_PARSE_STATE {
1329     unsigned int current_row;
1330     DWORD texcoord_w[2];
1331 } SHADER_PARSE_STATE;
1332
1333 /* Base Shader utility functions. 
1334  * (may move callers into the same file in the future) */
1335 extern int shader_addline(
1336     SHADER_BUFFER* buffer,
1337     const char* fmt, ...);
1338
1339 extern const SHADER_OPCODE* shader_get_opcode(
1340     IWineD3DBaseShader *iface, 
1341     const DWORD code);
1342
1343 /* ARB shader program Prototypes */
1344 extern void shader_hw_def(SHADER_OPCODE_ARG *arg);
1345
1346 /* GLSL helper programs */
1347 extern void set_glsl_shader_program(IWineD3DDevice *iface);
1348
1349 /** The following translate DirectX pixel/vertex shader opcodes to GLSL lines */
1350 extern void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg);
1351 extern void shader_glsl_arith(SHADER_OPCODE_ARG* arg);
1352 extern void shader_glsl_mov(SHADER_OPCODE_ARG* arg);
1353 extern void shader_glsl_mad(SHADER_OPCODE_ARG* arg);
1354 extern void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg);
1355 extern void shader_glsl_lrp(SHADER_OPCODE_ARG* arg);
1356 extern void shader_glsl_dot(SHADER_OPCODE_ARG* arg);
1357 extern void shader_glsl_rcp(SHADER_OPCODE_ARG* arg);
1358 extern void shader_glsl_cnd(SHADER_OPCODE_ARG* arg);
1359 extern void shader_glsl_compare(SHADER_OPCODE_ARG* arg);
1360 extern void shader_glsl_def(SHADER_OPCODE_ARG* arg);
1361 extern void shader_glsl_cmp(SHADER_OPCODE_ARG* arg);
1362
1363 /** GLSL Pixel Shader Prototypes */
1364 extern void pshader_glsl_tex(SHADER_OPCODE_ARG* arg);
1365 extern void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg);
1366 extern void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg);
1367 extern void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg);
1368 extern void pshader_glsl_input_pack(
1369    SHADER_BUFFER* buffer,
1370    DWORD* semantics_out);
1371
1372 /** GLSL Vertex Shader Prototypes */
1373 extern void vshader_glsl_output_unpack(
1374    SHADER_BUFFER* buffer,
1375    DWORD* semantics_out);
1376
1377 /*****************************************************************************
1378  * IDirect3DBaseShader implementation structure
1379  */
1380 typedef struct IWineD3DBaseShaderClass
1381 {
1382     DWORD                           hex_version;
1383     SHADER_LIMITS                   limits;
1384     SHADER_PARSE_STATE              parse_state;
1385     CONST SHADER_OPCODE             *shader_ins;
1386     CONST DWORD                     *function;
1387     UINT                            functionLength;
1388     GLuint                          prgId;
1389 } IWineD3DBaseShaderClass;
1390
1391 typedef struct IWineD3DBaseShaderImpl {
1392     /* IUnknown */
1393     const IWineD3DBaseShaderVtbl    *lpVtbl;
1394     LONG                            ref;
1395
1396     /* IWineD3DBaseShader */
1397     IWineD3DBaseShaderClass         baseShader;
1398 } IWineD3DBaseShaderImpl;
1399
1400 extern void shader_get_registers_used(
1401     IWineD3DBaseShader *iface,
1402     shader_reg_maps* reg_maps,
1403     CONST DWORD* pToken);
1404
1405 extern void shader_generate_glsl_declarations(
1406     IWineD3DBaseShader *iface,
1407     shader_reg_maps* reg_maps,
1408     SHADER_BUFFER* buffer);
1409
1410 extern void shader_generate_arb_declarations(
1411     IWineD3DBaseShader *iface,
1412     shader_reg_maps* reg_maps,
1413     SHADER_BUFFER* buffer);
1414
1415 extern void shader_generate_main(
1416     IWineD3DBaseShader *iface,
1417     SHADER_BUFFER* buffer,
1418     shader_reg_maps* reg_maps,
1419     CONST DWORD* pFunction);
1420
1421 extern void shader_dump_ins_modifiers(
1422     const DWORD output);
1423
1424 extern void shader_dump_param(
1425     IWineD3DBaseShader *iface,
1426     const DWORD param,
1427     const DWORD addr_token,
1428     int input);
1429
1430 extern void shader_trace_init(
1431     IWineD3DBaseShader *iface,
1432     const DWORD* pFunction);
1433
1434 extern int shader_get_param(
1435     IWineD3DBaseShader* iface,
1436     const DWORD* pToken,
1437     DWORD* param,
1438     DWORD* addr_token);
1439
1440 extern int shader_skip_unrecognized(
1441     IWineD3DBaseShader* iface,
1442     const DWORD* pToken);
1443
1444 extern void print_glsl_info_log(
1445     WineD3D_GL_Info *gl_info,
1446     GLhandleARB obj);
1447
1448 inline static int shader_get_regtype(const DWORD param) {
1449     return (((param & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) |
1450             ((param & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2));
1451 }
1452
1453 extern unsigned int shader_get_float_offset(const DWORD reg);
1454
1455 inline static BOOL shader_is_pshader_version(DWORD token) {
1456     return 0xFFFF0000 == (token & 0xFFFF0000);
1457 }
1458
1459 inline static BOOL shader_is_vshader_version(DWORD token) {
1460     return 0xFFFE0000 == (token & 0xFFFF0000);
1461 }
1462
1463 inline static BOOL shader_is_comment(DWORD token) {
1464     return D3DSIO_COMMENT == (token & D3DSI_OPCODE_MASK);
1465 }
1466
1467 /*****************************************************************************
1468  * IDirect3DVertexShader implementation structure
1469  */
1470 typedef struct IWineD3DVertexShaderImpl {
1471     /* IUnknown parts*/   
1472     const IWineD3DVertexShaderVtbl *lpVtbl;
1473     LONG                        ref;     /* Note: Ref counting not required */
1474
1475     /* IWineD3DBaseShader */
1476     IWineD3DBaseShaderClass     baseShader;
1477
1478     /* IWineD3DVertexShaderImpl */
1479     IUnknown                    *parent;
1480     IWineD3DDeviceImpl          *wineD3DDevice;
1481
1482     DWORD usage;
1483
1484     /* vertex declaration array mapping */
1485     DWORD arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE];
1486  
1487     /* run time datas...  */
1488     VSHADERDATA                *data;
1489     IWineD3DVertexDeclaration  *vertexDeclaration;
1490 #if 0 /* needs reworking */
1491     /* run time datas */
1492     VSHADERINPUTDATA input;
1493     VSHADEROUTPUTDATA output;
1494 #endif
1495 } IWineD3DVertexShaderImpl;
1496 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1497 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1498
1499 /*****************************************************************************
1500  * IDirect3DPixelShader implementation structure
1501  */
1502 typedef struct IWineD3DPixelShaderImpl {
1503     /* IUnknown parts */
1504     const IWineD3DPixelShaderVtbl *lpVtbl;
1505     LONG                        ref;     /* Note: Ref counting not required */
1506
1507     /* IWineD3DBaseShader */
1508     IWineD3DBaseShaderClass     baseShader;
1509
1510     /* IWineD3DPixelShaderImpl */
1511     IUnknown                   *parent;
1512     IWineD3DDeviceImpl         *wineD3DDevice;
1513
1514     /* run time data */
1515     PSHADERDATA                *data;
1516
1517 #if 0 /* needs reworking */
1518     PSHADERINPUTDATA input;
1519     PSHADEROUTPUTDATA output;
1520 #endif
1521 } IWineD3DPixelShaderImpl;
1522
1523 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1524 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1525
1526 /*****************************************************************************
1527  * IWineD3DPalette implementation structure
1528  */
1529 struct IWineD3DPaletteImpl {
1530     /* IUnknown parts */
1531     const IWineD3DPaletteVtbl  *lpVtbl;
1532     LONG                       ref;
1533
1534     IUnknown                   *parent;
1535     IWineD3DDeviceImpl         *wineD3DDevice;
1536
1537     /* IWineD3DPalette */
1538     HPALETTE                   hpal;
1539     WORD                       palVersion;     /*|               */
1540     WORD                       palNumEntries;  /*|  LOGPALETTE   */
1541     PALETTEENTRY               palents[256];   /*|               */
1542     /* This is to store the palette in 'screen format' */
1543     int                        screen_palents[256];
1544     DWORD                      Flags;
1545 };
1546
1547 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
1548 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
1549
1550 /* DirectDraw utility functions */
1551 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
1552 LONG get_bitmask_red(WINED3DFORMAT fmt);
1553 LONG get_bitmask_green(WINED3DFORMAT fmt);
1554 LONG get_bitmask_blue(WINED3DFORMAT fmt);
1555 LONG get_bitmask_alpha(WINED3DFORMAT fmt);
1556 BOOL isFourcc(WINED3DFORMAT fmt);
1557
1558 #endif