wined3d: Define D3D usage flags in wined3d_types.h.
[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     BOOL                    viewport_changed;  /* Was the viewport changed since the last draw?   */
498     GLenum                  tracking_parm;     /* Which source is tracking current colour         */
499     LONG                    tracking_color;    /* used iff GL_COLOR_MATERIAL was enabled          */
500 #define                         DISABLED_TRACKING  0  /* Disabled                                 */
501 #define                         IS_TRACKING        1  /* tracking_parm is tracking diffuse color  */
502 #define                         NEEDS_TRACKING     2  /* Tracking needs to be enabled when needed */
503 #define                         NEEDS_DISABLE      3  /* Tracking needs to be disabled when needed*/
504     UINT                    srcBlend;
505     UINT                    dstBlend;
506     UINT                    alphafunc;
507     UINT                    stencilfunc;
508     BOOL                    texture_shader_active;  /* TODO: Confirm use is correct */
509
510     /* State block related */
511     BOOL                    isRecordingState;
512     IWineD3DStateBlockImpl *stateBlock;
513     IWineD3DStateBlockImpl *updateStateBlock;
514
515     /* Internal use fields  */
516     D3DDEVICE_CREATION_PARAMETERS   createParms;
517     UINT                            adapterNo;
518     D3DDEVTYPE                      devType;
519
520     SwapChainList          *swapchains;
521
522     ResourceList           *resources; /* a linked list to track resources created by the device */
523
524     /* Render Target Support */
525     IWineD3DSurface        *depthStencilBuffer;
526
527     IWineD3DSurface        *renderTarget;
528     IWineD3DSurface        *stencilBufferTarget;
529
530     /* palettes texture management */
531     PALETTEENTRY            palettes[MAX_PALETTES][256];
532     UINT                    currentPalette;
533
534     /* For rendering to a texture using glCopyTexImage */
535     BOOL                    renderUpsideDown;
536
537     /* Cursor management */
538     BOOL                    bCursorVisible;
539     UINT                    xHotSpot;
540     UINT                    yHotSpot;
541     UINT                    xScreenSpace;
542     UINT                    yScreenSpace;
543
544     /* Textures for when no other textures are mapped */
545     UINT                          dummyTextureName[MAX_TEXTURES];
546
547     /* Debug stream management */
548     BOOL                     debug;
549
550     /* Device state management */
551     HRESULT                 state;
552
553     /* Screen buffer resources */
554     glContext contextCache[CONTEXT_CACHE];
555
556     /* A flag to check if endscene has been called before changing the render tartet */
557     BOOL sceneEnded;
558
559     /* process vertex shaders using software or hardware */
560     BOOL softwareVertexProcessing;
561     
562 } IWineD3DDeviceImpl;
563
564 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
565
566 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
567  * anybody uses it for much so a good implementation is optional. */
568 typedef struct PrivateData
569 {
570     struct PrivateData* next;
571
572     GUID tag;
573     DWORD flags; /* DDSPD_* */
574     DWORD uniqueness_value;
575
576     union
577     {
578         LPVOID data;
579         LPUNKNOWN object;
580     } ptr;
581
582     DWORD size;
583 } PrivateData;
584
585 /*****************************************************************************
586  * IWineD3DResource implementation structure
587  */
588 typedef struct IWineD3DResourceClass
589 {
590     /* IUnknown fields */
591     LONG                    ref;     /* Note: Ref counting not required */
592
593     /* WineD3DResource Information */
594     IUnknown               *parent;
595     D3DRESOURCETYPE         resourceType;
596     IWineD3DDeviceImpl     *wineD3DDevice;
597     D3DPOOL                 pool;
598     UINT                    size;
599     DWORD                   usage;
600     WINED3DFORMAT           format;
601     BYTE                   *allocatedMemory;
602     PrivateData            *privateData;
603
604 } IWineD3DResourceClass;
605
606 typedef struct IWineD3DResourceImpl
607 {
608     /* IUnknown & WineD3DResource Information     */
609     const IWineD3DResourceVtbl *lpVtbl;
610     IWineD3DResourceClass   resource;
611 } IWineD3DResourceImpl;
612
613
614 /*****************************************************************************
615  * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
616  */
617 typedef struct IWineD3DVertexBufferImpl
618 {
619     /* IUnknown & WineD3DResource Information     */
620     const IWineD3DVertexBufferVtbl *lpVtbl;
621     IWineD3DResourceClass     resource;
622
623     /* WineD3DVertexBuffer specifics */
624     DWORD                     fvf;
625
626 } IWineD3DVertexBufferImpl;
627
628 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
629
630
631 /*****************************************************************************
632  * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
633  */
634 typedef struct IWineD3DIndexBufferImpl
635 {
636     /* IUnknown & WineD3DResource Information     */
637     const IWineD3DIndexBufferVtbl *lpVtbl;
638     IWineD3DResourceClass     resource;
639
640     /* WineD3DVertexBuffer specifics */
641 } IWineD3DIndexBufferImpl;
642
643 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
644
645 /*****************************************************************************
646  * IWineD3DBaseTexture D3D- > openGL state map lookups
647  */
648 #define WINED3DFUNC_NOTSUPPORTED  -2
649 #define WINED3DFUNC_UNIMPLEMENTED -1
650
651 typedef enum winetexturestates {
652     WINED3DTEXSTA_ADDRESSU       = 0,
653     WINED3DTEXSTA_ADDRESSV       = 1,
654     WINED3DTEXSTA_ADDRESSW       = 2,
655     WINED3DTEXSTA_BORDERCOLOR    = 3,
656     WINED3DTEXSTA_MAGFILTER      = 4,
657     WINED3DTEXSTA_MINFILTER      = 5,
658     WINED3DTEXSTA_MIPFILTER      = 6,
659     WINED3DTEXSTA_MAXMIPLEVEL    = 7,
660     WINED3DTEXSTA_MAXANISOTROPY  = 8,
661     WINED3DTEXSTA_SRGBTEXTURE    = 9,
662     WINED3DTEXSTA_ELEMENTINDEX   = 10,
663     WINED3DTEXSTA_DMAPOFFSET     = 11,
664     WINED3DTEXSTA_TSSADDRESSW    = 12,
665     MAX_WINETEXTURESTATES        = 13,
666 } winetexturestates;
667
668 typedef struct Wined3dTextureStateMap {
669     CONST int state;
670     int function;
671 } Wined3dTextureStateMap;
672
673 /*****************************************************************************
674  * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
675  */
676 typedef struct IWineD3DBaseTextureClass
677 {
678     UINT                    levels;
679     BOOL                    dirty;
680     D3DFORMAT               format;
681     DWORD                   usage;
682     UINT                    textureName;
683     UINT                    LOD;
684     D3DTEXTUREFILTERTYPE    filterType;
685     DWORD                   states[MAX_WINETEXTURESTATES];
686
687 } IWineD3DBaseTextureClass;
688
689 typedef struct IWineD3DBaseTextureImpl
690 {
691     /* IUnknown & WineD3DResource Information     */
692     const IWineD3DBaseTextureVtbl *lpVtbl;
693     IWineD3DResourceClass     resource;
694     IWineD3DBaseTextureClass  baseTexture;
695
696 } IWineD3DBaseTextureImpl;
697
698 /*****************************************************************************
699  * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
700  */
701 typedef struct IWineD3DTextureImpl
702 {
703     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
704     const IWineD3DTextureVtbl *lpVtbl;
705     IWineD3DResourceClass     resource;
706     IWineD3DBaseTextureClass  baseTexture;
707
708     /* IWineD3DTexture */
709     IWineD3DSurface          *surfaces[MAX_LEVELS];
710     
711     UINT                      width;
712     UINT                      height;
713     float                     pow2scalingFactorX;
714     float                     pow2scalingFactorY;
715
716 } IWineD3DTextureImpl;
717
718 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
719
720 /*****************************************************************************
721  * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
722  */
723 typedef struct IWineD3DCubeTextureImpl
724 {
725     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
726     const IWineD3DCubeTextureVtbl *lpVtbl;
727     IWineD3DResourceClass     resource;
728     IWineD3DBaseTextureClass  baseTexture;
729
730     /* IWineD3DCubeTexture */
731     IWineD3DSurface          *surfaces[6][MAX_LEVELS];
732
733     UINT                      edgeLength;
734     float                     pow2scalingFactor;
735
736 } IWineD3DCubeTextureImpl;
737
738 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
739
740 /*****************************************************************************
741  * IWineD3DVolume implementation structure (extends IUnknown)
742  */
743 typedef struct IWineD3DVolumeImpl
744 {
745     /* IUnknown & WineD3DResource fields */
746     const IWineD3DVolumeVtbl  *lpVtbl;
747     IWineD3DResourceClass      resource;
748
749     /* WineD3DVolume Information */
750     D3DVOLUME_DESC          currentDesc;
751     IWineD3DBase            *container;
752     UINT                    bytesPerPixel;
753
754     BOOL                    lockable;
755     BOOL                    locked;
756     D3DBOX                  lockedBox;
757     D3DBOX                  dirtyBox;
758     BOOL                    dirty;
759
760
761 } IWineD3DVolumeImpl;
762
763 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
764
765 /*****************************************************************************
766  * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
767  */
768 typedef struct IWineD3DVolumeTextureImpl
769 {
770     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
771     const IWineD3DVolumeTextureVtbl *lpVtbl;
772     IWineD3DResourceClass     resource;
773     IWineD3DBaseTextureClass  baseTexture;
774
775     /* IWineD3DVolumeTexture */
776     IWineD3DVolume           *volumes[MAX_LEVELS];
777
778     UINT                      width;
779     UINT                      height;
780     UINT                      depth;
781 } IWineD3DVolumeTextureImpl;
782
783 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
784
785 typedef struct _WINED3DSURFACET_DESC
786 {
787     D3DMULTISAMPLE_TYPE MultiSampleType;
788     DWORD               MultiSampleQuality;
789     UINT                Width;
790     UINT                Height;
791 } WINED3DSURFACET_DESC;
792
793 /*****************************************************************************
794  * IWineD3DSurface implementation structure
795  */
796 struct IWineD3DSurfaceImpl
797 {
798     /* IUnknown & IWineD3DResource Information     */
799     const IWineD3DSurfaceVtbl *lpVtbl;
800     IWineD3DResourceClass     resource;
801
802     /* IWineD3DSurface fields */
803     IWineD3DBase              *container;
804     WINED3DSURFACET_DESC      currentDesc;
805
806     UINT                      textureName;
807     UINT                      bytesPerPixel;
808
809     /* TODO: move this off into a management class(maybe!) */
810     BOOL                      nonpow2;
811
812     UINT                      pow2Width;
813     UINT                      pow2Height;
814     UINT                      pow2Size;
815
816 #if 0
817     /* precalculated x and y scalings for texture coords */
818     float                     pow2scalingFactorX; /* =  (Width  / pow2Width ) */
819     float                     pow2scalingFactorY; /* =  (Height / pow2Height) */
820 #endif
821
822     BOOL                      lockable;
823     BOOL                      discard;
824     BOOL                      locked;
825     BOOL                      activeLock;
826     
827     RECT                      lockedRect;
828     RECT                      dirtyRect;
829     BOOL                      Dirty;
830     
831     BOOL                      inTexture;
832     BOOL                      inPBuffer;
833
834     glDescriptor              glDescription;
835 };
836
837 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
838
839 /*****************************************************************************
840  * IWineD3DVertexDeclaration implementation structure
841  */
842 typedef struct IWineD3DVertexDeclarationImpl {
843  /* IUnknown  Information     */
844   const IWineD3DVertexDeclarationVtbl *lpVtbl;
845   LONG                    ref;     /* Note: Ref counting not required */
846
847   IUnknown               *parent;
848   /** precomputed fvf if simple declaration */
849   IWineD3DDeviceImpl     *wineD3DDevice;
850   DWORD   fvf[MAX_STREAMS];
851   DWORD   allFVF;
852
853   /** dx8 compatible Declaration fields */
854   DWORD*  pDeclaration8;
855   DWORD   declaration8Length;
856
857   /** dx9+ */
858   D3DVERTEXELEMENT9 *pDeclaration9;
859   UINT               declaration9NumElements;
860
861   WINED3DVERTEXELEMENT  *pDeclarationWine;
862   UINT                   declarationWNumElements;
863   
864   float                 *constants;
865   
866 } IWineD3DVertexDeclarationImpl;
867
868 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
869
870 /*****************************************************************************
871  * IWineD3DStateBlock implementation structure
872  */
873
874 /* Internal state Block for Begin/End/Capture/Create/Apply info  */
875 /*   Note: Very long winded but gl Lists are not flexible enough */
876 /*   to resolve everything we need, so doing it manually for now */
877 typedef struct SAVEDSTATES {
878         BOOL                      indices;
879         BOOL                      material;
880         BOOL                      fvf;
881         BOOL                      streamSource[MAX_STREAMS];
882         BOOL                      streamFreq[MAX_STREAMS];
883         BOOL                      textures[MAX_TEXTURES];
884         BOOL                      transform[HIGHEST_TRANSFORMSTATE + 1];
885         BOOL                      viewport;
886         BOOL                      renderState[WINEHIGHEST_RENDER_STATE + 1];
887         BOOL                      textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
888         BOOL                      samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
889         BOOL                      clipplane[MAX_CLIPPLANES];
890         BOOL                      vertexDecl;
891         BOOL                      pixelShader;
892         BOOL                      pixelShaderConstants[MAX_PSHADER_CONSTANTS];
893         BOOL                      vertexShader;
894         BOOL                      vertexShaderConstants[MAX_VSHADER_CONSTANTS];
895 } SAVEDSTATES;
896
897 typedef enum {
898     WINESHADERCNST_NONE     = 0,
899     WINESHADERCNST_FLOAT    = 1,
900     WINESHADERCNST_INTEGER  = 2,
901     WINESHADERCNST_BOOL     = 3
902 } WINESHADERCNST;
903
904 struct IWineD3DStateBlockImpl
905 {
906     /* IUnknown fields */
907     const IWineD3DStateBlockVtbl *lpVtbl;
908     LONG                      ref;     /* Note: Ref counting not required */
909
910     /* IWineD3DStateBlock information */
911     IUnknown                 *parent;
912     IWineD3DDeviceImpl       *wineD3DDevice;
913     WINED3DSTATEBLOCKTYPE     blockType;
914
915     /* Array indicating whether things have been set or changed */
916     SAVEDSTATES               changed;
917     SAVEDSTATES               set;
918
919     /* Drawing - Vertex Shader or FVF related */
920     DWORD                     fvf;
921     /* Vertex Shader Declaration */
922     IWineD3DVertexDeclaration *vertexDecl;
923
924     IWineD3DVertexShader      *vertexShader;
925
926     /* Vertex Shader Constants */
927     BOOL                       vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
928     INT                        vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
929     float                      vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
930     WINESHADERCNST             vertexShaderConstantT[MAX_VSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
931
932     /* Stream Source */
933     BOOL                      streamIsUP;
934     UINT                      streamStride[MAX_STREAMS];
935     UINT                      streamOffset[MAX_STREAMS];
936     IWineD3DVertexBuffer     *streamSource[MAX_STREAMS];
937     UINT                      streamFreq[MAX_STREAMS];
938     UINT                      streamFlags[MAX_STREAMS];     /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA  */
939
940     /* Indices */
941     IWineD3DIndexBuffer*      pIndexData;
942     UINT                      baseVertexIndex; /* Note: only used for d3d8 */
943
944     /* Transform */
945     D3DMATRIX                 transforms[HIGHEST_TRANSFORMSTATE + 1];
946
947     /* Lights */
948     PLIGHTINFOEL             *lights; /* NOTE: active GL lights must be front of the chain */
949
950     /* Clipping */
951     double                    clipplane[MAX_CLIPPLANES][4];
952     WINED3DCLIPSTATUS         clip_status;
953
954     /* ViewPort */
955     WINED3DVIEWPORT           viewport;
956
957     /* Material */
958     WINED3DMATERIAL           material;
959
960     /* Pixel Shader */
961     IWineD3DPixelShader      *pixelShader;
962
963     /* Pixel Shader Constants */
964     BOOL                       pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
965     INT                        pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
966     float                      pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
967     WINESHADERCNST             pixelShaderConstantT[MAX_PSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
968
969     /* Indexed Vertex Blending */
970     D3DVERTEXBLENDFLAGS       vertex_blend;
971     FLOAT                     tween_factor;
972
973     /* RenderState */
974     DWORD                     renderState[WINEHIGHEST_RENDER_STATE + 1];
975
976     /* Texture */
977     IWineD3DBaseTexture      *textures[MAX_TEXTURES];
978     int                       textureDimensions[MAX_SAMPLERS];
979
980     /* Texture State Stage */
981     DWORD                     textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
982     /* Sampler States */
983     DWORD                     samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
984
985 };
986
987 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
988
989 /*****************************************************************************
990  * IWineD3DQueryImpl implementation structure (extends IUnknown)
991  */
992 typedef struct IWineD3DQueryImpl
993 {
994     const IWineD3DQueryVtbl  *lpVtbl;
995     LONG                      ref;     /* Note: Ref counting not required */
996     
997     IUnknown                 *parent;
998     /*TODO: replace with iface usage */
999 #if 0
1000     IWineD3DDevice         *wineD3DDevice;
1001 #else
1002     IWineD3DDeviceImpl       *wineD3DDevice;
1003 #endif
1004     /* IWineD3DQuery fields */
1005
1006     D3DQUERYTYPE              type;
1007     /* TODO: Think about using a IUnknown instead of a void* */
1008     void                     *extendedData;
1009     
1010   
1011 } IWineD3DQueryImpl;
1012
1013 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1014
1015 /* Datastructures for IWineD3DQueryImpl.extendedData */
1016 typedef struct  WineQueryOcclusionData {
1017        unsigned int queryId;
1018 } WineQueryOcclusionData;
1019
1020
1021 /*****************************************************************************
1022  * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1023  */
1024
1025 typedef struct IWineD3DSwapChainImpl
1026 {
1027     /*IUnknown part*/
1028     IWineD3DSwapChainVtbl    *lpVtbl;
1029     LONG                      ref;     /* Note: Ref counting not required */
1030
1031     IUnknown                 *parent;
1032     IWineD3DDeviceImpl       *wineD3DDevice;
1033
1034     /* IWineD3DSwapChain fields */
1035     IWineD3DSurface          *backBuffer;
1036     IWineD3DSurface          *frontBuffer;
1037     BOOL                      wantsDepthStencilBuffer;
1038     D3DPRESENT_PARAMETERS     presentParms;
1039
1040     /* TODO: move everything up to drawable off into a context manager
1041       and store the 'data' in the contextManagerData interface.
1042     IUnknown                  *contextManagerData;
1043     */
1044
1045     HWND                    win_handle;
1046     Window                  win;
1047     Display                *display;
1048
1049     GLXContext              glCtx;
1050     XVisualInfo            *visInfo;
1051     GLXContext              render_ctx;
1052     /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1053     Drawable                drawable;
1054 } IWineD3DSwapChainImpl;
1055
1056 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1057
1058 /*****************************************************************************
1059  * Utility function prototypes 
1060  */
1061
1062 /* Trace routines */
1063 const char* debug_d3dformat(WINED3DFORMAT fmt);
1064 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1065 const char* debug_d3dresourcetype(D3DRESOURCETYPE res);
1066 const char* debug_d3dusage(DWORD usage);
1067 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1068 const char* debug_d3drenderstate(DWORD state);
1069 const char* debug_d3dtexturestate(DWORD state);
1070 const char* debug_d3dpool(D3DPOOL pool);
1071
1072 /* Routines for GL <-> D3D values */
1073 GLenum StencilOp(DWORD op);
1074 void   set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1075 void   set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1076 void   GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
1077
1078 SHORT  D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1079 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1080 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
1081 GLint  D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1082
1083 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1084
1085
1086 /*****************************************************************************
1087  * To enable calling of inherited functions, requires prototypes 
1088  *
1089  * Note: Only require classes which are subclassed, ie resource, basetexture, 
1090  */
1091     /*** IUnknown methods ***/
1092     extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1093     extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1094     extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1095     /*** IWineD3DResource methods ***/
1096     extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1097     extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1098     extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1099     extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1100     extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID  refguid);
1101     extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD  PriorityNew);
1102     extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1103     extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1104     extern D3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1105     /*** class static members ***/
1106     void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1107
1108     /*** IUnknown methods ***/
1109     extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1110     extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1111     extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1112     /*** IWineD3DResource methods ***/
1113     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1114     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1115     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1116     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1117     extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid);
1118     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD  PriorityNew);
1119     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1120     extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1121     extern D3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1122     /*** IWineD3DBaseTexture methods ***/
1123     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1124     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1125     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1126     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, D3DTEXTUREFILTERTYPE FilterType);
1127     extern D3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1128     extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1129     extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1130     extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1131
1132     extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset);
1133     extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1134     extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1135     extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1136     extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1137     /*** class static members ***/
1138     void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1139
1140 /* An enum for the type of constants that are used... addressing causes
1141  * problems with being able to work out what's used and what's not.. so
1142  * maybe we'll have to rely on the server vertex shader const functions?
1143  */
1144 enum vsConstantsEnum {
1145     VS_CONSTANT_NOT_USED = 0,
1146     VS_CONSTANT_CONSTANT,
1147     VS_CONSTANT_INTEGER,
1148     VS_CONSTANT_BOOLEAN,
1149     VS_CONSTANT_FLOAT
1150 };
1151
1152 /*****************************************************************************
1153  * IDirect3DVertexShader implementation structure
1154  */
1155 typedef struct IWineD3DVertexShaderImpl {
1156     /* IUnknown parts*/   
1157     const IWineD3DVertexShaderVtbl *lpVtbl;
1158     LONG                        ref;     /* Note: Ref counting not required */
1159
1160     IUnknown                    *parent;
1161     IWineD3DDeviceImpl          *wineD3DDevice;
1162
1163     /* IWineD3DVertexShaderImpl */
1164     CONST DWORD                 *function;
1165     UINT                         functionLength;
1166
1167     DWORD usage;
1168     DWORD version;
1169
1170     /* vertex declaration array mapping */
1171     BOOL                        namedArrays;    /* don't map use named functions */
1172     BOOL                        declaredArrays; /* mapping requires */
1173     INT                         arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE];    /* lookup table for the maps */
1174     INT                         highestConstant;
1175     CHAR                        constantsUsedBitmap[256];
1176     /* 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 */
1177     /* run time datas...  */
1178     VSHADERDATA                *data;
1179     GLuint                      prgId;
1180     IWineD3DVertexDeclaration  *vertexDeclaration;
1181 #if 0 /* needs reworking */
1182     /* run time datas */
1183     VSHADERINPUTDATA input;
1184     VSHADEROUTPUTDATA output;
1185 #endif
1186 } IWineD3DVertexShaderImpl;
1187 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1188
1189 /*****************************************************************************
1190  * IDirect3DPixelShader implementation structure
1191  */
1192 typedef struct IWineD3DPixelShaderImpl {
1193     /* IUnknown parts */
1194     const IWineD3DPixelShaderVtbl *lpVtbl;
1195     LONG                        ref;     /* Note: Ref counting not required */
1196
1197     IUnknown                   *parent;
1198     IWineD3DDeviceImpl         *wineD3DDevice;
1199
1200     /* IWineD3DPixelShaderImpl */
1201     CONST DWORD                *function;
1202     UINT                        functionLength;
1203     DWORD                       version;
1204     CHAR                        constants[WINED3D_PSHADER_MAX_CONSTANTS];
1205
1206     /* run time data */
1207     PSHADERDATA                *data;
1208     GLuint                      prgId;
1209
1210 #if 0 /* needs reworking */
1211     PSHADERINPUTDATA input;
1212     PSHADEROUTPUTDATA output;
1213 #endif
1214 } IWineD3DPixelShaderImpl;
1215
1216 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1217 #endif