Implement a pixel shader parser and cross compiler. All version of
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 "wine/wined3d_interface.h"
43 #include "wine/wined3d_gl.h"
44
45 /* Device caps */
46 #define MAX_PALETTES      256
47 #define MAX_STREAMS       16
48 #define MAX_TEXTURES      8
49 #define MAX_SAMPLERS      16
50 #define MAX_ACTIVE_LIGHTS 8
51 #define MAX_CLIPPLANES    D3DMAXUSERCLIPPLANES
52 #define MAX_LEVELS        256
53
54 #define MAX_VSHADER_CONSTANTS 96
55 #define MAX_PSHADER_CONSTANTS 32
56
57 /* Used for CreateStateBlock */
58 #define NUM_SAVEDPIXELSTATES_R     35
59 #define NUM_SAVEDPIXELSTATES_T     18
60 #define NUM_SAVEDPIXELSTATES_S     12
61 #define NUM_SAVEDVERTEXSTATES_R    31
62 #define NUM_SAVEDVERTEXSTATES_T    2
63 #define NUM_SAVEDVERTEXSTATES_S    1
64
65 extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
66 extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
67 extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
68 extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
69 extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
70 extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
71
72 typedef enum _WINELOOKUP {
73     WINELOOKUP_WARPPARAM = 0,
74     WINELOOKUP_MAGFILTER = 1,
75     MAX_LOOKUPS          = 2
76 } WINELOOKUP;
77
78 extern int minLookup[MAX_LOOKUPS];
79 extern int maxLookup[MAX_LOOKUPS];
80 extern DWORD *stateLookup[MAX_LOOKUPS];
81
82 extern DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
83
84 /* NOTE: Make sure these are in the correct numerical order. (see /include/d3d9types.h typedef enum _D3DDECLTYPE) */
85 UINT static const glTypeLookup[D3DDECLTYPE_UNUSED][5] = {
86                                   {D3DDECLTYPE_FLOAT1,    1, GL_FLOAT           , GL_FALSE ,sizeof(float)},
87                                   {D3DDECLTYPE_FLOAT2,    2, GL_FLOAT           , GL_FALSE ,sizeof(float)},
88                                   {D3DDECLTYPE_FLOAT3,    3, GL_FLOAT           , GL_FALSE ,sizeof(float)},
89                                   {D3DDECLTYPE_FLOAT4,    4, GL_FLOAT           , GL_FALSE ,sizeof(float)},
90                                   {D3DDECLTYPE_D3DCOLOR,  4, GL_UNSIGNED_BYTE   , GL_TRUE  ,sizeof(BYTE)},
91                                   {D3DDECLTYPE_UBYTE4,    4, GL_UNSIGNED_BYTE   , GL_FALSE ,sizeof(BYTE)},
92                                   {D3DDECLTYPE_SHORT2,    2, GL_SHORT           , GL_FALSE ,sizeof(short int)},
93                                   {D3DDECLTYPE_SHORT4,    4, GL_SHORT           , GL_FALSE ,sizeof(short int)},
94                                   {D3DDECLTYPE_UBYTE4N,   4, GL_UNSIGNED_BYTE   , GL_FALSE ,sizeof(BYTE)},
95                                   {D3DDECLTYPE_SHORT2N,   2, GL_SHORT           , GL_FALSE ,sizeof(short int)},
96                                   {D3DDECLTYPE_SHORT4N,   4, GL_SHORT           , GL_FALSE ,sizeof(short int)},
97                                   {D3DDECLTYPE_USHORT2N,  2, GL_UNSIGNED_SHORT  , GL_FALSE ,sizeof(short int)},
98                                   {D3DDECLTYPE_USHORT4N,  4, GL_UNSIGNED_SHORT  , GL_FALSE ,sizeof(short int)},
99                                   {D3DDECLTYPE_UDEC3,     3, GL_UNSIGNED_SHORT  , GL_FALSE ,sizeof(short int)},
100                                   {D3DDECLTYPE_DEC3N,     3, GL_SHORT           , GL_FALSE ,sizeof(short int)},
101                                   {D3DDECLTYPE_FLOAT16_2, 2, GL_FLOAT           , GL_FALSE ,sizeof(short int)},
102                                   {D3DDECLTYPE_FLOAT16_4, 4, GL_FLOAT           , GL_FALSE ,sizeof(short int)}};
103
104 #define WINED3D_ATR_TYPE(_attribute)          glTypeLookup[sd->u.s._attribute.dwType][0]
105 #define WINED3D_ATR_SIZE(_attribute)          glTypeLookup[sd->u.s._attribute.dwType][1]
106 #define WINED3D_ATR_GLTYPE(_attribute)        glTypeLookup[sd->u.s._attribute.dwType][2]
107 #define WINED3D_ATR_NORMALIZED(_attribute)    glTypeLookup[sd->u.s._attribute.dwType][3]
108 #define WINED3D_ATR_TYPESIZE(_attribute)      glTypeLookup[sd->u.s._attribute.dwType][4]
109
110 /**
111  * Settings 
112  */
113 #define VS_NONE    0
114 #define VS_HW      1
115 #define VS_SW      2
116
117 #define PS_NONE    0
118 #define PS_HW      1
119
120 #define VBO_NONE   0
121 #define VBO_HW     1
122
123 #define NP2_NONE   0
124 #define NP2_REPACK 1
125
126 typedef struct wined3d_settings_s {
127 /* vertex and pixel shader modes */
128   int vs_mode;
129   int ps_mode;
130   int vbo_mode;
131 /* nonpower 2 function */
132   int nonpower2_mode;
133 } wined3d_settings_t;
134
135 extern wined3d_settings_t wined3d_settings;
136
137 /* X11 locking */
138
139 extern void (*wine_tsx11_lock_ptr)(void);
140 extern void (*wine_tsx11_unlock_ptr)(void);
141
142 /* As GLX relies on X, this is needed */
143 extern int num_lock;
144
145 #if 0
146 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
147 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
148 #else
149 #define ENTER_GL() wine_tsx11_lock_ptr()
150 #define LEAVE_GL() wine_tsx11_unlock_ptr()
151 #endif
152
153 /*****************************************************************************
154  * Defines
155  */
156
157 /* GL related defines */
158 /* ------------------ */
159 #define GL_SUPPORT(ExtName)           (GLINFO_LOCATION.supported[ExtName] != 0)
160 #define GL_LIMITS(ExtName)            (GLINFO_LOCATION.max_##ExtName)
161 #define GL_EXTCALL(FuncName)          (GLINFO_LOCATION.FuncName)
162 #define GL_VEND(_VendName)            (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
163
164 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
165 #define D3DCOLOR_B_G(dw) (((dw) >>  8) & 0xFF)
166 #define D3DCOLOR_B_B(dw) (((dw) >>  0) & 0xFF)
167 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
168
169 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
170 #define D3DCOLOR_G(dw) (((float) (((dw) >>  8) & 0xFF)) / 255.0f)
171 #define D3DCOLOR_B(dw) (((float) (((dw) >>  0) & 0xFF)) / 255.0f)
172 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
173
174 #define D3DCOLORTOGLFLOAT4(dw, vec) \
175   (vec)[0] = D3DCOLOR_R(dw); \
176   (vec)[1] = D3DCOLOR_G(dw); \
177   (vec)[2] = D3DCOLOR_B(dw); \
178   (vec)[3] = D3DCOLOR_A(dw);
179   
180 /* Note: The following is purely to keep the source code as clear from #ifdefs as possible */
181 #if defined(GL_VERSION_1_3)
182 #define GLACTIVETEXTURE(textureNo)                          \
183             glActiveTexture(GL_TEXTURE0 + textureNo);       \
184             checkGLcall("glActiveTexture");      
185 #define GLCLIENTACTIVETEXTURE(textureNo)                    \
186             glClientActiveTexture(GL_TEXTURE0 + textureNo);
187 #define GLMULTITEXCOORD1F(a,b)                              \
188             glMultiTexCoord1f(GL_TEXTURE0 + a, b);
189 #define GLMULTITEXCOORD2F(a,b,c)                            \
190             glMultiTexCoord2f(GL_TEXTURE0 + a, b, c);
191 #define GLMULTITEXCOORD3F(a,b,c,d)                          \
192             glMultiTexCoord3f(GL_TEXTURE0 + a, b, c, d);
193 #define GLMULTITEXCOORD4F(a,b,c,d,e)                        \
194             glMultiTexCoord4f(GL_TEXTURE0 + a, b, c, d, e);
195 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP
196 #else 
197 #define GLACTIVETEXTURE(textureNo)                             \
198             glActiveTextureARB(GL_TEXTURE0_ARB + textureNo);   \
199             checkGLcall("glActiveTextureARB");
200 #define GLCLIENTACTIVETEXTURE(textureNo)                    \
201             glClientActiveTextureARB(GL_TEXTURE0_ARB + textureNo);
202 #define GLMULTITEXCOORD1F(a,b)                                 \
203             glMultiTexCoord1fARB(GL_TEXTURE0_ARB + a, b);
204 #define GLMULTITEXCOORD2F(a,b,c)                               \
205             glMultiTexCoord2fARB(GL_TEXTURE0_ARB + a, b, c);
206 #define GLMULTITEXCOORD3F(a,b,c,d)                             \
207             glMultiTexCoord3fARB(GL_TEXTURE0_ARB + a, b, c, d);
208 #define GLMULTITEXCOORD4F(a,b,c,d,e)                           \
209             glMultiTexCoord4fARB(GL_TEXTURE0_ARB + a, b, c, d, e);
210 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP_ARB
211 #endif
212
213 /* DirectX Device Limits */
214 /* --------------------- */
215 #define MAX_LEVELS  256  /* Maximum number of mipmap levels. Guessed at 256 */
216
217 #define MAX_STREAMS  16  /* Maximum possible streams - used for fixed size arrays
218                             See MaxStreams in MSDN under GetDeviceCaps */
219                          /* Maximum number of constants provided to the shaders */
220 #define HIGHEST_TRANSFORMSTATE 512 
221                          /* Highest value in D3DTRANSFORMSTATETYPE */
222 #define MAX_CLIPPLANES  D3DMAXUSERCLIPPLANES
223
224 #define MAX_PALETTES      256
225
226 /* Checking of API calls */
227 /* --------------------- */
228 #define checkGLcall(A) \
229 { \
230     GLint err = glGetError();   \
231     if (err != GL_NO_ERROR) { \
232        FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
233     } else { \
234        TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
235     } \
236 }
237
238 /* Trace routines / diagnostics */
239 /* ---------------------------- */
240
241 /* Dump out a matrix and copy it */
242 #define conv_mat(mat,gl_mat)                                                                \
243 do {                                                                                        \
244     TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
245     TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
246     TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
247     TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
248     memcpy(gl_mat, (mat), 16 * sizeof(float));                                              \
249 } while (0)
250
251 /* Macro to dump out the current state of the light chain */
252 #define DUMP_LIGHT_CHAIN()                    \
253 {                                             \
254   PLIGHTINFOEL *el = This->stateBlock->lights;\
255   while (el) {                                \
256     TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
257     el = el->next;                            \
258   }                                           \
259 }
260
261 /* Trace vector and strided data information */
262 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
263 #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);
264
265 /* Defines used for optimizations */
266
267 /*    Only reapply what is necessary */
268 #define REAPPLY_ALPHAOP  0x0001
269 #define REAPPLY_ALL      0xFFFF
270
271 /* Advance declaration of structures to satisfy compiler */
272 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
273 typedef struct IWineD3DSurfaceImpl    IWineD3DSurfaceImpl;
274
275 /* Tracking */
276
277 /* TODO: Move some of this to the device */
278 long globalChangeGlRam(long glram);
279
280 /* Memory and object tracking */
281
282 /*Structure for holding information on all direct3d objects
283 useful for making sure tracking is ok and when release is called on a device!
284 and probably quite handy for debugging and dumping states out
285 */
286 typedef struct WineD3DGlobalStatistics {
287     int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
288 } WineD3DGlobalStatistics;
289
290 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
291
292 /* Global variables */
293 extern const float identity[16];
294
295 /*****************************************************************************
296  * Compilable extra diagnostics
297  */
298
299 /* Trace information per-vertex: (extremely high amount of trace) */
300 #if 0 /* NOTE: Must be 0 in cvs */
301 # define VTRACE(A) TRACE A
302 #else 
303 # define VTRACE(A) 
304 #endif
305
306 /* Checking of per-vertex related GL calls */
307 #define vcheckGLcall(A) \
308 { \
309     GLint err = glGetError();   \
310     if (err != GL_NO_ERROR) { \
311        FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
312     } else { \
313        VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
314     } \
315 }
316
317 /* TODO: Confirm each of these works when wined3d move completed */
318 #if 0 /* NOTE: Must be 0 in cvs */
319   /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
320      of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
321      is enabled, and if it doesn't exists it is disabled.                                           */
322 # define FRAME_DEBUGGING
323   /*  Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
324       the file is deleted                                                                            */
325 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
326 #  define SINGLE_FRAME_DEBUGGING
327 # endif  
328   /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
329      It can only be enabled when FRAME_DEBUGGING is also enabled                               
330      The contents of the back buffer are written into /tmp/backbuffer_* after each primitive 
331      array is drawn.                                                                            */
332 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */                                                                                       
333 #  define SHOW_FRAME_MAKEUP 1
334 # endif  
335   /* The following, when enabled, lets you see the makeup of the all the textures used during each
336      of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
337      The contents of the textures assigned to each stage are written into 
338      /tmp/texture_*_<Stage>.ppm after each primitive array is drawn.                            */
339 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
340 #  define SHOW_TEXTURE_MAKEUP 0
341 # endif  
342 extern BOOL isOn;
343 extern BOOL isDumpingFrames;
344 extern LONG primCounter;
345 #endif
346
347 /*****************************************************************************
348  * Prototypes
349  */
350
351 /* Routine common to the draw primitive and draw indexed primitive routines */
352 void drawPrimitive(IWineD3DDevice *iface,
353                     int PrimitiveType,
354                     long NumPrimitives,
355                     /* for Indexed: */
356                     long  StartVertexIndex,
357                     UINT  numberOfVertices,
358                     long  StartIdx,
359                     short idxBytes,
360                     const void *idxData,
361                     int   minIndex);
362
363 /*****************************************************************************
364  * Structures required to draw primitives 
365  */
366
367 typedef struct Direct3DStridedData {
368     BYTE     *lpData;        /* Pointer to start of data               */
369     DWORD     dwStride;      /* Stride between occurances of this data */
370     DWORD     dwType;        /* Type (as in D3DVSDT_TYPE)              */
371 } Direct3DStridedData;
372
373 typedef struct Direct3DVertexStridedData {
374     union {
375         struct {
376              Direct3DStridedData  position;
377              Direct3DStridedData  blendWeights;
378              Direct3DStridedData  blendMatrixIndices;
379              Direct3DStridedData  normal;
380              Direct3DStridedData  pSize;
381              Direct3DStridedData  diffuse;
382              Direct3DStridedData  specular;
383              Direct3DStridedData  texCoords[MAX_TEXTURES];
384              Direct3DStridedData  position2; /* tween data */
385              Direct3DStridedData  normal2;   /* tween data */
386              Direct3DStridedData  tangent;
387              Direct3DStridedData  binormal;
388              Direct3DStridedData  tessFactor;
389              Direct3DStridedData  fog;
390              Direct3DStridedData  depth;
391              Direct3DStridedData  sample;
392         } s;
393         Direct3DStridedData input[16];  /* Indexed by constants in D3DVSDE_REGISTER */
394     } u;
395 } Direct3DVertexStridedData;
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 /*****************************************************************************
477  * IWineD3DDevice implementation structure
478  */
479 typedef struct IWineD3DDeviceImpl
480 {
481     /* IUnknown fields      */
482     const IWineD3DDeviceVtbl *lpVtbl;
483     LONG                    ref;     /* Note: Ref counting not required */
484
485     /* WineD3D Information  */
486     IUnknown               *parent;
487     IWineD3D               *wineD3D;
488
489     /* X and GL Information */
490     GLint                   maxConcurrentLights;
491
492     /* Optimization */
493     BOOL                    modelview_valid;
494     BOOL                    proj_valid;
495     BOOL                    view_ident;        /* true iff view matrix is identity                */
496     BOOL                    last_was_rhw;      /* true iff last draw_primitive was in xyzrhw mode */
497     GLenum                  tracking_parm;     /* Which source is tracking current colour         */
498     LONG                    tracking_color;    /* used iff GL_COLOR_MATERIAL was enabled          */
499 #define                         DISABLED_TRACKING  0  /* Disabled                                 */
500 #define                         IS_TRACKING        1  /* tracking_parm is tracking diffuse color  */
501 #define                         NEEDS_TRACKING     2  /* Tracking needs to be enabled when needed */
502 #define                         NEEDS_DISABLE      3  /* Tracking needs to be disabled when needed*/
503     UINT                    srcBlend;
504     UINT                    dstBlend;
505     UINT                    alphafunc;
506     UINT                    stencilfunc;
507     BOOL                    texture_shader_active;  /* TODO: Confirm use is correct */
508
509     /* State block related */
510     BOOL                    isRecordingState;
511     IWineD3DStateBlockImpl *stateBlock;
512     IWineD3DStateBlockImpl *updateStateBlock;
513
514     /* Internal use fields  */
515     D3DDEVICE_CREATION_PARAMETERS   createParms;
516     UINT                            adapterNo;
517     D3DDEVTYPE                      devType;
518
519     SwapChainList          *swapchains;
520
521     ResourceList           *resources; /* a linked list to track resources created by the device */
522
523     /* Render Target Support */
524     IWineD3DSurface        *depthStencilBuffer;
525
526     IWineD3DSurface        *renderTarget;
527     IWineD3DSurface        *stencilBufferTarget;
528
529     /* palettes texture management */
530     PALETTEENTRY            palettes[MAX_PALETTES][256];
531     UINT                    currentPalette;
532
533     /* For rendering to a texture using glCopyTexImage */
534     BOOL                    renderUpsideDown;
535
536     /* Cursor management */
537     BOOL                    bCursorVisible;
538     UINT                    xHotSpot;
539     UINT                    yHotSpot;
540     UINT                    xScreenSpace;
541     UINT                    yScreenSpace;
542
543     /* Textures for when no other textures are mapped */
544     UINT                          dummyTextureName[MAX_TEXTURES];
545
546     /* Debug stream management */
547     BOOL                     debug;
548
549     /* Device state management */
550     HRESULT                 state;
551
552     /* Screen buffer resources */
553     glContext contextCache[CONTEXT_CACHE];
554
555     /* A flag to check if endscene has been called before changing the render tartet */
556     BOOL sceneEnded;
557
558     /* process vertex shaders using software or hardware */
559     BOOL softwareVertexProcessing;
560     
561 } IWineD3DDeviceImpl;
562
563 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
564
565 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
566  * anybody uses it for much so a good implementation is optional. */
567 typedef struct PrivateData
568 {
569     struct PrivateData* next;
570
571     GUID tag;
572     DWORD flags; /* DDSPD_* */
573     DWORD uniqueness_value;
574
575     union
576     {
577         LPVOID data;
578         LPUNKNOWN object;
579     } ptr;
580
581     DWORD size;
582 } PrivateData;
583
584 /*****************************************************************************
585  * IWineD3DResource implementation structure
586  */
587 typedef struct IWineD3DResourceClass
588 {
589     /* IUnknown fields */
590     LONG                    ref;     /* Note: Ref counting not required */
591
592     /* WineD3DResource Information */
593     IUnknown               *parent;
594     D3DRESOURCETYPE         resourceType;
595     IWineD3DDeviceImpl     *wineD3DDevice;
596     D3DPOOL                 pool;
597     UINT                    size;
598     DWORD                   usage;
599     WINED3DFORMAT           format;
600     BYTE                   *allocatedMemory;
601     PrivateData            *privateData;
602
603 } IWineD3DResourceClass;
604
605 typedef struct IWineD3DResourceImpl
606 {
607     /* IUnknown & WineD3DResource Information     */
608     const IWineD3DResourceVtbl *lpVtbl;
609     IWineD3DResourceClass   resource;
610 } IWineD3DResourceImpl;
611
612
613 /*****************************************************************************
614  * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
615  */
616 typedef struct IWineD3DVertexBufferImpl
617 {
618     /* IUnknown & WineD3DResource Information     */
619     const IWineD3DVertexBufferVtbl *lpVtbl;
620     IWineD3DResourceClass     resource;
621
622     /* WineD3DVertexBuffer specifics */
623     DWORD                     fvf;
624
625 } IWineD3DVertexBufferImpl;
626
627 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
628
629
630 /*****************************************************************************
631  * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
632  */
633 typedef struct IWineD3DIndexBufferImpl
634 {
635     /* IUnknown & WineD3DResource Information     */
636     const IWineD3DIndexBufferVtbl *lpVtbl;
637     IWineD3DResourceClass     resource;
638
639     /* WineD3DVertexBuffer specifics */
640 } IWineD3DIndexBufferImpl;
641
642 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
643
644 /*****************************************************************************
645  * IWineD3DBaseTexture D3D- > openGL state map lookups
646  */
647 #define WINED3DFUNC_NOTSUPPORTED  -2
648 #define WINED3DFUNC_UNIMPLEMENTED -1
649
650 typedef enum winetexturestates {
651     WINED3DTEXSTA_ADDRESSU       = 0,
652     WINED3DTEXSTA_ADDRESSV       = 1,
653     WINED3DTEXSTA_ADDRESSW       = 2,
654     WINED3DTEXSTA_BORDERCOLOR    = 3,
655     WINED3DTEXSTA_MAGFILTER      = 4,
656     WINED3DTEXSTA_MINFILTER      = 5,
657     WINED3DTEXSTA_MIPFILTER      = 6,
658     WINED3DTEXSTA_MAXMIPLEVEL    = 7,
659     WINED3DTEXSTA_MAXANISOTROPY  = 8,
660     WINED3DTEXSTA_SRGBTEXTURE    = 9,
661     WINED3DTEXSTA_ELEMENTINDEX   = 10,
662     WINED3DTEXSTA_DMAPOFFSET     = 11,
663     WINED3DTEXSTA_TSSADDRESSW    = 12,
664     MAX_WINETEXTURESTATES        = 13,
665 } winetexturestates;
666
667 typedef struct Wined3dTextureStateMap {
668     CONST int state;
669     int function;
670 } Wined3dTextureStateMap;
671
672 /*****************************************************************************
673  * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
674  */
675 typedef struct IWineD3DBaseTextureClass
676 {
677     UINT                    levels;
678     BOOL                    dirty;
679     D3DFORMAT               format;
680     DWORD                   usage;
681     UINT                    textureName;
682     UINT                    LOD;
683     D3DTEXTUREFILTERTYPE    filterType;
684     DWORD                   states[MAX_WINETEXTURESTATES];
685
686 } IWineD3DBaseTextureClass;
687
688 typedef struct IWineD3DBaseTextureImpl
689 {
690     /* IUnknown & WineD3DResource Information     */
691     const IWineD3DBaseTextureVtbl *lpVtbl;
692     IWineD3DResourceClass     resource;
693     IWineD3DBaseTextureClass  baseTexture;
694
695 } IWineD3DBaseTextureImpl;
696
697 /*****************************************************************************
698  * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
699  */
700 typedef struct IWineD3DTextureImpl
701 {
702     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
703     const IWineD3DTextureVtbl *lpVtbl;
704     IWineD3DResourceClass     resource;
705     IWineD3DBaseTextureClass  baseTexture;
706
707     /* IWineD3DTexture */
708     IWineD3DSurface          *surfaces[MAX_LEVELS];
709     
710     UINT                      width;
711     UINT                      height;
712     float                     pow2scalingFactorX;
713     float                     pow2scalingFactorY;
714
715 } IWineD3DTextureImpl;
716
717 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
718
719 /*****************************************************************************
720  * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
721  */
722 typedef struct IWineD3DCubeTextureImpl
723 {
724     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
725     const IWineD3DCubeTextureVtbl *lpVtbl;
726     IWineD3DResourceClass     resource;
727     IWineD3DBaseTextureClass  baseTexture;
728
729     /* IWineD3DCubeTexture */
730     IWineD3DSurface          *surfaces[6][MAX_LEVELS];
731
732     UINT                      edgeLength;
733     float                     pow2scalingFactor;
734
735 } IWineD3DCubeTextureImpl;
736
737 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
738
739 /*****************************************************************************
740  * IWineD3DVolume implementation structure (extends IUnknown)
741  */
742 typedef struct IWineD3DVolumeImpl
743 {
744     /* IUnknown & WineD3DResource fields */
745     const IWineD3DVolumeVtbl  *lpVtbl;
746     IWineD3DResourceClass      resource;
747
748     /* WineD3DVolume Information */
749     D3DVOLUME_DESC          currentDesc;
750     IUnknown               *container;
751     UINT                    bytesPerPixel;
752
753     BOOL                    lockable;
754     BOOL                    locked;
755     D3DBOX                  lockedBox;
756     D3DBOX                  dirtyBox;
757     BOOL                    dirty;
758
759
760 } IWineD3DVolumeImpl;
761
762 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
763
764 /*****************************************************************************
765  * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
766  */
767 typedef struct IWineD3DVolumeTextureImpl
768 {
769     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
770     const IWineD3DVolumeTextureVtbl *lpVtbl;
771     IWineD3DResourceClass     resource;
772     IWineD3DBaseTextureClass  baseTexture;
773
774     /* IWineD3DVolumeTexture */
775     IWineD3DVolume           *volumes[MAX_LEVELS];
776
777     UINT                      width;
778     UINT                      height;
779     UINT                      depth;
780 } IWineD3DVolumeTextureImpl;
781
782 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
783
784 typedef struct _WINED3DSURFACET_DESC
785 {
786     D3DMULTISAMPLE_TYPE MultiSampleType;
787     DWORD               MultiSampleQuality;
788     UINT                Width;
789     UINT                Height;
790 } WINED3DSURFACET_DESC;
791
792 /*****************************************************************************
793  * IWineD3DSurface implementation structure
794  */
795 struct IWineD3DSurfaceImpl
796 {
797     /* IUnknown & IWineD3DResource Information     */
798     const IWineD3DSurfaceVtbl *lpVtbl;
799     IWineD3DResourceClass     resource;
800
801     /* IWineD3DSurface fields */
802     IUnknown                 *container;
803     WINED3DSURFACET_DESC      currentDesc;
804
805     UINT                      textureName;
806     UINT                      bytesPerPixel;
807
808     /* TODO: move this off into a management class(maybe!) */
809     BOOL                      nonpow2;
810
811     UINT                      pow2Width;
812     UINT                      pow2Height;
813     UINT                      pow2Size;
814
815 #if 0
816     /* precalculated x and y scalings for texture coords */
817     float                     pow2scalingFactorX; /* =  (Width  / pow2Width ) */
818     float                     pow2scalingFactorY; /* =  (Height / pow2Height) */
819 #endif
820
821     BOOL                      lockable;
822     BOOL                      discard;
823     BOOL                      locked;
824     BOOL                      activeLock;
825     
826     RECT                      lockedRect;
827     RECT                      dirtyRect;
828     BOOL                      Dirty;
829     
830     BOOL                      inTexture;
831     BOOL                      inPBuffer;
832
833     glDescriptor              glDescription;
834 };
835
836 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
837
838 /*****************************************************************************
839  * IWineD3DVertexDeclaration implementation structure
840  */
841 typedef struct IWineD3DVertexDeclarationImpl {
842  /* IUnknown  Information     */
843   const IWineD3DVertexDeclarationVtbl *lpVtbl;
844   LONG                    ref;     /* Note: Ref counting not required */
845
846   IUnknown               *parent;
847   /** precomputed fvf if simple declaration */
848   IWineD3DDeviceImpl     *wineD3DDevice;
849   DWORD   fvf[MAX_STREAMS];
850   DWORD   allFVF;
851
852   /** dx8 compatible Declaration fields */
853   DWORD*  pDeclaration8;
854   DWORD   declaration8Length;
855
856   /** dx9+ */
857   D3DVERTEXELEMENT9* pDeclaration9;
858   UINT               declaration9NumElements;
859 } IWineD3DVertexDeclarationImpl;
860
861 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
862
863 /*****************************************************************************
864  * IWineD3DStateBlock implementation structure
865  */
866
867 /* Internal state Block for Begin/End/Capture/Create/Apply info  */
868 /*   Note: Very long winded but gl Lists are not flexible enough */
869 /*   to resolve everything we need, so doing it manually for now */
870 typedef struct SAVEDSTATES {
871         BOOL                      indices;
872         BOOL                      material;
873         BOOL                      fvf;
874         BOOL                      streamSource[MAX_STREAMS];
875         BOOL                      streamFreq[MAX_STREAMS];
876         BOOL                      textures[MAX_TEXTURES];
877         BOOL                      transform[HIGHEST_TRANSFORMSTATE + 1];
878         BOOL                      viewport;
879         BOOL                      renderState[WINEHIGHEST_RENDER_STATE + 1];
880         BOOL                      textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
881         BOOL                      samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
882         BOOL                      clipplane[MAX_CLIPPLANES];
883         BOOL                      vertexDecl;
884         BOOL                      pixelShader;
885         BOOL                      pixelShaderConstants[MAX_PSHADER_CONSTANTS];
886         BOOL                      vertexShader;
887         BOOL                      vertexShaderConstants[MAX_VSHADER_CONSTANTS];
888 } SAVEDSTATES;
889
890 typedef enum {
891     WINESHADERCNST_FLOAT    = 0,
892     WINESHADERCNST_INTEGER  = 1,
893     WINESHADERCNST_BOOL     = 2
894 } WINESHADERCNST;
895
896 struct IWineD3DStateBlockImpl
897 {
898     /* IUnknown fields */
899     const IWineD3DStateBlockVtbl *lpVtbl;
900     LONG                      ref;     /* Note: Ref counting not required */
901
902     /* IWineD3DStateBlock information */
903     IUnknown                 *parent;
904     IWineD3DDeviceImpl       *wineD3DDevice;
905     WINED3DSTATEBLOCKTYPE     blockType;
906
907     /* Array indicating whether things have been set or changed */
908     SAVEDSTATES               changed;
909     SAVEDSTATES               set;
910
911     /* Drawing - Vertex Shader or FVF related */
912     DWORD                     fvf;
913     /* Vertex Shader Declaration */
914     IWineD3DVertexDeclaration *vertexDecl;
915
916     IWineD3DVertexShader      *vertexShader;
917
918     /* Vertex Shader Constants */
919     BOOL                       vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
920     INT                        vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
921     float                      vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
922     WINESHADERCNST             vertexShaderConstantT[MAX_VSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
923
924     /* Stream Source */
925     BOOL                      streamIsUP;
926     UINT                      streamStride[MAX_STREAMS];
927     UINT                      streamOffset[MAX_STREAMS];
928     IWineD3DVertexBuffer     *streamSource[MAX_STREAMS];
929     UINT                      streamFreq[MAX_STREAMS];
930     UINT                      streamFlags[MAX_STREAMS];     /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA  */
931
932     /* Indices */
933     IWineD3DIndexBuffer*      pIndexData;
934     UINT                      baseVertexIndex; /* Note: only used for d3d8 */
935
936     /* Transform */
937     D3DMATRIX                 transforms[HIGHEST_TRANSFORMSTATE + 1];
938
939     /* Lights */
940     PLIGHTINFOEL             *lights; /* NOTE: active GL lights must be front of the chain */
941
942     /* Clipping */
943     double                    clipplane[MAX_CLIPPLANES][4];
944     WINED3DCLIPSTATUS         clip_status;
945
946     /* ViewPort */
947     WINED3DVIEWPORT           viewport;
948
949     /* Material */
950     WINED3DMATERIAL           material;
951
952     /* Pixel Shader */
953     IWineD3DPixelShader      *pixelShader;
954
955     /* Pixel Shader Constants */
956     BOOL                       pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
957     INT                        pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
958     float                      pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
959     WINESHADERCNST             pixelShaderConstantT[MAX_PSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
960
961     /* Indexed Vertex Blending */
962     D3DVERTEXBLENDFLAGS       vertex_blend;
963     FLOAT                     tween_factor;
964
965     /* RenderState */
966     DWORD                     renderState[WINEHIGHEST_RENDER_STATE + 1];
967
968     /* Texture */
969     IWineD3DBaseTexture      *textures[MAX_TEXTURES];
970     int                       textureDimensions[MAX_SAMPLERS];
971
972     /* Texture State Stage */
973     DWORD                     textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
974     /* Sampler States */
975     DWORD                     samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
976
977 };
978
979 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
980
981 /*****************************************************************************
982  * IWineD3DQueryImpl implementation structure (extends IUnknown)
983  */
984 typedef struct IWineD3DQueryImpl
985 {
986     const IWineD3DQueryVtbl  *lpVtbl;
987     LONG                      ref;     /* Note: Ref counting not required */
988     
989     IUnknown                 *parent;
990     /*TODO: replace with iface usage */
991 #if 0
992     IWineD3DDevice         *wineD3DDevice;
993 #else
994     IWineD3DDeviceImpl       *wineD3DDevice;
995 #endif
996     /* IWineD3DQuery fields */
997
998     D3DQUERYTYPE              type;
999     /* TODO: Think about using a IUnknown instead of a void* */
1000     void                     *extendedData;
1001     
1002   
1003 } IWineD3DQueryImpl;
1004
1005 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1006
1007 /* Datastructures for IWineD3DQueryImpl.extendedData */
1008 typedef struct  WineQueryOcclusionData {
1009        unsigned int queryId;
1010 } WineQueryOcclusionData;
1011
1012
1013 /*****************************************************************************
1014  * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1015  */
1016
1017 typedef struct IWineD3DSwapChainImpl
1018 {
1019     /*IUnknown part*/
1020     IWineD3DSwapChainVtbl    *lpVtbl;
1021     LONG                      ref;     /* Note: Ref counting not required */
1022
1023     IUnknown                 *parent;
1024     IWineD3DDeviceImpl       *wineD3DDevice;
1025
1026     /* IWineD3DSwapChain fields */
1027     IWineD3DSurface          *backBuffer;
1028     IWineD3DSurface          *frontBuffer;
1029     BOOL                      wantsDepthStencilBuffer;
1030     D3DPRESENT_PARAMETERS     presentParms;
1031
1032     /* TODO: move everything upto drawable off into a context manager
1033       and store the 'data' in the contextManagerData interface.
1034     IUnknown                  *contextManagerData;
1035     */
1036
1037     HWND                    win_handle;
1038     Window                  win;
1039     Display                *display;
1040
1041     GLXContext              glCtx;
1042     XVisualInfo            *visInfo;
1043     GLXContext              render_ctx;
1044     /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1045     Drawable                drawable;
1046 } IWineD3DSwapChainImpl;
1047
1048 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1049
1050 /*****************************************************************************
1051  * Utility function prototypes 
1052  */
1053
1054 /* Trace routines */
1055 const char* debug_d3dformat(WINED3DFORMAT fmt);
1056 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1057 const char* debug_d3dresourcetype(D3DRESOURCETYPE res);
1058 const char* debug_d3dusage(DWORD usage);
1059 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1060 const char* debug_d3drenderstate(DWORD state);
1061 const char* debug_d3dtexturestate(DWORD state);
1062 const char* debug_d3dpool(D3DPOOL pool);
1063
1064 /* Routines for GL <-> D3D values */
1065 GLenum StencilOp(DWORD op);
1066 void   set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1067 void   set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1068 void   GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
1069
1070 SHORT  D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1071 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1072 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
1073 GLint  D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1074
1075 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1076
1077
1078 /*****************************************************************************
1079  * To enable calling of inherited functions, requires prototypes 
1080  *
1081  * Note: Only require classes which are subclassed, ie resource, basetexture, 
1082  */
1083     /*** IUnknown methods ***/
1084     extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1085     extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1086     extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1087     /*** IWineD3DResource methods ***/
1088     extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1089     extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1090     extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1091     extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1092     extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID  refguid);
1093     extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD  PriorityNew);
1094     extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1095     extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1096     extern D3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1097     /*** class static members ***/
1098     void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1099
1100     /*** IUnknown methods ***/
1101     extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1102     extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1103     extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1104     /*** IWineD3DResource methods ***/
1105     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1106     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1107     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1108     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1109     extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid);
1110     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD  PriorityNew);
1111     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1112     extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1113     extern D3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1114     /*** IWineD3DBaseTexture methods ***/
1115     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1116     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1117     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1118     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, D3DTEXTUREFILTERTYPE FilterType);
1119     extern D3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1120     extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1121     extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1122     extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1123
1124     extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset);
1125     extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1126     extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1127     extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1128     extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1129     /*** class static members ***/
1130     void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1131
1132 /* An enum for the type of constants that are used... addressing causes
1133  * problems with being able to work out what's used and what's not.. so
1134  * maybe we'll have to rely on the server vertex shader const functions?
1135  */
1136 enum vsConstantsEnum {
1137     VS_CONSTANT_NOT_USED = 0,
1138     VS_CONSTANT_CONSTANT,
1139     VS_CONSTANT_INTEGER,
1140     VS_CONSTANT_BOOLEAN,
1141     VS_CONSTANT_FLOAT
1142 };
1143
1144 /*****************************************************************************
1145  * IDirect3DVertexShader implementation structure
1146  */
1147 typedef struct IWineD3DVertexShaderImpl {
1148     /* IUnknown parts*/   
1149     const IWineD3DVertexShaderVtbl *lpVtbl;
1150     LONG                        ref;     /* Note: Ref counting not required */
1151
1152     IUnknown                    *parent;
1153     IWineD3DDeviceImpl          *wineD3DDevice;
1154
1155     /* IWineD3DVertexShaderImpl */
1156     CONST DWORD                 *function;
1157     UINT                         functionLength;
1158
1159     DWORD usage;
1160     DWORD version;
1161
1162     /* vertex declaration array mapping */
1163     BOOL                        namedArrays;    /* don't map use named functions */
1164     BOOL                        declaredArrays; /* mapping requires */
1165     INT                         arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE];    /* lookup table for the maps */
1166     INT                         highestConstant;
1167     CHAR                        constantsUsedBitmap[256];
1168     /* 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 */
1169     /* run time datas...  */
1170     VSHADERDATA* data;
1171     GLuint                      prgId;
1172 #if 0 /* needs reworking */
1173     /* run time datas */
1174     VSHADERINPUTDATA input;
1175     VSHADEROUTPUTDATA output;
1176 #endif
1177 } IWineD3DVertexShaderImpl;
1178 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1179
1180 /*****************************************************************************
1181  * IDirect3DPixelShader implementation structure
1182  */
1183 typedef struct IWineD3DPixelShaderImpl {
1184     /* IUnknown parts */
1185     const IWineD3DPixelShaderVtbl *lpVtbl;
1186     LONG                        ref;     /* Note: Ref counting not required */
1187
1188     IUnknown                   *parent;
1189     IWineD3DDeviceImpl         *wineD3DDevice;
1190
1191     /* IWineD3DPixelShaderImpl */
1192     CONST DWORD                *function;
1193     UINT                        functionLength;
1194     DWORD                       version;
1195     CHAR                        constants[WINED3D_PSHADER_MAX_CONSTANTS];
1196
1197     /* run time data */
1198     PSHADERDATA                *data;
1199     GLuint                      prgId;
1200
1201 #if 0 /* needs reworking */
1202     PSHADERINPUTDATA input;
1203     PSHADEROUTPUTDATA output;
1204 #endif
1205 } IWineD3DPixelShaderImpl;
1206
1207 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1208 #endif