wined3d: Correctly draw transformed and untransformed vertices in the same scene.
[wine/multimedia.git] / dlls / wined3d / wined3d_private.h
blobcfb8a7da4fb0bce14d455819c421319f471e6f29
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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"
45 #include "wine/list.h"
47 /* Device caps */
48 #define MAX_PALETTES 256
49 #define MAX_STREAMS 16
50 #define MAX_TEXTURES 8
51 #define MAX_SAMPLERS 16
52 #define MAX_ACTIVE_LIGHTS 8
53 #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
54 #define MAX_LEVELS 256
56 #define MAX_CONST_I 16
57 #define MAX_CONST_B 16
59 /* Used for CreateStateBlock */
60 #define NUM_SAVEDPIXELSTATES_R 35
61 #define NUM_SAVEDPIXELSTATES_T 18
62 #define NUM_SAVEDPIXELSTATES_S 12
63 #define NUM_SAVEDVERTEXSTATES_R 31
64 #define NUM_SAVEDVERTEXSTATES_T 2
65 #define NUM_SAVEDVERTEXSTATES_S 1
67 extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
68 extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
69 extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
70 extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
71 extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
72 extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
74 typedef enum _WINELOOKUP {
75 WINELOOKUP_WARPPARAM = 0,
76 WINELOOKUP_MAGFILTER = 1,
77 MAX_LOOKUPS = 2
78 } WINELOOKUP;
80 extern int minLookup[MAX_LOOKUPS];
81 extern int maxLookup[MAX_LOOKUPS];
82 extern DWORD *stateLookup[MAX_LOOKUPS];
84 extern DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
86 typedef struct _WINED3DGLTYPE {
87 int d3dType;
88 GLint size;
89 GLenum glType;
90 GLboolean normalized;
91 int typesize;
92 } WINED3DGLTYPE;
94 /* NOTE: Make sure these are in the correct numerical order. (see /include/d3d9types.h typedef enum _D3DDECLTYPE) */
95 static WINED3DGLTYPE const glTypeLookup[D3DDECLTYPE_UNUSED] = {
96 {D3DDECLTYPE_FLOAT1, 1, GL_FLOAT , GL_FALSE ,sizeof(float)},
97 {D3DDECLTYPE_FLOAT2, 2, GL_FLOAT , GL_FALSE ,sizeof(float)},
98 {D3DDECLTYPE_FLOAT3, 3, GL_FLOAT , GL_FALSE ,sizeof(float)},
99 {D3DDECLTYPE_FLOAT4, 4, GL_FLOAT , GL_FALSE ,sizeof(float)},
100 {D3DDECLTYPE_D3DCOLOR, 4, GL_UNSIGNED_BYTE , GL_TRUE ,sizeof(BYTE)},
101 {D3DDECLTYPE_UBYTE4, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
102 {D3DDECLTYPE_SHORT2, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
103 {D3DDECLTYPE_SHORT4, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
104 {D3DDECLTYPE_UBYTE4N, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
105 {D3DDECLTYPE_SHORT2N, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
106 {D3DDECLTYPE_SHORT4N, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
107 {D3DDECLTYPE_USHORT2N, 2, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
108 {D3DDECLTYPE_USHORT4N, 4, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
109 {D3DDECLTYPE_UDEC3, 3, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
110 {D3DDECLTYPE_DEC3N, 3, GL_SHORT , GL_FALSE ,sizeof(short int)},
111 {D3DDECLTYPE_FLOAT16_2, 2, GL_FLOAT , GL_FALSE ,sizeof(short int)},
112 {D3DDECLTYPE_FLOAT16_4, 4, GL_FLOAT , GL_FALSE ,sizeof(short int)}};
114 #define WINED3D_ATR_TYPE(type) glTypeLookup[type].d3dType
115 #define WINED3D_ATR_SIZE(type) glTypeLookup[type].size
116 #define WINED3D_ATR_GLTYPE(type) glTypeLookup[type].glType
117 #define WINED3D_ATR_NORMALIZED(type) glTypeLookup[type].normalized
118 #define WINED3D_ATR_TYPESIZE(type) glTypeLookup[type].typesize
121 * Settings
123 #define VS_NONE 0
124 #define VS_HW 1
125 #define VS_SW 2
127 #define PS_NONE 0
128 #define PS_HW 1
130 #define VBO_NONE 0
131 #define VBO_HW 1
133 #define NP2_NONE 0
134 #define NP2_REPACK 1
136 #define SHADER_SW 0
137 #define SHADER_ARB 1
138 #define SHADER_GLSL 2
139 #define SHADER_NONE 3
141 #define RTL_DISABLE -1
142 #define RTL_AUTO 0
143 #define RTL_READDRAW 1
144 #define RTL_READTEX 2
145 #define RTL_TEXDRAW 3
146 #define RTL_TEXTEX 4
148 typedef struct wined3d_settings_s {
149 /* vertex and pixel shader modes */
150 int vs_mode;
151 int ps_mode;
152 int vbo_mode;
153 /* Ideally, we don't want the user to have to request GLSL. If the hardware supports GLSL,
154 we should use it. However, until it's fully implemented, we'll leave it as a registry
155 setting for developers. */
156 BOOL glslRequested;
157 int vs_selected_mode;
158 int ps_selected_mode;
159 /* nonpower 2 function */
160 int nonpower2_mode;
161 int rendertargetlock_mode;
162 /* Memory tracking and object counting */
163 unsigned int emulated_textureram;
164 } wined3d_settings_t;
166 extern wined3d_settings_t wined3d_settings;
168 /* X11 locking */
170 extern void (*wine_tsx11_lock_ptr)(void);
171 extern void (*wine_tsx11_unlock_ptr)(void);
173 /* As GLX relies on X, this is needed */
174 extern int num_lock;
176 #if 0
177 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
178 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
179 #else
180 #define ENTER_GL() wine_tsx11_lock_ptr()
181 #define LEAVE_GL() wine_tsx11_unlock_ptr()
182 #endif
184 /*****************************************************************************
185 * Defines
188 /* GL related defines */
189 /* ------------------ */
190 #define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
191 #define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
192 #define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
193 #define GL_VEND(_VendName) (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
195 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
196 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
197 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
198 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
200 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
201 #define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
202 #define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
203 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
205 #define D3DCOLORTOGLFLOAT4(dw, vec) \
206 (vec)[0] = D3DCOLOR_R(dw); \
207 (vec)[1] = D3DCOLOR_G(dw); \
208 (vec)[2] = D3DCOLOR_B(dw); \
209 (vec)[3] = D3DCOLOR_A(dw);
211 #define GLTEXTURECUBEMAP GL_TEXTURE_CUBE_MAP_ARB
213 /* DirectX Device Limits */
214 /* --------------------- */
215 #define MAX_LEVELS 256 /* Maximum number of mipmap levels. Guessed at 256 */
217 #define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
218 See MaxStreams in MSDN under GetDeviceCaps */
219 /* Maximum number of constants provided to the shaders */
220 #define HIGHEST_TRANSFORMSTATE 512
221 /* Highest value in D3DTRANSFORMSTATETYPE */
222 #define MAX_CLIPPLANES D3DMAXUSERCLIPPLANES
224 #define MAX_PALETTES 256
226 /* Checking of API calls */
227 /* --------------------- */
228 #define checkGLcall(A) \
230 GLint err = glGetError(); \
231 if (err == GL_NO_ERROR) { \
232 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
234 } else do { \
235 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", \
236 err, A, __FILE__, __LINE__); \
237 err = glGetError(); \
238 } while (err != GL_NO_ERROR); \
241 /* Trace routines / diagnostics */
242 /* ---------------------------- */
244 /* Dump out a matrix and copy it */
245 #define conv_mat(mat,gl_mat) \
246 do { \
247 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
248 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
249 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
250 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
251 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
252 } while (0)
254 /* Macro to dump out the current state of the light chain */
255 #define DUMP_LIGHT_CHAIN() \
257 PLIGHTINFOEL *el = This->stateBlock->lights;\
258 while (el) { \
259 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
260 el = el->next; \
264 /* Trace vector and strided data information */
265 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
266 #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);
268 /* Defines used for optimizations */
270 /* Only reapply what is necessary */
271 #define REAPPLY_ALPHAOP 0x0001
272 #define REAPPLY_ALL 0xFFFF
274 /* Advance declaration of structures to satisfy compiler */
275 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
276 typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
277 typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl;
279 /* Tracking */
281 /* TODO: Move some of this to the device */
282 long globalChangeGlRam(long glram);
284 /* Memory and object tracking */
286 /*Structure for holding information on all direct3d objects
287 useful for making sure tracking is ok and when release is called on a device!
288 and probably quite handy for debugging and dumping states out
290 typedef struct WineD3DGlobalStatistics {
291 int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
292 } WineD3DGlobalStatistics;
294 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
296 /* Global variables */
297 extern const float identity[16];
299 /*****************************************************************************
300 * Compilable extra diagnostics
303 /* Trace information per-vertex: (extremely high amount of trace) */
304 #if 0 /* NOTE: Must be 0 in cvs */
305 # define VTRACE(A) TRACE A
306 #else
307 # define VTRACE(A)
308 #endif
310 /* Checking of per-vertex related GL calls */
311 /* --------------------- */
312 #define vcheckGLcall(A) \
314 GLint err = glGetError(); \
315 if (err == GL_NO_ERROR) { \
316 VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
318 } else do { \
319 FIXME(">>>>>>>>>>>>>>>>> %x from %s @ %s / %d\n", \
320 err, A, __FILE__, __LINE__); \
321 err = glGetError(); \
322 } while (err != GL_NO_ERROR); \
325 /* TODO: Confirm each of these works when wined3d move completed */
326 #if 0 /* NOTE: Must be 0 in cvs */
327 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
328 of each frame, a check is made for the existence of C:\D3DTRACE, and if if exists d3d trace
329 is enabled, and if it doesn't exists it is disabled. */
330 # define FRAME_DEBUGGING
331 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
332 the file is deleted */
333 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
334 # define SINGLE_FRAME_DEBUGGING
335 # endif
336 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
337 It can only be enabled when FRAME_DEBUGGING is also enabled
338 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
339 array is drawn. */
340 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
341 # define SHOW_FRAME_MAKEUP 1
342 # endif
343 /* The following, when enabled, lets you see the makeup of the all the textures used during each
344 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
345 The contents of the textures assigned to each stage are written into
346 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
347 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
348 # define SHOW_TEXTURE_MAKEUP 0
349 # endif
350 extern BOOL isOn;
351 extern BOOL isDumpingFrames;
352 extern LONG primCounter;
353 #endif
355 /*****************************************************************************
356 * Prototypes
359 /* Routine common to the draw primitive and draw indexed primitive routines */
360 void drawPrimitive(IWineD3DDevice *iface,
361 int PrimitiveType,
362 long NumPrimitives,
363 /* for Indexed: */
364 long StartVertexIndex,
365 UINT numberOfVertices,
366 long StartIdx,
367 short idxBytes,
368 const void *idxData,
369 int minIndex,
370 WineDirect3DVertexStridedData *DrawPrimStrideData);
372 void primitiveConvertToStridedData(IWineD3DDevice *iface, WineDirect3DVertexStridedData *strided, LONG BaseVertexIndex, BOOL *fixup);
374 void primitiveDeclarationConvertToStridedData(
375 IWineD3DDevice *iface,
376 BOOL useVertexShaderFunction,
377 WineDirect3DVertexStridedData *strided,
378 LONG BaseVertexIndex,
379 BOOL *fixup);
381 void primitiveConvertFVFtoOffset(DWORD thisFVF,
382 DWORD stride,
383 BYTE *data,
384 WineDirect3DVertexStridedData *strided,
385 GLint streamVBO);
387 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
389 #define eps 1e-8
391 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
392 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
394 /* Routine to fill gl caps for swapchains and IWineD3D */
395 BOOL IWineD3DImpl_FillGLCaps(IWineD3D *iface, Display* display);
397 /* Macros for doing basic GPU detection based on opengl capabilities */
398 #define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
399 #define WINE_D3D7_CAPABLE(gl_info) (gl_info->supported[ARB_TEXTURE_COMPRESSION] && gl_info->supported[ARB_TEXTURE_CUBE_MAP] && gl_info->supported[ARB_TEXTURE_ENV_DOT3])
400 #define WINE_D3D8_CAPABLE(gl_info) WINE_D3D7_CAPABLE(gl_info) && (gl_info->supported[ARB_MULTISAMPLE] && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
401 #define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER])
403 /*****************************************************************************
404 * Internal representation of a light
406 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
407 struct PLIGHTINFOEL {
408 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
409 DWORD OriginalIndex;
410 LONG glIndex;
411 BOOL lightEnabled;
412 BOOL changed;
413 BOOL enabledChanged;
415 /* Converted parms to speed up swapping lights */
416 float lightPosn[4];
417 float lightDirn[4];
418 float exponent;
419 float cutoff;
421 PLIGHTINFOEL *next;
422 PLIGHTINFOEL *prev;
425 /* The default light parameters */
426 extern const WINED3DLIGHT WINED3D_default_light;
428 /*****************************************************************************
429 * IWineD3D implementation structure
431 typedef struct IWineD3DImpl
433 /* IUnknown fields */
434 const IWineD3DVtbl *lpVtbl;
435 LONG ref; /* Note: Ref counting not required */
437 /* WineD3D Information */
438 IUnknown *parent;
439 UINT dxVersion;
441 /* GL Information */
442 BOOL isGLInfoValid;
443 WineD3D_GL_Info gl_info;
444 } IWineD3DImpl;
446 extern const IWineD3DVtbl IWineD3D_Vtbl;
448 /** Hacked out start of a context manager!! **/
449 typedef struct glContext {
450 int Width;
451 int Height;
452 int usedcount;
453 GLXContext context;
455 Drawable drawable;
456 IWineD3DSurface *pSurface;
457 #if 0 /* TODO: someway to represent the state of the context */
458 IWineD3DStateBlock *pStateBlock;
459 #endif
460 /* a few other things like format */
461 } glContext;
463 /* TODO: setup some flags in the regestry to enable, disable pbuffer support
464 (since it will break quite a few things until contexts are managed properly!) */
465 extern BOOL pbuffer_support;
466 /* allocate one pbuffer per surface */
467 extern BOOL pbuffer_per_surface;
469 /* Maximum number of contexts/pbuffers to keep in cache,
470 set to 100 because ATI's drivers don't support deleting pBuffers properly
471 this needs to be migrated to a list and some option availalbe for controle the cache size.
473 #define CONTEXT_CACHE 100
475 typedef struct ResourceList {
476 IWineD3DResource *resource;
477 struct ResourceList *next;
478 } ResourceList;
480 /* A helper function that dumps a resource list */
481 void dumpResources(ResourceList *resources);
483 /*****************************************************************************
484 * IWineD3DDevice implementation structure
486 typedef struct IWineD3DDeviceImpl
488 /* IUnknown fields */
489 const IWineD3DDeviceVtbl *lpVtbl;
490 LONG ref; /* Note: Ref counting not required */
492 /* WineD3D Information */
493 IUnknown *parent;
494 IWineD3D *wineD3D;
496 /* X and GL Information */
497 GLint maxConcurrentLights;
499 /* Optimization */
500 BOOL modelview_valid;
501 BOOL proj_valid;
502 BOOL view_ident; /* true iff view matrix is identity */
503 BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
504 BOOL viewport_changed; /* Was the viewport changed since the last draw? */
505 GLenum tracking_parm; /* Which source is tracking current colour */
506 LONG tracking_color; /* used iff GL_COLOR_MATERIAL was enabled */
507 #define DISABLED_TRACKING 0 /* Disabled */
508 #define IS_TRACKING 1 /* tracking_parm is tracking diffuse color */
509 #define NEEDS_TRACKING 2 /* Tracking needs to be enabled when needed */
510 #define NEEDS_DISABLE 3 /* Tracking needs to be disabled when needed*/
511 UINT srcBlend;
512 UINT dstBlend;
513 UINT alphafunc;
514 BOOL texture_shader_active; /* TODO: Confirm use is correct */
515 BOOL last_was_notclipped;
516 BOOL untransformed;
518 /* State block related */
519 BOOL isRecordingState;
520 IWineD3DStateBlockImpl *stateBlock;
521 IWineD3DStateBlockImpl *updateStateBlock;
523 /* Internal use fields */
524 WINED3DDEVICE_CREATION_PARAMETERS createParms;
525 UINT adapterNo;
526 D3DDEVTYPE devType;
528 IWineD3DSwapChain **swapchains;
529 uint NumberOfSwapChains;
531 ResourceList *resources; /* a linked list to track resources created by the device */
533 /* Render Target Support */
534 IWineD3DSurface *depthStencilBuffer;
536 IWineD3DSurface *renderTarget;
537 IWineD3DSurface *stencilBufferTarget;
539 /* palettes texture management */
540 PALETTEENTRY palettes[MAX_PALETTES][256];
541 UINT currentPalette;
543 /* For rendering to a texture using glCopyTexImage */
544 BOOL renderUpsideDown;
546 /* Cursor management */
547 BOOL bCursorVisible;
548 UINT xHotSpot;
549 UINT yHotSpot;
550 UINT xScreenSpace;
551 UINT yScreenSpace;
552 UINT cursorWidth, cursorHeight;
553 GLuint cursorTexture;
555 /* Textures for when no other textures are mapped */
556 UINT dummyTextureName[MAX_TEXTURES];
558 /* Debug stream management */
559 BOOL debug;
561 /* Device state management */
562 HRESULT state;
563 BOOL d3d_initialized;
565 /* Screen buffer resources */
566 glContext contextCache[CONTEXT_CACHE];
568 /* A flag to check if endscene has been called before changing the render tartet */
569 BOOL sceneEnded;
571 /* process vertex shaders using software or hardware */
572 BOOL softwareVertexProcessing;
574 /* DirectDraw stuff */
575 HWND ddraw_window;
576 IWineD3DSurface *ddraw_primary;
577 DWORD ddraw_width, ddraw_height;
578 WINED3DFORMAT ddraw_format;
580 /* List of GLSL shader programs and their associated vertex & pixel shaders */
581 struct list glsl_shader_progs;
583 } IWineD3DDeviceImpl;
585 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
587 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
588 * anybody uses it for much so a good implementation is optional. */
589 typedef struct PrivateData
591 struct PrivateData* next;
593 GUID tag;
594 DWORD flags; /* DDSPD_* */
595 DWORD uniqueness_value;
597 union
599 LPVOID data;
600 LPUNKNOWN object;
601 } ptr;
603 DWORD size;
604 } PrivateData;
606 void d3ddevice_set_ortho(IWineD3DDeviceImpl *This);
608 /*****************************************************************************
609 * IWineD3DResource implementation structure
611 typedef struct IWineD3DResourceClass
613 /* IUnknown fields */
614 LONG ref; /* Note: Ref counting not required */
616 /* WineD3DResource Information */
617 IUnknown *parent;
618 WINED3DRESOURCETYPE resourceType;
619 IWineD3DDeviceImpl *wineD3DDevice;
620 WINED3DPOOL pool;
621 UINT size;
622 DWORD usage;
623 WINED3DFORMAT format;
624 BYTE *allocatedMemory;
625 PrivateData *privateData;
627 } IWineD3DResourceClass;
629 typedef struct IWineD3DResourceImpl
631 /* IUnknown & WineD3DResource Information */
632 const IWineD3DResourceVtbl *lpVtbl;
633 IWineD3DResourceClass resource;
634 } IWineD3DResourceImpl;
637 /*****************************************************************************
638 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
640 typedef struct IWineD3DVertexBufferImpl
642 /* IUnknown & WineD3DResource Information */
643 const IWineD3DVertexBufferVtbl *lpVtbl;
644 IWineD3DResourceClass resource;
646 /* WineD3DVertexBuffer specifics */
647 DWORD fvf;
649 /* Vertex buffer object support */
650 GLuint vbo;
651 BYTE Flags;
652 UINT stream;
654 UINT dirtystart, dirtyend;
655 LONG lockcount;
657 /* Last description of the buffer */
658 WineDirect3DVertexStridedData strided;
659 } IWineD3DVertexBufferImpl;
661 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
663 #define VBFLAG_LOAD 0x01 /* Data is written from allocatedMemory to the VBO */
664 #define VBFLAG_OPTIMIZED 0x02 /* Optimize has been called for the VB */
665 #define VBFLAG_DIRTY 0x04 /* Buffer data has been modified */
666 #define VBFLAG_STREAM 0x08 /* The vertex buffer is in a stream */
667 #define VBFLAG_HASDESC 0x10 /* A vertex description has been found */
668 #define VBFLAG_VBOCREATEFAIL 0x20 /* An attempt to create a vbo has failed */
670 /*****************************************************************************
671 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
673 typedef struct IWineD3DIndexBufferImpl
675 /* IUnknown & WineD3DResource Information */
676 const IWineD3DIndexBufferVtbl *lpVtbl;
677 IWineD3DResourceClass resource;
679 /* WineD3DVertexBuffer specifics */
680 } IWineD3DIndexBufferImpl;
682 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
684 /*****************************************************************************
685 * IWineD3DBaseTexture D3D- > openGL state map lookups
687 #define WINED3DFUNC_NOTSUPPORTED -2
688 #define WINED3DFUNC_UNIMPLEMENTED -1
690 typedef enum winetexturestates {
691 WINED3DTEXSTA_ADDRESSU = 0,
692 WINED3DTEXSTA_ADDRESSV = 1,
693 WINED3DTEXSTA_ADDRESSW = 2,
694 WINED3DTEXSTA_BORDERCOLOR = 3,
695 WINED3DTEXSTA_MAGFILTER = 4,
696 WINED3DTEXSTA_MINFILTER = 5,
697 WINED3DTEXSTA_MIPFILTER = 6,
698 WINED3DTEXSTA_MAXMIPLEVEL = 7,
699 WINED3DTEXSTA_MAXANISOTROPY = 8,
700 WINED3DTEXSTA_SRGBTEXTURE = 9,
701 WINED3DTEXSTA_ELEMENTINDEX = 10,
702 WINED3DTEXSTA_DMAPOFFSET = 11,
703 WINED3DTEXSTA_TSSADDRESSW = 12,
704 MAX_WINETEXTURESTATES = 13,
705 } winetexturestates;
707 typedef struct Wined3dTextureStateMap {
708 CONST int state;
709 int function;
710 } Wined3dTextureStateMap;
712 /*****************************************************************************
713 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
715 typedef struct IWineD3DBaseTextureClass
717 UINT levels;
718 BOOL dirty;
719 D3DFORMAT format;
720 DWORD usage;
721 UINT textureName;
722 UINT LOD;
723 WINED3DTEXTUREFILTERTYPE filterType;
724 DWORD states[MAX_WINETEXTURESTATES];
726 } IWineD3DBaseTextureClass;
728 typedef struct IWineD3DBaseTextureImpl
730 /* IUnknown & WineD3DResource Information */
731 const IWineD3DBaseTextureVtbl *lpVtbl;
732 IWineD3DResourceClass resource;
733 IWineD3DBaseTextureClass baseTexture;
735 } IWineD3DBaseTextureImpl;
737 /*****************************************************************************
738 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
740 typedef struct IWineD3DTextureImpl
742 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
743 const IWineD3DTextureVtbl *lpVtbl;
744 IWineD3DResourceClass resource;
745 IWineD3DBaseTextureClass baseTexture;
747 /* IWineD3DTexture */
748 IWineD3DSurface *surfaces[MAX_LEVELS];
750 UINT width;
751 UINT height;
752 float pow2scalingFactorX;
753 float pow2scalingFactorY;
755 } IWineD3DTextureImpl;
757 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
759 /*****************************************************************************
760 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
762 typedef struct IWineD3DCubeTextureImpl
764 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
765 const IWineD3DCubeTextureVtbl *lpVtbl;
766 IWineD3DResourceClass resource;
767 IWineD3DBaseTextureClass baseTexture;
769 /* IWineD3DCubeTexture */
770 IWineD3DSurface *surfaces[6][MAX_LEVELS];
772 UINT edgeLength;
773 float pow2scalingFactor;
775 } IWineD3DCubeTextureImpl;
777 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
779 typedef struct _WINED3DVOLUMET_DESC
781 UINT Width;
782 UINT Height;
783 UINT Depth;
784 } WINED3DVOLUMET_DESC;
786 /*****************************************************************************
787 * IWineD3DVolume implementation structure (extends IUnknown)
789 typedef struct IWineD3DVolumeImpl
791 /* IUnknown & WineD3DResource fields */
792 const IWineD3DVolumeVtbl *lpVtbl;
793 IWineD3DResourceClass resource;
795 /* WineD3DVolume Information */
796 WINED3DVOLUMET_DESC currentDesc;
797 IWineD3DBase *container;
798 UINT bytesPerPixel;
800 BOOL lockable;
801 BOOL locked;
802 WINED3DBOX lockedBox;
803 WINED3DBOX dirtyBox;
804 BOOL dirty;
807 } IWineD3DVolumeImpl;
809 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
811 /*****************************************************************************
812 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
814 typedef struct IWineD3DVolumeTextureImpl
816 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
817 const IWineD3DVolumeTextureVtbl *lpVtbl;
818 IWineD3DResourceClass resource;
819 IWineD3DBaseTextureClass baseTexture;
821 /* IWineD3DVolumeTexture */
822 IWineD3DVolume *volumes[MAX_LEVELS];
824 UINT width;
825 UINT height;
826 UINT depth;
827 } IWineD3DVolumeTextureImpl;
829 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
831 typedef struct _WINED3DSURFACET_DESC
833 WINED3DMULTISAMPLE_TYPE MultiSampleType;
834 DWORD MultiSampleQuality;
835 UINT Width;
836 UINT Height;
837 } WINED3DSURFACET_DESC;
839 /*****************************************************************************
840 * Structure for DIB Surfaces (GetDC and GDI surfaces)
842 typedef struct wineD3DSurface_DIB {
843 HBITMAP DIBsection;
844 void* bitmap_data;
845 HGDIOBJ holdbitmap;
846 BOOL client_memory;
847 } wineD3DSurface_DIB;
849 /*****************************************************************************
850 * IWineD3DSurface implementation structure
852 struct IWineD3DSurfaceImpl
854 /* IUnknown & IWineD3DResource Information */
855 const IWineD3DSurfaceVtbl *lpVtbl;
856 IWineD3DResourceClass resource;
858 /* IWineD3DSurface fields */
859 IWineD3DBase *container;
860 WINED3DSURFACET_DESC currentDesc;
861 IWineD3DPaletteImpl *palette;
863 UINT textureName;
864 UINT bytesPerPixel;
866 /* TODO: move this off into a management class(maybe!) */
867 DWORD Flags;
869 UINT pow2Width;
870 UINT pow2Height;
871 UINT pow2Size;
873 /* Oversized texture */
874 RECT glRect;
876 #if 0
877 /* precalculated x and y scalings for texture coords */
878 float pow2scalingFactorX; /* = (Width / pow2Width ) */
879 float pow2scalingFactorY; /* = (Height / pow2Height) */
880 #endif
882 RECT lockedRect;
883 RECT dirtyRect;
885 glDescriptor glDescription;
887 /* For GetDC */
888 wineD3DSurface_DIB dib;
889 HDC hDC;
891 /* Color keys for DDraw */
892 DDCOLORKEY DestBltCKey;
893 DDCOLORKEY DestOverlayCKey;
894 DDCOLORKEY SrcOverlayCKey;
895 DDCOLORKEY SrcBltCKey;
896 DWORD CKeyFlags;
898 DDCOLORKEY glCKey;
901 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
902 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
904 /* Predeclare the shared Surface functions */
905 HRESULT WINAPI IWineD3DSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
906 ULONG WINAPI IWineD3DSurfaceImpl_AddRef(IWineD3DSurface *iface);
907 ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface);
908 HRESULT WINAPI IWineD3DSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
909 HRESULT WINAPI IWineD3DSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
910 HRESULT WINAPI IWineD3DSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
911 HRESULT WINAPI IWineD3DSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
912 HRESULT WINAPI IWineD3DSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
913 DWORD WINAPI IWineD3DSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
914 DWORD WINAPI IWineD3DSurfaceImpl_GetPriority(IWineD3DSurface *iface);
915 void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface);
916 WINED3DRESOURCETYPE WINAPI IWineD3DSurfaceImpl_GetType(IWineD3DSurface *iface);
917 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainerParent(IWineD3DSurface* iface, IUnknown **ppContainerParent);
918 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
919 HRESULT WINAPI IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
920 HRESULT WINAPI IWineD3DSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
921 HRESULT WINAPI IWineD3DSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
922 HRESULT WINAPI IWineD3DSurfaceImpl_IsLost(IWineD3DSurface *iface);
923 HRESULT WINAPI IWineD3DSurfaceImpl_Restore(IWineD3DSurface *iface);
924 HRESULT WINAPI IWineD3DSurfaceImpl_SetPixelFormat(IWineD3DSurface *iface, WINED3DFORMAT Format, BYTE *Surface, DWORD Size);
925 HRESULT WINAPI IWineD3DSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
926 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
927 HRESULT WINAPI IWineD3DSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, DDCOLORKEY *CKey);
928 HRESULT WINAPI IWineD3DSurfaceImpl_CleanDirtyRect(IWineD3DSurface *iface);
929 extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect);
930 HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
931 HRESULT WINAPI IWineD3DSurfaceImpl_SetPBufferState(IWineD3DSurface *iface, BOOL inPBuffer, BOOL inTexture);
932 void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target);
933 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription);
934 const void *WINAPI IWineD3DSurfaceImpl_GetData(IWineD3DSurface *iface);
935 HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
936 HRESULT WINAPI IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx);
937 HRESULT WINAPI IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty, IWineD3DSurface *Source, RECT *rsrc, DWORD trans);
938 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
939 HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC);
940 HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC);
941 DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface);
942 HRESULT WINAPI IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
943 HRESULT WINAPI IWineD3DSurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem);
945 /* Surface flags: */
946 #define SFLAG_OVERSIZE 0x00000001 /* Surface is bigger than gl size, blts only */
947 #define SFLAG_CONVERTED 0x00000002 /* Converted for color keying or Palettized */
948 #define SFLAG_DIBSECTION 0x00000004 /* Has a DIB section attached for getdc */
949 #define SFLAG_DIRTY 0x00000008 /* Surface was locked by the app */
950 #define SFLAG_LOCKABLE 0x00000010 /* Surface can be locked */
951 #define SFLAG_DISCARD 0x00000020 /* ??? */
952 #define SFLAG_LOCKED 0x00000040 /* Surface is locked atm */
953 #define SFLAG_ACTIVELOCK 0x00000080 /* Not locked, but surface memory is needed */
954 #define SFLAG_INTEXTURE 0x00000100 /* ??? */
955 #define SFLAG_INPBUFFER 0x00000200 /* ??? */
956 #define SFLAG_NONPOW2 0x00000400 /* Surface sizes are not a power of 2 */
957 #define SFLAG_DYNLOCK 0x00000800 /* Surface is often locked by the app */
958 #define SFLAG_DYNCHANGE 0x00001800 /* Surface contents are changed very often, implies DYNLOCK */
959 #define SFLAG_DCINUSE 0x00002000 /* Set between GetDC and ReleaseDC calls */
960 #define SFLAG_GLDIRTY 0x00004000 /* The opengl texture is more up to date than the surface mem */
961 #define SFLAG_LOST 0x00008000 /* Surface lost flag for DDraw */
962 #define SFLAG_FORCELOAD 0x00010000 /* To force PreLoading of a scratch cursor */
963 #define SFLAG_USERPTR 0x00020000 /* The application allocated the memory for this surface */
964 #define SFLAG_GLCKEY 0x00040000 /* The gl texture was created with a color key */
966 /* In some conditions the surface memory must not be freed:
967 * SFLAG_OVERSIZE: Not all data can be kept in GL
968 * SFLAG_CONVERTED: Converting the data back would take too long
969 * SFLAG_DIBSECTION: The dib code manages the memory
970 * SFLAG_DIRTY: GL surface isn't up to date
971 * SFLAG_LOCKED: The app requires access to the surface data
972 * SFLAG_ACTIVELOCK: Some wined3d code needs the memory
973 * SFLAG_DYNLOCK: Avoid freeing the data for performance
974 * SFLAG_DYNCHANGE: Same reason as DYNLOCK
976 #define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
977 SFLAG_CONVERTED | \
978 SFLAG_DIBSECTION | \
979 SFLAG_DIRTY | \
980 SFLAG_LOCKED | \
981 SFLAG_ACTIVELOCK | \
982 SFLAG_DYNLOCK | \
983 SFLAG_DYNCHANGE | \
984 SFLAG_USERPTR)
986 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
988 /*****************************************************************************
989 * IWineD3DVertexDeclaration implementation structure
991 typedef struct IWineD3DVertexDeclarationImpl {
992 /* IUnknown Information */
993 const IWineD3DVertexDeclarationVtbl *lpVtbl;
994 LONG ref; /* Note: Ref counting not required */
996 IUnknown *parent;
997 /** precomputed fvf if simple declaration */
998 IWineD3DDeviceImpl *wineD3DDevice;
999 DWORD fvf[MAX_STREAMS];
1000 DWORD allFVF;
1002 /** dx8 compatible Declaration fields */
1003 DWORD* pDeclaration8;
1004 DWORD declaration8Length;
1006 /** dx9+ */
1007 D3DVERTEXELEMENT9 *pDeclaration9;
1008 UINT declaration9NumElements;
1010 WINED3DVERTEXELEMENT *pDeclarationWine;
1011 UINT declarationWNumElements;
1013 float *constants;
1015 } IWineD3DVertexDeclarationImpl;
1017 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
1019 /*****************************************************************************
1020 * IWineD3DStateBlock implementation structure
1023 /* Internal state Block for Begin/End/Capture/Create/Apply info */
1024 /* Note: Very long winded but gl Lists are not flexible enough */
1025 /* to resolve everything we need, so doing it manually for now */
1026 typedef struct SAVEDSTATES {
1027 BOOL indices;
1028 BOOL material;
1029 BOOL fvf;
1030 BOOL streamSource[MAX_STREAMS];
1031 BOOL streamFreq[MAX_STREAMS];
1032 BOOL textures[MAX_SAMPLERS];
1033 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
1034 BOOL viewport;
1035 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
1036 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1037 BOOL samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1038 BOOL clipplane[MAX_CLIPPLANES];
1039 BOOL vertexDecl;
1040 BOOL pixelShader;
1041 BOOL pixelShaderConstantsB[MAX_CONST_B];
1042 BOOL pixelShaderConstantsI[MAX_CONST_I];
1043 BOOL *pixelShaderConstantsF;
1044 BOOL vertexShader;
1045 BOOL vertexShaderConstantsB[MAX_CONST_B];
1046 BOOL vertexShaderConstantsI[MAX_CONST_I];
1047 BOOL *vertexShaderConstantsF;
1048 } SAVEDSTATES;
1050 typedef struct {
1051 struct list entry;
1052 int idx;
1053 } constant_entry;
1055 struct IWineD3DStateBlockImpl
1057 /* IUnknown fields */
1058 const IWineD3DStateBlockVtbl *lpVtbl;
1059 LONG ref; /* Note: Ref counting not required */
1061 /* IWineD3DStateBlock information */
1062 IUnknown *parent;
1063 IWineD3DDeviceImpl *wineD3DDevice;
1064 WINED3DSTATEBLOCKTYPE blockType;
1066 /* Array indicating whether things have been set or changed */
1067 SAVEDSTATES changed;
1068 SAVEDSTATES set;
1069 struct list set_vconstantsF;
1070 struct list set_pconstantsF;
1072 /* Drawing - Vertex Shader or FVF related */
1073 DWORD fvf;
1074 /* Vertex Shader Declaration */
1075 IWineD3DVertexDeclaration *vertexDecl;
1077 IWineD3DVertexShader *vertexShader;
1079 /* Vertex Shader Constants */
1080 BOOL vertexShaderConstantB[MAX_CONST_B];
1081 INT vertexShaderConstantI[MAX_CONST_I * 4];
1082 float *vertexShaderConstantF;
1084 /* Stream Source */
1085 BOOL streamIsUP;
1086 UINT streamStride[MAX_STREAMS];
1087 UINT streamOffset[MAX_STREAMS];
1088 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
1089 UINT streamFreq[MAX_STREAMS];
1090 UINT streamFlags[MAX_STREAMS]; /*0 | D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA */
1092 /* Indices */
1093 IWineD3DIndexBuffer* pIndexData;
1094 UINT baseVertexIndex; /* Note: only used for d3d8 */
1096 /* Transform */
1097 D3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
1099 /* Lights */
1100 PLIGHTINFOEL *lights; /* NOTE: active GL lights must be front of the chain */
1102 /* Clipping */
1103 double clipplane[MAX_CLIPPLANES][4];
1104 WINED3DCLIPSTATUS clip_status;
1106 /* ViewPort */
1107 WINED3DVIEWPORT viewport;
1109 /* Material */
1110 WINED3DMATERIAL material;
1112 /* Pixel Shader */
1113 IWineD3DPixelShader *pixelShader;
1115 /* Pixel Shader Constants */
1116 BOOL pixelShaderConstantB[MAX_CONST_B];
1117 INT pixelShaderConstantI[MAX_CONST_I * 4];
1118 float *pixelShaderConstantF;
1120 /* Indexed Vertex Blending */
1121 D3DVERTEXBLENDFLAGS vertex_blend;
1122 FLOAT tween_factor;
1124 /* RenderState */
1125 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
1127 /* Texture */
1128 IWineD3DBaseTexture *textures[MAX_SAMPLERS];
1129 int textureDimensions[MAX_SAMPLERS];
1131 /* Texture State Stage */
1132 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1133 /* Sampler States */
1134 DWORD samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1136 /* Current GLSL Shader Program */
1137 struct glsl_shader_prog_link *glsl_program;
1140 extern void stateblock_savedstates_set(
1141 IWineD3DStateBlock* iface,
1142 SAVEDSTATES* states,
1143 BOOL value);
1145 extern void stateblock_savedstates_copy(
1146 IWineD3DStateBlock* iface,
1147 SAVEDSTATES* dest,
1148 SAVEDSTATES* source);
1150 extern void stateblock_copy(
1151 IWineD3DStateBlock* destination,
1152 IWineD3DStateBlock* source);
1154 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1156 /*****************************************************************************
1157 * IWineD3DQueryImpl implementation structure (extends IUnknown)
1159 typedef struct IWineD3DQueryImpl
1161 const IWineD3DQueryVtbl *lpVtbl;
1162 LONG ref; /* Note: Ref counting not required */
1164 IUnknown *parent;
1165 /*TODO: replace with iface usage */
1166 #if 0
1167 IWineD3DDevice *wineD3DDevice;
1168 #else
1169 IWineD3DDeviceImpl *wineD3DDevice;
1170 #endif
1171 /* IWineD3DQuery fields */
1173 D3DQUERYTYPE type;
1174 /* TODO: Think about using a IUnknown instead of a void* */
1175 void *extendedData;
1178 } IWineD3DQueryImpl;
1180 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1182 /* Datastructures for IWineD3DQueryImpl.extendedData */
1183 typedef struct WineQueryOcclusionData {
1184 GLuint queryId;
1185 } WineQueryOcclusionData;
1188 /*****************************************************************************
1189 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1192 typedef struct IWineD3DSwapChainImpl
1194 /*IUnknown part*/
1195 IWineD3DSwapChainVtbl *lpVtbl;
1196 LONG ref; /* Note: Ref counting not required */
1198 IUnknown *parent;
1199 IWineD3DDeviceImpl *wineD3DDevice;
1201 /* IWineD3DSwapChain fields */
1202 IWineD3DSurface **backBuffer;
1203 IWineD3DSurface *frontBuffer;
1204 BOOL wantsDepthStencilBuffer;
1205 D3DPRESENT_PARAMETERS presentParms;
1207 /* TODO: move everything up to drawable off into a context manager
1208 and store the 'data' in the contextManagerData interface.
1209 IUnknown *contextManagerData;
1212 HWND win_handle;
1213 Window win;
1214 Display *display;
1216 GLXContext glCtx;
1217 XVisualInfo *visInfo;
1218 GLXContext render_ctx;
1219 /* This has been left in device for now, but needs moving off into a rendertarget management class and separated out from swapchains and devices. */
1220 Drawable drawable;
1221 } IWineD3DSwapChainImpl;
1223 extern IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1225 /*****************************************************************************
1226 * Utility function prototypes
1229 /* Trace routines */
1230 const char* debug_d3dformat(WINED3DFORMAT fmt);
1231 const char* debug_d3ddevicetype(D3DDEVTYPE devtype);
1232 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1233 const char* debug_d3dusage(DWORD usage);
1234 const char* debug_d3dusagequery(DWORD usagequery);
1235 const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method);
1236 const char* debug_d3ddecltype(WINED3DDECLTYPE type);
1237 const char* debug_d3ddeclusage(BYTE usage);
1238 const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
1239 const char* debug_d3drenderstate(DWORD state);
1240 const char* debug_d3dsamplerstate(DWORD state);
1241 const char* debug_d3dtexturestate(DWORD state);
1242 const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype);
1243 const char* debug_d3dpool(WINED3DPOOL pool);
1245 /* Routines for GL <-> D3D values */
1246 GLenum StencilOp(DWORD op);
1247 GLenum StencilFunc(DWORD func);
1248 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1249 void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, D3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx);
1250 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1252 int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1254 /* Math utils */
1255 void multiply_matrix(D3DMATRIX *dest, D3DMATRIX *src1, D3DMATRIX *src2);
1257 /*****************************************************************************
1258 * To enable calling of inherited functions, requires prototypes
1260 * Note: Only require classes which are subclassed, ie resource, basetexture,
1262 /*** IUnknown methods ***/
1263 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1264 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1265 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1266 /*** IWineD3DResource methods ***/
1267 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1268 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1269 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1270 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1271 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1272 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1273 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1274 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1275 extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1276 /*** class static members ***/
1277 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1279 /*** IUnknown methods ***/
1280 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1281 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1282 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1283 /*** IWineD3DResource methods ***/
1284 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1285 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1286 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1287 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1288 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1289 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1290 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1291 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1292 extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1293 /*** IWineD3DBaseTexture methods ***/
1294 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1295 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1296 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1297 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1298 extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1299 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1300 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1301 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1303 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset, GLint *vbo);
1304 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1305 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1306 extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1307 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1308 /*** class static members ***/
1309 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1311 struct SHADER_OPCODE_ARG;
1312 typedef void (*shader_fct_t)();
1313 typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
1315 /* Struct to maintain a list of GLSL shader programs and their associated pixel and
1316 * vertex shaders. A list of this type is maintained on the DeviceImpl, and is only
1317 * used if the user is using GLSL shaders. */
1318 struct glsl_shader_prog_link {
1319 struct list entry;
1320 GLhandleARB programId;
1321 GLhandleARB *vuniformF_locations;
1322 GLhandleARB *puniformF_locations;
1323 IWineD3DVertexShader* vertexShader;
1324 IWineD3DPixelShader* pixelShader;
1327 /* TODO: Make this dynamic, based on shader limits ? */
1328 #define MAX_REG_ADDR 1
1329 #define MAX_REG_TEMP 32
1330 #define MAX_REG_TEXCRD 8
1331 #define MAX_REG_INPUT 12
1332 #define MAX_REG_OUTPUT 12
1333 #define MAX_ATTRIBS 16
1334 #define MAX_CONST_I 16
1335 #define MAX_CONST_B 16
1337 /* FIXME: This needs to go up to 2048 for
1338 * Shader model 3 according to msdn (and for software shaders) */
1339 #define MAX_LABELS 16
1341 typedef struct semantic {
1342 DWORD usage;
1343 DWORD reg;
1344 } semantic;
1346 typedef struct local_constant {
1347 struct list entry;
1348 unsigned int idx;
1349 DWORD value[4];
1350 } local_constant;
1352 typedef struct shader_reg_maps {
1354 char texcoord[MAX_REG_TEXCRD]; /* pixel < 3.0 */
1355 char temporary[MAX_REG_TEMP]; /* pixel, vertex */
1356 char address[MAX_REG_ADDR]; /* vertex */
1357 char packed_input[MAX_REG_INPUT]; /* pshader >= 3.0 */
1358 char packed_output[MAX_REG_OUTPUT]; /* vertex >= 3.0 */
1359 char attributes[MAX_ATTRIBS]; /* vertex */
1360 char labels[MAX_LABELS]; /* pixel, vertex */
1362 /* Sampler usage tokens
1363 * Use 0 as default (bit 31 is always 1 on a valid token) */
1364 DWORD samplers[MAX_SAMPLERS];
1366 /* Whether or not a loop is used in this shader */
1367 char loop;
1369 /* Whether or not this shader uses fog */
1370 char fog;
1372 } shader_reg_maps;
1374 #define SHADER_PGMSIZE 65535
1375 typedef struct SHADER_BUFFER {
1376 char* buffer;
1377 unsigned int bsize;
1378 unsigned int lineNo;
1379 } SHADER_BUFFER;
1381 /* Undocumented opcode controls */
1382 #define INST_CONTROLS_SHIFT 16
1383 #define INST_CONTROLS_MASK 0x00ff0000
1385 typedef enum COMPARISON_TYPE {
1386 COMPARISON_GT = 1,
1387 COMPARISON_EQ = 2,
1388 COMPARISON_GE = 3,
1389 COMPARISON_LT = 4,
1390 COMPARISON_NE = 5,
1391 COMPARISON_LE = 6
1392 } COMPARISON_TYPE;
1394 typedef struct SHADER_OPCODE {
1395 unsigned int opcode;
1396 const char* name;
1397 const char* glname;
1398 char dst_token;
1399 CONST UINT num_params;
1400 shader_fct_t soft_fct;
1401 SHADER_HANDLER hw_fct;
1402 SHADER_HANDLER hw_glsl_fct;
1403 DWORD min_version;
1404 DWORD max_version;
1405 } SHADER_OPCODE;
1407 typedef struct SHADER_OPCODE_ARG {
1408 IWineD3DBaseShader* shader;
1409 shader_reg_maps* reg_maps;
1410 CONST SHADER_OPCODE* opcode;
1411 DWORD opcode_token;
1412 DWORD dst;
1413 DWORD dst_addr;
1414 DWORD predicate;
1415 DWORD src[4];
1416 DWORD src_addr[4];
1417 SHADER_BUFFER* buffer;
1418 } SHADER_OPCODE_ARG;
1420 typedef struct SHADER_LIMITS {
1421 unsigned int temporary;
1422 unsigned int texcoord;
1423 unsigned int sampler;
1424 unsigned int constant_int;
1425 unsigned int constant_float;
1426 unsigned int constant_bool;
1427 unsigned int address;
1428 unsigned int packed_output;
1429 unsigned int packed_input;
1430 unsigned int attributes;
1431 unsigned int label;
1432 } SHADER_LIMITS;
1434 /** Keeps track of details for TEX_M#x# shader opcodes which need to
1435 maintain state information between multiple codes */
1436 typedef struct SHADER_PARSE_STATE {
1437 unsigned int current_row;
1438 DWORD texcoord_w[2];
1439 } SHADER_PARSE_STATE;
1441 /* Base Shader utility functions.
1442 * (may move callers into the same file in the future) */
1443 extern int shader_addline(
1444 SHADER_BUFFER* buffer,
1445 const char* fmt, ...);
1447 extern const SHADER_OPCODE* shader_get_opcode(
1448 IWineD3DBaseShader *iface,
1449 const DWORD code);
1451 extern void shader_delete_constant_list(
1452 struct list* clist);
1454 /* Vertex shader utility functions */
1455 extern BOOL vshader_get_input(
1456 IWineD3DVertexShader* iface,
1457 BYTE usage_req, BYTE usage_idx_req,
1458 unsigned int* regnum);
1460 extern BOOL vshader_input_is_color(
1461 IWineD3DVertexShader* iface,
1462 unsigned int regnum);
1464 extern HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object);
1466 /* ARB_[vertex/fragment]_program helper functions */
1467 extern void shader_arb_load_constants(
1468 IWineD3DStateBlock* iface,
1469 char usePixelShader,
1470 char useVertexShader);
1472 /* ARB shader program Prototypes */
1473 extern void shader_hw_def(SHADER_OPCODE_ARG *arg);
1475 /* ARB pixel shader prototypes */
1476 extern void pshader_hw_cnd(SHADER_OPCODE_ARG* arg);
1477 extern void pshader_hw_cmp(SHADER_OPCODE_ARG* arg);
1478 extern void pshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1479 extern void pshader_hw_tex(SHADER_OPCODE_ARG* arg);
1480 extern void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg);
1481 extern void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg);
1482 extern void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg);
1483 extern void pshader_hw_texbem(SHADER_OPCODE_ARG* arg);
1484 extern void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG* arg);
1485 extern void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg);
1486 extern void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg);
1487 extern void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg);
1488 extern void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg);
1489 extern void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1491 /* ARB vertex shader prototypes */
1492 extern void vshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1493 extern void vshader_hw_mnxn(SHADER_OPCODE_ARG* arg);
1495 /* GLSL helper functions */
1496 extern void set_glsl_shader_program(IWineD3DDevice *iface);
1497 extern void shader_glsl_add_instruction_modifiers(SHADER_OPCODE_ARG *arg);
1498 extern void shader_glsl_load_constants(
1499 IWineD3DStateBlock* iface,
1500 char usePixelShader,
1501 char useVertexShader);
1503 /** The following translate DirectX pixel/vertex shader opcodes to GLSL lines */
1504 extern void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg);
1505 extern void shader_glsl_arith(SHADER_OPCODE_ARG* arg);
1506 extern void shader_glsl_mov(SHADER_OPCODE_ARG* arg);
1507 extern void shader_glsl_mad(SHADER_OPCODE_ARG* arg);
1508 extern void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg);
1509 extern void shader_glsl_lrp(SHADER_OPCODE_ARG* arg);
1510 extern void shader_glsl_dot(SHADER_OPCODE_ARG* arg);
1511 extern void shader_glsl_rcp(SHADER_OPCODE_ARG* arg);
1512 extern void shader_glsl_cnd(SHADER_OPCODE_ARG* arg);
1513 extern void shader_glsl_compare(SHADER_OPCODE_ARG* arg);
1514 extern void shader_glsl_def(SHADER_OPCODE_ARG* arg);
1515 extern void shader_glsl_defi(SHADER_OPCODE_ARG* arg);
1516 extern void shader_glsl_defb(SHADER_OPCODE_ARG* arg);
1517 extern void shader_glsl_expp(SHADER_OPCODE_ARG* arg);
1518 extern void shader_glsl_cmp(SHADER_OPCODE_ARG* arg);
1519 extern void shader_glsl_lit(SHADER_OPCODE_ARG* arg);
1520 extern void shader_glsl_dst(SHADER_OPCODE_ARG* arg);
1521 extern void shader_glsl_sincos(SHADER_OPCODE_ARG* arg);
1522 extern void shader_glsl_loop(SHADER_OPCODE_ARG* arg);
1523 extern void shader_glsl_end(SHADER_OPCODE_ARG* arg);
1524 extern void shader_glsl_if(SHADER_OPCODE_ARG* arg);
1525 extern void shader_glsl_ifc(SHADER_OPCODE_ARG* arg);
1526 extern void shader_glsl_else(SHADER_OPCODE_ARG* arg);
1527 extern void shader_glsl_break(SHADER_OPCODE_ARG* arg);
1528 extern void shader_glsl_breakc(SHADER_OPCODE_ARG* arg);
1529 extern void shader_glsl_rep(SHADER_OPCODE_ARG* arg);
1530 extern void shader_glsl_call(SHADER_OPCODE_ARG* arg);
1531 extern void shader_glsl_callnz(SHADER_OPCODE_ARG* arg);
1532 extern void shader_glsl_label(SHADER_OPCODE_ARG* arg);
1534 /** GLSL Pixel Shader Prototypes */
1535 extern void pshader_glsl_tex(SHADER_OPCODE_ARG* arg);
1536 extern void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg);
1537 extern void pshader_glsl_texdp3tex(SHADER_OPCODE_ARG* arg);
1538 extern void pshader_glsl_texdp3(SHADER_OPCODE_ARG* arg);
1539 extern void pshader_glsl_texdepth(SHADER_OPCODE_ARG* arg);
1540 extern void pshader_glsl_texm3x2depth(SHADER_OPCODE_ARG* arg);
1541 extern void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg);
1542 extern void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg);
1543 extern void pshader_glsl_texm3x3(SHADER_OPCODE_ARG* arg);
1544 extern void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg);
1545 extern void pshader_glsl_texm3x3tex(SHADER_OPCODE_ARG* arg);
1546 extern void pshader_glsl_texm3x3spec(SHADER_OPCODE_ARG* arg);
1547 extern void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1548 extern void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg);
1549 extern void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg);
1550 extern void pshader_glsl_texreg2ar(SHADER_OPCODE_ARG* arg);
1551 extern void pshader_glsl_texreg2gb(SHADER_OPCODE_ARG* arg);
1552 extern void pshader_glsl_texreg2rgb(SHADER_OPCODE_ARG* arg);
1553 extern void pshader_glsl_dp2add(SHADER_OPCODE_ARG* arg);
1554 extern void pshader_glsl_input_pack(
1555 SHADER_BUFFER* buffer,
1556 semantic* semantics_out);
1558 /** GLSL Vertex Shader Prototypes */
1559 extern void vshader_glsl_output_unpack(
1560 SHADER_BUFFER* buffer,
1561 semantic* semantics_out);
1563 /*****************************************************************************
1564 * IDirect3DBaseShader implementation structure
1566 typedef struct IWineD3DBaseShaderClass
1568 DWORD hex_version;
1569 SHADER_LIMITS limits;
1570 SHADER_PARSE_STATE parse_state;
1571 CONST SHADER_OPCODE *shader_ins;
1572 CONST DWORD *function;
1573 UINT functionLength;
1574 GLuint prgId;
1575 BOOL is_compiled;
1577 /* Type of shader backend */
1578 int shader_mode;
1580 /* Immediate constants (override global ones) */
1581 struct list constantsB;
1582 struct list constantsF;
1583 struct list constantsI;
1584 shader_reg_maps reg_maps;
1586 } IWineD3DBaseShaderClass;
1588 typedef struct IWineD3DBaseShaderImpl {
1589 /* IUnknown */
1590 const IWineD3DBaseShaderVtbl *lpVtbl;
1591 LONG ref;
1593 /* IWineD3DBaseShader */
1594 IWineD3DBaseShaderClass baseShader;
1595 } IWineD3DBaseShaderImpl;
1597 extern HRESULT shader_get_registers_used(
1598 IWineD3DBaseShader *iface,
1599 shader_reg_maps* reg_maps,
1600 semantic* semantics_in,
1601 semantic* semantics_out,
1602 CONST DWORD* pToken);
1604 extern void shader_generate_glsl_declarations(
1605 IWineD3DBaseShader *iface,
1606 shader_reg_maps* reg_maps,
1607 SHADER_BUFFER* buffer,
1608 WineD3D_GL_Info* gl_info);
1610 extern void shader_generate_arb_declarations(
1611 IWineD3DBaseShader *iface,
1612 shader_reg_maps* reg_maps,
1613 SHADER_BUFFER* buffer,
1614 WineD3D_GL_Info* gl_info);
1616 extern void shader_generate_main(
1617 IWineD3DBaseShader *iface,
1618 SHADER_BUFFER* buffer,
1619 shader_reg_maps* reg_maps,
1620 CONST DWORD* pFunction);
1622 extern void shader_dump_ins_modifiers(
1623 const DWORD output);
1625 extern void shader_dump_param(
1626 IWineD3DBaseShader *iface,
1627 const DWORD param,
1628 const DWORD addr_token,
1629 int input);
1631 extern void shader_trace_init(
1632 IWineD3DBaseShader *iface,
1633 const DWORD* pFunction);
1635 extern int shader_get_param(
1636 IWineD3DBaseShader* iface,
1637 const DWORD* pToken,
1638 DWORD* param,
1639 DWORD* addr_token);
1641 extern int shader_skip_unrecognized(
1642 IWineD3DBaseShader* iface,
1643 const DWORD* pToken);
1645 extern void print_glsl_info_log(
1646 WineD3D_GL_Info *gl_info,
1647 GLhandleARB obj);
1649 inline static int shader_get_regtype(const DWORD param) {
1650 return (((param & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) |
1651 ((param & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2));
1654 extern unsigned int shader_get_float_offset(const DWORD reg);
1656 inline static BOOL shader_is_pshader_version(DWORD token) {
1657 return 0xFFFF0000 == (token & 0xFFFF0000);
1660 inline static BOOL shader_is_vshader_version(DWORD token) {
1661 return 0xFFFE0000 == (token & 0xFFFF0000);
1664 inline static BOOL shader_is_comment(DWORD token) {
1665 return D3DSIO_COMMENT == (token & D3DSI_OPCODE_MASK);
1668 /*****************************************************************************
1669 * IDirect3DVertexShader implementation structure
1671 typedef struct IWineD3DVertexShaderImpl {
1672 /* IUnknown parts*/
1673 const IWineD3DVertexShaderVtbl *lpVtbl;
1674 LONG ref; /* Note: Ref counting not required */
1676 /* IWineD3DBaseShader */
1677 IWineD3DBaseShaderClass baseShader;
1679 /* IWineD3DVertexShaderImpl */
1680 IUnknown *parent;
1681 IWineD3DDeviceImpl *wineD3DDevice;
1683 char usesFog;
1684 DWORD usage;
1686 /* Vertex shader input and output semantics */
1687 semantic semantics_in [MAX_ATTRIBS];
1688 semantic semantics_out [MAX_REG_OUTPUT];
1690 /* run time datas... */
1691 VSHADERDATA *data;
1692 IWineD3DVertexDeclaration *vertexDeclaration;
1693 #if 0 /* needs reworking */
1694 /* run time datas */
1695 VSHADERINPUTDATA input;
1696 VSHADEROUTPUTDATA output;
1697 #endif
1698 } IWineD3DVertexShaderImpl;
1699 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1700 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1702 /*****************************************************************************
1703 * IDirect3DPixelShader implementation structure
1705 typedef struct IWineD3DPixelShaderImpl {
1706 /* IUnknown parts */
1707 const IWineD3DPixelShaderVtbl *lpVtbl;
1708 LONG ref; /* Note: Ref counting not required */
1710 /* IWineD3DBaseShader */
1711 IWineD3DBaseShaderClass baseShader;
1713 /* IWineD3DPixelShaderImpl */
1714 IUnknown *parent;
1715 IWineD3DDeviceImpl *wineD3DDevice;
1717 /* Pixel shader input semantics */
1718 semantic semantics_in [MAX_REG_INPUT];
1720 /* run time data */
1721 PSHADERDATA *data;
1723 #if 0 /* needs reworking */
1724 PSHADERINPUTDATA input;
1725 PSHADEROUTPUTDATA output;
1726 #endif
1727 } IWineD3DPixelShaderImpl;
1729 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1730 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1732 /*****************************************************************************
1733 * IWineD3DPalette implementation structure
1735 struct IWineD3DPaletteImpl {
1736 /* IUnknown parts */
1737 const IWineD3DPaletteVtbl *lpVtbl;
1738 LONG ref;
1740 IUnknown *parent;
1741 IWineD3DDeviceImpl *wineD3DDevice;
1743 /* IWineD3DPalette */
1744 HPALETTE hpal;
1745 WORD palVersion; /*| */
1746 WORD palNumEntries; /*| LOGPALETTE */
1747 PALETTEENTRY palents[256]; /*| */
1748 /* This is to store the palette in 'screen format' */
1749 int screen_palents[256];
1750 DWORD Flags;
1753 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
1754 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
1756 /* DirectDraw utility functions */
1757 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
1759 /*****************************************************************************
1760 * Pixel format management
1762 typedef struct {
1763 WINED3DFORMAT format;
1764 DWORD alphaMask, redMask, greenMask, blueMask;
1765 UINT bpp;
1766 BOOL isFourcc;
1767 GLint glInternal, glFormat, glType;
1768 } PixelFormatDesc;
1770 const PixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt);
1771 #endif