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