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