wined3d: Add a function to print out D3DDECLUSAGE9 values.
[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, WineDirect3DVertexStridedData *strided, LONG BaseVertexIndex, BOOL *fixup);
361
362 void primitiveDeclarationConvertToStridedData(
363      IWineD3DDevice *iface,
364      BOOL useVertexShaderFunction,
365      WineDirect3DVertexStridedData *strided,
366      LONG BaseVertexIndex, 
367      DWORD *fvf,
368      BOOL *fixup);
369
370 void primitiveConvertFVFtoOffset(DWORD thisFVF,
371                                  DWORD stride,
372                                  BYTE *data,
373                                  WineDirect3DVertexStridedData *strided,
374                                  GLint streamVBO);
375
376 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
377
378 #define eps 1e-8
379
380 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
381     (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
382
383 /* Routine to fill gl caps for swapchains and IWineD3D */
384 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info,
385                              Display* display);
386
387 /*****************************************************************************
388  * Internal representation of a light
389  */
390 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
391 struct PLIGHTINFOEL {
392     WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
393     DWORD        OriginalIndex;
394     LONG         glIndex;
395     BOOL         lightEnabled;
396     BOOL         changed;
397     BOOL         enabledChanged;
398
399     /* Converted parms to speed up swapping lights */
400     float                         lightPosn[4];
401     float                         lightDirn[4];
402     float                         exponent;
403     float                         cutoff;
404
405     PLIGHTINFOEL *next;
406     PLIGHTINFOEL *prev;
407 };
408
409 /* The default light parameters */
410 extern const WINED3DLIGHT WINED3D_default_light;
411
412 /*****************************************************************************
413  * IWineD3D implementation structure
414  */
415 typedef struct IWineD3DImpl
416 {
417     /* IUnknown fields */
418     const IWineD3DVtbl     *lpVtbl;
419     LONG                    ref;     /* Note: Ref counting not required */
420
421     /* WineD3D Information */
422     IUnknown               *parent;
423     UINT                    dxVersion;
424
425     /* GL Information */
426     BOOL                    isGLInfoValid;
427     WineD3D_GL_Info         gl_info;
428 } IWineD3DImpl;
429
430 extern const IWineD3DVtbl IWineD3D_Vtbl;
431
432 /** Hacked out start of a context manager!! **/
433 typedef struct glContext {
434     int Width;
435     int Height;
436     int usedcount;
437     GLXContext context;
438
439     Drawable drawable;
440     IWineD3DSurface *pSurface;
441 #if 0 /* TODO: someway to represent the state of the context */
442     IWineD3DStateBlock *pStateBlock;
443 #endif
444 /* a few other things like format */
445 } glContext;
446
447 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
448 (since it will break quite a few things until contexts are managed properly!) */
449 extern BOOL pbuffer_support;
450 /* allocate one pbuffer per surface */
451 extern BOOL pbuffer_per_surface;
452
453 /* Maximum number of contexts/pbuffers to keep in cache,
454 set to 100 because ATI's drivers don't support deleting pBuffers properly
455 this needs to be migrated to a list and some option availalbe for controle the cache size.
456 */
457 #define CONTEXT_CACHE 100
458
459 typedef struct ResourceList {
460     IWineD3DResource         *resource;
461     struct ResourceList      *next;
462 } ResourceList;
463
464 /* A helper function that dumps a resource list */
465 void dumpResources(ResourceList *resources);
466
467 /*****************************************************************************
468  * IWineD3DDevice implementation structure
469  */
470 typedef struct IWineD3DDeviceImpl
471 {
472     /* IUnknown fields      */
473     const IWineD3DDeviceVtbl *lpVtbl;
474     LONG                    ref;     /* Note: Ref counting not required */
475
476     /* WineD3D Information  */
477     IUnknown               *parent;
478     IWineD3D               *wineD3D;
479
480     /* X and GL Information */
481     GLint                   maxConcurrentLights;
482
483     /* Optimization */
484     BOOL                    modelview_valid;
485     BOOL                    proj_valid;
486     BOOL                    view_ident;        /* true iff view matrix is identity                */
487     BOOL                    last_was_rhw;      /* true iff last draw_primitive was in xyzrhw mode */
488     BOOL                    viewport_changed;  /* Was the viewport changed since the last draw?   */
489     GLenum                  tracking_parm;     /* Which source is tracking current colour         */
490     LONG                    tracking_color;    /* used iff GL_COLOR_MATERIAL was enabled          */
491 #define                         DISABLED_TRACKING  0  /* Disabled                                 */
492 #define                         IS_TRACKING        1  /* tracking_parm is tracking diffuse color  */
493 #define                         NEEDS_TRACKING     2  /* Tracking needs to be enabled when needed */
494 #define                         NEEDS_DISABLE      3  /* Tracking needs to be disabled when needed*/
495     UINT                    srcBlend;
496     UINT                    dstBlend;
497     UINT                    alphafunc;
498     BOOL                    texture_shader_active;  /* TODO: Confirm use is correct */
499     BOOL                    last_was_notclipped;
500
501     /* State block related */
502     BOOL                    isRecordingState;
503     IWineD3DStateBlockImpl *stateBlock;
504     IWineD3DStateBlockImpl *updateStateBlock;
505
506     /* Internal use fields  */
507     WINED3DDEVICE_CREATION_PARAMETERS createParms;
508     UINT                            adapterNo;
509     D3DDEVTYPE                      devType;
510
511     IWineD3DSwapChain     **swapchains;
512     uint                    NumberOfSwapChains;
513
514     ResourceList           *resources; /* a linked list to track resources created by the device */
515
516     /* Render Target Support */
517     IWineD3DSurface        *depthStencilBuffer;
518
519     IWineD3DSurface        *renderTarget;
520     IWineD3DSurface        *stencilBufferTarget;
521
522     /* palettes texture management */
523     PALETTEENTRY            palettes[MAX_PALETTES][256];
524     UINT                    currentPalette;
525
526     /* For rendering to a texture using glCopyTexImage */
527     BOOL                    renderUpsideDown;
528
529     /* Cursor management */
530     BOOL                    bCursorVisible;
531     UINT                    xHotSpot;
532     UINT                    yHotSpot;
533     UINT                    xScreenSpace;
534     UINT                    yScreenSpace;
535
536     /* Textures for when no other textures are mapped */
537     UINT                          dummyTextureName[MAX_TEXTURES];
538
539     /* Debug stream management */
540     BOOL                     debug;
541
542     /* Device state management */
543     HRESULT                 state;
544     BOOL                    d3d_initialized;
545
546     /* Screen buffer resources */
547     glContext contextCache[CONTEXT_CACHE];
548
549     /* A flag to check if endscene has been called before changing the render tartet */
550     BOOL sceneEnded;
551
552     /* process vertex shaders using software or hardware */
553     BOOL softwareVertexProcessing;
554
555     /* DirectDraw stuff */
556     HWND ddraw_window;
557     IWineD3DSurface *ddraw_primary;
558     DWORD ddraw_width, ddraw_height;
559     WINED3DFORMAT ddraw_format;
560
561     /* List of GLSL shader programs and their associated vertex & pixel shaders */
562     struct list glsl_shader_progs;
563
564 } IWineD3DDeviceImpl;
565
566 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
567
568 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
569  * anybody uses it for much so a good implementation is optional. */
570 typedef struct PrivateData
571 {
572     struct PrivateData* next;
573
574     GUID tag;
575     DWORD flags; /* DDSPD_* */
576     DWORD uniqueness_value;
577
578     union
579     {
580         LPVOID data;
581         LPUNKNOWN object;
582     } ptr;
583
584     DWORD size;
585 } PrivateData;
586
587 void d3ddevice_set_ortho(IWineD3DDeviceImpl *This);
588
589 /*****************************************************************************
590  * IWineD3DResource implementation structure
591  */
592 typedef struct IWineD3DResourceClass
593 {
594     /* IUnknown fields */
595     LONG                    ref;     /* Note: Ref counting not required */
596
597     /* WineD3DResource Information */
598     IUnknown               *parent;
599     WINED3DRESOURCETYPE     resourceType;
600     IWineD3DDeviceImpl     *wineD3DDevice;
601     WINED3DPOOL             pool;
602     UINT                    size;
603     DWORD                   usage;
604     WINED3DFORMAT           format;
605     BYTE                   *allocatedMemory;
606     PrivateData            *privateData;
607
608 } IWineD3DResourceClass;
609
610 typedef struct IWineD3DResourceImpl
611 {
612     /* IUnknown & WineD3DResource Information     */
613     const IWineD3DResourceVtbl *lpVtbl;
614     IWineD3DResourceClass   resource;
615 } IWineD3DResourceImpl;
616
617
618 /*****************************************************************************
619  * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
620  */
621 typedef struct IWineD3DVertexBufferImpl
622 {
623     /* IUnknown & WineD3DResource Information     */
624     const IWineD3DVertexBufferVtbl *lpVtbl;
625     IWineD3DResourceClass     resource;
626
627     /* WineD3DVertexBuffer specifics */
628     DWORD                     fvf;
629
630     /* Vertex buffer object support */
631     GLuint                    vbo;
632     BYTE                      Flags;
633     UINT                      stream;
634
635     UINT                      dirtystart, dirtyend;
636     LONG                      lockcount;
637
638     /* Last description of the buffer */
639     WineDirect3DVertexStridedData strided;
640 } IWineD3DVertexBufferImpl;
641
642 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
643
644 #define VBFLAG_LOAD           0x01    /* Data is written from allocatedMemory to the VBO */
645 #define VBFLAG_OPTIMIZED      0x02    /* Optimize has been called for the VB */
646 #define VBFLAG_DIRTY          0x04    /* Buffer data has been modified */
647 #define VBFLAG_STREAM         0x08    /* The vertex buffer is in a stream */
648 #define VBFLAG_HASDESC        0x10    /* A vertex description has been found */
649
650 /*****************************************************************************
651  * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
652  */
653 typedef struct IWineD3DIndexBufferImpl
654 {
655     /* IUnknown & WineD3DResource Information     */
656     const IWineD3DIndexBufferVtbl *lpVtbl;
657     IWineD3DResourceClass     resource;
658
659     /* WineD3DVertexBuffer specifics */
660 } IWineD3DIndexBufferImpl;
661
662 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
663
664 /*****************************************************************************
665  * IWineD3DBaseTexture D3D- > openGL state map lookups
666  */
667 #define WINED3DFUNC_NOTSUPPORTED  -2
668 #define WINED3DFUNC_UNIMPLEMENTED -1
669
670 typedef enum winetexturestates {
671     WINED3DTEXSTA_ADDRESSU       = 0,
672     WINED3DTEXSTA_ADDRESSV       = 1,
673     WINED3DTEXSTA_ADDRESSW       = 2,
674     WINED3DTEXSTA_BORDERCOLOR    = 3,
675     WINED3DTEXSTA_MAGFILTER      = 4,
676     WINED3DTEXSTA_MINFILTER      = 5,
677     WINED3DTEXSTA_MIPFILTER      = 6,
678     WINED3DTEXSTA_MAXMIPLEVEL    = 7,
679     WINED3DTEXSTA_MAXANISOTROPY  = 8,
680     WINED3DTEXSTA_SRGBTEXTURE    = 9,
681     WINED3DTEXSTA_ELEMENTINDEX   = 10,
682     WINED3DTEXSTA_DMAPOFFSET     = 11,
683     WINED3DTEXSTA_TSSADDRESSW    = 12,
684     MAX_WINETEXTURESTATES        = 13,
685 } winetexturestates;
686
687 typedef struct Wined3dTextureStateMap {
688     CONST int state;
689     int function;
690 } Wined3dTextureStateMap;
691
692 /*****************************************************************************
693  * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
694  */
695 typedef struct IWineD3DBaseTextureClass
696 {
697     UINT                    levels;
698     BOOL                    dirty;
699     D3DFORMAT               format;
700     DWORD                   usage;
701     UINT                    textureName;
702     UINT                    LOD;
703     WINED3DTEXTUREFILTERTYPE filterType;
704     DWORD                   states[MAX_WINETEXTURESTATES];
705
706 } IWineD3DBaseTextureClass;
707
708 typedef struct IWineD3DBaseTextureImpl
709 {
710     /* IUnknown & WineD3DResource Information     */
711     const IWineD3DBaseTextureVtbl *lpVtbl;
712     IWineD3DResourceClass     resource;
713     IWineD3DBaseTextureClass  baseTexture;
714
715 } IWineD3DBaseTextureImpl;
716
717 /*****************************************************************************
718  * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
719  */
720 typedef struct IWineD3DTextureImpl
721 {
722     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
723     const IWineD3DTextureVtbl *lpVtbl;
724     IWineD3DResourceClass     resource;
725     IWineD3DBaseTextureClass  baseTexture;
726
727     /* IWineD3DTexture */
728     IWineD3DSurface          *surfaces[MAX_LEVELS];
729     
730     UINT                      width;
731     UINT                      height;
732     float                     pow2scalingFactorX;
733     float                     pow2scalingFactorY;
734
735 } IWineD3DTextureImpl;
736
737 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
738
739 /*****************************************************************************
740  * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
741  */
742 typedef struct IWineD3DCubeTextureImpl
743 {
744     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
745     const IWineD3DCubeTextureVtbl *lpVtbl;
746     IWineD3DResourceClass     resource;
747     IWineD3DBaseTextureClass  baseTexture;
748
749     /* IWineD3DCubeTexture */
750     IWineD3DSurface          *surfaces[6][MAX_LEVELS];
751
752     UINT                      edgeLength;
753     float                     pow2scalingFactor;
754
755 } IWineD3DCubeTextureImpl;
756
757 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
758
759 typedef struct _WINED3DVOLUMET_DESC
760 {
761     UINT                    Width;
762     UINT                    Height;
763     UINT                    Depth;
764 } WINED3DVOLUMET_DESC;
765
766 /*****************************************************************************
767  * IWineD3DVolume implementation structure (extends IUnknown)
768  */
769 typedef struct IWineD3DVolumeImpl
770 {
771     /* IUnknown & WineD3DResource fields */
772     const IWineD3DVolumeVtbl  *lpVtbl;
773     IWineD3DResourceClass      resource;
774
775     /* WineD3DVolume Information */
776     WINED3DVOLUMET_DESC      currentDesc;
777     IWineD3DBase            *container;
778     UINT                    bytesPerPixel;
779
780     BOOL                    lockable;
781     BOOL                    locked;
782     WINED3DBOX              lockedBox;
783     WINED3DBOX              dirtyBox;
784     BOOL                    dirty;
785
786
787 } IWineD3DVolumeImpl;
788
789 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
790
791 /*****************************************************************************
792  * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
793  */
794 typedef struct IWineD3DVolumeTextureImpl
795 {
796     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
797     const IWineD3DVolumeTextureVtbl *lpVtbl;
798     IWineD3DResourceClass     resource;
799     IWineD3DBaseTextureClass  baseTexture;
800
801     /* IWineD3DVolumeTexture */
802     IWineD3DVolume           *volumes[MAX_LEVELS];
803
804     UINT                      width;
805     UINT                      height;
806     UINT                      depth;
807 } IWineD3DVolumeTextureImpl;
808
809 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
810
811 typedef struct _WINED3DSURFACET_DESC
812 {
813     WINED3DMULTISAMPLE_TYPE MultiSampleType;
814     DWORD                   MultiSampleQuality;
815     UINT                    Width;
816     UINT                    Height;
817 } WINED3DSURFACET_DESC;
818
819 /*****************************************************************************
820  * Structure for DIB Surfaces (GetDC and GDI surfaces)
821  */
822 typedef struct wineD3DSurface_DIB {
823     HBITMAP DIBsection;
824     void* bitmap_data;
825     HGDIOBJ holdbitmap;
826     BOOL client_memory;
827 } wineD3DSurface_DIB;
828
829 /*****************************************************************************
830  * IWineD3DSurface implementation structure
831  */
832 struct IWineD3DSurfaceImpl
833 {
834     /* IUnknown & IWineD3DResource Information     */
835     const IWineD3DSurfaceVtbl *lpVtbl;
836     IWineD3DResourceClass     resource;
837
838     /* IWineD3DSurface fields */
839     IWineD3DBase              *container;
840     WINED3DSURFACET_DESC      currentDesc;
841     IWineD3DPaletteImpl      *palette;
842
843     UINT                      textureName;
844     UINT                      bytesPerPixel;
845
846     /* TODO: move this off into a management class(maybe!) */
847     WORD                      Flags;
848
849     UINT                      pow2Width;
850     UINT                      pow2Height;
851     UINT                      pow2Size;
852
853     /* Oversized texture */
854     RECT                      glRect;
855
856 #if 0
857     /* precalculated x and y scalings for texture coords */
858     float                     pow2scalingFactorX; /* =  (Width  / pow2Width ) */
859     float                     pow2scalingFactorY; /* =  (Height / pow2Height) */
860 #endif
861
862     RECT                      lockedRect;
863     RECT                      dirtyRect;
864
865     glDescriptor              glDescription;
866
867     /* For GetDC */
868     wineD3DSurface_DIB        dib;
869     HDC                       hDC;
870
871     /* Color keys for DDraw */
872     DDCOLORKEY                DestBltCKey;
873     DDCOLORKEY                DestOverlayCKey;
874     DDCOLORKEY                SrcOverlayCKey;
875     DDCOLORKEY                SrcBltCKey;
876     DWORD                     CKeyFlags;
877
878 };
879
880 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
881 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
882
883 /* Predeclare the shared Surface functions */
884 HRESULT WINAPI IWineD3DSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
885 ULONG WINAPI IWineD3DSurfaceImpl_AddRef(IWineD3DSurface *iface);
886 ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface);
887 HRESULT WINAPI IWineD3DSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
888 HRESULT WINAPI IWineD3DSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
889 HRESULT WINAPI IWineD3DSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
890 HRESULT WINAPI IWineD3DSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
891 HRESULT WINAPI IWineD3DSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
892 DWORD   WINAPI IWineD3DSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
893 DWORD   WINAPI IWineD3DSurfaceImpl_GetPriority(IWineD3DSurface *iface);
894 void    WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface);
895 WINED3DRESOURCETYPE WINAPI IWineD3DSurfaceImpl_GetType(IWineD3DSurface *iface);
896 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainerParent(IWineD3DSurface* iface, IUnknown **ppContainerParent);
897 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
898 HRESULT WINAPI IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
899 HRESULT WINAPI IWineD3DSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
900 HRESULT WINAPI IWineD3DSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
901 HRESULT WINAPI IWineD3DSurfaceImpl_IsLost(IWineD3DSurface *iface);
902 HRESULT WINAPI IWineD3DSurfaceImpl_Restore(IWineD3DSurface *iface);
903 HRESULT WINAPI IWineD3DSurfaceImpl_SetPixelFormat(IWineD3DSurface *iface, WINED3DFORMAT Format, BYTE *Surface, DWORD Size);
904 HRESULT WINAPI IWineD3DSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
905 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
906 HRESULT WINAPI IWineD3DSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, DDCOLORKEY *CKey);
907 HRESULT WINAPI IWineD3DSurfaceImpl_CleanDirtyRect(IWineD3DSurface *iface);
908 extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect);
909 HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
910 HRESULT WINAPI IWineD3DSurfaceImpl_SetPBufferState(IWineD3DSurface *iface, BOOL inPBuffer, BOOL  inTexture);
911 void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target);
912 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription);
913 const void *WINAPI IWineD3DSurfaceImpl_GetData(IWineD3DSurface *iface);
914 HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
915 HRESULT WINAPI IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx);
916 HRESULT WINAPI IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty, IWineD3DSurface *Source, RECT *rsrc, DWORD trans);
917 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
918 HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC);
919 HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC);
920 DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface);
921 HRESULT WINAPI IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
922
923 /* Surface flags: */
924 #define SFLAG_OVERSIZE    0x0001 /* Surface is bigger than gl size, blts only */
925 #define SFLAG_CONVERTED   0x0002 /* Converted for color keying or Palettized */
926 #define SFLAG_DIBSECTION  0x0004 /* Has a DIB section attached for getdc */
927 #define SFLAG_DIRTY       0x0008 /* Surface was locked by the app */
928 #define SFLAG_LOCKABLE    0x0010 /* Surface can be locked */
929 #define SFLAG_DISCARD     0x0020 /* ??? */
930 #define SFLAG_LOCKED      0x0040 /* Surface is locked atm */
931 #define SFLAG_ACTIVELOCK  0x0080 /* Not locked, but surface memory is needed */
932 #define SFLAG_INTEXTURE   0x0100 /* ??? */
933 #define SFLAG_INPBUFFER   0x0200 /* ??? */
934 #define SFLAG_NONPOW2     0x0400 /* Surface sizes are not a power of 2 */
935 #define SFLAG_DYNLOCK     0x0800 /* Surface is often locked by the app */
936 #define SFLAG_DYNCHANGE   0x1800 /* Surface contents are changed very often, implies DYNLOCK */
937 #define SFLAG_DCINUSE     0x2000 /* Set between GetDC and ReleaseDC calls */
938 #define SFLAG_GLDIRTY     0x4000 /* The opengl texture is more up to date than the surface mem */
939 #define SFLAG_LOST        0x8000 /* Surface lost flag for DDraw */
940
941 /* In some conditions the surface memory must not be freed:
942  * SFLAG_OVERSIZE: Not all data can be kept in GL
943  * SFLAG_CONVERTED: Converting the data back would take too long
944  * SFLAG_DIBSECTION: The dib code manages the memory
945  * SFLAG_DIRTY: GL surface isn't up to date
946  * SFLAG_LOCKED: The app requires access to the surface data
947  * SFLAG_ACTIVELOCK: Some wined3d code needs the memory
948  * SFLAG_DYNLOCK: Avoid freeing the data for performance
949  * SFLAG_DYNCHANGE: Same reason as DYNLOCK
950  */
951 #define SFLAG_DONOTFREE  (SFLAG_OVERSIZE   | \
952                           SFLAG_CONVERTED  | \
953                           SFLAG_DIBSECTION | \
954                           SFLAG_DIRTY      | \
955                           SFLAG_LOCKED     | \
956                           SFLAG_ACTIVELOCK | \
957                           SFLAG_DYNLOCK    | \
958                           SFLAG_DYNCHANGE    )
959
960 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
961
962 /*****************************************************************************
963  * IWineD3DVertexDeclaration implementation structure
964  */
965 typedef struct IWineD3DVertexDeclarationImpl {
966  /* IUnknown  Information     */
967   const IWineD3DVertexDeclarationVtbl *lpVtbl;
968   LONG                    ref;     /* Note: Ref counting not required */
969
970   IUnknown               *parent;
971   /** precomputed fvf if simple declaration */
972   IWineD3DDeviceImpl     *wineD3DDevice;
973   DWORD   fvf[MAX_STREAMS];
974   DWORD   allFVF;
975
976   /** dx8 compatible Declaration fields */
977   DWORD*  pDeclaration8;
978   DWORD   declaration8Length;
979
980   /** dx9+ */
981   D3DVERTEXELEMENT9 *pDeclaration9;
982   UINT               declaration9NumElements;
983
984   WINED3DVERTEXELEMENT  *pDeclarationWine;
985   UINT                   declarationWNumElements;
986   
987   float                 *constants;
988   
989 } IWineD3DVertexDeclarationImpl;
990
991 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
992
993 /*****************************************************************************
994  * IWineD3DStateBlock implementation structure
995  */
996
997 /* Internal state Block for Begin/End/Capture/Create/Apply info  */
998 /*   Note: Very long winded but gl Lists are not flexible enough */
999 /*   to resolve everything we need, so doing it manually for now */
1000 typedef struct SAVEDSTATES {
1001         BOOL                      indices;
1002         BOOL                      material;
1003         BOOL                      fvf;
1004         BOOL                      streamSource[MAX_STREAMS];
1005         BOOL                      streamFreq[MAX_STREAMS];
1006         BOOL                      textures[MAX_SAMPLERS];
1007         BOOL                      transform[HIGHEST_TRANSFORMSTATE + 1];
1008         BOOL                      viewport;
1009         BOOL                      renderState[WINEHIGHEST_RENDER_STATE + 1];
1010         BOOL                      textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1011         BOOL                      samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1012         BOOL                      clipplane[MAX_CLIPPLANES];
1013         BOOL                      vertexDecl;
1014         BOOL                      pixelShader;
1015         BOOL                      pixelShaderConstantsB[MAX_PSHADER_CONSTANTS];
1016         BOOL                      pixelShaderConstantsI[MAX_PSHADER_CONSTANTS];
1017         BOOL                      pixelShaderConstantsF[MAX_PSHADER_CONSTANTS];
1018         BOOL                      vertexShader;
1019         BOOL                      vertexShaderConstantsB[MAX_VSHADER_CONSTANTS];
1020         BOOL                      vertexShaderConstantsI[MAX_VSHADER_CONSTANTS];
1021         BOOL                      vertexShaderConstantsF[MAX_VSHADER_CONSTANTS];
1022 } SAVEDSTATES;
1023
1024 struct IWineD3DStateBlockImpl
1025 {
1026     /* IUnknown fields */
1027     const IWineD3DStateBlockVtbl *lpVtbl;
1028     LONG                      ref;     /* Note: Ref counting not required */
1029
1030     /* IWineD3DStateBlock information */
1031     IUnknown                 *parent;
1032     IWineD3DDeviceImpl       *wineD3DDevice;
1033     WINED3DSTATEBLOCKTYPE     blockType;
1034
1035     /* Array indicating whether things have been set or changed */
1036     SAVEDSTATES               changed;
1037     SAVEDSTATES               set;
1038
1039     /* Drawing - Vertex Shader or FVF related */
1040     DWORD                     fvf;
1041     /* Vertex Shader Declaration */
1042     IWineD3DVertexDeclaration *vertexDecl;
1043
1044     IWineD3DVertexShader      *vertexShader;
1045
1046     /* Vertex Shader Constants */
1047     BOOL                       vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
1048     INT                        vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
1049     float                      vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
1050
1051     /* Stream Source */
1052     BOOL                      streamIsUP;
1053     UINT                      streamStride[MAX_STREAMS];
1054     UINT                      streamOffset[MAX_STREAMS];
1055     IWineD3DVertexBuffer     *streamSource[MAX_STREAMS];
1056     UINT                      streamFreq[MAX_STREAMS];
1057     UINT                      streamFlags[MAX_STREAMS];     /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA  */
1058
1059     /* Indices */
1060     IWineD3DIndexBuffer*      pIndexData;
1061     UINT                      baseVertexIndex; /* Note: only used for d3d8 */
1062
1063     /* Transform */
1064     D3DMATRIX                 transforms[HIGHEST_TRANSFORMSTATE + 1];
1065
1066     /* Lights */
1067     PLIGHTINFOEL             *lights; /* NOTE: active GL lights must be front of the chain */
1068
1069     /* Clipping */
1070     double                    clipplane[MAX_CLIPPLANES][4];
1071     WINED3DCLIPSTATUS         clip_status;
1072
1073     /* ViewPort */
1074     WINED3DVIEWPORT           viewport;
1075
1076     /* Material */
1077     WINED3DMATERIAL           material;
1078
1079     /* Pixel Shader */
1080     IWineD3DPixelShader      *pixelShader;
1081
1082     /* Pixel Shader Constants */
1083     BOOL                       pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
1084     INT                        pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
1085     float                      pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
1086
1087     /* Indexed Vertex Blending */
1088     D3DVERTEXBLENDFLAGS       vertex_blend;
1089     FLOAT                     tween_factor;
1090
1091     /* RenderState */
1092     DWORD                     renderState[WINEHIGHEST_RENDER_STATE + 1];
1093
1094     /* Texture */
1095     IWineD3DBaseTexture      *textures[MAX_SAMPLERS];
1096     int                       textureDimensions[MAX_SAMPLERS];
1097
1098     /* Texture State Stage */
1099     DWORD                     textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1100     /* Sampler States */
1101     DWORD                     samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1102
1103     /* Current GLSL Shader Program */
1104     GLhandleARB               shaderPrgId;
1105 };
1106
1107 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1108
1109 /*****************************************************************************
1110  * IWineD3DQueryImpl implementation structure (extends IUnknown)
1111  */
1112 typedef struct IWineD3DQueryImpl
1113 {
1114     const IWineD3DQueryVtbl  *lpVtbl;
1115     LONG                      ref;     /* Note: Ref counting not required */
1116     
1117     IUnknown                 *parent;
1118     /*TODO: replace with iface usage */
1119 #if 0
1120     IWineD3DDevice         *wineD3DDevice;
1121 #else
1122     IWineD3DDeviceImpl       *wineD3DDevice;
1123 #endif
1124     /* IWineD3DQuery fields */
1125
1126     D3DQUERYTYPE              type;
1127     /* TODO: Think about using a IUnknown instead of a void* */
1128     void                     *extendedData;
1129     
1130   
1131 } IWineD3DQueryImpl;
1132
1133 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1134
1135 /* Datastructures for IWineD3DQueryImpl.extendedData */
1136 typedef struct  WineQueryOcclusionData {
1137        unsigned int queryId;
1138 } WineQueryOcclusionData;
1139
1140
1141 /*****************************************************************************
1142  * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1143  */
1144
1145 typedef struct IWineD3DSwapChainImpl
1146 {
1147     /*IUnknown part*/
1148     IWineD3DSwapChainVtbl    *lpVtbl;
1149     LONG                      ref;     /* Note: Ref counting not required */
1150
1151     IUnknown                 *parent;
1152     IWineD3DDeviceImpl       *wineD3DDevice;
1153
1154     /* IWineD3DSwapChain fields */
1155     IWineD3DSurface         **backBuffer;
1156     IWineD3DSurface          *frontBuffer;
1157     BOOL                      wantsDepthStencilBuffer;
1158     D3DPRESENT_PARAMETERS     presentParms;
1159
1160     /* TODO: move everything up to drawable off into a context manager
1161       and store the 'data' in the contextManagerData interface.
1162     IUnknown                  *contextManagerData;
1163     */
1164
1165     HWND                    win_handle;
1166     Window                  win;
1167     Display                *display;
1168
1169     GLXContext              glCtx;
1170     XVisualInfo            *visInfo;
1171     GLXContext              render_ctx;
1172     /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1173     Drawable                drawable;
1174 } IWineD3DSwapChainImpl;
1175
1176 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1177
1178 /*****************************************************************************
1179  * Utility function prototypes 
1180  */
1181
1182 /* Trace routines */
1183 const char* debug_d3dformat(WINED3DFORMAT fmt);
1184 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1185 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1186 const char* debug_d3dusage(DWORD usage);
1187 const char* debug_d3ddeclusage(BYTE usage);
1188 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1189 const char* debug_d3drenderstate(DWORD state);
1190 const char* debug_d3dsamplerstate(DWORD state);
1191 const char* debug_d3dtexturestate(DWORD state);
1192 const char* debug_d3dpool(WINED3DPOOL pool);
1193
1194 /* Routines for GL <-> D3D values */
1195 GLenum StencilOp(DWORD op);
1196 GLenum StencilFunc(DWORD func);
1197 void   set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1198 void   set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx);
1199 void   set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1200
1201 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1202
1203 /* Math utils */
1204 void multiply_matrix(D3DMATRIX *dest, D3DMATRIX *src1, D3DMATRIX *src2);
1205
1206 /*****************************************************************************
1207  * To enable calling of inherited functions, requires prototypes 
1208  *
1209  * Note: Only require classes which are subclassed, ie resource, basetexture, 
1210  */
1211     /*** IUnknown methods ***/
1212     extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1213     extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1214     extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1215     /*** IWineD3DResource methods ***/
1216     extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1217     extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1218     extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1219     extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1220     extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID  refguid);
1221     extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD  PriorityNew);
1222     extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1223     extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1224     extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1225     /*** class static members ***/
1226     void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1227
1228     /*** IUnknown methods ***/
1229     extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1230     extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1231     extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1232     /*** IWineD3DResource methods ***/
1233     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1234     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1235     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1236     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1237     extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid);
1238     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD  PriorityNew);
1239     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1240     extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1241     extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1242     /*** IWineD3DBaseTexture methods ***/
1243     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1244     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1245     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1246     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1247     extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1248     extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1249     extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1250     extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1251
1252     extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset, GLint *vbo);
1253     extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1254     extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1255     extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1256     extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1257     /*** class static members ***/
1258     void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1259
1260 struct SHADER_OPCODE_ARG;
1261 typedef void (*shader_fct_t)();
1262 typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
1263
1264 /* Struct to maintain a list of GLSL shader programs and their associated pixel and
1265  * vertex shaders.  A list of this type is maintained on the DeviceImpl, and is only
1266  * used if the user is using GLSL shaders. */
1267 struct glsl_shader_prog_link {
1268     struct list             entry;
1269     GLhandleARB             programId;
1270     IWineD3DVertexShader*   vertexShader;
1271     IWineD3DPixelShader*    pixelShader;
1272 };
1273
1274 /* TODO: Make this dynamic, based on shader limits ? */
1275 #define MAX_REG_ADDR 1
1276 #define MAX_REG_TEMP 32
1277 #define MAX_REG_TEXCRD 8
1278 #define MAX_REG_INPUT 12
1279 #define MAX_REG_OUTPUT 12
1280 #define MAX_ATTRIBS 16
1281 #define MAX_CONST_F 256
1282 #define MAX_CONST_I 16
1283 #define MAX_CONST_B 16
1284
1285 typedef struct shader_reg_maps {
1286
1287     char texcoord[MAX_REG_TEXCRD];          /* pixel < 3.0 */
1288     char temporary[MAX_REG_TEMP];           /* pixel, vertex */
1289     char address[MAX_REG_ADDR];             /* vertex */
1290     char packed_input[MAX_REG_INPUT];       /* pshader >= 3.0 */
1291     char packed_output[MAX_REG_OUTPUT];     /* vertex >= 3.0 */
1292     char attributes[MAX_ATTRIBS];           /* vertex */
1293
1294     char constantsF[MAX_CONST_F];           /* pixel, vertex */
1295     char constantsI[MAX_CONST_I];           /* pixel & vertex >= 2.0 */
1296     char constantsB[MAX_CONST_B];           /* pixel & vertex >= 2.0 */
1297     
1298     /* Semantics maps (semantic -> reg_token)
1299      * Use 0 as default (bit 31 is always 1 on a valid token) */
1300     DWORD* semantics_in;                    /* vertex, pixel */
1301     DWORD* semantics_out;                   /* vertex */
1302
1303     /* Sampler usage tokens 
1304      * Use 0 as default (bit 31 is always 1 on a valid token) */
1305     DWORD samplers[MAX_SAMPLERS];
1306
1307     /* Whether or not a loop is used in this shader */
1308     char loop;
1309
1310 } shader_reg_maps;
1311
1312 #define SHADER_PGMSIZE 65535
1313 typedef struct SHADER_BUFFER {
1314     char* buffer;
1315     unsigned int bsize;
1316     unsigned int lineNo;
1317 } SHADER_BUFFER;
1318
1319 typedef struct SHADER_OPCODE {
1320     unsigned int  opcode;
1321     const char*   name;
1322     const char*   glname;
1323     char          dst_token;
1324     CONST UINT    num_params;
1325     shader_fct_t  soft_fct;
1326     SHADER_HANDLER hw_fct;
1327     SHADER_HANDLER hw_glsl_fct;
1328     DWORD         min_version;
1329     DWORD         max_version;
1330 } SHADER_OPCODE;
1331
1332 typedef struct SHADER_OPCODE_ARG {
1333     IWineD3DBaseShader* shader;
1334     shader_reg_maps* reg_maps;
1335     CONST SHADER_OPCODE* opcode;
1336     DWORD dst;
1337     DWORD dst_addr;
1338     DWORD predicate;
1339     DWORD src[4];
1340     DWORD src_addr[4];
1341     SHADER_BUFFER* buffer;
1342 } SHADER_OPCODE_ARG;
1343
1344 typedef struct SHADER_LIMITS {
1345     unsigned int temporary;
1346     unsigned int texcoord;
1347     unsigned int sampler;
1348     unsigned int constant_int;
1349     unsigned int constant_float;
1350     unsigned int constant_bool;
1351     unsigned int address;
1352     unsigned int packed_output;
1353     unsigned int packed_input;
1354     unsigned int attributes;
1355 } SHADER_LIMITS;
1356
1357 /** Keeps track of details for TEX_M#x# shader opcodes which need to 
1358     maintain state information between multiple codes */
1359 typedef struct SHADER_PARSE_STATE {
1360     unsigned int current_row;
1361     DWORD texcoord_w[2];
1362 } SHADER_PARSE_STATE;
1363
1364 /* Base Shader utility functions. 
1365  * (may move callers into the same file in the future) */
1366 extern int shader_addline(
1367     SHADER_BUFFER* buffer,
1368     const char* fmt, ...);
1369
1370 extern const SHADER_OPCODE* shader_get_opcode(
1371     IWineD3DBaseShader *iface, 
1372     const DWORD code);
1373
1374 /* ARB_[vertex/fragment]_program helper functions */
1375 extern void shader_arb_load_constants(
1376     IWineD3DStateBlock* iface,
1377     char usePixelShader,
1378     char useVertexShader);
1379
1380 /* ARB shader program Prototypes */
1381 extern void shader_hw_def(SHADER_OPCODE_ARG *arg);
1382
1383 /* ARB pixel shader prototypes */
1384 extern void pshader_hw_cnd(SHADER_OPCODE_ARG* arg);
1385 extern void pshader_hw_cmp(SHADER_OPCODE_ARG* arg);
1386 extern void pshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1387 extern void pshader_hw_tex(SHADER_OPCODE_ARG* arg);
1388 extern void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg);
1389 extern void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg);
1390 extern void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg);
1391 extern void pshader_hw_texbem(SHADER_OPCODE_ARG* arg);
1392 extern void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG* arg);
1393 extern void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg);
1394 extern void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg);
1395 extern void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg);
1396 extern void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg);
1397 extern void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1398
1399 /* ARB vertex shader prototypes */
1400 extern void vshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1401 extern void vshader_hw_mnxn(SHADER_OPCODE_ARG* arg);
1402
1403 /* GLSL helper functions */
1404 extern void set_glsl_shader_program(IWineD3DDevice *iface);
1405 extern void shader_glsl_add_instruction_modifiers(SHADER_OPCODE_ARG *arg);
1406 extern void shader_glsl_load_constants(
1407     IWineD3DStateBlock* iface,
1408     char usePixelShader,
1409     char useVertexShader);
1410
1411 /** The following translate DirectX pixel/vertex shader opcodes to GLSL lines */
1412 extern void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg);
1413 extern void shader_glsl_arith(SHADER_OPCODE_ARG* arg);
1414 extern void shader_glsl_mov(SHADER_OPCODE_ARG* arg);
1415 extern void shader_glsl_mad(SHADER_OPCODE_ARG* arg);
1416 extern void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg);
1417 extern void shader_glsl_lrp(SHADER_OPCODE_ARG* arg);
1418 extern void shader_glsl_dot(SHADER_OPCODE_ARG* arg);
1419 extern void shader_glsl_rcp(SHADER_OPCODE_ARG* arg);
1420 extern void shader_glsl_cnd(SHADER_OPCODE_ARG* arg);
1421 extern void shader_glsl_compare(SHADER_OPCODE_ARG* arg);
1422 extern void shader_glsl_def(SHADER_OPCODE_ARG* arg);
1423 extern void shader_glsl_defi(SHADER_OPCODE_ARG* arg);
1424 extern void shader_glsl_defb(SHADER_OPCODE_ARG* arg);
1425 extern void shader_glsl_cmp(SHADER_OPCODE_ARG* arg);
1426 extern void shader_glsl_lit(SHADER_OPCODE_ARG* arg);
1427 extern void shader_glsl_dst(SHADER_OPCODE_ARG* arg);
1428 extern void shader_glsl_sincos(SHADER_OPCODE_ARG* arg);
1429 extern void shader_glsl_loop(SHADER_OPCODE_ARG* arg);
1430 extern void shader_glsl_endloop(SHADER_OPCODE_ARG* arg);
1431
1432 /** GLSL Pixel Shader Prototypes */
1433 extern void pshader_glsl_tex(SHADER_OPCODE_ARG* arg);
1434 extern void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg);
1435 extern void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg);
1436 extern void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg);
1437 extern void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg);
1438 extern void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1439 extern void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg);
1440 extern void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg);
1441 extern void pshader_glsl_dp2add(SHADER_OPCODE_ARG* arg);
1442 extern void pshader_glsl_input_pack(
1443    SHADER_BUFFER* buffer,
1444    DWORD* semantics_out);
1445
1446 /** GLSL Vertex Shader Prototypes */
1447 extern void vshader_glsl_output_unpack(
1448    SHADER_BUFFER* buffer,
1449    DWORD* semantics_out);
1450
1451 /*****************************************************************************
1452  * IDirect3DBaseShader implementation structure
1453  */
1454 typedef struct IWineD3DBaseShaderClass
1455 {
1456     DWORD                           hex_version;
1457     SHADER_LIMITS                   limits;
1458     SHADER_PARSE_STATE              parse_state;
1459     CONST SHADER_OPCODE             *shader_ins;
1460     CONST DWORD                     *function;
1461     UINT                            functionLength;
1462     GLuint                          prgId;
1463 } IWineD3DBaseShaderClass;
1464
1465 typedef struct IWineD3DBaseShaderImpl {
1466     /* IUnknown */
1467     const IWineD3DBaseShaderVtbl    *lpVtbl;
1468     LONG                            ref;
1469
1470     /* IWineD3DBaseShader */
1471     IWineD3DBaseShaderClass         baseShader;
1472 } IWineD3DBaseShaderImpl;
1473
1474 extern void shader_get_registers_used(
1475     IWineD3DBaseShader *iface,
1476     shader_reg_maps* reg_maps,
1477     CONST DWORD* pToken);
1478
1479 extern void shader_generate_glsl_declarations(
1480     IWineD3DBaseShader *iface,
1481     shader_reg_maps* reg_maps,
1482     SHADER_BUFFER* buffer);
1483
1484 extern void shader_generate_arb_declarations(
1485     IWineD3DBaseShader *iface,
1486     shader_reg_maps* reg_maps,
1487     SHADER_BUFFER* buffer);
1488
1489 extern void shader_generate_main(
1490     IWineD3DBaseShader *iface,
1491     SHADER_BUFFER* buffer,
1492     shader_reg_maps* reg_maps,
1493     CONST DWORD* pFunction);
1494
1495 extern void shader_dump_ins_modifiers(
1496     const DWORD output);
1497
1498 extern void shader_dump_param(
1499     IWineD3DBaseShader *iface,
1500     const DWORD param,
1501     const DWORD addr_token,
1502     int input);
1503
1504 extern void shader_trace_init(
1505     IWineD3DBaseShader *iface,
1506     const DWORD* pFunction);
1507
1508 extern int shader_get_param(
1509     IWineD3DBaseShader* iface,
1510     const DWORD* pToken,
1511     DWORD* param,
1512     DWORD* addr_token);
1513
1514 extern int shader_skip_unrecognized(
1515     IWineD3DBaseShader* iface,
1516     const DWORD* pToken);
1517
1518 extern void print_glsl_info_log(
1519     WineD3D_GL_Info *gl_info,
1520     GLhandleARB obj);
1521
1522 inline static int shader_get_regtype(const DWORD param) {
1523     return (((param & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) |
1524             ((param & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2));
1525 }
1526
1527 extern unsigned int shader_get_float_offset(const DWORD reg);
1528
1529 inline static BOOL shader_is_pshader_version(DWORD token) {
1530     return 0xFFFF0000 == (token & 0xFFFF0000);
1531 }
1532
1533 inline static BOOL shader_is_vshader_version(DWORD token) {
1534     return 0xFFFE0000 == (token & 0xFFFF0000);
1535 }
1536
1537 inline static BOOL shader_is_comment(DWORD token) {
1538     return D3DSIO_COMMENT == (token & D3DSI_OPCODE_MASK);
1539 }
1540
1541 /*****************************************************************************
1542  * IDirect3DVertexShader implementation structure
1543  */
1544 typedef struct IWineD3DVertexShaderImpl {
1545     /* IUnknown parts*/   
1546     const IWineD3DVertexShaderVtbl *lpVtbl;
1547     LONG                        ref;     /* Note: Ref counting not required */
1548
1549     /* IWineD3DBaseShader */
1550     IWineD3DBaseShaderClass     baseShader;
1551
1552     /* IWineD3DVertexShaderImpl */
1553     IUnknown                    *parent;
1554     IWineD3DDeviceImpl          *wineD3DDevice;
1555
1556     DWORD usage;
1557
1558     /* vertex declaration array mapping */
1559     DWORD arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE];
1560  
1561     /* run time datas...  */
1562     VSHADERDATA                *data;
1563     IWineD3DVertexDeclaration  *vertexDeclaration;
1564 #if 0 /* needs reworking */
1565     /* run time datas */
1566     VSHADERINPUTDATA input;
1567     VSHADEROUTPUTDATA output;
1568 #endif
1569 } IWineD3DVertexShaderImpl;
1570 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1571 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1572
1573 /*****************************************************************************
1574  * IDirect3DPixelShader implementation structure
1575  */
1576 typedef struct IWineD3DPixelShaderImpl {
1577     /* IUnknown parts */
1578     const IWineD3DPixelShaderVtbl *lpVtbl;
1579     LONG                        ref;     /* Note: Ref counting not required */
1580
1581     /* IWineD3DBaseShader */
1582     IWineD3DBaseShaderClass     baseShader;
1583
1584     /* IWineD3DPixelShaderImpl */
1585     IUnknown                   *parent;
1586     IWineD3DDeviceImpl         *wineD3DDevice;
1587
1588     /* run time data */
1589     PSHADERDATA                *data;
1590
1591 #if 0 /* needs reworking */
1592     PSHADERINPUTDATA input;
1593     PSHADEROUTPUTDATA output;
1594 #endif
1595 } IWineD3DPixelShaderImpl;
1596
1597 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1598 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1599
1600 /*****************************************************************************
1601  * IWineD3DPalette implementation structure
1602  */
1603 struct IWineD3DPaletteImpl {
1604     /* IUnknown parts */
1605     const IWineD3DPaletteVtbl  *lpVtbl;
1606     LONG                       ref;
1607
1608     IUnknown                   *parent;
1609     IWineD3DDeviceImpl         *wineD3DDevice;
1610
1611     /* IWineD3DPalette */
1612     HPALETTE                   hpal;
1613     WORD                       palVersion;     /*|               */
1614     WORD                       palNumEntries;  /*|  LOGPALETTE   */
1615     PALETTEENTRY               palents[256];   /*|               */
1616     /* This is to store the palette in 'screen format' */
1617     int                        screen_palents[256];
1618     DWORD                      Flags;
1619 };
1620
1621 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
1622 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
1623
1624 /* DirectDraw utility functions */
1625 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
1626
1627 /*****************************************************************************
1628  * Pixel format management
1629  */
1630 typedef struct {
1631     WINED3DFORMAT           format;
1632     DWORD                   alphaMask, redMask, greenMask, blueMask;
1633     UINT                    bpp;
1634     BOOL                    isFourcc;
1635     GLint                   glInternal, glFormat, glType;
1636 } PixelFormatDesc;
1637
1638 const PixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt);
1639 #endif