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