wined3d: Implement IWineD3DDevice::SetFrontBackBuffers.
[wine/multimedia.git] / dlls / wined3d / wined3d_private.h
blobaa875e6373c4f56884bf7f1e0f8ba9a34835538c
1 /*
2 * Direct3D wine internal private include file
4 * Copyright 2002-2003 The wine-d3d team
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2004 Jason Edmeades
7 * Copyright 2005 Oliver Stieber
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifndef __WINE_WINED3D_PRIVATE_H
25 #define __WINE_WINED3D_PRIVATE_H
27 #include <stdarg.h>
28 #include <math.h>
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
31 #define COBJMACROS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winreg.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
40 #include "d3d9.h"
41 #include "d3d9types.h"
42 #include "ddraw.h"
43 #include "wine/wined3d_interface.h"
44 #include "wine/wined3d_gl.h"
46 /* Device caps */
47 #define MAX_PALETTES 256
48 #define MAX_STREAMS 16
49 #define MAX_TEXTURES 8
50 #define MAX_SAMPLERS 16
51 #define MAX_ACTIVE_LIGHTS 8
52 #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
53 #define MAX_LEVELS 256
55 #define MAX_VSHADER_CONSTANTS 96
56 #define MAX_PSHADER_CONSTANTS 32
58 /* Used for CreateStateBlock */
59 #define NUM_SAVEDPIXELSTATES_R 35
60 #define NUM_SAVEDPIXELSTATES_T 18
61 #define NUM_SAVEDPIXELSTATES_S 12
62 #define NUM_SAVEDVERTEXSTATES_R 31
63 #define NUM_SAVEDVERTEXSTATES_T 2
64 #define NUM_SAVEDVERTEXSTATES_S 1
66 extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
67 extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
68 extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
69 extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
70 extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
71 extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
73 typedef enum _WINELOOKUP {
74 WINELOOKUP_WARPPARAM = 0,
75 WINELOOKUP_MAGFILTER = 1,
76 MAX_LOOKUPS = 2
77 } WINELOOKUP;
79 extern int minLookup[MAX_LOOKUPS];
80 extern int maxLookup[MAX_LOOKUPS];
81 extern DWORD *stateLookup[MAX_LOOKUPS];
83 extern DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
85 typedef struct _WINED3DGLTYPE {
86 int d3dType;
87 GLint size;
88 GLenum glType;
89 GLboolean normalized;
90 int typesize;
91 } WINED3DGLTYPE;
93 /* NOTE: Make sure these are in the correct numerical order. (see /include/d3d9types.h typedef enum _D3DDECLTYPE) */
94 WINED3DGLTYPE static const glTypeLookup[D3DDECLTYPE_UNUSED] = {
95 {D3DDECLTYPE_FLOAT1, 1, GL_FLOAT , GL_FALSE ,sizeof(float)},
96 {D3DDECLTYPE_FLOAT2, 2, GL_FLOAT , GL_FALSE ,sizeof(float)},
97 {D3DDECLTYPE_FLOAT3, 3, GL_FLOAT , GL_FALSE ,sizeof(float)},
98 {D3DDECLTYPE_FLOAT4, 4, GL_FLOAT , GL_FALSE ,sizeof(float)},
99 {D3DDECLTYPE_D3DCOLOR, 4, GL_UNSIGNED_BYTE , GL_TRUE ,sizeof(BYTE)},
100 {D3DDECLTYPE_UBYTE4, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
101 {D3DDECLTYPE_SHORT2, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
102 {D3DDECLTYPE_SHORT4, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
103 {D3DDECLTYPE_UBYTE4N, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
104 {D3DDECLTYPE_SHORT2N, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
105 {D3DDECLTYPE_SHORT4N, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
106 {D3DDECLTYPE_USHORT2N, 2, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
107 {D3DDECLTYPE_USHORT4N, 4, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
108 {D3DDECLTYPE_UDEC3, 3, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
109 {D3DDECLTYPE_DEC3N, 3, GL_SHORT , GL_FALSE ,sizeof(short int)},
110 {D3DDECLTYPE_FLOAT16_2, 2, GL_FLOAT , GL_FALSE ,sizeof(short int)},
111 {D3DDECLTYPE_FLOAT16_4, 4, GL_FLOAT , GL_FALSE ,sizeof(short int)}};
113 #define WINED3D_ATR_TYPE(_attribute) glTypeLookup[sd->u.s._attribute.dwType].d3dType
114 #define WINED3D_ATR_SIZE(_attribute) glTypeLookup[sd->u.s._attribute.dwType].size
115 #define WINED3D_ATR_GLTYPE(_attribute) glTypeLookup[sd->u.s._attribute.dwType].glType
116 #define WINED3D_ATR_NORMALIZED(_attribute) glTypeLookup[sd->u.s._attribute.dwType].normalized
117 #define WINED3D_ATR_TYPESIZE(_attribute) glTypeLookup[sd->u.s._attribute.dwType].typesize
120 * Settings
122 #define VS_NONE 0
123 #define VS_HW 1
124 #define VS_SW 2
126 #define PS_NONE 0
127 #define PS_HW 1
129 #define VBO_NONE 0
130 #define VBO_HW 1
132 #define NP2_NONE 0
133 #define NP2_REPACK 1
135 typedef struct wined3d_settings_s {
136 /* vertex and pixel shader modes */
137 int vs_mode;
138 int ps_mode;
139 int vbo_mode;
140 /* nonpower 2 function */
141 int nonpower2_mode;
142 } wined3d_settings_t;
144 extern wined3d_settings_t wined3d_settings;
146 /* X11 locking */
148 extern void (*wine_tsx11_lock_ptr)(void);
149 extern void (*wine_tsx11_unlock_ptr)(void);
151 /* As GLX relies on X, this is needed */
152 extern int num_lock;
154 #if 0
155 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
156 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
157 #else
158 #define ENTER_GL() wine_tsx11_lock_ptr()
159 #define LEAVE_GL() wine_tsx11_unlock_ptr()
160 #endif
162 /*****************************************************************************
163 * Defines
166 /* GL related defines */
167 /* ------------------ */
168 #define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
169 #define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
170 #define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
171 #define GL_VEND(_VendName) (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
173 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
174 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
175 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
176 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
178 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
179 #define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
180 #define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
181 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
183 #define D3DCOLORTOGLFLOAT4(dw, vec) \
184 (vec)[0] = D3DCOLOR_R(dw); \
185 (vec)[1] = D3DCOLOR_G(dw); \
186 (vec)[2] = D3DCOLOR_B(dw); \
187 (vec)[3] = D3DCOLOR_A(dw);
189 /* Note: The following is purely to keep the source code as clear from #ifdefs as possible */
190 #if defined(GL_VERSION_1_3)
191 #define GLACTIVETEXTURE(textureNo) \
192 glActiveTexture(GL_TEXTURE0 + textureNo); \
193 checkGLcall("glActiveTexture");
194 #define GLCLIENTACTIVETEXTURE(textureNo) \
195 glClientActiveTexture(GL_TEXTURE0 + textureNo);
196 #define GLMULTITEXCOORD1F(a,b) \
197 glMultiTexCoord1f(GL_TEXTURE0 + a, b);
198 #define GLMULTITEXCOORD2F(a,b,c) \
199 glMultiTexCoord2f(GL_TEXTURE0 + a, b, c);
200 #define GLMULTITEXCOORD3F(a,b,c,d) \
201 glMultiTexCoord3f(GL_TEXTURE0 + a, b, c, d);
202 #define GLMULTITEXCOORD4F(a,b,c,d,e) \
203 glMultiTexCoord4f(GL_TEXTURE0 + a, b, c, d, e);
204 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP
205 #else
206 #define GLACTIVETEXTURE(textureNo) \
207 glActiveTextureARB(GL_TEXTURE0_ARB + textureNo); \
208 checkGLcall("glActiveTextureARB");
209 #define GLCLIENTACTIVETEXTURE(textureNo) \
210 glClientActiveTextureARB(GL_TEXTURE0_ARB + textureNo);
211 #define GLMULTITEXCOORD1F(a,b) \
212 glMultiTexCoord1fARB(GL_TEXTURE0_ARB + a, b);
213 #define GLMULTITEXCOORD2F(a,b,c) \
214 glMultiTexCoord2fARB(GL_TEXTURE0_ARB + a, b, c);
215 #define GLMULTITEXCOORD3F(a,b,c,d) \
216 glMultiTexCoord3fARB(GL_TEXTURE0_ARB + a, b, c, d);
217 #define GLMULTITEXCOORD4F(a,b,c,d,e) \
218 glMultiTexCoord4fARB(GL_TEXTURE0_ARB + a, b, c, d, e);
219 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP_ARB
220 #endif
222 /* DirectX Device Limits */
223 /* --------------------- */
224 #define MAX_LEVELS 256 /* Maximum number of mipmap levels. Guessed at 256 */
226 #define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
227 See MaxStreams in MSDN under GetDeviceCaps */
228 /* Maximum number of constants provided to the shaders */
229 #define HIGHEST_TRANSFORMSTATE 512
230 /* Highest value in D3DTRANSFORMSTATETYPE */
231 #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
233 #define MAX_PALETTES 256
235 /* Checking of API calls */
236 /* --------------------- */
237 #define checkGLcall(A) \
239 GLint err = glGetError(); \
240 if (err == GL_NO_ERROR) { \
241 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
243 } else do { \
244 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", \
245 err, A, __FILE__, __LINE__); \
246 err = glGetError(); \
247 } while (err != GL_NO_ERROR); \
250 /* Trace routines / diagnostics */
251 /* ---------------------------- */
253 /* Dump out a matrix and copy it */
254 #define conv_mat(mat,gl_mat) \
255 do { \
256 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
257 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
258 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
259 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
260 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
261 } while (0)
263 /* Macro to dump out the current state of the light chain */
264 #define DUMP_LIGHT_CHAIN() \
266 PLIGHTINFOEL *el = This->stateBlock->lights;\
267 while (el) { \
268 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
269 el = el->next; \
273 /* Trace vector and strided data information */
274 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
275 #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);
277 /* Defines used for optimizations */
279 /* Only reapply what is necessary */
280 #define REAPPLY_ALPHAOP 0x0001
281 #define REAPPLY_ALL 0xFFFF
283 /* Advance declaration of structures to satisfy compiler */
284 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
285 typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
286 typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl;
288 /* Tracking */
290 /* TODO: Move some of this to the device */
291 long globalChangeGlRam(long glram);
293 /* Memory and object tracking */
295 /*Structure for holding information on all direct3d objects
296 useful for making sure tracking is ok and when release is called on a device!
297 and probably quite handy for debugging and dumping states out
299 typedef struct WineD3DGlobalStatistics {
300 int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
301 } WineD3DGlobalStatistics;
303 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
305 /* Global variables */
306 extern const float identity[16];
308 /*****************************************************************************
309 * Compilable extra diagnostics
312 /* Trace information per-vertex: (extremely high amount of trace) */
313 #if 0 /* NOTE: Must be 0 in cvs */
314 # define VTRACE(A) TRACE A
315 #else
316 # define VTRACE(A)
317 #endif
319 /* Checking of per-vertex related GL calls */
320 /* --------------------- */
321 #define vcheckGLcall(A) \
323 GLint err = glGetError(); \
324 if (err == GL_NO_ERROR) { \
325 VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
327 } else do { \
328 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", \
329 err, A, __FILE__, __LINE__); \
330 err = glGetError(); \
331 } while (err != GL_NO_ERROR); \
334 /* TODO: Confirm each of these works when wined3d move completed */
335 #if 0 /* NOTE: Must be 0 in cvs */
336 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
337 of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
338 is enabled, and if it doesn't exists it is disabled. */
339 # define FRAME_DEBUGGING
340 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
341 the file is deleted */
342 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
343 # define SINGLE_FRAME_DEBUGGING
344 # endif
345 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
346 It can only be enabled when FRAME_DEBUGGING is also enabled
347 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
348 array is drawn. */
349 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
350 # define SHOW_FRAME_MAKEUP 1
351 # endif
352 /* The following, when enabled, lets you see the makeup of the all the textures used during each
353 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
354 The contents of the textures assigned to each stage are written into
355 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
356 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
357 # define SHOW_TEXTURE_MAKEUP 0
358 # endif
359 extern BOOL isOn;
360 extern BOOL isDumpingFrames;
361 extern LONG primCounter;
362 #endif
364 /*****************************************************************************
365 * Prototypes
368 /* Routine common to the draw primitive and draw indexed primitive routines */
369 void drawPrimitive(IWineD3DDevice *iface,
370 int PrimitiveType,
371 long NumPrimitives,
372 /* for Indexed: */
373 long StartVertexIndex,
374 UINT numberOfVertices,
375 long StartIdx,
376 short idxBytes,
377 const void *idxData,
378 int minIndex,
379 WineDirect3DVertexStridedData *DrawPrimStrideData);
381 void primitiveConvertToStridedData(IWineD3DDevice *iface,
382 WineDirect3DVertexStridedData *strided,
383 LONG BaseVertexIndex);
385 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
387 #define eps 1e-8
389 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
390 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
392 /* Routine to fill gl caps for swapchains and IWineD3D */
393 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info,
394 Display* display);
396 /*****************************************************************************
397 * Internal representation of a light
399 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
400 struct PLIGHTINFOEL {
401 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
402 DWORD OriginalIndex;
403 LONG glIndex;
404 BOOL lightEnabled;
405 BOOL changed;
406 BOOL enabledChanged;
408 /* Converted parms to speed up swapping lights */
409 float lightPosn[4];
410 float lightDirn[4];
411 float exponent;
412 float cutoff;
414 PLIGHTINFOEL *next;
415 PLIGHTINFOEL *prev;
418 /*****************************************************************************
419 * IWineD3D implementation structure
421 typedef struct IWineD3DImpl
423 /* IUnknown fields */
424 const IWineD3DVtbl *lpVtbl;
425 LONG ref; /* Note: Ref counting not required */
427 /* WineD3D Information */
428 IUnknown *parent;
429 UINT dxVersion;
431 /* GL Information */
432 BOOL isGLInfoValid;
433 WineD3D_GL_Info gl_info;
434 } IWineD3DImpl;
436 extern const IWineD3DVtbl IWineD3D_Vtbl;
438 typedef struct SwapChainList {
439 IWineD3DSwapChain *swapchain;
440 struct SwapChainList *next;
441 } SwapChainList;
443 /** Hacked out start of a context manager!! **/
444 typedef struct glContext {
445 int Width;
446 int Height;
447 int usedcount;
448 GLXContext context;
450 Drawable drawable;
451 IWineD3DSurface *pSurface;
452 #if 0 /* TODO: someway to represent the state of the context */
453 IWineD3DStateBlock *pStateBlock;
454 #endif
455 /* a few other things like format */
456 } glContext;
458 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
459 (since it will break quite a few things until contexts are managed properly!) */
460 extern BOOL pbuffer_support;
461 /* allocate one pbuffer per surface */
462 extern BOOL pbuffer_per_surface;
464 /* Maximum number of contexts/pbuffers to keep in cache,
465 set to 100 because ATI's drivers don't support deleting pBuffers properly
466 this needs to be migrated to a list and some option availalbe for controle the cache size.
468 #define CONTEXT_CACHE 100
470 typedef struct ResourceList {
471 IWineD3DResource *resource;
472 struct ResourceList *next;
473 } ResourceList;
475 /* A helper function that dumps a resource list */
476 void dumpResources(ResourceList *resources);
478 /*****************************************************************************
479 * IWineD3DDevice implementation structure
481 typedef struct IWineD3DDeviceImpl
483 /* IUnknown fields */
484 const IWineD3DDeviceVtbl *lpVtbl;
485 LONG ref; /* Note: Ref counting not required */
487 /* WineD3D Information */
488 IUnknown *parent;
489 IWineD3D *wineD3D;
491 /* X and GL Information */
492 GLint maxConcurrentLights;
494 /* Optimization */
495 BOOL modelview_valid;
496 BOOL proj_valid;
497 BOOL view_ident; /* true iff view matrix is identity */
498 BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
499 BOOL viewport_changed; /* Was the viewport changed since the last draw? */
500 GLenum tracking_parm; /* Which source is tracking current colour */
501 LONG tracking_color; /* used iff GL_COLOR_MATERIAL was enabled */
502 #define DISABLED_TRACKING 0 /* Disabled */
503 #define IS_TRACKING 1 /* tracking_parm is tracking diffuse color */
504 #define NEEDS_TRACKING 2 /* Tracking needs to be enabled when needed */
505 #define NEEDS_DISABLE 3 /* Tracking needs to be disabled when needed*/
506 UINT srcBlend;
507 UINT dstBlend;
508 UINT alphafunc;
509 UINT stencilfunc;
510 BOOL texture_shader_active; /* TODO: Confirm use is correct */
511 BOOL last_was_notclipped;
513 /* State block related */
514 BOOL isRecordingState;
515 IWineD3DStateBlockImpl *stateBlock;
516 IWineD3DStateBlockImpl *updateStateBlock;
518 /* Internal use fields */
519 WINED3DDEVICE_CREATION_PARAMETERS createParms;
520 UINT adapterNo;
521 D3DDEVTYPE devType;
523 SwapChainList *swapchains;
525 ResourceList *resources; /* a linked list to track resources created by the device */
527 /* Render Target Support */
528 IWineD3DSurface *depthStencilBuffer;
530 IWineD3DSurface *renderTarget;
531 IWineD3DSurface *stencilBufferTarget;
533 /* palettes texture management */
534 PALETTEENTRY palettes[MAX_PALETTES][256];
535 UINT currentPalette;
537 /* For rendering to a texture using glCopyTexImage */
538 BOOL renderUpsideDown;
540 /* Cursor management */
541 BOOL bCursorVisible;
542 UINT xHotSpot;
543 UINT yHotSpot;
544 UINT xScreenSpace;
545 UINT yScreenSpace;
547 /* Textures for when no other textures are mapped */
548 UINT dummyTextureName[MAX_TEXTURES];
550 /* Debug stream management */
551 BOOL debug;
553 /* Device state management */
554 HRESULT state;
555 BOOL d3d_initialized;
557 /* Screen buffer resources */
558 glContext contextCache[CONTEXT_CACHE];
560 /* A flag to check if endscene has been called before changing the render tartet */
561 BOOL sceneEnded;
563 /* process vertex shaders using software or hardware */
564 BOOL softwareVertexProcessing;
566 /* DirectDraw stuff */
567 HWND ddraw_window;
568 IWineD3DSurface *ddraw_primary;
570 } IWineD3DDeviceImpl;
572 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
574 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
575 * anybody uses it for much so a good implementation is optional. */
576 typedef struct PrivateData
578 struct PrivateData* next;
580 GUID tag;
581 DWORD flags; /* DDSPD_* */
582 DWORD uniqueness_value;
584 union
586 LPVOID data;
587 LPUNKNOWN object;
588 } ptr;
590 DWORD size;
591 } PrivateData;
593 /* OpenGL ortho matrix setup */
594 void d3ddevice_set_ortho(IWineD3DDeviceImpl *This, BOOL dontclip);
596 /*****************************************************************************
597 * IWineD3DResource implementation structure
599 typedef struct IWineD3DResourceClass
601 /* IUnknown fields */
602 LONG ref; /* Note: Ref counting not required */
604 /* WineD3DResource Information */
605 IUnknown *parent;
606 WINED3DRESOURCETYPE resourceType;
607 IWineD3DDeviceImpl *wineD3DDevice;
608 WINED3DPOOL pool;
609 UINT size;
610 DWORD usage;
611 WINED3DFORMAT format;
612 BYTE *allocatedMemory;
613 PrivateData *privateData;
615 } IWineD3DResourceClass;
617 typedef struct IWineD3DResourceImpl
619 /* IUnknown & WineD3DResource Information */
620 const IWineD3DResourceVtbl *lpVtbl;
621 IWineD3DResourceClass resource;
622 } IWineD3DResourceImpl;
625 /*****************************************************************************
626 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
628 typedef struct IWineD3DVertexBufferImpl
630 /* IUnknown & WineD3DResource Information */
631 const IWineD3DVertexBufferVtbl *lpVtbl;
632 IWineD3DResourceClass resource;
634 /* WineD3DVertexBuffer specifics */
635 DWORD fvf;
637 } IWineD3DVertexBufferImpl;
639 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
642 /*****************************************************************************
643 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
645 typedef struct IWineD3DIndexBufferImpl
647 /* IUnknown & WineD3DResource Information */
648 const IWineD3DIndexBufferVtbl *lpVtbl;
649 IWineD3DResourceClass resource;
651 /* WineD3DVertexBuffer specifics */
652 } IWineD3DIndexBufferImpl;
654 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
656 /*****************************************************************************
657 * IWineD3DBaseTexture D3D- > openGL state map lookups
659 #define WINED3DFUNC_NOTSUPPORTED -2
660 #define WINED3DFUNC_UNIMPLEMENTED -1
662 typedef enum winetexturestates {
663 WINED3DTEXSTA_ADDRESSU = 0,
664 WINED3DTEXSTA_ADDRESSV = 1,
665 WINED3DTEXSTA_ADDRESSW = 2,
666 WINED3DTEXSTA_BORDERCOLOR = 3,
667 WINED3DTEXSTA_MAGFILTER = 4,
668 WINED3DTEXSTA_MINFILTER = 5,
669 WINED3DTEXSTA_MIPFILTER = 6,
670 WINED3DTEXSTA_MAXMIPLEVEL = 7,
671 WINED3DTEXSTA_MAXANISOTROPY = 8,
672 WINED3DTEXSTA_SRGBTEXTURE = 9,
673 WINED3DTEXSTA_ELEMENTINDEX = 10,
674 WINED3DTEXSTA_DMAPOFFSET = 11,
675 WINED3DTEXSTA_TSSADDRESSW = 12,
676 MAX_WINETEXTURESTATES = 13,
677 } winetexturestates;
679 typedef struct Wined3dTextureStateMap {
680 CONST int state;
681 int function;
682 } Wined3dTextureStateMap;
684 /*****************************************************************************
685 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
687 typedef struct IWineD3DBaseTextureClass
689 UINT levels;
690 BOOL dirty;
691 D3DFORMAT format;
692 DWORD usage;
693 UINT textureName;
694 UINT LOD;
695 WINED3DTEXTUREFILTERTYPE filterType;
696 DWORD states[MAX_WINETEXTURESTATES];
698 } IWineD3DBaseTextureClass;
700 typedef struct IWineD3DBaseTextureImpl
702 /* IUnknown & WineD3DResource Information */
703 const IWineD3DBaseTextureVtbl *lpVtbl;
704 IWineD3DResourceClass resource;
705 IWineD3DBaseTextureClass baseTexture;
707 } IWineD3DBaseTextureImpl;
709 /*****************************************************************************
710 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
712 typedef struct IWineD3DTextureImpl
714 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
715 const IWineD3DTextureVtbl *lpVtbl;
716 IWineD3DResourceClass resource;
717 IWineD3DBaseTextureClass baseTexture;
719 /* IWineD3DTexture */
720 IWineD3DSurface *surfaces[MAX_LEVELS];
722 UINT width;
723 UINT height;
724 float pow2scalingFactorX;
725 float pow2scalingFactorY;
727 } IWineD3DTextureImpl;
729 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
731 /*****************************************************************************
732 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
734 typedef struct IWineD3DCubeTextureImpl
736 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
737 const IWineD3DCubeTextureVtbl *lpVtbl;
738 IWineD3DResourceClass resource;
739 IWineD3DBaseTextureClass baseTexture;
741 /* IWineD3DCubeTexture */
742 IWineD3DSurface *surfaces[6][MAX_LEVELS];
744 UINT edgeLength;
745 float pow2scalingFactor;
747 } IWineD3DCubeTextureImpl;
749 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
751 typedef struct _WINED3DVOLUMET_DESC
753 UINT Width;
754 UINT Height;
755 UINT Depth;
756 } WINED3DVOLUMET_DESC;
758 /*****************************************************************************
759 * IWineD3DVolume implementation structure (extends IUnknown)
761 typedef struct IWineD3DVolumeImpl
763 /* IUnknown & WineD3DResource fields */
764 const IWineD3DVolumeVtbl *lpVtbl;
765 IWineD3DResourceClass resource;
767 /* WineD3DVolume Information */
768 WINED3DVOLUMET_DESC currentDesc;
769 IWineD3DBase *container;
770 UINT bytesPerPixel;
772 BOOL lockable;
773 BOOL locked;
774 WINED3DBOX lockedBox;
775 WINED3DBOX dirtyBox;
776 BOOL dirty;
779 } IWineD3DVolumeImpl;
781 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
783 /*****************************************************************************
784 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
786 typedef struct IWineD3DVolumeTextureImpl
788 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
789 const IWineD3DVolumeTextureVtbl *lpVtbl;
790 IWineD3DResourceClass resource;
791 IWineD3DBaseTextureClass baseTexture;
793 /* IWineD3DVolumeTexture */
794 IWineD3DVolume *volumes[MAX_LEVELS];
796 UINT width;
797 UINT height;
798 UINT depth;
799 } IWineD3DVolumeTextureImpl;
801 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
803 typedef struct _WINED3DSURFACET_DESC
805 WINED3DMULTISAMPLE_TYPE MultiSampleType;
806 DWORD MultiSampleQuality;
807 UINT Width;
808 UINT Height;
809 } WINED3DSURFACET_DESC;
811 /*****************************************************************************
812 * Structure for DIB Surfaces (GetDC and GDI surfaces)
814 typedef struct wineD3DSurface_DIB {
815 HBITMAP DIBsection;
816 void* bitmap_data;
817 HGDIOBJ holdbitmap;
818 BOOL client_memory;
819 } wineD3DSurface_DIB;
821 /*****************************************************************************
822 * IWineD3DSurface implementation structure
824 struct IWineD3DSurfaceImpl
826 /* IUnknown & IWineD3DResource Information */
827 const IWineD3DSurfaceVtbl *lpVtbl;
828 IWineD3DResourceClass resource;
830 /* IWineD3DSurface fields */
831 IWineD3DBase *container;
832 WINED3DSURFACET_DESC currentDesc;
833 IWineD3DPaletteImpl *palette;
835 UINT textureName;
836 UINT bytesPerPixel;
838 /* TODO: move this off into a management class(maybe!) */
839 WORD Flags;
841 UINT pow2Width;
842 UINT pow2Height;
843 UINT pow2Size;
845 #if 0
846 /* precalculated x and y scalings for texture coords */
847 float pow2scalingFactorX; /* = (Width / pow2Width ) */
848 float pow2scalingFactorY; /* = (Height / pow2Height) */
849 #endif
851 RECT lockedRect;
852 RECT dirtyRect;
854 glDescriptor glDescription;
856 /* For GetDC */
857 wineD3DSurface_DIB dib;
858 HDC hDC;
860 /* Color keys for DDraw */
861 DDCOLORKEY DestBltCKey;
862 DDCOLORKEY DestOverlayCKey;
863 DDCOLORKEY SrcOverlayCKey;
864 DDCOLORKEY SrcBltCKey;
865 DWORD CKeyFlags;
869 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
870 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
872 /* Predeclare the shared Surface functions */
873 HRESULT WINAPI IWineD3DSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
874 ULONG WINAPI IWineD3DSurfaceImpl_AddRef(IWineD3DSurface *iface);
875 ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface);
876 HRESULT WINAPI IWineD3DSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
877 HRESULT WINAPI IWineD3DSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
878 HRESULT WINAPI IWineD3DSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
879 HRESULT WINAPI IWineD3DSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
880 HRESULT WINAPI IWineD3DSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
881 DWORD WINAPI IWineD3DSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
882 DWORD WINAPI IWineD3DSurfaceImpl_GetPriority(IWineD3DSurface *iface);
883 void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface);
884 WINED3DRESOURCETYPE WINAPI IWineD3DSurfaceImpl_GetType(IWineD3DSurface *iface);
885 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainerParent(IWineD3DSurface* iface, IUnknown **ppContainerParent);
886 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
887 HRESULT WINAPI IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
888 HRESULT WINAPI IWineD3DSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
889 HRESULT WINAPI IWineD3DSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
890 HRESULT WINAPI IWineD3DSurfaceImpl_IsLost(IWineD3DSurface *iface);
891 HRESULT WINAPI IWineD3DSurfaceImpl_Restore(IWineD3DSurface *iface);
892 HRESULT WINAPI IWineD3DSurfaceImpl_SetPixelFormat(IWineD3DSurface *iface, WINED3DFORMAT Format, BYTE *Surface, DWORD Size);
893 HRESULT WINAPI IWineD3DSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
894 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
895 HRESULT WINAPI IWineD3DSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, DDCOLORKEY *CKey);
896 HRESULT WINAPI IWineD3DSurfaceImpl_CleanDirtyRect(IWineD3DSurface *iface);
897 extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect);
898 HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
899 HRESULT WINAPI IWineD3DSurfaceImpl_SetPBufferState(IWineD3DSurface *iface, BOOL inPBuffer, BOOL inTexture);
900 void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target);
901 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription);
902 const void *WINAPI IWineD3DSurfaceImpl_GetData(IWineD3DSurface *iface);
903 HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
904 HRESULT WINAPI IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx);
905 HRESULT WINAPI IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty, IWineD3DSurface *Source, RECT *rsrc, DWORD trans);
906 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
907 HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC);
908 HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC);
909 DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface);
910 HRESULT WINAPI IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
912 /* Surface flags: */
913 #define SFLAG_OVERSIZE 0x0001 /* Surface is bigger than gl size, blts only */
914 #define SFLAG_CONVERTED 0x0002 /* Converted for color keying or Palettized */
915 #define SFLAG_DIBSECTION 0x0004 /* Has a DIB section attached for getdc */
916 #define SFLAG_DIRTY 0x0008 /* Surface was locked by the app */
917 #define SFLAG_LOCKABLE 0x0010 /* Surface can be locked */
918 #define SFLAG_DISCARD 0x0020 /* ??? */
919 #define SFLAG_LOCKED 0x0040 /* Surface is locked atm */
920 #define SFLAG_ACTIVELOCK 0x0080 /* Not locked, but surface memory is needed */
921 #define SFLAG_INTEXTURE 0x0100 /* ??? */
922 #define SFLAG_INPBUFFER 0x0200 /* ??? */
923 #define SFLAG_NONPOW2 0x0400 /* Surface sizes are not a power of 2 */
924 #define SFLAG_DYNLOCK 0x0800 /* Surface is often locked by the app */
925 #define SFLAG_DYNCHANGE 0x1800 /* Surface contents are changed very often, implies DYNLOCK */
926 #define SFLAG_DCINUSE 0x2000 /* Set between GetDC and ReleaseDC calls */
927 #define SFLAG_NEWDC 0x4000 /* To inform LockRect about a new dc */
928 #define SFLAG_LOST 0x8000 /* Surface lost flag for DDraw */
930 /* In some conditions the surface memory must not be freed:
931 * SFLAG_OVERSIZE: Not all data can be kept in GL
932 * SFLAG_CONVERTED: Converting the data back would take too long
933 * SFLAG_DIBSECTION: The dib code manages the memory
934 * SFLAG_DIRTY: GL surface isn't up to date
935 * SFLAG_LOCKED: The app requires access to the surface data
936 * SFLAG_ACTIVELOCK: Some wined3d code needs the memory
937 * SFLAG_DYNLOCK: Avoid freeing the data for performance
938 * SFLAG_DYNCHANGE: Same reason as DYNLOCK
940 #define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
941 SFLAG_CONVERTED | \
942 SFLAG_DIBSECTION | \
943 SFLAG_DIRTY | \
944 SFLAG_LOCKED | \
945 SFLAG_ACTIVELOCK | \
946 SFLAG_DYNLOCK | \
947 SFLAG_DYNCHANGE )
949 /*****************************************************************************
950 * IWineD3DVertexDeclaration implementation structure
952 typedef struct IWineD3DVertexDeclarationImpl {
953 /* IUnknown Information */
954 const IWineD3DVertexDeclarationVtbl *lpVtbl;
955 LONG ref; /* Note: Ref counting not required */
957 IUnknown *parent;
958 /** precomputed fvf if simple declaration */
959 IWineD3DDeviceImpl *wineD3DDevice;
960 DWORD fvf[MAX_STREAMS];
961 DWORD allFVF;
963 /** dx8 compatible Declaration fields */
964 DWORD* pDeclaration8;
965 DWORD declaration8Length;
967 /** dx9+ */
968 D3DVERTEXELEMENT9 *pDeclaration9;
969 UINT declaration9NumElements;
971 WINED3DVERTEXELEMENT *pDeclarationWine;
972 UINT declarationWNumElements;
974 float *constants;
976 } IWineD3DVertexDeclarationImpl;
978 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
980 /*****************************************************************************
981 * IWineD3DStateBlock implementation structure
984 /* Internal state Block for Begin/End/Capture/Create/Apply info */
985 /* Note: Very long winded but gl Lists are not flexible enough */
986 /* to resolve everything we need, so doing it manually for now */
987 typedef struct SAVEDSTATES {
988 BOOL indices;
989 BOOL material;
990 BOOL fvf;
991 BOOL streamSource[MAX_STREAMS];
992 BOOL streamFreq[MAX_STREAMS];
993 BOOL textures[MAX_TEXTURES];
994 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
995 BOOL viewport;
996 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
997 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
998 BOOL samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
999 BOOL clipplane[MAX_CLIPPLANES];
1000 BOOL vertexDecl;
1001 BOOL pixelShader;
1002 BOOL pixelShaderConstants[MAX_PSHADER_CONSTANTS];
1003 BOOL vertexShader;
1004 BOOL vertexShaderConstants[MAX_VSHADER_CONSTANTS];
1005 } SAVEDSTATES;
1007 typedef enum {
1008 WINESHADERCNST_NONE = 0,
1009 WINESHADERCNST_FLOAT = 1,
1010 WINESHADERCNST_INTEGER = 2,
1011 WINESHADERCNST_BOOL = 3
1012 } WINESHADERCNST;
1014 struct IWineD3DStateBlockImpl
1016 /* IUnknown fields */
1017 const IWineD3DStateBlockVtbl *lpVtbl;
1018 LONG ref; /* Note: Ref counting not required */
1020 /* IWineD3DStateBlock information */
1021 IUnknown *parent;
1022 IWineD3DDeviceImpl *wineD3DDevice;
1023 WINED3DSTATEBLOCKTYPE blockType;
1025 /* Array indicating whether things have been set or changed */
1026 SAVEDSTATES changed;
1027 SAVEDSTATES set;
1029 /* Drawing - Vertex Shader or FVF related */
1030 DWORD fvf;
1031 /* Vertex Shader Declaration */
1032 IWineD3DVertexDeclaration *vertexDecl;
1034 IWineD3DVertexShader *vertexShader;
1036 /* Vertex Shader Constants */
1037 BOOL vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
1038 INT vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
1039 float vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
1040 WINESHADERCNST vertexShaderConstantT[MAX_VSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
1042 /* Stream Source */
1043 BOOL streamIsUP;
1044 UINT streamStride[MAX_STREAMS];
1045 UINT streamOffset[MAX_STREAMS];
1046 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
1047 UINT streamFreq[MAX_STREAMS];
1048 UINT streamFlags[MAX_STREAMS]; /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA */
1050 /* Indices */
1051 IWineD3DIndexBuffer* pIndexData;
1052 UINT baseVertexIndex; /* Note: only used for d3d8 */
1054 /* Transform */
1055 D3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
1057 /* Lights */
1058 PLIGHTINFOEL *lights; /* NOTE: active GL lights must be front of the chain */
1060 /* Clipping */
1061 double clipplane[MAX_CLIPPLANES][4];
1062 WINED3DCLIPSTATUS clip_status;
1064 /* ViewPort */
1065 WINED3DVIEWPORT viewport;
1067 /* Material */
1068 WINED3DMATERIAL material;
1070 /* Pixel Shader */
1071 IWineD3DPixelShader *pixelShader;
1073 /* Pixel Shader Constants */
1074 BOOL pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
1075 INT pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
1076 float pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
1077 WINESHADERCNST pixelShaderConstantT[MAX_PSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
1079 /* Indexed Vertex Blending */
1080 D3DVERTEXBLENDFLAGS vertex_blend;
1081 FLOAT tween_factor;
1083 /* RenderState */
1084 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
1086 /* Texture */
1087 IWineD3DBaseTexture *textures[MAX_TEXTURES];
1088 int textureDimensions[MAX_SAMPLERS];
1090 /* Texture State Stage */
1091 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1092 /* Sampler States */
1093 DWORD samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1097 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1099 /*****************************************************************************
1100 * IWineD3DQueryImpl implementation structure (extends IUnknown)
1102 typedef struct IWineD3DQueryImpl
1104 const IWineD3DQueryVtbl *lpVtbl;
1105 LONG ref; /* Note: Ref counting not required */
1107 IUnknown *parent;
1108 /*TODO: replace with iface usage */
1109 #if 0
1110 IWineD3DDevice *wineD3DDevice;
1111 #else
1112 IWineD3DDeviceImpl *wineD3DDevice;
1113 #endif
1114 /* IWineD3DQuery fields */
1116 D3DQUERYTYPE type;
1117 /* TODO: Think about using a IUnknown instead of a void* */
1118 void *extendedData;
1121 } IWineD3DQueryImpl;
1123 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1125 /* Datastructures for IWineD3DQueryImpl.extendedData */
1126 typedef struct WineQueryOcclusionData {
1127 unsigned int queryId;
1128 } WineQueryOcclusionData;
1131 /*****************************************************************************
1132 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1135 typedef struct IWineD3DSwapChainImpl
1137 /*IUnknown part*/
1138 IWineD3DSwapChainVtbl *lpVtbl;
1139 LONG ref; /* Note: Ref counting not required */
1141 IUnknown *parent;
1142 IWineD3DDeviceImpl *wineD3DDevice;
1144 /* IWineD3DSwapChain fields */
1145 IWineD3DSurface *backBuffer;
1146 IWineD3DSurface *frontBuffer;
1147 BOOL wantsDepthStencilBuffer;
1148 D3DPRESENT_PARAMETERS presentParms;
1150 /* TODO: move everything up to drawable off into a context manager
1151 and store the 'data' in the contextManagerData interface.
1152 IUnknown *contextManagerData;
1155 HWND win_handle;
1156 Window win;
1157 Display *display;
1159 GLXContext glCtx;
1160 XVisualInfo *visInfo;
1161 GLXContext render_ctx;
1162 /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1163 Drawable drawable;
1164 } IWineD3DSwapChainImpl;
1166 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1168 /*****************************************************************************
1169 * Utility function prototypes
1172 /* Trace routines */
1173 const char* debug_d3dformat(WINED3DFORMAT fmt);
1174 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1175 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1176 const char* debug_d3dusage(DWORD usage);
1177 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1178 const char* debug_d3drenderstate(DWORD state);
1179 const char* debug_d3dtexturestate(DWORD state);
1180 const char* debug_d3dpool(WINED3DPOOL pool);
1182 /* Routines for GL <-> D3D values */
1183 GLenum StencilOp(DWORD op);
1184 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1185 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1186 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
1188 SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1189 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1190 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
1191 GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1193 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1195 /* Math utils */
1196 void multiply_matrix(D3DMATRIX *dest, D3DMATRIX *src1, D3DMATRIX *src2);
1198 /*****************************************************************************
1199 * To enable calling of inherited functions, requires prototypes
1201 * Note: Only require classes which are subclassed, ie resource, basetexture,
1203 /*** IUnknown methods ***/
1204 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1205 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1206 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1207 /*** IWineD3DResource methods ***/
1208 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1209 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1210 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1211 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1212 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1213 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1214 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1215 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1216 extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1217 /*** class static members ***/
1218 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1220 /*** IUnknown methods ***/
1221 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1222 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1223 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1224 /*** IWineD3DResource methods ***/
1225 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1226 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1227 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1228 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1229 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1230 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1231 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1232 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1233 extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1234 /*** IWineD3DBaseTexture methods ***/
1235 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1236 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1237 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1238 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1239 extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1240 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1241 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1242 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1244 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset);
1245 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1246 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1247 extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1248 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1249 /*** class static members ***/
1250 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1252 /* An enum for the type of constants that are used... addressing causes
1253 * problems with being able to work out what's used and what's not.. so
1254 * maybe we'll have to rely on the server vertex shader const functions?
1256 enum vsConstantsEnum {
1257 VS_CONSTANT_NOT_USED = 0,
1258 VS_CONSTANT_CONSTANT,
1259 VS_CONSTANT_INTEGER,
1260 VS_CONSTANT_BOOLEAN,
1261 VS_CONSTANT_FLOAT
1264 struct SHADER_OPCODE_ARG;
1265 typedef void (*shader_fct_t)();
1266 typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
1269 /* This must be 0 in the main branch until GLSL is at least mostly implemented.
1270 Also, think about making it a winecfg option to use GLSL (if the card supports it)
1271 or ARB_vertex_program. Ideally, we want to use GLSL if it's available, but until
1272 everything is implemented, we'll probably have better luck with the ARB generation */
1273 #define USING_GLSL 0
1275 #define SHADER_PGMSIZE 65535
1276 typedef struct SHADER_BUFFER {
1277 char* buffer;
1278 size_t bsize;
1279 unsigned int lineNo;
1280 } SHADER_BUFFER;
1282 typedef struct SHADER_OPCODE {
1283 unsigned int opcode;
1284 const char* name;
1285 const char* glname;
1286 CONST UINT num_params;
1287 shader_fct_t soft_fct;
1288 SHADER_HANDLER hw_fct;
1289 SHADER_HANDLER hw_glsl_fct;
1290 DWORD min_version;
1291 DWORD max_version;
1292 } SHADER_OPCODE;
1294 typedef struct SHADER_OPCODE_ARG {
1295 IWineD3DBaseShader* shader;
1296 CONST SHADER_OPCODE* opcode;
1297 DWORD dst;
1298 DWORD src[4];
1299 SHADER_BUFFER* buffer;
1300 } SHADER_OPCODE_ARG;
1302 typedef struct SHADER_LIMITS {
1303 unsigned int temporary;
1304 unsigned int texture;
1305 unsigned int constant_int;
1306 unsigned int constant_float;
1307 unsigned int constant_bool;
1308 unsigned int address;
1309 } SHADER_LIMITS;
1311 /** Keeps track of details for TEX_M#x# shader opcodes which need to
1312 maintain state information between multiple codes */
1313 typedef struct SHADER_PARSE_STATE {
1314 unsigned int current_row;
1315 DWORD texcoord_w[2];
1316 } SHADER_PARSE_STATE;
1318 /* Base Shader utility functions.
1319 * (may move callers into the same file in the future) */
1320 extern int shader_addline(
1321 SHADER_BUFFER* buffer,
1322 const char* fmt, ...);
1324 extern const SHADER_OPCODE* shader_get_opcode(
1325 IWineD3DBaseShader *iface,
1326 const DWORD code);
1328 /*****************************************************************************
1329 * IDirect3DBaseShader implementation structure
1331 typedef struct IWineD3DBaseShaderClass
1333 DWORD version;
1334 DWORD hex_version;
1335 DWORD temps_used;
1336 DWORD textures_used;
1337 SHADER_LIMITS limits;
1338 SHADER_PARSE_STATE parse_state;
1339 CONST SHADER_OPCODE *shader_ins;
1340 CONST DWORD *function;
1341 UINT functionLength;
1342 GLuint prgId;
1343 } IWineD3DBaseShaderClass;
1345 typedef struct IWineD3DBaseShaderImpl {
1346 /* IUnknown */
1347 const IWineD3DBaseShaderVtbl *lpVtbl;
1348 LONG ref;
1350 /* IWineD3DBaseShader */
1351 IWineD3DBaseShaderClass baseShader;
1352 } IWineD3DBaseShaderImpl;
1354 extern void shader_get_registers_used(
1355 IWineD3DBaseShader *iface,
1356 CONST DWORD* pToken);
1358 extern void shader_program_dump_decl_usage(
1359 DWORD dcl,
1360 DWORD param);
1362 extern void generate_base_shader(
1363 IWineD3DBaseShader *iface,
1364 SHADER_BUFFER* buffer,
1365 CONST DWORD* pFunction);
1367 extern void shader_dump_ins_modifiers(
1368 const DWORD output);
1370 extern void shader_dump_param(
1371 IWineD3DBaseShader *iface,
1372 const DWORD param,
1373 int input);
1375 inline static int shader_get_regtype(const DWORD param) {
1376 return (((param & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) |
1377 ((param & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2));
1380 inline static BOOL shader_is_pshader_version(DWORD token) {
1381 return 0xFFFF0000 == (token & 0xFFFF0000);
1384 inline static BOOL shader_is_vshader_version(DWORD token) {
1385 return 0xFFFE0000 == (token & 0xFFFF0000);
1388 inline static BOOL shader_is_comment(DWORD token) {
1389 return D3DSIO_COMMENT == (token & D3DSI_OPCODE_MASK);
1392 /*****************************************************************************
1393 * IDirect3DVertexShader implementation structure
1395 typedef struct IWineD3DVertexShaderImpl {
1396 /* IUnknown parts*/
1397 const IWineD3DVertexShaderVtbl *lpVtbl;
1398 LONG ref; /* Note: Ref counting not required */
1400 /* IWineD3DBaseShader */
1401 IWineD3DBaseShaderClass baseShader;
1403 /* IWineD3DVertexShaderImpl */
1404 IUnknown *parent;
1405 IWineD3DDeviceImpl *wineD3DDevice;
1407 DWORD usage;
1409 /* vertex declaration array mapping */
1410 BOOL namedArrays; /* don't map use named functions */
1411 BOOL declaredArrays; /* mapping requires */
1412 INT arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE]; /* lookup table for the maps */
1413 INT highestConstant;
1414 CHAR constantsUsedBitmap[256];
1415 /* FIXME: This needs to be populated with some flags of VS_CONSTANT_NOT_USED, VS_CONSTANT_CONSTANT, VS_CONSTANT_INTEGER, VS_CONSTANT_BOOLEAN, VS_CONSTANT_FLOAT, a half byte bitmap will be the best option, but I'll keep it as chards for siplicity */
1416 /* run time datas... */
1417 VSHADERDATA *data;
1418 IWineD3DVertexDeclaration *vertexDeclaration;
1419 #if 0 /* needs reworking */
1420 /* run time datas */
1421 VSHADERINPUTDATA input;
1422 VSHADEROUTPUTDATA output;
1423 #endif
1424 } IWineD3DVertexShaderImpl;
1425 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1426 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1428 /*****************************************************************************
1429 * IDirect3DPixelShader implementation structure
1431 typedef struct IWineD3DPixelShaderImpl {
1432 /* IUnknown parts */
1433 const IWineD3DPixelShaderVtbl *lpVtbl;
1434 LONG ref; /* Note: Ref counting not required */
1436 /* IWineD3DBaseShader */
1437 IWineD3DBaseShaderClass baseShader;
1439 /* IWineD3DPixelShaderImpl */
1440 IUnknown *parent;
1441 IWineD3DDeviceImpl *wineD3DDevice;
1443 CHAR constants[WINED3D_PSHADER_MAX_CONSTANTS];
1445 /* run time data */
1446 PSHADERDATA *data;
1448 #if 0 /* needs reworking */
1449 PSHADERINPUTDATA input;
1450 PSHADEROUTPUTDATA output;
1451 #endif
1452 } IWineD3DPixelShaderImpl;
1454 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1455 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1457 /*****************************************************************************
1458 * IWineD3DPalette implementation structure
1460 struct IWineD3DPaletteImpl {
1461 /* IUnknown parts */
1462 const IWineD3DPaletteVtbl *lpVtbl;
1463 LONG ref;
1465 IUnknown *parent;
1466 IWineD3DDeviceImpl *wineD3DDevice;
1468 /* IWineD3DPalette */
1469 HPALETTE hpal;
1470 WORD palVersion; /*| */
1471 WORD palNumEntries; /*| LOGPALETTE */
1472 PALETTEENTRY palents[256]; /*| */
1473 /* This is to store the palette in 'screen format' */
1474 int screen_palents[256];
1475 DWORD Flags;
1478 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
1479 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
1481 /* DirectDraw utility functions */
1482 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
1483 LONG get_bitmask_red(WINED3DFORMAT fmt);
1484 LONG get_bitmask_green(WINED3DFORMAT fmt);
1485 LONG get_bitmask_blue(WINED3DFORMAT fmt);
1486 LONG get_bitmask_alpha(WINED3DFORMAT fmt);
1487 BOOL isFourcc(WINED3DFORMAT fmt);
1489 #endif