Fixed regression that occurred because changes to texture loading were
[wine] / dlls / wined3d / wined3d_private.h
1 /*
2  * Direct3D wine internal private include file
3  *
4  * Copyright 2002-2003 The wine-d3d team
5  * Copyright 2002-2003 Raphael Junqueira
6  * Copyright 2004 Jason Edmeades
7  * Copyright 2005 Oliver Stieber
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #ifndef __WINE_WINED3D_PRIVATE_H
25 #define __WINE_WINED3D_PRIVATE_H
26
27 #include <stdarg.h>
28 #include <math.h>
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
31 #define COBJMACROS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winreg.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
39
40 #include "d3d9.h"
41 #include "d3d9types.h"
42 #include "wine/wined3d_interface.h"
43 #include "wine/wined3d_gl.h"
44
45 /* Device caps */
46 #define MAX_PALETTES      256
47 #define MAX_STREAMS       16
48 #define MAX_TEXTURES      8
49 #define MAX_SAMPLERS      16
50 #define MAX_ACTIVE_LIGHTS 8
51 #define MAX_CLIPPLANES    D3DMAXUSERCLIPPLANES
52 #define MAX_LEVELS        256
53
54 /* Swap chains */
55 #define MAX_SWAPCHAINS 256
56
57 /* Used for CreateStateBlock */
58 #define NUM_SAVEDPIXELSTATES_R     35
59 #define NUM_SAVEDPIXELSTATES_T     18
60 #define NUM_SAVEDPIXELSTATES_S     12
61 #define NUM_SAVEDVERTEXSTATES_R    31
62 #define NUM_SAVEDVERTEXSTATES_T    2
63 #define NUM_SAVEDVERTEXSTATES_S    1
64
65 extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
66 extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
67 extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
68 extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
69 extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
70 extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
71
72 /* vertex and pixel shader modes */
73 extern int vs_mode;
74 #define VS_NONE 0
75 #define VS_HW   1
76 #define VS_SW   2
77
78 extern int ps_mode;
79 #define PS_NONE 0
80 #define PS_HW   1
81
82 /* X11 locking */
83
84 extern void (*wine_tsx11_lock_ptr)(void);
85 extern void (*wine_tsx11_unlock_ptr)(void);
86
87 /* As GLX relies on X, this is needed */
88 extern int num_lock;
89
90 #if 0
91 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
92 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
93 #else
94 #define ENTER_GL() wine_tsx11_lock_ptr()
95 #define LEAVE_GL() wine_tsx11_unlock_ptr()
96 #endif
97
98 /*****************************************************************************
99  * Defines
100  */
101
102 /* GL related defines */
103 /* ------------------ */
104 #define GL_SUPPORT(ExtName)           (GLINFO_LOCATION.supported[ExtName] != 0)
105 #define GL_LIMITS(ExtName)            (GLINFO_LOCATION.max_##ExtName)
106 #define GL_EXTCALL(FuncName)          (GLINFO_LOCATION.FuncName)
107
108 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
109 #define D3DCOLOR_G(dw) (((float) (((dw) >>  8) & 0xFF)) / 255.0f)
110 #define D3DCOLOR_B(dw) (((float) (((dw) >>  0) & 0xFF)) / 255.0f)
111 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
112
113 #define D3DCOLORTOGLFLOAT4(dw, vec) \
114   (vec)[0] = D3DCOLOR_R(dw); \
115   (vec)[1] = D3DCOLOR_G(dw); \
116   (vec)[2] = D3DCOLOR_B(dw); \
117   (vec)[3] = D3DCOLOR_A(dw);
118   
119 /* Note: The following is purely to keep the source code as clear from #ifdefs as possible */
120 #if defined(GL_VERSION_1_3)
121 #define GLACTIVETEXTURE(textureNo)                          \
122             glActiveTexture(GL_TEXTURE0 + textureNo);       \
123             checkGLcall("glActiveTexture");      
124 #define GLCLIENTACTIVETEXTURE(textureNo)                    \
125             glClientActiveTexture(GL_TEXTURE0 + textureNo);
126 #define GLMULTITEXCOORD1F(a,b)                              \
127             glMultiTexCoord1f(GL_TEXTURE0 + a, b);
128 #define GLMULTITEXCOORD2F(a,b,c)                            \
129             glMultiTexCoord2f(GL_TEXTURE0 + a, b, c);
130 #define GLMULTITEXCOORD3F(a,b,c,d)                          \
131             glMultiTexCoord3f(GL_TEXTURE0 + a, b, c, d);
132 #define GLMULTITEXCOORD4F(a,b,c,d,e)                        \
133             glMultiTexCoord4f(GL_TEXTURE0 + a, b, c, d, e);
134 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP
135 #else 
136 #define GLACTIVETEXTURE(textureNo)                             \
137             glActiveTextureARB(GL_TEXTURE0_ARB + textureNo);   \
138             checkGLcall("glActiveTextureARB");
139 #define GLCLIENTACTIVETEXTURE(textureNo)                    \
140             glClientActiveTextureARB(GL_TEXTURE0_ARB + textureNo);
141 #define GLMULTITEXCOORD1F(a,b)                                 \
142             glMultiTexCoord1fARB(GL_TEXTURE0_ARB + a, b);
143 #define GLMULTITEXCOORD2F(a,b,c)                               \
144             glMultiTexCoord2fARB(GL_TEXTURE0_ARB + a, b, c);
145 #define GLMULTITEXCOORD3F(a,b,c,d)                             \
146             glMultiTexCoord3fARB(GL_TEXTURE0_ARB + a, b, c, d);
147 #define GLMULTITEXCOORD4F(a,b,c,d,e)                           \
148             glMultiTexCoord4fARB(GL_TEXTURE0_ARB + a, b, c, d, e);
149 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP_ARB
150 #endif
151
152 /* DirectX Device Limits */
153 /* --------------------- */
154 #define MAX_LEVELS  256  /* Maximum number of mipmap levels. Guessed at 256 */
155
156 #define MAX_STREAMS  16  /* Maximum possible streams - used for fixed size arrays
157                             See MaxStreams in MSDN under GetDeviceCaps */
158                          /* Maximum number of constants provided to the shaders */
159 #define HIGHEST_TRANSFORMSTATE 512 
160                          /* Highest value in D3DTRANSFORMSTATETYPE */
161 #define HIGHEST_TEXTURE_STATE   D3DTSS_CONSTANT
162                          /* Highest D3DTSS_ value                  */
163 #define HIGHEST_SAMPLER_STATE   D3DSAMP_DMAPOFFSET
164                          /* Maximum number of constants provided to the shaders */
165 #define MAX_CLIPPLANES  D3DMAXUSERCLIPPLANES
166
167 #define MAX_PALETTES      256
168
169 /* Checking of API calls */
170 /* --------------------- */
171 #define checkGLcall(A) \
172 { \
173     GLint err = glGetError();   \
174     if (err != GL_NO_ERROR) { \
175        FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
176     } else { \
177        TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
178     } \
179 }
180
181 /* Trace routines / diagnostics */
182 /* ---------------------------- */
183
184 /* Dump out a matrix and copy it */
185 #define conv_mat(mat,gl_mat)                                                                \
186 do {                                                                                        \
187     TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
188     TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
189     TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
190     TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
191     memcpy(gl_mat, (mat), 16 * sizeof(float));                                              \
192 } while (0)
193
194 /* Macro to dump out the current state of the light chain */
195 #define DUMP_LIGHT_CHAIN()                    \
196 {                                             \
197   PLIGHTINFOEL *el = This->stateBlock->lights;\
198   while (el) {                                \
199     TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
200     el = el->next;                            \
201   }                                           \
202 }
203
204 /* Trace vector and strided data information */
205 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
206 #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);
207
208 /* Defines used for optimizations */
209
210 /*    Only reapply what is necessary */
211 #define REAPPLY_ALPHAOP  0x0001
212 #define REAPPLY_ALL      0xFFFF
213
214 /* Advance declaration of structures to satisfy compiler */
215 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
216 typedef struct IWineD3DSurfaceImpl    IWineD3DSurfaceImpl;
217
218 /* Tracking */
219
220 /* TODO: Move some of this to the device */
221 long globalChangeGlRam(long glram);
222
223 /* Memory and object tracking */
224
225 /*Structure for holding information on all direct3d objects
226 usefull for making sure tracking is ok and when release is called on a device!
227 and probably quite handy for debuggin and dumping states out
228 */
229 typedef struct WineD3DGlobalStatistics {
230     int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
231 } WineD3DGlobalStatistics;
232
233 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
234
235 /* Global variables */
236 extern const float identity[16];
237
238 /*****************************************************************************
239  * Compilable extra diagnostics
240  */
241
242 /* Trace information per-vertex: (extremely high amount of trace) */
243 #if 0 /* NOTE: Must be 0 in cvs */
244 # define VTRACE(A) TRACE A
245 #else 
246 # define VTRACE(A) 
247 #endif
248
249 /* Checking of per-vertex related GL calls */
250 #define vcheckGLcall(A) \
251 { \
252     GLint err = glGetError();   \
253     if (err != GL_NO_ERROR) { \
254        FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
255     } else { \
256        VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
257     } \
258 }
259
260 /* TODO: Confirm each of these works when wined3d move completed */
261 #if 0 /* NOTE: Must be 0 in cvs */
262   /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
263      of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
264      is enabled, and if it doesn't exists it is disabled.                                           */
265 # define FRAME_DEBUGGING
266   /*  Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
267       the file is deleted                                                                            */
268 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
269 #  define SINGLE_FRAME_DEBUGGING
270 # endif  
271   /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
272      It can only be enabled when FRAME_DEBUGGING is also enabled                               
273      The contents of the back buffer are written into /tmp/backbuffer_* after each primitive 
274      array is drawn.                                                                            */
275 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */                                                                                       
276 #  define SHOW_FRAME_MAKEUP 1
277 # endif  
278   /* The following, when enabled, lets you see the makeup of the all the textures used during each
279      of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
280      The contents of the textures assigned to each stage are written into 
281      /tmp/texture_*_<Stage>.ppm after each primitive array is drawn.                            */
282 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
283 #  define SHOW_TEXTURE_MAKEUP 0
284 # endif  
285 extern BOOL isOn;
286 extern BOOL isDumpingFrames;
287 extern LONG primCounter;
288 #endif
289
290 /*****************************************************************************
291  * Prototypes
292  */
293
294 /* Routine common to the draw primitive and draw indexed primitive routines */
295 void drawPrimitive(IWineD3DDevice *iface,
296                     int PrimitiveType,
297                     long NumPrimitives,
298
299                     /* for Indexed: */
300                     long  StartVertexIndex,
301                     long  StartIdx,
302                     short idxBytes,
303                     const void *idxData,
304                     int   minIndex);
305
306 /*****************************************************************************
307  * Structures required to draw primitives 
308  */
309
310 typedef struct Direct3DStridedData {
311     BYTE     *lpData;        /* Pointer to start of data               */
312     DWORD     dwStride;      /* Stride between occurances of this data */
313     DWORD     dwType;        /* Type (as in D3DVSDT_TYPE)              */
314 } Direct3DStridedData;
315
316 typedef struct Direct3DVertexStridedData {
317     union {
318         struct {
319              Direct3DStridedData  position;
320              Direct3DStridedData  blendWeights;
321              Direct3DStridedData  blendMatrixIndices;
322              Direct3DStridedData  normal;
323              Direct3DStridedData  pSize;
324              Direct3DStridedData  diffuse;
325              Direct3DStridedData  specular;
326              Direct3DStridedData  texCoords[MAX_TEXTURES];
327         } s;
328         Direct3DStridedData input[16];  /* Indexed by constants in D3DVSDE_REGISTER */
329     } u;
330 } Direct3DVertexStridedData;
331
332 /*****************************************************************************
333  * Internal representation of a light
334  */
335 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
336 struct PLIGHTINFOEL {
337     WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
338     DWORD        OriginalIndex;
339     LONG         glIndex;
340     BOOL         lightEnabled;
341     BOOL         changed;
342     BOOL         enabledChanged;
343
344     /* Converted parms to speed up swapping lights */
345     float                         lightPosn[4];
346     float                         lightDirn[4];
347     float                         exponent;
348     float                         cutoff;
349
350     PLIGHTINFOEL *next;
351     PLIGHTINFOEL *prev;
352 };
353
354 /*****************************************************************************
355  * IWineD3D implementation structure
356  */
357 typedef struct IWineD3DImpl
358 {
359     /* IUnknown fields */
360     const IWineD3DVtbl     *lpVtbl;
361     DWORD                   ref;     /* Note: Ref counting not required */
362
363     /* WineD3D Information */
364     IUnknown               *parent;
365     UINT                    dxVersion;
366
367     /* GL Information */
368     BOOL                    isGLInfoValid;
369     WineD3D_GL_Info         gl_info;
370 } IWineD3DImpl;
371
372 extern const IWineD3DVtbl IWineD3D_Vtbl;
373
374
375 /** Hacked out start of a context manager!! **/
376 typedef struct glContext {
377     int Width;
378     int Height;
379     int usedcount;
380     GLXContext context;
381
382     Drawable drawable;
383     IWineD3DSurface *pSurface;
384 #if 0 /* TODO: someway to represent the state of the context */
385     IWineD3DStateBlock *pStateBlock;
386 #endif
387 /* a few other things like format */
388 } glContext;
389
390 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
391 (since it will break quite a few things until contexts are managed properly!) */
392 extern BOOL pbuffer_support;
393 /* allocate one pbuffer per surface */
394 extern BOOL pbuffer_per_surface;
395
396 /* Maximum number of contexts/pbuffers to keep in cache,
397 set to 100 because ATI's drivers don't support deleting pBuffers properly
398 this needs to be migrated to a list and some option availalbe for controle the cache size.
399 */
400 #define CONTEXT_CACHE 100
401
402
403 /*****************************************************************************
404  * IWineD3DDevice implementation structure
405  */
406 typedef struct IWineD3DDeviceImpl
407 {
408     /* IUnknown fields      */
409     const IWineD3DDeviceVtbl *lpVtbl;
410     DWORD                   ref;     /* Note: Ref counting not required */
411
412     /* WineD3D Information  */
413     IUnknown               *parent;
414     IWineD3D               *wineD3D;
415
416     /* X and GL Information */
417     GLint                   maxConcurrentLights;
418
419     /* Optimization */
420     BOOL                    modelview_valid;
421     BOOL                    proj_valid;
422     BOOL                    view_ident;        /* true iff view matrix is identity                */
423     BOOL                    last_was_rhw;      /* true iff last draw_primitive was in xyzrhw mode */
424     GLenum                  tracking_parm;     /* Which source is tracking current colour         */
425     LONG                    tracking_color;    /* used iff GL_COLOR_MATERIAL was enabled          */
426 #define                         DISABLED_TRACKING  0  /* Disabled                                 */
427 #define                         IS_TRACKING        1  /* tracking_parm is tracking diffuse color  */
428 #define                         NEEDS_TRACKING     2  /* Tracking needs to be enabled when needed */
429 #define                         NEEDS_DISABLE      3  /* Tracking needs to be disabled when needed*/
430     UINT                    srcBlend;
431     UINT                    dstBlend;
432     UINT                    alphafunc;
433     UINT                    stencilfunc;
434     BOOL                    texture_shader_active;  /* TODO: Confirm use is correct */
435
436     /* State block related */
437     BOOL                    isRecordingState;
438     IWineD3DStateBlockImpl *stateBlock;
439     IWineD3DStateBlockImpl *updateStateBlock;
440
441     /* Internal use fields  */
442     D3DDEVICE_CREATION_PARAMETERS   createParms;
443     UINT                            adapterNo;
444     D3DDEVTYPE                      devType;
445
446     /* TODO: Replace with a linked list */
447     IWineD3DSwapChain      *swapchains[MAX_SWAPCHAINS]; /* no-one wil ever need more that MAX_SWAPCHAINS swapchains */
448     int                     numberOfSwapChains;
449
450     /* Render Target Support */
451     IWineD3DSurface        *depthStencilBuffer;
452
453     IWineD3DSurface        *renderTarget;
454     IWineD3DSurface        *stencilBufferTarget;
455
456     /* palettes texture management */
457     PALETTEENTRY            palettes[MAX_PALETTES][256];
458     UINT                    currentPalette;
459
460     /* For rendering to a texture using glCopyTexImage */
461     BOOL                    renderUpsideDown;
462
463     /* Cursor management */
464     BOOL                    bCursorVisible;
465     UINT                    xHotSpot;
466     UINT                    yHotSpot;
467     UINT                    xScreenSpace;
468     UINT                    yScreenSpace;
469
470     /* Textures for when no other textures are mapped */
471     UINT                          dummyTextureName[MAX_TEXTURES];
472
473     /* Debug stream management */
474     BOOL                     debug;
475
476     /* Screen buffer resources */
477     glContext contextCache[CONTEXT_CACHE];
478
479     /* A flag to check if endscene has been called before changing the render tartet */
480     BOOL sceneEnded;
481 } IWineD3DDeviceImpl;
482
483 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
484
485 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
486  * anybody uses it for much so a good implementation is optional. */
487 typedef struct PrivateData
488 {
489     struct PrivateData* next;
490
491     GUID tag;
492     DWORD flags; /* DDSPD_* */
493     DWORD uniqueness_value;
494
495     union
496     {
497         LPVOID data;
498         LPUNKNOWN object;
499     } ptr;
500
501     DWORD size;
502 } PrivateData;
503
504 /*****************************************************************************
505  * IWineD3DResource implementation structure
506  */
507 typedef struct IWineD3DResourceClass
508 {
509     /* IUnknown fields */
510     DWORD                   ref;     /* Note: Ref counting not required */
511
512     /* WineD3DResource Information */
513     IUnknown               *parent;
514     D3DRESOURCETYPE         resourceType;
515     IWineD3DDeviceImpl     *wineD3DDevice;
516     D3DPOOL                 pool;
517     UINT                    size;
518     DWORD                   usage;
519     WINED3DFORMAT           format;
520     BYTE                   *allocatedMemory;
521     PrivateData            *privateData;
522
523 } IWineD3DResourceClass;
524
525 typedef struct IWineD3DResourceImpl
526 {
527     /* IUnknown & WineD3DResource Information     */
528     const IWineD3DResourceVtbl *lpVtbl;
529     IWineD3DResourceClass   resource;
530 } IWineD3DResourceImpl;
531
532
533 /*****************************************************************************
534  * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
535  */
536 typedef struct IWineD3DVertexBufferImpl
537 {
538     /* IUnknown & WineD3DResource Information     */
539     const IWineD3DVertexBufferVtbl *lpVtbl;
540     IWineD3DResourceClass     resource;
541
542     /* WineD3DVertexBuffer specifics */
543     DWORD                     fvf;
544
545 } IWineD3DVertexBufferImpl;
546
547 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
548
549
550 /*****************************************************************************
551  * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
552  */
553 typedef struct IWineD3DIndexBufferImpl
554 {
555     /* IUnknown & WineD3DResource Information     */
556     const IWineD3DIndexBufferVtbl *lpVtbl;
557     IWineD3DResourceClass     resource;
558
559     /* WineD3DVertexBuffer specifics */
560 } IWineD3DIndexBufferImpl;
561
562 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
563
564 /*****************************************************************************
565  * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
566  */
567 typedef struct IWineD3DBaseTextureClass
568 {
569     UINT                    levels;
570     BOOL                    dirty;
571     D3DFORMAT               format;
572     DWORD                   usage;
573     UINT                    textureName;    
574     UINT                    LOD;
575     D3DTEXTUREFILTERTYPE    filterType;
576
577 } IWineD3DBaseTextureClass;
578
579 typedef struct IWineD3DBaseTextureImpl
580 {
581     /* IUnknown & WineD3DResource Information     */
582     const IWineD3DBaseTextureVtbl *lpVtbl;
583     IWineD3DResourceClass     resource;
584     IWineD3DBaseTextureClass  baseTexture;
585
586 } IWineD3DBaseTextureImpl;
587
588 /*****************************************************************************
589  * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
590  */
591 typedef struct IWineD3DTextureImpl
592 {
593     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
594     const IWineD3DTextureVtbl *lpVtbl;
595     IWineD3DResourceClass     resource;
596     IWineD3DBaseTextureClass  baseTexture;
597
598     /* IWineD3DTexture */
599     IWineD3DSurface          *surfaces[MAX_LEVELS];
600     
601     UINT                      width;
602     UINT                      height;
603
604 } IWineD3DTextureImpl;
605
606 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
607
608 /*****************************************************************************
609  * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
610  */
611 typedef struct IWineD3DCubeTextureImpl
612 {
613     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
614     const IWineD3DCubeTextureVtbl *lpVtbl;
615     IWineD3DResourceClass     resource;
616     IWineD3DBaseTextureClass  baseTexture;
617
618     /* IWineD3DCubeTexture */
619     IWineD3DSurface          *surfaces[6][MAX_LEVELS];
620
621     UINT                      edgeLength;
622
623 } IWineD3DCubeTextureImpl;
624
625 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
626
627 /*****************************************************************************
628  * IWineD3DVolume implementation structure (extends IUnknown)
629  */
630 typedef struct IWineD3DVolumeImpl
631 {
632     /* IUnknown & WineD3DResource fields */
633     const IWineD3DVolumeVtbl  *lpVtbl;
634     IWineD3DResourceClass      resource;
635
636     /* WineD3DVolume Information */
637     D3DVOLUME_DESC          currentDesc;
638     IUnknown               *container;
639     UINT                    bytesPerPixel;
640
641     BOOL                    lockable;
642     BOOL                    locked;
643     D3DBOX                  lockedBox;
644     D3DBOX                  dirtyBox;
645     BOOL                    dirty;
646
647
648 } IWineD3DVolumeImpl;
649
650 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
651
652 /*****************************************************************************
653  * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
654  */
655 typedef struct IWineD3DVolumeTextureImpl
656 {
657     /* IUnknown & WineD3DResource/WineD3DBaseTexture Information     */
658     const IWineD3DVolumeTextureVtbl *lpVtbl;
659     IWineD3DResourceClass     resource;
660     IWineD3DBaseTextureClass  baseTexture;
661
662     /* IWineD3DVolumeTexture */
663     IWineD3DVolume           *volumes[MAX_LEVELS];
664
665     UINT                      width;
666     UINT                      height;
667     UINT                      depth;
668 } IWineD3DVolumeTextureImpl;
669
670 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
671
672 typedef struct _WINED3DSURFACET_DESC
673 {
674     D3DMULTISAMPLE_TYPE MultiSampleType;
675     DWORD               MultiSampleQuality;
676     UINT                Width;
677     UINT                Height;
678 } WINED3DSURFACET_DESC;
679
680 /*****************************************************************************
681  * IWineD3DSurface implementation structure
682  */
683 struct IWineD3DSurfaceImpl
684 {
685     /* IUnknown & IWineD3DResource Information     */
686     const IWineD3DSurfaceVtbl *lpVtbl;
687     IWineD3DResourceClass     resource;
688
689     /* IWineD3DSurface fields */
690     IUnknown                 *container;
691     WINED3DSURFACET_DESC      currentDesc;
692
693     UINT                      textureName;
694     UINT                      bytesPerPixel;
695
696     /* TODO: move this off into a management class(maybe!) */
697     BOOL                      nonpow2;
698
699     UINT                      pow2Width;
700     UINT                      pow2Height;
701     UINT                      pow2Size;
702
703     /* precalculated x and y scalings for texture coords */
704     float                     pow2scalingFactorX; /* =  (Width  / pow2Width ) */
705     float                     pow2scalingFactorY; /* =  (Height / pow2Height) */
706
707     BOOL                      lockable;
708     BOOL                      discard;
709     BOOL                      locked;
710     BOOL                      activeLock;
711     
712     RECT                      lockedRect;
713     RECT                      dirtyRect;
714     BOOL                      Dirty;
715     
716     BOOL                      inTexture;
717     BOOL                      inPBuffer;
718
719     glDescriptor              glDescription;
720 };
721
722 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
723
724 /*****************************************************************************
725  * IWineD3DVertexDeclaration implementation structure
726  */
727 typedef struct IWineD3DVertexDeclarationImpl {
728  /* IUnknown  Information     */
729   const IWineD3DVertexDeclarationVtbl *lpVtbl;
730   DWORD                   ref;     /* Note: Ref counting not required */
731
732   IUnknown               *parent;
733   /** precomputed fvf if simple declaration */
734   IWineD3DDeviceImpl     *wineD3DDevice;
735   DWORD   fvf[MAX_STREAMS];
736   DWORD   allFVF;
737
738   /** dx8 compatible Declaration fields */
739   DWORD*  pDeclaration8;
740   DWORD   declaration8Length;
741
742   /** dx9+ */
743   D3DVERTEXELEMENT9* pDeclaration9;
744   UINT               declaration9NumElements;
745 } IWineD3DVertexDeclarationImpl;
746
747 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
748
749 /*****************************************************************************
750  * IWineD3DStateBlock implementation structure
751  */
752
753 /* Internal state Block for Begin/End/Capture/Create/Apply info  */
754 /*   Note: Very long winded but gl Lists are not flexible enough */
755 /*   to resolve everything we need, so doing it manually for now */
756 typedef struct SAVEDSTATES {
757         BOOL                      indices;
758         BOOL                      material;
759         BOOL                      fvf;
760         BOOL                      streamSource[MAX_STREAMS];
761         BOOL                      streamFreq[MAX_STREAMS];
762         BOOL                      textures[MAX_TEXTURES];
763         BOOL                      transform[HIGHEST_TRANSFORMSTATE + 1];
764         BOOL                      viewport;
765         BOOL                      renderState[WINEHIGHEST_RENDER_STATE + 1];
766         BOOL                      textureState[MAX_TEXTURES][HIGHEST_TEXTURE_STATE + 1];
767         BOOL                      clipplane[MAX_CLIPPLANES];
768         BOOL                      samplerState[MAX_SAMPLERS][HIGHEST_SAMPLER_STATE + 1];
769         BOOL                      vertexDecl;
770         BOOL                      pixelShader;
771         BOOL                      vertexShader;
772 } SAVEDSTATES;
773
774 struct IWineD3DStateBlockImpl
775 {
776     /* IUnknown fields */
777     const IWineD3DStateBlockVtbl *lpVtbl;
778     DWORD                     ref;     /* Note: Ref counting not required */
779
780     /* IWineD3DStateBlock information */
781     IUnknown                 *parent;
782     IWineD3DDeviceImpl       *wineD3DDevice;
783     D3DSTATEBLOCKTYPE         blockType;
784
785     /* Array indicating whether things have been set or changed */
786     SAVEDSTATES               changed;
787     SAVEDSTATES               set;
788
789     /* Drawing - Vertex Shader or FVF related */
790     DWORD                     fvf;
791     /* Vertex Shader Declaration */
792     IWineD3DVertexDeclaration* vertexDecl;
793
794     void                     *vertexShader; /* @TODO: Replace void * with IWineD3DVertexShader * */
795
796     /* Stream Source */
797     BOOL                      streamIsUP;
798     UINT                      streamStride[MAX_STREAMS];
799     UINT                      streamOffset[MAX_STREAMS];
800     IWineD3DVertexBuffer     *streamSource[MAX_STREAMS];
801     UINT                      streamFreq[MAX_STREAMS];
802     UINT                      streamFlags[MAX_STREAMS];     /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA  */
803
804     /* Indices */
805     IWineD3DIndexBuffer*      pIndexData;
806     UINT                      baseVertexIndex; /* Note: only used for d3d8 */
807
808     /* Transform */
809     D3DMATRIX                 transforms[HIGHEST_TRANSFORMSTATE + 1];
810
811     /* Lights */
812     PLIGHTINFOEL             *lights; /* NOTE: active GL lights must be front of the chain */
813
814     /* Clipping */
815     double                    clipplane[MAX_CLIPPLANES][4];
816     WINED3DCLIPSTATUS         clip_status;
817
818     /* ViewPort */
819     WINED3DVIEWPORT           viewport;
820
821     /* Material */
822     WINED3DMATERIAL           material;
823
824     /* Pixel Shader */
825     void                     *pixelShader; /* TODO: Replace void * with IWineD3DPixelShader * */
826
827     /* Indexed Vertex Blending */
828     D3DVERTEXBLENDFLAGS       vertex_blend;
829     FLOAT                     tween_factor;
830
831     /* RenderState */
832     DWORD                     renderState[WINEHIGHEST_RENDER_STATE + 1];
833
834     /* Texture */
835     IWineD3DBaseTexture      *textures[MAX_TEXTURES];
836     int                       textureDimensions[MAX_SAMPLERS];
837
838     /* Texture State Stage */
839     DWORD                     textureState[MAX_TEXTURES][HIGHEST_TEXTURE_STATE + 1];
840     /* Sampler States */
841     DWORD                     samplerState[MAX_SAMPLERS][HIGHEST_SAMPLER_STATE + 1];
842
843 };
844
845 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
846
847 /*****************************************************************************
848  * IWineD3DQueryImpl implementation structure (extends IUnknown)
849  */
850 typedef struct IWineD3DQueryImpl
851 {
852     const IWineD3DQueryVtbl  *lpVtbl;
853     DWORD                     ref;     /* Note: Ref counting not required */
854     
855     IUnknown                 *parent;
856     /*TODO: replace with iface usage */
857 #if 0
858     IWineD3DDevice         *wineD3DDevice;
859 #else
860     IWineD3DDeviceImpl       *wineD3DDevice;
861 #endif
862     /* IWineD3DQuery fields */
863
864     D3DQUERYTYPE              type;
865     void                     *extendedData;
866     
867   
868 } IWineD3DQueryImpl;
869
870 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
871
872 /*****************************************************************************
873  * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
874  */
875
876 typedef struct IWineD3DSwapChainImpl
877 {
878     /*IUnknown part*/
879     IWineD3DSwapChainVtbl    *lpVtbl;
880     DWORD                     ref;     /* Note: Ref counting not required */
881
882     IUnknown                 *parent;
883     IWineD3DDeviceImpl       *wineD3DDevice;
884
885     /* IWineD3DSwapChain fields */
886     IWineD3DSurface          *backBuffer;
887     IWineD3DSurface          *frontBuffer;
888     BOOL                      wantsDepthStencilBuffer;
889     D3DPRESENT_PARAMETERS     presentParms;
890
891     /* TODO: move everything upto drawable off into a context manager
892       and store the 'data' in the contextManagerData interface.
893     IUnknown                  *contextManagerData;
894     */
895
896     HWND                    win_handle;
897     Window                  win;
898     Display                *display;
899
900     GLXContext              glCtx;
901     XVisualInfo            *visInfo;
902     GLXContext              render_ctx;
903     /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
904     Drawable                drawable;
905 } IWineD3DSwapChainImpl;
906
907 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
908
909 /*****************************************************************************
910  * Utility function prototypes 
911  */
912
913 /* Trace routines */
914 const char* debug_d3dformat(WINED3DFORMAT fmt);
915 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
916 const char* debug_d3dresourcetype(D3DRESOURCETYPE res);
917 const char* debug_d3dusage(DWORD usage);
918 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
919 const char* debug_d3drenderstate(DWORD state);
920 const char* debug_d3dtexturestate(DWORD state);
921 const char* debug_d3dpool(D3DPOOL pool);
922
923 /* Routines for GL <-> D3D values */
924 GLenum StencilOp(DWORD op);
925 void   set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
926 void   set_texture_matrix(const float *smat, DWORD flags);
927 void   GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
928
929 SHORT  D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
930 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
931 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
932 GLint  D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
933
934 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
935
936
937 /*****************************************************************************
938  * To enable calling of inherited functions, requires prototypes 
939  *
940  * Note: Only require classes which are subclassed, ie resource, basetexture, 
941  */
942     /*** IUnknown methods ***/
943     extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
944     extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
945     extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
946     /*** IWineD3DResource methods ***/
947     extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
948     extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
949     extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
950     extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
951     extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID  refguid);
952     extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD  PriorityNew);
953     extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
954     extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
955     extern D3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
956     /*** class static members ***/
957     void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
958
959     /*** IUnknown methods ***/
960     extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
961     extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
962     extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
963     /*** IWineD3DResource methods ***/
964     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
965     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
966     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, CONST void * pData, DWORD  SizeOfData, DWORD  Flags);
967     extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid, void * pData, DWORD * pSizeOfData);
968     extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID  refguid);
969     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD  PriorityNew);
970     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
971     extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
972     extern D3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
973     /*** IWineD3DBaseTexture methods ***/
974     extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
975     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
976     extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
977     extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, D3DTEXTUREFILTERTYPE FilterType);
978     extern D3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
979     extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
980     extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
981     extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
982     extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
983     extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
984     /*** class static members ***/
985     void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
986
987 /*****************************************************************************
988  * IDirect3DVertexShader implementation structure
989  */
990 typedef struct IWineD3DVertexShaderImpl {
991     /* IUnknown parts*/   
992     const IWineD3DVertexShaderVtbl *lpVtbl;
993     DWORD                       ref;     /* Note: Ref counting not required */
994
995     IUnknown                    *parent;
996     IWineD3DDeviceImpl          *wineD3DDevice;
997
998     /* IWineD3DVertexShaderImpl*/
999     CONST DWORD                 *function;
1000     UINT                         functionLength;
1001
1002 #if 0 /* needs reworking */
1003     DWORD usage;
1004     DWORD version;
1005     /* run time datas */
1006     VSHADERDATA* data;
1007     VSHADERINPUTDATA input;
1008     VSHADEROUTPUTDATA output;
1009 #endif
1010 } IWineD3DVertexShaderImpl;
1011 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1012
1013 /*****************************************************************************
1014  * IDirect3DPixelShader implementation structure
1015  */
1016 typedef struct IWineD3DPixelShaderImpl {
1017     /* IUnknown parts*/   
1018     const IWineD3DPixelShaderVtbl *lpVtbl;
1019     DWORD                       ref;     /* Note: Ref counting not required */
1020     
1021     IUnknown                   *parent;
1022     IWineD3DDeviceImpl         *wineD3DDevice;
1023
1024     
1025     /* IWineD3DPixelShaderImpl*/
1026     CONST DWORD                *function;
1027     UINT                        functionLength;
1028
1029 #if 0 /* needs reworking */
1030     UINT functionLength;
1031     DWORD version;
1032     /* run time datas */
1033     PSHADERDATA* data;
1034     PSHADERINPUTDATA input;
1035     PSHADEROUTPUTDATA output;
1036 #endif
1037 } IWineD3DPixelShaderImpl;
1038
1039 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1040 #endif