wined3d: Modified the opcode tables (and struct) to include a pointer to a GLSL gener...
[wine/hacks.git] / dlls / wined3d / wined3d_private.h
blob137cb1a44716e4f1c9c129a3297712296af340d8
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 #define eps 1e-8
383 /* Routine to fill gl caps for swapchains and IWineD3D */
384 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info,
385 Display* display);
387 /*****************************************************************************
388 * Internal representation of a light
390 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
391 struct PLIGHTINFOEL {
392 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
393 DWORD OriginalIndex;
394 LONG glIndex;
395 BOOL lightEnabled;
396 BOOL changed;
397 BOOL enabledChanged;
399 /* Converted parms to speed up swapping lights */
400 float lightPosn[4];
401 float lightDirn[4];
402 float exponent;
403 float cutoff;
405 PLIGHTINFOEL *next;
406 PLIGHTINFOEL *prev;
409 /*****************************************************************************
410 * IWineD3D implementation structure
412 typedef struct IWineD3DImpl
414 /* IUnknown fields */
415 const IWineD3DVtbl *lpVtbl;
416 LONG ref; /* Note: Ref counting not required */
418 /* WineD3D Information */
419 IUnknown *parent;
420 UINT dxVersion;
422 /* GL Information */
423 BOOL isGLInfoValid;
424 WineD3D_GL_Info gl_info;
425 } IWineD3DImpl;
427 extern const IWineD3DVtbl IWineD3D_Vtbl;
429 typedef struct SwapChainList {
430 IWineD3DSwapChain *swapchain;
431 struct SwapChainList *next;
432 } SwapChainList;
434 /** Hacked out start of a context manager!! **/
435 typedef struct glContext {
436 int Width;
437 int Height;
438 int usedcount;
439 GLXContext context;
441 Drawable drawable;
442 IWineD3DSurface *pSurface;
443 #if 0 /* TODO: someway to represent the state of the context */
444 IWineD3DStateBlock *pStateBlock;
445 #endif
446 /* a few other things like format */
447 } glContext;
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;
464 } ResourceList;
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 */
479 IUnknown *parent;
480 IWineD3D *wineD3D;
482 /* X and GL Information */
483 GLint maxConcurrentLights;
485 /* Optimization */
486 BOOL modelview_valid;
487 BOOL proj_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*/
497 UINT srcBlend;
498 UINT dstBlend;
499 UINT alphafunc;
500 UINT stencilfunc;
501 BOOL texture_shader_active; /* TODO: Confirm use is correct */
503 /* State block related */
504 BOOL isRecordingState;
505 IWineD3DStateBlockImpl *stateBlock;
506 IWineD3DStateBlockImpl *updateStateBlock;
508 /* Internal use fields */
509 WINED3DDEVICE_CREATION_PARAMETERS createParms;
510 UINT adapterNo;
511 D3DDEVTYPE devType;
513 SwapChainList *swapchains;
515 ResourceList *resources; /* a linked list to track resources created by the device */
517 /* Render Target Support */
518 IWineD3DSurface *depthStencilBuffer;
520 IWineD3DSurface *renderTarget;
521 IWineD3DSurface *stencilBufferTarget;
523 /* palettes texture management */
524 PALETTEENTRY palettes[MAX_PALETTES][256];
525 UINT currentPalette;
527 /* For rendering to a texture using glCopyTexImage */
528 BOOL renderUpsideDown;
530 /* Cursor management */
531 BOOL bCursorVisible;
532 UINT xHotSpot;
533 UINT yHotSpot;
534 UINT xScreenSpace;
535 UINT yScreenSpace;
537 /* Textures for when no other textures are mapped */
538 UINT dummyTextureName[MAX_TEXTURES];
540 /* Debug stream management */
541 BOOL debug;
543 /* Device state management */
544 HRESULT state;
545 BOOL d3d_initialized;
547 /* Screen buffer resources */
548 glContext contextCache[CONTEXT_CACHE];
550 /* A flag to check if endscene has been called before changing the render tartet */
551 BOOL sceneEnded;
553 /* process vertex shaders using software or hardware */
554 BOOL softwareVertexProcessing;
556 /* DirectDraw stuff */
557 HWND ddraw_window;
559 } IWineD3DDeviceImpl;
561 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
563 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
564 * anybody uses it for much so a good implementation is optional. */
565 typedef struct PrivateData
567 struct PrivateData* next;
569 GUID tag;
570 DWORD flags; /* DDSPD_* */
571 DWORD uniqueness_value;
573 union
575 LPVOID data;
576 LPUNKNOWN object;
577 } ptr;
579 DWORD size;
580 } PrivateData;
582 /*****************************************************************************
583 * IWineD3DResource implementation structure
585 typedef struct IWineD3DResourceClass
587 /* IUnknown fields */
588 LONG ref; /* Note: Ref counting not required */
590 /* WineD3DResource Information */
591 IUnknown *parent;
592 WINED3DRESOURCETYPE resourceType;
593 IWineD3DDeviceImpl *wineD3DDevice;
594 WINED3DPOOL pool;
595 UINT size;
596 DWORD usage;
597 WINED3DFORMAT format;
598 BYTE *allocatedMemory;
599 PrivateData *privateData;
601 } IWineD3DResourceClass;
603 typedef struct IWineD3DResourceImpl
605 /* IUnknown & WineD3DResource Information */
606 const IWineD3DResourceVtbl *lpVtbl;
607 IWineD3DResourceClass resource;
608 } IWineD3DResourceImpl;
611 /*****************************************************************************
612 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
614 typedef struct IWineD3DVertexBufferImpl
616 /* IUnknown & WineD3DResource Information */
617 const IWineD3DVertexBufferVtbl *lpVtbl;
618 IWineD3DResourceClass resource;
620 /* WineD3DVertexBuffer specifics */
621 DWORD fvf;
623 } IWineD3DVertexBufferImpl;
625 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
628 /*****************************************************************************
629 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
631 typedef struct IWineD3DIndexBufferImpl
633 /* IUnknown & WineD3DResource Information */
634 const IWineD3DIndexBufferVtbl *lpVtbl;
635 IWineD3DResourceClass resource;
637 /* WineD3DVertexBuffer specifics */
638 } IWineD3DIndexBufferImpl;
640 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
642 /*****************************************************************************
643 * IWineD3DBaseTexture D3D- > openGL state map lookups
645 #define WINED3DFUNC_NOTSUPPORTED -2
646 #define WINED3DFUNC_UNIMPLEMENTED -1
648 typedef enum winetexturestates {
649 WINED3DTEXSTA_ADDRESSU = 0,
650 WINED3DTEXSTA_ADDRESSV = 1,
651 WINED3DTEXSTA_ADDRESSW = 2,
652 WINED3DTEXSTA_BORDERCOLOR = 3,
653 WINED3DTEXSTA_MAGFILTER = 4,
654 WINED3DTEXSTA_MINFILTER = 5,
655 WINED3DTEXSTA_MIPFILTER = 6,
656 WINED3DTEXSTA_MAXMIPLEVEL = 7,
657 WINED3DTEXSTA_MAXANISOTROPY = 8,
658 WINED3DTEXSTA_SRGBTEXTURE = 9,
659 WINED3DTEXSTA_ELEMENTINDEX = 10,
660 WINED3DTEXSTA_DMAPOFFSET = 11,
661 WINED3DTEXSTA_TSSADDRESSW = 12,
662 MAX_WINETEXTURESTATES = 13,
663 } winetexturestates;
665 typedef struct Wined3dTextureStateMap {
666 CONST int state;
667 int function;
668 } Wined3dTextureStateMap;
670 /*****************************************************************************
671 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
673 typedef struct IWineD3DBaseTextureClass
675 UINT levels;
676 BOOL dirty;
677 D3DFORMAT format;
678 DWORD usage;
679 UINT textureName;
680 UINT LOD;
681 WINED3DTEXTUREFILTERTYPE filterType;
682 DWORD states[MAX_WINETEXTURESTATES];
684 } IWineD3DBaseTextureClass;
686 typedef struct IWineD3DBaseTextureImpl
688 /* IUnknown & WineD3DResource Information */
689 const IWineD3DBaseTextureVtbl *lpVtbl;
690 IWineD3DResourceClass resource;
691 IWineD3DBaseTextureClass baseTexture;
693 } IWineD3DBaseTextureImpl;
695 /*****************************************************************************
696 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
698 typedef struct IWineD3DTextureImpl
700 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
701 const IWineD3DTextureVtbl *lpVtbl;
702 IWineD3DResourceClass resource;
703 IWineD3DBaseTextureClass baseTexture;
705 /* IWineD3DTexture */
706 IWineD3DSurface *surfaces[MAX_LEVELS];
708 UINT width;
709 UINT height;
710 float pow2scalingFactorX;
711 float pow2scalingFactorY;
713 } IWineD3DTextureImpl;
715 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
717 /*****************************************************************************
718 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
720 typedef struct IWineD3DCubeTextureImpl
722 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
723 const IWineD3DCubeTextureVtbl *lpVtbl;
724 IWineD3DResourceClass resource;
725 IWineD3DBaseTextureClass baseTexture;
727 /* IWineD3DCubeTexture */
728 IWineD3DSurface *surfaces[6][MAX_LEVELS];
730 UINT edgeLength;
731 float pow2scalingFactor;
733 } IWineD3DCubeTextureImpl;
735 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
737 /*****************************************************************************
738 * IWineD3DVolume implementation structure (extends IUnknown)
740 typedef struct IWineD3DVolumeImpl
742 /* IUnknown & WineD3DResource fields */
743 const IWineD3DVolumeVtbl *lpVtbl;
744 IWineD3DResourceClass resource;
746 /* WineD3DVolume Information */
747 D3DVOLUME_DESC currentDesc;
748 IWineD3DBase *container;
749 UINT bytesPerPixel;
751 BOOL lockable;
752 BOOL locked;
753 WINED3DBOX lockedBox;
754 WINED3DBOX dirtyBox;
755 BOOL dirty;
758 } IWineD3DVolumeImpl;
760 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
762 /*****************************************************************************
763 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
765 typedef struct IWineD3DVolumeTextureImpl
767 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
768 const IWineD3DVolumeTextureVtbl *lpVtbl;
769 IWineD3DResourceClass resource;
770 IWineD3DBaseTextureClass baseTexture;
772 /* IWineD3DVolumeTexture */
773 IWineD3DVolume *volumes[MAX_LEVELS];
775 UINT width;
776 UINT height;
777 UINT depth;
778 } IWineD3DVolumeTextureImpl;
780 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
782 typedef struct _WINED3DSURFACET_DESC
784 WINED3DMULTISAMPLE_TYPE MultiSampleType;
785 DWORD MultiSampleQuality;
786 UINT Width;
787 UINT Height;
788 } WINED3DSURFACET_DESC;
790 /*****************************************************************************
791 * Structure for DIB Surfaces (GetDC and GDI surfaces)
793 typedef struct wineD3DSurface_DIB {
794 HBITMAP DIBsection;
795 void* bitmap_data;
796 HGDIOBJ holdbitmap;
797 BOOL client_memory;
798 } wineD3DSurface_DIB;
800 /*****************************************************************************
801 * IWineD3DSurface implementation structure
803 struct IWineD3DSurfaceImpl
805 /* IUnknown & IWineD3DResource Information */
806 const IWineD3DSurfaceVtbl *lpVtbl;
807 IWineD3DResourceClass resource;
809 /* IWineD3DSurface fields */
810 IWineD3DBase *container;
811 WINED3DSURFACET_DESC currentDesc;
812 IWineD3DPaletteImpl *palette;
814 UINT textureName;
815 UINT bytesPerPixel;
817 /* TODO: move this off into a management class(maybe!) */
818 WORD Flags;
820 UINT pow2Width;
821 UINT pow2Height;
822 UINT pow2Size;
824 #if 0
825 /* precalculated x and y scalings for texture coords */
826 float pow2scalingFactorX; /* = (Width / pow2Width ) */
827 float pow2scalingFactorY; /* = (Height / pow2Height) */
828 #endif
830 RECT lockedRect;
831 RECT dirtyRect;
833 glDescriptor glDescription;
835 /* For GetDC */
836 wineD3DSurface_DIB dib;
837 HDC hDC;
839 /* Color keys for DDraw */
840 DDCOLORKEY DestBltCKey;
841 DDCOLORKEY DestOverlayCKey;
842 DDCOLORKEY SrcOverlayCKey;
843 DDCOLORKEY SrcBltCKey;
844 DWORD CKeyFlags;
848 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
850 /* Surface flags: */
851 #define SFLAG_OVERSIZE 0x0001 /* Surface is bigger than gl size, blts only */
852 #define SFLAG_CONVERTED 0x0002 /* Converted for color keying or Palettized */
853 #define SFLAG_DIBSECTION 0x0004 /* Has a DIB section attached for getdc */
854 #define SFLAG_DIRTY 0x0008 /* Surface was locked by the app */
855 #define SFLAG_LOCKABLE 0x0010 /* Surface can be locked */
856 #define SFLAG_DISCARD 0x0020 /* ??? */
857 #define SFLAG_LOCKED 0x0040 /* Surface is locked atm */
858 #define SFLAG_ACTIVELOCK 0x0080 /* Not locked, but surface memory is needed */
859 #define SFLAG_INTEXTURE 0x0100 /* ??? */
860 #define SFLAG_INPBUFFER 0x0200 /* ??? */
861 #define SFLAG_NONPOW2 0x0400 /* Surface sizes are not a power of 2 */
862 #define SFLAG_DYNLOCK 0x0800 /* Surface is often locked by the app */
863 #define SFLAG_DYNCHANGE 0x1800 /* Surface contents are changed very often, implies DYNLOCK */
864 #define SFLAG_DCINUSE 0x2000 /* Set between GetDC and ReleaseDC calls */
865 #define SFLAG_NEWDC 0x4000 /* To inform LockRect about a new dc */
866 #define SFLAG_LOST 0x8000 /* Surface lost flag for DDraw */
868 /* In some conditions the surface memory must not be freed:
869 * SFLAG_OVERSIZE: Not all data can be kept in GL
870 * SFLAG_CONVERTED: Converting the data back would take too long
871 * SFLAG_DIBSECTION: The dib code manages the memory
872 * SFLAG_DIRTY: GL surface isn't up to date
873 * SFLAG_LOCKED: The app requires access to the surface data
874 * SFLAG_ACTIVELOCK: Some wined3d code needs the memory
875 * SFLAG_DYNLOCK: Avoid freeing the data for performance
876 * SFLAG_DYNCHANGE: Same reason as DYNLOCK
878 #define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
879 SFLAG_CONVERTED | \
880 SFLAG_DIBSECTION | \
881 SFLAG_DIRTY | \
882 SFLAG_LOCKED | \
883 SFLAG_ACTIVELOCK | \
884 SFLAG_DYNLOCK | \
885 SFLAG_DYNCHANGE )
887 /*****************************************************************************
888 * IWineD3DVertexDeclaration implementation structure
890 typedef struct IWineD3DVertexDeclarationImpl {
891 /* IUnknown Information */
892 const IWineD3DVertexDeclarationVtbl *lpVtbl;
893 LONG ref; /* Note: Ref counting not required */
895 IUnknown *parent;
896 /** precomputed fvf if simple declaration */
897 IWineD3DDeviceImpl *wineD3DDevice;
898 DWORD fvf[MAX_STREAMS];
899 DWORD allFVF;
901 /** dx8 compatible Declaration fields */
902 DWORD* pDeclaration8;
903 DWORD declaration8Length;
905 /** dx9+ */
906 D3DVERTEXELEMENT9 *pDeclaration9;
907 UINT declaration9NumElements;
909 WINED3DVERTEXELEMENT *pDeclarationWine;
910 UINT declarationWNumElements;
912 float *constants;
914 } IWineD3DVertexDeclarationImpl;
916 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
918 /*****************************************************************************
919 * IWineD3DStateBlock implementation structure
922 /* Internal state Block for Begin/End/Capture/Create/Apply info */
923 /* Note: Very long winded but gl Lists are not flexible enough */
924 /* to resolve everything we need, so doing it manually for now */
925 typedef struct SAVEDSTATES {
926 BOOL indices;
927 BOOL material;
928 BOOL fvf;
929 BOOL streamSource[MAX_STREAMS];
930 BOOL streamFreq[MAX_STREAMS];
931 BOOL textures[MAX_TEXTURES];
932 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
933 BOOL viewport;
934 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
935 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
936 BOOL samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
937 BOOL clipplane[MAX_CLIPPLANES];
938 BOOL vertexDecl;
939 BOOL pixelShader;
940 BOOL pixelShaderConstants[MAX_PSHADER_CONSTANTS];
941 BOOL vertexShader;
942 BOOL vertexShaderConstants[MAX_VSHADER_CONSTANTS];
943 } SAVEDSTATES;
945 typedef enum {
946 WINESHADERCNST_NONE = 0,
947 WINESHADERCNST_FLOAT = 1,
948 WINESHADERCNST_INTEGER = 2,
949 WINESHADERCNST_BOOL = 3
950 } WINESHADERCNST;
952 struct IWineD3DStateBlockImpl
954 /* IUnknown fields */
955 const IWineD3DStateBlockVtbl *lpVtbl;
956 LONG ref; /* Note: Ref counting not required */
958 /* IWineD3DStateBlock information */
959 IUnknown *parent;
960 IWineD3DDeviceImpl *wineD3DDevice;
961 WINED3DSTATEBLOCKTYPE blockType;
963 /* Array indicating whether things have been set or changed */
964 SAVEDSTATES changed;
965 SAVEDSTATES set;
967 /* Drawing - Vertex Shader or FVF related */
968 DWORD fvf;
969 /* Vertex Shader Declaration */
970 IWineD3DVertexDeclaration *vertexDecl;
972 IWineD3DVertexShader *vertexShader;
974 /* Vertex Shader Constants */
975 BOOL vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
976 INT vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
977 float vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
978 WINESHADERCNST vertexShaderConstantT[MAX_VSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
980 /* Stream Source */
981 BOOL streamIsUP;
982 UINT streamStride[MAX_STREAMS];
983 UINT streamOffset[MAX_STREAMS];
984 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
985 UINT streamFreq[MAX_STREAMS];
986 UINT streamFlags[MAX_STREAMS]; /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA */
988 /* Indices */
989 IWineD3DIndexBuffer* pIndexData;
990 UINT baseVertexIndex; /* Note: only used for d3d8 */
992 /* Transform */
993 D3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
995 /* Lights */
996 PLIGHTINFOEL *lights; /* NOTE: active GL lights must be front of the chain */
998 /* Clipping */
999 double clipplane[MAX_CLIPPLANES][4];
1000 WINED3DCLIPSTATUS clip_status;
1002 /* ViewPort */
1003 WINED3DVIEWPORT viewport;
1005 /* Material */
1006 WINED3DMATERIAL material;
1008 /* Pixel Shader */
1009 IWineD3DPixelShader *pixelShader;
1011 /* Pixel Shader Constants */
1012 BOOL pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
1013 INT pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
1014 float pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
1015 WINESHADERCNST pixelShaderConstantT[MAX_PSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
1017 /* Indexed Vertex Blending */
1018 D3DVERTEXBLENDFLAGS vertex_blend;
1019 FLOAT tween_factor;
1021 /* RenderState */
1022 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
1024 /* Texture */
1025 IWineD3DBaseTexture *textures[MAX_TEXTURES];
1026 int textureDimensions[MAX_SAMPLERS];
1028 /* Texture State Stage */
1029 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1030 /* Sampler States */
1031 DWORD samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1035 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1037 /*****************************************************************************
1038 * IWineD3DQueryImpl implementation structure (extends IUnknown)
1040 typedef struct IWineD3DQueryImpl
1042 const IWineD3DQueryVtbl *lpVtbl;
1043 LONG ref; /* Note: Ref counting not required */
1045 IUnknown *parent;
1046 /*TODO: replace with iface usage */
1047 #if 0
1048 IWineD3DDevice *wineD3DDevice;
1049 #else
1050 IWineD3DDeviceImpl *wineD3DDevice;
1051 #endif
1052 /* IWineD3DQuery fields */
1054 D3DQUERYTYPE type;
1055 /* TODO: Think about using a IUnknown instead of a void* */
1056 void *extendedData;
1059 } IWineD3DQueryImpl;
1061 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1063 /* Datastructures for IWineD3DQueryImpl.extendedData */
1064 typedef struct WineQueryOcclusionData {
1065 unsigned int queryId;
1066 } WineQueryOcclusionData;
1069 /*****************************************************************************
1070 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1073 typedef struct IWineD3DSwapChainImpl
1075 /*IUnknown part*/
1076 IWineD3DSwapChainVtbl *lpVtbl;
1077 LONG ref; /* Note: Ref counting not required */
1079 IUnknown *parent;
1080 IWineD3DDeviceImpl *wineD3DDevice;
1082 /* IWineD3DSwapChain fields */
1083 IWineD3DSurface *backBuffer;
1084 IWineD3DSurface *frontBuffer;
1085 BOOL wantsDepthStencilBuffer;
1086 D3DPRESENT_PARAMETERS presentParms;
1088 /* TODO: move everything up to drawable off into a context manager
1089 and store the 'data' in the contextManagerData interface.
1090 IUnknown *contextManagerData;
1093 HWND win_handle;
1094 Window win;
1095 Display *display;
1097 GLXContext glCtx;
1098 XVisualInfo *visInfo;
1099 GLXContext render_ctx;
1100 /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1101 Drawable drawable;
1102 } IWineD3DSwapChainImpl;
1104 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1106 /*****************************************************************************
1107 * Utility function prototypes
1110 /* Trace routines */
1111 const char* debug_d3dformat(WINED3DFORMAT fmt);
1112 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1113 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1114 const char* debug_d3dusage(DWORD usage);
1115 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1116 const char* debug_d3drenderstate(DWORD state);
1117 const char* debug_d3dtexturestate(DWORD state);
1118 const char* debug_d3dpool(WINED3DPOOL pool);
1120 /* Routines for GL <-> D3D values */
1121 GLenum StencilOp(DWORD op);
1122 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1123 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1124 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
1126 SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1127 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1128 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
1129 GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1131 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1134 /*****************************************************************************
1135 * To enable calling of inherited functions, requires prototypes
1137 * Note: Only require classes which are subclassed, ie resource, basetexture,
1139 /*** IUnknown methods ***/
1140 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1141 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1142 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1143 /*** IWineD3DResource methods ***/
1144 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1145 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1146 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1147 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1148 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1149 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1150 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1151 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1152 extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1153 /*** class static members ***/
1154 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1156 /*** IUnknown methods ***/
1157 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1158 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1159 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1160 /*** IWineD3DResource methods ***/
1161 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1162 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1163 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1164 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1165 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1166 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1167 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1168 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1169 extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1170 /*** IWineD3DBaseTexture methods ***/
1171 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1172 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1173 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1174 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1175 extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1176 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1177 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1178 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1180 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset);
1181 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1182 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1183 extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1184 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1185 /*** class static members ***/
1186 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1188 /* An enum for the type of constants that are used... addressing causes
1189 * problems with being able to work out what's used and what's not.. so
1190 * maybe we'll have to rely on the server vertex shader const functions?
1192 enum vsConstantsEnum {
1193 VS_CONSTANT_NOT_USED = 0,
1194 VS_CONSTANT_CONSTANT,
1195 VS_CONSTANT_INTEGER,
1196 VS_CONSTANT_BOOLEAN,
1197 VS_CONSTANT_FLOAT
1200 struct SHADER_OPCODE_ARG;
1201 typedef void (*shader_fct_t)();
1202 typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
1204 #define SHADER_PGMSIZE 65535
1205 typedef struct SHADER_BUFFER {
1206 char* buffer;
1207 size_t bsize;
1208 unsigned int lineNo;
1209 } SHADER_BUFFER;
1211 typedef struct SHADER_OPCODE {
1212 unsigned int opcode;
1213 const char* name;
1214 const char* glname;
1215 CONST UINT num_params;
1216 shader_fct_t soft_fct;
1217 SHADER_HANDLER hw_fct;
1218 SHADER_HANDLER hw_glsl_fct;
1219 DWORD min_version;
1220 DWORD max_version;
1221 } SHADER_OPCODE;
1223 typedef struct SHADER_OPCODE_ARG {
1224 IWineD3DBaseShader* shader;
1225 CONST SHADER_OPCODE* opcode;
1226 DWORD dst;
1227 DWORD src[4];
1228 SHADER_BUFFER* buffer;
1229 } SHADER_OPCODE_ARG;
1231 typedef struct SHADER_LIMITS {
1232 unsigned int temporary;
1233 unsigned int texture;
1234 unsigned int constant_int;
1235 unsigned int constant_float;
1236 unsigned int constant_bool;
1237 unsigned int address;
1238 } SHADER_LIMITS;
1240 /** Keeps track of details for TEX_M#x# shader opcodes which need to
1241 maintain state information between multiple codes */
1242 typedef struct SHADER_PARSE_STATE {
1243 unsigned int current_row;
1244 DWORD texcoord_w[2];
1245 } SHADER_PARSE_STATE;
1247 /* Base Shader utility functions.
1248 * (may move callers into the same file in the future) */
1249 extern int shader_addline(
1250 SHADER_BUFFER* buffer,
1251 const char* fmt, ...);
1253 extern const SHADER_OPCODE* shader_get_opcode(
1254 IWineD3DBaseShader *iface,
1255 const DWORD code);
1257 /*****************************************************************************
1258 * IDirect3DBaseShader implementation structure
1260 typedef struct IWineD3DBaseShaderClass
1262 DWORD version;
1263 DWORD hex_version;
1264 DWORD temps_used;
1265 DWORD textures_used;
1266 SHADER_LIMITS limits;
1267 SHADER_PARSE_STATE parse_state;
1268 CONST SHADER_OPCODE *shader_ins;
1269 CONST DWORD *function;
1270 UINT functionLength;
1271 GLuint prgId;
1272 } IWineD3DBaseShaderClass;
1274 typedef struct IWineD3DBaseShaderImpl {
1275 /* IUnknown */
1276 const IWineD3DBaseShaderVtbl *lpVtbl;
1277 LONG ref;
1279 /* IWineD3DBaseShader */
1280 IWineD3DBaseShaderClass baseShader;
1281 } IWineD3DBaseShaderImpl;
1283 extern void shader_get_registers_used(
1284 IWineD3DBaseShader *iface,
1285 CONST DWORD* pToken);
1287 extern void shader_program_dump_decl_usage(
1288 DWORD dcl,
1289 DWORD param);
1291 extern void generate_base_shader(
1292 IWineD3DBaseShader *iface,
1293 SHADER_BUFFER* buffer,
1294 CONST DWORD* pFunction);
1296 inline static int shader_get_regtype(const DWORD param) {
1297 return (((param & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) |
1298 ((param & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2));
1301 /*****************************************************************************
1302 * IDirect3DVertexShader implementation structure
1304 typedef struct IWineD3DVertexShaderImpl {
1305 /* IUnknown parts*/
1306 const IWineD3DVertexShaderVtbl *lpVtbl;
1307 LONG ref; /* Note: Ref counting not required */
1309 /* IWineD3DBaseShader */
1310 IWineD3DBaseShaderClass baseShader;
1312 /* IWineD3DVertexShaderImpl */
1313 IUnknown *parent;
1314 IWineD3DDeviceImpl *wineD3DDevice;
1316 DWORD usage;
1318 /* vertex declaration array mapping */
1319 BOOL namedArrays; /* don't map use named functions */
1320 BOOL declaredArrays; /* mapping requires */
1321 INT arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE]; /* lookup table for the maps */
1322 INT highestConstant;
1323 CHAR constantsUsedBitmap[256];
1324 /* 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 */
1325 /* run time datas... */
1326 VSHADERDATA *data;
1327 IWineD3DVertexDeclaration *vertexDeclaration;
1328 #if 0 /* needs reworking */
1329 /* run time datas */
1330 VSHADERINPUTDATA input;
1331 VSHADEROUTPUTDATA output;
1332 #endif
1333 } IWineD3DVertexShaderImpl;
1334 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1335 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1337 /*****************************************************************************
1338 * IDirect3DPixelShader implementation structure
1340 typedef struct IWineD3DPixelShaderImpl {
1341 /* IUnknown parts */
1342 const IWineD3DPixelShaderVtbl *lpVtbl;
1343 LONG ref; /* Note: Ref counting not required */
1345 /* IWineD3DBaseShader */
1346 IWineD3DBaseShaderClass baseShader;
1348 /* IWineD3DPixelShaderImpl */
1349 IUnknown *parent;
1350 IWineD3DDeviceImpl *wineD3DDevice;
1352 CHAR constants[WINED3D_PSHADER_MAX_CONSTANTS];
1354 /* run time data */
1355 PSHADERDATA *data;
1357 #if 0 /* needs reworking */
1358 PSHADERINPUTDATA input;
1359 PSHADEROUTPUTDATA output;
1360 #endif
1361 } IWineD3DPixelShaderImpl;
1363 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1364 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1366 /*****************************************************************************
1367 * IWineD3DPalette implementation structure
1369 struct IWineD3DPaletteImpl {
1370 /* IUnknown parts */
1371 const IWineD3DPaletteVtbl *lpVtbl;
1372 LONG ref;
1374 IUnknown *parent;
1375 IWineD3DDeviceImpl *wineD3DDevice;
1377 /* IWineD3DPalette */
1378 HPALETTE hpal;
1379 WORD palVersion; /*| */
1380 WORD palNumEntries; /*| LOGPALETTE */
1381 PALETTEENTRY palents[256]; /*| */
1382 /* This is to store the palette in 'screen format' */
1383 int screen_palents[256];
1384 DWORD Flags;
1387 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
1388 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
1390 /* DirectDraw utility functions */
1391 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
1392 LONG get_bitmask_red(WINED3DFORMAT fmt);
1393 LONG get_bitmask_green(WINED3DFORMAT fmt);
1394 LONG get_bitmask_blue(WINED3DFORMAT fmt);
1395 LONG get_bitmask_alpha(WINED3DFORMAT fmt);
1397 #endif