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_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
165 #define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
166 #define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
167 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
169 #define D3DCOLORTOGLFLOAT4(dw, vec) \
170 (vec)[0] = D3DCOLOR_R(dw); \
171 (vec)[1] = D3DCOLOR_G(dw); \
172 (vec)[2] = D3DCOLOR_B(dw); \
173 (vec)[3] = D3DCOLOR_A(dw);
175 /* Note: The following is purely to keep the source code as clear from #ifdefs as possible */
176 #if defined(GL_VERSION_1_3)
177 #define GLACTIVETEXTURE(textureNo) \
178 glActiveTexture(GL_TEXTURE0 + textureNo); \
179 checkGLcall("glActiveTexture");
180 #define GLCLIENTACTIVETEXTURE(textureNo) \
181 glClientActiveTexture(GL_TEXTURE0 + textureNo);
182 #define GLMULTITEXCOORD1F(a,b) \
183 glMultiTexCoord1f(GL_TEXTURE0 + a, b);
184 #define GLMULTITEXCOORD2F(a,b,c) \
185 glMultiTexCoord2f(GL_TEXTURE0 + a, b, c);
186 #define GLMULTITEXCOORD3F(a,b,c,d) \
187 glMultiTexCoord3f(GL_TEXTURE0 + a, b, c, d);
188 #define GLMULTITEXCOORD4F(a,b,c,d,e) \
189 glMultiTexCoord4f(GL_TEXTURE0 + a, b, c, d, e);
190 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP
192 #define GLACTIVETEXTURE(textureNo) \
193 glActiveTextureARB(GL_TEXTURE0_ARB + textureNo); \
194 checkGLcall("glActiveTextureARB");
195 #define GLCLIENTACTIVETEXTURE(textureNo) \
196 glClientActiveTextureARB(GL_TEXTURE0_ARB + textureNo);
197 #define GLMULTITEXCOORD1F(a,b) \
198 glMultiTexCoord1fARB(GL_TEXTURE0_ARB + a, b);
199 #define GLMULTITEXCOORD2F(a,b,c) \
200 glMultiTexCoord2fARB(GL_TEXTURE0_ARB + a, b, c);
201 #define GLMULTITEXCOORD3F(a,b,c,d) \
202 glMultiTexCoord3fARB(GL_TEXTURE0_ARB + a, b, c, d);
203 #define GLMULTITEXCOORD4F(a,b,c,d,e) \
204 glMultiTexCoord4fARB(GL_TEXTURE0_ARB + a, b, c, d, e);
205 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP_ARB
208 /* DirectX Device Limits */
209 /* --------------------- */
210 #define MAX_LEVELS 256 /* Maximum number of mipmap levels. Guessed at 256 */
212 #define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
213 See MaxStreams in MSDN under GetDeviceCaps */
214 /* Maximum number of constants provided to the shaders */
215 #define HIGHEST_TRANSFORMSTATE 512
216 /* Highest value in D3DTRANSFORMSTATETYPE */
217 #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
219 #define MAX_PALETTES 256
221 /* Checking of API calls */
222 /* --------------------- */
223 #define checkGLcall(A) \
225 GLint err = glGetError(); \
226 if (err != GL_NO_ERROR) { \
227 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
229 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
233 /* Trace routines / diagnostics */
234 /* ---------------------------- */
236 /* Dump out a matrix and copy it */
237 #define conv_mat(mat,gl_mat) \
239 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
240 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
241 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
242 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
243 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
246 /* Macro to dump out the current state of the light chain */
247 #define DUMP_LIGHT_CHAIN() \
249 PLIGHTINFOEL *el = This->stateBlock->lights;\
251 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
256 /* Trace vector and strided data information */
257 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
258 #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);
260 /* Defines used for optimizations */
262 /* Only reapply what is necessary */
263 #define REAPPLY_ALPHAOP 0x0001
264 #define REAPPLY_ALL 0xFFFF
266 /* Advance declaration of structures to satisfy compiler */
267 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
268 typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
272 /* TODO: Move some of this to the device */
273 long globalChangeGlRam(long glram);
275 /* Memory and object tracking */
277 /*Structure for holding information on all direct3d objects
278 useful for making sure tracking is ok and when release is called on a device!
279 and probably quite handy for debugging and dumping states out
281 typedef struct WineD3DGlobalStatistics {
282 int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
283 } WineD3DGlobalStatistics;
285 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
287 /* Global variables */
288 extern const float identity[16];
290 /*****************************************************************************
291 * Compilable extra diagnostics
294 /* Trace information per-vertex: (extremely high amount of trace) */
295 #if 0 /* NOTE: Must be 0 in cvs */
296 # define VTRACE(A) TRACE A
301 /* Checking of per-vertex related GL calls */
302 #define vcheckGLcall(A) \
304 GLint err = glGetError(); \
305 if (err != GL_NO_ERROR) { \
306 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
308 VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
312 /* TODO: Confirm each of these works when wined3d move completed */
313 #if 0 /* NOTE: Must be 0 in cvs */
314 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
315 of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
316 is enabled, and if it doesn't exists it is disabled. */
317 # define FRAME_DEBUGGING
318 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
319 the file is deleted */
320 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
321 # define SINGLE_FRAME_DEBUGGING
323 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
324 It can only be enabled when FRAME_DEBUGGING is also enabled
325 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
327 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
328 # define SHOW_FRAME_MAKEUP 1
330 /* The following, when enabled, lets you see the makeup of the all the textures used during each
331 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
332 The contents of the textures assigned to each stage are written into
333 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
334 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
335 # define SHOW_TEXTURE_MAKEUP 0
338 extern BOOL isDumpingFrames;
339 extern LONG primCounter;
342 /*****************************************************************************
346 /* Routine common to the draw primitive and draw indexed primitive routines */
347 void drawPrimitive(IWineD3DDevice *iface,
351 long StartVertexIndex,
352 UINT numberOfVertices,
358 /*****************************************************************************
359 * Structures required to draw primitives
362 typedef struct Direct3DStridedData {
363 BYTE *lpData; /* Pointer to start of data */
364 DWORD dwStride; /* Stride between occurances of this data */
365 DWORD dwType; /* Type (as in D3DVSDT_TYPE) */
366 } Direct3DStridedData;
368 typedef struct Direct3DVertexStridedData {
371 Direct3DStridedData position;
372 Direct3DStridedData blendWeights;
373 Direct3DStridedData blendMatrixIndices;
374 Direct3DStridedData normal;
375 Direct3DStridedData pSize;
376 Direct3DStridedData diffuse;
377 Direct3DStridedData specular;
378 Direct3DStridedData texCoords[MAX_TEXTURES];
379 Direct3DStridedData position2; /* tween data */
380 Direct3DStridedData normal2; /* tween data */
381 Direct3DStridedData tangent;
382 Direct3DStridedData binormal;
383 Direct3DStridedData tessFactor;
384 Direct3DStridedData fog;
385 Direct3DStridedData depth;
386 Direct3DStridedData sample;
388 Direct3DStridedData input[16]; /* Indexed by constants in D3DVSDE_REGISTER */
390 } Direct3DVertexStridedData;
392 /*****************************************************************************
393 * Internal representation of a light
395 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
396 struct PLIGHTINFOEL {
397 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
404 /* Converted parms to speed up swapping lights */
414 /*****************************************************************************
415 * IWineD3D implementation structure
417 typedef struct IWineD3DImpl
419 /* IUnknown fields */
420 const IWineD3DVtbl *lpVtbl;
421 LONG ref; /* Note: Ref counting not required */
423 /* WineD3D Information */
429 WineD3D_GL_Info gl_info;
432 extern const IWineD3DVtbl IWineD3D_Vtbl;
434 typedef struct SwapChainList {
435 IWineD3DSwapChain *swapchain;
436 struct SwapChainList *next;
439 /** Hacked out start of a context manager!! **/
440 typedef struct glContext {
447 IWineD3DSurface *pSurface;
448 #if 0 /* TODO: someway to represent the state of the context */
449 IWineD3DStateBlock *pStateBlock;
451 /* a few other things like format */
454 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
455 (since it will break quite a few things until contexts are managed properly!) */
456 extern BOOL pbuffer_support;
457 /* allocate one pbuffer per surface */
458 extern BOOL pbuffer_per_surface;
460 /* Maximum number of contexts/pbuffers to keep in cache,
461 set to 100 because ATI's drivers don't support deleting pBuffers properly
462 this needs to be migrated to a list and some option availalbe for controle the cache size.
464 #define CONTEXT_CACHE 100
466 typedef struct ResourceList {
467 IWineD3DResource *resource;
468 struct ResourceList *next;
471 /*****************************************************************************
472 * IWineD3DDevice implementation structure
474 typedef struct IWineD3DDeviceImpl
476 /* IUnknown fields */
477 const IWineD3DDeviceVtbl *lpVtbl;
478 LONG ref; /* Note: Ref counting not required */
480 /* WineD3D Information */
484 /* X and GL Information */
485 GLint maxConcurrentLights;
488 BOOL modelview_valid;
490 BOOL view_ident; /* true iff view matrix is identity */
491 BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
492 GLenum tracking_parm; /* Which source is tracking current colour */
493 LONG tracking_color; /* used iff GL_COLOR_MATERIAL was enabled */
494 #define DISABLED_TRACKING 0 /* Disabled */
495 #define IS_TRACKING 1 /* tracking_parm is tracking diffuse color */
496 #define NEEDS_TRACKING 2 /* Tracking needs to be enabled when needed */
497 #define NEEDS_DISABLE 3 /* Tracking needs to be disabled when needed*/
502 BOOL texture_shader_active; /* TODO: Confirm use is correct */
504 /* State block related */
505 BOOL isRecordingState;
506 IWineD3DStateBlockImpl *stateBlock;
507 IWineD3DStateBlockImpl *updateStateBlock;
509 /* Internal use fields */
510 D3DDEVICE_CREATION_PARAMETERS createParms;
514 SwapChainList *swapchains;
516 ResourceList *resources; /* a linked list to track resources created by the device */
518 /* Render Target Support */
519 IWineD3DSurface *depthStencilBuffer;
521 IWineD3DSurface *renderTarget;
522 IWineD3DSurface *stencilBufferTarget;
524 /* palettes texture management */
525 PALETTEENTRY palettes[MAX_PALETTES][256];
528 /* For rendering to a texture using glCopyTexImage */
529 BOOL renderUpsideDown;
531 /* Cursor management */
538 /* Textures for when no other textures are mapped */
539 UINT dummyTextureName[MAX_TEXTURES];
541 /* Debug stream management */
544 /* Device state management */
547 /* Screen buffer resources */
548 glContext contextCache[CONTEXT_CACHE];
550 /* A flag to check if endscene has been called before changing the render tartet */
552 } IWineD3DDeviceImpl;
554 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
556 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
557 * anybody uses it for much so a good implementation is optional. */
558 typedef struct PrivateData
560 struct PrivateData* next;
563 DWORD flags; /* DDSPD_* */
564 DWORD uniqueness_value;
575 /*****************************************************************************
576 * IWineD3DResource implementation structure
578 typedef struct IWineD3DResourceClass
580 /* IUnknown fields */
581 LONG ref; /* Note: Ref counting not required */
583 /* WineD3DResource Information */
585 D3DRESOURCETYPE resourceType;
586 IWineD3DDeviceImpl *wineD3DDevice;
590 WINED3DFORMAT format;
591 BYTE *allocatedMemory;
592 PrivateData *privateData;
594 } IWineD3DResourceClass;
596 typedef struct IWineD3DResourceImpl
598 /* IUnknown & WineD3DResource Information */
599 const IWineD3DResourceVtbl *lpVtbl;
600 IWineD3DResourceClass resource;
601 } IWineD3DResourceImpl;
604 /*****************************************************************************
605 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
607 typedef struct IWineD3DVertexBufferImpl
609 /* IUnknown & WineD3DResource Information */
610 const IWineD3DVertexBufferVtbl *lpVtbl;
611 IWineD3DResourceClass resource;
613 /* WineD3DVertexBuffer specifics */
616 } IWineD3DVertexBufferImpl;
618 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
621 /*****************************************************************************
622 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
624 typedef struct IWineD3DIndexBufferImpl
626 /* IUnknown & WineD3DResource Information */
627 const IWineD3DIndexBufferVtbl *lpVtbl;
628 IWineD3DResourceClass resource;
630 /* WineD3DVertexBuffer specifics */
631 } IWineD3DIndexBufferImpl;
633 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
635 /*****************************************************************************
636 * IWineD3DBaseTexture D3D- > openGL state map lookups
638 #define WINED3DFUNC_NOTSUPPORTED -2
639 #define WINED3DFUNC_UNIMPLEMENTED -1
641 typedef enum winetexturestates {
642 WINED3DTEXSTA_ADDRESSU = 0,
643 WINED3DTEXSTA_ADDRESSV = 1,
644 WINED3DTEXSTA_ADDRESSW = 2,
645 WINED3DTEXSTA_BORDERCOLOR = 3,
646 WINED3DTEXSTA_MAGFILTER = 4,
647 WINED3DTEXSTA_MINFILTER = 5,
648 WINED3DTEXSTA_MIPFILTER = 6,
649 WINED3DTEXSTA_MAXMIPLEVEL = 7,
650 WINED3DTEXSTA_MAXANISOTROPY = 8,
651 WINED3DTEXSTA_SRGBTEXTURE = 9,
652 WINED3DTEXSTA_ELEMENTINDEX = 10,
653 WINED3DTEXSTA_DMAPOFFSET = 11,
654 WINED3DTEXSTA_TSSADDRESSW = 12,
655 MAX_WINETEXTURESTATES = 13,
658 typedef struct Wined3dTextureStateMap {
661 } Wined3dTextureStateMap;
663 /*****************************************************************************
664 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
666 typedef struct IWineD3DBaseTextureClass
674 D3DTEXTUREFILTERTYPE filterType;
675 DWORD states[MAX_WINETEXTURESTATES];
677 } IWineD3DBaseTextureClass;
679 typedef struct IWineD3DBaseTextureImpl
681 /* IUnknown & WineD3DResource Information */
682 const IWineD3DBaseTextureVtbl *lpVtbl;
683 IWineD3DResourceClass resource;
684 IWineD3DBaseTextureClass baseTexture;
686 } IWineD3DBaseTextureImpl;
688 /*****************************************************************************
689 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
691 typedef struct IWineD3DTextureImpl
693 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
694 const IWineD3DTextureVtbl *lpVtbl;
695 IWineD3DResourceClass resource;
696 IWineD3DBaseTextureClass baseTexture;
698 /* IWineD3DTexture */
699 IWineD3DSurface *surfaces[MAX_LEVELS];
703 float pow2scalingFactorX;
704 float pow2scalingFactorY;
706 } IWineD3DTextureImpl;
708 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
710 /*****************************************************************************
711 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
713 typedef struct IWineD3DCubeTextureImpl
715 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
716 const IWineD3DCubeTextureVtbl *lpVtbl;
717 IWineD3DResourceClass resource;
718 IWineD3DBaseTextureClass baseTexture;
720 /* IWineD3DCubeTexture */
721 IWineD3DSurface *surfaces[6][MAX_LEVELS];
724 float pow2scalingFactor;
726 } IWineD3DCubeTextureImpl;
728 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
730 /*****************************************************************************
731 * IWineD3DVolume implementation structure (extends IUnknown)
733 typedef struct IWineD3DVolumeImpl
735 /* IUnknown & WineD3DResource fields */
736 const IWineD3DVolumeVtbl *lpVtbl;
737 IWineD3DResourceClass resource;
739 /* WineD3DVolume Information */
740 D3DVOLUME_DESC currentDesc;
751 } IWineD3DVolumeImpl;
753 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
755 /*****************************************************************************
756 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
758 typedef struct IWineD3DVolumeTextureImpl
760 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
761 const IWineD3DVolumeTextureVtbl *lpVtbl;
762 IWineD3DResourceClass resource;
763 IWineD3DBaseTextureClass baseTexture;
765 /* IWineD3DVolumeTexture */
766 IWineD3DVolume *volumes[MAX_LEVELS];
771 } IWineD3DVolumeTextureImpl;
773 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
775 typedef struct _WINED3DSURFACET_DESC
777 D3DMULTISAMPLE_TYPE MultiSampleType;
778 DWORD MultiSampleQuality;
781 } WINED3DSURFACET_DESC;
783 /*****************************************************************************
784 * IWineD3DSurface implementation structure
786 struct IWineD3DSurfaceImpl
788 /* IUnknown & IWineD3DResource Information */
789 const IWineD3DSurfaceVtbl *lpVtbl;
790 IWineD3DResourceClass resource;
792 /* IWineD3DSurface fields */
794 WINED3DSURFACET_DESC currentDesc;
799 /* TODO: move this off into a management class(maybe!) */
807 /* precalculated x and y scalings for texture coords */
808 float pow2scalingFactorX; /* = (Width / pow2Width ) */
809 float pow2scalingFactorY; /* = (Height / pow2Height) */
824 glDescriptor glDescription;
827 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
829 /*****************************************************************************
830 * IWineD3DVertexDeclaration implementation structure
832 typedef struct IWineD3DVertexDeclarationImpl {
833 /* IUnknown Information */
834 const IWineD3DVertexDeclarationVtbl *lpVtbl;
835 LONG ref; /* Note: Ref counting not required */
838 /** precomputed fvf if simple declaration */
839 IWineD3DDeviceImpl *wineD3DDevice;
840 DWORD fvf[MAX_STREAMS];
843 /** dx8 compatible Declaration fields */
844 DWORD* pDeclaration8;
845 DWORD declaration8Length;
848 D3DVERTEXELEMENT9* pDeclaration9;
849 UINT declaration9NumElements;
850 } IWineD3DVertexDeclarationImpl;
852 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
854 /*****************************************************************************
855 * IWineD3DStateBlock implementation structure
858 /* Internal state Block for Begin/End/Capture/Create/Apply info */
859 /* Note: Very long winded but gl Lists are not flexible enough */
860 /* to resolve everything we need, so doing it manually for now */
861 typedef struct SAVEDSTATES {
865 BOOL streamSource[MAX_STREAMS];
866 BOOL streamFreq[MAX_STREAMS];
867 BOOL textures[MAX_TEXTURES];
868 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
870 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
871 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
872 BOOL samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
873 BOOL clipplane[MAX_CLIPPLANES];
876 BOOL pixelShaderConstants[MAX_PSHADER_CONSTANTS];
878 BOOL vertexShaderConstants[MAX_VSHADER_CONSTANTS];
882 WINESHADERCNST_FLOAT = 0,
883 WINESHADERCNST_INTEGER = 1,
884 WINESHADERCNST_BOOL = 2
887 struct IWineD3DStateBlockImpl
889 /* IUnknown fields */
890 const IWineD3DStateBlockVtbl *lpVtbl;
891 LONG ref; /* Note: Ref counting not required */
893 /* IWineD3DStateBlock information */
895 IWineD3DDeviceImpl *wineD3DDevice;
896 WINED3DSTATEBLOCKTYPE blockType;
898 /* Array indicating whether things have been set or changed */
902 /* Drawing - Vertex Shader or FVF related */
904 /* Vertex Shader Declaration */
905 IWineD3DVertexDeclaration *vertexDecl;
907 IWineD3DVertexShader *vertexShader;
909 /* Vertex Shader Constants */
910 BOOL vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
911 INT vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
912 float vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
913 WINESHADERCNST vertexShaderConstantT[MAX_VSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
915 BOOL softwareVertexProcessing;
919 UINT streamStride[MAX_STREAMS];
920 UINT streamOffset[MAX_STREAMS];
921 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
922 UINT streamFreq[MAX_STREAMS];
923 UINT streamFlags[MAX_STREAMS]; /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA */
926 IWineD3DIndexBuffer* pIndexData;
927 UINT baseVertexIndex; /* Note: only used for d3d8 */
930 D3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
933 PLIGHTINFOEL *lights; /* NOTE: active GL lights must be front of the chain */
936 double clipplane[MAX_CLIPPLANES][4];
937 WINED3DCLIPSTATUS clip_status;
940 WINED3DVIEWPORT viewport;
943 WINED3DMATERIAL material;
946 IWineD3DPixelShader *pixelShader;
948 /* Pixel Shader Constants */
949 BOOL pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
950 INT pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
951 float pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
952 WINESHADERCNST pixelShaderConstantT[MAX_PSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
954 /* Indexed Vertex Blending */
955 D3DVERTEXBLENDFLAGS vertex_blend;
959 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
962 IWineD3DBaseTexture *textures[MAX_TEXTURES];
963 int textureDimensions[MAX_SAMPLERS];
965 /* Texture State Stage */
966 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
968 DWORD samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
972 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
974 /*****************************************************************************
975 * IWineD3DQueryImpl implementation structure (extends IUnknown)
977 typedef struct IWineD3DQueryImpl
979 const IWineD3DQueryVtbl *lpVtbl;
980 LONG ref; /* Note: Ref counting not required */
983 /*TODO: replace with iface usage */
985 IWineD3DDevice *wineD3DDevice;
987 IWineD3DDeviceImpl *wineD3DDevice;
989 /* IWineD3DQuery fields */
992 /* TODO: Think about using a IUnknown instead of a void* */
998 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1000 /* Datastructures for IWineD3DQueryImpl.extendedData */
1001 typedef struct WineQueryOcclusionData {
1002 unsigned int queryId;
1003 } WineQueryOcclusionData;
1006 /*****************************************************************************
1007 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1010 typedef struct IWineD3DSwapChainImpl
1013 IWineD3DSwapChainVtbl *lpVtbl;
1014 LONG ref; /* Note: Ref counting not required */
1017 IWineD3DDeviceImpl *wineD3DDevice;
1019 /* IWineD3DSwapChain fields */
1020 IWineD3DSurface *backBuffer;
1021 IWineD3DSurface *frontBuffer;
1022 BOOL wantsDepthStencilBuffer;
1023 D3DPRESENT_PARAMETERS presentParms;
1025 /* TODO: move everything upto drawable off into a context manager
1026 and store the 'data' in the contextManagerData interface.
1027 IUnknown *contextManagerData;
1035 XVisualInfo *visInfo;
1036 GLXContext render_ctx;
1037 /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1039 } IWineD3DSwapChainImpl;
1041 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1043 /*****************************************************************************
1044 * Utility function prototypes
1047 /* Trace routines */
1048 const char* debug_d3dformat(WINED3DFORMAT fmt);
1049 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1050 const char* debug_d3dresourcetype(D3DRESOURCETYPE res);
1051 const char* debug_d3dusage(DWORD usage);
1052 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1053 const char* debug_d3drenderstate(DWORD state);
1054 const char* debug_d3dtexturestate(DWORD state);
1055 const char* debug_d3dpool(D3DPOOL pool);
1057 /* Routines for GL <-> D3D values */
1058 GLenum StencilOp(DWORD op);
1059 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1060 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1061 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
1063 SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1064 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1065 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
1066 GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1068 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1071 /*****************************************************************************
1072 * To enable calling of inherited functions, requires prototypes
1074 * Note: Only require classes which are subclassed, ie resource, basetexture,
1076 /*** IUnknown methods ***/
1077 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1078 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1079 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1080 /*** IWineD3DResource methods ***/
1081 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1082 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1083 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1084 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1085 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1086 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1087 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1088 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1089 extern D3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1090 /*** class static members ***/
1091 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1093 /*** IUnknown methods ***/
1094 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1095 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1096 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1097 /*** IWineD3DResource methods ***/
1098 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1099 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1100 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1101 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1102 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1103 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1104 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1105 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1106 extern D3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1107 /*** IWineD3DBaseTexture methods ***/
1108 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1109 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1110 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1111 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, D3DTEXTUREFILTERTYPE FilterType);
1112 extern D3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1113 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1114 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1115 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1117 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset);
1118 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1119 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1120 extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1121 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1122 /*** class static members ***/
1123 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1125 /* An enum for the type of constants that are used... addressing causes
1126 * problems with being able to work out what's used and what's not.. so
1127 * maybe we'll have to rely on the server vertex shader const functions?
1129 enum vsConstantsEnum {
1130 VS_CONSTANT_NOT_USED = 0,
1131 VS_CONSTANT_CONSTANT,
1132 VS_CONSTANT_INTEGER,
1133 VS_CONSTANT_BOOLEAN,
1137 /*****************************************************************************
1138 * IDirect3DVertexShader implementation structure
1140 typedef struct IWineD3DVertexShaderImpl {
1142 const IWineD3DVertexShaderVtbl *lpVtbl;
1143 LONG ref; /* Note: Ref counting not required */
1146 IWineD3DDeviceImpl *wineD3DDevice;
1148 /* IWineD3DVertexShaderImpl */
1149 CONST DWORD *function;
1150 UINT functionLength;
1155 /* vertex declaration array mapping */
1156 BOOL namedArrays; /* don't map use named functions */
1157 BOOL declaredArrays; /* mapping requires */
1158 INT arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE]; /* lookup table for the maps */
1159 INT highestConstant;
1160 CHAR constantsUsedBitmap[256];
1161 /* 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 */
1162 /* run time datas... */
1165 #if 0 /* needs reworking */
1166 /* run time datas */
1167 VSHADERINPUTDATA input;
1168 VSHADEROUTPUTDATA output;
1170 } IWineD3DVertexShaderImpl;
1171 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1173 /*****************************************************************************
1174 * IDirect3DPixelShader implementation structure
1176 typedef struct IWineD3DPixelShaderImpl {
1177 /* IUnknown parts */
1178 const IWineD3DPixelShaderVtbl *lpVtbl;
1179 LONG ref; /* Note: Ref counting not required */
1182 IWineD3DDeviceImpl *wineD3DDevice;
1184 /* IWineD3DPixelShaderImpl */
1185 CONST DWORD *function;
1186 UINT functionLength;
1192 #if 0 /* needs reworking */
1193 PSHADERINPUTDATA input;
1194 PSHADEROUTPUTDATA output;
1196 } IWineD3DPixelShaderImpl;
1198 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;