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
139 #define SHADER_NONE 3
141 typedef struct wined3d_settings_s {
142 /* vertex and pixel shader modes */
146 /* Ideally, we don't want the user to have to request GLSL. If the hardware supports GLSL,
147 we should use it. However, until it's fully implemented, we'll leave it as a registry
148 setting for developers. */
150 int vs_selected_mode;
151 int ps_selected_mode;
152 /* nonpower 2 function */
154 } wined3d_settings_t;
156 extern wined3d_settings_t wined3d_settings;
160 extern void (*wine_tsx11_lock_ptr)(void);
161 extern void (*wine_tsx11_unlock_ptr)(void);
163 /* As GLX relies on X, this is needed */
167 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
168 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
170 #define ENTER_GL() wine_tsx11_lock_ptr()
171 #define LEAVE_GL() wine_tsx11_unlock_ptr()
174 /*****************************************************************************
178 /* GL related defines */
179 /* ------------------ */
180 #define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
181 #define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
182 #define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
183 #define GL_VEND(_VendName) (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
185 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
186 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
187 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
188 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
190 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
191 #define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
192 #define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
193 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
195 #define D3DCOLORTOGLFLOAT4(dw, vec) \
196 (vec)[0] = D3DCOLOR_R(dw); \
197 (vec)[1] = D3DCOLOR_G(dw); \
198 (vec)[2] = D3DCOLOR_B(dw); \
199 (vec)[3] = D3DCOLOR_A(dw);
201 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP_ARB
203 /* DirectX Device Limits */
204 /* --------------------- */
205 #define MAX_LEVELS 256 /* Maximum number of mipmap levels. Guessed at 256 */
207 #define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
208 See MaxStreams in MSDN under GetDeviceCaps */
209 /* Maximum number of constants provided to the shaders */
210 #define HIGHEST_TRANSFORMSTATE 512
211 /* Highest value in D3DTRANSFORMSTATETYPE */
212 #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
214 #define MAX_PALETTES 256
216 /* Checking of API calls */
217 /* --------------------- */
218 #define checkGLcall(A) \
220 GLint err = glGetError(); \
221 if (err == GL_NO_ERROR) { \
222 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
225 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", \
226 err, A, __FILE__, __LINE__); \
227 err = glGetError(); \
228 } while (err != GL_NO_ERROR); \
231 /* Trace routines / diagnostics */
232 /* ---------------------------- */
234 /* Dump out a matrix and copy it */
235 #define conv_mat(mat,gl_mat) \
237 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
238 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
239 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
240 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
241 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
244 /* Macro to dump out the current state of the light chain */
245 #define DUMP_LIGHT_CHAIN() \
247 PLIGHTINFOEL *el = This->stateBlock->lights;\
249 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
254 /* Trace vector and strided data information */
255 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
256 #define TRACE_STRIDED(sd,name) TRACE( #name "=(data:%p, stride:%ld, type:%ld)\n", sd->u.s.name.lpData, sd->u.s.name.dwStride, sd->u.s.name.dwType);
258 /* Defines used for optimizations */
260 /* Only reapply what is necessary */
261 #define REAPPLY_ALPHAOP 0x0001
262 #define REAPPLY_ALL 0xFFFF
264 /* Advance declaration of structures to satisfy compiler */
265 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
266 typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
267 typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl;
271 /* TODO: Move some of this to the device */
272 long globalChangeGlRam(long glram);
274 /* Memory and object tracking */
276 /*Structure for holding information on all direct3d objects
277 useful for making sure tracking is ok and when release is called on a device!
278 and probably quite handy for debugging and dumping states out
280 typedef struct WineD3DGlobalStatistics {
281 int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
282 } WineD3DGlobalStatistics;
284 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
286 /* Global variables */
287 extern const float identity[16];
289 /*****************************************************************************
290 * Compilable extra diagnostics
293 /* Trace information per-vertex: (extremely high amount of trace) */
294 #if 0 /* NOTE: Must be 0 in cvs */
295 # define VTRACE(A) TRACE A
300 /* Checking of per-vertex related GL calls */
301 /* --------------------- */
302 #define vcheckGLcall(A) \
304 GLint err = glGetError(); \
305 if (err == GL_NO_ERROR) { \
306 VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
309 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", \
310 err, A, __FILE__, __LINE__); \
311 err = glGetError(); \
312 } while (err != GL_NO_ERROR); \
315 /* TODO: Confirm each of these works when wined3d move completed */
316 #if 0 /* NOTE: Must be 0 in cvs */
317 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
318 of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
319 is enabled, and if it doesn't exists it is disabled. */
320 # define FRAME_DEBUGGING
321 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
322 the file is deleted */
323 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
324 # define SINGLE_FRAME_DEBUGGING
326 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
327 It can only be enabled when FRAME_DEBUGGING is also enabled
328 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
330 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
331 # define SHOW_FRAME_MAKEUP 1
333 /* The following, when enabled, lets you see the makeup of the all the textures used during each
334 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
335 The contents of the textures assigned to each stage are written into
336 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
337 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
338 # define SHOW_TEXTURE_MAKEUP 0
341 extern BOOL isDumpingFrames;
342 extern LONG primCounter;
345 /*****************************************************************************
349 /* Routine common to the draw primitive and draw indexed primitive routines */
350 void drawPrimitive(IWineD3DDevice *iface,
354 long StartVertexIndex,
355 UINT numberOfVertices,
360 WineDirect3DVertexStridedData *DrawPrimStrideData);
362 void primitiveConvertToStridedData(IWineD3DDevice *iface, WineDirect3DVertexStridedData *strided, LONG BaseVertexIndex, BOOL *fixup);
364 void primitiveDeclarationConvertToStridedData(
365 IWineD3DDevice *iface,
366 BOOL useVertexShaderFunction,
367 WineDirect3DVertexStridedData *strided,
368 LONG BaseVertexIndex,
372 void primitiveConvertFVFtoOffset(DWORD thisFVF,
375 WineDirect3DVertexStridedData *strided,
378 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
382 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
383 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
385 /* Routine to fill gl caps for swapchains and IWineD3D */
386 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info,
389 /*****************************************************************************
390 * Internal representation of a light
392 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
393 struct PLIGHTINFOEL {
394 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
401 /* Converted parms to speed up swapping lights */
411 /* The default light parameters */
412 extern const WINED3DLIGHT WINED3D_default_light;
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 /** Hacked out start of a context manager!! **/
435 typedef struct glContext {
442 IWineD3DSurface *pSurface;
443 #if 0 /* TODO: someway to represent the state of the context */
444 IWineD3DStateBlock *pStateBlock;
446 /* a few other things like format */
449 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
450 (since it will break quite a few things until contexts are managed properly!) */
451 extern BOOL pbuffer_support;
452 /* allocate one pbuffer per surface */
453 extern BOOL pbuffer_per_surface;
455 /* Maximum number of contexts/pbuffers to keep in cache,
456 set to 100 because ATI's drivers don't support deleting pBuffers properly
457 this needs to be migrated to a list and some option availalbe for controle the cache size.
459 #define CONTEXT_CACHE 100
461 typedef struct ResourceList {
462 IWineD3DResource *resource;
463 struct ResourceList *next;
466 /* A helper function that dumps a resource list */
467 void dumpResources(ResourceList *resources);
469 /*****************************************************************************
470 * IWineD3DDevice implementation structure
472 typedef struct IWineD3DDeviceImpl
474 /* IUnknown fields */
475 const IWineD3DDeviceVtbl *lpVtbl;
476 LONG ref; /* Note: Ref counting not required */
478 /* WineD3D Information */
482 /* X and GL Information */
483 GLint maxConcurrentLights;
486 BOOL modelview_valid;
488 BOOL view_ident; /* true iff view matrix is identity */
489 BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
490 BOOL viewport_changed; /* Was the viewport changed since the last draw? */
491 GLenum tracking_parm; /* Which source is tracking current colour */
492 LONG tracking_color; /* used iff GL_COLOR_MATERIAL was enabled */
493 #define DISABLED_TRACKING 0 /* Disabled */
494 #define IS_TRACKING 1 /* tracking_parm is tracking diffuse color */
495 #define NEEDS_TRACKING 2 /* Tracking needs to be enabled when needed */
496 #define NEEDS_DISABLE 3 /* Tracking needs to be disabled when needed*/
500 BOOL texture_shader_active; /* TODO: Confirm use is correct */
501 BOOL last_was_notclipped;
503 /* State block related */
504 BOOL isRecordingState;
505 IWineD3DStateBlockImpl *stateBlock;
506 IWineD3DStateBlockImpl *updateStateBlock;
508 /* Internal use fields */
509 WINED3DDEVICE_CREATION_PARAMETERS createParms;
513 IWineD3DSwapChain **swapchains;
514 uint NumberOfSwapChains;
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 */
546 BOOL d3d_initialized;
548 /* Screen buffer resources */
549 glContext contextCache[CONTEXT_CACHE];
551 /* A flag to check if endscene has been called before changing the render tartet */
554 /* process vertex shaders using software or hardware */
555 BOOL softwareVertexProcessing;
557 /* DirectDraw stuff */
559 IWineD3DSurface *ddraw_primary;
560 DWORD ddraw_width, ddraw_height;
561 WINED3DFORMAT ddraw_format;
563 /* List of GLSL shader programs and their associated vertex & pixel shaders */
564 struct list glsl_shader_progs;
566 } IWineD3DDeviceImpl;
568 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
570 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
571 * anybody uses it for much so a good implementation is optional. */
572 typedef struct PrivateData
574 struct PrivateData* next;
577 DWORD flags; /* DDSPD_* */
578 DWORD uniqueness_value;
589 void d3ddevice_set_ortho(IWineD3DDeviceImpl *This);
591 /*****************************************************************************
592 * IWineD3DResource implementation structure
594 typedef struct IWineD3DResourceClass
596 /* IUnknown fields */
597 LONG ref; /* Note: Ref counting not required */
599 /* WineD3DResource Information */
601 WINED3DRESOURCETYPE resourceType;
602 IWineD3DDeviceImpl *wineD3DDevice;
606 WINED3DFORMAT format;
607 BYTE *allocatedMemory;
608 PrivateData *privateData;
610 } IWineD3DResourceClass;
612 typedef struct IWineD3DResourceImpl
614 /* IUnknown & WineD3DResource Information */
615 const IWineD3DResourceVtbl *lpVtbl;
616 IWineD3DResourceClass resource;
617 } IWineD3DResourceImpl;
620 /*****************************************************************************
621 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
623 typedef struct IWineD3DVertexBufferImpl
625 /* IUnknown & WineD3DResource Information */
626 const IWineD3DVertexBufferVtbl *lpVtbl;
627 IWineD3DResourceClass resource;
629 /* WineD3DVertexBuffer specifics */
632 /* Vertex buffer object support */
637 UINT dirtystart, dirtyend;
640 /* Last description of the buffer */
641 WineDirect3DVertexStridedData strided;
642 } IWineD3DVertexBufferImpl;
644 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
646 #define VBFLAG_LOAD 0x01 /* Data is written from allocatedMemory to the VBO */
647 #define VBFLAG_OPTIMIZED 0x02 /* Optimize has been called for the VB */
648 #define VBFLAG_DIRTY 0x04 /* Buffer data has been modified */
649 #define VBFLAG_STREAM 0x08 /* The vertex buffer is in a stream */
650 #define VBFLAG_HASDESC 0x10 /* A vertex description has been found */
652 /*****************************************************************************
653 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
655 typedef struct IWineD3DIndexBufferImpl
657 /* IUnknown & WineD3DResource Information */
658 const IWineD3DIndexBufferVtbl *lpVtbl;
659 IWineD3DResourceClass resource;
661 /* WineD3DVertexBuffer specifics */
662 } IWineD3DIndexBufferImpl;
664 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
666 /*****************************************************************************
667 * IWineD3DBaseTexture D3D- > openGL state map lookups
669 #define WINED3DFUNC_NOTSUPPORTED -2
670 #define WINED3DFUNC_UNIMPLEMENTED -1
672 typedef enum winetexturestates {
673 WINED3DTEXSTA_ADDRESSU = 0,
674 WINED3DTEXSTA_ADDRESSV = 1,
675 WINED3DTEXSTA_ADDRESSW = 2,
676 WINED3DTEXSTA_BORDERCOLOR = 3,
677 WINED3DTEXSTA_MAGFILTER = 4,
678 WINED3DTEXSTA_MINFILTER = 5,
679 WINED3DTEXSTA_MIPFILTER = 6,
680 WINED3DTEXSTA_MAXMIPLEVEL = 7,
681 WINED3DTEXSTA_MAXANISOTROPY = 8,
682 WINED3DTEXSTA_SRGBTEXTURE = 9,
683 WINED3DTEXSTA_ELEMENTINDEX = 10,
684 WINED3DTEXSTA_DMAPOFFSET = 11,
685 WINED3DTEXSTA_TSSADDRESSW = 12,
686 MAX_WINETEXTURESTATES = 13,
689 typedef struct Wined3dTextureStateMap {
692 } Wined3dTextureStateMap;
694 /*****************************************************************************
695 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
697 typedef struct IWineD3DBaseTextureClass
705 WINED3DTEXTUREFILTERTYPE filterType;
706 DWORD states[MAX_WINETEXTURESTATES];
708 } IWineD3DBaseTextureClass;
710 typedef struct IWineD3DBaseTextureImpl
712 /* IUnknown & WineD3DResource Information */
713 const IWineD3DBaseTextureVtbl *lpVtbl;
714 IWineD3DResourceClass resource;
715 IWineD3DBaseTextureClass baseTexture;
717 } IWineD3DBaseTextureImpl;
719 /*****************************************************************************
720 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
722 typedef struct IWineD3DTextureImpl
724 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
725 const IWineD3DTextureVtbl *lpVtbl;
726 IWineD3DResourceClass resource;
727 IWineD3DBaseTextureClass baseTexture;
729 /* IWineD3DTexture */
730 IWineD3DSurface *surfaces[MAX_LEVELS];
734 float pow2scalingFactorX;
735 float pow2scalingFactorY;
737 } IWineD3DTextureImpl;
739 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
741 /*****************************************************************************
742 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
744 typedef struct IWineD3DCubeTextureImpl
746 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
747 const IWineD3DCubeTextureVtbl *lpVtbl;
748 IWineD3DResourceClass resource;
749 IWineD3DBaseTextureClass baseTexture;
751 /* IWineD3DCubeTexture */
752 IWineD3DSurface *surfaces[6][MAX_LEVELS];
755 float pow2scalingFactor;
757 } IWineD3DCubeTextureImpl;
759 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
761 typedef struct _WINED3DVOLUMET_DESC
766 } WINED3DVOLUMET_DESC;
768 /*****************************************************************************
769 * IWineD3DVolume implementation structure (extends IUnknown)
771 typedef struct IWineD3DVolumeImpl
773 /* IUnknown & WineD3DResource fields */
774 const IWineD3DVolumeVtbl *lpVtbl;
775 IWineD3DResourceClass resource;
777 /* WineD3DVolume Information */
778 WINED3DVOLUMET_DESC currentDesc;
779 IWineD3DBase *container;
784 WINED3DBOX lockedBox;
789 } IWineD3DVolumeImpl;
791 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
793 /*****************************************************************************
794 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
796 typedef struct IWineD3DVolumeTextureImpl
798 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
799 const IWineD3DVolumeTextureVtbl *lpVtbl;
800 IWineD3DResourceClass resource;
801 IWineD3DBaseTextureClass baseTexture;
803 /* IWineD3DVolumeTexture */
804 IWineD3DVolume *volumes[MAX_LEVELS];
809 } IWineD3DVolumeTextureImpl;
811 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
813 typedef struct _WINED3DSURFACET_DESC
815 WINED3DMULTISAMPLE_TYPE MultiSampleType;
816 DWORD MultiSampleQuality;
819 } WINED3DSURFACET_DESC;
821 /*****************************************************************************
822 * Structure for DIB Surfaces (GetDC and GDI surfaces)
824 typedef struct wineD3DSurface_DIB {
829 } wineD3DSurface_DIB;
831 /*****************************************************************************
832 * IWineD3DSurface implementation structure
834 struct IWineD3DSurfaceImpl
836 /* IUnknown & IWineD3DResource Information */
837 const IWineD3DSurfaceVtbl *lpVtbl;
838 IWineD3DResourceClass resource;
840 /* IWineD3DSurface fields */
841 IWineD3DBase *container;
842 WINED3DSURFACET_DESC currentDesc;
843 IWineD3DPaletteImpl *palette;
848 /* TODO: move this off into a management class(maybe!) */
855 /* Oversized texture */
859 /* precalculated x and y scalings for texture coords */
860 float pow2scalingFactorX; /* = (Width / pow2Width ) */
861 float pow2scalingFactorY; /* = (Height / pow2Height) */
867 glDescriptor glDescription;
870 wineD3DSurface_DIB dib;
873 /* Color keys for DDraw */
874 DDCOLORKEY DestBltCKey;
875 DDCOLORKEY DestOverlayCKey;
876 DDCOLORKEY SrcOverlayCKey;
877 DDCOLORKEY SrcBltCKey;
882 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
883 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
885 /* Predeclare the shared Surface functions */
886 HRESULT WINAPI IWineD3DSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
887 ULONG WINAPI IWineD3DSurfaceImpl_AddRef(IWineD3DSurface *iface);
888 ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface);
889 HRESULT WINAPI IWineD3DSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
890 HRESULT WINAPI IWineD3DSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
891 HRESULT WINAPI IWineD3DSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
892 HRESULT WINAPI IWineD3DSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
893 HRESULT WINAPI IWineD3DSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
894 DWORD WINAPI IWineD3DSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
895 DWORD WINAPI IWineD3DSurfaceImpl_GetPriority(IWineD3DSurface *iface);
896 void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface);
897 WINED3DRESOURCETYPE WINAPI IWineD3DSurfaceImpl_GetType(IWineD3DSurface *iface);
898 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainerParent(IWineD3DSurface* iface, IUnknown **ppContainerParent);
899 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
900 HRESULT WINAPI IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
901 HRESULT WINAPI IWineD3DSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
902 HRESULT WINAPI IWineD3DSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
903 HRESULT WINAPI IWineD3DSurfaceImpl_IsLost(IWineD3DSurface *iface);
904 HRESULT WINAPI IWineD3DSurfaceImpl_Restore(IWineD3DSurface *iface);
905 HRESULT WINAPI IWineD3DSurfaceImpl_SetPixelFormat(IWineD3DSurface *iface, WINED3DFORMAT Format, BYTE *Surface, DWORD Size);
906 HRESULT WINAPI IWineD3DSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
907 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
908 HRESULT WINAPI IWineD3DSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, DDCOLORKEY *CKey);
909 HRESULT WINAPI IWineD3DSurfaceImpl_CleanDirtyRect(IWineD3DSurface *iface);
910 extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect);
911 HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
912 HRESULT WINAPI IWineD3DSurfaceImpl_SetPBufferState(IWineD3DSurface *iface, BOOL inPBuffer, BOOL inTexture);
913 void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target);
914 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription);
915 const void *WINAPI IWineD3DSurfaceImpl_GetData(IWineD3DSurface *iface);
916 HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
917 HRESULT WINAPI IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx);
918 HRESULT WINAPI IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty, IWineD3DSurface *Source, RECT *rsrc, DWORD trans);
919 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
920 HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC);
921 HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC);
922 DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface);
923 HRESULT WINAPI IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
926 #define SFLAG_OVERSIZE 0x0001 /* Surface is bigger than gl size, blts only */
927 #define SFLAG_CONVERTED 0x0002 /* Converted for color keying or Palettized */
928 #define SFLAG_DIBSECTION 0x0004 /* Has a DIB section attached for getdc */
929 #define SFLAG_DIRTY 0x0008 /* Surface was locked by the app */
930 #define SFLAG_LOCKABLE 0x0010 /* Surface can be locked */
931 #define SFLAG_DISCARD 0x0020 /* ??? */
932 #define SFLAG_LOCKED 0x0040 /* Surface is locked atm */
933 #define SFLAG_ACTIVELOCK 0x0080 /* Not locked, but surface memory is needed */
934 #define SFLAG_INTEXTURE 0x0100 /* ??? */
935 #define SFLAG_INPBUFFER 0x0200 /* ??? */
936 #define SFLAG_NONPOW2 0x0400 /* Surface sizes are not a power of 2 */
937 #define SFLAG_DYNLOCK 0x0800 /* Surface is often locked by the app */
938 #define SFLAG_DYNCHANGE 0x1800 /* Surface contents are changed very often, implies DYNLOCK */
939 #define SFLAG_DCINUSE 0x2000 /* Set between GetDC and ReleaseDC calls */
940 #define SFLAG_GLDIRTY 0x4000 /* The opengl texture is more up to date than the surface mem */
941 #define SFLAG_LOST 0x8000 /* Surface lost flag for DDraw */
943 /* In some conditions the surface memory must not be freed:
944 * SFLAG_OVERSIZE: Not all data can be kept in GL
945 * SFLAG_CONVERTED: Converting the data back would take too long
946 * SFLAG_DIBSECTION: The dib code manages the memory
947 * SFLAG_DIRTY: GL surface isn't up to date
948 * SFLAG_LOCKED: The app requires access to the surface data
949 * SFLAG_ACTIVELOCK: Some wined3d code needs the memory
950 * SFLAG_DYNLOCK: Avoid freeing the data for performance
951 * SFLAG_DYNCHANGE: Same reason as DYNLOCK
953 #define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
962 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
964 /*****************************************************************************
965 * IWineD3DVertexDeclaration implementation structure
967 typedef struct IWineD3DVertexDeclarationImpl {
968 /* IUnknown Information */
969 const IWineD3DVertexDeclarationVtbl *lpVtbl;
970 LONG ref; /* Note: Ref counting not required */
973 /** precomputed fvf if simple declaration */
974 IWineD3DDeviceImpl *wineD3DDevice;
975 DWORD fvf[MAX_STREAMS];
978 /** dx8 compatible Declaration fields */
979 DWORD* pDeclaration8;
980 DWORD declaration8Length;
983 D3DVERTEXELEMENT9 *pDeclaration9;
984 UINT declaration9NumElements;
986 WINED3DVERTEXELEMENT *pDeclarationWine;
987 UINT declarationWNumElements;
991 } IWineD3DVertexDeclarationImpl;
993 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
995 /*****************************************************************************
996 * IWineD3DStateBlock implementation structure
999 /* Internal state Block for Begin/End/Capture/Create/Apply info */
1000 /* Note: Very long winded but gl Lists are not flexible enough */
1001 /* to resolve everything we need, so doing it manually for now */
1002 typedef struct SAVEDSTATES {
1006 BOOL streamSource[MAX_STREAMS];
1007 BOOL streamFreq[MAX_STREAMS];
1008 BOOL textures[MAX_SAMPLERS];
1009 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
1011 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
1012 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1013 BOOL samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1014 BOOL clipplane[MAX_CLIPPLANES];
1017 BOOL pixelShaderConstantsB[MAX_PSHADER_CONSTANTS];
1018 BOOL pixelShaderConstantsI[MAX_PSHADER_CONSTANTS];
1019 BOOL pixelShaderConstantsF[MAX_PSHADER_CONSTANTS];
1021 BOOL vertexShaderConstantsB[MAX_VSHADER_CONSTANTS];
1022 BOOL vertexShaderConstantsI[MAX_VSHADER_CONSTANTS];
1023 BOOL vertexShaderConstantsF[MAX_VSHADER_CONSTANTS];
1026 struct IWineD3DStateBlockImpl
1028 /* IUnknown fields */
1029 const IWineD3DStateBlockVtbl *lpVtbl;
1030 LONG ref; /* Note: Ref counting not required */
1032 /* IWineD3DStateBlock information */
1034 IWineD3DDeviceImpl *wineD3DDevice;
1035 WINED3DSTATEBLOCKTYPE blockType;
1037 /* Array indicating whether things have been set or changed */
1038 SAVEDSTATES changed;
1041 /* Drawing - Vertex Shader or FVF related */
1043 /* Vertex Shader Declaration */
1044 IWineD3DVertexDeclaration *vertexDecl;
1046 IWineD3DVertexShader *vertexShader;
1048 /* Vertex Shader Constants */
1049 BOOL vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
1050 INT vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
1051 float vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
1055 UINT streamStride[MAX_STREAMS];
1056 UINT streamOffset[MAX_STREAMS];
1057 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
1058 UINT streamFreq[MAX_STREAMS];
1059 UINT streamFlags[MAX_STREAMS]; /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA */
1062 IWineD3DIndexBuffer* pIndexData;
1063 UINT baseVertexIndex; /* Note: only used for d3d8 */
1066 D3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
1069 PLIGHTINFOEL *lights; /* NOTE: active GL lights must be front of the chain */
1072 double clipplane[MAX_CLIPPLANES][4];
1073 WINED3DCLIPSTATUS clip_status;
1076 WINED3DVIEWPORT viewport;
1079 WINED3DMATERIAL material;
1082 IWineD3DPixelShader *pixelShader;
1084 /* Pixel Shader Constants */
1085 BOOL pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
1086 INT pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
1087 float pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
1089 /* Indexed Vertex Blending */
1090 D3DVERTEXBLENDFLAGS vertex_blend;
1094 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
1097 IWineD3DBaseTexture *textures[MAX_SAMPLERS];
1098 int textureDimensions[MAX_SAMPLERS];
1100 /* Texture State Stage */
1101 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1102 /* Sampler States */
1103 DWORD samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1105 /* Current GLSL Shader Program */
1106 GLhandleARB shaderPrgId;
1109 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1111 /*****************************************************************************
1112 * IWineD3DQueryImpl implementation structure (extends IUnknown)
1114 typedef struct IWineD3DQueryImpl
1116 const IWineD3DQueryVtbl *lpVtbl;
1117 LONG ref; /* Note: Ref counting not required */
1120 /*TODO: replace with iface usage */
1122 IWineD3DDevice *wineD3DDevice;
1124 IWineD3DDeviceImpl *wineD3DDevice;
1126 /* IWineD3DQuery fields */
1129 /* TODO: Think about using a IUnknown instead of a void* */
1133 } IWineD3DQueryImpl;
1135 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1137 /* Datastructures for IWineD3DQueryImpl.extendedData */
1138 typedef struct WineQueryOcclusionData {
1139 unsigned int queryId;
1140 } WineQueryOcclusionData;
1143 /*****************************************************************************
1144 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1147 typedef struct IWineD3DSwapChainImpl
1150 IWineD3DSwapChainVtbl *lpVtbl;
1151 LONG ref; /* Note: Ref counting not required */
1154 IWineD3DDeviceImpl *wineD3DDevice;
1156 /* IWineD3DSwapChain fields */
1157 IWineD3DSurface **backBuffer;
1158 IWineD3DSurface *frontBuffer;
1159 BOOL wantsDepthStencilBuffer;
1160 D3DPRESENT_PARAMETERS presentParms;
1162 /* TODO: move everything up to drawable off into a context manager
1163 and store the 'data' in the contextManagerData interface.
1164 IUnknown *contextManagerData;
1172 XVisualInfo *visInfo;
1173 GLXContext render_ctx;
1174 /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1176 } IWineD3DSwapChainImpl;
1178 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1180 /*****************************************************************************
1181 * Utility function prototypes
1184 /* Trace routines */
1185 const char* debug_d3dformat(WINED3DFORMAT fmt);
1186 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1187 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1188 const char* debug_d3dusage(DWORD usage);
1189 const char* debug_d3ddeclusage(BYTE usage);
1190 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1191 const char* debug_d3drenderstate(DWORD state);
1192 const char* debug_d3dsamplerstate(DWORD state);
1193 const char* debug_d3dtexturestate(DWORD state);
1194 const char* debug_d3dpool(WINED3DPOOL pool);
1196 /* Routines for GL <-> D3D values */
1197 GLenum StencilOp(DWORD op);
1198 GLenum StencilFunc(DWORD func);
1199 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1200 void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx);
1201 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1203 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1206 void multiply_matrix(D3DMATRIX *dest, D3DMATRIX *src1, D3DMATRIX *src2);
1208 /*****************************************************************************
1209 * To enable calling of inherited functions, requires prototypes
1211 * Note: Only require classes which are subclassed, ie resource, basetexture,
1213 /*** IUnknown methods ***/
1214 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1215 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1216 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1217 /*** IWineD3DResource methods ***/
1218 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1219 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1220 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1221 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1222 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1223 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1224 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1225 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1226 extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1227 /*** class static members ***/
1228 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1230 /*** IUnknown methods ***/
1231 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1232 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1233 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1234 /*** IWineD3DResource methods ***/
1235 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1236 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1237 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1238 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1239 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1240 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1241 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1242 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1243 extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1244 /*** IWineD3DBaseTexture methods ***/
1245 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1246 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1247 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1248 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1249 extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1250 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1251 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1252 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1254 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset, GLint *vbo);
1255 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1256 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1257 extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1258 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1259 /*** class static members ***/
1260 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1262 struct SHADER_OPCODE_ARG;
1263 typedef void (*shader_fct_t)();
1264 typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
1266 /* Struct to maintain a list of GLSL shader programs and their associated pixel and
1267 * vertex shaders. A list of this type is maintained on the DeviceImpl, and is only
1268 * used if the user is using GLSL shaders. */
1269 struct glsl_shader_prog_link {
1271 GLhandleARB programId;
1272 IWineD3DVertexShader* vertexShader;
1273 IWineD3DPixelShader* pixelShader;
1276 /* TODO: Make this dynamic, based on shader limits ? */
1277 #define MAX_REG_ADDR 1
1278 #define MAX_REG_TEMP 32
1279 #define MAX_REG_TEXCRD 8
1280 #define MAX_REG_INPUT 12
1281 #define MAX_REG_OUTPUT 12
1282 #define MAX_ATTRIBS 16
1283 #define MAX_CONST_F 256
1284 #define MAX_CONST_I 16
1285 #define MAX_CONST_B 16
1287 typedef struct shader_reg_maps {
1289 char texcoord[MAX_REG_TEXCRD]; /* pixel < 3.0 */
1290 char temporary[MAX_REG_TEMP]; /* pixel, vertex */
1291 char address[MAX_REG_ADDR]; /* vertex */
1292 char packed_input[MAX_REG_INPUT]; /* pshader >= 3.0 */
1293 char packed_output[MAX_REG_OUTPUT]; /* vertex >= 3.0 */
1294 char attributes[MAX_ATTRIBS]; /* vertex */
1296 char constantsF[MAX_CONST_F]; /* pixel, vertex */
1297 char constantsI[MAX_CONST_I]; /* pixel & vertex >= 2.0 */
1298 char constantsB[MAX_CONST_B]; /* pixel & vertex >= 2.0 */
1300 /* Sampler usage tokens
1301 * Use 0 as default (bit 31 is always 1 on a valid token) */
1302 DWORD samplers[MAX_SAMPLERS];
1304 /* Whether or not a loop is used in this shader */
1309 #define SHADER_PGMSIZE 65535
1310 typedef struct SHADER_BUFFER {
1313 unsigned int lineNo;
1316 typedef struct SHADER_OPCODE {
1317 unsigned int opcode;
1321 CONST UINT num_params;
1322 shader_fct_t soft_fct;
1323 SHADER_HANDLER hw_fct;
1324 SHADER_HANDLER hw_glsl_fct;
1329 typedef struct SHADER_OPCODE_ARG {
1330 IWineD3DBaseShader* shader;
1331 shader_reg_maps* reg_maps;
1332 CONST SHADER_OPCODE* opcode;
1338 SHADER_BUFFER* buffer;
1339 } SHADER_OPCODE_ARG;
1341 typedef struct SHADER_LIMITS {
1342 unsigned int temporary;
1343 unsigned int texcoord;
1344 unsigned int sampler;
1345 unsigned int constant_int;
1346 unsigned int constant_float;
1347 unsigned int constant_bool;
1348 unsigned int address;
1349 unsigned int packed_output;
1350 unsigned int packed_input;
1351 unsigned int attributes;
1354 /** Keeps track of details for TEX_M#x# shader opcodes which need to
1355 maintain state information between multiple codes */
1356 typedef struct SHADER_PARSE_STATE {
1357 unsigned int current_row;
1358 DWORD texcoord_w[2];
1359 } SHADER_PARSE_STATE;
1361 /* Base Shader utility functions.
1362 * (may move callers into the same file in the future) */
1363 extern int shader_addline(
1364 SHADER_BUFFER* buffer,
1365 const char* fmt, ...);
1367 extern const SHADER_OPCODE* shader_get_opcode(
1368 IWineD3DBaseShader *iface,
1371 /* ARB_[vertex/fragment]_program helper functions */
1372 extern void shader_arb_load_constants(
1373 IWineD3DStateBlock* iface,
1374 char usePixelShader,
1375 char useVertexShader);
1377 /* ARB shader program Prototypes */
1378 extern void shader_hw_def(SHADER_OPCODE_ARG *arg);
1380 /* ARB pixel shader prototypes */
1381 extern void pshader_hw_cnd(SHADER_OPCODE_ARG* arg);
1382 extern void pshader_hw_cmp(SHADER_OPCODE_ARG* arg);
1383 extern void pshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1384 extern void pshader_hw_tex(SHADER_OPCODE_ARG* arg);
1385 extern void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg);
1386 extern void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg);
1387 extern void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg);
1388 extern void pshader_hw_texbem(SHADER_OPCODE_ARG* arg);
1389 extern void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG* arg);
1390 extern void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg);
1391 extern void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg);
1392 extern void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg);
1393 extern void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg);
1394 extern void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1396 /* ARB vertex shader prototypes */
1397 extern void vshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1398 extern void vshader_hw_mnxn(SHADER_OPCODE_ARG* arg);
1400 /* GLSL helper functions */
1401 extern void set_glsl_shader_program(IWineD3DDevice *iface);
1402 extern void shader_glsl_add_instruction_modifiers(SHADER_OPCODE_ARG *arg);
1403 extern void shader_glsl_load_constants(
1404 IWineD3DStateBlock* iface,
1405 char usePixelShader,
1406 char useVertexShader);
1408 /** The following translate DirectX pixel/vertex shader opcodes to GLSL lines */
1409 extern void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg);
1410 extern void shader_glsl_arith(SHADER_OPCODE_ARG* arg);
1411 extern void shader_glsl_mov(SHADER_OPCODE_ARG* arg);
1412 extern void shader_glsl_mad(SHADER_OPCODE_ARG* arg);
1413 extern void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg);
1414 extern void shader_glsl_lrp(SHADER_OPCODE_ARG* arg);
1415 extern void shader_glsl_dot(SHADER_OPCODE_ARG* arg);
1416 extern void shader_glsl_rcp(SHADER_OPCODE_ARG* arg);
1417 extern void shader_glsl_cnd(SHADER_OPCODE_ARG* arg);
1418 extern void shader_glsl_compare(SHADER_OPCODE_ARG* arg);
1419 extern void shader_glsl_def(SHADER_OPCODE_ARG* arg);
1420 extern void shader_glsl_defi(SHADER_OPCODE_ARG* arg);
1421 extern void shader_glsl_defb(SHADER_OPCODE_ARG* arg);
1422 extern void shader_glsl_cmp(SHADER_OPCODE_ARG* arg);
1423 extern void shader_glsl_lit(SHADER_OPCODE_ARG* arg);
1424 extern void shader_glsl_dst(SHADER_OPCODE_ARG* arg);
1425 extern void shader_glsl_sincos(SHADER_OPCODE_ARG* arg);
1426 extern void shader_glsl_loop(SHADER_OPCODE_ARG* arg);
1427 extern void shader_glsl_endloop(SHADER_OPCODE_ARG* arg);
1429 /** GLSL Pixel Shader Prototypes */
1430 extern void pshader_glsl_tex(SHADER_OPCODE_ARG* arg);
1431 extern void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg);
1432 extern void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg);
1433 extern void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg);
1434 extern void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg);
1435 extern void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1436 extern void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg);
1437 extern void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg);
1438 extern void pshader_glsl_dp2add(SHADER_OPCODE_ARG* arg);
1439 extern void pshader_glsl_input_pack(
1440 SHADER_BUFFER* buffer,
1441 DWORD* semantics_out);
1443 /** GLSL Vertex Shader Prototypes */
1444 extern void vshader_glsl_output_unpack(
1445 SHADER_BUFFER* buffer,
1446 DWORD* semantics_out);
1448 /*****************************************************************************
1449 * IDirect3DBaseShader implementation structure
1451 typedef struct IWineD3DBaseShaderClass
1454 SHADER_LIMITS limits;
1455 SHADER_PARSE_STATE parse_state;
1456 CONST SHADER_OPCODE *shader_ins;
1457 CONST DWORD *function;
1458 UINT functionLength;
1461 /* Type of shader backend */
1464 } IWineD3DBaseShaderClass;
1466 typedef struct IWineD3DBaseShaderImpl {
1468 const IWineD3DBaseShaderVtbl *lpVtbl;
1471 /* IWineD3DBaseShader */
1472 IWineD3DBaseShaderClass baseShader;
1473 } IWineD3DBaseShaderImpl;
1475 extern void shader_get_registers_used(
1476 IWineD3DBaseShader *iface,
1477 shader_reg_maps* reg_maps,
1478 DWORD* semantics_in,
1479 DWORD* semantics_out,
1480 CONST DWORD* pToken);
1482 extern void shader_generate_glsl_declarations(
1483 IWineD3DBaseShader *iface,
1484 shader_reg_maps* reg_maps,
1485 SHADER_BUFFER* buffer);
1487 extern void shader_generate_arb_declarations(
1488 IWineD3DBaseShader *iface,
1489 shader_reg_maps* reg_maps,
1490 SHADER_BUFFER* buffer);
1492 extern void shader_generate_main(
1493 IWineD3DBaseShader *iface,
1494 SHADER_BUFFER* buffer,
1495 shader_reg_maps* reg_maps,
1496 CONST DWORD* pFunction);
1498 extern void shader_dump_ins_modifiers(
1499 const DWORD output);
1501 extern void shader_dump_param(
1502 IWineD3DBaseShader *iface,
1504 const DWORD addr_token,
1507 extern void shader_trace_init(
1508 IWineD3DBaseShader *iface,
1509 const DWORD* pFunction);
1511 extern int shader_get_param(
1512 IWineD3DBaseShader* iface,
1513 const DWORD* pToken,
1517 extern int shader_skip_unrecognized(
1518 IWineD3DBaseShader* iface,
1519 const DWORD* pToken);
1521 extern void print_glsl_info_log(
1522 WineD3D_GL_Info *gl_info,
1525 inline static int shader_get_regtype(const DWORD param) {
1526 return (((param & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) |
1527 ((param & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2));
1530 extern unsigned int shader_get_float_offset(const DWORD reg);
1532 inline static BOOL shader_is_pshader_version(DWORD token) {
1533 return 0xFFFF0000 == (token & 0xFFFF0000);
1536 inline static BOOL shader_is_vshader_version(DWORD token) {
1537 return 0xFFFE0000 == (token & 0xFFFF0000);
1540 inline static BOOL shader_is_comment(DWORD token) {
1541 return D3DSIO_COMMENT == (token & D3DSI_OPCODE_MASK);
1544 /*****************************************************************************
1545 * IDirect3DVertexShader implementation structure
1547 typedef struct IWineD3DVertexShaderImpl {
1549 const IWineD3DVertexShaderVtbl *lpVtbl;
1550 LONG ref; /* Note: Ref counting not required */
1552 /* IWineD3DBaseShader */
1553 IWineD3DBaseShaderClass baseShader;
1555 /* IWineD3DVertexShaderImpl */
1557 IWineD3DDeviceImpl *wineD3DDevice;
1561 /* Vertex shader input and output semantics */
1562 DWORD semantics_in [WINED3DSHADERDECLUSAGE_MAX_USAGE];
1563 DWORD semantics_out [WINED3DSHADERDECLUSAGE_MAX_USAGE];
1565 /* run time datas... */
1567 IWineD3DVertexDeclaration *vertexDeclaration;
1568 #if 0 /* needs reworking */
1569 /* run time datas */
1570 VSHADERINPUTDATA input;
1571 VSHADEROUTPUTDATA output;
1573 } IWineD3DVertexShaderImpl;
1574 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1575 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1577 /*****************************************************************************
1578 * IDirect3DPixelShader implementation structure
1580 typedef struct IWineD3DPixelShaderImpl {
1581 /* IUnknown parts */
1582 const IWineD3DPixelShaderVtbl *lpVtbl;
1583 LONG ref; /* Note: Ref counting not required */
1585 /* IWineD3DBaseShader */
1586 IWineD3DBaseShaderClass baseShader;
1588 /* IWineD3DPixelShaderImpl */
1590 IWineD3DDeviceImpl *wineD3DDevice;
1592 /* Pixel shader input semantics */
1593 DWORD semantics_in [WINED3DSHADERDECLUSAGE_MAX_USAGE];
1598 #if 0 /* needs reworking */
1599 PSHADERINPUTDATA input;
1600 PSHADEROUTPUTDATA output;
1602 } IWineD3DPixelShaderImpl;
1604 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1605 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1607 /*****************************************************************************
1608 * IWineD3DPalette implementation structure
1610 struct IWineD3DPaletteImpl {
1611 /* IUnknown parts */
1612 const IWineD3DPaletteVtbl *lpVtbl;
1616 IWineD3DDeviceImpl *wineD3DDevice;
1618 /* IWineD3DPalette */
1620 WORD palVersion; /*| */
1621 WORD palNumEntries; /*| LOGPALETTE */
1622 PALETTEENTRY palents[256]; /*| */
1623 /* This is to store the palette in 'screen format' */
1624 int screen_palents[256];
1628 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
1629 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
1631 /* DirectDraw utility functions */
1632 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
1634 /*****************************************************************************
1635 * Pixel format management
1638 WINED3DFORMAT format;
1639 DWORD alphaMask, redMask, greenMask, blueMask;
1642 GLint glInternal, glFormat, glType;
1645 const PixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt);