2 * Direct3D wine internal private include file
4 * Copyright 2002-2003 The wine-d3d team
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2004 Jason Edmeades
7 * Copyright 2005 Oliver Stieber
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.
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.
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
24 #ifndef __WINE_WINED3D_PRIVATE_H
25 #define __WINE_WINED3D_PRIVATE_H
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
41 #include "d3d9types.h"
42 #include "wine/wined3d_interface.h"
43 #include "wine/wined3d_gl.h"
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
54 #define MAX_VSHADER_CONSTANTS 96
55 #define MAX_PSHADER_CONSTANTS 32
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
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];
72 typedef enum _WINELOOKUP {
73 WINELOOKUP_WARPPARAM = 0,
74 WINELOOKUP_MAGFILTER = 1,
78 extern int minLookup[MAX_LOOKUPS];
79 extern int maxLookup[MAX_LOOKUPS];
80 extern DWORD *stateLookup[MAX_LOOKUPS];
82 extern DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
84 /* NOTE: Make sure these are in the correct numerical order. (see /include/d3d9types.h typedef enum _D3DDECLTYPE) */
85 UINT static const glTypeLookup[D3DDECLTYPE_UNUSED][5] = {
86 {D3DDECLTYPE_FLOAT1, 1, GL_FLOAT , GL_FALSE ,sizeof(float)},
87 {D3DDECLTYPE_FLOAT2, 2, GL_FLOAT , GL_FALSE ,sizeof(float)},
88 {D3DDECLTYPE_FLOAT3, 3, GL_FLOAT , GL_FALSE ,sizeof(float)},
89 {D3DDECLTYPE_FLOAT4, 4, GL_FLOAT , GL_FALSE ,sizeof(float)},
90 {D3DDECLTYPE_D3DCOLOR, 4, GL_UNSIGNED_BYTE , GL_TRUE ,sizeof(BYTE)},
91 {D3DDECLTYPE_UBYTE4, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
92 {D3DDECLTYPE_SHORT2, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
93 {D3DDECLTYPE_SHORT4, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
94 {D3DDECLTYPE_UBYTE4N, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
95 {D3DDECLTYPE_SHORT2N, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
96 {D3DDECLTYPE_SHORT4N, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
97 {D3DDECLTYPE_USHORT2N, 2, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
98 {D3DDECLTYPE_USHORT4N, 4, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
99 {D3DDECLTYPE_UDEC3, 3, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
100 {D3DDECLTYPE_DEC3N, 3, GL_SHORT , GL_FALSE ,sizeof(short int)},
101 {D3DDECLTYPE_FLOAT16_2, 2, GL_FLOAT , GL_FALSE ,sizeof(short int)},
102 {D3DDECLTYPE_FLOAT16_4, 4, GL_FLOAT , GL_FALSE ,sizeof(short int)}};
104 #define WINED3D_ATR_TYPE(_attribute) glTypeLookup[sd->u.s._attribute.dwType][0]
105 #define WINED3D_ATR_SIZE(_attribute) glTypeLookup[sd->u.s._attribute.dwType][1]
106 #define WINED3D_ATR_GLTYPE(_attribute) glTypeLookup[sd->u.s._attribute.dwType][2]
107 #define WINED3D_ATR_NORMALIZED(_attribute) glTypeLookup[sd->u.s._attribute.dwType][3]
108 #define WINED3D_ATR_TYPESIZE(_attribute) glTypeLookup[sd->u.s._attribute.dwType][4]
126 typedef struct wined3d_settings_s {
127 /* vertex and pixel shader modes */
131 /* nonpower 2 function */
133 } wined3d_settings_t;
135 extern wined3d_settings_t wined3d_settings;
139 extern void (*wine_tsx11_lock_ptr)(void);
140 extern void (*wine_tsx11_unlock_ptr)(void);
142 /* As GLX relies on X, this is needed */
146 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
147 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
149 #define ENTER_GL() wine_tsx11_lock_ptr()
150 #define LEAVE_GL() wine_tsx11_unlock_ptr()
153 /*****************************************************************************
157 /* GL related defines */
158 /* ------------------ */
159 #define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
160 #define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
161 #define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
162 #define GL_VEND(_VendName) (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
164 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
165 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
166 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
167 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
169 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
170 #define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
171 #define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
172 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
174 #define D3DCOLORTOGLFLOAT4(dw, vec) \
175 (vec)[0] = D3DCOLOR_R(dw); \
176 (vec)[1] = D3DCOLOR_G(dw); \
177 (vec)[2] = D3DCOLOR_B(dw); \
178 (vec)[3] = D3DCOLOR_A(dw);
180 /* Note: The following is purely to keep the source code as clear from #ifdefs as possible */
181 #if defined(GL_VERSION_1_3)
182 #define GLACTIVETEXTURE(textureNo) \
183 glActiveTexture(GL_TEXTURE0 + textureNo); \
184 checkGLcall("glActiveTexture");
185 #define GLCLIENTACTIVETEXTURE(textureNo) \
186 glClientActiveTexture(GL_TEXTURE0 + textureNo);
187 #define GLMULTITEXCOORD1F(a,b) \
188 glMultiTexCoord1f(GL_TEXTURE0 + a, b);
189 #define GLMULTITEXCOORD2F(a,b,c) \
190 glMultiTexCoord2f(GL_TEXTURE0 + a, b, c);
191 #define GLMULTITEXCOORD3F(a,b,c,d) \
192 glMultiTexCoord3f(GL_TEXTURE0 + a, b, c, d);
193 #define GLMULTITEXCOORD4F(a,b,c,d,e) \
194 glMultiTexCoord4f(GL_TEXTURE0 + a, b, c, d, e);
195 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP
197 #define GLACTIVETEXTURE(textureNo) \
198 glActiveTextureARB(GL_TEXTURE0_ARB + textureNo); \
199 checkGLcall("glActiveTextureARB");
200 #define GLCLIENTACTIVETEXTURE(textureNo) \
201 glClientActiveTextureARB(GL_TEXTURE0_ARB + textureNo);
202 #define GLMULTITEXCOORD1F(a,b) \
203 glMultiTexCoord1fARB(GL_TEXTURE0_ARB + a, b);
204 #define GLMULTITEXCOORD2F(a,b,c) \
205 glMultiTexCoord2fARB(GL_TEXTURE0_ARB + a, b, c);
206 #define GLMULTITEXCOORD3F(a,b,c,d) \
207 glMultiTexCoord3fARB(GL_TEXTURE0_ARB + a, b, c, d);
208 #define GLMULTITEXCOORD4F(a,b,c,d,e) \
209 glMultiTexCoord4fARB(GL_TEXTURE0_ARB + a, b, c, d, e);
210 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP_ARB
213 /* DirectX Device Limits */
214 /* --------------------- */
215 #define MAX_LEVELS 256 /* Maximum number of mipmap levels. Guessed at 256 */
217 #define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
218 See MaxStreams in MSDN under GetDeviceCaps */
219 /* Maximum number of constants provided to the shaders */
220 #define HIGHEST_TRANSFORMSTATE 512
221 /* Highest value in D3DTRANSFORMSTATETYPE */
222 #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
224 #define MAX_PALETTES 256
226 /* Checking of API calls */
227 /* --------------------- */
228 #define checkGLcall(A) \
230 GLint err = glGetError(); \
231 if (err != GL_NO_ERROR) { \
232 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
234 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
238 /* Trace routines / diagnostics */
239 /* ---------------------------- */
241 /* Dump out a matrix and copy it */
242 #define conv_mat(mat,gl_mat) \
244 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
245 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
246 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
247 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
248 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
251 /* Macro to dump out the current state of the light chain */
252 #define DUMP_LIGHT_CHAIN() \
254 PLIGHTINFOEL *el = This->stateBlock->lights;\
256 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
261 /* Trace vector and strided data information */
262 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
263 #define TRACE_STRIDED(sd,name) TRACE( #name "=(data:%p, stride:%ld, type:%ld)\n", sd->u.s.name.lpData, sd->u.s.name.dwStride, sd->u.s.name.dwType);
265 /* Defines used for optimizations */
267 /* Only reapply what is necessary */
268 #define REAPPLY_ALPHAOP 0x0001
269 #define REAPPLY_ALL 0xFFFF
271 /* Advance declaration of structures to satisfy compiler */
272 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
273 typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
277 /* TODO: Move some of this to the device */
278 long globalChangeGlRam(long glram);
280 /* Memory and object tracking */
282 /*Structure for holding information on all direct3d objects
283 useful for making sure tracking is ok and when release is called on a device!
284 and probably quite handy for debugging and dumping states out
286 typedef struct WineD3DGlobalStatistics {
287 int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
288 } WineD3DGlobalStatistics;
290 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
292 /* Global variables */
293 extern const float identity[16];
295 /*****************************************************************************
296 * Compilable extra diagnostics
299 /* Trace information per-vertex: (extremely high amount of trace) */
300 #if 0 /* NOTE: Must be 0 in cvs */
301 # define VTRACE(A) TRACE A
306 /* Checking of per-vertex related GL calls */
307 #define vcheckGLcall(A) \
309 GLint err = glGetError(); \
310 if (err != GL_NO_ERROR) { \
311 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
313 VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
317 /* TODO: Confirm each of these works when wined3d move completed */
318 #if 0 /* NOTE: Must be 0 in cvs */
319 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
320 of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
321 is enabled, and if it doesn't exists it is disabled. */
322 # define FRAME_DEBUGGING
323 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
324 the file is deleted */
325 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
326 # define SINGLE_FRAME_DEBUGGING
328 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
329 It can only be enabled when FRAME_DEBUGGING is also enabled
330 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
332 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
333 # define SHOW_FRAME_MAKEUP 1
335 /* The following, when enabled, lets you see the makeup of the all the textures used during each
336 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
337 The contents of the textures assigned to each stage are written into
338 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
339 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
340 # define SHOW_TEXTURE_MAKEUP 0
343 extern BOOL isDumpingFrames;
344 extern LONG primCounter;
347 /*****************************************************************************
351 /* Routine common to the draw primitive and draw indexed primitive routines */
352 void drawPrimitive(IWineD3DDevice *iface,
356 long StartVertexIndex,
357 UINT numberOfVertices,
363 /*****************************************************************************
364 * Structures required to draw primitives
367 typedef struct Direct3DStridedData {
368 BYTE *lpData; /* Pointer to start of data */
369 DWORD dwStride; /* Stride between occurances of this data */
370 DWORD dwType; /* Type (as in D3DVSDT_TYPE) */
371 } Direct3DStridedData;
373 typedef struct Direct3DVertexStridedData {
376 Direct3DStridedData position;
377 Direct3DStridedData blendWeights;
378 Direct3DStridedData blendMatrixIndices;
379 Direct3DStridedData normal;
380 Direct3DStridedData pSize;
381 Direct3DStridedData diffuse;
382 Direct3DStridedData specular;
383 Direct3DStridedData texCoords[MAX_TEXTURES];
384 Direct3DStridedData position2; /* tween data */
385 Direct3DStridedData normal2; /* tween data */
386 Direct3DStridedData tangent;
387 Direct3DStridedData binormal;
388 Direct3DStridedData tessFactor;
389 Direct3DStridedData fog;
390 Direct3DStridedData depth;
391 Direct3DStridedData sample;
393 Direct3DStridedData input[16]; /* Indexed by constants in D3DVSDE_REGISTER */
395 } Direct3DVertexStridedData;
397 /*****************************************************************************
398 * Internal representation of a light
400 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
401 struct PLIGHTINFOEL {
402 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
409 /* Converted parms to speed up swapping lights */
419 /*****************************************************************************
420 * IWineD3D implementation structure
422 typedef struct IWineD3DImpl
424 /* IUnknown fields */
425 const IWineD3DVtbl *lpVtbl;
426 LONG ref; /* Note: Ref counting not required */
428 /* WineD3D Information */
434 WineD3D_GL_Info gl_info;
437 extern const IWineD3DVtbl IWineD3D_Vtbl;
439 typedef struct SwapChainList {
440 IWineD3DSwapChain *swapchain;
441 struct SwapChainList *next;
444 /** Hacked out start of a context manager!! **/
445 typedef struct glContext {
452 IWineD3DSurface *pSurface;
453 #if 0 /* TODO: someway to represent the state of the context */
454 IWineD3DStateBlock *pStateBlock;
456 /* a few other things like format */
459 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
460 (since it will break quite a few things until contexts are managed properly!) */
461 extern BOOL pbuffer_support;
462 /* allocate one pbuffer per surface */
463 extern BOOL pbuffer_per_surface;
465 /* Maximum number of contexts/pbuffers to keep in cache,
466 set to 100 because ATI's drivers don't support deleting pBuffers properly
467 this needs to be migrated to a list and some option availalbe for controle the cache size.
469 #define CONTEXT_CACHE 100
471 typedef struct ResourceList {
472 IWineD3DResource *resource;
473 struct ResourceList *next;
476 /*****************************************************************************
477 * IWineD3DDevice implementation structure
479 typedef struct IWineD3DDeviceImpl
481 /* IUnknown fields */
482 const IWineD3DDeviceVtbl *lpVtbl;
483 LONG ref; /* Note: Ref counting not required */
485 /* WineD3D Information */
489 /* X and GL Information */
490 GLint maxConcurrentLights;
493 BOOL modelview_valid;
495 BOOL view_ident; /* true iff view matrix is identity */
496 BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
497 BOOL viewport_changed; /* Was the viewport changed since the last draw? */
498 GLenum tracking_parm; /* Which source is tracking current colour */
499 LONG tracking_color; /* used iff GL_COLOR_MATERIAL was enabled */
500 #define DISABLED_TRACKING 0 /* Disabled */
501 #define IS_TRACKING 1 /* tracking_parm is tracking diffuse color */
502 #define NEEDS_TRACKING 2 /* Tracking needs to be enabled when needed */
503 #define NEEDS_DISABLE 3 /* Tracking needs to be disabled when needed*/
508 BOOL texture_shader_active; /* TODO: Confirm use is correct */
510 /* State block related */
511 BOOL isRecordingState;
512 IWineD3DStateBlockImpl *stateBlock;
513 IWineD3DStateBlockImpl *updateStateBlock;
515 /* Internal use fields */
516 D3DDEVICE_CREATION_PARAMETERS createParms;
520 SwapChainList *swapchains;
522 ResourceList *resources; /* a linked list to track resources created by the device */
524 /* Render Target Support */
525 IWineD3DSurface *depthStencilBuffer;
527 IWineD3DSurface *renderTarget;
528 IWineD3DSurface *stencilBufferTarget;
530 /* palettes texture management */
531 PALETTEENTRY palettes[MAX_PALETTES][256];
534 /* For rendering to a texture using glCopyTexImage */
535 BOOL renderUpsideDown;
537 /* Cursor management */
544 /* Textures for when no other textures are mapped */
545 UINT dummyTextureName[MAX_TEXTURES];
547 /* Debug stream management */
550 /* Device state management */
553 /* Screen buffer resources */
554 glContext contextCache[CONTEXT_CACHE];
556 /* A flag to check if endscene has been called before changing the render tartet */
559 /* process vertex shaders using software or hardware */
560 BOOL softwareVertexProcessing;
562 } IWineD3DDeviceImpl;
564 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
566 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
567 * anybody uses it for much so a good implementation is optional. */
568 typedef struct PrivateData
570 struct PrivateData* next;
573 DWORD flags; /* DDSPD_* */
574 DWORD uniqueness_value;
585 /*****************************************************************************
586 * IWineD3DResource implementation structure
588 typedef struct IWineD3DResourceClass
590 /* IUnknown fields */
591 LONG ref; /* Note: Ref counting not required */
593 /* WineD3DResource Information */
595 D3DRESOURCETYPE resourceType;
596 IWineD3DDeviceImpl *wineD3DDevice;
600 WINED3DFORMAT format;
601 BYTE *allocatedMemory;
602 PrivateData *privateData;
604 } IWineD3DResourceClass;
606 typedef struct IWineD3DResourceImpl
608 /* IUnknown & WineD3DResource Information */
609 const IWineD3DResourceVtbl *lpVtbl;
610 IWineD3DResourceClass resource;
611 } IWineD3DResourceImpl;
614 /*****************************************************************************
615 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
617 typedef struct IWineD3DVertexBufferImpl
619 /* IUnknown & WineD3DResource Information */
620 const IWineD3DVertexBufferVtbl *lpVtbl;
621 IWineD3DResourceClass resource;
623 /* WineD3DVertexBuffer specifics */
626 } IWineD3DVertexBufferImpl;
628 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
631 /*****************************************************************************
632 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
634 typedef struct IWineD3DIndexBufferImpl
636 /* IUnknown & WineD3DResource Information */
637 const IWineD3DIndexBufferVtbl *lpVtbl;
638 IWineD3DResourceClass resource;
640 /* WineD3DVertexBuffer specifics */
641 } IWineD3DIndexBufferImpl;
643 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
645 /*****************************************************************************
646 * IWineD3DBaseTexture D3D- > openGL state map lookups
648 #define WINED3DFUNC_NOTSUPPORTED -2
649 #define WINED3DFUNC_UNIMPLEMENTED -1
651 typedef enum winetexturestates {
652 WINED3DTEXSTA_ADDRESSU = 0,
653 WINED3DTEXSTA_ADDRESSV = 1,
654 WINED3DTEXSTA_ADDRESSW = 2,
655 WINED3DTEXSTA_BORDERCOLOR = 3,
656 WINED3DTEXSTA_MAGFILTER = 4,
657 WINED3DTEXSTA_MINFILTER = 5,
658 WINED3DTEXSTA_MIPFILTER = 6,
659 WINED3DTEXSTA_MAXMIPLEVEL = 7,
660 WINED3DTEXSTA_MAXANISOTROPY = 8,
661 WINED3DTEXSTA_SRGBTEXTURE = 9,
662 WINED3DTEXSTA_ELEMENTINDEX = 10,
663 WINED3DTEXSTA_DMAPOFFSET = 11,
664 WINED3DTEXSTA_TSSADDRESSW = 12,
665 MAX_WINETEXTURESTATES = 13,
668 typedef struct Wined3dTextureStateMap {
671 } Wined3dTextureStateMap;
673 /*****************************************************************************
674 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
676 typedef struct IWineD3DBaseTextureClass
684 D3DTEXTUREFILTERTYPE filterType;
685 DWORD states[MAX_WINETEXTURESTATES];
687 } IWineD3DBaseTextureClass;
689 typedef struct IWineD3DBaseTextureImpl
691 /* IUnknown & WineD3DResource Information */
692 const IWineD3DBaseTextureVtbl *lpVtbl;
693 IWineD3DResourceClass resource;
694 IWineD3DBaseTextureClass baseTexture;
696 } IWineD3DBaseTextureImpl;
698 /*****************************************************************************
699 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
701 typedef struct IWineD3DTextureImpl
703 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
704 const IWineD3DTextureVtbl *lpVtbl;
705 IWineD3DResourceClass resource;
706 IWineD3DBaseTextureClass baseTexture;
708 /* IWineD3DTexture */
709 IWineD3DSurface *surfaces[MAX_LEVELS];
713 float pow2scalingFactorX;
714 float pow2scalingFactorY;
716 } IWineD3DTextureImpl;
718 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
720 /*****************************************************************************
721 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
723 typedef struct IWineD3DCubeTextureImpl
725 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
726 const IWineD3DCubeTextureVtbl *lpVtbl;
727 IWineD3DResourceClass resource;
728 IWineD3DBaseTextureClass baseTexture;
730 /* IWineD3DCubeTexture */
731 IWineD3DSurface *surfaces[6][MAX_LEVELS];
734 float pow2scalingFactor;
736 } IWineD3DCubeTextureImpl;
738 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
740 /*****************************************************************************
741 * IWineD3DVolume implementation structure (extends IUnknown)
743 typedef struct IWineD3DVolumeImpl
745 /* IUnknown & WineD3DResource fields */
746 const IWineD3DVolumeVtbl *lpVtbl;
747 IWineD3DResourceClass resource;
749 /* WineD3DVolume Information */
750 D3DVOLUME_DESC currentDesc;
751 IWineD3DBase *container;
761 } IWineD3DVolumeImpl;
763 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
765 /*****************************************************************************
766 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
768 typedef struct IWineD3DVolumeTextureImpl
770 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
771 const IWineD3DVolumeTextureVtbl *lpVtbl;
772 IWineD3DResourceClass resource;
773 IWineD3DBaseTextureClass baseTexture;
775 /* IWineD3DVolumeTexture */
776 IWineD3DVolume *volumes[MAX_LEVELS];
781 } IWineD3DVolumeTextureImpl;
783 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
785 typedef struct _WINED3DSURFACET_DESC
787 D3DMULTISAMPLE_TYPE MultiSampleType;
788 DWORD MultiSampleQuality;
791 } WINED3DSURFACET_DESC;
793 /*****************************************************************************
794 * IWineD3DSurface implementation structure
796 struct IWineD3DSurfaceImpl
798 /* IUnknown & IWineD3DResource Information */
799 const IWineD3DSurfaceVtbl *lpVtbl;
800 IWineD3DResourceClass resource;
802 /* IWineD3DSurface fields */
803 IWineD3DBase *container;
804 WINED3DSURFACET_DESC currentDesc;
809 /* TODO: move this off into a management class(maybe!) */
817 /* precalculated x and y scalings for texture coords */
818 float pow2scalingFactorX; /* = (Width / pow2Width ) */
819 float pow2scalingFactorY; /* = (Height / pow2Height) */
834 glDescriptor glDescription;
837 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
839 /*****************************************************************************
840 * IWineD3DVertexDeclaration implementation structure
842 typedef struct IWineD3DVertexDeclarationImpl {
843 /* IUnknown Information */
844 const IWineD3DVertexDeclarationVtbl *lpVtbl;
845 LONG ref; /* Note: Ref counting not required */
848 /** precomputed fvf if simple declaration */
849 IWineD3DDeviceImpl *wineD3DDevice;
850 DWORD fvf[MAX_STREAMS];
853 /** dx8 compatible Declaration fields */
854 DWORD* pDeclaration8;
855 DWORD declaration8Length;
858 D3DVERTEXELEMENT9 *pDeclaration9;
859 UINT declaration9NumElements;
861 WINED3DVERTEXELEMENT *pDeclarationWine;
862 UINT declarationWNumElements;
866 } IWineD3DVertexDeclarationImpl;
868 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
870 /*****************************************************************************
871 * IWineD3DStateBlock implementation structure
874 /* Internal state Block for Begin/End/Capture/Create/Apply info */
875 /* Note: Very long winded but gl Lists are not flexible enough */
876 /* to resolve everything we need, so doing it manually for now */
877 typedef struct SAVEDSTATES {
881 BOOL streamSource[MAX_STREAMS];
882 BOOL streamFreq[MAX_STREAMS];
883 BOOL textures[MAX_TEXTURES];
884 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
886 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
887 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
888 BOOL samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
889 BOOL clipplane[MAX_CLIPPLANES];
892 BOOL pixelShaderConstants[MAX_PSHADER_CONSTANTS];
894 BOOL vertexShaderConstants[MAX_VSHADER_CONSTANTS];
898 WINESHADERCNST_NONE = 0,
899 WINESHADERCNST_FLOAT = 1,
900 WINESHADERCNST_INTEGER = 2,
901 WINESHADERCNST_BOOL = 3
904 struct IWineD3DStateBlockImpl
906 /* IUnknown fields */
907 const IWineD3DStateBlockVtbl *lpVtbl;
908 LONG ref; /* Note: Ref counting not required */
910 /* IWineD3DStateBlock information */
912 IWineD3DDeviceImpl *wineD3DDevice;
913 WINED3DSTATEBLOCKTYPE blockType;
915 /* Array indicating whether things have been set or changed */
919 /* Drawing - Vertex Shader or FVF related */
921 /* Vertex Shader Declaration */
922 IWineD3DVertexDeclaration *vertexDecl;
924 IWineD3DVertexShader *vertexShader;
926 /* Vertex Shader Constants */
927 BOOL vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
928 INT vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
929 float vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
930 WINESHADERCNST vertexShaderConstantT[MAX_VSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
934 UINT streamStride[MAX_STREAMS];
935 UINT streamOffset[MAX_STREAMS];
936 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
937 UINT streamFreq[MAX_STREAMS];
938 UINT streamFlags[MAX_STREAMS]; /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA */
941 IWineD3DIndexBuffer* pIndexData;
942 UINT baseVertexIndex; /* Note: only used for d3d8 */
945 D3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
948 PLIGHTINFOEL *lights; /* NOTE: active GL lights must be front of the chain */
951 double clipplane[MAX_CLIPPLANES][4];
952 WINED3DCLIPSTATUS clip_status;
955 WINED3DVIEWPORT viewport;
958 WINED3DMATERIAL material;
961 IWineD3DPixelShader *pixelShader;
963 /* Pixel Shader Constants */
964 BOOL pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
965 INT pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
966 float pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
967 WINESHADERCNST pixelShaderConstantT[MAX_PSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
969 /* Indexed Vertex Blending */
970 D3DVERTEXBLENDFLAGS vertex_blend;
974 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
977 IWineD3DBaseTexture *textures[MAX_TEXTURES];
978 int textureDimensions[MAX_SAMPLERS];
980 /* Texture State Stage */
981 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
983 DWORD samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
987 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
989 /*****************************************************************************
990 * IWineD3DQueryImpl implementation structure (extends IUnknown)
992 typedef struct IWineD3DQueryImpl
994 const IWineD3DQueryVtbl *lpVtbl;
995 LONG ref; /* Note: Ref counting not required */
998 /*TODO: replace with iface usage */
1000 IWineD3DDevice *wineD3DDevice;
1002 IWineD3DDeviceImpl *wineD3DDevice;
1004 /* IWineD3DQuery fields */
1007 /* TODO: Think about using a IUnknown instead of a void* */
1011 } IWineD3DQueryImpl;
1013 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1015 /* Datastructures for IWineD3DQueryImpl.extendedData */
1016 typedef struct WineQueryOcclusionData {
1017 unsigned int queryId;
1018 } WineQueryOcclusionData;
1021 /*****************************************************************************
1022 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1025 typedef struct IWineD3DSwapChainImpl
1028 IWineD3DSwapChainVtbl *lpVtbl;
1029 LONG ref; /* Note: Ref counting not required */
1032 IWineD3DDeviceImpl *wineD3DDevice;
1034 /* IWineD3DSwapChain fields */
1035 IWineD3DSurface *backBuffer;
1036 IWineD3DSurface *frontBuffer;
1037 BOOL wantsDepthStencilBuffer;
1038 D3DPRESENT_PARAMETERS presentParms;
1040 /* TODO: move everything up to drawable off into a context manager
1041 and store the 'data' in the contextManagerData interface.
1042 IUnknown *contextManagerData;
1050 XVisualInfo *visInfo;
1051 GLXContext render_ctx;
1052 /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1054 } IWineD3DSwapChainImpl;
1056 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1058 /*****************************************************************************
1059 * Utility function prototypes
1062 /* Trace routines */
1063 const char* debug_d3dformat(WINED3DFORMAT fmt);
1064 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1065 const char* debug_d3dresourcetype(D3DRESOURCETYPE res);
1066 const char* debug_d3dusage(DWORD usage);
1067 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1068 const char* debug_d3drenderstate(DWORD state);
1069 const char* debug_d3dtexturestate(DWORD state);
1070 const char* debug_d3dpool(D3DPOOL pool);
1072 /* Routines for GL <-> D3D values */
1073 GLenum StencilOp(DWORD op);
1074 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1075 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1076 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
1078 SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1079 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1080 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
1081 GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1083 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1086 /*****************************************************************************
1087 * To enable calling of inherited functions, requires prototypes
1089 * Note: Only require classes which are subclassed, ie resource, basetexture,
1091 /*** IUnknown methods ***/
1092 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1093 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1094 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1095 /*** IWineD3DResource methods ***/
1096 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1097 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1098 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1099 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1100 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1101 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1102 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1103 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1104 extern D3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1105 /*** class static members ***/
1106 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1108 /*** IUnknown methods ***/
1109 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1110 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1111 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1112 /*** IWineD3DResource methods ***/
1113 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1114 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1115 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1116 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1117 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1118 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1119 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1120 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1121 extern D3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1122 /*** IWineD3DBaseTexture methods ***/
1123 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1124 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1125 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1126 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, D3DTEXTUREFILTERTYPE FilterType);
1127 extern D3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1128 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1129 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1130 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1132 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset);
1133 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1134 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1135 extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1136 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1137 /*** class static members ***/
1138 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1140 /* An enum for the type of constants that are used... addressing causes
1141 * problems with being able to work out what's used and what's not.. so
1142 * maybe we'll have to rely on the server vertex shader const functions?
1144 enum vsConstantsEnum {
1145 VS_CONSTANT_NOT_USED = 0,
1146 VS_CONSTANT_CONSTANT,
1147 VS_CONSTANT_INTEGER,
1148 VS_CONSTANT_BOOLEAN,
1152 /*****************************************************************************
1153 * IDirect3DVertexShader implementation structure
1155 typedef struct IWineD3DVertexShaderImpl {
1157 const IWineD3DVertexShaderVtbl *lpVtbl;
1158 LONG ref; /* Note: Ref counting not required */
1161 IWineD3DDeviceImpl *wineD3DDevice;
1163 /* IWineD3DVertexShaderImpl */
1164 CONST DWORD *function;
1165 UINT functionLength;
1170 /* vertex declaration array mapping */
1171 BOOL namedArrays; /* don't map use named functions */
1172 BOOL declaredArrays; /* mapping requires */
1173 INT arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE]; /* lookup table for the maps */
1174 INT highestConstant;
1175 CHAR constantsUsedBitmap[256];
1176 /* FIXME: This needs to be populated with some flags of VS_CONSTANT_NOT_USED, VS_CONSTANT_CONSTANT, VS_CONSTANT_INTEGER, VS_CONSTANT_BOOLEAN, VS_CONSTANT_FLOAT, a half byte bitmap will be the best option, but I'll keep it as chards for siplicity */
1177 /* run time datas... */
1180 IWineD3DVertexDeclaration *vertexDeclaration;
1181 #if 0 /* needs reworking */
1182 /* run time datas */
1183 VSHADERINPUTDATA input;
1184 VSHADEROUTPUTDATA output;
1186 } IWineD3DVertexShaderImpl;
1187 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1189 /*****************************************************************************
1190 * IDirect3DPixelShader implementation structure
1192 typedef struct IWineD3DPixelShaderImpl {
1193 /* IUnknown parts */
1194 const IWineD3DPixelShaderVtbl *lpVtbl;
1195 LONG ref; /* Note: Ref counting not required */
1198 IWineD3DDeviceImpl *wineD3DDevice;
1200 /* IWineD3DPixelShaderImpl */
1201 CONST DWORD *function;
1202 UINT functionLength;
1204 CHAR constants[WINED3D_PSHADER_MAX_CONSTANTS];
1210 #if 0 /* needs reworking */
1211 PSHADERINPUTDATA input;
1212 PSHADEROUTPUTDATA output;
1214 } IWineD3DPixelShaderImpl;
1216 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;