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