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
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef __WINE_WINED3D_PRIVATE_H
24 #define __WINE_WINED3D_PRIVATE_H
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
40 #include "d3d9types.h"
41 #include "wine/wined3d_interface.h"
42 #include "wine/wined3d_gl.h"
55 extern void (*wine_tsx11_lock_ptr
)(void);
56 extern void (*wine_tsx11_unlock_ptr
)(void);
58 /* As GLX relies on X, this is needed */
62 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
63 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
65 #define ENTER_GL() wine_tsx11_lock_ptr()
66 #define LEAVE_GL() wine_tsx11_unlock_ptr()
69 /*****************************************************************************
73 /* GL related defines */
74 /* ------------------ */
75 #define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
76 #define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
77 #define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
79 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
80 #define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
81 #define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
82 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
84 #define D3DCOLORTOGLFLOAT4(dw, vec) \
85 (vec)[0] = D3DCOLOR_R(dw); \
86 (vec)[1] = D3DCOLOR_G(dw); \
87 (vec)[2] = D3DCOLOR_B(dw); \
88 (vec)[3] = D3DCOLOR_A(dw);
90 /* Note: The following is purely to keep the source code as clear from #ifdefs as possible */
91 #if defined(GL_VERSION_1_3)
92 #define GLACTIVETEXTURE(textureNo) \
93 glActiveTexture(GL_TEXTURE0 + textureNo); \
94 checkGLcall("glActiveTexture");
95 #define GLMULTITEXCOORD1F(a,b) \
96 glMultiTexCoord1f(GL_TEXTURE0 + a, b);
97 #define GLMULTITEXCOORD2F(a,b,c) \
98 glMultiTexCoord2f(GL_TEXTURE0 + a, b, c);
99 #define GLMULTITEXCOORD3F(a,b,c,d) \
100 glMultiTexCoord3f(GL_TEXTURE0 + a, b, c, d);
101 #define GLMULTITEXCOORD4F(a,b,c,d,e) \
102 glMultiTexCoord4f(GL_TEXTURE0 + a, b, c, d, e);
104 #define GLACTIVETEXTURE(textureNo) \
105 glActiveTextureARB(GL_TEXTURE0_ARB + textureNo); \
106 checkGLcall("glActiveTextureARB");
107 #define GLMULTITEXCOORD1F(a,b) \
108 glMultiTexCoord1fARB(GL_TEXTURE0_ARB + a, b);
109 #define GLMULTITEXCOORD2F(a,b,c) \
110 glMultiTexCoord2fARB(GL_TEXTURE0_ARB + a, b, c);
111 #define GLMULTITEXCOORD3F(a,b,c,d) \
112 glMultiTexCoord3fARB(GL_TEXTURE0_ARB + a, b, c, d);
113 #define GLMULTITEXCOORD4F(a,b,c,d,e) \
114 glMultiTexCoord4fARB(GL_TEXTURE0_ARB + a, b, c, d, e);
117 /* DirectX Device Limits */
118 /* --------------------- */
119 #define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
120 See MaxStreams in MSDN under GetDeviceCaps */
121 #define HIGHEST_TRANSFORMSTATE 512
122 /* Highest value in D3DTRANSFORMSTATETYPE */
123 #define HIGHEST_RENDER_STATE 209
124 /* Highest D3DRS_ value */
125 #define HIGHEST_TEXTURE_STATE 32
126 /* Highest D3DTSS_ value */
127 #define WINED3D_VSHADER_MAX_CONSTANTS 96
128 /* Maximum number of constants provided to the shaders */
129 #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
131 #define MAX_PALETTES 256
133 /* Checking of API calls */
134 /* --------------------- */
135 #define checkGLcall(A) \
137 GLint err = glGetError(); \
138 if (err != GL_NO_ERROR) { \
139 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
141 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
145 /* Trace routines / diagnostics */
146 /* ---------------------------- */
148 /* Dump out a matrix and copy it */
149 #define conv_mat(mat,gl_mat) \
151 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
152 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
153 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
154 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
155 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
158 /* Macro to dump out the current state of the light chain */
159 #define DUMP_LIGHT_CHAIN() \
161 PLIGHTINFOEL *el = This->stateBlock->lights;\
163 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
168 /* Trace vector and strided data information */
169 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
170 #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);
172 /* Defines used for optimizations */
174 /* Only reapply what is necessary */
175 #define REAPPLY_ALPHAOP 0x0001
176 #define REAPPLY_ALL 0xFFFF
178 /* Advance declaration of structures to satisfy compiler */
179 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl
;
180 typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl
;
182 /* Global variables */
183 extern const float identity
[16];
185 /*****************************************************************************
186 * Compilable extra diagnostics
189 /* Trace information per-vertex: (extremely high amount of trace) */
190 #if 0 /* NOTE: Must be 0 in cvs */
191 # define VTRACE(A) TRACE A
196 /* Checking of per-vertex related GL calls */
197 #define vcheckGLcall(A) \
199 GLint err = glGetError(); \
200 if (err != GL_NO_ERROR) { \
201 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", err, A, __FILE__, __LINE__); \
203 VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
207 /* TODO: Confirm each of these works when wined3d move completed */
208 #if 0 /* NOTE: Must be 0 in cvs */
209 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
210 of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
211 is enabled, and if it doesn't exists it is disabled. */
212 # define FRAME_DEBUGGING
213 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
214 the file is deleted */
215 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
216 # define SINGLE_FRAME_DEBUGGING
218 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
219 It can only be enabled when FRAME_DEBUGGING is also enabled
220 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
222 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
223 # define SHOW_FRAME_MAKEUP 1
225 /* The following, when enabled, lets you see the makeup of the all the textures used during each
226 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
227 The contents of the textures assigned to each stage are written into
228 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
229 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
230 # define SHOW_TEXTURE_MAKEUP 0
233 extern BOOL isDumpingFrames
;
234 extern LONG primCounter
;
237 /*****************************************************************************
241 /* Routine common to the draw primitive and draw indexed primitive routines */
242 void drawPrimitive(IWineD3DDevice
*iface
,
247 long StartVertexIndex
,
253 /*****************************************************************************
254 * Structures required to draw primitives
257 typedef struct Direct3DStridedData
{
258 BYTE
*lpData
; /* Pointer to start of data */
259 DWORD dwStride
; /* Stride between occurances of this data */
260 DWORD dwType
; /* Type (as in D3DVSDT_TYPE) */
261 } Direct3DStridedData
;
263 typedef struct Direct3DVertexStridedData
{
266 Direct3DStridedData position
;
267 Direct3DStridedData blendWeights
;
268 Direct3DStridedData blendMatrixIndices
;
269 Direct3DStridedData normal
;
270 Direct3DStridedData pSize
;
271 Direct3DStridedData diffuse
;
272 Direct3DStridedData specular
;
273 Direct3DStridedData texCoords
[8];
275 Direct3DStridedData input
[16]; /* Indexed by constants in D3DVSDE_REGISTER */
277 } Direct3DVertexStridedData
;
279 /*****************************************************************************
280 * Internal representation of a light
282 typedef struct PLIGHTINFOEL PLIGHTINFOEL
;
283 struct PLIGHTINFOEL
{
284 WINED3DLIGHT OriginalParms
; /* Note D3D8LIGHT == D3D9LIGHT */
291 /* Converted parms to speed up swapping lights */
301 /*****************************************************************************
302 * IWineD3D implementation structure
304 typedef struct IWineD3DImpl
306 /* IUnknown fields */
307 IWineD3DVtbl
*lpVtbl
;
308 DWORD ref
; /* Note: Ref counting not required */
310 /* WineD3D Information */
316 WineD3D_GL_Info gl_info
;
319 extern IWineD3DVtbl IWineD3D_Vtbl
;
321 /*****************************************************************************
322 * IWineD3DDevice implementation structure
324 typedef struct IWineD3DDeviceImpl
326 /* IUnknown fields */
327 IWineD3DDeviceVtbl
*lpVtbl
;
328 DWORD ref
; /* Note: Ref counting not required */
330 /* WineD3D Information */
331 IUnknown
*parent
; /* TODO - to be a new interface eventually */
334 /* X and GL Information */
339 XVisualInfo
*visInfo
;
340 GLXContext render_ctx
;
342 GLint maxConcurrentLights
;
345 BOOL modelview_valid
;
347 BOOL view_ident
; /* true iff view matrix is identity */
348 BOOL last_was_rhw
; /* true iff last draw_primitive was in xyzrhw mode */
349 GLenum tracking_parm
; /* Which source is tracking current colour */
350 LONG tracking_color
; /* used iff GL_COLOR_MATERIAL was enabled */
351 #define DISABLED_TRACKING 0 /* Disabled */
352 #define IS_TRACKING 1 /* tracking_parm is tracking diffuse color */
353 #define NEEDS_TRACKING 2 /* Tracking needs to be enabled when needed */
354 #define NEEDS_DISABLE 3 /* Tracking needs to be disabled when needed*/
359 BOOL texture_shader_active
; /* TODO: Confirm use is correct */
361 /* State block related */
362 BOOL isRecordingState
;
363 IWineD3DStateBlockImpl
*stateBlock
;
364 IWineD3DStateBlockImpl
*updateStateBlock
;
366 /* Internal use fields */
367 D3DDEVICE_CREATION_PARAMETERS createParms
;
368 D3DPRESENT_PARAMETERS presentParms
;
372 /* Render Target Support */
373 IWineD3DSurfaceImpl
*frontBuffer
;
374 IWineD3DSurfaceImpl
*backBuffer
;
375 IWineD3DSurfaceImpl
*depthStencilBuffer
;
377 IWineD3DSurfaceImpl
*renderTarget
;
378 IWineD3DSurfaceImpl
*stencilBufferTarget
;
380 /* palettes texture management */
381 PALETTEENTRY palettes
[MAX_PALETTES
][256];
384 /* For rendering to a texture using glCopyTexImage */
385 BOOL renderUpsideDown
;
387 /* Textures for when no other textures are mapped */
388 UINT dummyTextureName
[8];
390 } IWineD3DDeviceImpl
;
392 extern IWineD3DDeviceVtbl IWineD3DDevice_Vtbl
;
394 /*****************************************************************************
395 * IWineD3DResource implementation structure
397 typedef struct IWineD3DResourceClass
399 /* IUnknown fields */
400 DWORD ref
; /* Note: Ref counting not required */
402 /* WineD3DResource Information */
404 D3DRESOURCETYPE resourceType
;
405 IWineD3DDeviceImpl
*wineD3DDevice
;
407 } IWineD3DResourceClass
;
409 typedef struct IWineD3DResourceImpl
411 /* IUnknown & WineD3DResource Information */
412 IWineD3DResourceVtbl
*lpVtbl
;
413 IWineD3DResourceClass resource
;
414 } IWineD3DResourceImpl
;
416 extern IWineD3DResourceVtbl IWineD3DResource_Vtbl
;
418 /*****************************************************************************
419 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
421 typedef struct IWineD3DVertexBufferImpl
423 /* IUnknown & WineD3DResource Information */
424 IWineD3DVertexBufferVtbl
*lpVtbl
;
425 IWineD3DResourceClass resource
;
427 /* WineD3DVertexBuffer specifics */
428 BYTE
*allocatedMemory
;
429 D3DVERTEXBUFFER_DESC currentDesc
;
431 } IWineD3DVertexBufferImpl
;
433 extern IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl
;
435 /*****************************************************************************
436 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
438 typedef struct IWineD3DIndexBufferImpl
440 /* IUnknown & WineD3DResource Information */
441 IWineD3DIndexBufferVtbl
*lpVtbl
;
442 IWineD3DResourceClass resource
;
444 /* WineD3DVertexBuffer specifics */
445 BYTE
*allocatedMemory
;
446 D3DINDEXBUFFER_DESC currentDesc
;
448 } IWineD3DIndexBufferImpl
;
450 extern IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl
;
452 /*****************************************************************************
453 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
455 typedef struct IWineD3DBaseTextureClass
460 } IWineD3DBaseTextureClass
;
462 typedef struct IWineD3DBaseTextureImpl
464 /* IUnknown & WineD3DResource Information */
465 IWineD3DIndexBufferVtbl
*lpVtbl
;
466 IWineD3DResourceClass resource
;
467 IWineD3DBaseTextureClass baseTexture
;
469 } IWineD3DBaseTextureImpl
;
471 extern IWineD3DBaseTextureVtbl IWineD3DBaseTexture_Vtbl
;
473 /*****************************************************************************
474 * IWineD3DSurface implementation structure
476 struct IWineD3DSurfaceImpl
478 /* IUnknown & IWineD3DResource Information */
479 IWineD3DSurfaceVtbl
*lpVtbl
;
480 IWineD3DResourceClass resource
;
482 /* IWineD3DSurface fields */
484 D3DSURFACE_DESC currentDesc
;
485 BYTE
*allocatedMemory
;
499 extern IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl
;
501 /*****************************************************************************
502 * IWineD3DStateBlock implementation structure
505 /* Internal state Block for Begin/End/Capture/Create/Apply info */
506 /* Note: Very long winded but gl Lists are not flexible enough */
507 /* to resolve everything we need, so doing it manually for now */
508 typedef struct SAVEDSTATES
{
512 BOOL stream_source
[MAX_STREAMS
];
514 BOOL transform
[HIGHEST_TRANSFORMSTATE
];
516 BOOL renderState
[HIGHEST_RENDER_STATE
];
517 BOOL textureState
[8][HIGHEST_TEXTURE_STATE
];
518 BOOL clipplane
[MAX_CLIPPLANES
];
521 struct IWineD3DStateBlockImpl
523 /* IUnknown fields */
524 IWineD3DStateBlockVtbl
*lpVtbl
;
525 DWORD ref
; /* Note: Ref counting not required */
527 /* IWineD3DStateBlock information */
529 IWineD3DDeviceImpl
*wineD3DDevice
;
530 D3DSTATEBLOCKTYPE blockType
;
532 /* Array indicating whether things have been set or changed */
536 /* Drawing - Vertex Shader or FVF related */
538 void *vertexShader
; /* TODO: Replace void * with IWineD3DVertexShader * */
542 UINT stream_stride
[MAX_STREAMS
];
543 UINT stream_offset
[MAX_STREAMS
];
544 IWineD3DVertexBuffer
*stream_source
[MAX_STREAMS
];
547 IWineD3DIndexBuffer
* pIndexData
;
548 UINT baseVertexIndex
; /* Note: only used for d3d8 */
551 D3DMATRIX transforms
[HIGHEST_TRANSFORMSTATE
];
554 PLIGHTINFOEL
*lights
; /* NOTE: active GL lights must be front of the chain */
557 double clipplane
[MAX_CLIPPLANES
][4];
558 WINED3DCLIPSTATUS clip_status
;
561 WINED3DVIEWPORT viewport
;
564 WINED3DMATERIAL material
;
566 /* Indexed Vertex Blending */
567 D3DVERTEXBLENDFLAGS vertex_blend
;
571 DWORD renderState
[HIGHEST_RENDER_STATE
];
574 IWineD3DBaseTexture
*textures
[8];
575 int textureDimensions
[8];
577 /* Texture State Stage */
578 DWORD textureState
[8][HIGHEST_TEXTURE_STATE
];
582 extern IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl
;
584 /*****************************************************************************
585 * Utility function prototypes
589 const char* debug_d3dformat(D3DFORMAT fmt
);
590 const char* debug_d3ddevicetype(D3DDEVTYPE devtype
);
591 const char* debug_d3dresourcetype(D3DRESOURCETYPE res
);
592 const char* debug_d3dusage(DWORD usage
);
593 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType
);
594 const char* debug_d3drenderstate(DWORD state
);
595 const char* debug_d3dtexturestate(DWORD state
);
597 /* Routines for GL <-> D3D values */
598 GLenum
StencilOp(DWORD op
);
599 void set_tex_op(IWineD3DDevice
*iface
, BOOL isAlpha
, int Stage
, D3DTEXTUREOP op
, DWORD arg1
, DWORD arg2
, DWORD arg3
);
600 void set_texture_matrix(const float *smat
, DWORD flags
);
601 void GetSrcAndOpFromValue(DWORD iValue
, BOOL isAlphaArg
, GLenum
* source
, GLenum
* operand
);
603 SHORT
D3DFmtGetBpp(IWineD3DDeviceImpl
* This
, D3DFORMAT fmt
);
604 GLenum
D3DFmt2GLFmt(IWineD3DDeviceImpl
* This
, D3DFORMAT fmt
);
605 GLenum
D3DFmt2GLType(IWineD3DDeviceImpl
*This
, D3DFORMAT fmt
);
606 GLint
D3DFmt2GLIntFmt(IWineD3DDeviceImpl
* This
, D3DFORMAT fmt
);
609 #if 0 /* Needs fixing during rework */
610 /*****************************************************************************
611 * IDirect3DVertexShaderDeclaration implementation structure
613 struct IDirect3DVertexShaderDeclarationImpl
{
615 /*IDirect3DDeviceImpl* device;*/
617 /** precomputed fvf if simple declaration */
618 DWORD fvf
[MAX_STREAMS
];
621 /** dx8 compatible Declaration fields */
622 DWORD
* pDeclaration8
;
623 DWORD declaration8Length
;
627 /*****************************************************************************
628 * IDirect3DVertexShader implementation structure
630 struct IDirect3DVertexShaderImpl
{
632 /*IDirect3DDeviceImpl* device;*/
640 VSHADERINPUTDATA input
;
641 VSHADEROUTPUTDATA output
;
645 /*****************************************************************************
646 * IDirect3DPixelShader implementation structure
648 struct IDirect3DPixelShaderImpl
{
650 /*IDirect3DDeviceImpl* device;*/
657 PSHADERINPUTDATA input
;
658 PSHADEROUTPUTDATA output
;
661 #endif /* Needs fixing during rework */