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"
41 #include "wine/wined3d_interface.h"
42 #include "wine/wined3d_caps.h"
43 #include "wine/wined3d_gl.h"
44 #include "wine/list.h"
46 /* Hash table functions */
47 typedef unsigned int (hash_function_t
)(void *key
);
48 typedef BOOL (compare_function_t
)(void *keya
, void *keyb
);
58 hash_function_t
*hash_function
;
59 compare_function_t
*compare_function
;
61 unsigned int bucket_count
;
62 hash_table_entry_t
*entries
;
63 unsigned int entry_count
;
64 struct list free_entries
;
66 unsigned int grow_size
;
67 unsigned int shrink_size
;
70 hash_table_t
*hash_table_create(hash_function_t
*hash_function
, compare_function_t
*compare_function
);
71 void hash_table_destroy(hash_table_t
*table
);
72 void *hash_table_get(hash_table_t
*table
, void *key
);
73 void hash_table_put(hash_table_t
*table
, void *key
, void *value
);
74 void hash_table_remove(hash_table_t
*table
, void *key
);
77 #define MAX_PALETTES 256
78 #define MAX_STREAMS 16
79 #define MAX_TEXTURES 8
80 #define MAX_SAMPLERS 16
81 #define MAX_ACTIVE_LIGHTS 8
82 #define MAX_CLIPPLANES WINED3DMAXUSERCLIPPLANES
83 #define MAX_LEVELS 256
85 #define MAX_CONST_I 16
86 #define MAX_CONST_B 16
88 /* Used for CreateStateBlock */
89 #define NUM_SAVEDPIXELSTATES_R 35
90 #define NUM_SAVEDPIXELSTATES_T 18
91 #define NUM_SAVEDPIXELSTATES_S 12
92 #define NUM_SAVEDVERTEXSTATES_R 31
93 #define NUM_SAVEDVERTEXSTATES_T 2
94 #define NUM_SAVEDVERTEXSTATES_S 1
96 extern const DWORD SavedPixelStates_R
[NUM_SAVEDPIXELSTATES_R
];
97 extern const DWORD SavedPixelStates_T
[NUM_SAVEDPIXELSTATES_T
];
98 extern const DWORD SavedPixelStates_S
[NUM_SAVEDPIXELSTATES_S
];
99 extern const DWORD SavedVertexStates_R
[NUM_SAVEDVERTEXSTATES_R
];
100 extern const DWORD SavedVertexStates_T
[NUM_SAVEDVERTEXSTATES_T
];
101 extern const DWORD SavedVertexStates_S
[NUM_SAVEDVERTEXSTATES_S
];
103 typedef enum _WINELOOKUP
{
104 WINELOOKUP_WARPPARAM
= 0,
105 WINELOOKUP_MAGFILTER
= 1,
109 extern int minLookup
[MAX_LOOKUPS
];
110 extern int maxLookup
[MAX_LOOKUPS
];
111 extern DWORD
*stateLookup
[MAX_LOOKUPS
];
113 extern DWORD minMipLookup
[WINED3DTEXF_ANISOTROPIC
+ 1][WINED3DTEXF_LINEAR
+ 1];
115 typedef struct _WINED3DGLTYPE
{
119 GLboolean normalized
;
123 /* NOTE: Make sure these are in the correct numerical order. (see /include/wined3d_types.h) */
124 static WINED3DGLTYPE
const glTypeLookup
[WINED3DDECLTYPE_UNUSED
] = {
125 {WINED3DDECLTYPE_FLOAT1
, 1, GL_FLOAT
, GL_FALSE
,sizeof(float)},
126 {WINED3DDECLTYPE_FLOAT2
, 2, GL_FLOAT
, GL_FALSE
,sizeof(float)},
127 {WINED3DDECLTYPE_FLOAT3
, 3, GL_FLOAT
, GL_FALSE
,sizeof(float)},
128 {WINED3DDECLTYPE_FLOAT4
, 4, GL_FLOAT
, GL_FALSE
,sizeof(float)},
129 {WINED3DDECLTYPE_D3DCOLOR
, 4, GL_UNSIGNED_BYTE
, GL_TRUE
,sizeof(BYTE
)},
130 {WINED3DDECLTYPE_UBYTE4
, 4, GL_UNSIGNED_BYTE
, GL_FALSE
,sizeof(BYTE
)},
131 {WINED3DDECLTYPE_SHORT2
, 2, GL_SHORT
, GL_FALSE
,sizeof(short int)},
132 {WINED3DDECLTYPE_SHORT4
, 4, GL_SHORT
, GL_FALSE
,sizeof(short int)},
133 {WINED3DDECLTYPE_UBYTE4N
, 4, GL_UNSIGNED_BYTE
, GL_FALSE
,sizeof(BYTE
)},
134 {WINED3DDECLTYPE_SHORT2N
, 2, GL_SHORT
, GL_FALSE
,sizeof(short int)},
135 {WINED3DDECLTYPE_SHORT4N
, 4, GL_SHORT
, GL_FALSE
,sizeof(short int)},
136 {WINED3DDECLTYPE_USHORT2N
, 2, GL_UNSIGNED_SHORT
, GL_FALSE
,sizeof(short int)},
137 {WINED3DDECLTYPE_USHORT4N
, 4, GL_UNSIGNED_SHORT
, GL_FALSE
,sizeof(short int)},
138 {WINED3DDECLTYPE_UDEC3
, 3, GL_UNSIGNED_SHORT
, GL_FALSE
,sizeof(short int)},
139 {WINED3DDECLTYPE_DEC3N
, 3, GL_SHORT
, GL_FALSE
,sizeof(short int)},
140 {WINED3DDECLTYPE_FLOAT16_2
, 2, GL_FLOAT
, GL_FALSE
,sizeof(short int)},
141 {WINED3DDECLTYPE_FLOAT16_4
, 4, GL_FLOAT
, GL_FALSE
,sizeof(short int)}};
143 #define WINED3D_ATR_TYPE(type) glTypeLookup[type].d3dType
144 #define WINED3D_ATR_SIZE(type) glTypeLookup[type].size
145 #define WINED3D_ATR_GLTYPE(type) glTypeLookup[type].glType
146 #define WINED3D_ATR_NORMALIZED(type) glTypeLookup[type].normalized
147 #define WINED3D_ATR_TYPESIZE(type) glTypeLookup[type].typesize
165 #define ORM_BACKBUFFER 0
166 #define ORM_PBUFFER 1
170 #define SHADER_GLSL 2
171 #define SHADER_NONE 3
173 #define RTL_DISABLE -1
175 #define RTL_READDRAW 1
176 #define RTL_READTEX 2
177 #define RTL_TEXDRAW 3
180 /* NOTE: When adding fields to this structure, make sure to update the default
181 * values in wined3d_main.c as well. */
182 typedef struct wined3d_settings_s
{
183 /* vertex and pixel shader modes */
187 /* Ideally, we don't want the user to have to request GLSL. If the hardware supports GLSL,
188 we should use it. However, until it's fully implemented, we'll leave it as a registry
189 setting for developers. */
191 int offscreen_rendering_mode
;
192 int rendertargetlock_mode
;
193 /* Memory tracking and object counting */
194 unsigned int emulated_textureram
;
195 } wined3d_settings_t
;
197 extern wined3d_settings_t wined3d_settings
;
199 /* Shader backends */
202 void (*shader_select
)(IWineD3DDevice
*iface
, BOOL usePS
, BOOL useVS
);
203 void (*shader_select_depth_blt
)(IWineD3DDevice
*iface
);
204 void (*shader_load_constants
)(IWineD3DDevice
*iface
, char usePS
, char useVS
);
205 void (*shader_cleanup
)(IWineD3DDevice
*iface
);
208 extern const shader_backend_t glsl_shader_backend
;
209 extern const shader_backend_t arb_program_shader_backend
;
210 extern const shader_backend_t none_shader_backend
;
214 extern void (*wine_tsx11_lock_ptr
)(void);
215 extern void (*wine_tsx11_unlock_ptr
)(void);
217 /* As GLX relies on X, this is needed */
221 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
222 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
224 #define ENTER_GL() wine_tsx11_lock_ptr()
225 #define LEAVE_GL() wine_tsx11_unlock_ptr()
228 /*****************************************************************************
232 /* GL related defines */
233 /* ------------------ */
234 #define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
235 #define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
236 #define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
237 #define GL_VEND(_VendName) (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
239 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
240 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
241 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
242 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
244 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
245 #define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
246 #define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
247 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
249 #define D3DCOLORTOGLFLOAT4(dw, vec) \
250 (vec)[0] = D3DCOLOR_R(dw); \
251 (vec)[1] = D3DCOLOR_G(dw); \
252 (vec)[2] = D3DCOLOR_B(dw); \
253 (vec)[3] = D3DCOLOR_A(dw);
255 /* DirectX Device Limits */
256 /* --------------------- */
257 #define MAX_LEVELS 256 /* Maximum number of mipmap levels. Guessed at 256 */
259 #define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
260 See MaxStreams in MSDN under GetDeviceCaps */
261 /* Maximum number of constants provided to the shaders */
262 #define HIGHEST_TRANSFORMSTATE 512
263 /* Highest value in WINED3DTRANSFORMSTATETYPE */
264 #define MAX_PALETTES 256
266 /* Checking of API calls */
267 /* --------------------- */
268 #define checkGLcall(A) \
270 GLint err = glGetError(); \
271 if (err == GL_NO_ERROR) { \
272 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
275 FIXME(">>>>>>>>>>>>>>>>> %s (%#x) from %s @ %s / %d\n", \
276 debug_glerror(err), err, A, __FILE__, __LINE__); \
277 err = glGetError(); \
278 } while (err != GL_NO_ERROR); \
281 /* Trace routines / diagnostics */
282 /* ---------------------------- */
284 /* Dump out a matrix and copy it */
285 #define conv_mat(mat,gl_mat) \
287 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
288 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
289 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
290 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
291 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
294 /* Macro to dump out the current state of the light chain */
295 #define DUMP_LIGHT_CHAIN() \
297 PLIGHTINFOEL *el = This->stateBlock->lights;\
299 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
304 /* Trace vector and strided data information */
305 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
306 #define TRACE_STRIDED(sd,name) TRACE( #name "=(data:%p, stride:%d, type:%d, vbo %d, stream %u)\n", \
307 sd->u.s.name.lpData, sd->u.s.name.dwStride, sd->u.s.name.dwType, sd->u.s.name.VBO, sd->u.s.name.streamNo);
309 /* Defines used for optimizations */
311 /* Only reapply what is necessary */
312 #define REAPPLY_ALPHAOP 0x0001
313 #define REAPPLY_ALL 0xFFFF
315 /* Advance declaration of structures to satisfy compiler */
316 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl
;
317 typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl
;
318 typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl
;
319 typedef struct IWineD3DDeviceImpl IWineD3DDeviceImpl
;
323 /* TODO: Move some of this to the device */
324 long globalChangeGlRam(long glram
);
326 /* Memory and object tracking */
328 /*Structure for holding information on all direct3d objects
329 useful for making sure tracking is ok and when release is called on a device!
330 and probably quite handy for debugging and dumping states out
332 typedef struct WineD3DGlobalStatistics
{
333 int glsurfaceram
; /* The aproximate amount of glTexture memory allocated for textures */
334 } WineD3DGlobalStatistics
;
336 extern WineD3DGlobalStatistics
* wineD3DGlobalStatistics
;
338 /* Global variables */
339 extern const float identity
[16];
341 /*****************************************************************************
342 * Compilable extra diagnostics
345 /* Trace information per-vertex: (extremely high amount of trace) */
346 #if 0 /* NOTE: Must be 0 in cvs */
347 # define VTRACE(A) TRACE A
352 /* Checking of per-vertex related GL calls */
353 /* --------------------- */
354 #define vcheckGLcall(A) \
356 GLint err = glGetError(); \
357 if (err == GL_NO_ERROR) { \
358 VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
361 FIXME(">>>>>>>>>>>>>>>>> %s (%#x) from %s @ %s / %d\n", \
362 debug_glerror(err), err, A, __FILE__, __LINE__); \
363 err = glGetError(); \
364 } while (err != GL_NO_ERROR); \
367 /* TODO: Confirm each of these works when wined3d move completed */
368 #if 0 /* NOTE: Must be 0 in cvs */
369 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
370 of each frame, a check is made for the existence of C:\D3DTRACE, and if it exists d3d trace
371 is enabled, and if it doesn't exist it is disabled. */
372 # define FRAME_DEBUGGING
373 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
374 the file is deleted */
375 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
376 # define SINGLE_FRAME_DEBUGGING
378 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
379 It can only be enabled when FRAME_DEBUGGING is also enabled
380 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
382 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
383 # define SHOW_FRAME_MAKEUP 1
385 /* The following, when enabled, lets you see the makeup of the all the textures used during each
386 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
387 The contents of the textures assigned to each stage are written into
388 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
389 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
390 # define SHOW_TEXTURE_MAKEUP 0
393 extern BOOL isDumpingFrames
;
394 extern LONG primCounter
;
397 /*****************************************************************************
401 /* Routine common to the draw primitive and draw indexed primitive routines */
402 void drawPrimitive(IWineD3DDevice
*iface
,
406 long StartVertexIndex
,
407 UINT numberOfVertices
,
413 void primitiveDeclarationConvertToStridedData(
414 IWineD3DDevice
*iface
,
415 BOOL useVertexShaderFunction
,
416 WineDirect3DVertexStridedData
*strided
,
419 DWORD
get_flexible_vertex_size(DWORD d3dvtVertexType
);
421 void blt_to_drawable(IWineD3DDeviceImpl
*This
, IWineD3DSurfaceImpl
*surface
);
425 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
426 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
428 /* Routines and structures related to state management */
429 typedef struct WineD3DContext WineD3DContext
;
430 typedef void (*APPLYSTATEFUNC
)(DWORD state
, IWineD3DStateBlockImpl
*stateblock
, WineD3DContext
*ctx
);
432 #define STATE_RENDER(a) (a)
433 #define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
435 #define STATE_TEXTURESTAGE(stage, num) (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + (stage) * WINED3D_HIGHEST_TEXTURE_STATE + (num))
436 #define STATE_IS_TEXTURESTAGE(a) ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
438 /* + 1 because samplers start with 0 */
439 #define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
440 #define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(MAX_SAMPLERS - 1))
442 #define STATE_PIXELSHADER (STATE_SAMPLER(MAX_SAMPLERS - 1) + 1)
443 #define STATE_IS_PIXELSHADER(a) ((a) == STATE_PIXELSHADER)
445 #define STATE_TRANSFORM(a) (STATE_PIXELSHADER + (a))
446 #define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)))
448 #define STATE_STREAMSRC (STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)) + 1)
449 #define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
450 #define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
451 #define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
453 #define STATE_VDECL (STATE_INDEXBUFFER + 1)
454 #define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
456 #define STATE_VSHADER (STATE_VDECL + 1)
457 #define STATE_IS_VSHADER(a) ((a) == STATE_VSHADER)
459 #define STATE_VIEWPORT (STATE_VSHADER + 1)
460 #define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
462 #define STATE_VERTEXSHADERCONSTANT (STATE_VIEWPORT + 1)
463 #define STATE_PIXELSHADERCONSTANT (STATE_VERTEXSHADERCONSTANT + 1)
464 #define STATE_IS_VERTEXSHADERCONSTANT(a) ((a) == STATE_VERTEXSHADERCONSTANT)
465 #define STATE_IS_PIXELSHADERCONSTANT(a) ((a) == STATE_PIXELSHADERCONSTANT)
467 #define STATE_ACTIVELIGHT(a) (STATE_PIXELSHADERCONSTANT + (a) + 1)
468 #define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_PIXELSHADERCONSTANT(MAX_ACTIVE_LIGHTS))
470 #define STATE_SCISSORRECT (STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS - 1) + 1)
471 #define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
473 #define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
474 #define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(MAX_CLIPPLANES - 1))
476 #define STATE_MATERIAL (STATE_CLIPPLANE(MAX_CLIPPLANES))
478 #define STATE_HIGHEST (STATE_MATERIAL)
482 DWORD representative
;
483 APPLYSTATEFUNC apply
;
486 /* Global state table */
487 extern const struct StateEntry StateTable
[];
489 /* The new context manager that should deal with onscreen and offscreen rendering */
490 struct WineD3DContext
{
491 /* State dirtification
492 * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices
493 * 0...numDirtyEntries - 1. isStateDirty is a redundant copy of the dirtyArray. Technically only one of them would be needed,
494 * 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
495 * only numDirtyEntries array elements have to be checked, not STATE_HIGHEST states.
497 DWORD dirtyArray
[STATE_HIGHEST
+ 1]; /* Won't get bigger than that, a state is never marked dirty 2 times */
498 DWORD numDirtyEntries
;
499 DWORD isStateDirty
[STATE_HIGHEST
/32 + 1]; /* Bitmap to find out quickly if a state is dirty */
501 IWineD3DSurface
*surface
;
502 DWORD tid
; /* Thread ID which owns this context at the moment */
504 /* Stores some inforation about the context state for optimization */
505 BOOL last_was_rhw
; /* true iff last draw_primitive was in xyzrhw mode */
506 BOOL last_was_pshader
;
507 BOOL last_was_vshader
;
508 BOOL last_was_foggy_shader
;
509 BOOL namedArraysLoaded
, numberedArraysLoaded
;
510 BOOL lastWasPow2Texture
[MAX_TEXTURES
];
511 GLenum tracking_parm
; /* Which source is tracking current colour */
512 unsigned char num_untracked_materials
;
513 GLenum untracked_materials
[2];
514 BOOL last_was_blit
, last_was_ckey
;
515 char texShaderBumpMap
;
517 /* The actual opengl context */
524 typedef enum ContextUsage
{
525 CTXUSAGE_RESOURCELOAD
= 1, /* Only loads textures: No State is applied */
526 CTXUSAGE_DRAWPRIM
= 2, /* OpenGL states are set up for blitting DirectDraw surfacs */
527 CTXUSAGE_BLIT
= 3, /* OpenGL states are set up 3D drawing */
530 void ActivateContext(IWineD3DDeviceImpl
*device
, IWineD3DSurface
*target
, ContextUsage usage
);
531 WineD3DContext
*CreateContext(IWineD3DDeviceImpl
*This
, IWineD3DSurfaceImpl
*target
, Display
*display
, Window win
);
532 void DestroyContext(IWineD3DDeviceImpl
*This
, WineD3DContext
*context
);
533 void apply_fbo_state(IWineD3DDevice
*iface
);
535 /* Macros for doing basic GPU detection based on opengl capabilities */
536 #define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
537 #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])
538 #define WINE_D3D8_CAPABLE(gl_info) WINE_D3D7_CAPABLE(gl_info) && (gl_info->supported[ARB_MULTISAMPLE] && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
539 #define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER])
541 /* Default callbacks for implicit object destruction */
542 extern ULONG WINAPI
D3DCB_DefaultDestroySurface(IWineD3DSurface
*pSurface
);
544 extern ULONG WINAPI
D3DCB_DefaultDestroyVolume(IWineD3DVolume
*pSurface
);
546 /*****************************************************************************
547 * Internal representation of a light
549 typedef struct PLIGHTINFOEL PLIGHTINFOEL
;
550 struct PLIGHTINFOEL
{
551 WINED3DLIGHT OriginalParms
; /* Note D3D8LIGHT == D3D9LIGHT */
557 /* Converted parms to speed up swapping lights */
566 /* The default light parameters */
567 extern const WINED3DLIGHT WINED3D_default_light
;
569 /* The adapter structure */
570 struct WineD3DAdapter
574 WineD3D_GL_Info gl_info
;
576 const char *description
;
581 extern BOOL
InitAdapters(void);
583 /*****************************************************************************
584 * IWineD3D implementation structure
586 typedef struct IWineD3DImpl
588 /* IUnknown fields */
589 const IWineD3DVtbl
*lpVtbl
;
590 LONG ref
; /* Note: Ref counting not required */
592 /* WineD3D Information */
597 extern const IWineD3DVtbl IWineD3D_Vtbl
;
599 /* TODO: setup some flags in the registry to enable, disable pbuffer support
600 (since it will break quite a few things until contexts are managed properly!) */
601 extern BOOL pbuffer_support
;
602 /* allocate one pbuffer per surface */
603 extern BOOL pbuffer_per_surface
;
605 typedef struct ResourceList
{
606 IWineD3DResource
*resource
;
607 struct ResourceList
*next
;
610 /* A helper function that dumps a resource list */
611 void dumpResources(ResourceList
*resources
);
613 /*****************************************************************************
614 * IWineD3DDevice implementation structure
616 struct IWineD3DDeviceImpl
618 /* IUnknown fields */
619 const IWineD3DDeviceVtbl
*lpVtbl
;
620 LONG ref
; /* Note: Ref counting not required */
622 /* WineD3D Information */
625 struct WineD3DAdapter
*adapter
;
627 /* Window styles to restore when switching fullscreen mode */
631 /* X and GL Information */
632 GLint maxConcurrentLights
;
633 GLenum offscreenBuffer
;
635 /* Selected capabilities */
636 int vs_selected_mode
;
637 int ps_selected_mode
;
638 const shader_backend_t
*shader_backend
;
639 hash_table_t
*glsl_program_lookup
;
642 BOOL view_ident
; /* true iff view matrix is identity */
644 BOOL vertexBlendUsed
; /* To avoid needless setting of the blend matrices */
645 unsigned char surface_alignment
; /* Line Alignment of surfaces */
647 /* State block related */
648 BOOL isRecordingState
;
649 IWineD3DStateBlockImpl
*stateBlock
;
650 IWineD3DStateBlockImpl
*updateStateBlock
;
653 /* Internal use fields */
654 WINED3DDEVICE_CREATION_PARAMETERS createParms
;
656 WINED3DDEVTYPE devType
;
658 IWineD3DSwapChain
**swapchains
;
659 uint NumberOfSwapChains
;
661 ResourceList
*resources
; /* a linked list to track resources created by the device */
663 /* Render Target Support */
664 IWineD3DSurface
**render_targets
;
665 IWineD3DSurface
*depthStencilBuffer
;
666 IWineD3DSurface
**fbo_color_attachments
;
667 IWineD3DSurface
*fbo_depth_attachment
;
669 IWineD3DSurface
*stencilBufferTarget
;
671 /* Caches to avoid unneeded context changes */
672 IWineD3DSurface
*lastActiveRenderTarget
;
673 IWineD3DSwapChain
*lastActiveSwapChain
;
675 /* palettes texture management */
676 PALETTEENTRY palettes
[MAX_PALETTES
][256];
679 /* For rendering to a texture using glCopyTexImage */
680 BOOL render_offscreen
;
681 WINED3D_DEPTHCOPYSTATE depth_copy_state
;
685 GLenum
*draw_buffers
;
687 /* Cursor management */
693 UINT cursorWidth
, cursorHeight
;
694 GLuint cursorTexture
;
695 BOOL haveHardwareCursor
;
696 HCURSOR hardwareCursor
;
698 /* Textures for when no other textures are mapped */
699 UINT dummyTextureName
[MAX_TEXTURES
];
701 /* Debug stream management */
704 /* Device state management */
706 BOOL d3d_initialized
;
708 /* A flag to check for proper BeginScene / EndScene call pairs */
711 /* process vertex shaders using software or hardware */
712 BOOL softwareVertexProcessing
;
714 /* DirectDraw stuff */
716 IWineD3DSurface
*ddraw_primary
;
717 DWORD ddraw_width
, ddraw_height
;
718 WINED3DFORMAT ddraw_format
;
719 BOOL ddraw_fullscreen
;
721 /* Final position fixup constant */
724 /* With register combiners we can skip junk texture stages */
725 DWORD texUnitMap
[MAX_SAMPLERS
];
726 DWORD rev_tex_unit_map
[MAX_SAMPLERS
];
727 BOOL oneToOneTexUnitMap
;
729 /* Stream source management */
730 WineDirect3DVertexStridedData strided_streams
;
731 WineDirect3DVertexStridedData
*up_strided
;
732 BOOL useDrawStridedSlow
;
735 /* Context management */
736 WineD3DContext
**contexts
; /* Dynamic array containing pointers to context structures */
737 WineD3DContext
*activeContext
; /* Only 0 for now */
738 UINT numContexts
; /* Always 1 for now */
739 WineD3DContext
*pbufferContext
; /* The context that has a pbuffer as drawable */
740 DWORD pbufferWidth
, pbufferHeight
; /* Size of the buffer drawable */
743 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl
;
745 void IWineD3DDeviceImpl_FindTexUnitMap(IWineD3DDeviceImpl
*This
);
746 void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl
*This
, DWORD state
);
747 static inline BOOL
isStateDirty(WineD3DContext
*context
, DWORD state
) {
748 DWORD idx
= state
>> 5;
749 BYTE shift
= state
& 0x1f;
750 return context
->isStateDirty
[idx
] & (1 << shift
);
753 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. */
754 typedef struct PrivateData
759 DWORD flags
; /* DDSPD_* */
760 DWORD uniqueness_value
;
771 /*****************************************************************************
772 * IWineD3DResource implementation structure
774 typedef struct IWineD3DResourceClass
776 /* IUnknown fields */
777 LONG ref
; /* Note: Ref counting not required */
779 /* WineD3DResource Information */
781 WINED3DRESOURCETYPE resourceType
;
782 IWineD3DDeviceImpl
*wineD3DDevice
;
786 WINED3DFORMAT format
;
787 BYTE
*allocatedMemory
;
788 struct list privateData
;
790 } IWineD3DResourceClass
;
792 typedef struct IWineD3DResourceImpl
794 /* IUnknown & WineD3DResource Information */
795 const IWineD3DResourceVtbl
*lpVtbl
;
796 IWineD3DResourceClass resource
;
797 } IWineD3DResourceImpl
;
800 /*****************************************************************************
801 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
803 typedef struct IWineD3DVertexBufferImpl
805 /* IUnknown & WineD3DResource Information */
806 const IWineD3DVertexBufferVtbl
*lpVtbl
;
807 IWineD3DResourceClass resource
;
809 /* WineD3DVertexBuffer specifics */
812 /* Vertex buffer object support */
817 UINT dirtystart
, dirtyend
;
820 LONG declChanges
, draws
;
821 /* Last description of the buffer */
822 WineDirect3DVertexStridedData strided
;
823 } IWineD3DVertexBufferImpl
;
825 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl
;
827 #define VBFLAG_LOAD 0x01 /* Data is written from allocatedMemory to the VBO */
828 #define VBFLAG_OPTIMIZED 0x02 /* Optimize has been called for the VB */
829 #define VBFLAG_DIRTY 0x04 /* Buffer data has been modified */
830 #define VBFLAG_HASDESC 0x08 /* A vertex description has been found */
831 #define VBFLAG_VBOCREATEFAIL 0x10 /* An attempt to create a vbo has failed */
833 /*****************************************************************************
834 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
836 typedef struct IWineD3DIndexBufferImpl
838 /* IUnknown & WineD3DResource Information */
839 const IWineD3DIndexBufferVtbl
*lpVtbl
;
840 IWineD3DResourceClass resource
;
843 UINT dirtystart
, dirtyend
;
846 /* WineD3DVertexBuffer specifics */
847 } IWineD3DIndexBufferImpl
;
849 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl
;
851 /*****************************************************************************
852 * IWineD3DBaseTexture D3D- > openGL state map lookups
854 #define WINED3DFUNC_NOTSUPPORTED -2
855 #define WINED3DFUNC_UNIMPLEMENTED -1
857 typedef enum winetexturestates
{
858 WINED3DTEXSTA_ADDRESSU
= 0,
859 WINED3DTEXSTA_ADDRESSV
= 1,
860 WINED3DTEXSTA_ADDRESSW
= 2,
861 WINED3DTEXSTA_BORDERCOLOR
= 3,
862 WINED3DTEXSTA_MAGFILTER
= 4,
863 WINED3DTEXSTA_MINFILTER
= 5,
864 WINED3DTEXSTA_MIPFILTER
= 6,
865 WINED3DTEXSTA_MAXMIPLEVEL
= 7,
866 WINED3DTEXSTA_MAXANISOTROPY
= 8,
867 WINED3DTEXSTA_SRGBTEXTURE
= 9,
868 WINED3DTEXSTA_ELEMENTINDEX
= 10,
869 WINED3DTEXSTA_DMAPOFFSET
= 11,
870 WINED3DTEXSTA_TSSADDRESSW
= 12,
871 MAX_WINETEXTURESTATES
= 13,
874 typedef struct Wined3dTextureStateMap
{
877 } Wined3dTextureStateMap
;
879 /*****************************************************************************
880 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
882 typedef struct IWineD3DBaseTextureClass
888 WINED3DTEXTUREFILTERTYPE filterType
;
889 DWORD states
[MAX_WINETEXTURESTATES
];
893 UINT srgb_mode_change_count
;
894 } IWineD3DBaseTextureClass
;
896 typedef struct IWineD3DBaseTextureImpl
898 /* IUnknown & WineD3DResource Information */
899 const IWineD3DBaseTextureVtbl
*lpVtbl
;
900 IWineD3DResourceClass resource
;
901 IWineD3DBaseTextureClass baseTexture
;
903 } IWineD3DBaseTextureImpl
;
905 /*****************************************************************************
906 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
908 typedef struct IWineD3DTextureImpl
910 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
911 const IWineD3DTextureVtbl
*lpVtbl
;
912 IWineD3DResourceClass resource
;
913 IWineD3DBaseTextureClass baseTexture
;
915 /* IWineD3DTexture */
916 IWineD3DSurface
*surfaces
[MAX_LEVELS
];
920 float pow2scalingFactorX
;
921 float pow2scalingFactorY
;
923 } IWineD3DTextureImpl
;
925 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl
;
927 /*****************************************************************************
928 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
930 typedef struct IWineD3DCubeTextureImpl
932 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
933 const IWineD3DCubeTextureVtbl
*lpVtbl
;
934 IWineD3DResourceClass resource
;
935 IWineD3DBaseTextureClass baseTexture
;
937 /* IWineD3DCubeTexture */
938 IWineD3DSurface
*surfaces
[6][MAX_LEVELS
];
941 float pow2scalingFactor
;
943 } IWineD3DCubeTextureImpl
;
945 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl
;
947 typedef struct _WINED3DVOLUMET_DESC
952 } WINED3DVOLUMET_DESC
;
954 /*****************************************************************************
955 * IWineD3DVolume implementation structure (extends IUnknown)
957 typedef struct IWineD3DVolumeImpl
959 /* IUnknown & WineD3DResource fields */
960 const IWineD3DVolumeVtbl
*lpVtbl
;
961 IWineD3DResourceClass resource
;
963 /* WineD3DVolume Information */
964 WINED3DVOLUMET_DESC currentDesc
;
965 IWineD3DBase
*container
;
970 WINED3DBOX lockedBox
;
975 } IWineD3DVolumeImpl
;
977 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl
;
979 /*****************************************************************************
980 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
982 typedef struct IWineD3DVolumeTextureImpl
984 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
985 const IWineD3DVolumeTextureVtbl
*lpVtbl
;
986 IWineD3DResourceClass resource
;
987 IWineD3DBaseTextureClass baseTexture
;
989 /* IWineD3DVolumeTexture */
990 IWineD3DVolume
*volumes
[MAX_LEVELS
];
995 } IWineD3DVolumeTextureImpl
;
997 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl
;
999 typedef struct _WINED3DSURFACET_DESC
1001 WINED3DMULTISAMPLE_TYPE MultiSampleType
;
1002 DWORD MultiSampleQuality
;
1005 } WINED3DSURFACET_DESC
;
1007 /*****************************************************************************
1008 * Structure for DIB Surfaces (GetDC and GDI surfaces)
1010 typedef struct wineD3DSurface_DIB
{
1015 } wineD3DSurface_DIB
;
1022 } renderbuffer_entry_t
;
1024 /*****************************************************************************
1025 * IWineD3DClipp implementation structure
1027 typedef struct IWineD3DClipperImpl
1029 const IWineD3DClipperVtbl
*lpVtbl
;
1034 } IWineD3DClipperImpl
;
1037 /*****************************************************************************
1038 * IWineD3DSurface implementation structure
1040 struct IWineD3DSurfaceImpl
1042 /* IUnknown & IWineD3DResource Information */
1043 const IWineD3DSurfaceVtbl
*lpVtbl
;
1044 IWineD3DResourceClass resource
;
1046 /* IWineD3DSurface fields */
1047 IWineD3DBase
*container
;
1048 WINED3DSURFACET_DESC currentDesc
;
1049 IWineD3DPaletteImpl
*palette
; /* D3D7 style palette handling */
1050 PALETTEENTRY
*palette9
; /* D3D8/9 style palette handling */
1054 /* TODO: move this off into a management class(maybe!) */
1060 /* Oversized texture */
1064 /* precalculated x and y scalings for texture coords */
1065 float pow2scalingFactorX
; /* = (Width / pow2Width ) */
1066 float pow2scalingFactorY
; /* = (Height / pow2Height) */
1072 #define MAXLOCKCOUNT 50 /* After this amount of locks do not free the sysmem copy */
1074 glDescriptor glDescription
;
1077 wineD3DSurface_DIB dib
;
1080 /* Color keys for DDraw */
1081 WINEDDCOLORKEY DestBltCKey
;
1082 WINEDDCOLORKEY DestOverlayCKey
;
1083 WINEDDCOLORKEY SrcOverlayCKey
;
1084 WINEDDCOLORKEY SrcBltCKey
;
1087 WINEDDCOLORKEY glCKey
;
1089 struct list renderbuffers
;
1090 renderbuffer_entry_t
*current_renderbuffer
;
1092 /* DirectDraw clippers */
1093 IWineD3DClipper
*clipper
;
1096 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl
;
1097 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl
;
1099 /* Predeclare the shared Surface functions */
1100 HRESULT WINAPI
IWineD3DSurfaceImpl_QueryInterface(IWineD3DSurface
*iface
, REFIID riid
, LPVOID
*ppobj
);
1101 ULONG WINAPI
IWineD3DSurfaceImpl_AddRef(IWineD3DSurface
*iface
);
1102 ULONG WINAPI
IWineD3DSurfaceImpl_Release(IWineD3DSurface
*iface
);
1103 HRESULT WINAPI
IWineD3DSurfaceImpl_GetParent(IWineD3DSurface
*iface
, IUnknown
**pParent
);
1104 HRESULT WINAPI
IWineD3DSurfaceImpl_GetDevice(IWineD3DSurface
*iface
, IWineD3DDevice
** ppDevice
);
1105 HRESULT WINAPI
IWineD3DSurfaceImpl_SetPrivateData(IWineD3DSurface
*iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
);
1106 HRESULT WINAPI
IWineD3DSurfaceImpl_GetPrivateData(IWineD3DSurface
*iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
);
1107 HRESULT WINAPI
IWineD3DSurfaceImpl_FreePrivateData(IWineD3DSurface
*iface
, REFGUID refguid
);
1108 DWORD WINAPI
IWineD3DSurfaceImpl_SetPriority(IWineD3DSurface
*iface
, DWORD PriorityNew
);
1109 DWORD WINAPI
IWineD3DSurfaceImpl_GetPriority(IWineD3DSurface
*iface
);
1110 void WINAPI
IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface
*iface
);
1111 WINED3DRESOURCETYPE WINAPI
IWineD3DSurfaceImpl_GetType(IWineD3DSurface
*iface
);
1112 HRESULT WINAPI
IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface
* iface
, REFIID riid
, void** ppContainer
);
1113 HRESULT WINAPI
IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface
*iface
, WINED3DSURFACE_DESC
*pDesc
);
1114 HRESULT WINAPI
IWineD3DSurfaceImpl_GetBltStatus(IWineD3DSurface
*iface
, DWORD Flags
);
1115 HRESULT WINAPI
IWineD3DSurfaceImpl_GetFlipStatus(IWineD3DSurface
*iface
, DWORD Flags
);
1116 HRESULT WINAPI
IWineD3DSurfaceImpl_IsLost(IWineD3DSurface
*iface
);
1117 HRESULT WINAPI
IWineD3DSurfaceImpl_Restore(IWineD3DSurface
*iface
);
1118 HRESULT WINAPI
IWineD3DSurfaceImpl_SetPixelFormat(IWineD3DSurface
*iface
, WINED3DFORMAT Format
, BYTE
*Surface
, DWORD Size
);
1119 HRESULT WINAPI
IWineD3DSurfaceImpl_GetPalette(IWineD3DSurface
*iface
, IWineD3DPalette
**Pal
);
1120 HRESULT WINAPI
IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface
*iface
, IWineD3DPalette
*Pal
);
1121 HRESULT WINAPI
IWineD3DSurfaceImpl_SetColorKey(IWineD3DSurface
*iface
, DWORD Flags
, WINEDDCOLORKEY
*CKey
);
1122 HRESULT WINAPI
IWineD3DSurfaceImpl_CleanDirtyRect(IWineD3DSurface
*iface
);
1123 extern HRESULT WINAPI
IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface
*iface
, CONST RECT
* pDirtyRect
);
1124 HRESULT WINAPI
IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface
*iface
, IWineD3DBase
*container
);
1125 void WINAPI
IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface
*iface
, UINT textureName
, int target
);
1126 void WINAPI
IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface
*iface
, glDescriptor
**glDescription
);
1127 const void *WINAPI
IWineD3DSurfaceImpl_GetData(IWineD3DSurface
*iface
);
1128 HRESULT WINAPI
IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface
*iface
, WINED3DFORMAT format
);
1129 HRESULT WINAPI
IWineGDISurfaceImpl_Blt(IWineD3DSurface
*iface
, RECT
*DestRect
, IWineD3DSurface
*SrcSurface
, RECT
*SrcRect
, DWORD Flags
, WINEDDBLTFX
*DDBltFx
, WINED3DTEXTUREFILTERTYPE Filter
);
1130 HRESULT WINAPI
IWineGDISurfaceImpl_BltFast(IWineD3DSurface
*iface
, DWORD dstx
, DWORD dsty
, IWineD3DSurface
*Source
, RECT
*rsrc
, DWORD trans
);
1131 HRESULT WINAPI
IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface
*iface
, IWineD3DPalette
*Pal
);
1132 HRESULT WINAPI
IWineD3DSurfaceImpl_GetDC(IWineD3DSurface
*iface
, HDC
*pHDC
);
1133 HRESULT WINAPI
IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface
*iface
, HDC hDC
);
1134 DWORD WINAPI
IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface
*iface
);
1135 HRESULT WINAPI
IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface
*iface
);
1136 HRESULT WINAPI
IWineD3DSurfaceImpl_SetMem(IWineD3DSurface
*iface
, void *Mem
);
1137 HRESULT WINAPI
IWineD3DSurfaceImpl_SetOverlayPosition(IWineD3DSurface
*iface
, LONG X
, LONG Y
);
1138 HRESULT WINAPI
IWineD3DSurfaceImpl_GetOverlayPosition(IWineD3DSurface
*iface
, LONG
*X
, LONG
*Y
);
1139 HRESULT WINAPI
IWineD3DSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface
*iface
, DWORD Flags
, IWineD3DSurface
*Ref
);
1140 HRESULT WINAPI
IWineD3DSurfaceImpl_UpdateOverlay(IWineD3DSurface
*iface
, RECT
*SrcRect
, IWineD3DSurface
*DstSurface
, RECT
*DstRect
, DWORD Flags
, WINEDDOVERLAYFX
*FX
);
1141 HRESULT WINAPI
IWineD3DSurfaceImpl_SetClipper(IWineD3DSurface
*iface
, IWineD3DClipper
*clipper
);
1142 HRESULT WINAPI
IWineD3DSurfaceImpl_GetClipper(IWineD3DSurface
*iface
, IWineD3DClipper
**clipper
);
1144 /* Surface flags: */
1145 #define SFLAG_OVERSIZE 0x00000001 /* Surface is bigger than gl size, blts only */
1146 #define SFLAG_CONVERTED 0x00000002 /* Converted for color keying or Palettized */
1147 #define SFLAG_DIBSECTION 0x00000004 /* Has a DIB section attached for getdc */
1148 #define SFLAG_LOCKABLE 0x00000008 /* Surface can be locked */
1149 #define SFLAG_DISCARD 0x00000010 /* ??? */
1150 #define SFLAG_LOCKED 0x00000020 /* Surface is locked atm */
1151 #define SFLAG_INTEXTURE 0x00000040 /* The GL texture contains the newest surface content */
1152 #define SFLAG_INDRAWABLE 0x00000080 /* The gl drawable contains the most up to date data */
1153 #define SFLAG_INSYSMEM 0x00000100 /* The system memory copy is most up to date */
1154 #define SFLAG_NONPOW2 0x00000200 /* Surface sizes are not a power of 2 */
1155 #define SFLAG_DYNLOCK 0x00000400 /* Surface is often locked by the app */
1156 #define SFLAG_DYNCHANGE 0x00000C00 /* Surface contents are changed very often, implies DYNLOCK */
1157 #define SFLAG_DCINUSE 0x00001000 /* Set between GetDC and ReleaseDC calls */
1158 #define SFLAG_LOST 0x00002000 /* Surface lost flag for DDraw */
1159 #define SFLAG_USERPTR 0x00004000 /* The application allocated the memory for this surface */
1160 #define SFLAG_GLCKEY 0x00008000 /* The gl texture was created with a color key */
1161 #define SFLAG_CLIENT 0x00010000 /* GL_APPLE_client_storage is used on that texture */
1162 #define SFLAG_ALLOCATED 0x00020000 /* A gl texture is allocated for this surface */
1164 /* In some conditions the surface memory must not be freed:
1165 * SFLAG_OVERSIZE: Not all data can be kept in GL
1166 * SFLAG_CONVERTED: Converting the data back would take too long
1167 * SFLAG_DIBSECTION: The dib code manages the memory
1168 * SFLAG_LOCKED: The app requires access to the surface data
1169 * SFLAG_DYNLOCK: Avoid freeing the data for performance
1170 * SFLAG_DYNCHANGE: Same reason as DYNLOCK
1171 * SFLAG_CLIENT: OpenGL uses our memory as backup
1173 #define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
1175 SFLAG_DIBSECTION | \
1182 BOOL
CalculateTexRect(IWineD3DSurfaceImpl
*This
, RECT
*Rect
, float glTexCoord
[4]);
1184 /*****************************************************************************
1185 * IWineD3DVertexDeclaration implementation structure
1187 typedef struct IWineD3DVertexDeclarationImpl
{
1188 /* IUnknown Information */
1189 const IWineD3DVertexDeclarationVtbl
*lpVtbl
;
1193 IWineD3DDeviceImpl
*wineD3DDevice
;
1195 WINED3DVERTEXELEMENT
*pDeclarationWine
;
1196 UINT declarationWNumElements
;
1197 } IWineD3DVertexDeclarationImpl
;
1199 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl
;
1201 /*****************************************************************************
1202 * IWineD3DStateBlock implementation structure
1205 /* Internal state Block for Begin/End/Capture/Create/Apply info */
1206 /* Note: Very long winded but gl Lists are not flexible enough */
1207 /* to resolve everything we need, so doing it manually for now */
1208 typedef struct SAVEDSTATES
{
1212 BOOL streamSource
[MAX_STREAMS
];
1213 BOOL streamFreq
[MAX_STREAMS
];
1214 BOOL textures
[MAX_SAMPLERS
];
1215 BOOL transform
[HIGHEST_TRANSFORMSTATE
+ 1];
1217 BOOL renderState
[WINEHIGHEST_RENDER_STATE
+ 1];
1218 BOOL textureState
[MAX_TEXTURES
][WINED3D_HIGHEST_TEXTURE_STATE
+ 1];
1219 BOOL samplerState
[MAX_SAMPLERS
][WINED3D_HIGHEST_SAMPLER_STATE
+ 1];
1220 BOOL clipplane
[MAX_CLIPPLANES
];
1223 BOOL pixelShaderConstantsB
[MAX_CONST_B
];
1224 BOOL pixelShaderConstantsI
[MAX_CONST_I
];
1225 BOOL
*pixelShaderConstantsF
;
1227 BOOL vertexShaderConstantsB
[MAX_CONST_B
];
1228 BOOL vertexShaderConstantsI
[MAX_CONST_I
];
1229 BOOL
*vertexShaderConstantsF
;
1239 struct IWineD3DStateBlockImpl
1241 /* IUnknown fields */
1242 const IWineD3DStateBlockVtbl
*lpVtbl
;
1243 LONG ref
; /* Note: Ref counting not required */
1245 /* IWineD3DStateBlock information */
1247 IWineD3DDeviceImpl
*wineD3DDevice
;
1248 WINED3DSTATEBLOCKTYPE blockType
;
1250 /* Array indicating whether things have been set or changed */
1251 SAVEDSTATES changed
;
1253 struct list set_vconstantsF
;
1254 struct list set_pconstantsF
;
1256 /* Drawing - Vertex Shader or FVF related */
1258 /* Vertex Shader Declaration */
1259 IWineD3DVertexDeclaration
*vertexDecl
;
1261 IWineD3DVertexShader
*vertexShader
;
1263 /* Vertex Shader Constants */
1264 BOOL vertexShaderConstantB
[MAX_CONST_B
];
1265 INT vertexShaderConstantI
[MAX_CONST_I
* 4];
1266 float *vertexShaderConstantF
;
1270 UINT streamStride
[MAX_STREAMS
];
1271 UINT streamOffset
[MAX_STREAMS
];
1272 IWineD3DVertexBuffer
*streamSource
[MAX_STREAMS
];
1273 UINT streamFreq
[MAX_STREAMS
];
1274 UINT streamFlags
[MAX_STREAMS
]; /*0 | WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA */
1277 IWineD3DIndexBuffer
* pIndexData
;
1278 UINT baseVertexIndex
;
1279 UINT loadBaseVertexIndex
; /* non-indexed drawing needs 0 here, indexed baseVertexIndex */
1282 WINED3DMATRIX transforms
[HIGHEST_TRANSFORMSTATE
+ 1];
1284 /* Light hashmap . Collisions are handled using standard wine double linked lists */
1285 #define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
1286 #define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
1287 struct list lightMap
[LIGHTMAP_SIZE
]; /* Mashmap containing the lights */
1288 PLIGHTINFOEL
*activeLights
[MAX_ACTIVE_LIGHTS
]; /* Map of opengl lights to d3d lights */
1291 double clipplane
[MAX_CLIPPLANES
][4];
1292 WINED3DCLIPSTATUS clip_status
;
1295 WINED3DVIEWPORT viewport
;
1298 WINED3DMATERIAL material
;
1301 IWineD3DPixelShader
*pixelShader
;
1303 /* Pixel Shader Constants */
1304 BOOL pixelShaderConstantB
[MAX_CONST_B
];
1305 INT pixelShaderConstantI
[MAX_CONST_I
* 4];
1306 float *pixelShaderConstantF
;
1309 DWORD renderState
[WINEHIGHEST_RENDER_STATE
+ 1];
1312 IWineD3DBaseTexture
*textures
[MAX_SAMPLERS
];
1313 int textureDimensions
[MAX_SAMPLERS
];
1315 /* Texture State Stage */
1316 DWORD textureState
[MAX_TEXTURES
][WINED3D_HIGHEST_TEXTURE_STATE
+ 1];
1317 DWORD lowest_disabled_stage
;
1318 /* Sampler States */
1319 DWORD samplerState
[MAX_SAMPLERS
][WINED3D_HIGHEST_SAMPLER_STATE
+ 1];
1321 /* Current GLSL Shader Program */
1322 struct glsl_shader_prog_link
*glsl_program
;
1324 /* Scissor test rectangle */
1328 extern void stateblock_savedstates_set(
1329 IWineD3DStateBlock
* iface
,
1330 SAVEDSTATES
* states
,
1333 extern void stateblock_savedstates_copy(
1334 IWineD3DStateBlock
* iface
,
1336 SAVEDSTATES
* source
);
1338 extern void stateblock_copy(
1339 IWineD3DStateBlock
* destination
,
1340 IWineD3DStateBlock
* source
);
1342 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl
;
1344 /*****************************************************************************
1345 * IWineD3DQueryImpl implementation structure (extends IUnknown)
1347 typedef struct IWineD3DQueryImpl
1349 const IWineD3DQueryVtbl
*lpVtbl
;
1350 LONG ref
; /* Note: Ref counting not required */
1353 /*TODO: replace with iface usage */
1355 IWineD3DDevice
*wineD3DDevice
;
1357 IWineD3DDeviceImpl
*wineD3DDevice
;
1360 /* IWineD3DQuery fields */
1361 WINED3DQUERYTYPE type
;
1362 /* TODO: Think about using a IUnknown instead of a void* */
1366 } IWineD3DQueryImpl
;
1368 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl
;
1370 /* Datastructures for IWineD3DQueryImpl.extendedData */
1371 typedef struct WineQueryOcclusionData
{
1373 } WineQueryOcclusionData
;
1375 typedef struct WineQueryEventData
{
1377 } WineQueryEventData
;
1379 /*****************************************************************************
1380 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1383 typedef struct IWineD3DSwapChainImpl
1386 const IWineD3DSwapChainVtbl
*lpVtbl
;
1387 LONG ref
; /* Note: Ref counting not required */
1390 IWineD3DDeviceImpl
*wineD3DDevice
;
1392 /* IWineD3DSwapChain fields */
1393 IWineD3DSurface
**backBuffer
;
1394 IWineD3DSurface
*frontBuffer
;
1395 BOOL wantsDepthStencilBuffer
;
1396 WINED3DPRESENT_PARAMETERS presentParms
;
1397 DWORD orig_width
, orig_height
;
1398 WINED3DFORMAT orig_fmt
;
1400 long prev_time
, frames
; /* Performance tracking */
1401 unsigned int vSyncCounter
;
1403 WineD3DContext
**context
; /* Later a array for multithreading */
1404 unsigned int num_contexts
;
1408 } IWineD3DSwapChainImpl
;
1410 extern const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl
;
1412 /*****************************************************************************
1413 * Utility function prototypes
1416 /* Trace routines */
1417 const char* debug_d3dformat(WINED3DFORMAT fmt
);
1418 const char* debug_d3ddevicetype(WINED3DDEVTYPE devtype
);
1419 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res
);
1420 const char* debug_d3dusage(DWORD usage
);
1421 const char* debug_d3dusagequery(DWORD usagequery
);
1422 const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method
);
1423 const char* debug_d3ddecltype(WINED3DDECLTYPE type
);
1424 const char* debug_d3ddeclusage(BYTE usage
);
1425 const char* debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType
);
1426 const char* debug_d3drenderstate(DWORD state
);
1427 const char* debug_d3dsamplerstate(DWORD state
);
1428 const char* debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type
);
1429 const char* debug_d3dtexturestate(DWORD state
);
1430 const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype
);
1431 const char* debug_d3dpool(WINED3DPOOL pool
);
1432 const char *debug_fbostatus(GLenum status
);
1433 const char *debug_glerror(GLenum error
);
1435 /* Routines for GL <-> D3D values */
1436 GLenum
StencilOp(DWORD op
);
1437 GLenum
CompareFunc(DWORD func
);
1438 void set_tex_op(IWineD3DDevice
*iface
, BOOL isAlpha
, int Stage
, WINED3DTEXTUREOP op
, DWORD arg1
, DWORD arg2
, DWORD arg3
);
1439 void set_tex_op_nvrc(IWineD3DDevice
*iface
, BOOL is_alpha
, int stage
, WINED3DTEXTUREOP op
, DWORD arg1
, DWORD arg2
, DWORD arg3
, INT texture_idx
);
1440 void set_texture_matrix(const float *smat
, DWORD flags
, BOOL calculatedCoords
);
1442 void surface_set_compatible_renderbuffer(IWineD3DSurface
*iface
, unsigned int width
, unsigned int height
);
1443 GLenum
surface_get_gl_buffer(IWineD3DSurface
*iface
, IWineD3DSwapChain
*swapchain
);
1445 int D3DFmtMakeGlCfg(WINED3DFORMAT BackBufferFormat
, WINED3DFORMAT StencilBufferFormat
, int *attribs
, int* nAttribs
, BOOL alternate
);
1448 void multiply_matrix(WINED3DMATRIX
*dest
, const WINED3DMATRIX
*src1
, const WINED3DMATRIX
*src2
);
1450 /*****************************************************************************
1451 * To enable calling of inherited functions, requires prototypes
1453 * Note: Only require classes which are subclassed, ie resource, basetexture,
1455 /*** IUnknown methods ***/
1456 extern HRESULT WINAPI
IWineD3DResourceImpl_QueryInterface(IWineD3DResource
*iface
, REFIID riid
, void** ppvObject
);
1457 extern ULONG WINAPI
IWineD3DResourceImpl_AddRef(IWineD3DResource
*iface
);
1458 extern ULONG WINAPI
IWineD3DResourceImpl_Release(IWineD3DResource
*iface
);
1459 /*** IWineD3DResource methods ***/
1460 extern HRESULT WINAPI
IWineD3DResourceImpl_GetParent(IWineD3DResource
*iface
, IUnknown
**pParent
);
1461 extern HRESULT WINAPI
IWineD3DResourceImpl_GetDevice(IWineD3DResource
*iface
, IWineD3DDevice
** ppDevice
);
1462 extern HRESULT WINAPI
IWineD3DResourceImpl_SetPrivateData(IWineD3DResource
*iface
, REFGUID refguid
, CONST
void * pData
, DWORD SizeOfData
, DWORD Flags
);
1463 extern HRESULT WINAPI
IWineD3DResourceImpl_GetPrivateData(IWineD3DResource
*iface
, REFGUID refguid
, void * pData
, DWORD
* pSizeOfData
);
1464 extern HRESULT WINAPI
IWineD3DResourceImpl_FreePrivateData(IWineD3DResource
*iface
, REFGUID refguid
);
1465 extern DWORD WINAPI
IWineD3DResourceImpl_SetPriority(IWineD3DResource
*iface
, DWORD PriorityNew
);
1466 extern DWORD WINAPI
IWineD3DResourceImpl_GetPriority(IWineD3DResource
*iface
);
1467 extern void WINAPI
IWineD3DResourceImpl_PreLoad(IWineD3DResource
*iface
);
1468 extern WINED3DRESOURCETYPE WINAPI
IWineD3DResourceImpl_GetType(IWineD3DResource
*iface
);
1469 /*** class static members ***/
1470 void IWineD3DResourceImpl_CleanUp(IWineD3DResource
*iface
);
1472 /*** IUnknown methods ***/
1473 extern HRESULT WINAPI
IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture
*iface
, REFIID riid
, void** ppvObject
);
1474 extern ULONG WINAPI
IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture
*iface
);
1475 extern ULONG WINAPI
IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture
*iface
);
1476 /*** IWineD3DResource methods ***/
1477 extern HRESULT WINAPI
IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture
*iface
, IUnknown
**pParent
);
1478 extern HRESULT WINAPI
IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture
*iface
, IWineD3DDevice
** ppDevice
);
1479 extern HRESULT WINAPI
IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture
*iface
, REFGUID refguid
, CONST
void * pData
, DWORD SizeOfData
, DWORD Flags
);
1480 extern HRESULT WINAPI
IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture
*iface
, REFGUID refguid
, void * pData
, DWORD
* pSizeOfData
);
1481 extern HRESULT WINAPI
IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture
*iface
, REFGUID refguid
);
1482 extern DWORD WINAPI
IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture
*iface
, DWORD PriorityNew
);
1483 extern DWORD WINAPI
IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture
*iface
);
1484 extern void WINAPI
IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture
*iface
);
1485 extern WINED3DRESOURCETYPE WINAPI
IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture
*iface
);
1486 /*** IWineD3DBaseTexture methods ***/
1487 extern DWORD WINAPI
IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture
*iface
, DWORD LODNew
);
1488 extern DWORD WINAPI
IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture
*iface
);
1489 extern DWORD WINAPI
IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture
*iface
);
1490 extern HRESULT WINAPI
IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture
*iface
, WINED3DTEXTUREFILTERTYPE FilterType
);
1491 extern WINED3DTEXTUREFILTERTYPE WINAPI
IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture
*iface
);
1492 extern void WINAPI
IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture
*iface
);
1493 extern BOOL WINAPI
IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture
*iface
, BOOL
);
1494 extern BOOL WINAPI
IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture
*iface
);
1496 extern BYTE
* WINAPI
IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer
* iface
, DWORD iOffset
, GLint
*vbo
);
1497 extern HRESULT WINAPI
IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer
* iface
);
1498 extern HRESULT WINAPI
IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture
*iface
);
1499 extern HRESULT WINAPI
IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture
*iface
);
1500 extern void WINAPI
IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture
*iface
, const DWORD textureStates
[WINED3D_HIGHEST_TEXTURE_STATE
+ 1], const DWORD samplerStates
[WINED3D_HIGHEST_SAMPLER_STATE
+ 1]);
1501 /*** class static members ***/
1502 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture
*iface
);
1504 struct SHADER_OPCODE_ARG
;
1505 typedef void (*SHADER_HANDLER
) (struct SHADER_OPCODE_ARG
*);
1507 /* Struct to maintain a list of GLSL shader programs and their associated pixel and
1508 * vertex shaders. A list of this type is maintained on the DeviceImpl, and is only
1509 * used if the user is using GLSL shaders. */
1510 struct glsl_shader_prog_link
{
1511 struct list vshader_entry
;
1512 struct list pshader_entry
;
1513 GLhandleARB programId
;
1514 GLhandleARB
*vuniformF_locations
;
1515 GLhandleARB
*puniformF_locations
;
1516 GLhandleARB vshader
;
1517 GLhandleARB pshader
;
1521 GLhandleARB vshader
;
1522 GLhandleARB pshader
;
1523 } glsl_program_key_t
;
1525 /* TODO: Make this dynamic, based on shader limits ? */
1526 #define MAX_REG_ADDR 1
1527 #define MAX_REG_TEMP 32
1528 #define MAX_REG_TEXCRD 8
1529 #define MAX_REG_INPUT 12
1530 #define MAX_REG_OUTPUT 12
1531 #define MAX_ATTRIBS 16
1532 #define MAX_CONST_I 16
1533 #define MAX_CONST_B 16
1535 /* FIXME: This needs to go up to 2048 for
1536 * Shader model 3 according to msdn (and for software shaders) */
1537 #define MAX_LABELS 16
1539 typedef struct semantic
{
1544 typedef struct local_constant
{
1550 typedef struct shader_reg_maps
{
1552 char texcoord
[MAX_REG_TEXCRD
]; /* pixel < 3.0 */
1553 char temporary
[MAX_REG_TEMP
]; /* pixel, vertex */
1554 char address
[MAX_REG_ADDR
]; /* vertex */
1555 char packed_input
[MAX_REG_INPUT
]; /* pshader >= 3.0 */
1556 char packed_output
[MAX_REG_OUTPUT
]; /* vertex >= 3.0 */
1557 char attributes
[MAX_ATTRIBS
]; /* vertex */
1558 char labels
[MAX_LABELS
]; /* pixel, vertex */
1560 /* Sampler usage tokens
1561 * Use 0 as default (bit 31 is always 1 on a valid token) */
1562 DWORD samplers
[MAX_SAMPLERS
];
1565 /* Whether or not a loop is used in this shader */
1568 /* Whether or not this shader uses fog */
1573 #define SHADER_PGMSIZE 65535
1574 typedef struct SHADER_BUFFER
{
1577 unsigned int lineNo
;
1581 /* Undocumented opcode controls */
1582 #define INST_CONTROLS_SHIFT 16
1583 #define INST_CONTROLS_MASK 0x00ff0000
1585 typedef enum COMPARISON_TYPE
{
1594 typedef struct SHADER_OPCODE
{
1595 unsigned int opcode
;
1599 CONST UINT num_params
;
1600 SHADER_HANDLER hw_fct
;
1601 SHADER_HANDLER hw_glsl_fct
;
1606 typedef struct SHADER_OPCODE_ARG
{
1607 IWineD3DBaseShader
* shader
;
1608 shader_reg_maps
* reg_maps
;
1609 CONST SHADER_OPCODE
* opcode
;
1616 SHADER_BUFFER
* buffer
;
1617 } SHADER_OPCODE_ARG
;
1619 typedef struct SHADER_LIMITS
{
1620 unsigned int temporary
;
1621 unsigned int texcoord
;
1622 unsigned int sampler
;
1623 unsigned int constant_int
;
1624 unsigned int constant_float
;
1625 unsigned int constant_bool
;
1626 unsigned int address
;
1627 unsigned int packed_output
;
1628 unsigned int packed_input
;
1629 unsigned int attributes
;
1633 /** Keeps track of details for TEX_M#x# shader opcodes which need to
1634 maintain state information between multiple codes */
1635 typedef struct SHADER_PARSE_STATE
{
1636 unsigned int current_row
;
1637 DWORD texcoord_w
[2];
1638 } SHADER_PARSE_STATE
;
1640 /* Base Shader utility functions.
1641 * (may move callers into the same file in the future) */
1642 extern int shader_addline(
1643 SHADER_BUFFER
* buffer
,
1644 const char* fmt
, ...);
1646 extern const SHADER_OPCODE
* shader_get_opcode(
1647 IWineD3DBaseShader
*iface
,
1650 extern void shader_delete_constant_list(
1651 struct list
* clist
);
1653 void delete_glsl_program_entry(IWineD3DDevice
*iface
, struct glsl_shader_prog_link
*entry
);
1655 /* Vertex shader utility functions */
1656 extern BOOL
vshader_get_input(
1657 IWineD3DVertexShader
* iface
,
1658 BYTE usage_req
, BYTE usage_idx_req
,
1659 unsigned int* regnum
);
1661 extern BOOL
vshader_input_is_color(
1662 IWineD3DVertexShader
* iface
,
1663 unsigned int regnum
);
1665 extern HRESULT
allocate_shader_constants(IWineD3DStateBlockImpl
* object
);
1667 /* ARB_[vertex/fragment]_program helper functions */
1668 extern void shader_arb_load_constants(
1669 IWineD3DDevice
* device
,
1670 char usePixelShader
,
1671 char useVertexShader
);
1673 /* ARB shader program Prototypes */
1674 extern void shader_hw_def(SHADER_OPCODE_ARG
*arg
);
1676 /* ARB pixel shader prototypes */
1677 extern void pshader_hw_bem(SHADER_OPCODE_ARG
* arg
);
1678 extern void pshader_hw_cnd(SHADER_OPCODE_ARG
* arg
);
1679 extern void pshader_hw_cmp(SHADER_OPCODE_ARG
* arg
);
1680 extern void pshader_hw_map2gl(SHADER_OPCODE_ARG
* arg
);
1681 extern void pshader_hw_tex(SHADER_OPCODE_ARG
* arg
);
1682 extern void pshader_hw_texcoord(SHADER_OPCODE_ARG
* arg
);
1683 extern void pshader_hw_texreg2ar(SHADER_OPCODE_ARG
* arg
);
1684 extern void pshader_hw_texreg2gb(SHADER_OPCODE_ARG
* arg
);
1685 extern void pshader_hw_texbem(SHADER_OPCODE_ARG
* arg
);
1686 extern void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG
* arg
);
1687 extern void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG
* arg
);
1688 extern void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG
* arg
);
1689 extern void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG
* arg
);
1690 extern void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG
* arg
);
1691 extern void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG
* arg
);
1693 /* ARB vertex shader prototypes */
1694 extern void vshader_hw_map2gl(SHADER_OPCODE_ARG
* arg
);
1695 extern void vshader_hw_mnxn(SHADER_OPCODE_ARG
* arg
);
1696 extern void vshader_hw_rsq_rcp(SHADER_OPCODE_ARG
* arg
);
1698 /* GLSL helper functions */
1699 extern void shader_glsl_add_instruction_modifiers(SHADER_OPCODE_ARG
*arg
);
1700 extern void shader_glsl_load_constants(
1701 IWineD3DDevice
* device
,
1702 char usePixelShader
,
1703 char useVertexShader
);
1705 /** The following translate DirectX pixel/vertex shader opcodes to GLSL lines */
1706 extern void shader_glsl_cross(SHADER_OPCODE_ARG
* arg
);
1707 extern void shader_glsl_map2gl(SHADER_OPCODE_ARG
* arg
);
1708 extern void shader_glsl_arith(SHADER_OPCODE_ARG
* arg
);
1709 extern void shader_glsl_mov(SHADER_OPCODE_ARG
* arg
);
1710 extern void shader_glsl_mad(SHADER_OPCODE_ARG
* arg
);
1711 extern void shader_glsl_mnxn(SHADER_OPCODE_ARG
* arg
);
1712 extern void shader_glsl_lrp(SHADER_OPCODE_ARG
* arg
);
1713 extern void shader_glsl_dot(SHADER_OPCODE_ARG
* arg
);
1714 extern void shader_glsl_rcp(SHADER_OPCODE_ARG
* arg
);
1715 extern void shader_glsl_cnd(SHADER_OPCODE_ARG
* arg
);
1716 extern void shader_glsl_compare(SHADER_OPCODE_ARG
* arg
);
1717 extern void shader_glsl_def(SHADER_OPCODE_ARG
* arg
);
1718 extern void shader_glsl_defi(SHADER_OPCODE_ARG
* arg
);
1719 extern void shader_glsl_defb(SHADER_OPCODE_ARG
* arg
);
1720 extern void shader_glsl_expp(SHADER_OPCODE_ARG
* arg
);
1721 extern void shader_glsl_cmp(SHADER_OPCODE_ARG
* arg
);
1722 extern void shader_glsl_lit(SHADER_OPCODE_ARG
* arg
);
1723 extern void shader_glsl_dst(SHADER_OPCODE_ARG
* arg
);
1724 extern void shader_glsl_sincos(SHADER_OPCODE_ARG
* arg
);
1725 extern void shader_glsl_loop(SHADER_OPCODE_ARG
* arg
);
1726 extern void shader_glsl_end(SHADER_OPCODE_ARG
* arg
);
1727 extern void shader_glsl_if(SHADER_OPCODE_ARG
* arg
);
1728 extern void shader_glsl_ifc(SHADER_OPCODE_ARG
* arg
);
1729 extern void shader_glsl_else(SHADER_OPCODE_ARG
* arg
);
1730 extern void shader_glsl_break(SHADER_OPCODE_ARG
* arg
);
1731 extern void shader_glsl_breakc(SHADER_OPCODE_ARG
* arg
);
1732 extern void shader_glsl_rep(SHADER_OPCODE_ARG
* arg
);
1733 extern void shader_glsl_call(SHADER_OPCODE_ARG
* arg
);
1734 extern void shader_glsl_callnz(SHADER_OPCODE_ARG
* arg
);
1735 extern void shader_glsl_label(SHADER_OPCODE_ARG
* arg
);
1736 extern void shader_glsl_pow(SHADER_OPCODE_ARG
* arg
);
1738 /** GLSL Pixel Shader Prototypes */
1739 extern void pshader_glsl_tex(SHADER_OPCODE_ARG
* arg
);
1740 extern void pshader_glsl_texcoord(SHADER_OPCODE_ARG
* arg
);
1741 extern void pshader_glsl_texdp3tex(SHADER_OPCODE_ARG
* arg
);
1742 extern void pshader_glsl_texdp3(SHADER_OPCODE_ARG
* arg
);
1743 extern void pshader_glsl_texdepth(SHADER_OPCODE_ARG
* arg
);
1744 extern void pshader_glsl_texm3x2depth(SHADER_OPCODE_ARG
* arg
);
1745 extern void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG
* arg
);
1746 extern void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG
* arg
);
1747 extern void pshader_glsl_texm3x3(SHADER_OPCODE_ARG
* arg
);
1748 extern void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG
* arg
);
1749 extern void pshader_glsl_texm3x3tex(SHADER_OPCODE_ARG
* arg
);
1750 extern void pshader_glsl_texm3x3spec(SHADER_OPCODE_ARG
* arg
);
1751 extern void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG
* arg
);
1752 extern void pshader_glsl_texkill(SHADER_OPCODE_ARG
* arg
);
1753 extern void pshader_glsl_texbem(SHADER_OPCODE_ARG
* arg
);
1754 extern void pshader_glsl_bem(SHADER_OPCODE_ARG
* arg
);
1755 extern void pshader_glsl_texreg2ar(SHADER_OPCODE_ARG
* arg
);
1756 extern void pshader_glsl_texreg2gb(SHADER_OPCODE_ARG
* arg
);
1757 extern void pshader_glsl_texreg2rgb(SHADER_OPCODE_ARG
* arg
);
1758 extern void pshader_glsl_dp2add(SHADER_OPCODE_ARG
* arg
);
1759 extern void pshader_glsl_input_pack(
1760 SHADER_BUFFER
* buffer
,
1761 semantic
* semantics_out
);
1763 /** GLSL Vertex Shader Prototypes */
1764 extern void vshader_glsl_output_unpack(
1765 SHADER_BUFFER
* buffer
,
1766 semantic
* semantics_out
);
1768 /*****************************************************************************
1769 * IDirect3DBaseShader implementation structure
1771 typedef struct IWineD3DBaseShaderClass
1774 SHADER_LIMITS limits
;
1775 SHADER_PARSE_STATE parse_state
;
1776 CONST SHADER_OPCODE
*shader_ins
;
1777 CONST DWORD
*function
;
1778 UINT functionLength
;
1782 /* Type of shader backend */
1785 /* Programs this shader is linked with */
1786 struct list linked_programs
;
1788 /* Immediate constants (override global ones) */
1789 struct list constantsB
;
1790 struct list constantsF
;
1791 struct list constantsI
;
1792 shader_reg_maps reg_maps
;
1794 /* Pointer to the parent device */
1795 IWineD3DDevice
*device
;
1797 } IWineD3DBaseShaderClass
;
1799 typedef struct IWineD3DBaseShaderImpl
{
1801 const IWineD3DBaseShaderVtbl
*lpVtbl
;
1804 /* IWineD3DBaseShader */
1805 IWineD3DBaseShaderClass baseShader
;
1806 } IWineD3DBaseShaderImpl
;
1808 extern HRESULT
shader_get_registers_used(
1809 IWineD3DBaseShader
*iface
,
1810 shader_reg_maps
* reg_maps
,
1811 semantic
* semantics_in
,
1812 semantic
* semantics_out
,
1813 CONST DWORD
* pToken
,
1814 IWineD3DStateBlockImpl
*stateBlock
);
1816 extern void shader_generate_glsl_declarations(
1817 IWineD3DBaseShader
*iface
,
1818 shader_reg_maps
* reg_maps
,
1819 SHADER_BUFFER
* buffer
,
1820 WineD3D_GL_Info
* gl_info
);
1822 extern void shader_generate_arb_declarations(
1823 IWineD3DBaseShader
*iface
,
1824 shader_reg_maps
* reg_maps
,
1825 SHADER_BUFFER
* buffer
,
1826 WineD3D_GL_Info
* gl_info
);
1828 extern void shader_generate_main(
1829 IWineD3DBaseShader
*iface
,
1830 SHADER_BUFFER
* buffer
,
1831 shader_reg_maps
* reg_maps
,
1832 CONST DWORD
* pFunction
);
1834 extern void shader_dump_ins_modifiers(
1835 const DWORD output
);
1837 extern void shader_dump_param(
1838 IWineD3DBaseShader
*iface
,
1840 const DWORD addr_token
,
1843 extern void shader_trace_init(
1844 IWineD3DBaseShader
*iface
,
1845 const DWORD
* pFunction
);
1847 extern int shader_get_param(
1848 IWineD3DBaseShader
* iface
,
1849 const DWORD
* pToken
,
1853 extern int shader_skip_unrecognized(
1854 IWineD3DBaseShader
* iface
,
1855 const DWORD
* pToken
);
1857 extern void print_glsl_info_log(
1858 WineD3D_GL_Info
*gl_info
,
1861 static inline int shader_get_regtype(const DWORD param
) {
1862 return (((param
& WINED3DSP_REGTYPE_MASK
) >> WINED3DSP_REGTYPE_SHIFT
) |
1863 ((param
& WINED3DSP_REGTYPE_MASK2
) >> WINED3DSP_REGTYPE_SHIFT2
));
1866 extern unsigned int shader_get_float_offset(const DWORD reg
);
1868 static inline BOOL
shader_is_pshader_version(DWORD token
) {
1869 return 0xFFFF0000 == (token
& 0xFFFF0000);
1872 static inline BOOL
shader_is_vshader_version(DWORD token
) {
1873 return 0xFFFE0000 == (token
& 0xFFFF0000);
1876 static inline BOOL
shader_is_comment(DWORD token
) {
1877 return WINED3DSIO_COMMENT
== (token
& WINED3DSI_OPCODE_MASK
);
1880 /* TODO: vFace (ps_3_0) */
1881 static inline BOOL
shader_is_scalar(DWORD param
) {
1882 DWORD reg_type
= shader_get_regtype(param
);
1885 case WINED3DSPR_RASTOUT
:
1886 if ((param
& WINED3DSP_REGNUM_MASK
) != 0) {
1893 case WINED3DSPR_DEPTHOUT
: /* oDepth */
1894 case WINED3DSPR_CONSTBOOL
: /* b# */
1895 case WINED3DSPR_LOOP
: /* aL */
1896 case WINED3DSPR_PREDICATE
: /* p0 */
1904 /* Internally used shader constants. Applications can use constants 0 to GL_LIMITS(vshader_constantsF) - 1,
1905 * so upload them above that
1907 #define ARB_SHADER_PRIVCONST_BASE GL_LIMITS(vshader_constantsF)
1908 #define ARB_SHADER_PRIVCONST_POS ARB_SHADER_PRIVCONST_BASE + 0
1910 /*****************************************************************************
1911 * IDirect3DVertexShader implementation structure
1913 typedef struct IWineD3DVertexShaderImpl
{
1915 const IWineD3DVertexShaderVtbl
*lpVtbl
;
1916 LONG ref
; /* Note: Ref counting not required */
1918 /* IWineD3DBaseShader */
1919 IWineD3DBaseShaderClass baseShader
;
1921 /* IWineD3DVertexShaderImpl */
1926 /* Vertex shader input and output semantics */
1927 semantic semantics_in
[MAX_ATTRIBS
];
1928 semantic semantics_out
[MAX_REG_OUTPUT
];
1930 /* run time datas... */
1932 #if 0 /* needs reworking */
1933 /* run time datas */
1934 VSHADERINPUTDATA input
;
1935 VSHADEROUTPUTDATA output
;
1937 } IWineD3DVertexShaderImpl
;
1938 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins
[];
1939 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl
;
1941 /*****************************************************************************
1942 * IDirect3DPixelShader implementation structure
1944 typedef struct IWineD3DPixelShaderImpl
{
1945 /* IUnknown parts */
1946 const IWineD3DPixelShaderVtbl
*lpVtbl
;
1947 LONG ref
; /* Note: Ref counting not required */
1949 /* IWineD3DBaseShader */
1950 IWineD3DBaseShaderClass baseShader
;
1952 /* IWineD3DPixelShaderImpl */
1955 /* Pixel shader input semantics */
1956 semantic semantics_in
[MAX_REG_INPUT
];
1961 /* Some information about the shader behavior */
1963 UINT bumpenvmatconst
;
1965 #if 0 /* needs reworking */
1966 PSHADERINPUTDATA input
;
1967 PSHADEROUTPUTDATA output
;
1969 } IWineD3DPixelShaderImpl
;
1971 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins
[];
1972 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl
;
1974 /*****************************************************************************
1975 * IWineD3DPalette implementation structure
1977 struct IWineD3DPaletteImpl
{
1978 /* IUnknown parts */
1979 const IWineD3DPaletteVtbl
*lpVtbl
;
1983 IWineD3DDeviceImpl
*wineD3DDevice
;
1985 /* IWineD3DPalette */
1987 WORD palVersion
; /*| */
1988 WORD palNumEntries
; /*| LOGPALETTE */
1989 PALETTEENTRY palents
[256]; /*| */
1990 /* This is to store the palette in 'screen format' */
1991 int screen_palents
[256];
1995 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl
;
1996 DWORD
IWineD3DPaletteImpl_Size(DWORD dwFlags
);
1998 /* DirectDraw utility functions */
1999 extern WINED3DFORMAT
pixelformat_for_depth(DWORD depth
);
2001 /*****************************************************************************
2002 * Pixel format management
2005 WINED3DFORMAT format
;
2006 DWORD alphaMask
, redMask
, greenMask
, blueMask
;
2009 GLint glInternal
, glGammaInternal
, glFormat
, glType
;
2012 const PixelFormatDesc
*getFormatDescEntry(WINED3DFORMAT fmt
);
2014 static inline BOOL
use_vs(IWineD3DDeviceImpl
*device
) {
2015 return (device
->vs_selected_mode
!= SHADER_NONE
2016 && device
->stateBlock
->vertexShader
2017 && ((IWineD3DVertexShaderImpl
*)device
->stateBlock
->vertexShader
)->baseShader
.function
2018 && !device
->strided_streams
.u
.s
.position_transformed
);
2021 static inline BOOL
use_ps(IWineD3DDeviceImpl
*device
) {
2022 return (device
->ps_selected_mode
!= SHADER_NONE
2023 && device
->stateBlock
->pixelShader
2024 && ((IWineD3DPixelShaderImpl
*)device
->stateBlock
->pixelShader
)->baseShader
.function
);
2027 void stretch_rect_fbo(IWineD3DDevice
*iface
, IWineD3DSurface
*src_surface
, WINED3DRECT
*src_rect
,
2028 IWineD3DSurface
*dst_surface
, WINED3DRECT
*dst_rect
, WINED3DTEXTUREFILTERTYPE filter
, BOOL flip
);