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
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
40 #include "wined3d_private_types.h"
42 #include "wine/wined3d_interface.h"
43 #include "wine/wined3d_caps.h"
44 #include "wine/wined3d_gl.h"
45 #include "wine/list.h"
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 WINED3DMAXUSERCLIPPLANES
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,
80 extern int minLookup[MAX_LOOKUPS];
81 extern int maxLookup[MAX_LOOKUPS];
82 extern DWORD *stateLookup[MAX_LOOKUPS];
84 extern DWORD minMipLookup[WINED3DTEXF_ANISOTROPIC + 1][WINED3DTEXF_LINEAR + 1];
86 typedef struct _WINED3DGLTYPE {
94 /* NOTE: Make sure these are in the correct numerical order. (see /include/wined3d_types.h) */
95 static WINED3DGLTYPE const glTypeLookup[WINED3DDECLTYPE_UNUSED] = {
96 {WINED3DDECLTYPE_FLOAT1, 1, GL_FLOAT , GL_FALSE ,sizeof(float)},
97 {WINED3DDECLTYPE_FLOAT2, 2, GL_FLOAT , GL_FALSE ,sizeof(float)},
98 {WINED3DDECLTYPE_FLOAT3, 3, GL_FLOAT , GL_FALSE ,sizeof(float)},
99 {WINED3DDECLTYPE_FLOAT4, 4, GL_FLOAT , GL_FALSE ,sizeof(float)},
100 {WINED3DDECLTYPE_D3DCOLOR, 4, GL_UNSIGNED_BYTE , GL_TRUE ,sizeof(BYTE)},
101 {WINED3DDECLTYPE_UBYTE4, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
102 {WINED3DDECLTYPE_SHORT2, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
103 {WINED3DDECLTYPE_SHORT4, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
104 {WINED3DDECLTYPE_UBYTE4N, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
105 {WINED3DDECLTYPE_SHORT2N, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
106 {WINED3DDECLTYPE_SHORT4N, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
107 {WINED3DDECLTYPE_USHORT2N, 2, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
108 {WINED3DDECLTYPE_USHORT4N, 4, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
109 {WINED3DDECLTYPE_UDEC3, 3, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
110 {WINED3DDECLTYPE_DEC3N, 3, GL_SHORT , GL_FALSE ,sizeof(short int)},
111 {WINED3DDECLTYPE_FLOAT16_2, 2, GL_FLOAT , GL_FALSE ,sizeof(short int)},
112 {WINED3DDECLTYPE_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
137 #define ORM_BACKBUFFER 0
138 #define ORM_PBUFFER 1
143 #define SHADER_GLSL 2
144 #define SHADER_NONE 3
146 #define RTL_DISABLE -1
148 #define RTL_READDRAW 1
149 #define RTL_READTEX 2
150 #define RTL_TEXDRAW 3
153 /* NOTE: When adding fields to this structure, make sure to update the default
154 * values in wined3d_main.c as well. */
155 typedef struct wined3d_settings_s {
156 /* vertex and pixel shader modes */
160 /* Ideally, we don't want the user to have to request GLSL. If the hardware supports GLSL,
161 we should use it. However, until it's fully implemented, we'll leave it as a registry
162 setting for developers. */
164 int offscreen_rendering_mode;
165 int rendertargetlock_mode;
166 /* Memory tracking and object counting */
167 unsigned int emulated_textureram;
168 } wined3d_settings_t;
170 extern wined3d_settings_t wined3d_settings;
172 /* Shader backends */
175 void (*shader_select)(IWineD3DDevice *iface, BOOL usePS, BOOL useVS);
176 void (*shader_select_depth_blt)(IWineD3DDevice *iface);
177 void (*shader_load_constants)(IWineD3DDevice *iface, char usePS, char useVS);
178 void (*shader_cleanup)(IWineD3DDevice *iface);
181 extern const shader_backend_t glsl_shader_backend;
182 extern const shader_backend_t arb_program_shader_backend;
183 extern const shader_backend_t none_shader_backend;
187 extern void (*wine_tsx11_lock_ptr)(void);
188 extern void (*wine_tsx11_unlock_ptr)(void);
190 /* As GLX relies on X, this is needed */
194 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
195 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
197 #define ENTER_GL() wine_tsx11_lock_ptr()
198 #define LEAVE_GL() wine_tsx11_unlock_ptr()
201 /*****************************************************************************
205 /* GL related defines */
206 /* ------------------ */
207 #define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
208 #define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
209 #define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
210 #define GL_VEND(_VendName) (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
212 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
213 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
214 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
215 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
217 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
218 #define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
219 #define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
220 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
222 #define D3DCOLORTOGLFLOAT4(dw, vec) \
223 (vec)[0] = D3DCOLOR_R(dw); \
224 (vec)[1] = D3DCOLOR_G(dw); \
225 (vec)[2] = D3DCOLOR_B(dw); \
226 (vec)[3] = D3DCOLOR_A(dw);
228 /* DirectX Device Limits */
229 /* --------------------- */
230 #define MAX_LEVELS 256 /* Maximum number of mipmap levels. Guessed at 256 */
232 #define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
233 See MaxStreams in MSDN under GetDeviceCaps */
234 /* Maximum number of constants provided to the shaders */
235 #define HIGHEST_TRANSFORMSTATE 512
236 /* Highest value in WINED3DTRANSFORMSTATETYPE */
237 #define MAX_PALETTES 256
239 /* Checking of API calls */
240 /* --------------------- */
241 #define checkGLcall(A) \
243 GLint err = glGetError(); \
244 if (err == GL_NO_ERROR) { \
245 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
248 FIXME(">>>>>>>>>>>>>>>>> %#x from %s @ %s / %d\n", \
249 err, A, __FILE__, __LINE__); \
250 err = glGetError(); \
251 } while (err != GL_NO_ERROR); \
254 /* Trace routines / diagnostics */
255 /* ---------------------------- */
257 /* Dump out a matrix and copy it */
258 #define conv_mat(mat,gl_mat) \
260 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
261 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
262 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
263 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
264 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
267 /* Macro to dump out the current state of the light chain */
268 #define DUMP_LIGHT_CHAIN() \
270 PLIGHTINFOEL *el = This->stateBlock->lights;\
272 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
277 /* Trace vector and strided data information */
278 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
279 #define TRACE_STRIDED(sd,name) TRACE( #name "=(data:%p, stride:%d, type:%d)\n", sd->u.s.name.lpData, sd->u.s.name.dwStride, sd->u.s.name.dwType);
281 /* Defines used for optimizations */
283 /* Only reapply what is necessary */
284 #define REAPPLY_ALPHAOP 0x0001
285 #define REAPPLY_ALL 0xFFFF
287 /* Advance declaration of structures to satisfy compiler */
288 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
289 typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
290 typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl;
291 typedef struct IWineD3DDeviceImpl IWineD3DDeviceImpl;
295 /* TODO: Move some of this to the device */
296 long globalChangeGlRam(long glram);
298 /* Memory and object tracking */
300 /*Structure for holding information on all direct3d objects
301 useful for making sure tracking is ok and when release is called on a device!
302 and probably quite handy for debugging and dumping states out
304 typedef struct WineD3DGlobalStatistics {
305 int glsurfaceram; /* The aproximate amount of glTexture memory allocated for textures */
306 } WineD3DGlobalStatistics;
308 extern WineD3DGlobalStatistics* wineD3DGlobalStatistics;
310 /* Global variables */
311 extern const float identity[16];
313 /*****************************************************************************
314 * Compilable extra diagnostics
317 /* Trace information per-vertex: (extremely high amount of trace) */
318 #if 0 /* NOTE: Must be 0 in cvs */
319 # define VTRACE(A) TRACE A
324 /* Checking of per-vertex related GL calls */
325 /* --------------------- */
326 #define vcheckGLcall(A) \
328 GLint err = glGetError(); \
329 if (err == GL_NO_ERROR) { \
330 VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
333 FIXME(">>>>>>>>>>>>>>>>> %#x from %s @ %s / %d\n", \
334 err, A, __FILE__, __LINE__); \
335 err = glGetError(); \
336 } while (err != GL_NO_ERROR); \
339 /* TODO: Confirm each of these works when wined3d move completed */
340 #if 0 /* NOTE: Must be 0 in cvs */
341 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
342 of each frame, a check is made for the existence of C:\D3DTRACE, and if it exists d3d trace
343 is enabled, and if it doesn't exist it is disabled. */
344 # define FRAME_DEBUGGING
345 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
346 the file is deleted */
347 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
348 # define SINGLE_FRAME_DEBUGGING
350 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
351 It can only be enabled when FRAME_DEBUGGING is also enabled
352 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
354 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
355 # define SHOW_FRAME_MAKEUP 1
357 /* The following, when enabled, lets you see the makeup of the all the textures used during each
358 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
359 The contents of the textures assigned to each stage are written into
360 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
361 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
362 # define SHOW_TEXTURE_MAKEUP 0
365 extern BOOL isDumpingFrames;
366 extern LONG primCounter;
369 /*****************************************************************************
373 /* Routine common to the draw primitive and draw indexed primitive routines */
374 void drawPrimitive(IWineD3DDevice *iface,
378 long StartVertexIndex,
379 UINT numberOfVertices,
385 void primitiveConvertToStridedData(IWineD3DDevice *iface, WineDirect3DVertexStridedData *strided, BOOL *fixup);
387 void primitiveDeclarationConvertToStridedData(
388 IWineD3DDevice *iface,
389 BOOL useVertexShaderFunction,
390 WineDirect3DVertexStridedData *strided,
393 void primitiveConvertFVFtoOffset(DWORD thisFVF,
396 WineDirect3DVertexStridedData *strided,
400 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
404 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
405 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
407 /* Routines and structures related to state management */
408 typedef struct WineD3DContext WineD3DContext;
409 typedef void (*APPLYSTATEFUNC)(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *ctx);
411 #define STATE_RENDER(a) (a)
412 #define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
414 #define STATE_TEXTURESTAGE(stage, num) (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + (stage) * WINED3D_HIGHEST_TEXTURE_STATE + (num))
415 #define STATE_IS_TEXTURESTAGE(a) ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
417 /* + 1 because samplers start with 0 */
418 #define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
419 #define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(MAX_SAMPLERS - 1))
421 #define STATE_PIXELSHADER (STATE_SAMPLER(MAX_SAMPLERS - 1) + 1)
422 #define STATE_IS_PIXELSHADER(a) ((a) == STATE_PIXELSHADER)
424 #define STATE_TRANSFORM(a) (STATE_PIXELSHADER + (a))
425 #define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)))
427 #define STATE_STREAMSRC (STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)) + 1)
428 #define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
429 #define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
430 #define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
432 #define STATE_VDECL (STATE_INDEXBUFFER + 1)
433 #define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
435 #define STATE_VSHADER (STATE_VDECL + 1)
436 #define STATE_IS_VSHADER(a) ((a) == STATE_VSHADER)
438 #define STATE_VIEWPORT (STATE_VSHADER + 1)
439 #define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
441 #define STATE_VERTEXSHADERCONSTANT (STATE_VIEWPORT + 1)
442 #define STATE_PIXELSHADERCONSTANT (STATE_VERTEXSHADERCONSTANT + 1)
443 #define STATE_IS_VERTEXSHADERCONSTANT(a) ((a) == STATE_VERTEXSHADERCONSTANT)
444 #define STATE_IS_PIXELSHADERCONSTANT(a) ((a) == STATE_PIXELSHADERCONSTANT)
446 #define STATE_ACTIVELIGHT(a) (STATE_PIXELSHADERCONSTANT + (a) + 1)
447 #define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_PIXELSHADERCONSTANT(MAX_ACTIVE_LIGHTS))
449 #define STATE_SCISSORRECT (STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS - 1) + 1)
450 #define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
452 #define STATE_HIGHEST (STATE_SCISSORRECT)
456 DWORD representative;
457 APPLYSTATEFUNC apply;
460 /* Global state table */
461 extern const struct StateEntry StateTable[];
463 /* The new context manager that should deal with onscreen and offscreen rendering */
464 struct WineD3DContext {
465 /* State dirtification
466 * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices
467 * 0...numDirtyEntries - 1. isStateDirty is a redundant copy of the dirtyArray. Technically only one of them would be needed,
468 * but with the help of both it is easy to find out if a state is dirty(just check the array index), and for applying dirty states
469 * only numDirtyEntries array elements have to be checked, not STATE_HIGHEST states.
471 DWORD dirtyArray[STATE_HIGHEST + 1]; /* Won't get bigger than that, a state is never marked dirty 2 times */
472 DWORD numDirtyEntries;
473 DWORD isStateDirty[STATE_HIGHEST/32 + 1]; /* Bitmap to find out quickly if a state is dirty */
475 IWineD3DSurface *surface;
476 /* TODO: Thread this ctx belongs to */
478 /* Stores some inforation about the context state for optimization */
479 BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
480 BOOL last_was_pshader;
481 BOOL last_was_vshader;
482 BOOL last_was_foggy_shader;
483 BOOL namedArraysLoaded, numberedArraysLoaded;
484 BOOL lastWasPow2Texture[MAX_TEXTURES];
485 GLenum tracking_parm; /* Which source is tracking current colour */
486 BOOL last_was_blit, last_was_ckey;
488 /* The actual opengl context */
495 typedef enum ContextUsage {
496 CTXUSAGE_RESOURCELOAD = 1, /* Only loads textures: No State is applied */
497 CTXUSAGE_DRAWPRIM = 2, /* OpenGL states are set up for blitting DirectDraw surfacs */
498 CTXUSAGE_BLIT = 3, /* OpenGL states are set up 3D drawing */
501 void ActivateContext(IWineD3DDeviceImpl *device, IWineD3DSurface *target, ContextUsage usage);
502 WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, Display *display, Window win);
503 void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context);
504 void set_render_target_fbo(IWineD3DDevice *iface, DWORD idx, IWineD3DSurface *render_target);
506 /* Routine to fill gl caps for swapchains and IWineD3D */
507 BOOL IWineD3DImpl_FillGLCaps(IWineD3D *iface, Display* display);
509 /* Macros for doing basic GPU detection based on opengl capabilities */
510 #define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
511 #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])
512 #define WINE_D3D8_CAPABLE(gl_info) WINE_D3D7_CAPABLE(gl_info) && (gl_info->supported[ARB_MULTISAMPLE] && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
513 #define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER])
515 /* Default callbacks for implicit object destruction */
516 extern ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface);
518 extern ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pSurface);
520 /*****************************************************************************
521 * Internal representation of a light
523 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
524 struct PLIGHTINFOEL {
525 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
531 /* Converted parms to speed up swapping lights */
540 /* The default light parameters */
541 extern const WINED3DLIGHT WINED3D_default_light;
543 /*****************************************************************************
544 * IWineD3D implementation structure
546 typedef struct IWineD3DImpl
548 /* IUnknown fields */
549 const IWineD3DVtbl *lpVtbl;
550 LONG ref; /* Note: Ref counting not required */
552 /* WineD3D Information */
558 WineD3D_GL_Info gl_info;
561 extern const IWineD3DVtbl IWineD3D_Vtbl;
563 /* TODO: setup some flags in the registry to enable, disable pbuffer support
564 (since it will break quite a few things until contexts are managed properly!) */
565 extern BOOL pbuffer_support;
566 /* allocate one pbuffer per surface */
567 extern BOOL pbuffer_per_surface;
569 typedef struct ResourceList {
570 IWineD3DResource *resource;
571 struct ResourceList *next;
574 /* A helper function that dumps a resource list */
575 void dumpResources(ResourceList *resources);
577 /*****************************************************************************
578 * IWineD3DDevice implementation structure
580 struct IWineD3DDeviceImpl
582 /* IUnknown fields */
583 const IWineD3DDeviceVtbl *lpVtbl;
584 LONG ref; /* Note: Ref counting not required */
586 /* WineD3D Information */
590 /* Window styles to restore when switching fullscreen mode */
594 /* X and GL Information */
595 GLint maxConcurrentLights;
597 /* Selected capabilities */
598 int vs_selected_mode;
599 int ps_selected_mode;
600 const shader_backend_t *shader_backend;
603 BOOL view_ident; /* true iff view matrix is identity */
606 /* State block related */
607 BOOL isRecordingState;
608 IWineD3DStateBlockImpl *stateBlock;
609 IWineD3DStateBlockImpl *updateStateBlock;
612 /* Internal use fields */
613 WINED3DDEVICE_CREATION_PARAMETERS createParms;
615 WINED3DDEVTYPE devType;
617 IWineD3DSwapChain **swapchains;
618 uint NumberOfSwapChains;
620 ResourceList *resources; /* a linked list to track resources created by the device */
622 /* Render Target Support */
623 IWineD3DSurface **render_targets;
624 IWineD3DSurface *depthStencilBuffer;
626 IWineD3DSurface *stencilBufferTarget;
628 /* Caches to avoid unneeded context changes */
629 IWineD3DSurface *lastActiveRenderTarget;
630 IWineD3DSwapChain *lastActiveSwapChain;
632 /* palettes texture management */
633 PALETTEENTRY palettes[MAX_PALETTES][256];
636 /* For rendering to a texture using glCopyTexImage */
637 BOOL render_offscreen;
638 WINED3D_DEPTHCOPYSTATE depth_copy_state;
640 GLenum *draw_buffers;
642 /* Cursor management */
648 UINT cursorWidth, cursorHeight;
649 GLuint cursorTexture;
651 /* Textures for when no other textures are mapped */
652 UINT dummyTextureName[MAX_TEXTURES];
654 /* Debug stream management */
657 /* Device state management */
659 BOOL d3d_initialized;
661 /* A flag to check for proper BeginScene / EndScene call pairs */
664 /* process vertex shaders using software or hardware */
665 BOOL softwareVertexProcessing;
667 /* DirectDraw stuff */
669 IWineD3DSurface *ddraw_primary;
670 DWORD ddraw_width, ddraw_height;
671 WINED3DFORMAT ddraw_format;
672 BOOL ddraw_fullscreen;
674 /* List of GLSL shader programs and their associated vertex & pixel shaders */
675 struct list glsl_shader_progs;
678 /* Final position fixup constant */
681 /* With register combiners we can skip junk texture stages */
682 DWORD texUnitMap[MAX_SAMPLERS];
683 BOOL oneToOneTexUnitMap;
685 /* Stream source management */
686 WineDirect3DVertexStridedData strided_streams;
687 WineDirect3DVertexStridedData *up_strided;
688 BOOL useDrawStridedSlow;
691 /* Context management */
692 WineD3DContext **contexts; /* Dynamic array containing pointers to context structures */
693 WineD3DContext *activeContext; /* Only 0 for now */
694 UINT numContexts; /* Always 1 for now */
695 WineD3DContext *pbufferContext; /* The context that has a pbuffer as drawable */
696 DWORD pbufferWidth, pbufferHeight; /* Size of the buffer drawable */
699 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
701 void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state);
702 static inline BOOL isStateDirty(WineD3DContext *context, DWORD state) {
703 DWORD idx = state >> 5;
704 BYTE shift = state & 0x1f;
705 return context->isStateDirty[idx] & (1 << shift);
708 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. I don't think
709 * anybody uses it for much so a good implementation is optional. */
710 typedef struct PrivateData
712 struct PrivateData* next;
715 DWORD flags; /* DDSPD_* */
716 DWORD uniqueness_value;
727 /*****************************************************************************
728 * IWineD3DResource implementation structure
730 typedef struct IWineD3DResourceClass
732 /* IUnknown fields */
733 LONG ref; /* Note: Ref counting not required */
735 /* WineD3DResource Information */
737 WINED3DRESOURCETYPE resourceType;
738 IWineD3DDeviceImpl *wineD3DDevice;
742 WINED3DFORMAT format;
743 BYTE *allocatedMemory;
744 PrivateData *privateData;
746 } IWineD3DResourceClass;
748 typedef struct IWineD3DResourceImpl
750 /* IUnknown & WineD3DResource Information */
751 const IWineD3DResourceVtbl *lpVtbl;
752 IWineD3DResourceClass resource;
753 } IWineD3DResourceImpl;
756 /*****************************************************************************
757 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
759 typedef struct IWineD3DVertexBufferImpl
761 /* IUnknown & WineD3DResource Information */
762 const IWineD3DVertexBufferVtbl *lpVtbl;
763 IWineD3DResourceClass resource;
765 /* WineD3DVertexBuffer specifics */
768 /* Vertex buffer object support */
773 UINT dirtystart, dirtyend;
776 LONG declChanges, draws;
777 /* Last description of the buffer */
778 WineDirect3DVertexStridedData strided;
779 } IWineD3DVertexBufferImpl;
781 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
783 #define VBFLAG_LOAD 0x01 /* Data is written from allocatedMemory to the VBO */
784 #define VBFLAG_OPTIMIZED 0x02 /* Optimize has been called for the VB */
785 #define VBFLAG_DIRTY 0x04 /* Buffer data has been modified */
786 #define VBFLAG_HASDESC 0x08 /* A vertex description has been found */
787 #define VBFLAG_VBOCREATEFAIL 0x10 /* An attempt to create a vbo has failed */
789 /*****************************************************************************
790 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
792 typedef struct IWineD3DIndexBufferImpl
794 /* IUnknown & WineD3DResource Information */
795 const IWineD3DIndexBufferVtbl *lpVtbl;
796 IWineD3DResourceClass resource;
799 UINT dirtystart, dirtyend;
802 /* WineD3DVertexBuffer specifics */
803 } IWineD3DIndexBufferImpl;
805 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
807 /*****************************************************************************
808 * IWineD3DBaseTexture D3D- > openGL state map lookups
810 #define WINED3DFUNC_NOTSUPPORTED -2
811 #define WINED3DFUNC_UNIMPLEMENTED -1
813 typedef enum winetexturestates {
814 WINED3DTEXSTA_ADDRESSU = 0,
815 WINED3DTEXSTA_ADDRESSV = 1,
816 WINED3DTEXSTA_ADDRESSW = 2,
817 WINED3DTEXSTA_BORDERCOLOR = 3,
818 WINED3DTEXSTA_MAGFILTER = 4,
819 WINED3DTEXSTA_MINFILTER = 5,
820 WINED3DTEXSTA_MIPFILTER = 6,
821 WINED3DTEXSTA_MAXMIPLEVEL = 7,
822 WINED3DTEXSTA_MAXANISOTROPY = 8,
823 WINED3DTEXSTA_SRGBTEXTURE = 9,
824 WINED3DTEXSTA_ELEMENTINDEX = 10,
825 WINED3DTEXSTA_DMAPOFFSET = 11,
826 WINED3DTEXSTA_TSSADDRESSW = 12,
827 MAX_WINETEXTURESTATES = 13,
830 typedef struct Wined3dTextureStateMap {
833 } Wined3dTextureStateMap;
835 /*****************************************************************************
836 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
838 typedef struct IWineD3DBaseTextureClass
842 WINED3DFORMAT format;
846 WINED3DTEXTUREFILTERTYPE filterType;
847 DWORD states[MAX_WINETEXTURESTATES];
850 } IWineD3DBaseTextureClass;
852 typedef struct IWineD3DBaseTextureImpl
854 /* IUnknown & WineD3DResource Information */
855 const IWineD3DBaseTextureVtbl *lpVtbl;
856 IWineD3DResourceClass resource;
857 IWineD3DBaseTextureClass baseTexture;
859 } IWineD3DBaseTextureImpl;
861 /*****************************************************************************
862 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
864 typedef struct IWineD3DTextureImpl
866 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
867 const IWineD3DTextureVtbl *lpVtbl;
868 IWineD3DResourceClass resource;
869 IWineD3DBaseTextureClass baseTexture;
871 /* IWineD3DTexture */
872 IWineD3DSurface *surfaces[MAX_LEVELS];
876 float pow2scalingFactorX;
877 float pow2scalingFactorY;
879 } IWineD3DTextureImpl;
881 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
883 /*****************************************************************************
884 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
886 typedef struct IWineD3DCubeTextureImpl
888 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
889 const IWineD3DCubeTextureVtbl *lpVtbl;
890 IWineD3DResourceClass resource;
891 IWineD3DBaseTextureClass baseTexture;
893 /* IWineD3DCubeTexture */
894 IWineD3DSurface *surfaces[6][MAX_LEVELS];
897 float pow2scalingFactor;
899 } IWineD3DCubeTextureImpl;
901 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
903 typedef struct _WINED3DVOLUMET_DESC
908 } WINED3DVOLUMET_DESC;
910 /*****************************************************************************
911 * IWineD3DVolume implementation structure (extends IUnknown)
913 typedef struct IWineD3DVolumeImpl
915 /* IUnknown & WineD3DResource fields */
916 const IWineD3DVolumeVtbl *lpVtbl;
917 IWineD3DResourceClass resource;
919 /* WineD3DVolume Information */
920 WINED3DVOLUMET_DESC currentDesc;
921 IWineD3DBase *container;
926 WINED3DBOX lockedBox;
931 } IWineD3DVolumeImpl;
933 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
935 /*****************************************************************************
936 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
938 typedef struct IWineD3DVolumeTextureImpl
940 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
941 const IWineD3DVolumeTextureVtbl *lpVtbl;
942 IWineD3DResourceClass resource;
943 IWineD3DBaseTextureClass baseTexture;
945 /* IWineD3DVolumeTexture */
946 IWineD3DVolume *volumes[MAX_LEVELS];
951 } IWineD3DVolumeTextureImpl;
953 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
955 typedef struct _WINED3DSURFACET_DESC
957 WINED3DMULTISAMPLE_TYPE MultiSampleType;
958 DWORD MultiSampleQuality;
961 } WINED3DSURFACET_DESC;
963 /*****************************************************************************
964 * Structure for DIB Surfaces (GetDC and GDI surfaces)
966 typedef struct wineD3DSurface_DIB {
971 } wineD3DSurface_DIB;
973 /*****************************************************************************
974 * IWineD3DSurface implementation structure
976 struct IWineD3DSurfaceImpl
978 /* IUnknown & IWineD3DResource Information */
979 const IWineD3DSurfaceVtbl *lpVtbl;
980 IWineD3DResourceClass resource;
982 /* IWineD3DSurface fields */
983 IWineD3DBase *container;
984 WINED3DSURFACET_DESC currentDesc;
985 IWineD3DPaletteImpl *palette; /* D3D7 style palette handling */
986 PALETTEENTRY *palette9; /* D3D8/9 style palette handling */
990 /* TODO: move this off into a management class(maybe!) */
997 /* Oversized texture */
1001 /* precalculated x and y scalings for texture coords */
1002 float pow2scalingFactorX; /* = (Width / pow2Width ) */
1003 float pow2scalingFactorY; /* = (Height / pow2Height) */
1009 #define MAXLOCKCOUNT 50 /* After this amount of locks do not free the sysmem copy */
1011 glDescriptor glDescription;
1014 wineD3DSurface_DIB dib;
1017 /* Color keys for DDraw */
1018 DDCOLORKEY DestBltCKey;
1019 DDCOLORKEY DestOverlayCKey;
1020 DDCOLORKEY SrcOverlayCKey;
1021 DDCOLORKEY SrcBltCKey;
1027 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
1028 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
1030 /* Predeclare the shared Surface functions */
1031 HRESULT WINAPI IWineD3DSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
1032 ULONG WINAPI IWineD3DSurfaceImpl_AddRef(IWineD3DSurface *iface);
1033 ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface);
1034 HRESULT WINAPI IWineD3DSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
1035 HRESULT WINAPI IWineD3DSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
1036 HRESULT WINAPI IWineD3DSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
1037 HRESULT WINAPI IWineD3DSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
1038 HRESULT WINAPI IWineD3DSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
1039 DWORD WINAPI IWineD3DSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
1040 DWORD WINAPI IWineD3DSurfaceImpl_GetPriority(IWineD3DSurface *iface);
1041 void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface);
1042 WINED3DRESOURCETYPE WINAPI IWineD3DSurfaceImpl_GetType(IWineD3DSurface *iface);
1043 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
1044 HRESULT WINAPI IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
1045 HRESULT WINAPI IWineD3DSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
1046 HRESULT WINAPI IWineD3DSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
1047 HRESULT WINAPI IWineD3DSurfaceImpl_IsLost(IWineD3DSurface *iface);
1048 HRESULT WINAPI IWineD3DSurfaceImpl_Restore(IWineD3DSurface *iface);
1049 HRESULT WINAPI IWineD3DSurfaceImpl_SetPixelFormat(IWineD3DSurface *iface, WINED3DFORMAT Format, BYTE *Surface, DWORD Size);
1050 HRESULT WINAPI IWineD3DSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
1051 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
1052 HRESULT WINAPI IWineD3DSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, DDCOLORKEY *CKey);
1053 HRESULT WINAPI IWineD3DSurfaceImpl_CleanDirtyRect(IWineD3DSurface *iface);
1054 extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect);
1055 HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
1056 HRESULT WINAPI IWineD3DSurfaceImpl_SetPBufferState(IWineD3DSurface *iface, BOOL inPBuffer, BOOL inTexture);
1057 void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target);
1058 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription);
1059 const void *WINAPI IWineD3DSurfaceImpl_GetData(IWineD3DSurface *iface);
1060 HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
1061 HRESULT WINAPI IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, DDBLTFX *DDBltFx);
1062 HRESULT WINAPI IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty, IWineD3DSurface *Source, RECT *rsrc, DWORD trans);
1063 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
1064 HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC);
1065 HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC);
1066 DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface);
1067 HRESULT WINAPI IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
1068 HRESULT WINAPI IWineD3DSurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem);
1069 HRESULT WINAPI IWineD3DSurfaceImpl_SetOverlayPosition(IWineD3DSurface *iface, LONG X, LONG Y);
1070 HRESULT WINAPI IWineD3DSurfaceImpl_GetOverlayPosition(IWineD3DSurface *iface, LONG *X, LONG *Y);
1071 HRESULT WINAPI IWineD3DSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface *iface, DWORD Flags, IWineD3DSurface *Ref);
1072 HRESULT WINAPI IWineD3DSurfaceImpl_UpdateOverlay(IWineD3DSurface *iface, RECT *SrcRect, IWineD3DSurface *DstSurface, RECT *DstRect, DWORD Flags, WINEDDOVERLAYFX *FX);
1074 /* Surface flags: */
1075 #define SFLAG_OVERSIZE 0x00000001 /* Surface is bigger than gl size, blts only */
1076 #define SFLAG_CONVERTED 0x00000002 /* Converted for color keying or Palettized */
1077 #define SFLAG_DIBSECTION 0x00000004 /* Has a DIB section attached for getdc */
1078 #define SFLAG_DIRTY 0x00000008 /* Surface was locked by the app */
1079 #define SFLAG_LOCKABLE 0x00000010 /* Surface can be locked */
1080 #define SFLAG_DISCARD 0x00000020 /* ??? */
1081 #define SFLAG_LOCKED 0x00000040 /* Surface is locked atm */
1082 #define SFLAG_INTEXTURE 0x00000080 /* ??? */
1083 #define SFLAG_INPBUFFER 0x00000100 /* ??? */
1084 #define SFLAG_NONPOW2 0x00000200 /* Surface sizes are not a power of 2 */
1085 #define SFLAG_DYNLOCK 0x00000400 /* Surface is often locked by the app */
1086 #define SFLAG_DYNCHANGE 0x00000C00 /* Surface contents are changed very often, implies DYNLOCK */
1087 #define SFLAG_DCINUSE 0x00001000 /* Set between GetDC and ReleaseDC calls */
1088 #define SFLAG_GLDIRTY 0x00002000 /* The opengl texture is more up to date than the surface mem */
1089 #define SFLAG_LOST 0x00004000 /* Surface lost flag for DDraw */
1090 #define SFLAG_FORCELOAD 0x00008000 /* To force PreLoading of a scratch cursor */
1091 #define SFLAG_USERPTR 0x00010000 /* The application allocated the memory for this surface */
1092 #define SFLAG_GLCKEY 0x00020000 /* The gl texture was created with a color key */
1094 /* In some conditions the surface memory must not be freed:
1095 * SFLAG_OVERSIZE: Not all data can be kept in GL
1096 * SFLAG_CONVERTED: Converting the data back would take too long
1097 * SFLAG_DIBSECTION: The dib code manages the memory
1098 * SFLAG_DIRTY: GL surface isn't up to date
1099 * SFLAG_LOCKED: The app requires access to the surface data
1100 * SFLAG_DYNLOCK: Avoid freeing the data for performance
1101 * SFLAG_DYNCHANGE: Same reason as DYNLOCK
1103 #define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
1105 SFLAG_DIBSECTION | \
1112 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
1114 /* Alignment of the pitch */
1115 #define SURFACE_ALIGNMENT 4
1117 /*****************************************************************************
1118 * IWineD3DVertexDeclaration implementation structure
1120 typedef struct IWineD3DVertexDeclarationImpl {
1121 /* IUnknown Information */
1122 const IWineD3DVertexDeclarationVtbl *lpVtbl;
1123 LONG ref; /* Note: Ref counting not required */
1126 /** precomputed fvf if simple declaration */
1127 IWineD3DDeviceImpl *wineD3DDevice;
1128 DWORD fvf[MAX_STREAMS];
1131 WINED3DVERTEXELEMENT *pDeclarationWine;
1132 UINT declarationWNumElements;
1133 } IWineD3DVertexDeclarationImpl;
1135 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
1137 /*****************************************************************************
1138 * IWineD3DStateBlock implementation structure
1141 /* Internal state Block for Begin/End/Capture/Create/Apply info */
1142 /* Note: Very long winded but gl Lists are not flexible enough */
1143 /* to resolve everything we need, so doing it manually for now */
1144 typedef struct SAVEDSTATES {
1148 BOOL streamSource[MAX_STREAMS];
1149 BOOL streamFreq[MAX_STREAMS];
1150 BOOL textures[MAX_SAMPLERS];
1151 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
1153 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
1154 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1155 BOOL samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1156 BOOL clipplane[MAX_CLIPPLANES];
1159 BOOL pixelShaderConstantsB[MAX_CONST_B];
1160 BOOL pixelShaderConstantsI[MAX_CONST_I];
1161 BOOL *pixelShaderConstantsF;
1163 BOOL vertexShaderConstantsB[MAX_CONST_B];
1164 BOOL vertexShaderConstantsI[MAX_CONST_I];
1165 BOOL *vertexShaderConstantsF;
1174 struct IWineD3DStateBlockImpl
1176 /* IUnknown fields */
1177 const IWineD3DStateBlockVtbl *lpVtbl;
1178 LONG ref; /* Note: Ref counting not required */
1180 /* IWineD3DStateBlock information */
1182 IWineD3DDeviceImpl *wineD3DDevice;
1183 WINED3DSTATEBLOCKTYPE blockType;
1185 /* Array indicating whether things have been set or changed */
1186 SAVEDSTATES changed;
1188 struct list set_vconstantsF;
1189 struct list set_pconstantsF;
1191 /* Drawing - Vertex Shader or FVF related */
1193 /* Vertex Shader Declaration */
1194 IWineD3DVertexDeclaration *vertexDecl;
1196 IWineD3DVertexShader *vertexShader;
1198 /* Vertex Shader Constants */
1199 BOOL vertexShaderConstantB[MAX_CONST_B];
1200 INT vertexShaderConstantI[MAX_CONST_I * 4];
1201 float *vertexShaderConstantF;
1205 UINT streamStride[MAX_STREAMS];
1206 UINT streamOffset[MAX_STREAMS];
1207 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
1208 UINT streamFreq[MAX_STREAMS];
1209 UINT streamFlags[MAX_STREAMS]; /*0 | WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA */
1212 IWineD3DIndexBuffer* pIndexData;
1213 UINT baseVertexIndex;
1214 UINT loadBaseVertexIndex; /* non-indexed drawing needs 0 here, indexed baseVertexIndex */
1217 WINED3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
1219 /* Light hashmap . Collisions are handled using standard wine double linked lists */
1220 #define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
1221 #define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
1222 struct list lightMap[LIGHTMAP_SIZE]; /* Mashmap containing the lights */
1223 PLIGHTINFOEL *activeLights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
1226 double clipplane[MAX_CLIPPLANES][4];
1227 WINED3DCLIPSTATUS clip_status;
1230 WINED3DVIEWPORT viewport;
1233 WINED3DMATERIAL material;
1236 IWineD3DPixelShader *pixelShader;
1238 /* Pixel Shader Constants */
1239 BOOL pixelShaderConstantB[MAX_CONST_B];
1240 INT pixelShaderConstantI[MAX_CONST_I * 4];
1241 float *pixelShaderConstantF;
1244 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
1247 IWineD3DBaseTexture *textures[MAX_SAMPLERS];
1248 int textureDimensions[MAX_SAMPLERS];
1250 /* Texture State Stage */
1251 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1252 DWORD lowest_disabled_stage;
1253 /* Sampler States */
1254 DWORD samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1256 /* Current GLSL Shader Program */
1257 struct glsl_shader_prog_link *glsl_program;
1259 /* Scissor test rectangle */
1263 extern void stateblock_savedstates_set(
1264 IWineD3DStateBlock* iface,
1265 SAVEDSTATES* states,
1268 extern void stateblock_savedstates_copy(
1269 IWineD3DStateBlock* iface,
1271 SAVEDSTATES* source);
1273 extern void stateblock_copy(
1274 IWineD3DStateBlock* destination,
1275 IWineD3DStateBlock* source);
1277 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1279 /*****************************************************************************
1280 * IWineD3DQueryImpl implementation structure (extends IUnknown)
1282 typedef struct IWineD3DQueryImpl
1284 const IWineD3DQueryVtbl *lpVtbl;
1285 LONG ref; /* Note: Ref counting not required */
1288 /*TODO: replace with iface usage */
1290 IWineD3DDevice *wineD3DDevice;
1292 IWineD3DDeviceImpl *wineD3DDevice;
1295 /* IWineD3DQuery fields */
1296 WINED3DQUERYTYPE type;
1297 /* TODO: Think about using a IUnknown instead of a void* */
1301 } IWineD3DQueryImpl;
1303 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1305 /* Datastructures for IWineD3DQueryImpl.extendedData */
1306 typedef struct WineQueryOcclusionData {
1308 } WineQueryOcclusionData;
1311 /*****************************************************************************
1312 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1315 typedef struct IWineD3DSwapChainImpl
1318 const IWineD3DSwapChainVtbl *lpVtbl;
1319 LONG ref; /* Note: Ref counting not required */
1322 IWineD3DDeviceImpl *wineD3DDevice;
1324 /* IWineD3DSwapChain fields */
1325 IWineD3DSurface **backBuffer;
1326 IWineD3DSurface *frontBuffer;
1327 BOOL wantsDepthStencilBuffer;
1328 WINED3DPRESENT_PARAMETERS presentParms;
1329 DWORD orig_width, orig_height;
1330 WINED3DFORMAT orig_fmt;
1332 long prev_time, frames; /* Performance tracking */
1334 WineD3DContext *context; /* Later a array for multithreading */
1338 } IWineD3DSwapChainImpl;
1340 extern const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1342 /*****************************************************************************
1343 * Utility function prototypes
1346 /* Trace routines */
1347 const char* debug_d3dformat(WINED3DFORMAT fmt);
1348 const char* debug_d3ddevicetype(WINED3DDEVTYPE devtype);
1349 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1350 const char* debug_d3dusage(DWORD usage);
1351 const char* debug_d3dusagequery(DWORD usagequery);
1352 const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method);
1353 const char* debug_d3ddecltype(WINED3DDECLTYPE type);
1354 const char* debug_d3ddeclusage(BYTE usage);
1355 const char* debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType);
1356 const char* debug_d3drenderstate(DWORD state);
1357 const char* debug_d3dsamplerstate(DWORD state);
1358 const char* debug_d3dtexturestate(DWORD state);
1359 const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype);
1360 const char* debug_d3dpool(WINED3DPOOL pool);
1362 /* Routines for GL <-> D3D values */
1363 GLenum StencilOp(DWORD op);
1364 GLenum CompareFunc(DWORD func);
1365 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1366 void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx);
1367 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1369 int D3DFmtMakeGlCfg(WINED3DFORMAT BackBufferFormat, WINED3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1372 void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2);
1374 /*****************************************************************************
1375 * To enable calling of inherited functions, requires prototypes
1377 * Note: Only require classes which are subclassed, ie resource, basetexture,
1379 /*** IUnknown methods ***/
1380 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1381 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1382 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1383 /*** IWineD3DResource methods ***/
1384 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1385 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1386 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1387 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1388 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1389 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1390 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1391 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1392 extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1393 /*** class static members ***/
1394 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1396 /*** IUnknown methods ***/
1397 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1398 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1399 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1400 /*** IWineD3DResource methods ***/
1401 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1402 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1403 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1404 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1405 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1406 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1407 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1408 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1409 extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1410 /*** IWineD3DBaseTexture methods ***/
1411 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1412 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1413 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1414 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1415 extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1416 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1417 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1418 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1420 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset, GLint *vbo);
1421 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1422 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1423 extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1424 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1425 /*** class static members ***/
1426 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1428 struct SHADER_OPCODE_ARG;
1429 typedef void (*shader_fct_t)();
1430 typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
1432 /* Struct to maintain a list of GLSL shader programs and their associated pixel and
1433 * vertex shaders. A list of this type is maintained on the DeviceImpl, and is only
1434 * used if the user is using GLSL shaders. */
1435 struct glsl_shader_prog_link {
1437 GLhandleARB programId;
1438 GLhandleARB *vuniformF_locations;
1439 GLhandleARB *puniformF_locations;
1440 IWineD3DVertexShader* vertexShader;
1441 IWineD3DPixelShader* pixelShader;
1444 /* TODO: Make this dynamic, based on shader limits ? */
1445 #define MAX_REG_ADDR 1
1446 #define MAX_REG_TEMP 32
1447 #define MAX_REG_TEXCRD 8
1448 #define MAX_REG_INPUT 12
1449 #define MAX_REG_OUTPUT 12
1450 #define MAX_ATTRIBS 16
1451 #define MAX_CONST_I 16
1452 #define MAX_CONST_B 16
1454 /* FIXME: This needs to go up to 2048 for
1455 * Shader model 3 according to msdn (and for software shaders) */
1456 #define MAX_LABELS 16
1458 typedef struct semantic {
1463 typedef struct local_constant {
1469 typedef struct shader_reg_maps {
1471 char texcoord[MAX_REG_TEXCRD]; /* pixel < 3.0 */
1472 char temporary[MAX_REG_TEMP]; /* pixel, vertex */
1473 char address[MAX_REG_ADDR]; /* vertex */
1474 char packed_input[MAX_REG_INPUT]; /* pshader >= 3.0 */
1475 char packed_output[MAX_REG_OUTPUT]; /* vertex >= 3.0 */
1476 char attributes[MAX_ATTRIBS]; /* vertex */
1477 char labels[MAX_LABELS]; /* pixel, vertex */
1479 /* Sampler usage tokens
1480 * Use 0 as default (bit 31 is always 1 on a valid token) */
1481 DWORD samplers[MAX_SAMPLERS];
1484 /* Whether or not a loop is used in this shader */
1487 /* Whether or not this shader uses fog */
1492 #define SHADER_PGMSIZE 65535
1493 typedef struct SHADER_BUFFER {
1496 unsigned int lineNo;
1500 /* Undocumented opcode controls */
1501 #define INST_CONTROLS_SHIFT 16
1502 #define INST_CONTROLS_MASK 0x00ff0000
1504 typedef enum COMPARISON_TYPE {
1513 typedef struct SHADER_OPCODE {
1514 unsigned int opcode;
1518 CONST UINT num_params;
1519 shader_fct_t soft_fct;
1520 SHADER_HANDLER hw_fct;
1521 SHADER_HANDLER hw_glsl_fct;
1526 typedef struct SHADER_OPCODE_ARG {
1527 IWineD3DBaseShader* shader;
1528 shader_reg_maps* reg_maps;
1529 CONST SHADER_OPCODE* opcode;
1536 SHADER_BUFFER* buffer;
1537 } SHADER_OPCODE_ARG;
1539 typedef struct SHADER_LIMITS {
1540 unsigned int temporary;
1541 unsigned int texcoord;
1542 unsigned int sampler;
1543 unsigned int constant_int;
1544 unsigned int constant_float;
1545 unsigned int constant_bool;
1546 unsigned int address;
1547 unsigned int packed_output;
1548 unsigned int packed_input;
1549 unsigned int attributes;
1553 /** Keeps track of details for TEX_M#x# shader opcodes which need to
1554 maintain state information between multiple codes */
1555 typedef struct SHADER_PARSE_STATE {
1556 unsigned int current_row;
1557 DWORD texcoord_w[2];
1558 } SHADER_PARSE_STATE;
1560 /* Base Shader utility functions.
1561 * (may move callers into the same file in the future) */
1562 extern int shader_addline(
1563 SHADER_BUFFER* buffer,
1564 const char* fmt, ...);
1566 extern const SHADER_OPCODE* shader_get_opcode(
1567 IWineD3DBaseShader *iface,
1570 extern void shader_delete_constant_list(
1571 struct list* clist);
1573 /* Vertex shader utility functions */
1574 extern BOOL vshader_get_input(
1575 IWineD3DVertexShader* iface,
1576 BYTE usage_req, BYTE usage_idx_req,
1577 unsigned int* regnum);
1579 extern BOOL vshader_input_is_color(
1580 IWineD3DVertexShader* iface,
1581 unsigned int regnum);
1583 extern HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object);
1585 /* ARB_[vertex/fragment]_program helper functions */
1586 extern void shader_arb_load_constants(
1587 IWineD3DDevice* device,
1588 char usePixelShader,
1589 char useVertexShader);
1591 /* ARB shader program Prototypes */
1592 extern void shader_hw_def(SHADER_OPCODE_ARG *arg);
1594 /* ARB pixel shader prototypes */
1595 extern void pshader_hw_cnd(SHADER_OPCODE_ARG* arg);
1596 extern void pshader_hw_cmp(SHADER_OPCODE_ARG* arg);
1597 extern void pshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1598 extern void pshader_hw_tex(SHADER_OPCODE_ARG* arg);
1599 extern void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg);
1600 extern void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg);
1601 extern void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg);
1602 extern void pshader_hw_texbem(SHADER_OPCODE_ARG* arg);
1603 extern void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG* arg);
1604 extern void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg);
1605 extern void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg);
1606 extern void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg);
1607 extern void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg);
1608 extern void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1610 /* ARB vertex shader prototypes */
1611 extern void vshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1612 extern void vshader_hw_mnxn(SHADER_OPCODE_ARG* arg);
1613 extern void vshader_hw_rsq_rcp(SHADER_OPCODE_ARG* arg);
1615 /* GLSL helper functions */
1616 extern void shader_glsl_add_instruction_modifiers(SHADER_OPCODE_ARG *arg);
1617 extern void shader_glsl_load_constants(
1618 IWineD3DDevice* device,
1619 char usePixelShader,
1620 char useVertexShader);
1622 /** The following translate DirectX pixel/vertex shader opcodes to GLSL lines */
1623 extern void shader_glsl_cross(SHADER_OPCODE_ARG* arg);
1624 extern void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg);
1625 extern void shader_glsl_arith(SHADER_OPCODE_ARG* arg);
1626 extern void shader_glsl_mov(SHADER_OPCODE_ARG* arg);
1627 extern void shader_glsl_mad(SHADER_OPCODE_ARG* arg);
1628 extern void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg);
1629 extern void shader_glsl_lrp(SHADER_OPCODE_ARG* arg);
1630 extern void shader_glsl_dot(SHADER_OPCODE_ARG* arg);
1631 extern void shader_glsl_rcp(SHADER_OPCODE_ARG* arg);
1632 extern void shader_glsl_cnd(SHADER_OPCODE_ARG* arg);
1633 extern void shader_glsl_compare(SHADER_OPCODE_ARG* arg);
1634 extern void shader_glsl_def(SHADER_OPCODE_ARG* arg);
1635 extern void shader_glsl_defi(SHADER_OPCODE_ARG* arg);
1636 extern void shader_glsl_defb(SHADER_OPCODE_ARG* arg);
1637 extern void shader_glsl_expp(SHADER_OPCODE_ARG* arg);
1638 extern void shader_glsl_cmp(SHADER_OPCODE_ARG* arg);
1639 extern void shader_glsl_lit(SHADER_OPCODE_ARG* arg);
1640 extern void shader_glsl_dst(SHADER_OPCODE_ARG* arg);
1641 extern void shader_glsl_sincos(SHADER_OPCODE_ARG* arg);
1642 extern void shader_glsl_loop(SHADER_OPCODE_ARG* arg);
1643 extern void shader_glsl_end(SHADER_OPCODE_ARG* arg);
1644 extern void shader_glsl_if(SHADER_OPCODE_ARG* arg);
1645 extern void shader_glsl_ifc(SHADER_OPCODE_ARG* arg);
1646 extern void shader_glsl_else(SHADER_OPCODE_ARG* arg);
1647 extern void shader_glsl_break(SHADER_OPCODE_ARG* arg);
1648 extern void shader_glsl_breakc(SHADER_OPCODE_ARG* arg);
1649 extern void shader_glsl_rep(SHADER_OPCODE_ARG* arg);
1650 extern void shader_glsl_call(SHADER_OPCODE_ARG* arg);
1651 extern void shader_glsl_callnz(SHADER_OPCODE_ARG* arg);
1652 extern void shader_glsl_label(SHADER_OPCODE_ARG* arg);
1654 /** GLSL Pixel Shader Prototypes */
1655 extern void pshader_glsl_tex(SHADER_OPCODE_ARG* arg);
1656 extern void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg);
1657 extern void pshader_glsl_texdp3tex(SHADER_OPCODE_ARG* arg);
1658 extern void pshader_glsl_texdp3(SHADER_OPCODE_ARG* arg);
1659 extern void pshader_glsl_texdepth(SHADER_OPCODE_ARG* arg);
1660 extern void pshader_glsl_texm3x2depth(SHADER_OPCODE_ARG* arg);
1661 extern void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg);
1662 extern void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg);
1663 extern void pshader_glsl_texm3x3(SHADER_OPCODE_ARG* arg);
1664 extern void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg);
1665 extern void pshader_glsl_texm3x3tex(SHADER_OPCODE_ARG* arg);
1666 extern void pshader_glsl_texm3x3spec(SHADER_OPCODE_ARG* arg);
1667 extern void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1668 extern void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg);
1669 extern void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg);
1670 extern void pshader_glsl_texreg2ar(SHADER_OPCODE_ARG* arg);
1671 extern void pshader_glsl_texreg2gb(SHADER_OPCODE_ARG* arg);
1672 extern void pshader_glsl_texreg2rgb(SHADER_OPCODE_ARG* arg);
1673 extern void pshader_glsl_dp2add(SHADER_OPCODE_ARG* arg);
1674 extern void pshader_glsl_input_pack(
1675 SHADER_BUFFER* buffer,
1676 semantic* semantics_out);
1678 /** GLSL Vertex Shader Prototypes */
1679 extern void vshader_glsl_output_unpack(
1680 SHADER_BUFFER* buffer,
1681 semantic* semantics_out);
1683 /*****************************************************************************
1684 * IDirect3DBaseShader implementation structure
1686 typedef struct IWineD3DBaseShaderClass
1689 SHADER_LIMITS limits;
1690 SHADER_PARSE_STATE parse_state;
1691 CONST SHADER_OPCODE *shader_ins;
1692 CONST DWORD *function;
1693 UINT functionLength;
1697 /* Type of shader backend */
1700 /* Immediate constants (override global ones) */
1701 struct list constantsB;
1702 struct list constantsF;
1703 struct list constantsI;
1704 shader_reg_maps reg_maps;
1706 /* Pointer to the parent device */
1707 IWineD3DDevice *device;
1709 } IWineD3DBaseShaderClass;
1711 typedef struct IWineD3DBaseShaderImpl {
1713 const IWineD3DBaseShaderVtbl *lpVtbl;
1716 /* IWineD3DBaseShader */
1717 IWineD3DBaseShaderClass baseShader;
1718 } IWineD3DBaseShaderImpl;
1720 extern HRESULT shader_get_registers_used(
1721 IWineD3DBaseShader *iface,
1722 shader_reg_maps* reg_maps,
1723 semantic* semantics_in,
1724 semantic* semantics_out,
1725 CONST DWORD* pToken,
1726 IWineD3DStateBlockImpl *stateBlock);
1728 extern void shader_generate_glsl_declarations(
1729 IWineD3DBaseShader *iface,
1730 shader_reg_maps* reg_maps,
1731 SHADER_BUFFER* buffer,
1732 WineD3D_GL_Info* gl_info);
1734 extern void shader_generate_arb_declarations(
1735 IWineD3DBaseShader *iface,
1736 shader_reg_maps* reg_maps,
1737 SHADER_BUFFER* buffer,
1738 WineD3D_GL_Info* gl_info);
1740 extern void shader_generate_main(
1741 IWineD3DBaseShader *iface,
1742 SHADER_BUFFER* buffer,
1743 shader_reg_maps* reg_maps,
1744 CONST DWORD* pFunction);
1746 extern void shader_dump_ins_modifiers(
1747 const DWORD output);
1749 extern void shader_dump_param(
1750 IWineD3DBaseShader *iface,
1752 const DWORD addr_token,
1755 extern void shader_trace_init(
1756 IWineD3DBaseShader *iface,
1757 const DWORD* pFunction);
1759 extern int shader_get_param(
1760 IWineD3DBaseShader* iface,
1761 const DWORD* pToken,
1765 extern int shader_skip_unrecognized(
1766 IWineD3DBaseShader* iface,
1767 const DWORD* pToken);
1769 extern void print_glsl_info_log(
1770 WineD3D_GL_Info *gl_info,
1773 inline static int shader_get_regtype(const DWORD param) {
1774 return (((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT) |
1775 ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2));
1778 extern unsigned int shader_get_float_offset(const DWORD reg);
1780 inline static BOOL shader_is_pshader_version(DWORD token) {
1781 return 0xFFFF0000 == (token & 0xFFFF0000);
1784 inline static BOOL shader_is_vshader_version(DWORD token) {
1785 return 0xFFFE0000 == (token & 0xFFFF0000);
1788 inline static BOOL shader_is_comment(DWORD token) {
1789 return WINED3DSIO_COMMENT == (token & WINED3DSI_OPCODE_MASK);
1792 /* Internally used shader constants. Applications can use constants 0 to GL_LIMITS(vshader_constantsF) - 1,
1793 * so upload them above that
1795 #define ARB_SHADER_PRIVCONST_BASE GL_LIMITS(vshader_constantsF)
1796 #define ARB_SHADER_PRIVCONST_POS ARB_SHADER_PRIVCONST_BASE + 0
1798 /*****************************************************************************
1799 * IDirect3DVertexShader implementation structure
1801 typedef struct IWineD3DVertexShaderImpl {
1803 const IWineD3DVertexShaderVtbl *lpVtbl;
1804 LONG ref; /* Note: Ref counting not required */
1806 /* IWineD3DBaseShader */
1807 IWineD3DBaseShaderClass baseShader;
1809 /* IWineD3DVertexShaderImpl */
1815 /* Vertex shader input and output semantics */
1816 semantic semantics_in [MAX_ATTRIBS];
1817 semantic semantics_out [MAX_REG_OUTPUT];
1819 /* run time datas... */
1821 #if 0 /* needs reworking */
1822 /* run time datas */
1823 VSHADERINPUTDATA input;
1824 VSHADEROUTPUTDATA output;
1826 } IWineD3DVertexShaderImpl;
1827 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1828 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1830 /*****************************************************************************
1831 * IDirect3DPixelShader implementation structure
1833 typedef struct IWineD3DPixelShaderImpl {
1834 /* IUnknown parts */
1835 const IWineD3DPixelShaderVtbl *lpVtbl;
1836 LONG ref; /* Note: Ref counting not required */
1838 /* IWineD3DBaseShader */
1839 IWineD3DBaseShaderClass baseShader;
1841 /* IWineD3DPixelShaderImpl */
1844 /* Pixel shader input semantics */
1845 semantic semantics_in [MAX_REG_INPUT];
1850 /* Some information about the shader behavior */
1852 UINT bumpenvmatconst;
1854 #if 0 /* needs reworking */
1855 PSHADERINPUTDATA input;
1856 PSHADEROUTPUTDATA output;
1858 } IWineD3DPixelShaderImpl;
1860 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1861 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1863 /*****************************************************************************
1864 * IWineD3DPalette implementation structure
1866 struct IWineD3DPaletteImpl {
1867 /* IUnknown parts */
1868 const IWineD3DPaletteVtbl *lpVtbl;
1872 IWineD3DDeviceImpl *wineD3DDevice;
1874 /* IWineD3DPalette */
1876 WORD palVersion; /*| */
1877 WORD palNumEntries; /*| LOGPALETTE */
1878 PALETTEENTRY palents[256]; /*| */
1879 /* This is to store the palette in 'screen format' */
1880 int screen_palents[256];
1884 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
1885 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
1887 /* DirectDraw utility functions */
1888 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
1890 /*****************************************************************************
1891 * Pixel format management
1894 WINED3DFORMAT format;
1895 DWORD alphaMask, redMask, greenMask, blueMask;
1898 GLint glInternal, glFormat, glType;
1901 const PixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt);