comdlg32: Moved a FIXME out of the user-visible string.
[wine] / dlls / wined3d / wined3d_private.h
1 /*
2  * Direct3D wine internal private include file
3  *
4  * Copyright 2002-2003 The wine-d3d team
5  * Copyright 2002-2003 Raphael Junqueira
6  * Copyright 2004 Jason Edmeades
7  * Copyright 2005 Oliver Stieber
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #ifndef __WINE_WINED3D_PRIVATE_H
25 #define __WINE_WINED3D_PRIVATE_H
26
27 #include <stdarg.h>
28 #include <math.h>
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
31 #define COBJMACROS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winreg.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
39
40 #include "d3d9.h"
41 #include "d3d9types.h"
42 #include "wined3d_private_types.h"
43 #include "ddraw.h"
44 #include "wine/wined3d_interface.h"
45 #include "wine/wined3d_gl.h"
46 #include "wine/list.h"
47
48 /* Device caps */
49 #define MAX_PALETTES      256
50 #define MAX_STREAMS       16
51 #define MAX_TEXTURES      8
52 #define MAX_SAMPLERS      16
53 #define MAX_ACTIVE_LIGHTS 8
54 #define MAX_CLIPPLANES    WINED3DMAXUSERCLIPPLANES
55 #define MAX_LEVELS        256
56
57 #define MAX_CONST_I 16
58 #define MAX_CONST_B 16
59
60 /* Used for CreateStateBlock */
61 #define NUM_SAVEDPIXELSTATES_R     35
62 #define NUM_SAVEDPIXELSTATES_T     18
63 #define NUM_SAVEDPIXELSTATES_S     12
64 #define NUM_SAVEDVERTEXSTATES_R    31
65 #define NUM_SAVEDVERTEXSTATES_T    2
66 #define NUM_SAVEDVERTEXSTATES_S    1
67
68 extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
69 extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
70 extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
71 extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
72 extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
73 extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
74
75 typedef enum _WINELOOKUP {
76     WINELOOKUP_WARPPARAM = 0,
77     WINELOOKUP_MAGFILTER = 1,
78     MAX_LOOKUPS          = 2
79 } WINELOOKUP;
80
81 extern int minLookup[MAX_LOOKUPS];
82 extern int maxLookup[MAX_LOOKUPS];
83 extern DWORD *stateLookup[MAX_LOOKUPS];
84
85 extern DWORD minMipLookup[WINED3DTEXF_ANISOTROPIC + 1][WINED3DTEXF_LINEAR + 1];
86
87 typedef struct _WINED3DGLTYPE {
88     int         d3dType;
89     GLint       size;
90     GLenum      glType;
91     GLboolean   normalized;
92     int         typesize;
93 } WINED3DGLTYPE;
94
95 /* NOTE: Make sure these are in the correct numerical order. (see /include/wined3d_types.h) */
96 static WINED3DGLTYPE const glTypeLookup[WINED3DDECLTYPE_UNUSED] = {
97                                   {WINED3DDECLTYPE_FLOAT1,    1, GL_FLOAT           , GL_FALSE ,sizeof(float)},
98                                   {WINED3DDECLTYPE_FLOAT2,    2, GL_FLOAT           , GL_FALSE ,sizeof(float)},
99                                   {WINED3DDECLTYPE_FLOAT3,    3, GL_FLOAT           , GL_FALSE ,sizeof(float)},
100                                   {WINED3DDECLTYPE_FLOAT4,    4, GL_FLOAT           , GL_FALSE ,sizeof(float)},
101                                   {WINED3DDECLTYPE_D3DCOLOR,  4, GL_UNSIGNED_BYTE   , GL_TRUE  ,sizeof(BYTE)},
102                                   {WINED3DDECLTYPE_UBYTE4,    4, GL_UNSIGNED_BYTE   , GL_FALSE ,sizeof(BYTE)},
103                                   {WINED3DDECLTYPE_SHORT2,    2, GL_SHORT           , GL_FALSE ,sizeof(short int)},
104                                   {WINED3DDECLTYPE_SHORT4,    4, GL_SHORT           , GL_FALSE ,sizeof(short int)},
105                                   {WINED3DDECLTYPE_UBYTE4N,   4, GL_UNSIGNED_BYTE   , GL_FALSE ,sizeof(BYTE)},
106                                   {WINED3DDECLTYPE_SHORT2N,   2, GL_SHORT           , GL_FALSE ,sizeof(short int)},
107                                   {WINED3DDECLTYPE_SHORT4N,   4, GL_SHORT           , GL_FALSE ,sizeof(short int)},
108                                   {WINED3DDECLTYPE_USHORT2N,  2, GL_UNSIGNED_SHORT  , GL_FALSE ,sizeof(short int)},
109                                   {WINED3DDECLTYPE_USHORT4N,  4, GL_UNSIGNED_SHORT  , GL_FALSE ,sizeof(short int)},
110                                   {WINED3DDECLTYPE_UDEC3,     3, GL_UNSIGNED_SHORT  , GL_FALSE ,sizeof(short int)},
111                                   {WINED3DDECLTYPE_DEC3N,     3, GL_SHORT           , GL_FALSE ,sizeof(short int)},
112                                   {WINED3DDECLTYPE_FLOAT16_2, 2, GL_FLOAT           , GL_FALSE ,sizeof(short int)},
113                                   {WINED3DDECLTYPE_FLOAT16_4, 4, GL_FLOAT           , GL_FALSE ,sizeof(short int)}};
114
115 #define WINED3D_ATR_TYPE(type)          glTypeLookup[type].d3dType
116 #define WINED3D_ATR_SIZE(type)          glTypeLookup[type].size
117 #define WINED3D_ATR_GLTYPE(type)        glTypeLookup[type].glType
118 #define WINED3D_ATR_NORMALIZED(type)    glTypeLookup[type].normalized
119 #define WINED3D_ATR_TYPESIZE(type)      glTypeLookup[type].typesize
120
121 /**
122  * Settings 
123  */
124 #define VS_NONE    0
125 #define VS_HW      1
126 #define VS_SW      2
127
128 #define PS_NONE    0
129 #define PS_HW      1
130
131 #define VBO_NONE   0
132 #define VBO_HW     1
133
134 #define NP2_NONE   0
135 #define NP2_REPACK 1
136 #define NP2_NATIVE 2
137
138 #define ORM_BACKBUFFER  0
139 #define ORM_PBUFFER     1
140 #define ORM_FBO         2
141
142 #define SHADER_SW   0
143 #define SHADER_ARB  1
144 #define SHADER_GLSL 2
145 #define SHADER_NONE 3
146
147 #define RTL_DISABLE   -1
148 #define RTL_AUTO       0
149 #define RTL_READDRAW   1
150 #define RTL_READTEX    2
151 #define RTL_TEXDRAW    3
152 #define RTL_TEXTEX     4
153
154 /* NOTE: When adding fields to this structure, make sure to update the default
155  * values in wined3d_main.c as well. */
156 typedef struct wined3d_settings_s {
157 /* vertex and pixel shader modes */
158   int vs_mode;
159   int ps_mode;
160   int vbo_mode;
161 /* Ideally, we don't want the user to have to request GLSL.  If the hardware supports GLSL,
162     we should use it.  However, until it's fully implemented, we'll leave it as a registry
163     setting for developers. */
164   BOOL glslRequested;
165 /* nonpower 2 function */
166   int nonpower2_mode;
167   int offscreen_rendering_mode;
168   int rendertargetlock_mode;
169 /* Memory tracking and object counting */
170   unsigned int emulated_textureram;
171 } wined3d_settings_t;
172
173 extern wined3d_settings_t wined3d_settings;
174
175 /* X11 locking */
176
177 extern void (*wine_tsx11_lock_ptr)(void);
178 extern void (*wine_tsx11_unlock_ptr)(void);
179
180 /* As GLX relies on X, this is needed */
181 extern int num_lock;
182
183 #if 0
184 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
185 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
186 #else
187 #define ENTER_GL() wine_tsx11_lock_ptr()
188 #define LEAVE_GL() wine_tsx11_unlock_ptr()
189 #endif
190
191 /*****************************************************************************
192  * Defines
193  */
194
195 /* GL related defines */
196 /* ------------------ */
197 #define GL_SUPPORT(ExtName)           (GLINFO_LOCATION.supported[ExtName] != 0)
198 #define GL_LIMITS(ExtName)            (GLINFO_LOCATION.max_##ExtName)
199 #define GL_EXTCALL(FuncName)          (GLINFO_LOCATION.FuncName)
200 #define GL_VEND(_VendName)            (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
201
202 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
203 #define D3DCOLOR_B_G(dw) (((dw) >>  8) & 0xFF)
204 #define D3DCOLOR_B_B(dw) (((dw) >>  0) & 0xFF)
205 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
206
207 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
208 #define D3DCOLOR_G(dw) (((float) (((dw) >>  8) & 0xFF)) / 255.0f)
209 #define D3DCOLOR_B(dw) (((float) (((dw) >>  0) & 0xFF)) / 255.0f)
210 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
211
212 #define D3DCOLORTOGLFLOAT4(dw, vec) \
213   (vec)[0] = D3DCOLOR_R(dw); \
214   (vec)[1] = D3DCOLOR_G(dw); \
215   (vec)[2] = D3DCOLOR_B(dw); \
216   (vec)[3] = D3DCOLOR_A(dw);
217
218 /* DirectX Device Limits */
219 /* --------------------- */
220 #define MAX_LEVELS  256  /* Maximum number of mipmap levels. Guessed at 256 */
221
222 #define MAX_STREAMS  16  /* Maximum possible streams - used for fixed size arrays
223                             See MaxStreams in MSDN under GetDeviceCaps */
224                          /* Maximum number of constants provided to the shaders */
225 #define HIGHEST_TRANSFORMSTATE 512 
226                          /* Highest value in WINED3DTRANSFORMSTATETYPE */
227 #define MAX_PALETTES      256
228
229 /* Checking of API calls */
230 /* --------------------- */
231 #define checkGLcall(A)                                          \
232 {                                                               \
233     GLint err = glGetError();                                   \
234     if (err == GL_NO_ERROR) {                                   \
235        TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__);    \
236                                                                 \
237     } else do {                                                 \
238        FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n",        \
239                 err, A, __FILE__, __LINE__);                    \
240        err = glGetError();                                      \
241     } while (err != GL_NO_ERROR);                               \
242
243
244 /* Trace routines / diagnostics */
245 /* ---------------------------- */
246
247 /* Dump out a matrix and copy it */
248 #define conv_mat(mat,gl_mat)                                                                \
249 do {                                                                                        \
250     TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
251     TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
252     TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
253     TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
254     memcpy(gl_mat, (mat), 16 * sizeof(float));                                              \
255 } while (0)
256
257 /* Macro to dump out the current state of the light chain */
258 #define DUMP_LIGHT_CHAIN()                    \
259 {                                             \
260   PLIGHTINFOEL *el = This->stateBlock->lights;\
261   while (el) {                                \
262     TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
263     el = el->next;                            \
264   }                                           \
265 }
266
267 /* Trace vector and strided data information */
268 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
269 #define TRACE_STRIDED(sd,name) TRACE( #name "=(data:%p, stride:%d, type:%d)\n", sd->u.s.name.lpData, sd->u.s.name.dwStride, sd->u.s.name.dwType);
270
271 /* Defines used for optimizations */
272
273 /*    Only reapply what is necessary */
274 #define REAPPLY_ALPHAOP  0x0001
275 #define REAPPLY_ALL      0xFFFF
276
277 /* Advance declaration of structures to satisfy compiler */
278 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
279 typedef struct IWineD3DSurfaceImpl    IWineD3DSurfaceImpl;
280 typedef struct IWineD3DPaletteImpl    IWineD3DPaletteImpl;
281
282 /* Tracking */
283
284 /* TODO: Move some of this to the device */
285 long globalChangeGlRam(long glram);
286
287 /* Memory and object tracking */
288
289 /*Structure for holding information on all direct3d objects
290 useful for making sure tracking is ok and when release is called on a device!
291 and probably quite handy for debugging and dumping states out
292 */
293 typedef struct WineD3DGlobalStatistics {
294     int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
295 } WineD3DGlobalStatistics;
296
297 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
298
299 /* Global variables */
300 extern const float identity[16];
301
302 /*****************************************************************************
303  * Compilable extra diagnostics
304  */
305
306 /* Trace information per-vertex: (extremely high amount of trace) */
307 #if 0 /* NOTE: Must be 0 in cvs */
308 # define VTRACE(A) TRACE A
309 #else 
310 # define VTRACE(A) 
311 #endif
312
313 /* Checking of per-vertex related GL calls */
314 /* --------------------- */
315 #define vcheckGLcall(A)                                         \
316 {                                                               \
317     GLint err = glGetError();                                   \
318     if (err == GL_NO_ERROR) {                                   \
319        VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
320                                                                 \
321     } else do {                                                 \
322        FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n",        \
323                 err, A, __FILE__, __LINE__);                    \
324        err = glGetError();                                      \
325     } while (err != GL_NO_ERROR);                               \
326 }
327
328 /* TODO: Confirm each of these works when wined3d move completed */
329 #if 0 /* NOTE: Must be 0 in cvs */
330   /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
331      of each frame, a check is made for the existence of C:\D3DTRACE, and if it exists d3d trace
332      is enabled, and if it doesn't exist it is disabled. */
333 # define FRAME_DEBUGGING
334   /*  Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
335       the file is deleted                                                                            */
336 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
337 #  define SINGLE_FRAME_DEBUGGING
338 # endif  
339   /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
340      It can only be enabled when FRAME_DEBUGGING is also enabled                               
341      The contents of the back buffer are written into /tmp/backbuffer_* after each primitive 
342      array is drawn.                                                                            */
343 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */                                                                                       
344 #  define SHOW_FRAME_MAKEUP 1
345 # endif  
346   /* The following, when enabled, lets you see the makeup of the all the textures used during each
347      of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
348      The contents of the textures assigned to each stage are written into 
349      /tmp/texture_*_<Stage>.ppm after each primitive array is drawn.                            */
350 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
351 #  define SHOW_TEXTURE_MAKEUP 0
352 # endif  
353 extern BOOL isOn;
354 extern BOOL isDumpingFrames;
355 extern LONG primCounter;
356 #endif
357
358 /*****************************************************************************
359  * Prototypes
360  */
361
362 /* Routine common to the draw primitive and draw indexed primitive routines */
363 void drawPrimitive(IWineD3DDevice *iface,
364                     int PrimitiveType,
365                     long NumPrimitives,
366                     /* for Indexed: */
367                     long  StartVertexIndex,
368                     UINT  numberOfVertices,
369                     long  StartIdx,
370                     short idxBytes,
371                     const void *idxData,
372                     int   minIndex,
373                     WineDirect3DVertexStridedData *DrawPrimStrideData);
374
375 void primitiveConvertToStridedData(IWineD3DDevice *iface, WineDirect3DVertexStridedData *strided, LONG BaseVertexIndex, BOOL *fixup);
376
377 void primitiveDeclarationConvertToStridedData(
378      IWineD3DDevice *iface,
379      BOOL useVertexShaderFunction,
380      WineDirect3DVertexStridedData *strided,
381      LONG BaseVertexIndex, 
382      BOOL *fixup);
383
384 void primitiveConvertFVFtoOffset(DWORD thisFVF,
385                                  DWORD stride,
386                                  BYTE *data,
387                                  WineDirect3DVertexStridedData *strided,
388                                  GLint streamVBO);
389
390 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
391
392 #define eps 1e-8
393
394 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
395     (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
396
397 /* Routine to fill gl caps for swapchains and IWineD3D */
398 BOOL IWineD3DImpl_FillGLCaps(IWineD3D *iface, Display* display);
399
400 /* Macros for doing basic GPU detection based on opengl capabilities */
401 #define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
402 #define WINE_D3D7_CAPABLE(gl_info) (gl_info->supported[ARB_TEXTURE_COMPRESSION] && gl_info->supported[ARB_TEXTURE_CUBE_MAP] && gl_info->supported[ARB_TEXTURE_ENV_DOT3])
403 #define WINE_D3D8_CAPABLE(gl_info) WINE_D3D7_CAPABLE(gl_info) && (gl_info->supported[ARB_MULTISAMPLE] && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
404 #define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER])
405
406 /*****************************************************************************
407  * Internal representation of a light
408  */
409 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
410 struct PLIGHTINFOEL {
411     WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
412     DWORD        OriginalIndex;
413     LONG         glIndex;
414     BOOL         lightEnabled;
415     BOOL         changed;
416     BOOL         enabledChanged;
417
418     /* Converted parms to speed up swapping lights */
419     float                         lightPosn[4];
420     float                         lightDirn[4];
421     float                         exponent;
422     float                         cutoff;
423
424     PLIGHTINFOEL *next;
425     PLIGHTINFOEL *prev;
426 };
427
428 /* The default light parameters */
429 extern const WINED3DLIGHT WINED3D_default_light;
430
431 /*****************************************************************************
432  * IWineD3D implementation structure
433  */
434 typedef struct IWineD3DImpl
435 {
436     /* IUnknown fields */
437     const IWineD3DVtbl     *lpVtbl;
438     LONG                    ref;     /* Note: Ref counting not required */
439
440     /* WineD3D Information */
441     IUnknown               *parent;
442     UINT                    dxVersion;
443
444     /* GL Information */
445     BOOL                    isGLInfoValid;
446     WineD3D_GL_Info         gl_info;
447 } IWineD3DImpl;
448
449 extern const IWineD3DVtbl IWineD3D_Vtbl;
450
451 /** Hacked out start of a context manager!! **/
452 typedef struct glContext {
453     int Width;
454     int Height;
455     int usedcount;
456     GLXContext context;
457
458     Drawable drawable;
459     IWineD3DSurface *pSurface;
460 #if 0 /* TODO: someway to represent the state of the context */
461     IWineD3DStateBlock *pStateBlock;
462 #endif
463 /* a few other things like format */
464 } glContext;
465
466 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
467 (since it will break quite a few things until contexts are managed properly!) */
468 extern BOOL pbuffer_support;
469 /* allocate one pbuffer per surface */
470 extern BOOL pbuffer_per_surface;
471
472 /* Maximum number of contexts/pbuffers to keep in cache,
473 set to 100 because ATI's drivers don't support deleting pBuffers properly
474 this needs to be migrated to a list and some option availalbe for controle the cache size.
475 */
476 #define CONTEXT_CACHE 100
477
478 typedef struct ResourceList {
479     IWineD3DResource         *resource;
480     struct ResourceList      *next;
481 } ResourceList;
482
483 /* A helper function that dumps a resource list */
484 void dumpResources(ResourceList *resources);
485
486 /*****************************************************************************
487  * IWineD3DDevice implementation structure
488  */
489 typedef struct IWineD3DDeviceImpl
490 {
491     /* IUnknown fields      */
492     const IWineD3DDeviceVtbl *lpVtbl;
493     LONG                    ref;     /* Note: Ref counting not required */
494
495     /* WineD3D Information  */
496     IUnknown               *parent;
497     IWineD3D               *wineD3D;
498
499     /* X and GL Information */
500     GLint                   maxConcurrentLights;
501
502     /* Selected capabilities */
503     int vs_selected_mode;
504     int ps_selected_mode;
505
506     /* Optimization */
507     BOOL                    modelview_valid;
508     BOOL                    proj_valid;
509     BOOL                    view_ident;        /* true iff view matrix is identity                */
510     BOOL                    last_was_rhw;      /* true iff last draw_primitive was in xyzrhw mode */
511     BOOL                    viewport_changed;  /* Was the viewport changed since the last draw?   */
512     GLenum                  tracking_parm;     /* Which source is tracking current colour         */
513     LONG                    tracking_color;    /* used iff GL_COLOR_MATERIAL was enabled          */
514 #define                         DISABLED_TRACKING  0  /* Disabled                                 */
515 #define                         IS_TRACKING        1  /* tracking_parm is tracking diffuse color  */
516 #define                         NEEDS_TRACKING     2  /* Tracking needs to be enabled when needed */
517 #define                         NEEDS_DISABLE      3  /* Tracking needs to be disabled when needed*/
518     UINT                    srcBlend;
519     UINT                    dstBlend;
520     UINT                    alphafunc;
521     BOOL                    texture_shader_active;  /* TODO: Confirm use is correct */
522     BOOL                    last_was_notclipped;
523     BOOL                    untransformed;
524
525     /* State block related */
526     BOOL                    isRecordingState;
527     IWineD3DStateBlockImpl *stateBlock;
528     IWineD3DStateBlockImpl *updateStateBlock;
529
530     /* Internal use fields  */
531     WINED3DDEVICE_CREATION_PARAMETERS createParms;
532     UINT                            adapterNo;
533     WINED3DDEVTYPE                  devType;
534
535     IWineD3DSwapChain     **swapchains;
536     uint                    NumberOfSwapChains;
537
538     ResourceList           *resources; /* a linked list to track resources created by the device */
539
540     /* Render Target Support */
541     IWineD3DSurface        *depthStencilBuffer;
542
543     IWineD3DSurface        *renderTarget;
544     IWineD3DSurface        *stencilBufferTarget;
545
546     /* palettes texture management */
547     PALETTEENTRY            palettes[MAX_PALETTES][256];
548     UINT                    currentPalette;
549
550     /* For rendering to a texture using glCopyTexImage */
551     BOOL                    render_offscreen;
552     WINED3D_DEPTHCOPYSTATE  depth_copy_state;
553     GLuint                  fbo;
554
555     /* Cursor management */
556     BOOL                    bCursorVisible;
557     UINT                    xHotSpot;
558     UINT                    yHotSpot;
559     UINT                    xScreenSpace;
560     UINT                    yScreenSpace;
561     UINT                    cursorWidth, cursorHeight;
562     GLuint                  cursorTexture;
563
564     /* Textures for when no other textures are mapped */
565     UINT                          dummyTextureName[MAX_TEXTURES];
566
567     /* Debug stream management */
568     BOOL                     debug;
569
570     /* Device state management */
571     HRESULT                 state;
572     BOOL                    d3d_initialized;
573
574     /* Screen buffer resources */
575     glContext contextCache[CONTEXT_CACHE];
576
577     /* A flag to check if endscene has been called before changing the render tartet */
578     BOOL sceneEnded;
579
580     /* process vertex shaders using software or hardware */
581     BOOL softwareVertexProcessing;
582
583     /* DirectDraw stuff */
584     HWND ddraw_window;
585     IWineD3DSurface *ddraw_primary;
586     DWORD ddraw_width, ddraw_height;
587     WINED3DFORMAT ddraw_format;
588     BOOL ddraw_fullscreen;
589
590     /* List of GLSL shader programs and their associated vertex & pixel shaders */
591     struct list glsl_shader_progs;
592
593
594     /* Final position fixup constant */
595     float                       posFixup[4];
596 } IWineD3DDeviceImpl;
597
598 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
599
600 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
601  * anybody uses it for much so a good implementation is optional. */
602 typedef struct PrivateData
603 {
604     struct PrivateData* next;
605
606     GUID tag;
607     DWORD flags; /* DDSPD_* */
608     DWORD uniqueness_value;
609
610     union
611     {
612         LPVOID data;
613         LPUNKNOWN object;
614     } ptr;
615
616     DWORD size;
617 } PrivateData;
618
619 void d3ddevice_set_ortho(IWineD3DDeviceImpl *This);
620
621 /*****************************************************************************
622  * IWineD3DResource implementation structure
623  */
624 typedef struct IWineD3DResourceClass
625 {
626     /* IUnknown fields */
627     LONG                    ref;     /* Note: Ref counting not required */
628
629     /* WineD3DResource Information */
630     IUnknown               *parent;
631     WINED3DRESOURCETYPE     resourceType;
632     IWineD3DDeviceImpl     *wineD3DDevice;
633     WINED3DPOOL             pool;
634     UINT                    size;
635     DWORD                   usage;
636     WINED3DFORMAT           format;
637     BYTE                   *allocatedMemory;
638     PrivateData            *privateData;
639
640 } IWineD3DResourceClass;
641
642 typedef struct IWineD3DResourceImpl
643 {
644     /* IUnknown & WineD3DResource Information     */
645     const IWineD3DResourceVtbl *lpVtbl;
646     IWineD3DResourceClass   resource;
647 } IWineD3DResourceImpl;
648
649
650 /*****************************************************************************
651  * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
652  */
653 typedef struct IWineD3DVertexBufferImpl
654 {
655     /* IUnknown & WineD3DResource Information     */
656     const IWineD3DVertexBufferVtbl *lpVtbl;
657     IWineD3DResourceClass     resource;
658
659     /* WineD3DVertexBuffer specifics */
660     DWORD                     fvf;
661
662     /* Vertex buffer object support */
663     GLuint                    vbo;
664     BYTE                      Flags;
665     UINT                      stream;
666
667     UINT                      dirtystart, dirtyend;
668     LONG                      lockcount;
669
670     LONG                      declChanges, draws;
671     /* Last description of the buffer */
672     WineDirect3DVertexStridedData strided;
673 } IWineD3DVertexBufferImpl;
674
675 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
676
677 #define VBFLAG_LOAD           0x01    /* Data is written from allocatedMemory to the VBO */
678 #define VBFLAG_OPTIMIZED      0x02    /* Optimize has been called for the VB */
679 #define VBFLAG_DIRTY          0x04    /* Buffer data has been modified */
680 #define VBFLAG_STREAM         0x08    /* The vertex buffer is in a stream */
681 #define VBFLAG_HASDESC        0x10    /* A vertex description has been found */
682 #define VBFLAG_VBOCREATEFAIL  0x20    /* An attempt to create a vbo has failed */
683
684 /*****************************************************************************
685  * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
686  */
687 typedef struct IWineD3DIndexBufferImpl
688 {
689     /* IUnknown & WineD3DResource Information     */
690     const IWineD3DIndexBufferVtbl *lpVtbl;
691     IWineD3DResourceClass     resource;
692
693     /* WineD3DVertexBuffer specifics */
694 } IWineD3DIndexBufferImpl;
695
696 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
697
698 /*****************************************************************************
699  * IWineD3DBaseTexture D3D- > openGL state map lookups
700  */
701 #define WINED3DFUNC_NOTSUPPORTED  -2
702 #define WINED3DFUNC_UNIMPLEMENTED -1
703
704 typedef enum winetexturestates {
705     WINED3DTEXSTA_ADDRESSU       = 0,
706     WINED3DTEXSTA_ADDRESSV       = 1,
707     WINED3DTEXSTA_ADDRESSW       = 2,
708     WINED3DTEXSTA_BORDERCOLOR    = 3,
709     WINED3DTEXSTA_MAGFILTER      = 4,
710     WINED3DTEXSTA_MINFILTER      = 5,
711     WINED3DTEXSTA_MIPFILTER      = 6,
712     WINED3DTEXSTA_MAXMIPLEVEL    = 7,
713     WINED3DTEXSTA_MAXANISOTROPY  = 8,
714     WINED3DTEXSTA_SRGBTEXTURE    = 9,
715     WINED3DTEXSTA_ELEMENTINDEX   = 10,
716     WINED3DTEXSTA_DMAPOFFSET     = 11,
717     WINED3DTEXSTA_TSSADDRESSW    = 12,
718     MAX_WINETEXTURESTATES        = 13,
719 } winetexturestates;
720
721 typedef struct Wined3dTextureStateMap {
722     CONST int state;
723     int function;
724 } Wined3dTextureStateMap;
725
726 /*****************************************************************************
727  * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
728  */
729 typedef struct IWineD3DBaseTextureClass
730 {
731     UINT                    levels;
732     BOOL                    dirty;
733     WINED3DFORMAT           format;
734     DWORD                   usage;
735     UINT                    textureName;
736     UINT                    LOD;
737     WINED3DTEXTUREFILTERTYPE filterType;
738     DWORD                   states[MAX_WINETEXTURESTATES];
739
740 } IWineD3DBaseTextureClass;
741
742 typedef struct IWineD3DBaseTextureImpl
743 {
744     /* IUnknown & WineD3DResource Information     */
745     const IWineD3DBaseTextureVtbl *lpVtbl;
746     IWineD3DResourceClass     resource;
747     IWineD3DBaseTextureClass  baseTexture;
748
749 } IWineD3DBaseTextureImpl;
750
751 /*****************************************************************************
752  * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
753  */
754 typedef struct IWineD3DTextureImpl
755 {
756     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
757     const IWineD3DTextureVtbl *lpVtbl;
758     IWineD3DResourceClass     resource;
759     IWineD3DBaseTextureClass  baseTexture;
760
761     /* IWineD3DTexture */
762     IWineD3DSurface          *surfaces[MAX_LEVELS];
763     
764     UINT                      width;
765     UINT                      height;
766     float                     pow2scalingFactorX;
767     float                     pow2scalingFactorY;
768
769 } IWineD3DTextureImpl;
770
771 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
772
773 /*****************************************************************************
774  * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
775  */
776 typedef struct IWineD3DCubeTextureImpl
777 {
778     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
779     const IWineD3DCubeTextureVtbl *lpVtbl;
780     IWineD3DResourceClass     resource;
781     IWineD3DBaseTextureClass  baseTexture;
782
783     /* IWineD3DCubeTexture */
784     IWineD3DSurface          *surfaces[6][MAX_LEVELS];
785
786     UINT                      edgeLength;
787     float                     pow2scalingFactor;
788
789 } IWineD3DCubeTextureImpl;
790
791 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
792
793 typedef struct _WINED3DVOLUMET_DESC
794 {
795     UINT                    Width;
796     UINT                    Height;
797     UINT                    Depth;
798 } WINED3DVOLUMET_DESC;
799
800 /*****************************************************************************
801  * IWineD3DVolume implementation structure (extends IUnknown)
802  */
803 typedef struct IWineD3DVolumeImpl
804 {
805     /* IUnknown & WineD3DResource fields */
806     const IWineD3DVolumeVtbl  *lpVtbl;
807     IWineD3DResourceClass      resource;
808
809     /* WineD3DVolume Information */
810     WINED3DVOLUMET_DESC      currentDesc;
811     IWineD3DBase            *container;
812     UINT                    bytesPerPixel;
813
814     BOOL                    lockable;
815     BOOL                    locked;
816     WINED3DBOX              lockedBox;
817     WINED3DBOX              dirtyBox;
818     BOOL                    dirty;
819
820
821 } IWineD3DVolumeImpl;
822
823 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
824
825 /*****************************************************************************
826  * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
827  */
828 typedef struct IWineD3DVolumeTextureImpl
829 {
830     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
831     const IWineD3DVolumeTextureVtbl *lpVtbl;
832     IWineD3DResourceClass     resource;
833     IWineD3DBaseTextureClass  baseTexture;
834
835     /* IWineD3DVolumeTexture */
836     IWineD3DVolume           *volumes[MAX_LEVELS];
837
838     UINT                      width;
839     UINT                      height;
840     UINT                      depth;
841 } IWineD3DVolumeTextureImpl;
842
843 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
844
845 typedef struct _WINED3DSURFACET_DESC
846 {
847     WINED3DMULTISAMPLE_TYPE MultiSampleType;
848     DWORD                   MultiSampleQuality;
849     UINT                    Width;
850     UINT                    Height;
851 } WINED3DSURFACET_DESC;
852
853 /*****************************************************************************
854  * Structure for DIB Surfaces (GetDC and GDI surfaces)
855  */
856 typedef struct wineD3DSurface_DIB {
857     HBITMAP DIBsection;
858     void* bitmap_data;
859     HGDIOBJ holdbitmap;
860     BOOL client_memory;
861 } wineD3DSurface_DIB;
862
863 /*****************************************************************************
864  * IWineD3DSurface implementation structure
865  */
866 struct IWineD3DSurfaceImpl
867 {
868     /* IUnknown & IWineD3DResource Information     */
869     const IWineD3DSurfaceVtbl *lpVtbl;
870     IWineD3DResourceClass     resource;
871
872     /* IWineD3DSurface fields */
873     IWineD3DBase              *container;
874     WINED3DSURFACET_DESC      currentDesc;
875     IWineD3DPaletteImpl      *palette;
876
877     UINT                      bytesPerPixel;
878
879     /* TODO: move this off into a management class(maybe!) */
880     DWORD                      Flags;
881
882     UINT                      pow2Width;
883     UINT                      pow2Height;
884     UINT                      pow2Size;
885
886     /* Oversized texture */
887     RECT                      glRect;
888
889 #if 0
890     /* precalculated x and y scalings for texture coords */
891     float                     pow2scalingFactorX; /* =  (Width  / pow2Width ) */
892     float                     pow2scalingFactorY; /* =  (Height / pow2Height) */
893 #endif
894
895     RECT                      lockedRect;
896     RECT                      dirtyRect;
897
898     glDescriptor              glDescription;
899
900     /* For GetDC */
901     wineD3DSurface_DIB        dib;
902     HDC                       hDC;
903
904     /* Color keys for DDraw */
905     DDCOLORKEY                DestBltCKey;
906     DDCOLORKEY                DestOverlayCKey;
907     DDCOLORKEY                SrcOverlayCKey;
908     DDCOLORKEY                SrcBltCKey;
909     DWORD                     CKeyFlags;
910
911     DDCOLORKEY                glCKey;
912 };
913
914 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
915 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
916
917 /* Predeclare the shared Surface functions */
918 HRESULT WINAPI IWineD3DSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
919 ULONG WINAPI IWineD3DSurfaceImpl_AddRef(IWineD3DSurface *iface);
920 ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface);
921 HRESULT WINAPI IWineD3DSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
922 HRESULT WINAPI IWineD3DSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
923 HRESULT WINAPI IWineD3DSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
924 HRESULT WINAPI IWineD3DSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
925 HRESULT WINAPI IWineD3DSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
926 DWORD   WINAPI IWineD3DSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
927 DWORD   WINAPI IWineD3DSurfaceImpl_GetPriority(IWineD3DSurface *iface);
928 void    WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface);
929 WINED3DRESOURCETYPE WINAPI IWineD3DSurfaceImpl_GetType(IWineD3DSurface *iface);
930 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainerParent(IWineD3DSurface* iface, IUnknown **ppContainerParent);
931 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
932 HRESULT WINAPI IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
933 HRESULT WINAPI IWineD3DSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
934 HRESULT WINAPI IWineD3DSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
935 HRESULT WINAPI IWineD3DSurfaceImpl_IsLost(IWineD3DSurface *iface);
936 HRESULT WINAPI IWineD3DSurfaceImpl_Restore(IWineD3DSurface *iface);
937 HRESULT WINAPI IWineD3DSurfaceImpl_SetPixelFormat(IWineD3DSurface *iface, WINED3DFORMAT Format, BYTE *Surface, DWORD Size);
938 HRESULT WINAPI IWineD3DSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
939 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
940 HRESULT WINAPI IWineD3DSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, DDCOLORKEY *CKey);
941 HRESULT WINAPI IWineD3DSurfaceImpl_CleanDirtyRect(IWineD3DSurface *iface);
942 extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect);
943 HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
944 HRESULT WINAPI IWineD3DSurfaceImpl_SetPBufferState(IWineD3DSurface *iface, BOOL inPBuffer, BOOL  inTexture);
945 void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target);
946 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription);
947 const void *WINAPI IWineD3DSurfaceImpl_GetData(IWineD3DSurface *iface);
948 HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
949 HRESULT WINAPI IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx);
950 HRESULT WINAPI IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty, IWineD3DSurface *Source, RECT *rsrc, DWORD trans);
951 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
952 HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC);
953 HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC);
954 DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface);
955 HRESULT WINAPI IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
956 HRESULT WINAPI IWineD3DSurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem);
957 HRESULT WINAPI IWineD3DSurfaceImpl_SetOverlayPosition(IWineD3DSurface *iface, LONG X, LONG Y);
958 HRESULT WINAPI IWineD3DSurfaceImpl_GetOverlayPosition(IWineD3DSurface *iface, LONG *X, LONG *Y);
959 HRESULT WINAPI IWineD3DSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface *iface, DWORD Flags, IWineD3DSurface *Ref);
960 HRESULT WINAPI IWineD3DSurfaceImpl_UpdateOverlay(IWineD3DSurface *iface, RECT *SrcRect, IWineD3DSurface *DstSurface, RECT *DstRect, DWORD Flags, WINEDDOVERLAYFX *FX);
961
962 /* Surface flags: */
963 #define SFLAG_OVERSIZE    0x00000001 /* Surface is bigger than gl size, blts only */
964 #define SFLAG_CONVERTED   0x00000002 /* Converted for color keying or Palettized */
965 #define SFLAG_DIBSECTION  0x00000004 /* Has a DIB section attached for getdc */
966 #define SFLAG_DIRTY       0x00000008 /* Surface was locked by the app */
967 #define SFLAG_LOCKABLE    0x00000010 /* Surface can be locked */
968 #define SFLAG_DISCARD     0x00000020 /* ??? */
969 #define SFLAG_LOCKED      0x00000040 /* Surface is locked atm */
970 #define SFLAG_ACTIVELOCK  0x00000080 /* Not locked, but surface memory is needed */
971 #define SFLAG_INTEXTURE   0x00000100 /* ??? */
972 #define SFLAG_INPBUFFER   0x00000200 /* ??? */
973 #define SFLAG_NONPOW2     0x00000400 /* Surface sizes are not a power of 2 */
974 #define SFLAG_DYNLOCK     0x00000800 /* Surface is often locked by the app */
975 #define SFLAG_DYNCHANGE   0x00001800 /* Surface contents are changed very often, implies DYNLOCK */
976 #define SFLAG_DCINUSE     0x00002000 /* Set between GetDC and ReleaseDC calls */
977 #define SFLAG_GLDIRTY     0x00004000 /* The opengl texture is more up to date than the surface mem */
978 #define SFLAG_LOST        0x00008000 /* Surface lost flag for DDraw */
979 #define SFLAG_FORCELOAD   0x00010000 /* To force PreLoading of a scratch cursor */
980 #define SFLAG_USERPTR     0x00020000 /* The application allocated the memory for this surface */
981 #define SFLAG_GLCKEY      0x00040000 /* The gl texture was created with a color key */
982
983 /* In some conditions the surface memory must not be freed:
984  * SFLAG_OVERSIZE: Not all data can be kept in GL
985  * SFLAG_CONVERTED: Converting the data back would take too long
986  * SFLAG_DIBSECTION: The dib code manages the memory
987  * SFLAG_DIRTY: GL surface isn't up to date
988  * SFLAG_LOCKED: The app requires access to the surface data
989  * SFLAG_ACTIVELOCK: Some wined3d code needs the memory
990  * SFLAG_DYNLOCK: Avoid freeing the data for performance
991  * SFLAG_DYNCHANGE: Same reason as DYNLOCK
992  */
993 #define SFLAG_DONOTFREE  (SFLAG_OVERSIZE   | \
994                           SFLAG_CONVERTED  | \
995                           SFLAG_DIBSECTION | \
996                           SFLAG_DIRTY      | \
997                           SFLAG_LOCKED     | \
998                           SFLAG_ACTIVELOCK | \
999                           SFLAG_DYNLOCK    | \
1000                           SFLAG_DYNCHANGE  | \
1001                           SFLAG_USERPTR)
1002
1003 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
1004
1005 /* Alignment of the pitch */
1006 #define SURFACE_ALIGNMENT 4
1007
1008 /*****************************************************************************
1009  * IWineD3DVertexDeclaration implementation structure
1010  */
1011 typedef struct IWineD3DVertexDeclarationImpl {
1012  /* IUnknown  Information     */
1013   const IWineD3DVertexDeclarationVtbl *lpVtbl;
1014   LONG                    ref;     /* Note: Ref counting not required */
1015
1016   IUnknown               *parent;
1017   /** precomputed fvf if simple declaration */
1018   IWineD3DDeviceImpl     *wineD3DDevice;
1019   DWORD   fvf[MAX_STREAMS];
1020   DWORD   allFVF;
1021
1022   /** dx8 compatible Declaration fields */
1023   DWORD*  pDeclaration8;
1024   DWORD   declaration8Length;
1025
1026   /** dx9+ */
1027   D3DVERTEXELEMENT9 *pDeclaration9;
1028   UINT               declaration9NumElements;
1029
1030   WINED3DVERTEXELEMENT  *pDeclarationWine;
1031   UINT                   declarationWNumElements;
1032   
1033   float                 *constants;
1034   
1035 } IWineD3DVertexDeclarationImpl;
1036
1037 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
1038
1039 /*****************************************************************************
1040  * IWineD3DStateBlock implementation structure
1041  */
1042
1043 /* Internal state Block for Begin/End/Capture/Create/Apply info  */
1044 /*   Note: Very long winded but gl Lists are not flexible enough */
1045 /*   to resolve everything we need, so doing it manually for now */
1046 typedef struct SAVEDSTATES {
1047         BOOL                      indices;
1048         BOOL                      material;
1049         BOOL                      fvf;
1050         BOOL                      streamSource[MAX_STREAMS];
1051         BOOL                      streamFreq[MAX_STREAMS];
1052         BOOL                      textures[MAX_SAMPLERS];
1053         BOOL                      transform[HIGHEST_TRANSFORMSTATE + 1];
1054         BOOL                      viewport;
1055         BOOL                      renderState[WINEHIGHEST_RENDER_STATE + 1];
1056         BOOL                      textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1057         BOOL                      samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1058         BOOL                      clipplane[MAX_CLIPPLANES];
1059         BOOL                      vertexDecl;
1060         BOOL                      pixelShader;
1061         BOOL                      pixelShaderConstantsB[MAX_CONST_B];
1062         BOOL                      pixelShaderConstantsI[MAX_CONST_I];
1063         BOOL                     *pixelShaderConstantsF;
1064         BOOL                      vertexShader;
1065         BOOL                      vertexShaderConstantsB[MAX_CONST_B];
1066         BOOL                      vertexShaderConstantsI[MAX_CONST_I];
1067         BOOL                     *vertexShaderConstantsF;
1068 } SAVEDSTATES;
1069
1070 typedef struct {
1071     struct list entry;
1072     int idx;
1073 } constant_entry;
1074
1075 struct IWineD3DStateBlockImpl
1076 {
1077     /* IUnknown fields */
1078     const IWineD3DStateBlockVtbl *lpVtbl;
1079     LONG                      ref;     /* Note: Ref counting not required */
1080
1081     /* IWineD3DStateBlock information */
1082     IUnknown                 *parent;
1083     IWineD3DDeviceImpl       *wineD3DDevice;
1084     WINED3DSTATEBLOCKTYPE     blockType;
1085
1086     /* Array indicating whether things have been set or changed */
1087     SAVEDSTATES               changed;
1088     SAVEDSTATES               set;
1089     struct list               set_vconstantsF;
1090     struct list               set_pconstantsF;
1091
1092     /* Drawing - Vertex Shader or FVF related */
1093     DWORD                     fvf;
1094     /* Vertex Shader Declaration */
1095     IWineD3DVertexDeclaration *vertexDecl;
1096
1097     IWineD3DVertexShader      *vertexShader;
1098
1099     /* Vertex Shader Constants */
1100     BOOL                       vertexShaderConstantB[MAX_CONST_B];
1101     INT                        vertexShaderConstantI[MAX_CONST_I * 4];
1102     float                     *vertexShaderConstantF;
1103
1104     /* Stream Source */
1105     BOOL                      streamIsUP;
1106     UINT                      streamStride[MAX_STREAMS];
1107     UINT                      streamOffset[MAX_STREAMS];
1108     IWineD3DVertexBuffer     *streamSource[MAX_STREAMS];
1109     UINT                      streamFreq[MAX_STREAMS];
1110     UINT                      streamFlags[MAX_STREAMS];     /*0 | WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA  */
1111
1112     /* Indices */
1113     IWineD3DIndexBuffer*      pIndexData;
1114     UINT                      baseVertexIndex; /* Note: only used for d3d8 */
1115
1116     /* Transform */
1117     WINED3DMATRIX             transforms[HIGHEST_TRANSFORMSTATE + 1];
1118
1119     /* Lights */
1120     PLIGHTINFOEL             *lights; /* NOTE: active GL lights must be front of the chain */
1121
1122     /* Clipping */
1123     double                    clipplane[MAX_CLIPPLANES][4];
1124     WINED3DCLIPSTATUS         clip_status;
1125
1126     /* ViewPort */
1127     WINED3DVIEWPORT           viewport;
1128
1129     /* Material */
1130     WINED3DMATERIAL           material;
1131
1132     /* Pixel Shader */
1133     IWineD3DPixelShader      *pixelShader;
1134
1135     /* Pixel Shader Constants */
1136     BOOL                       pixelShaderConstantB[MAX_CONST_B];
1137     INT                        pixelShaderConstantI[MAX_CONST_I * 4];
1138     float                     *pixelShaderConstantF;
1139
1140     /* Indexed Vertex Blending */
1141     WINED3DVERTEXBLENDFLAGS   vertex_blend;
1142     FLOAT                     tween_factor;
1143
1144     /* RenderState */
1145     DWORD                     renderState[WINEHIGHEST_RENDER_STATE + 1];
1146
1147     /* Texture */
1148     IWineD3DBaseTexture      *textures[MAX_SAMPLERS];
1149     int                       textureDimensions[MAX_SAMPLERS];
1150
1151     /* Texture State Stage */
1152     DWORD                     textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1153     /* Sampler States */
1154     DWORD                     samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1155
1156     /* Current GLSL Shader Program */
1157     struct glsl_shader_prog_link *glsl_program;
1158 };
1159
1160 extern void stateblock_savedstates_set(
1161     IWineD3DStateBlock* iface,
1162     SAVEDSTATES* states,
1163     BOOL value);
1164
1165 extern void stateblock_savedstates_copy(
1166     IWineD3DStateBlock* iface,
1167     SAVEDSTATES* dest,
1168     SAVEDSTATES* source);
1169
1170 extern void stateblock_copy(
1171     IWineD3DStateBlock* destination,
1172     IWineD3DStateBlock* source);
1173
1174 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1175
1176 /*****************************************************************************
1177  * IWineD3DQueryImpl implementation structure (extends IUnknown)
1178  */
1179 typedef struct IWineD3DQueryImpl
1180 {
1181     const IWineD3DQueryVtbl  *lpVtbl;
1182     LONG                      ref;     /* Note: Ref counting not required */
1183     
1184     IUnknown                 *parent;
1185     /*TODO: replace with iface usage */
1186 #if 0
1187     IWineD3DDevice         *wineD3DDevice;
1188 #else
1189     IWineD3DDeviceImpl       *wineD3DDevice;
1190 #endif
1191
1192     /* IWineD3DQuery fields */
1193     WINED3DQUERYTYPE         type;
1194     /* TODO: Think about using a IUnknown instead of a void* */
1195     void                     *extendedData;
1196     
1197   
1198 } IWineD3DQueryImpl;
1199
1200 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1201
1202 /* Datastructures for IWineD3DQueryImpl.extendedData */
1203 typedef struct  WineQueryOcclusionData {
1204     GLuint  queryId;
1205 } WineQueryOcclusionData;
1206
1207
1208 /*****************************************************************************
1209  * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1210  */
1211
1212 typedef struct IWineD3DSwapChainImpl
1213 {
1214     /*IUnknown part*/
1215     IWineD3DSwapChainVtbl    *lpVtbl;
1216     LONG                      ref;     /* Note: Ref counting not required */
1217
1218     IUnknown                 *parent;
1219     IWineD3DDeviceImpl       *wineD3DDevice;
1220
1221     /* IWineD3DSwapChain fields */
1222     IWineD3DSurface         **backBuffer;
1223     IWineD3DSurface          *frontBuffer;
1224     BOOL                      wantsDepthStencilBuffer;
1225     D3DPRESENT_PARAMETERS     presentParms;
1226
1227     /* TODO: move everything up to drawable off into a context manager
1228       and store the 'data' in the contextManagerData interface.
1229     IUnknown                  *contextManagerData;
1230     */
1231
1232     HWND                    win_handle;
1233     Window                  win;
1234     Display                *display;
1235
1236     GLXContext              glCtx;
1237     XVisualInfo            *visInfo;
1238     GLXContext              render_ctx;
1239     /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1240     Drawable                drawable;
1241 } IWineD3DSwapChainImpl;
1242
1243 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1244
1245 /*****************************************************************************
1246  * Utility function prototypes 
1247  */
1248
1249 /* Trace routines */
1250 const char* debug_d3dformat(WINED3DFORMAT fmt);
1251 const char* debug_d3ddevicetype(WINED3DDEVTYPE devtype);
1252 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1253 const char* debug_d3dusage(DWORD usage);
1254 const char* debug_d3dusagequery(DWORD usagequery);
1255 const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method);
1256 const char* debug_d3ddecltype(WINED3DDECLTYPE type);
1257 const char* debug_d3ddeclusage(BYTE usage);
1258 const char* debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType);
1259 const char* debug_d3drenderstate(DWORD state);
1260 const char* debug_d3dsamplerstate(DWORD state);
1261 const char* debug_d3dtexturestate(DWORD state);
1262 const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype);
1263 const char* debug_d3dpool(WINED3DPOOL pool);
1264
1265 /* Routines for GL <-> D3D values */
1266 GLenum StencilOp(DWORD op);
1267 GLenum CompareFunc(DWORD func);
1268 void   set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1269 void   set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx);
1270 void   set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1271
1272 int D3DFmtMakeGlCfg(WINED3DFORMAT BackBufferFormat, WINED3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1273
1274 /* Math utils */
1275 void multiply_matrix(WINED3DMATRIX *dest, WINED3DMATRIX *src1, WINED3DMATRIX *src2);
1276
1277 /*****************************************************************************
1278  * To enable calling of inherited functions, requires prototypes 
1279  *
1280  * Note: Only require classes which are subclassed, ie resource, basetexture, 
1281  */
1282     /*** IUnknown methods ***/
1283     extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1284     extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1285     extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1286     /*** IWineD3DResource methods ***/
1287     extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1288     extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1289     extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1290     extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1291     extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID  refguid);
1292     extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD  PriorityNew);
1293     extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1294     extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1295     extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1296     /*** class static members ***/
1297     void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1298
1299     /*** IUnknown methods ***/
1300     extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1301     extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1302     extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1303     /*** IWineD3DResource methods ***/
1304     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1305     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1306     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
1307     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
1308     extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid);
1309     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD  PriorityNew);
1310     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1311     extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1312     extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1313     /*** IWineD3DBaseTexture methods ***/
1314     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1315     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1316     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1317     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1318     extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1319     extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1320     extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1321     extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1322
1323     extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset, GLint *vbo);
1324     extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1325     extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1326     extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1327     extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1328     /*** class static members ***/
1329     void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1330
1331 struct SHADER_OPCODE_ARG;
1332 typedef void (*shader_fct_t)();
1333 typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
1334
1335 /* Struct to maintain a list of GLSL shader programs and their associated pixel and
1336  * vertex shaders.  A list of this type is maintained on the DeviceImpl, and is only
1337  * used if the user is using GLSL shaders. */
1338 struct glsl_shader_prog_link {
1339     struct list             entry;
1340     GLhandleARB             programId;
1341     GLhandleARB             *vuniformF_locations;
1342     GLhandleARB             *puniformF_locations;
1343     IWineD3DVertexShader*   vertexShader;
1344     IWineD3DPixelShader*    pixelShader;
1345 };
1346
1347 /* TODO: Make this dynamic, based on shader limits ? */
1348 #define MAX_REG_ADDR 1
1349 #define MAX_REG_TEMP 32
1350 #define MAX_REG_TEXCRD 8
1351 #define MAX_REG_INPUT 12
1352 #define MAX_REG_OUTPUT 12
1353 #define MAX_ATTRIBS 16
1354 #define MAX_CONST_I 16
1355 #define MAX_CONST_B 16
1356
1357 /* FIXME: This needs to go up to 2048 for
1358  * Shader model 3 according to msdn (and for software shaders) */
1359 #define MAX_LABELS 16
1360
1361 typedef struct semantic {
1362     DWORD usage;
1363     DWORD reg;
1364 } semantic;
1365
1366 typedef struct local_constant {
1367     struct list entry;
1368     unsigned int idx;
1369     DWORD value[4];
1370 } local_constant;
1371
1372 typedef struct shader_reg_maps {
1373
1374     char texcoord[MAX_REG_TEXCRD];          /* pixel < 3.0 */
1375     char temporary[MAX_REG_TEMP];           /* pixel, vertex */
1376     char address[MAX_REG_ADDR];             /* vertex */
1377     char packed_input[MAX_REG_INPUT];       /* pshader >= 3.0 */
1378     char packed_output[MAX_REG_OUTPUT];     /* vertex >= 3.0 */
1379     char attributes[MAX_ATTRIBS];           /* vertex */
1380     char labels[MAX_LABELS];                /* pixel, vertex */
1381
1382     /* Sampler usage tokens 
1383      * Use 0 as default (bit 31 is always 1 on a valid token) */
1384     DWORD samplers[MAX_SAMPLERS];
1385
1386     /* Whether or not a loop is used in this shader */
1387     char loop;
1388
1389     /* Whether or not this shader uses fog */
1390     char fog;
1391
1392 } shader_reg_maps;
1393
1394 #define SHADER_PGMSIZE 65535
1395 typedef struct SHADER_BUFFER {
1396     char* buffer;
1397     unsigned int bsize;
1398     unsigned int lineNo;
1399 } SHADER_BUFFER;
1400
1401 /* Undocumented opcode controls */
1402 #define INST_CONTROLS_SHIFT 16
1403 #define INST_CONTROLS_MASK 0x00ff0000
1404
1405 typedef enum COMPARISON_TYPE {
1406     COMPARISON_GT = 1,
1407     COMPARISON_EQ = 2,
1408     COMPARISON_GE = 3,
1409     COMPARISON_LT = 4,
1410     COMPARISON_NE = 5,
1411     COMPARISON_LE = 6
1412 } COMPARISON_TYPE;
1413
1414 typedef struct SHADER_OPCODE {
1415     unsigned int  opcode;
1416     const char*   name;
1417     const char*   glname;
1418     char          dst_token;
1419     CONST UINT    num_params;
1420     shader_fct_t  soft_fct;
1421     SHADER_HANDLER hw_fct;
1422     SHADER_HANDLER hw_glsl_fct;
1423     DWORD         min_version;
1424     DWORD         max_version;
1425 } SHADER_OPCODE;
1426
1427 typedef struct SHADER_OPCODE_ARG {
1428     IWineD3DBaseShader* shader;
1429     shader_reg_maps* reg_maps;
1430     CONST SHADER_OPCODE* opcode;
1431     DWORD opcode_token;
1432     DWORD dst;
1433     DWORD dst_addr;
1434     DWORD predicate;
1435     DWORD src[4];
1436     DWORD src_addr[4];
1437     SHADER_BUFFER* buffer;
1438 } SHADER_OPCODE_ARG;
1439
1440 typedef struct SHADER_LIMITS {
1441     unsigned int temporary;
1442     unsigned int texcoord;
1443     unsigned int sampler;
1444     unsigned int constant_int;
1445     unsigned int constant_float;
1446     unsigned int constant_bool;
1447     unsigned int address;
1448     unsigned int packed_output;
1449     unsigned int packed_input;
1450     unsigned int attributes;
1451     unsigned int label;
1452 } SHADER_LIMITS;
1453
1454 /** Keeps track of details for TEX_M#x# shader opcodes which need to 
1455     maintain state information between multiple codes */
1456 typedef struct SHADER_PARSE_STATE {
1457     unsigned int current_row;
1458     DWORD texcoord_w[2];
1459 } SHADER_PARSE_STATE;
1460
1461 /* Base Shader utility functions. 
1462  * (may move callers into the same file in the future) */
1463 extern int shader_addline(
1464     SHADER_BUFFER* buffer,
1465     const char* fmt, ...);
1466
1467 extern const SHADER_OPCODE* shader_get_opcode(
1468     IWineD3DBaseShader *iface, 
1469     const DWORD code);
1470
1471 extern void shader_delete_constant_list(
1472     struct list* clist);
1473
1474 /* Vertex shader utility functions */
1475 extern BOOL vshader_get_input(
1476     IWineD3DVertexShader* iface,
1477     BYTE usage_req, BYTE usage_idx_req,
1478     unsigned int* regnum);
1479
1480 extern BOOL vshader_input_is_color(
1481     IWineD3DVertexShader* iface,
1482     unsigned int regnum);
1483
1484 extern HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object);
1485
1486 /* ARB_[vertex/fragment]_program helper functions */
1487 extern void shader_arb_load_constants(
1488     IWineD3DDevice* device,
1489     char usePixelShader,
1490     char useVertexShader);
1491
1492 /* ARB shader program Prototypes */
1493 extern void shader_hw_def(SHADER_OPCODE_ARG *arg);
1494
1495 /* ARB pixel shader prototypes */
1496 extern void pshader_hw_cnd(SHADER_OPCODE_ARG* arg);
1497 extern void pshader_hw_cmp(SHADER_OPCODE_ARG* arg);
1498 extern void pshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1499 extern void pshader_hw_tex(SHADER_OPCODE_ARG* arg);
1500 extern void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg);
1501 extern void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg);
1502 extern void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg);
1503 extern void pshader_hw_texbem(SHADER_OPCODE_ARG* arg);
1504 extern void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG* arg);
1505 extern void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg);
1506 extern void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg);
1507 extern void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg);
1508 extern void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg);
1509 extern void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1510
1511 /* ARB vertex shader prototypes */
1512 extern void vshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1513 extern void vshader_hw_mnxn(SHADER_OPCODE_ARG* arg);
1514
1515 /* GLSL helper functions */
1516 extern void set_glsl_shader_program(IWineD3DDevice *iface);
1517 extern void shader_glsl_add_instruction_modifiers(SHADER_OPCODE_ARG *arg);
1518 extern void shader_glsl_load_constants(
1519     IWineD3DDevice* device,
1520     char usePixelShader,
1521     char useVertexShader);
1522
1523 /** The following translate DirectX pixel/vertex shader opcodes to GLSL lines */
1524 extern void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg);
1525 extern void shader_glsl_arith(SHADER_OPCODE_ARG* arg);
1526 extern void shader_glsl_mov(SHADER_OPCODE_ARG* arg);
1527 extern void shader_glsl_mad(SHADER_OPCODE_ARG* arg);
1528 extern void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg);
1529 extern void shader_glsl_lrp(SHADER_OPCODE_ARG* arg);
1530 extern void shader_glsl_dot(SHADER_OPCODE_ARG* arg);
1531 extern void shader_glsl_rcp(SHADER_OPCODE_ARG* arg);
1532 extern void shader_glsl_cnd(SHADER_OPCODE_ARG* arg);
1533 extern void shader_glsl_compare(SHADER_OPCODE_ARG* arg);
1534 extern void shader_glsl_def(SHADER_OPCODE_ARG* arg);
1535 extern void shader_glsl_defi(SHADER_OPCODE_ARG* arg);
1536 extern void shader_glsl_defb(SHADER_OPCODE_ARG* arg);
1537 extern void shader_glsl_expp(SHADER_OPCODE_ARG* arg);
1538 extern void shader_glsl_cmp(SHADER_OPCODE_ARG* arg);
1539 extern void shader_glsl_lit(SHADER_OPCODE_ARG* arg);
1540 extern void shader_glsl_dst(SHADER_OPCODE_ARG* arg);
1541 extern void shader_glsl_sincos(SHADER_OPCODE_ARG* arg);
1542 extern void shader_glsl_loop(SHADER_OPCODE_ARG* arg);
1543 extern void shader_glsl_end(SHADER_OPCODE_ARG* arg);
1544 extern void shader_glsl_if(SHADER_OPCODE_ARG* arg);
1545 extern void shader_glsl_ifc(SHADER_OPCODE_ARG* arg);
1546 extern void shader_glsl_else(SHADER_OPCODE_ARG* arg);
1547 extern void shader_glsl_break(SHADER_OPCODE_ARG* arg);
1548 extern void shader_glsl_breakc(SHADER_OPCODE_ARG* arg);
1549 extern void shader_glsl_rep(SHADER_OPCODE_ARG* arg);
1550 extern void shader_glsl_call(SHADER_OPCODE_ARG* arg);
1551 extern void shader_glsl_callnz(SHADER_OPCODE_ARG* arg);
1552 extern void shader_glsl_label(SHADER_OPCODE_ARG* arg);
1553
1554 /** GLSL Pixel Shader Prototypes */
1555 extern void pshader_glsl_tex(SHADER_OPCODE_ARG* arg);
1556 extern void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg);
1557 extern void pshader_glsl_texdp3tex(SHADER_OPCODE_ARG* arg);
1558 extern void pshader_glsl_texdp3(SHADER_OPCODE_ARG* arg);
1559 extern void pshader_glsl_texdepth(SHADER_OPCODE_ARG* arg);
1560 extern void pshader_glsl_texm3x2depth(SHADER_OPCODE_ARG* arg);
1561 extern void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg);
1562 extern void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg);
1563 extern void pshader_glsl_texm3x3(SHADER_OPCODE_ARG* arg);
1564 extern void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg);
1565 extern void pshader_glsl_texm3x3tex(SHADER_OPCODE_ARG* arg);
1566 extern void pshader_glsl_texm3x3spec(SHADER_OPCODE_ARG* arg);
1567 extern void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1568 extern void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg);
1569 extern void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg);
1570 extern void pshader_glsl_texreg2ar(SHADER_OPCODE_ARG* arg);
1571 extern void pshader_glsl_texreg2gb(SHADER_OPCODE_ARG* arg);
1572 extern void pshader_glsl_texreg2rgb(SHADER_OPCODE_ARG* arg);
1573 extern void pshader_glsl_dp2add(SHADER_OPCODE_ARG* arg);
1574 extern void pshader_glsl_input_pack(
1575    SHADER_BUFFER* buffer,
1576    semantic* semantics_out);
1577
1578 /** GLSL Vertex Shader Prototypes */
1579 extern void vshader_glsl_output_unpack(
1580    SHADER_BUFFER* buffer,
1581    semantic* semantics_out);
1582
1583 /*****************************************************************************
1584  * IDirect3DBaseShader implementation structure
1585  */
1586 typedef struct IWineD3DBaseShaderClass
1587 {
1588     DWORD                           hex_version;
1589     SHADER_LIMITS                   limits;
1590     SHADER_PARSE_STATE              parse_state;
1591     CONST SHADER_OPCODE             *shader_ins;
1592     CONST DWORD                     *function;
1593     UINT                            functionLength;
1594     GLuint                          prgId;
1595     BOOL                            is_compiled;
1596
1597     /* Type of shader backend */
1598     int shader_mode;
1599
1600     /* Immediate constants (override global ones) */
1601     struct list constantsB;
1602     struct list constantsF;
1603     struct list constantsI;
1604     shader_reg_maps reg_maps;
1605
1606     /* Pointer to the parent device */
1607     IWineD3DDevice *device;
1608
1609 } IWineD3DBaseShaderClass;
1610
1611 typedef struct IWineD3DBaseShaderImpl {
1612     /* IUnknown */
1613     const IWineD3DBaseShaderVtbl    *lpVtbl;
1614     LONG                            ref;
1615
1616     /* IWineD3DBaseShader */
1617     IWineD3DBaseShaderClass         baseShader;
1618 } IWineD3DBaseShaderImpl;
1619
1620 extern HRESULT shader_get_registers_used(
1621     IWineD3DBaseShader *iface,
1622     shader_reg_maps* reg_maps,
1623     semantic* semantics_in,
1624     semantic* semantics_out,
1625     CONST DWORD* pToken,
1626     IWineD3DStateBlockImpl *stateBlock);
1627
1628 extern void shader_generate_glsl_declarations(
1629     IWineD3DBaseShader *iface,
1630     shader_reg_maps* reg_maps,
1631     SHADER_BUFFER* buffer,
1632     WineD3D_GL_Info* gl_info);
1633
1634 extern void shader_generate_arb_declarations(
1635     IWineD3DBaseShader *iface,
1636     shader_reg_maps* reg_maps,
1637     SHADER_BUFFER* buffer,
1638     WineD3D_GL_Info* gl_info);
1639
1640 extern void shader_generate_main(
1641     IWineD3DBaseShader *iface,
1642     SHADER_BUFFER* buffer,
1643     shader_reg_maps* reg_maps,
1644     CONST DWORD* pFunction);
1645
1646 extern void shader_dump_ins_modifiers(
1647     const DWORD output);
1648
1649 extern void shader_dump_param(
1650     IWineD3DBaseShader *iface,
1651     const DWORD param,
1652     const DWORD addr_token,
1653     int input);
1654
1655 extern void shader_trace_init(
1656     IWineD3DBaseShader *iface,
1657     const DWORD* pFunction);
1658
1659 extern int shader_get_param(
1660     IWineD3DBaseShader* iface,
1661     const DWORD* pToken,
1662     DWORD* param,
1663     DWORD* addr_token);
1664
1665 extern int shader_skip_unrecognized(
1666     IWineD3DBaseShader* iface,
1667     const DWORD* pToken);
1668
1669 extern void print_glsl_info_log(
1670     WineD3D_GL_Info *gl_info,
1671     GLhandleARB obj);
1672
1673 inline static int shader_get_regtype(const DWORD param) {
1674     return (((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT) |
1675             ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2));
1676 }
1677
1678 extern unsigned int shader_get_float_offset(const DWORD reg);
1679
1680 inline static BOOL shader_is_pshader_version(DWORD token) {
1681     return 0xFFFF0000 == (token & 0xFFFF0000);
1682 }
1683
1684 inline static BOOL shader_is_vshader_version(DWORD token) {
1685     return 0xFFFE0000 == (token & 0xFFFF0000);
1686 }
1687
1688 inline static BOOL shader_is_comment(DWORD token) {
1689     return WINED3DSIO_COMMENT == (token & WINED3DSI_OPCODE_MASK);
1690 }
1691
1692 /* Internally used shader constants. Applications can use constants 0 to GL_LIMITS(vshader_constantsF) - 1,
1693  * so upload them above that
1694  */
1695 #define ARB_SHADER_PRIVCONST_BASE GL_LIMITS(vshader_constantsF)
1696 #define ARB_SHADER_PRIVCONST_POS ARB_SHADER_PRIVCONST_BASE + 0
1697
1698 /*****************************************************************************
1699  * IDirect3DVertexShader implementation structure
1700  */
1701 typedef struct IWineD3DVertexShaderImpl {
1702     /* IUnknown parts*/   
1703     const IWineD3DVertexShaderVtbl *lpVtbl;
1704     LONG                        ref;     /* Note: Ref counting not required */
1705
1706     /* IWineD3DBaseShader */
1707     IWineD3DBaseShaderClass     baseShader;
1708
1709     /* IWineD3DVertexShaderImpl */
1710     IUnknown                    *parent;
1711
1712     char                        usesFog;
1713     DWORD                       usage;
1714
1715     /* Vertex shader input and output semantics */
1716     semantic semantics_in [MAX_ATTRIBS];
1717     semantic semantics_out [MAX_REG_OUTPUT];
1718
1719     /* run time datas...  */
1720     VSHADERDATA                *data;
1721     IWineD3DVertexDeclaration  *vertexDeclaration;
1722 #if 0 /* needs reworking */
1723     /* run time datas */
1724     VSHADERINPUTDATA input;
1725     VSHADEROUTPUTDATA output;
1726 #endif
1727 } IWineD3DVertexShaderImpl;
1728 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1729 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1730
1731 /*****************************************************************************
1732  * IDirect3DPixelShader implementation structure
1733  */
1734 typedef struct IWineD3DPixelShaderImpl {
1735     /* IUnknown parts */
1736     const IWineD3DPixelShaderVtbl *lpVtbl;
1737     LONG                        ref;     /* Note: Ref counting not required */
1738
1739     /* IWineD3DBaseShader */
1740     IWineD3DBaseShaderClass     baseShader;
1741
1742     /* IWineD3DPixelShaderImpl */
1743     IUnknown                   *parent;
1744
1745     /* Pixel shader input semantics */
1746     semantic semantics_in [MAX_REG_INPUT];
1747
1748     /* run time data */
1749     PSHADERDATA                *data;
1750
1751 #if 0 /* needs reworking */
1752     PSHADERINPUTDATA input;
1753     PSHADEROUTPUTDATA output;
1754 #endif
1755 } IWineD3DPixelShaderImpl;
1756
1757 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1758 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1759
1760 /*****************************************************************************
1761  * IWineD3DPalette implementation structure
1762  */
1763 struct IWineD3DPaletteImpl {
1764     /* IUnknown parts */
1765     const IWineD3DPaletteVtbl  *lpVtbl;
1766     LONG                       ref;
1767
1768     IUnknown                   *parent;
1769     IWineD3DDeviceImpl         *wineD3DDevice;
1770
1771     /* IWineD3DPalette */
1772     HPALETTE                   hpal;
1773     WORD                       palVersion;     /*|               */
1774     WORD                       palNumEntries;  /*|  LOGPALETTE   */
1775     PALETTEENTRY               palents[256];   /*|               */
1776     /* This is to store the palette in 'screen format' */
1777     int                        screen_palents[256];
1778     DWORD                      Flags;
1779 };
1780
1781 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
1782 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
1783
1784 /* DirectDraw utility functions */
1785 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
1786
1787 /*****************************************************************************
1788  * Pixel format management
1789  */
1790 typedef struct {
1791     WINED3DFORMAT           format;
1792     DWORD                   alphaMask, redMask, greenMask, blueMask;
1793     UINT                    bpp;
1794     BOOL                    isFourcc;
1795     GLint                   glInternal, glFormat, glType;
1796 } PixelFormatDesc;
1797
1798 const PixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt);
1799 #endif