wined3d: Added support for ARB_POINT_PARAMETERS.
[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
860   WINED3DVERTEXELEMENT  *pDeclarationWine;
861   UINT                   declarationWNumElements;
862   
863   float                 *constants;
864   
865 } IWineD3DVertexDeclarationImpl;
866
867 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
868
869 /*****************************************************************************
870  * IWineD3DStateBlock implementation structure
871  */
872
873 /* Internal state Block for Begin/End/Capture/Create/Apply info  */
874 /*   Note: Very long winded but gl Lists are not flexible enough */
875 /*   to resolve everything we need, so doing it manually for now */
876 typedef struct SAVEDSTATES {
877         BOOL                      indices;
878         BOOL                      material;
879         BOOL                      fvf;
880         BOOL                      streamSource[MAX_STREAMS];
881         BOOL                      streamFreq[MAX_STREAMS];
882         BOOL                      textures[MAX_TEXTURES];
883         BOOL                      transform[HIGHEST_TRANSFORMSTATE + 1];
884         BOOL                      viewport;
885         BOOL                      renderState[WINEHIGHEST_RENDER_STATE + 1];
886         BOOL                      textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
887         BOOL                      samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
888         BOOL                      clipplane[MAX_CLIPPLANES];
889         BOOL                      vertexDecl;
890         BOOL                      pixelShader;
891         BOOL                      pixelShaderConstants[MAX_PSHADER_CONSTANTS];
892         BOOL                      vertexShader;
893         BOOL                      vertexShaderConstants[MAX_VSHADER_CONSTANTS];
894 } SAVEDSTATES;
895
896 typedef enum {
897     WINESHADERCNST_NONE     = 0,
898     WINESHADERCNST_FLOAT    = 1,
899     WINESHADERCNST_INTEGER  = 2,
900     WINESHADERCNST_BOOL     = 3
901 } WINESHADERCNST;
902
903 struct IWineD3DStateBlockImpl
904 {
905     /* IUnknown fields */
906     const IWineD3DStateBlockVtbl *lpVtbl;
907     LONG                      ref;     /* Note: Ref counting not required */
908
909     /* IWineD3DStateBlock information */
910     IUnknown                 *parent;
911     IWineD3DDeviceImpl       *wineD3DDevice;
912     WINED3DSTATEBLOCKTYPE     blockType;
913
914     /* Array indicating whether things have been set or changed */
915     SAVEDSTATES               changed;
916     SAVEDSTATES               set;
917
918     /* Drawing - Vertex Shader or FVF related */
919     DWORD                     fvf;
920     /* Vertex Shader Declaration */
921     IWineD3DVertexDeclaration *vertexDecl;
922
923     IWineD3DVertexShader      *vertexShader;
924
925     /* Vertex Shader Constants */
926     BOOL                       vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
927     INT                        vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
928     float                      vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
929     WINESHADERCNST             vertexShaderConstantT[MAX_VSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
930
931     /* Stream Source */
932     BOOL                      streamIsUP;
933     UINT                      streamStride[MAX_STREAMS];
934     UINT                      streamOffset[MAX_STREAMS];
935     IWineD3DVertexBuffer     *streamSource[MAX_STREAMS];
936     UINT                      streamFreq[MAX_STREAMS];
937     UINT                      streamFlags[MAX_STREAMS];     /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA  */
938
939     /* Indices */
940     IWineD3DIndexBuffer*      pIndexData;
941     UINT                      baseVertexIndex; /* Note: only used for d3d8 */
942
943     /* Transform */
944     D3DMATRIX                 transforms[HIGHEST_TRANSFORMSTATE + 1];
945
946     /* Lights */
947     PLIGHTINFOEL             *lights; /* NOTE: active GL lights must be front of the chain */
948
949     /* Clipping */
950     double                    clipplane[MAX_CLIPPLANES][4];
951     WINED3DCLIPSTATUS         clip_status;
952
953     /* ViewPort */
954     WINED3DVIEWPORT           viewport;
955
956     /* Material */
957     WINED3DMATERIAL           material;
958
959     /* Pixel Shader */
960     IWineD3DPixelShader      *pixelShader;
961
962     /* Pixel Shader Constants */
963     BOOL                       pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
964     INT                        pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
965     float                      pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
966     WINESHADERCNST             pixelShaderConstantT[MAX_PSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
967
968     /* Indexed Vertex Blending */
969     D3DVERTEXBLENDFLAGS       vertex_blend;
970     FLOAT                     tween_factor;
971
972     /* RenderState */
973     DWORD                     renderState[WINEHIGHEST_RENDER_STATE + 1];
974
975     /* Texture */
976     IWineD3DBaseTexture      *textures[MAX_TEXTURES];
977     int                       textureDimensions[MAX_SAMPLERS];
978
979     /* Texture State Stage */
980     DWORD                     textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
981     /* Sampler States */
982     DWORD                     samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
983
984 };
985
986 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
987
988 /*****************************************************************************
989  * IWineD3DQueryImpl implementation structure (extends IUnknown)
990  */
991 typedef struct IWineD3DQueryImpl
992 {
993     const IWineD3DQueryVtbl  *lpVtbl;
994     LONG                      ref;     /* Note: Ref counting not required */
995     
996     IUnknown                 *parent;
997     /*TODO: replace with iface usage */
998 #if 0
999     IWineD3DDevice         *wineD3DDevice;
1000 #else
1001     IWineD3DDeviceImpl       *wineD3DDevice;
1002 #endif
1003     /* IWineD3DQuery fields */
1004
1005     D3DQUERYTYPE              type;
1006     /* TODO: Think about using a IUnknown instead of a void* */
1007     void                     *extendedData;
1008     
1009   
1010 } IWineD3DQueryImpl;
1011
1012 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1013
1014 /* Datastructures for IWineD3DQueryImpl.extendedData */
1015 typedef struct  WineQueryOcclusionData {
1016        unsigned int queryId;
1017 } WineQueryOcclusionData;
1018
1019
1020 /*****************************************************************************
1021  * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1022  */
1023
1024 typedef struct IWineD3DSwapChainImpl
1025 {
1026     /*IUnknown part*/
1027     IWineD3DSwapChainVtbl    *lpVtbl;
1028     LONG                      ref;     /* Note: Ref counting not required */
1029
1030     IUnknown                 *parent;
1031     IWineD3DDeviceImpl       *wineD3DDevice;
1032
1033     /* IWineD3DSwapChain fields */
1034     IWineD3DSurface          *backBuffer;
1035     IWineD3DSurface          *frontBuffer;
1036     BOOL                      wantsDepthStencilBuffer;
1037     D3DPRESENT_PARAMETERS     presentParms;
1038
1039     /* TODO: move everything up to drawable off into a context manager
1040       and store the 'data' in the contextManagerData interface.
1041     IUnknown                  *contextManagerData;
1042     */
1043
1044     HWND                    win_handle;
1045     Window                  win;
1046     Display                *display;
1047
1048     GLXContext              glCtx;
1049     XVisualInfo            *visInfo;
1050     GLXContext              render_ctx;
1051     /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1052     Drawable                drawable;
1053 } IWineD3DSwapChainImpl;
1054
1055 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1056
1057 /*****************************************************************************
1058  * Utility function prototypes 
1059  */
1060
1061 /* Trace routines */
1062 const char* debug_d3dformat(WINED3DFORMAT fmt);
1063 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1064 const char* debug_d3dresourcetype(D3DRESOURCETYPE res);
1065 const char* debug_d3dusage(DWORD usage);
1066 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1067 const char* debug_d3drenderstate(DWORD state);
1068 const char* debug_d3dtexturestate(DWORD state);
1069 const char* debug_d3dpool(D3DPOOL pool);
1070
1071 /* Routines for GL <-> D3D values */
1072 GLenum StencilOp(DWORD op);
1073 void   set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1074 void   set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1075 void   GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
1076
1077 SHORT  D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1078 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1079 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
1080 GLint  D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1081
1082 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1083
1084
1085 /*****************************************************************************
1086  * To enable calling of inherited functions, requires prototypes 
1087  *
1088  * Note: Only require classes which are subclassed, ie resource, basetexture, 
1089  */
1090     /*** IUnknown methods ***/
1091     extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1092     extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1093     extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1094     /*** IWineD3DResource methods ***/
1095     extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1096     extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1097     extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1098     extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1099     extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID  refguid);
1100     extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD  PriorityNew);
1101     extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1102     extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1103     extern D3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1104     /*** class static members ***/
1105     void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1106
1107     /*** IUnknown methods ***/
1108     extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1109     extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1110     extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1111     /*** IWineD3DResource methods ***/
1112     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1113     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1114     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1115     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1116     extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid);
1117     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD  PriorityNew);
1118     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1119     extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1120     extern D3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1121     /*** IWineD3DBaseTexture methods ***/
1122     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1123     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1124     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1125     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, D3DTEXTUREFILTERTYPE FilterType);
1126     extern D3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1127     extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1128     extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1129     extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1130
1131     extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset);
1132     extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1133     extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1134     extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1135     extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1136     /*** class static members ***/
1137     void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1138
1139 /* An enum for the type of constants that are used... addressing causes
1140  * problems with being able to work out what's used and what's not.. so
1141  * maybe we'll have to rely on the server vertex shader const functions?
1142  */
1143 enum vsConstantsEnum {
1144     VS_CONSTANT_NOT_USED = 0,
1145     VS_CONSTANT_CONSTANT,
1146     VS_CONSTANT_INTEGER,
1147     VS_CONSTANT_BOOLEAN,
1148     VS_CONSTANT_FLOAT
1149 };
1150
1151 /*****************************************************************************
1152  * IDirect3DVertexShader implementation structure
1153  */
1154 typedef struct IWineD3DVertexShaderImpl {
1155     /* IUnknown parts*/   
1156     const IWineD3DVertexShaderVtbl *lpVtbl;
1157     LONG                        ref;     /* Note: Ref counting not required */
1158
1159     IUnknown                    *parent;
1160     IWineD3DDeviceImpl          *wineD3DDevice;
1161
1162     /* IWineD3DVertexShaderImpl */
1163     CONST DWORD                 *function;
1164     UINT                         functionLength;
1165
1166     DWORD usage;
1167     DWORD version;
1168
1169     /* vertex declaration array mapping */
1170     BOOL                        namedArrays;    /* don't map use named functions */
1171     BOOL                        declaredArrays; /* mapping requires */
1172     INT                         arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE];    /* lookup table for the maps */
1173     INT                         highestConstant;
1174     CHAR                        constantsUsedBitmap[256];
1175     /* 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 */
1176     /* run time datas...  */
1177     VSHADERDATA                *data;
1178     GLuint                      prgId;
1179     IWineD3DVertexDeclaration  *vertexDeclaration;
1180 #if 0 /* needs reworking */
1181     /* run time datas */
1182     VSHADERINPUTDATA input;
1183     VSHADEROUTPUTDATA output;
1184 #endif
1185 } IWineD3DVertexShaderImpl;
1186 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1187
1188 /*****************************************************************************
1189  * IDirect3DPixelShader implementation structure
1190  */
1191 typedef struct IWineD3DPixelShaderImpl {
1192     /* IUnknown parts */
1193     const IWineD3DPixelShaderVtbl *lpVtbl;
1194     LONG                        ref;     /* Note: Ref counting not required */
1195
1196     IUnknown                   *parent;
1197     IWineD3DDeviceImpl         *wineD3DDevice;
1198
1199     /* IWineD3DPixelShaderImpl */
1200     CONST DWORD                *function;
1201     UINT                        functionLength;
1202     DWORD                       version;
1203     CHAR                        constants[WINED3D_PSHADER_MAX_CONSTANTS];
1204
1205     /* run time data */
1206     PSHADERDATA                *data;
1207     GLuint                      prgId;
1208
1209 #if 0 /* needs reworking */
1210     PSHADERINPUTDATA input;
1211     PSHADEROUTPUTDATA output;
1212 #endif
1213 } IWineD3DPixelShaderImpl;
1214
1215 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1216 #endif