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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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"
43 #include "wine/wined3d_interface.h"
44 #include "wine/wined3d_gl.h"
45 #include "wine/list.h"
48 #define MAX_PALETTES 256
49 #define MAX_STREAMS 16
50 #define MAX_TEXTURES 8
51 #define MAX_SAMPLERS 16
52 #define MAX_ACTIVE_LIGHTS 8
53 #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
54 #define MAX_LEVELS 256
56 #define MAX_VSHADER_CONSTANTS 96
57 #define MAX_PSHADER_CONSTANTS 32
59 /* Used for CreateStateBlock */
60 #define NUM_SAVEDPIXELSTATES_R 35
61 #define NUM_SAVEDPIXELSTATES_T 18
62 #define NUM_SAVEDPIXELSTATES_S 12
63 #define NUM_SAVEDVERTEXSTATES_R 31
64 #define NUM_SAVEDVERTEXSTATES_T 2
65 #define NUM_SAVEDVERTEXSTATES_S 1
67 extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
68 extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
69 extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
70 extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
71 extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
72 extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
74 typedef enum _WINELOOKUP {
75 WINELOOKUP_WARPPARAM = 0,
76 WINELOOKUP_MAGFILTER = 1,
80 extern int minLookup[MAX_LOOKUPS];
81 extern int maxLookup[MAX_LOOKUPS];
82 extern DWORD *stateLookup[MAX_LOOKUPS];
84 extern DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
86 typedef struct _WINED3DGLTYPE {
94 /* NOTE: Make sure these are in the correct numerical order. (see /include/d3d9types.h typedef enum _D3DDECLTYPE) */
95 WINED3DGLTYPE static const glTypeLookup[D3DDECLTYPE_UNUSED] = {
96 {D3DDECLTYPE_FLOAT1, 1, GL_FLOAT , GL_FALSE ,sizeof(float)},
97 {D3DDECLTYPE_FLOAT2, 2, GL_FLOAT , GL_FALSE ,sizeof(float)},
98 {D3DDECLTYPE_FLOAT3, 3, GL_FLOAT , GL_FALSE ,sizeof(float)},
99 {D3DDECLTYPE_FLOAT4, 4, GL_FLOAT , GL_FALSE ,sizeof(float)},
100 {D3DDECLTYPE_D3DCOLOR, 4, GL_UNSIGNED_BYTE , GL_TRUE ,sizeof(BYTE)},
101 {D3DDECLTYPE_UBYTE4, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
102 {D3DDECLTYPE_SHORT2, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
103 {D3DDECLTYPE_SHORT4, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
104 {D3DDECLTYPE_UBYTE4N, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
105 {D3DDECLTYPE_SHORT2N, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
106 {D3DDECLTYPE_SHORT4N, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
107 {D3DDECLTYPE_USHORT2N, 2, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
108 {D3DDECLTYPE_USHORT4N, 4, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
109 {D3DDECLTYPE_UDEC3, 3, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
110 {D3DDECLTYPE_DEC3N, 3, GL_SHORT , GL_FALSE ,sizeof(short int)},
111 {D3DDECLTYPE_FLOAT16_2, 2, GL_FLOAT , GL_FALSE ,sizeof(short int)},
112 {D3DDECLTYPE_FLOAT16_4, 4, GL_FLOAT , GL_FALSE ,sizeof(short int)}};
114 #define WINED3D_ATR_TYPE(_attribute) glTypeLookup[sd->u.s._attribute.dwType].d3dType
115 #define WINED3D_ATR_SIZE(_attribute) glTypeLookup[sd->u.s._attribute.dwType].size
116 #define WINED3D_ATR_GLTYPE(_attribute) glTypeLookup[sd->u.s._attribute.dwType].glType
117 #define WINED3D_ATR_NORMALIZED(_attribute) glTypeLookup[sd->u.s._attribute.dwType].normalized
118 #define WINED3D_ATR_TYPESIZE(_attribute) glTypeLookup[sd->u.s._attribute.dwType].typesize
138 #define SHADER_GLSL 2
140 typedef struct wined3d_settings_s {
141 /* vertex and pixel shader modes */
145 /* Ideally, we don't want the user to have to request GLSL. If the hardware supports GLSL,
146 we should use it. However, until it's fully implemented, we'll leave it as a registry
147 setting for developers. */
150 /* nonpower 2 function */
152 } wined3d_settings_t;
154 extern wined3d_settings_t wined3d_settings;
158 extern void (*wine_tsx11_lock_ptr)(void);
159 extern void (*wine_tsx11_unlock_ptr)(void);
161 /* As GLX relies on X, this is needed */
165 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
166 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
168 #define ENTER_GL() wine_tsx11_lock_ptr()
169 #define LEAVE_GL() wine_tsx11_unlock_ptr()
172 /*****************************************************************************
176 /* GL related defines */
177 /* ------------------ */
178 #define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
179 #define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
180 #define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
181 #define GL_VEND(_VendName) (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
183 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
184 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
185 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
186 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
188 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
189 #define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
190 #define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
191 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
193 #define D3DCOLORTOGLFLOAT4(dw, vec) \
194 (vec)[0] = D3DCOLOR_R(dw); \
195 (vec)[1] = D3DCOLOR_G(dw); \
196 (vec)[2] = D3DCOLOR_B(dw); \
197 (vec)[3] = D3DCOLOR_A(dw);
199 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP_ARB
201 /* DirectX Device Limits */
202 /* --------------------- */
203 #define MAX_LEVELS 256 /* Maximum number of mipmap levels. Guessed at 256 */
205 #define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
206 See MaxStreams in MSDN under GetDeviceCaps */
207 /* Maximum number of constants provided to the shaders */
208 #define HIGHEST_TRANSFORMSTATE 512
209 /* Highest value in D3DTRANSFORMSTATETYPE */
210 #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
212 #define MAX_PALETTES 256
214 /* Checking of API calls */
215 /* --------------------- */
216 #define checkGLcall(A) \
218 GLint err = glGetError(); \
219 if (err == GL_NO_ERROR) { \
220 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
223 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", \
224 err, A, __FILE__, __LINE__); \
225 err = glGetError(); \
226 } while (err != GL_NO_ERROR); \
229 /* Trace routines / diagnostics */
230 /* ---------------------------- */
232 /* Dump out a matrix and copy it */
233 #define conv_mat(mat,gl_mat) \
235 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
236 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
237 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
238 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
239 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
242 /* Macro to dump out the current state of the light chain */
243 #define DUMP_LIGHT_CHAIN() \
245 PLIGHTINFOEL *el = This->stateBlock->lights;\
247 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
252 /* Trace vector and strided data information */
253 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
254 #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);
256 /* Defines used for optimizations */
258 /* Only reapply what is necessary */
259 #define REAPPLY_ALPHAOP 0x0001
260 #define REAPPLY_ALL 0xFFFF
262 /* Advance declaration of structures to satisfy compiler */
263 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
264 typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
265 typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl;
269 /* TODO: Move some of this to the device */
270 long globalChangeGlRam(long glram);
272 /* Memory and object tracking */
274 /*Structure for holding information on all direct3d objects
275 useful for making sure tracking is ok and when release is called on a device!
276 and probably quite handy for debugging and dumping states out
278 typedef struct WineD3DGlobalStatistics {
279 int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
280 } WineD3DGlobalStatistics;
282 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
284 /* Global variables */
285 extern const float identity[16];
287 /*****************************************************************************
288 * Compilable extra diagnostics
291 /* Trace information per-vertex: (extremely high amount of trace) */
292 #if 0 /* NOTE: Must be 0 in cvs */
293 # define VTRACE(A) TRACE A
298 /* Checking of per-vertex related GL calls */
299 /* --------------------- */
300 #define vcheckGLcall(A) \
302 GLint err = glGetError(); \
303 if (err == GL_NO_ERROR) { \
304 VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
307 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", \
308 err, A, __FILE__, __LINE__); \
309 err = glGetError(); \
310 } while (err != GL_NO_ERROR); \
313 /* TODO: Confirm each of these works when wined3d move completed */
314 #if 0 /* NOTE: Must be 0 in cvs */
315 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
316 of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
317 is enabled, and if it doesn't exists it is disabled. */
318 # define FRAME_DEBUGGING
319 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
320 the file is deleted */
321 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
322 # define SINGLE_FRAME_DEBUGGING
324 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
325 It can only be enabled when FRAME_DEBUGGING is also enabled
326 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
328 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
329 # define SHOW_FRAME_MAKEUP 1
331 /* The following, when enabled, lets you see the makeup of the all the textures used during each
332 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
333 The contents of the textures assigned to each stage are written into
334 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
335 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
336 # define SHOW_TEXTURE_MAKEUP 0
339 extern BOOL isDumpingFrames;
340 extern LONG primCounter;
343 /*****************************************************************************
347 /* Routine common to the draw primitive and draw indexed primitive routines */
348 void drawPrimitive(IWineD3DDevice *iface,
352 long StartVertexIndex,
353 UINT numberOfVertices,
358 WineDirect3DVertexStridedData *DrawPrimStrideData);
360 void primitiveConvertToStridedData(IWineD3DDevice *iface, WineDirect3DVertexStridedData *strided, LONG BaseVertexIndex, BOOL *fixup);
362 void primitiveDeclarationConvertToStridedData(
363 IWineD3DDevice *iface,
364 BOOL useVertexShaderFunction,
365 WineDirect3DVertexStridedData *strided,
366 LONG BaseVertexIndex,
370 void primitiveConvertFVFtoOffset(DWORD thisFVF,
373 WineDirect3DVertexStridedData *strided,
376 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
380 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
381 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
383 /* Routine to fill gl caps for swapchains and IWineD3D */
384 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info,
387 /*****************************************************************************
388 * Internal representation of a light
390 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
391 struct PLIGHTINFOEL {
392 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
399 /* Converted parms to speed up swapping lights */
409 /* The default light parameters */
410 extern const WINED3DLIGHT WINED3D_default_light;
412 /*****************************************************************************
413 * IWineD3D implementation structure
415 typedef struct IWineD3DImpl
417 /* IUnknown fields */
418 const IWineD3DVtbl *lpVtbl;
419 LONG ref; /* Note: Ref counting not required */
421 /* WineD3D Information */
427 WineD3D_GL_Info gl_info;
430 extern const IWineD3DVtbl IWineD3D_Vtbl;
432 /** Hacked out start of a context manager!! **/
433 typedef struct glContext {
440 IWineD3DSurface *pSurface;
441 #if 0 /* TODO: someway to represent the state of the context */
442 IWineD3DStateBlock *pStateBlock;
444 /* a few other things like format */
447 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
448 (since it will break quite a few things until contexts are managed properly!) */
449 extern BOOL pbuffer_support;
450 /* allocate one pbuffer per surface */
451 extern BOOL pbuffer_per_surface;
453 /* Maximum number of contexts/pbuffers to keep in cache,
454 set to 100 because ATI's drivers don't support deleting pBuffers properly
455 this needs to be migrated to a list and some option availalbe for controle the cache size.
457 #define CONTEXT_CACHE 100
459 typedef struct ResourceList {
460 IWineD3DResource *resource;
461 struct ResourceList *next;
464 /* A helper function that dumps a resource list */
465 void dumpResources(ResourceList *resources);
467 /*****************************************************************************
468 * IWineD3DDevice implementation structure
470 typedef struct IWineD3DDeviceImpl
472 /* IUnknown fields */
473 const IWineD3DDeviceVtbl *lpVtbl;
474 LONG ref; /* Note: Ref counting not required */
476 /* WineD3D Information */
480 /* X and GL Information */
481 GLint maxConcurrentLights;
484 BOOL modelview_valid;
486 BOOL view_ident; /* true iff view matrix is identity */
487 BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
488 BOOL viewport_changed; /* Was the viewport changed since the last draw? */
489 GLenum tracking_parm; /* Which source is tracking current colour */
490 LONG tracking_color; /* used iff GL_COLOR_MATERIAL was enabled */
491 #define DISABLED_TRACKING 0 /* Disabled */
492 #define IS_TRACKING 1 /* tracking_parm is tracking diffuse color */
493 #define NEEDS_TRACKING 2 /* Tracking needs to be enabled when needed */
494 #define NEEDS_DISABLE 3 /* Tracking needs to be disabled when needed*/
498 BOOL texture_shader_active; /* TODO: Confirm use is correct */
499 BOOL last_was_notclipped;
501 /* State block related */
502 BOOL isRecordingState;
503 IWineD3DStateBlockImpl *stateBlock;
504 IWineD3DStateBlockImpl *updateStateBlock;
506 /* Internal use fields */
507 WINED3DDEVICE_CREATION_PARAMETERS createParms;
511 IWineD3DSwapChain **swapchains;
512 uint NumberOfSwapChains;
514 ResourceList *resources; /* a linked list to track resources created by the device */
516 /* Render Target Support */
517 IWineD3DSurface *depthStencilBuffer;
519 IWineD3DSurface *renderTarget;
520 IWineD3DSurface *stencilBufferTarget;
522 /* palettes texture management */
523 PALETTEENTRY palettes[MAX_PALETTES][256];
526 /* For rendering to a texture using glCopyTexImage */
527 BOOL renderUpsideDown;
529 /* Cursor management */
536 /* Textures for when no other textures are mapped */
537 UINT dummyTextureName[MAX_TEXTURES];
539 /* Debug stream management */
542 /* Device state management */
544 BOOL d3d_initialized;
546 /* Screen buffer resources */
547 glContext contextCache[CONTEXT_CACHE];
549 /* A flag to check if endscene has been called before changing the render tartet */
552 /* process vertex shaders using software or hardware */
553 BOOL softwareVertexProcessing;
555 /* DirectDraw stuff */
557 IWineD3DSurface *ddraw_primary;
558 DWORD ddraw_width, ddraw_height;
559 WINED3DFORMAT ddraw_format;
561 /* List of GLSL shader programs and their associated vertex & pixel shaders */
562 struct list glsl_shader_progs;
564 } IWineD3DDeviceImpl;
566 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
568 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
569 * anybody uses it for much so a good implementation is optional. */
570 typedef struct PrivateData
572 struct PrivateData* next;
575 DWORD flags; /* DDSPD_* */
576 DWORD uniqueness_value;
587 void d3ddevice_set_ortho(IWineD3DDeviceImpl *This);
589 /*****************************************************************************
590 * IWineD3DResource implementation structure
592 typedef struct IWineD3DResourceClass
594 /* IUnknown fields */
595 LONG ref; /* Note: Ref counting not required */
597 /* WineD3DResource Information */
599 WINED3DRESOURCETYPE resourceType;
600 IWineD3DDeviceImpl *wineD3DDevice;
604 WINED3DFORMAT format;
605 BYTE *allocatedMemory;
606 PrivateData *privateData;
608 } IWineD3DResourceClass;
610 typedef struct IWineD3DResourceImpl
612 /* IUnknown & WineD3DResource Information */
613 const IWineD3DResourceVtbl *lpVtbl;
614 IWineD3DResourceClass resource;
615 } IWineD3DResourceImpl;
618 /*****************************************************************************
619 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
621 typedef struct IWineD3DVertexBufferImpl
623 /* IUnknown & WineD3DResource Information */
624 const IWineD3DVertexBufferVtbl *lpVtbl;
625 IWineD3DResourceClass resource;
627 /* WineD3DVertexBuffer specifics */
630 /* Vertex buffer object support */
635 UINT dirtystart, dirtyend;
638 /* Last description of the buffer */
639 WineDirect3DVertexStridedData strided;
640 } IWineD3DVertexBufferImpl;
642 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
644 #define VBFLAG_LOAD 0x01 /* Data is written from allocatedMemory to the VBO */
645 #define VBFLAG_OPTIMIZED 0x02 /* Optimize has been called for the VB */
646 #define VBFLAG_DIRTY 0x04 /* Buffer data has been modified */
647 #define VBFLAG_STREAM 0x08 /* The vertex buffer is in a stream */
648 #define VBFLAG_HASDESC 0x10 /* A vertex description has been found */
650 /*****************************************************************************
651 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
653 typedef struct IWineD3DIndexBufferImpl
655 /* IUnknown & WineD3DResource Information */
656 const IWineD3DIndexBufferVtbl *lpVtbl;
657 IWineD3DResourceClass resource;
659 /* WineD3DVertexBuffer specifics */
660 } IWineD3DIndexBufferImpl;
662 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
664 /*****************************************************************************
665 * IWineD3DBaseTexture D3D- > openGL state map lookups
667 #define WINED3DFUNC_NOTSUPPORTED -2
668 #define WINED3DFUNC_UNIMPLEMENTED -1
670 typedef enum winetexturestates {
671 WINED3DTEXSTA_ADDRESSU = 0,
672 WINED3DTEXSTA_ADDRESSV = 1,
673 WINED3DTEXSTA_ADDRESSW = 2,
674 WINED3DTEXSTA_BORDERCOLOR = 3,
675 WINED3DTEXSTA_MAGFILTER = 4,
676 WINED3DTEXSTA_MINFILTER = 5,
677 WINED3DTEXSTA_MIPFILTER = 6,
678 WINED3DTEXSTA_MAXMIPLEVEL = 7,
679 WINED3DTEXSTA_MAXANISOTROPY = 8,
680 WINED3DTEXSTA_SRGBTEXTURE = 9,
681 WINED3DTEXSTA_ELEMENTINDEX = 10,
682 WINED3DTEXSTA_DMAPOFFSET = 11,
683 WINED3DTEXSTA_TSSADDRESSW = 12,
684 MAX_WINETEXTURESTATES = 13,
687 typedef struct Wined3dTextureStateMap {
690 } Wined3dTextureStateMap;
692 /*****************************************************************************
693 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
695 typedef struct IWineD3DBaseTextureClass
703 WINED3DTEXTUREFILTERTYPE filterType;
704 DWORD states[MAX_WINETEXTURESTATES];
706 } IWineD3DBaseTextureClass;
708 typedef struct IWineD3DBaseTextureImpl
710 /* IUnknown & WineD3DResource Information */
711 const IWineD3DBaseTextureVtbl *lpVtbl;
712 IWineD3DResourceClass resource;
713 IWineD3DBaseTextureClass baseTexture;
715 } IWineD3DBaseTextureImpl;
717 /*****************************************************************************
718 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
720 typedef struct IWineD3DTextureImpl
722 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
723 const IWineD3DTextureVtbl *lpVtbl;
724 IWineD3DResourceClass resource;
725 IWineD3DBaseTextureClass baseTexture;
727 /* IWineD3DTexture */
728 IWineD3DSurface *surfaces[MAX_LEVELS];
732 float pow2scalingFactorX;
733 float pow2scalingFactorY;
735 } IWineD3DTextureImpl;
737 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
739 /*****************************************************************************
740 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
742 typedef struct IWineD3DCubeTextureImpl
744 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
745 const IWineD3DCubeTextureVtbl *lpVtbl;
746 IWineD3DResourceClass resource;
747 IWineD3DBaseTextureClass baseTexture;
749 /* IWineD3DCubeTexture */
750 IWineD3DSurface *surfaces[6][MAX_LEVELS];
753 float pow2scalingFactor;
755 } IWineD3DCubeTextureImpl;
757 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
759 typedef struct _WINED3DVOLUMET_DESC
764 } WINED3DVOLUMET_DESC;
766 /*****************************************************************************
767 * IWineD3DVolume implementation structure (extends IUnknown)
769 typedef struct IWineD3DVolumeImpl
771 /* IUnknown & WineD3DResource fields */
772 const IWineD3DVolumeVtbl *lpVtbl;
773 IWineD3DResourceClass resource;
775 /* WineD3DVolume Information */
776 WINED3DVOLUMET_DESC currentDesc;
777 IWineD3DBase *container;
782 WINED3DBOX lockedBox;
787 } IWineD3DVolumeImpl;
789 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
791 /*****************************************************************************
792 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
794 typedef struct IWineD3DVolumeTextureImpl
796 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
797 const IWineD3DVolumeTextureVtbl *lpVtbl;
798 IWineD3DResourceClass resource;
799 IWineD3DBaseTextureClass baseTexture;
801 /* IWineD3DVolumeTexture */
802 IWineD3DVolume *volumes[MAX_LEVELS];
807 } IWineD3DVolumeTextureImpl;
809 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
811 typedef struct _WINED3DSURFACET_DESC
813 WINED3DMULTISAMPLE_TYPE MultiSampleType;
814 DWORD MultiSampleQuality;
817 } WINED3DSURFACET_DESC;
819 /*****************************************************************************
820 * Structure for DIB Surfaces (GetDC and GDI surfaces)
822 typedef struct wineD3DSurface_DIB {
827 } wineD3DSurface_DIB;
829 /*****************************************************************************
830 * IWineD3DSurface implementation structure
832 struct IWineD3DSurfaceImpl
834 /* IUnknown & IWineD3DResource Information */
835 const IWineD3DSurfaceVtbl *lpVtbl;
836 IWineD3DResourceClass resource;
838 /* IWineD3DSurface fields */
839 IWineD3DBase *container;
840 WINED3DSURFACET_DESC currentDesc;
841 IWineD3DPaletteImpl *palette;
846 /* TODO: move this off into a management class(maybe!) */
853 /* Oversized texture */
857 /* precalculated x and y scalings for texture coords */
858 float pow2scalingFactorX; /* = (Width / pow2Width ) */
859 float pow2scalingFactorY; /* = (Height / pow2Height) */
865 glDescriptor glDescription;
868 wineD3DSurface_DIB dib;
871 /* Color keys for DDraw */
872 DDCOLORKEY DestBltCKey;
873 DDCOLORKEY DestOverlayCKey;
874 DDCOLORKEY SrcOverlayCKey;
875 DDCOLORKEY SrcBltCKey;
880 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
881 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
883 /* Predeclare the shared Surface functions */
884 HRESULT WINAPI IWineD3DSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
885 ULONG WINAPI IWineD3DSurfaceImpl_AddRef(IWineD3DSurface *iface);
886 ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface);
887 HRESULT WINAPI IWineD3DSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
888 HRESULT WINAPI IWineD3DSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
889 HRESULT WINAPI IWineD3DSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
890 HRESULT WINAPI IWineD3DSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
891 HRESULT WINAPI IWineD3DSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
892 DWORD WINAPI IWineD3DSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
893 DWORD WINAPI IWineD3DSurfaceImpl_GetPriority(IWineD3DSurface *iface);
894 void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface);
895 WINED3DRESOURCETYPE WINAPI IWineD3DSurfaceImpl_GetType(IWineD3DSurface *iface);
896 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainerParent(IWineD3DSurface* iface, IUnknown **ppContainerParent);
897 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
898 HRESULT WINAPI IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
899 HRESULT WINAPI IWineD3DSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
900 HRESULT WINAPI IWineD3DSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
901 HRESULT WINAPI IWineD3DSurfaceImpl_IsLost(IWineD3DSurface *iface);
902 HRESULT WINAPI IWineD3DSurfaceImpl_Restore(IWineD3DSurface *iface);
903 HRESULT WINAPI IWineD3DSurfaceImpl_SetPixelFormat(IWineD3DSurface *iface, WINED3DFORMAT Format, BYTE *Surface, DWORD Size);
904 HRESULT WINAPI IWineD3DSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
905 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
906 HRESULT WINAPI IWineD3DSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, DDCOLORKEY *CKey);
907 HRESULT WINAPI IWineD3DSurfaceImpl_CleanDirtyRect(IWineD3DSurface *iface);
908 extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect);
909 HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
910 HRESULT WINAPI IWineD3DSurfaceImpl_SetPBufferState(IWineD3DSurface *iface, BOOL inPBuffer, BOOL inTexture);
911 void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target);
912 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription);
913 const void *WINAPI IWineD3DSurfaceImpl_GetData(IWineD3DSurface *iface);
914 HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
915 HRESULT WINAPI IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx);
916 HRESULT WINAPI IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty, IWineD3DSurface *Source, RECT *rsrc, DWORD trans);
917 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
918 HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC);
919 HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC);
920 DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface);
921 HRESULT WINAPI IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
924 #define SFLAG_OVERSIZE 0x0001 /* Surface is bigger than gl size, blts only */
925 #define SFLAG_CONVERTED 0x0002 /* Converted for color keying or Palettized */
926 #define SFLAG_DIBSECTION 0x0004 /* Has a DIB section attached for getdc */
927 #define SFLAG_DIRTY 0x0008 /* Surface was locked by the app */
928 #define SFLAG_LOCKABLE 0x0010 /* Surface can be locked */
929 #define SFLAG_DISCARD 0x0020 /* ??? */
930 #define SFLAG_LOCKED 0x0040 /* Surface is locked atm */
931 #define SFLAG_ACTIVELOCK 0x0080 /* Not locked, but surface memory is needed */
932 #define SFLAG_INTEXTURE 0x0100 /* ??? */
933 #define SFLAG_INPBUFFER 0x0200 /* ??? */
934 #define SFLAG_NONPOW2 0x0400 /* Surface sizes are not a power of 2 */
935 #define SFLAG_DYNLOCK 0x0800 /* Surface is often locked by the app */
936 #define SFLAG_DYNCHANGE 0x1800 /* Surface contents are changed very often, implies DYNLOCK */
937 #define SFLAG_DCINUSE 0x2000 /* Set between GetDC and ReleaseDC calls */
938 #define SFLAG_GLDIRTY 0x4000 /* The opengl texture is more up to date than the surface mem */
939 #define SFLAG_LOST 0x8000 /* Surface lost flag for DDraw */
941 /* In some conditions the surface memory must not be freed:
942 * SFLAG_OVERSIZE: Not all data can be kept in GL
943 * SFLAG_CONVERTED: Converting the data back would take too long
944 * SFLAG_DIBSECTION: The dib code manages the memory
945 * SFLAG_DIRTY: GL surface isn't up to date
946 * SFLAG_LOCKED: The app requires access to the surface data
947 * SFLAG_ACTIVELOCK: Some wined3d code needs the memory
948 * SFLAG_DYNLOCK: Avoid freeing the data for performance
949 * SFLAG_DYNCHANGE: Same reason as DYNLOCK
951 #define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
960 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
962 /*****************************************************************************
963 * IWineD3DVertexDeclaration implementation structure
965 typedef struct IWineD3DVertexDeclarationImpl {
966 /* IUnknown Information */
967 const IWineD3DVertexDeclarationVtbl *lpVtbl;
968 LONG ref; /* Note: Ref counting not required */
971 /** precomputed fvf if simple declaration */
972 IWineD3DDeviceImpl *wineD3DDevice;
973 DWORD fvf[MAX_STREAMS];
976 /** dx8 compatible Declaration fields */
977 DWORD* pDeclaration8;
978 DWORD declaration8Length;
981 D3DVERTEXELEMENT9 *pDeclaration9;
982 UINT declaration9NumElements;
984 WINED3DVERTEXELEMENT *pDeclarationWine;
985 UINT declarationWNumElements;
989 } IWineD3DVertexDeclarationImpl;
991 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
993 /*****************************************************************************
994 * IWineD3DStateBlock implementation structure
997 /* Internal state Block for Begin/End/Capture/Create/Apply info */
998 /* Note: Very long winded but gl Lists are not flexible enough */
999 /* to resolve everything we need, so doing it manually for now */
1000 typedef struct SAVEDSTATES {
1004 BOOL streamSource[MAX_STREAMS];
1005 BOOL streamFreq[MAX_STREAMS];
1006 BOOL textures[MAX_SAMPLERS];
1007 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
1009 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
1010 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1011 BOOL samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1012 BOOL clipplane[MAX_CLIPPLANES];
1015 BOOL pixelShaderConstantsB[MAX_PSHADER_CONSTANTS];
1016 BOOL pixelShaderConstantsI[MAX_PSHADER_CONSTANTS];
1017 BOOL pixelShaderConstantsF[MAX_PSHADER_CONSTANTS];
1019 BOOL vertexShaderConstantsB[MAX_VSHADER_CONSTANTS];
1020 BOOL vertexShaderConstantsI[MAX_VSHADER_CONSTANTS];
1021 BOOL vertexShaderConstantsF[MAX_VSHADER_CONSTANTS];
1024 struct IWineD3DStateBlockImpl
1026 /* IUnknown fields */
1027 const IWineD3DStateBlockVtbl *lpVtbl;
1028 LONG ref; /* Note: Ref counting not required */
1030 /* IWineD3DStateBlock information */
1032 IWineD3DDeviceImpl *wineD3DDevice;
1033 WINED3DSTATEBLOCKTYPE blockType;
1035 /* Array indicating whether things have been set or changed */
1036 SAVEDSTATES changed;
1039 /* Drawing - Vertex Shader or FVF related */
1041 /* Vertex Shader Declaration */
1042 IWineD3DVertexDeclaration *vertexDecl;
1044 IWineD3DVertexShader *vertexShader;
1046 /* Vertex Shader Constants */
1047 BOOL vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
1048 INT vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
1049 float vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
1053 UINT streamStride[MAX_STREAMS];
1054 UINT streamOffset[MAX_STREAMS];
1055 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
1056 UINT streamFreq[MAX_STREAMS];
1057 UINT streamFlags[MAX_STREAMS]; /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA */
1060 IWineD3DIndexBuffer* pIndexData;
1061 UINT baseVertexIndex; /* Note: only used for d3d8 */
1064 D3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
1067 PLIGHTINFOEL *lights; /* NOTE: active GL lights must be front of the chain */
1070 double clipplane[MAX_CLIPPLANES][4];
1071 WINED3DCLIPSTATUS clip_status;
1074 WINED3DVIEWPORT viewport;
1077 WINED3DMATERIAL material;
1080 IWineD3DPixelShader *pixelShader;
1082 /* Pixel Shader Constants */
1083 BOOL pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
1084 INT pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
1085 float pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
1087 /* Indexed Vertex Blending */
1088 D3DVERTEXBLENDFLAGS vertex_blend;
1092 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
1095 IWineD3DBaseTexture *textures[MAX_SAMPLERS];
1096 int textureDimensions[MAX_SAMPLERS];
1098 /* Texture State Stage */
1099 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1100 /* Sampler States */
1101 DWORD samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1103 /* Current GLSL Shader Program */
1104 GLhandleARB shaderPrgId;
1107 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1109 /*****************************************************************************
1110 * IWineD3DQueryImpl implementation structure (extends IUnknown)
1112 typedef struct IWineD3DQueryImpl
1114 const IWineD3DQueryVtbl *lpVtbl;
1115 LONG ref; /* Note: Ref counting not required */
1118 /*TODO: replace with iface usage */
1120 IWineD3DDevice *wineD3DDevice;
1122 IWineD3DDeviceImpl *wineD3DDevice;
1124 /* IWineD3DQuery fields */
1127 /* TODO: Think about using a IUnknown instead of a void* */
1131 } IWineD3DQueryImpl;
1133 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1135 /* Datastructures for IWineD3DQueryImpl.extendedData */
1136 typedef struct WineQueryOcclusionData {
1137 unsigned int queryId;
1138 } WineQueryOcclusionData;
1141 /*****************************************************************************
1142 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1145 typedef struct IWineD3DSwapChainImpl
1148 IWineD3DSwapChainVtbl *lpVtbl;
1149 LONG ref; /* Note: Ref counting not required */
1152 IWineD3DDeviceImpl *wineD3DDevice;
1154 /* IWineD3DSwapChain fields */
1155 IWineD3DSurface **backBuffer;
1156 IWineD3DSurface *frontBuffer;
1157 BOOL wantsDepthStencilBuffer;
1158 D3DPRESENT_PARAMETERS presentParms;
1160 /* TODO: move everything up to drawable off into a context manager
1161 and store the 'data' in the contextManagerData interface.
1162 IUnknown *contextManagerData;
1170 XVisualInfo *visInfo;
1171 GLXContext render_ctx;
1172 /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1174 } IWineD3DSwapChainImpl;
1176 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1178 /*****************************************************************************
1179 * Utility function prototypes
1182 /* Trace routines */
1183 const char* debug_d3dformat(WINED3DFORMAT fmt);
1184 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1185 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1186 const char* debug_d3dusage(DWORD usage);
1187 const char* debug_d3ddeclusage(BYTE usage);
1188 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1189 const char* debug_d3drenderstate(DWORD state);
1190 const char* debug_d3dsamplerstate(DWORD state);
1191 const char* debug_d3dtexturestate(DWORD state);
1192 const char* debug_d3dpool(WINED3DPOOL pool);
1194 /* Routines for GL <-> D3D values */
1195 GLenum StencilOp(DWORD op);
1196 GLenum StencilFunc(DWORD func);
1197 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1198 void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx);
1199 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1201 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1204 void multiply_matrix(D3DMATRIX *dest, D3DMATRIX *src1, D3DMATRIX *src2);
1206 /*****************************************************************************
1207 * To enable calling of inherited functions, requires prototypes
1209 * Note: Only require classes which are subclassed, ie resource, basetexture,
1211 /*** IUnknown methods ***/
1212 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1213 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1214 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1215 /*** IWineD3DResource methods ***/
1216 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1217 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1218 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1219 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1220 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1221 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1222 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1223 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1224 extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1225 /*** class static members ***/
1226 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1228 /*** IUnknown methods ***/
1229 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1230 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1231 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1232 /*** IWineD3DResource methods ***/
1233 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1234 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1235 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1236 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1237 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1238 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1239 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1240 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1241 extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1242 /*** IWineD3DBaseTexture methods ***/
1243 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1244 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1245 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1246 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1247 extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1248 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1249 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1250 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1252 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset, GLint *vbo);
1253 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1254 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1255 extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1256 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1257 /*** class static members ***/
1258 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1260 struct SHADER_OPCODE_ARG;
1261 typedef void (*shader_fct_t)();
1262 typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
1264 /* Struct to maintain a list of GLSL shader programs and their associated pixel and
1265 * vertex shaders. A list of this type is maintained on the DeviceImpl, and is only
1266 * used if the user is using GLSL shaders. */
1267 struct glsl_shader_prog_link {
1269 GLhandleARB programId;
1270 IWineD3DVertexShader* vertexShader;
1271 IWineD3DPixelShader* pixelShader;
1274 /* TODO: Make this dynamic, based on shader limits ? */
1275 #define MAX_REG_ADDR 1
1276 #define MAX_REG_TEMP 32
1277 #define MAX_REG_TEXCRD 8
1278 #define MAX_REG_INPUT 12
1279 #define MAX_REG_OUTPUT 12
1280 #define MAX_ATTRIBS 16
1281 #define MAX_CONST_F 256
1282 #define MAX_CONST_I 16
1283 #define MAX_CONST_B 16
1285 typedef struct shader_reg_maps {
1287 char texcoord[MAX_REG_TEXCRD]; /* pixel < 3.0 */
1288 char temporary[MAX_REG_TEMP]; /* pixel, vertex */
1289 char address[MAX_REG_ADDR]; /* vertex */
1290 char packed_input[MAX_REG_INPUT]; /* pshader >= 3.0 */
1291 char packed_output[MAX_REG_OUTPUT]; /* vertex >= 3.0 */
1292 char attributes[MAX_ATTRIBS]; /* vertex */
1294 char constantsF[MAX_CONST_F]; /* pixel, vertex */
1295 char constantsI[MAX_CONST_I]; /* pixel & vertex >= 2.0 */
1296 char constantsB[MAX_CONST_B]; /* pixel & vertex >= 2.0 */
1298 /* Semantics maps (semantic -> reg_token)
1299 * Use 0 as default (bit 31 is always 1 on a valid token) */
1300 DWORD* semantics_in; /* vertex, pixel */
1301 DWORD* semantics_out; /* vertex */
1303 /* Sampler usage tokens
1304 * Use 0 as default (bit 31 is always 1 on a valid token) */
1305 DWORD samplers[MAX_SAMPLERS];
1307 /* Whether or not a loop is used in this shader */
1312 #define SHADER_PGMSIZE 65535
1313 typedef struct SHADER_BUFFER {
1316 unsigned int lineNo;
1319 typedef struct SHADER_OPCODE {
1320 unsigned int opcode;
1324 CONST UINT num_params;
1325 shader_fct_t soft_fct;
1326 SHADER_HANDLER hw_fct;
1327 SHADER_HANDLER hw_glsl_fct;
1332 typedef struct SHADER_OPCODE_ARG {
1333 IWineD3DBaseShader* shader;
1334 shader_reg_maps* reg_maps;
1335 CONST SHADER_OPCODE* opcode;
1341 SHADER_BUFFER* buffer;
1342 } SHADER_OPCODE_ARG;
1344 typedef struct SHADER_LIMITS {
1345 unsigned int temporary;
1346 unsigned int texcoord;
1347 unsigned int sampler;
1348 unsigned int constant_int;
1349 unsigned int constant_float;
1350 unsigned int constant_bool;
1351 unsigned int address;
1352 unsigned int packed_output;
1353 unsigned int packed_input;
1354 unsigned int attributes;
1357 /** Keeps track of details for TEX_M#x# shader opcodes which need to
1358 maintain state information between multiple codes */
1359 typedef struct SHADER_PARSE_STATE {
1360 unsigned int current_row;
1361 DWORD texcoord_w[2];
1362 } SHADER_PARSE_STATE;
1364 /* Base Shader utility functions.
1365 * (may move callers into the same file in the future) */
1366 extern int shader_addline(
1367 SHADER_BUFFER* buffer,
1368 const char* fmt, ...);
1370 extern const SHADER_OPCODE* shader_get_opcode(
1371 IWineD3DBaseShader *iface,
1374 /* ARB_[vertex/fragment]_program helper functions */
1375 extern void shader_arb_load_constants(
1376 IWineD3DStateBlock* iface,
1377 char usePixelShader,
1378 char useVertexShader);
1380 /* ARB shader program Prototypes */
1381 extern void shader_hw_def(SHADER_OPCODE_ARG *arg);
1383 /* ARB pixel shader prototypes */
1384 extern void pshader_hw_cnd(SHADER_OPCODE_ARG* arg);
1385 extern void pshader_hw_cmp(SHADER_OPCODE_ARG* arg);
1386 extern void pshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1387 extern void pshader_hw_tex(SHADER_OPCODE_ARG* arg);
1388 extern void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg);
1389 extern void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg);
1390 extern void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg);
1391 extern void pshader_hw_texbem(SHADER_OPCODE_ARG* arg);
1392 extern void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG* arg);
1393 extern void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg);
1394 extern void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg);
1395 extern void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg);
1396 extern void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg);
1397 extern void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1399 /* ARB vertex shader prototypes */
1400 extern void vshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1401 extern void vshader_hw_mnxn(SHADER_OPCODE_ARG* arg);
1403 /* GLSL helper functions */
1404 extern void set_glsl_shader_program(IWineD3DDevice *iface);
1405 extern void shader_glsl_add_instruction_modifiers(SHADER_OPCODE_ARG *arg);
1406 extern void shader_glsl_load_constants(
1407 IWineD3DStateBlock* iface,
1408 char usePixelShader,
1409 char useVertexShader);
1411 /** The following translate DirectX pixel/vertex shader opcodes to GLSL lines */
1412 extern void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg);
1413 extern void shader_glsl_arith(SHADER_OPCODE_ARG* arg);
1414 extern void shader_glsl_mov(SHADER_OPCODE_ARG* arg);
1415 extern void shader_glsl_mad(SHADER_OPCODE_ARG* arg);
1416 extern void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg);
1417 extern void shader_glsl_lrp(SHADER_OPCODE_ARG* arg);
1418 extern void shader_glsl_dot(SHADER_OPCODE_ARG* arg);
1419 extern void shader_glsl_rcp(SHADER_OPCODE_ARG* arg);
1420 extern void shader_glsl_cnd(SHADER_OPCODE_ARG* arg);
1421 extern void shader_glsl_compare(SHADER_OPCODE_ARG* arg);
1422 extern void shader_glsl_def(SHADER_OPCODE_ARG* arg);
1423 extern void shader_glsl_defi(SHADER_OPCODE_ARG* arg);
1424 extern void shader_glsl_defb(SHADER_OPCODE_ARG* arg);
1425 extern void shader_glsl_cmp(SHADER_OPCODE_ARG* arg);
1426 extern void shader_glsl_lit(SHADER_OPCODE_ARG* arg);
1427 extern void shader_glsl_dst(SHADER_OPCODE_ARG* arg);
1428 extern void shader_glsl_sincos(SHADER_OPCODE_ARG* arg);
1429 extern void shader_glsl_loop(SHADER_OPCODE_ARG* arg);
1430 extern void shader_glsl_endloop(SHADER_OPCODE_ARG* arg);
1432 /** GLSL Pixel Shader Prototypes */
1433 extern void pshader_glsl_tex(SHADER_OPCODE_ARG* arg);
1434 extern void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg);
1435 extern void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg);
1436 extern void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg);
1437 extern void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg);
1438 extern void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1439 extern void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg);
1440 extern void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg);
1441 extern void pshader_glsl_dp2add(SHADER_OPCODE_ARG* arg);
1442 extern void pshader_glsl_input_pack(
1443 SHADER_BUFFER* buffer,
1444 DWORD* semantics_out);
1446 /** GLSL Vertex Shader Prototypes */
1447 extern void vshader_glsl_output_unpack(
1448 SHADER_BUFFER* buffer,
1449 DWORD* semantics_out);
1451 /*****************************************************************************
1452 * IDirect3DBaseShader implementation structure
1454 typedef struct IWineD3DBaseShaderClass
1457 SHADER_LIMITS limits;
1458 SHADER_PARSE_STATE parse_state;
1459 CONST SHADER_OPCODE *shader_ins;
1460 CONST DWORD *function;
1461 UINT functionLength;
1463 } IWineD3DBaseShaderClass;
1465 typedef struct IWineD3DBaseShaderImpl {
1467 const IWineD3DBaseShaderVtbl *lpVtbl;
1470 /* IWineD3DBaseShader */
1471 IWineD3DBaseShaderClass baseShader;
1472 } IWineD3DBaseShaderImpl;
1474 extern void shader_get_registers_used(
1475 IWineD3DBaseShader *iface,
1476 shader_reg_maps* reg_maps,
1477 CONST DWORD* pToken);
1479 extern void shader_generate_glsl_declarations(
1480 IWineD3DBaseShader *iface,
1481 shader_reg_maps* reg_maps,
1482 SHADER_BUFFER* buffer);
1484 extern void shader_generate_arb_declarations(
1485 IWineD3DBaseShader *iface,
1486 shader_reg_maps* reg_maps,
1487 SHADER_BUFFER* buffer);
1489 extern void shader_generate_main(
1490 IWineD3DBaseShader *iface,
1491 SHADER_BUFFER* buffer,
1492 shader_reg_maps* reg_maps,
1493 CONST DWORD* pFunction);
1495 extern void shader_dump_ins_modifiers(
1496 const DWORD output);
1498 extern void shader_dump_param(
1499 IWineD3DBaseShader *iface,
1501 const DWORD addr_token,
1504 extern void shader_trace_init(
1505 IWineD3DBaseShader *iface,
1506 const DWORD* pFunction);
1508 extern int shader_get_param(
1509 IWineD3DBaseShader* iface,
1510 const DWORD* pToken,
1514 extern int shader_skip_unrecognized(
1515 IWineD3DBaseShader* iface,
1516 const DWORD* pToken);
1518 extern void print_glsl_info_log(
1519 WineD3D_GL_Info *gl_info,
1522 inline static int shader_get_regtype(const DWORD param) {
1523 return (((param & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) |
1524 ((param & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2));
1527 extern unsigned int shader_get_float_offset(const DWORD reg);
1529 inline static BOOL shader_is_pshader_version(DWORD token) {
1530 return 0xFFFF0000 == (token & 0xFFFF0000);
1533 inline static BOOL shader_is_vshader_version(DWORD token) {
1534 return 0xFFFE0000 == (token & 0xFFFF0000);
1537 inline static BOOL shader_is_comment(DWORD token) {
1538 return D3DSIO_COMMENT == (token & D3DSI_OPCODE_MASK);
1541 /*****************************************************************************
1542 * IDirect3DVertexShader implementation structure
1544 typedef struct IWineD3DVertexShaderImpl {
1546 const IWineD3DVertexShaderVtbl *lpVtbl;
1547 LONG ref; /* Note: Ref counting not required */
1549 /* IWineD3DBaseShader */
1550 IWineD3DBaseShaderClass baseShader;
1552 /* IWineD3DVertexShaderImpl */
1554 IWineD3DDeviceImpl *wineD3DDevice;
1558 /* vertex declaration array mapping */
1559 DWORD arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE];
1561 /* run time datas... */
1563 IWineD3DVertexDeclaration *vertexDeclaration;
1564 #if 0 /* needs reworking */
1565 /* run time datas */
1566 VSHADERINPUTDATA input;
1567 VSHADEROUTPUTDATA output;
1569 } IWineD3DVertexShaderImpl;
1570 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1571 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1573 /*****************************************************************************
1574 * IDirect3DPixelShader implementation structure
1576 typedef struct IWineD3DPixelShaderImpl {
1577 /* IUnknown parts */
1578 const IWineD3DPixelShaderVtbl *lpVtbl;
1579 LONG ref; /* Note: Ref counting not required */
1581 /* IWineD3DBaseShader */
1582 IWineD3DBaseShaderClass baseShader;
1584 /* IWineD3DPixelShaderImpl */
1586 IWineD3DDeviceImpl *wineD3DDevice;
1591 #if 0 /* needs reworking */
1592 PSHADERINPUTDATA input;
1593 PSHADEROUTPUTDATA output;
1595 } IWineD3DPixelShaderImpl;
1597 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1598 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1600 /*****************************************************************************
1601 * IWineD3DPalette implementation structure
1603 struct IWineD3DPaletteImpl {
1604 /* IUnknown parts */
1605 const IWineD3DPaletteVtbl *lpVtbl;
1609 IWineD3DDeviceImpl *wineD3DDevice;
1611 /* IWineD3DPalette */
1613 WORD palVersion; /*| */
1614 WORD palNumEntries; /*| LOGPALETTE */
1615 PALETTEENTRY palents[256]; /*| */
1616 /* This is to store the palette in 'screen format' */
1617 int screen_palents[256];
1621 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
1622 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
1624 /* DirectDraw utility functions */
1625 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
1627 /*****************************************************************************
1628 * Pixel format management
1631 WINED3DFORMAT format;
1632 DWORD alphaMask, redMask, greenMask, blueMask;
1635 GLint glInternal, glFormat, glType;
1638 const PixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt);