wined3d: Clean up per version shader limits code.
[wine/multimedia.git] / dlls / wined3d / wined3d_private.h
blobde303c5de91c2936157ec7810ec7d0e895a99957
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 /* Routine to fill gl caps for swapchains and IWineD3D */
382 BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info,
383 Display* display);
385 /*****************************************************************************
386 * Internal representation of a light
388 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
389 struct PLIGHTINFOEL {
390 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
391 DWORD OriginalIndex;
392 LONG glIndex;
393 BOOL lightEnabled;
394 BOOL changed;
395 BOOL enabledChanged;
397 /* Converted parms to speed up swapping lights */
398 float lightPosn[4];
399 float lightDirn[4];
400 float exponent;
401 float cutoff;
403 PLIGHTINFOEL *next;
404 PLIGHTINFOEL *prev;
407 /*****************************************************************************
408 * IWineD3D implementation structure
410 typedef struct IWineD3DImpl
412 /* IUnknown fields */
413 const IWineD3DVtbl *lpVtbl;
414 LONG ref; /* Note: Ref counting not required */
416 /* WineD3D Information */
417 IUnknown *parent;
418 UINT dxVersion;
420 /* GL Information */
421 BOOL isGLInfoValid;
422 WineD3D_GL_Info gl_info;
423 } IWineD3DImpl;
425 extern const IWineD3DVtbl IWineD3D_Vtbl;
427 typedef struct SwapChainList {
428 IWineD3DSwapChain *swapchain;
429 struct SwapChainList *next;
430 } SwapChainList;
432 /** Hacked out start of a context manager!! **/
433 typedef struct glContext {
434 int Width;
435 int Height;
436 int usedcount;
437 GLXContext context;
439 Drawable drawable;
440 IWineD3DSurface *pSurface;
441 #if 0 /* TODO: someway to represent the state of the context */
442 IWineD3DStateBlock *pStateBlock;
443 #endif
444 /* a few other things like format */
445 } glContext;
447 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
448 (since it will break quite a few things until contexts are managed properly!) */
449 extern BOOL pbuffer_support;
450 /* allocate one pbuffer per surface */
451 extern BOOL pbuffer_per_surface;
453 /* Maximum number of contexts/pbuffers to keep in cache,
454 set to 100 because ATI's drivers don't support deleting pBuffers properly
455 this needs to be migrated to a list and some option availalbe for controle the cache size.
457 #define CONTEXT_CACHE 100
459 typedef struct ResourceList {
460 IWineD3DResource *resource;
461 struct ResourceList *next;
462 } ResourceList;
464 /* A helper function that dumps a resource list */
465 void dumpResources(ResourceList *resources);
467 /*****************************************************************************
468 * IWineD3DDevice implementation structure
470 typedef struct IWineD3DDeviceImpl
472 /* IUnknown fields */
473 const IWineD3DDeviceVtbl *lpVtbl;
474 LONG ref; /* Note: Ref counting not required */
476 /* WineD3D Information */
477 IUnknown *parent;
478 IWineD3D *wineD3D;
480 /* X and GL Information */
481 GLint maxConcurrentLights;
483 /* Optimization */
484 BOOL modelview_valid;
485 BOOL proj_valid;
486 BOOL view_ident; /* true iff view matrix is identity */
487 BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
488 BOOL viewport_changed; /* Was the viewport changed since the last draw? */
489 GLenum tracking_parm; /* Which source is tracking current colour */
490 LONG tracking_color; /* used iff GL_COLOR_MATERIAL was enabled */
491 #define DISABLED_TRACKING 0 /* Disabled */
492 #define IS_TRACKING 1 /* tracking_parm is tracking diffuse color */
493 #define NEEDS_TRACKING 2 /* Tracking needs to be enabled when needed */
494 #define NEEDS_DISABLE 3 /* Tracking needs to be disabled when needed*/
495 UINT srcBlend;
496 UINT dstBlend;
497 UINT alphafunc;
498 UINT stencilfunc;
499 BOOL texture_shader_active; /* TODO: Confirm use is correct */
501 /* State block related */
502 BOOL isRecordingState;
503 IWineD3DStateBlockImpl *stateBlock;
504 IWineD3DStateBlockImpl *updateStateBlock;
506 /* Internal use fields */
507 WINED3DDEVICE_CREATION_PARAMETERS createParms;
508 UINT adapterNo;
509 D3DDEVTYPE devType;
511 SwapChainList *swapchains;
513 ResourceList *resources; /* a linked list to track resources created by the device */
515 /* Render Target Support */
516 IWineD3DSurface *depthStencilBuffer;
518 IWineD3DSurface *renderTarget;
519 IWineD3DSurface *stencilBufferTarget;
521 /* palettes texture management */
522 PALETTEENTRY palettes[MAX_PALETTES][256];
523 UINT currentPalette;
525 /* For rendering to a texture using glCopyTexImage */
526 BOOL renderUpsideDown;
528 /* Cursor management */
529 BOOL bCursorVisible;
530 UINT xHotSpot;
531 UINT yHotSpot;
532 UINT xScreenSpace;
533 UINT yScreenSpace;
535 /* Textures for when no other textures are mapped */
536 UINT dummyTextureName[MAX_TEXTURES];
538 /* Debug stream management */
539 BOOL debug;
541 /* Device state management */
542 HRESULT state;
543 BOOL d3d_initialized;
545 /* Screen buffer resources */
546 glContext contextCache[CONTEXT_CACHE];
548 /* A flag to check if endscene has been called before changing the render tartet */
549 BOOL sceneEnded;
551 /* process vertex shaders using software or hardware */
552 BOOL softwareVertexProcessing;
554 /* DirectDraw stuff */
555 HWND ddraw_window;
557 } IWineD3DDeviceImpl;
559 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
561 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
562 * anybody uses it for much so a good implementation is optional. */
563 typedef struct PrivateData
565 struct PrivateData* next;
567 GUID tag;
568 DWORD flags; /* DDSPD_* */
569 DWORD uniqueness_value;
571 union
573 LPVOID data;
574 LPUNKNOWN object;
575 } ptr;
577 DWORD size;
578 } PrivateData;
580 /*****************************************************************************
581 * IWineD3DResource implementation structure
583 typedef struct IWineD3DResourceClass
585 /* IUnknown fields */
586 LONG ref; /* Note: Ref counting not required */
588 /* WineD3DResource Information */
589 IUnknown *parent;
590 WINED3DRESOURCETYPE resourceType;
591 IWineD3DDeviceImpl *wineD3DDevice;
592 WINED3DPOOL pool;
593 UINT size;
594 DWORD usage;
595 WINED3DFORMAT format;
596 BYTE *allocatedMemory;
597 PrivateData *privateData;
599 } IWineD3DResourceClass;
601 typedef struct IWineD3DResourceImpl
603 /* IUnknown & WineD3DResource Information */
604 const IWineD3DResourceVtbl *lpVtbl;
605 IWineD3DResourceClass resource;
606 } IWineD3DResourceImpl;
609 /*****************************************************************************
610 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
612 typedef struct IWineD3DVertexBufferImpl
614 /* IUnknown & WineD3DResource Information */
615 const IWineD3DVertexBufferVtbl *lpVtbl;
616 IWineD3DResourceClass resource;
618 /* WineD3DVertexBuffer specifics */
619 DWORD fvf;
621 } IWineD3DVertexBufferImpl;
623 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
626 /*****************************************************************************
627 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
629 typedef struct IWineD3DIndexBufferImpl
631 /* IUnknown & WineD3DResource Information */
632 const IWineD3DIndexBufferVtbl *lpVtbl;
633 IWineD3DResourceClass resource;
635 /* WineD3DVertexBuffer specifics */
636 } IWineD3DIndexBufferImpl;
638 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
640 /*****************************************************************************
641 * IWineD3DBaseTexture D3D- > openGL state map lookups
643 #define WINED3DFUNC_NOTSUPPORTED -2
644 #define WINED3DFUNC_UNIMPLEMENTED -1
646 typedef enum winetexturestates {
647 WINED3DTEXSTA_ADDRESSU = 0,
648 WINED3DTEXSTA_ADDRESSV = 1,
649 WINED3DTEXSTA_ADDRESSW = 2,
650 WINED3DTEXSTA_BORDERCOLOR = 3,
651 WINED3DTEXSTA_MAGFILTER = 4,
652 WINED3DTEXSTA_MINFILTER = 5,
653 WINED3DTEXSTA_MIPFILTER = 6,
654 WINED3DTEXSTA_MAXMIPLEVEL = 7,
655 WINED3DTEXSTA_MAXANISOTROPY = 8,
656 WINED3DTEXSTA_SRGBTEXTURE = 9,
657 WINED3DTEXSTA_ELEMENTINDEX = 10,
658 WINED3DTEXSTA_DMAPOFFSET = 11,
659 WINED3DTEXSTA_TSSADDRESSW = 12,
660 MAX_WINETEXTURESTATES = 13,
661 } winetexturestates;
663 typedef struct Wined3dTextureStateMap {
664 CONST int state;
665 int function;
666 } Wined3dTextureStateMap;
668 /*****************************************************************************
669 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
671 typedef struct IWineD3DBaseTextureClass
673 UINT levels;
674 BOOL dirty;
675 D3DFORMAT format;
676 DWORD usage;
677 UINT textureName;
678 UINT LOD;
679 WINED3DTEXTUREFILTERTYPE filterType;
680 DWORD states[MAX_WINETEXTURESTATES];
682 } IWineD3DBaseTextureClass;
684 typedef struct IWineD3DBaseTextureImpl
686 /* IUnknown & WineD3DResource Information */
687 const IWineD3DBaseTextureVtbl *lpVtbl;
688 IWineD3DResourceClass resource;
689 IWineD3DBaseTextureClass baseTexture;
691 } IWineD3DBaseTextureImpl;
693 /*****************************************************************************
694 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
696 typedef struct IWineD3DTextureImpl
698 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
699 const IWineD3DTextureVtbl *lpVtbl;
700 IWineD3DResourceClass resource;
701 IWineD3DBaseTextureClass baseTexture;
703 /* IWineD3DTexture */
704 IWineD3DSurface *surfaces[MAX_LEVELS];
706 UINT width;
707 UINT height;
708 float pow2scalingFactorX;
709 float pow2scalingFactorY;
711 } IWineD3DTextureImpl;
713 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
715 /*****************************************************************************
716 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
718 typedef struct IWineD3DCubeTextureImpl
720 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
721 const IWineD3DCubeTextureVtbl *lpVtbl;
722 IWineD3DResourceClass resource;
723 IWineD3DBaseTextureClass baseTexture;
725 /* IWineD3DCubeTexture */
726 IWineD3DSurface *surfaces[6][MAX_LEVELS];
728 UINT edgeLength;
729 float pow2scalingFactor;
731 } IWineD3DCubeTextureImpl;
733 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
735 /*****************************************************************************
736 * IWineD3DVolume implementation structure (extends IUnknown)
738 typedef struct IWineD3DVolumeImpl
740 /* IUnknown & WineD3DResource fields */
741 const IWineD3DVolumeVtbl *lpVtbl;
742 IWineD3DResourceClass resource;
744 /* WineD3DVolume Information */
745 D3DVOLUME_DESC currentDesc;
746 IWineD3DBase *container;
747 UINT bytesPerPixel;
749 BOOL lockable;
750 BOOL locked;
751 WINED3DBOX lockedBox;
752 WINED3DBOX dirtyBox;
753 BOOL dirty;
756 } IWineD3DVolumeImpl;
758 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
760 /*****************************************************************************
761 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
763 typedef struct IWineD3DVolumeTextureImpl
765 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
766 const IWineD3DVolumeTextureVtbl *lpVtbl;
767 IWineD3DResourceClass resource;
768 IWineD3DBaseTextureClass baseTexture;
770 /* IWineD3DVolumeTexture */
771 IWineD3DVolume *volumes[MAX_LEVELS];
773 UINT width;
774 UINT height;
775 UINT depth;
776 } IWineD3DVolumeTextureImpl;
778 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
780 typedef struct _WINED3DSURFACET_DESC
782 WINED3DMULTISAMPLE_TYPE MultiSampleType;
783 DWORD MultiSampleQuality;
784 UINT Width;
785 UINT Height;
786 } WINED3DSURFACET_DESC;
788 /*****************************************************************************
789 * Structure for DIB Surfaces (GetDC and GDI surfaces)
791 typedef struct wineD3DSurface_DIB {
792 HBITMAP DIBsection;
793 void* bitmap_data;
794 HGDIOBJ holdbitmap;
795 BOOL client_memory;
796 } wineD3DSurface_DIB;
798 /*****************************************************************************
799 * IWineD3DSurface implementation structure
801 struct IWineD3DSurfaceImpl
803 /* IUnknown & IWineD3DResource Information */
804 const IWineD3DSurfaceVtbl *lpVtbl;
805 IWineD3DResourceClass resource;
807 /* IWineD3DSurface fields */
808 IWineD3DBase *container;
809 WINED3DSURFACET_DESC currentDesc;
810 IWineD3DPaletteImpl *palette;
812 UINT textureName;
813 UINT bytesPerPixel;
815 /* TODO: move this off into a management class(maybe!) */
816 WORD Flags;
818 UINT pow2Width;
819 UINT pow2Height;
820 UINT pow2Size;
822 #if 0
823 /* precalculated x and y scalings for texture coords */
824 float pow2scalingFactorX; /* = (Width / pow2Width ) */
825 float pow2scalingFactorY; /* = (Height / pow2Height) */
826 #endif
828 RECT lockedRect;
829 RECT dirtyRect;
831 glDescriptor glDescription;
833 /* For GetDC */
834 wineD3DSurface_DIB dib;
835 HDC hDC;
838 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
840 /* Surface flags: */
841 #define SFLAG_OVERSIZE 0x0001 /* Surface is bigger than gl size, blts only */
842 #define SFLAG_CONVERTED 0x0002 /* Converted for color keying or Palettized */
843 #define SFLAG_DIBSECTION 0x0004 /* Has a DIB section attached for getdc */
844 #define SFLAG_DIRTY 0x0008 /* Surface was locked by the app */
845 #define SFLAG_LOCKABLE 0x0010 /* Surface can be locked */
846 #define SFLAG_DISCARD 0x0020 /* ??? */
847 #define SFLAG_LOCKED 0x0040 /* Surface is locked atm */
848 #define SFLAG_ACTIVELOCK 0x0080 /* Not locked, but surface memory is needed */
849 #define SFLAG_INTEXTURE 0x0100 /* ??? */
850 #define SFLAG_INPBUFFER 0x0200 /* ??? */
851 #define SFLAG_NONPOW2 0x0400 /* Surface sizes are not a power of 2 */
852 #define SFLAG_DYNLOCK 0x0800 /* Surface is often locked by the app */
853 #define SFLAG_DYNCHANGE 0x1800 /* Surface contents are changed very often, implies DYNLOCK */
854 #define SFLAG_DCINUSE 0x2000 /* Set between GetDC and ReleaseDC calls */
855 #define SFLAG_NEWDC 0x4000 /* To inform LockRect about a new dc */
857 /* In some conditions the surface memory must not be freed:
858 * SFLAG_OVERSIZE: Not all data can be kept in GL
859 * SFLAG_CONVERTED: Converting the data back would take too long
860 * SFLAG_DIBSECTION: The dib code manages the memory
861 * SFLAG_DIRTY: GL surface isn't up to date
862 * SFLAG_LOCKED: The app requires access to the surface data
863 * SFLAG_ACTIVELOCK: Some wined3d code needs the memory
864 * SFLAG_DYNLOCK: Avoid freeing the data for performance
865 * SFLAG_DYNCHANGE: Same reason as DYNLOCK
867 #define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
868 SFLAG_CONVERTED | \
869 SFLAG_DIBSECTION | \
870 SFLAG_DIRTY | \
871 SFLAG_LOCKED | \
872 SFLAG_ACTIVELOCK | \
873 SFLAG_DYNLOCK | \
874 SFLAG_DYNCHANGE )
876 /*****************************************************************************
877 * IWineD3DVertexDeclaration implementation structure
879 typedef struct IWineD3DVertexDeclarationImpl {
880 /* IUnknown Information */
881 const IWineD3DVertexDeclarationVtbl *lpVtbl;
882 LONG ref; /* Note: Ref counting not required */
884 IUnknown *parent;
885 /** precomputed fvf if simple declaration */
886 IWineD3DDeviceImpl *wineD3DDevice;
887 DWORD fvf[MAX_STREAMS];
888 DWORD allFVF;
890 /** dx8 compatible Declaration fields */
891 DWORD* pDeclaration8;
892 DWORD declaration8Length;
894 /** dx9+ */
895 D3DVERTEXELEMENT9 *pDeclaration9;
896 UINT declaration9NumElements;
898 WINED3DVERTEXELEMENT *pDeclarationWine;
899 UINT declarationWNumElements;
901 float *constants;
903 } IWineD3DVertexDeclarationImpl;
905 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
907 /*****************************************************************************
908 * IWineD3DStateBlock implementation structure
911 /* Internal state Block for Begin/End/Capture/Create/Apply info */
912 /* Note: Very long winded but gl Lists are not flexible enough */
913 /* to resolve everything we need, so doing it manually for now */
914 typedef struct SAVEDSTATES {
915 BOOL indices;
916 BOOL material;
917 BOOL fvf;
918 BOOL streamSource[MAX_STREAMS];
919 BOOL streamFreq[MAX_STREAMS];
920 BOOL textures[MAX_TEXTURES];
921 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
922 BOOL viewport;
923 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
924 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
925 BOOL samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
926 BOOL clipplane[MAX_CLIPPLANES];
927 BOOL vertexDecl;
928 BOOL pixelShader;
929 BOOL pixelShaderConstants[MAX_PSHADER_CONSTANTS];
930 BOOL vertexShader;
931 BOOL vertexShaderConstants[MAX_VSHADER_CONSTANTS];
932 } SAVEDSTATES;
934 typedef enum {
935 WINESHADERCNST_NONE = 0,
936 WINESHADERCNST_FLOAT = 1,
937 WINESHADERCNST_INTEGER = 2,
938 WINESHADERCNST_BOOL = 3
939 } WINESHADERCNST;
941 struct IWineD3DStateBlockImpl
943 /* IUnknown fields */
944 const IWineD3DStateBlockVtbl *lpVtbl;
945 LONG ref; /* Note: Ref counting not required */
947 /* IWineD3DStateBlock information */
948 IUnknown *parent;
949 IWineD3DDeviceImpl *wineD3DDevice;
950 WINED3DSTATEBLOCKTYPE blockType;
952 /* Array indicating whether things have been set or changed */
953 SAVEDSTATES changed;
954 SAVEDSTATES set;
956 /* Drawing - Vertex Shader or FVF related */
957 DWORD fvf;
958 /* Vertex Shader Declaration */
959 IWineD3DVertexDeclaration *vertexDecl;
961 IWineD3DVertexShader *vertexShader;
963 /* Vertex Shader Constants */
964 BOOL vertexShaderConstantB[MAX_VSHADER_CONSTANTS];
965 INT vertexShaderConstantI[MAX_VSHADER_CONSTANTS * 4];
966 float vertexShaderConstantF[MAX_VSHADER_CONSTANTS * 4];
967 WINESHADERCNST vertexShaderConstantT[MAX_VSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
969 /* Stream Source */
970 BOOL streamIsUP;
971 UINT streamStride[MAX_STREAMS];
972 UINT streamOffset[MAX_STREAMS];
973 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
974 UINT streamFreq[MAX_STREAMS];
975 UINT streamFlags[MAX_STREAMS]; /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA */
977 /* Indices */
978 IWineD3DIndexBuffer* pIndexData;
979 UINT baseVertexIndex; /* Note: only used for d3d8 */
981 /* Transform */
982 D3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
984 /* Lights */
985 PLIGHTINFOEL *lights; /* NOTE: active GL lights must be front of the chain */
987 /* Clipping */
988 double clipplane[MAX_CLIPPLANES][4];
989 WINED3DCLIPSTATUS clip_status;
991 /* ViewPort */
992 WINED3DVIEWPORT viewport;
994 /* Material */
995 WINED3DMATERIAL material;
997 /* Pixel Shader */
998 IWineD3DPixelShader *pixelShader;
1000 /* Pixel Shader Constants */
1001 BOOL pixelShaderConstantB[MAX_PSHADER_CONSTANTS];
1002 INT pixelShaderConstantI[MAX_PSHADER_CONSTANTS * 4];
1003 float pixelShaderConstantF[MAX_PSHADER_CONSTANTS * 4];
1004 WINESHADERCNST pixelShaderConstantT[MAX_PSHADER_CONSTANTS]; /* TODO: Think about changing this to a char to possibly save a little memory */
1006 /* Indexed Vertex Blending */
1007 D3DVERTEXBLENDFLAGS vertex_blend;
1008 FLOAT tween_factor;
1010 /* RenderState */
1011 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
1013 /* Texture */
1014 IWineD3DBaseTexture *textures[MAX_TEXTURES];
1015 int textureDimensions[MAX_SAMPLERS];
1017 /* Texture State Stage */
1018 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1019 /* Sampler States */
1020 DWORD samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1024 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1026 /*****************************************************************************
1027 * IWineD3DQueryImpl implementation structure (extends IUnknown)
1029 typedef struct IWineD3DQueryImpl
1031 const IWineD3DQueryVtbl *lpVtbl;
1032 LONG ref; /* Note: Ref counting not required */
1034 IUnknown *parent;
1035 /*TODO: replace with iface usage */
1036 #if 0
1037 IWineD3DDevice *wineD3DDevice;
1038 #else
1039 IWineD3DDeviceImpl *wineD3DDevice;
1040 #endif
1041 /* IWineD3DQuery fields */
1043 D3DQUERYTYPE type;
1044 /* TODO: Think about using a IUnknown instead of a void* */
1045 void *extendedData;
1048 } IWineD3DQueryImpl;
1050 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1052 /* Datastructures for IWineD3DQueryImpl.extendedData */
1053 typedef struct WineQueryOcclusionData {
1054 unsigned int queryId;
1055 } WineQueryOcclusionData;
1058 /*****************************************************************************
1059 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1062 typedef struct IWineD3DSwapChainImpl
1064 /*IUnknown part*/
1065 IWineD3DSwapChainVtbl *lpVtbl;
1066 LONG ref; /* Note: Ref counting not required */
1068 IUnknown *parent;
1069 IWineD3DDeviceImpl *wineD3DDevice;
1071 /* IWineD3DSwapChain fields */
1072 IWineD3DSurface *backBuffer;
1073 IWineD3DSurface *frontBuffer;
1074 BOOL wantsDepthStencilBuffer;
1075 D3DPRESENT_PARAMETERS presentParms;
1077 /* TODO: move everything up to drawable off into a context manager
1078 and store the 'data' in the contextManagerData interface.
1079 IUnknown *contextManagerData;
1082 HWND win_handle;
1083 Window win;
1084 Display *display;
1086 GLXContext glCtx;
1087 XVisualInfo *visInfo;
1088 GLXContext render_ctx;
1089 /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1090 Drawable drawable;
1091 } IWineD3DSwapChainImpl;
1093 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1095 /*****************************************************************************
1096 * Utility function prototypes
1099 /* Trace routines */
1100 const char* debug_d3dformat(WINED3DFORMAT fmt);
1101 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1102 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1103 const char* debug_d3dusage(DWORD usage);
1104 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1105 const char* debug_d3drenderstate(DWORD state);
1106 const char* debug_d3dtexturestate(DWORD state);
1107 const char* debug_d3dpool(WINED3DPOOL pool);
1109 /* Routines for GL <-> D3D values */
1110 GLenum StencilOp(DWORD op);
1111 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1112 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1113 void GetSrcAndOpFromValue(DWORD iValue, BOOL isAlphaArg, GLenum* source, GLenum* operand);
1115 SHORT D3DFmtGetBpp(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1116 GLenum D3DFmt2GLFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1117 GLenum D3DFmt2GLType(IWineD3DDeviceImpl *This, D3DFORMAT fmt);
1118 GLint D3DFmt2GLIntFmt(IWineD3DDeviceImpl* This, D3DFORMAT fmt);
1120 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1123 /*****************************************************************************
1124 * To enable calling of inherited functions, requires prototypes
1126 * Note: Only require classes which are subclassed, ie resource, basetexture,
1128 /*** IUnknown methods ***/
1129 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1130 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1131 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1132 /*** IWineD3DResource methods ***/
1133 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1134 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1135 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1136 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1137 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1138 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1139 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1140 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1141 extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1142 /*** class static members ***/
1143 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1145 /*** IUnknown methods ***/
1146 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1147 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1148 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1149 /*** IWineD3DResource methods ***/
1150 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1151 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1152 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1153 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1154 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1155 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1156 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1157 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1158 extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1159 /*** IWineD3DBaseTexture methods ***/
1160 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1161 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1162 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1163 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1164 extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1165 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1166 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1167 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1169 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset);
1170 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1171 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1172 extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1173 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1174 /*** class static members ***/
1175 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1177 /* An enum for the type of constants that are used... addressing causes
1178 * problems with being able to work out what's used and what's not.. so
1179 * maybe we'll have to rely on the server vertex shader const functions?
1181 enum vsConstantsEnum {
1182 VS_CONSTANT_NOT_USED = 0,
1183 VS_CONSTANT_CONSTANT,
1184 VS_CONSTANT_INTEGER,
1185 VS_CONSTANT_BOOLEAN,
1186 VS_CONSTANT_FLOAT
1189 typedef void (*shader_fct_t)();
1191 typedef struct SHADER_OPCODE {
1192 unsigned int opcode;
1193 const char* name;
1194 const char* glname;
1195 CONST UINT num_params;
1196 shader_fct_t soft_fct;
1197 DWORD min_version;
1198 DWORD max_version;
1199 } SHADER_OPCODE;
1201 #define SHADER_PGMSIZE 65535
1202 typedef struct SHADER_BUFFER {
1203 char* buffer;
1204 size_t bsize;
1205 unsigned int lineNo;
1206 } SHADER_BUFFER;
1208 typedef struct SHADER_LIMITS {
1209 unsigned int temporary;
1210 unsigned int texture;
1211 unsigned int constant_int;
1212 unsigned int constant_float;
1213 unsigned int constant_bool;
1214 unsigned int address;
1215 } SHADER_LIMITS;
1217 /* Base Shader utility functions.
1218 * (may move callers into the same file in the future) */
1219 extern int shader_addline(
1220 SHADER_BUFFER* buffer,
1221 const char* fmt, ...);
1223 /*****************************************************************************
1224 * IDirect3DBaseShader implementation structure
1226 typedef struct IWineD3DBaseShaderClass
1228 DWORD version;
1229 DWORD hex_version;
1230 SHADER_LIMITS limits;
1231 CONST SHADER_OPCODE *shader_ins;
1232 CONST DWORD *function;
1233 UINT functionLength;
1234 GLuint prgId;
1235 } IWineD3DBaseShaderClass;
1237 typedef struct IWineD3DBaseShaderImpl {
1238 /* IUnknown */
1239 const IWineD3DBaseShaderVtbl *lpVtbl;
1240 LONG ref;
1242 /* IWineD3DBaseShader */
1243 IWineD3DBaseShaderClass baseShader;
1244 } IWineD3DBaseShaderImpl;
1246 inline static int shader_get_regtype(const DWORD param) {
1247 return (((param & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) |
1248 ((param & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2));
1251 /*****************************************************************************
1252 * IDirect3DVertexShader implementation structure
1254 typedef struct IWineD3DVertexShaderImpl {
1255 /* IUnknown parts*/
1256 const IWineD3DVertexShaderVtbl *lpVtbl;
1257 LONG ref; /* Note: Ref counting not required */
1259 /* IWineD3DBaseShader */
1260 IWineD3DBaseShaderClass baseShader;
1262 /* IWineD3DVertexShaderImpl */
1263 IUnknown *parent;
1264 IWineD3DDeviceImpl *wineD3DDevice;
1266 DWORD usage;
1268 /* vertex declaration array mapping */
1269 BOOL namedArrays; /* don't map use named functions */
1270 BOOL declaredArrays; /* mapping requires */
1271 INT arrayUsageMap[WINED3DSHADERDECLUSAGE_MAX_USAGE]; /* lookup table for the maps */
1272 INT highestConstant;
1273 CHAR constantsUsedBitmap[256];
1274 /* 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 */
1275 /* run time datas... */
1276 VSHADERDATA *data;
1277 IWineD3DVertexDeclaration *vertexDeclaration;
1278 #if 0 /* needs reworking */
1279 /* run time datas */
1280 VSHADERINPUTDATA input;
1281 VSHADEROUTPUTDATA output;
1282 #endif
1283 } IWineD3DVertexShaderImpl;
1284 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1285 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1287 /*****************************************************************************
1288 * IDirect3DPixelShader implementation structure
1290 typedef struct IWineD3DPixelShaderImpl {
1291 /* IUnknown parts */
1292 const IWineD3DPixelShaderVtbl *lpVtbl;
1293 LONG ref; /* Note: Ref counting not required */
1295 /* IWineD3DBaseShader */
1296 IWineD3DBaseShaderClass baseShader;
1298 /* IWineD3DPixelShaderImpl */
1299 IUnknown *parent;
1300 IWineD3DDeviceImpl *wineD3DDevice;
1302 CHAR constants[WINED3D_PSHADER_MAX_CONSTANTS];
1304 /* run time data */
1305 PSHADERDATA *data;
1307 #if 0 /* needs reworking */
1308 PSHADERINPUTDATA input;
1309 PSHADEROUTPUTDATA output;
1310 #endif
1311 } IWineD3DPixelShaderImpl;
1313 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1314 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1316 /*****************************************************************************
1317 * IWineD3DPalette implementation structure
1319 struct IWineD3DPaletteImpl {
1320 /* IUnknown parts */
1321 const IWineD3DPaletteVtbl *lpVtbl;
1322 LONG ref;
1324 IUnknown *parent;
1325 IWineD3DDeviceImpl *wineD3DDevice;
1327 /* IWineD3DPalette */
1328 HPALETTE hpal;
1329 WORD palVersion; /*| */
1330 WORD palNumEntries; /*| LOGPALETTE */
1331 PALETTEENTRY palents[256]; /*| */
1332 /* This is to store the palette in 'screen format' */
1333 int screen_palents[256];
1334 DWORD Flags;
1337 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
1338 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
1340 /* DirectDraw utility functions */
1341 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
1342 LONG get_bitmask_red(WINED3DFORMAT fmt);
1343 LONG get_bitmask_green(WINED3DFORMAT fmt);
1344 LONG get_bitmask_blue(WINED3DFORMAT fmt);
1345 LONG get_bitmask_alpha(WINED3DFORMAT fmt);
1347 #endif