wined3d: DDraw surfaces are QWORD aligned.
[wine.git] / dlls / wined3d / wined3d_private.h
blob8549232de60597938d4ff42662ceb8d1f9c78c9b
1 /*
2 * Direct3D wine internal private include file
4 * Copyright 2002-2003 The wine-d3d team
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2004 Jason Edmeades
7 * Copyright 2005 Oliver Stieber
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #ifndef __WINE_WINED3D_PRIVATE_H
25 #define __WINE_WINED3D_PRIVATE_H
27 #include <stdarg.h>
28 #include <math.h>
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
31 #define COBJMACROS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winreg.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
40 #include "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);
50 typedef struct {
51 void *key;
52 void *value;
53 unsigned int hash;
54 struct list entry;
55 } hash_table_entry_t;
57 typedef struct {
58 hash_function_t *hash_function;
59 compare_function_t *compare_function;
60 struct list *buckets;
61 unsigned int bucket_count;
62 hash_table_entry_t *entries;
63 unsigned int entry_count;
64 struct list free_entries;
65 unsigned int count;
66 unsigned int grow_size;
67 unsigned int shrink_size;
68 } hash_table_t;
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);
76 /* Device caps */
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,
106 MAX_LOOKUPS = 2
107 } WINELOOKUP;
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 {
116 int d3dType;
117 GLint size;
118 GLenum glType;
119 GLboolean normalized;
120 int typesize;
121 } WINED3DGLTYPE;
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
150 * Settings
152 #define VS_NONE 0
153 #define VS_HW 1
155 #define PS_NONE 0
156 #define PS_HW 1
158 #define VBO_NONE 0
159 #define VBO_HW 1
161 #define NP2_NONE 0
162 #define NP2_REPACK 1
163 #define NP2_NATIVE 2
165 #define ORM_BACKBUFFER 0
166 #define ORM_PBUFFER 1
167 #define ORM_FBO 2
169 #define SHADER_ARB 1
170 #define SHADER_GLSL 2
171 #define SHADER_NONE 3
173 #define RTL_DISABLE -1
174 #define RTL_AUTO 0
175 #define RTL_READDRAW 1
176 #define RTL_READTEX 2
177 #define RTL_TEXDRAW 3
178 #define RTL_TEXTEX 4
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 */
184 int vs_mode;
185 int ps_mode;
186 int vbo_mode;
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. */
190 BOOL glslRequested;
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 */
201 typedef struct {
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);
206 } shader_backend_t;
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;
212 /* X11 locking */
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 */
218 extern int num_lock;
220 #if 0
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()
223 #else
224 #define ENTER_GL() wine_tsx11_lock_ptr()
225 #define LEAVE_GL() wine_tsx11_unlock_ptr()
226 #endif
228 /*****************************************************************************
229 * Defines
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__); \
274 } else do { \
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) \
286 do { \
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)); \
292 } while (0)
294 /* Macro to dump out the current state of the light chain */
295 #define DUMP_LIGHT_CHAIN() \
297 PLIGHTINFOEL *el = This->stateBlock->lights;\
298 while (el) { \
299 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
300 el = el->next; \
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;
321 /* Tracking */
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
348 #else
349 # define VTRACE(A)
350 #endif
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__)); \
360 } else do { \
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
377 # endif
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
381 array is drawn. */
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
384 # endif
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
391 # endif
392 extern BOOL isOn;
393 extern BOOL isDumpingFrames;
394 extern LONG primCounter;
395 #endif
397 /*****************************************************************************
398 * Prototypes
401 /* Routine common to the draw primitive and draw indexed primitive routines */
402 void drawPrimitive(IWineD3DDevice *iface,
403 int PrimitiveType,
404 long NumPrimitives,
405 /* for Indexed: */
406 long StartVertexIndex,
407 UINT numberOfVertices,
408 long StartIdx,
409 short idxBytes,
410 const void *idxData,
411 int minIndex);
413 void primitiveConvertToStridedData(IWineD3DDevice *iface, WineDirect3DVertexStridedData *strided, BOOL *fixup);
415 void primitiveDeclarationConvertToStridedData(
416 IWineD3DDevice *iface,
417 BOOL useVertexShaderFunction,
418 WineDirect3DVertexStridedData *strided,
419 BOOL *fixup);
421 void primitiveConvertFVFtoOffset(DWORD thisFVF,
422 DWORD stride,
423 BYTE *data,
424 WineDirect3DVertexStridedData *strided,
425 GLint streamVBO,
426 UINT streamNo);
428 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
430 void blt_to_drawable(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *surface);
432 #define eps 1e-8
434 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
435 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
437 /* Routines and structures related to state management */
438 typedef struct WineD3DContext WineD3DContext;
439 typedef void (*APPLYSTATEFUNC)(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *ctx);
441 #define STATE_RENDER(a) (a)
442 #define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
444 #define STATE_TEXTURESTAGE(stage, num) (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + (stage) * WINED3D_HIGHEST_TEXTURE_STATE + (num))
445 #define STATE_IS_TEXTURESTAGE(a) ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
447 /* + 1 because samplers start with 0 */
448 #define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
449 #define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(MAX_SAMPLERS - 1))
451 #define STATE_PIXELSHADER (STATE_SAMPLER(MAX_SAMPLERS - 1) + 1)
452 #define STATE_IS_PIXELSHADER(a) ((a) == STATE_PIXELSHADER)
454 #define STATE_TRANSFORM(a) (STATE_PIXELSHADER + (a))
455 #define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)))
457 #define STATE_STREAMSRC (STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)) + 1)
458 #define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
459 #define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
460 #define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
462 #define STATE_VDECL (STATE_INDEXBUFFER + 1)
463 #define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
465 #define STATE_VSHADER (STATE_VDECL + 1)
466 #define STATE_IS_VSHADER(a) ((a) == STATE_VSHADER)
468 #define STATE_VIEWPORT (STATE_VSHADER + 1)
469 #define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
471 #define STATE_VERTEXSHADERCONSTANT (STATE_VIEWPORT + 1)
472 #define STATE_PIXELSHADERCONSTANT (STATE_VERTEXSHADERCONSTANT + 1)
473 #define STATE_IS_VERTEXSHADERCONSTANT(a) ((a) == STATE_VERTEXSHADERCONSTANT)
474 #define STATE_IS_PIXELSHADERCONSTANT(a) ((a) == STATE_PIXELSHADERCONSTANT)
476 #define STATE_ACTIVELIGHT(a) (STATE_PIXELSHADERCONSTANT + (a) + 1)
477 #define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_PIXELSHADERCONSTANT(MAX_ACTIVE_LIGHTS))
479 #define STATE_SCISSORRECT (STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS - 1) + 1)
480 #define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
482 #define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
483 #define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(MAX_CLIPPLANES - 1))
485 #define STATE_HIGHEST (STATE_CLIPPLANE(MAX_CLIPPLANES - 1))
487 struct StateEntry
489 DWORD representative;
490 APPLYSTATEFUNC apply;
493 /* Global state table */
494 extern const struct StateEntry StateTable[];
496 /* The new context manager that should deal with onscreen and offscreen rendering */
497 struct WineD3DContext {
498 /* State dirtification
499 * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices
500 * 0...numDirtyEntries - 1. isStateDirty is a redundant copy of the dirtyArray. Technically only one of them would be needed,
501 * 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
502 * only numDirtyEntries array elements have to be checked, not STATE_HIGHEST states.
504 DWORD dirtyArray[STATE_HIGHEST + 1]; /* Won't get bigger than that, a state is never marked dirty 2 times */
505 DWORD numDirtyEntries;
506 DWORD isStateDirty[STATE_HIGHEST/32 + 1]; /* Bitmap to find out quickly if a state is dirty */
508 IWineD3DSurface *surface;
509 DWORD tid; /* Thread ID which owns this context at the moment */
511 /* Stores some inforation about the context state for optimization */
512 BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
513 BOOL last_was_pshader;
514 BOOL last_was_vshader;
515 BOOL last_was_foggy_shader;
516 BOOL namedArraysLoaded, numberedArraysLoaded;
517 BOOL lastWasPow2Texture[MAX_TEXTURES];
518 GLenum tracking_parm; /* Which source is tracking current colour */
519 BOOL last_was_blit, last_was_ckey;
520 char texShaderBumpMap;
522 /* The actual opengl context */
523 GLXContext glCtx;
524 Drawable drawable;
525 Display *display;
526 BOOL isPBuffer;
529 typedef enum ContextUsage {
530 CTXUSAGE_RESOURCELOAD = 1, /* Only loads textures: No State is applied */
531 CTXUSAGE_DRAWPRIM = 2, /* OpenGL states are set up for blitting DirectDraw surfacs */
532 CTXUSAGE_BLIT = 3, /* OpenGL states are set up 3D drawing */
533 } ContextUsage;
535 void ActivateContext(IWineD3DDeviceImpl *device, IWineD3DSurface *target, ContextUsage usage);
536 WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, Display *display, Window win);
537 void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context);
538 void apply_fbo_state(IWineD3DDevice *iface);
540 /* Macros for doing basic GPU detection based on opengl capabilities */
541 #define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
542 #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])
543 #define WINE_D3D8_CAPABLE(gl_info) WINE_D3D7_CAPABLE(gl_info) && (gl_info->supported[ARB_MULTISAMPLE] && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
544 #define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER])
546 /* Default callbacks for implicit object destruction */
547 extern ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface);
549 extern ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pSurface);
551 /*****************************************************************************
552 * Internal representation of a light
554 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
555 struct PLIGHTINFOEL {
556 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
557 DWORD OriginalIndex;
558 LONG glIndex;
559 BOOL changed;
560 BOOL enabledChanged;
562 /* Converted parms to speed up swapping lights */
563 float lightPosn[4];
564 float lightDirn[4];
565 float exponent;
566 float cutoff;
568 struct list entry;
571 /* The default light parameters */
572 extern const WINED3DLIGHT WINED3D_default_light;
574 /* The adapter structure */
575 struct WineD3DAdapter
577 POINT monitorPoint;
578 Display *display;
579 WineD3D_GL_Info gl_info;
580 const char *driver;
581 const char *description;
582 GLXFBConfig *cfgs;
583 int nCfgs;
586 extern BOOL InitAdapters(void);
588 /*****************************************************************************
589 * IWineD3D implementation structure
591 typedef struct IWineD3DImpl
593 /* IUnknown fields */
594 const IWineD3DVtbl *lpVtbl;
595 LONG ref; /* Note: Ref counting not required */
597 /* WineD3D Information */
598 IUnknown *parent;
599 UINT dxVersion;
600 } IWineD3DImpl;
602 extern const IWineD3DVtbl IWineD3D_Vtbl;
604 /* TODO: setup some flags in the registry to enable, disable pbuffer support
605 (since it will break quite a few things until contexts are managed properly!) */
606 extern BOOL pbuffer_support;
607 /* allocate one pbuffer per surface */
608 extern BOOL pbuffer_per_surface;
610 typedef struct ResourceList {
611 IWineD3DResource *resource;
612 struct ResourceList *next;
613 } ResourceList;
615 /* A helper function that dumps a resource list */
616 void dumpResources(ResourceList *resources);
618 /*****************************************************************************
619 * IWineD3DDevice implementation structure
621 struct IWineD3DDeviceImpl
623 /* IUnknown fields */
624 const IWineD3DDeviceVtbl *lpVtbl;
625 LONG ref; /* Note: Ref counting not required */
627 /* WineD3D Information */
628 IUnknown *parent;
629 IWineD3D *wineD3D;
630 struct WineD3DAdapter *adapter;
632 /* Window styles to restore when switching fullscreen mode */
633 LONG style;
634 LONG exStyle;
636 /* X and GL Information */
637 GLint maxConcurrentLights;
638 GLenum offscreenBuffer;
640 /* Selected capabilities */
641 int vs_selected_mode;
642 int ps_selected_mode;
643 const shader_backend_t *shader_backend;
644 hash_table_t *glsl_program_lookup;
646 /* To store */
647 BOOL view_ident; /* true iff view matrix is identity */
648 BOOL untransformed;
649 BOOL vertexBlendUsed; /* To avoid needless setting of the blend matrices */
650 unsigned char surface_alignment; /* Line Alignment of surfaces */
652 /* State block related */
653 BOOL isRecordingState;
654 IWineD3DStateBlockImpl *stateBlock;
655 IWineD3DStateBlockImpl *updateStateBlock;
656 BOOL isInDraw;
658 /* Internal use fields */
659 WINED3DDEVICE_CREATION_PARAMETERS createParms;
660 UINT adapterNo;
661 WINED3DDEVTYPE devType;
663 IWineD3DSwapChain **swapchains;
664 uint NumberOfSwapChains;
666 ResourceList *resources; /* a linked list to track resources created by the device */
668 /* Render Target Support */
669 IWineD3DSurface **render_targets;
670 IWineD3DSurface *depthStencilBuffer;
671 IWineD3DSurface **fbo_color_attachments;
672 IWineD3DSurface *fbo_depth_attachment;
674 IWineD3DSurface *stencilBufferTarget;
676 /* Caches to avoid unneeded context changes */
677 IWineD3DSurface *lastActiveRenderTarget;
678 IWineD3DSwapChain *lastActiveSwapChain;
680 /* palettes texture management */
681 PALETTEENTRY palettes[MAX_PALETTES][256];
682 UINT currentPalette;
684 /* For rendering to a texture using glCopyTexImage */
685 BOOL render_offscreen;
686 WINED3D_DEPTHCOPYSTATE depth_copy_state;
687 GLuint fbo;
688 GLuint src_fbo;
689 GLuint dst_fbo;
690 GLenum *draw_buffers;
692 /* Cursor management */
693 BOOL bCursorVisible;
694 UINT xHotSpot;
695 UINT yHotSpot;
696 UINT xScreenSpace;
697 UINT yScreenSpace;
698 UINT cursorWidth, cursorHeight;
699 GLuint cursorTexture;
700 BOOL haveHardwareCursor;
701 HCURSOR hardwareCursor;
703 /* Textures for when no other textures are mapped */
704 UINT dummyTextureName[MAX_TEXTURES];
706 /* Debug stream management */
707 BOOL debug;
709 /* Device state management */
710 HRESULT state;
711 BOOL d3d_initialized;
713 /* A flag to check for proper BeginScene / EndScene call pairs */
714 BOOL inScene;
716 /* process vertex shaders using software or hardware */
717 BOOL softwareVertexProcessing;
719 /* DirectDraw stuff */
720 HWND ddraw_window;
721 IWineD3DSurface *ddraw_primary;
722 DWORD ddraw_width, ddraw_height;
723 WINED3DFORMAT ddraw_format;
724 BOOL ddraw_fullscreen;
726 /* Final position fixup constant */
727 float posFixup[4];
729 /* With register combiners we can skip junk texture stages */
730 DWORD texUnitMap[MAX_SAMPLERS];
731 BOOL oneToOneTexUnitMap;
733 /* Stream source management */
734 WineDirect3DVertexStridedData strided_streams;
735 WineDirect3DVertexStridedData *up_strided;
736 BOOL useDrawStridedSlow;
737 BOOL instancedDraw;
739 /* Context management */
740 WineD3DContext **contexts; /* Dynamic array containing pointers to context structures */
741 WineD3DContext *activeContext; /* Only 0 for now */
742 UINT numContexts; /* Always 1 for now */
743 WineD3DContext *pbufferContext; /* The context that has a pbuffer as drawable */
744 DWORD pbufferWidth, pbufferHeight; /* Size of the buffer drawable */
747 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
749 void IWineD3DDeviceImpl_FindTexUnitMap(IWineD3DDeviceImpl *This);
750 void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state);
751 static inline BOOL isStateDirty(WineD3DContext *context, DWORD state) {
752 DWORD idx = state >> 5;
753 BYTE shift = state & 0x1f;
754 return context->isStateDirty[idx] & (1 << shift);
757 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. */
758 typedef struct PrivateData
760 struct list entry;
762 GUID tag;
763 DWORD flags; /* DDSPD_* */
764 DWORD uniqueness_value;
766 union
768 LPVOID data;
769 LPUNKNOWN object;
770 } ptr;
772 DWORD size;
773 } PrivateData;
775 /*****************************************************************************
776 * IWineD3DResource implementation structure
778 typedef struct IWineD3DResourceClass
780 /* IUnknown fields */
781 LONG ref; /* Note: Ref counting not required */
783 /* WineD3DResource Information */
784 IUnknown *parent;
785 WINED3DRESOURCETYPE resourceType;
786 IWineD3DDeviceImpl *wineD3DDevice;
787 WINED3DPOOL pool;
788 UINT size;
789 DWORD usage;
790 WINED3DFORMAT format;
791 BYTE *allocatedMemory;
792 struct list privateData;
794 } IWineD3DResourceClass;
796 typedef struct IWineD3DResourceImpl
798 /* IUnknown & WineD3DResource Information */
799 const IWineD3DResourceVtbl *lpVtbl;
800 IWineD3DResourceClass resource;
801 } IWineD3DResourceImpl;
804 /*****************************************************************************
805 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
807 typedef struct IWineD3DVertexBufferImpl
809 /* IUnknown & WineD3DResource Information */
810 const IWineD3DVertexBufferVtbl *lpVtbl;
811 IWineD3DResourceClass resource;
813 /* WineD3DVertexBuffer specifics */
814 DWORD fvf;
816 /* Vertex buffer object support */
817 GLuint vbo;
818 BYTE Flags;
819 LONG bindCount;
821 UINT dirtystart, dirtyend;
822 LONG lockcount;
824 LONG declChanges, draws;
825 /* Last description of the buffer */
826 WineDirect3DVertexStridedData strided;
827 } IWineD3DVertexBufferImpl;
829 extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
831 #define VBFLAG_LOAD 0x01 /* Data is written from allocatedMemory to the VBO */
832 #define VBFLAG_OPTIMIZED 0x02 /* Optimize has been called for the VB */
833 #define VBFLAG_DIRTY 0x04 /* Buffer data has been modified */
834 #define VBFLAG_HASDESC 0x08 /* A vertex description has been found */
835 #define VBFLAG_VBOCREATEFAIL 0x10 /* An attempt to create a vbo has failed */
837 /*****************************************************************************
838 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
840 typedef struct IWineD3DIndexBufferImpl
842 /* IUnknown & WineD3DResource Information */
843 const IWineD3DIndexBufferVtbl *lpVtbl;
844 IWineD3DResourceClass resource;
846 GLuint vbo;
847 UINT dirtystart, dirtyend;
848 LONG lockcount;
850 /* WineD3DVertexBuffer specifics */
851 } IWineD3DIndexBufferImpl;
853 extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
855 /*****************************************************************************
856 * IWineD3DBaseTexture D3D- > openGL state map lookups
858 #define WINED3DFUNC_NOTSUPPORTED -2
859 #define WINED3DFUNC_UNIMPLEMENTED -1
861 typedef enum winetexturestates {
862 WINED3DTEXSTA_ADDRESSU = 0,
863 WINED3DTEXSTA_ADDRESSV = 1,
864 WINED3DTEXSTA_ADDRESSW = 2,
865 WINED3DTEXSTA_BORDERCOLOR = 3,
866 WINED3DTEXSTA_MAGFILTER = 4,
867 WINED3DTEXSTA_MINFILTER = 5,
868 WINED3DTEXSTA_MIPFILTER = 6,
869 WINED3DTEXSTA_MAXMIPLEVEL = 7,
870 WINED3DTEXSTA_MAXANISOTROPY = 8,
871 WINED3DTEXSTA_SRGBTEXTURE = 9,
872 WINED3DTEXSTA_ELEMENTINDEX = 10,
873 WINED3DTEXSTA_DMAPOFFSET = 11,
874 WINED3DTEXSTA_TSSADDRESSW = 12,
875 MAX_WINETEXTURESTATES = 13,
876 } winetexturestates;
878 typedef struct Wined3dTextureStateMap {
879 CONST int state;
880 int function;
881 } Wined3dTextureStateMap;
883 /*****************************************************************************
884 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
886 typedef struct IWineD3DBaseTextureClass
888 UINT levels;
889 BOOL dirty;
890 UINT textureName;
891 UINT LOD;
892 WINED3DTEXTUREFILTERTYPE filterType;
893 DWORD states[MAX_WINETEXTURESTATES];
894 LONG bindCount;
895 DWORD sampler;
896 BOOL is_srgb;
897 UINT srgb_mode_change_count;
898 } IWineD3DBaseTextureClass;
900 typedef struct IWineD3DBaseTextureImpl
902 /* IUnknown & WineD3DResource Information */
903 const IWineD3DBaseTextureVtbl *lpVtbl;
904 IWineD3DResourceClass resource;
905 IWineD3DBaseTextureClass baseTexture;
907 } IWineD3DBaseTextureImpl;
909 /*****************************************************************************
910 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
912 typedef struct IWineD3DTextureImpl
914 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
915 const IWineD3DTextureVtbl *lpVtbl;
916 IWineD3DResourceClass resource;
917 IWineD3DBaseTextureClass baseTexture;
919 /* IWineD3DTexture */
920 IWineD3DSurface *surfaces[MAX_LEVELS];
922 UINT width;
923 UINT height;
924 float pow2scalingFactorX;
925 float pow2scalingFactorY;
927 } IWineD3DTextureImpl;
929 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
931 /*****************************************************************************
932 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
934 typedef struct IWineD3DCubeTextureImpl
936 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
937 const IWineD3DCubeTextureVtbl *lpVtbl;
938 IWineD3DResourceClass resource;
939 IWineD3DBaseTextureClass baseTexture;
941 /* IWineD3DCubeTexture */
942 IWineD3DSurface *surfaces[6][MAX_LEVELS];
944 UINT edgeLength;
945 float pow2scalingFactor;
947 } IWineD3DCubeTextureImpl;
949 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
951 typedef struct _WINED3DVOLUMET_DESC
953 UINT Width;
954 UINT Height;
955 UINT Depth;
956 } WINED3DVOLUMET_DESC;
958 /*****************************************************************************
959 * IWineD3DVolume implementation structure (extends IUnknown)
961 typedef struct IWineD3DVolumeImpl
963 /* IUnknown & WineD3DResource fields */
964 const IWineD3DVolumeVtbl *lpVtbl;
965 IWineD3DResourceClass resource;
967 /* WineD3DVolume Information */
968 WINED3DVOLUMET_DESC currentDesc;
969 IWineD3DBase *container;
970 UINT bytesPerPixel;
972 BOOL lockable;
973 BOOL locked;
974 WINED3DBOX lockedBox;
975 WINED3DBOX dirtyBox;
976 BOOL dirty;
979 } IWineD3DVolumeImpl;
981 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
983 /*****************************************************************************
984 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
986 typedef struct IWineD3DVolumeTextureImpl
988 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
989 const IWineD3DVolumeTextureVtbl *lpVtbl;
990 IWineD3DResourceClass resource;
991 IWineD3DBaseTextureClass baseTexture;
993 /* IWineD3DVolumeTexture */
994 IWineD3DVolume *volumes[MAX_LEVELS];
996 UINT width;
997 UINT height;
998 UINT depth;
999 } IWineD3DVolumeTextureImpl;
1001 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
1003 typedef struct _WINED3DSURFACET_DESC
1005 WINED3DMULTISAMPLE_TYPE MultiSampleType;
1006 DWORD MultiSampleQuality;
1007 UINT Width;
1008 UINT Height;
1009 } WINED3DSURFACET_DESC;
1011 /*****************************************************************************
1012 * Structure for DIB Surfaces (GetDC and GDI surfaces)
1014 typedef struct wineD3DSurface_DIB {
1015 HBITMAP DIBsection;
1016 void* bitmap_data;
1017 HGDIOBJ holdbitmap;
1018 BOOL client_memory;
1019 } wineD3DSurface_DIB;
1021 typedef struct {
1022 struct list entry;
1023 GLuint id;
1024 UINT width;
1025 UINT height;
1026 } renderbuffer_entry_t;
1028 /*****************************************************************************
1029 * IWineD3DClipp implementation structure
1031 typedef struct IWineD3DClipperImpl
1033 const IWineD3DClipperVtbl *lpVtbl;
1034 LONG ref;
1036 IUnknown *Parent;
1037 HWND hWnd;
1038 } IWineD3DClipperImpl;
1041 /*****************************************************************************
1042 * IWineD3DSurface implementation structure
1044 struct IWineD3DSurfaceImpl
1046 /* IUnknown & IWineD3DResource Information */
1047 const IWineD3DSurfaceVtbl *lpVtbl;
1048 IWineD3DResourceClass resource;
1050 /* IWineD3DSurface fields */
1051 IWineD3DBase *container;
1052 WINED3DSURFACET_DESC currentDesc;
1053 IWineD3DPaletteImpl *palette; /* D3D7 style palette handling */
1054 PALETTEENTRY *palette9; /* D3D8/9 style palette handling */
1056 UINT bytesPerPixel;
1058 /* TODO: move this off into a management class(maybe!) */
1059 DWORD Flags;
1061 UINT pow2Width;
1062 UINT pow2Height;
1064 /* Oversized texture */
1065 RECT glRect;
1067 #if 0
1068 /* precalculated x and y scalings for texture coords */
1069 float pow2scalingFactorX; /* = (Width / pow2Width ) */
1070 float pow2scalingFactorY; /* = (Height / pow2Height) */
1071 #endif
1073 RECT lockedRect;
1074 RECT dirtyRect;
1075 int lockCount;
1076 #define MAXLOCKCOUNT 50 /* After this amount of locks do not free the sysmem copy */
1078 glDescriptor glDescription;
1080 /* For GetDC */
1081 wineD3DSurface_DIB dib;
1082 HDC hDC;
1084 /* Color keys for DDraw */
1085 WINEDDCOLORKEY DestBltCKey;
1086 WINEDDCOLORKEY DestOverlayCKey;
1087 WINEDDCOLORKEY SrcOverlayCKey;
1088 WINEDDCOLORKEY SrcBltCKey;
1089 DWORD CKeyFlags;
1091 WINEDDCOLORKEY glCKey;
1093 struct list renderbuffers;
1094 renderbuffer_entry_t *current_renderbuffer;
1096 /* DirectDraw clippers */
1097 IWineD3DClipper *clipper;
1100 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
1101 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
1103 /* Predeclare the shared Surface functions */
1104 HRESULT WINAPI IWineD3DSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
1105 ULONG WINAPI IWineD3DSurfaceImpl_AddRef(IWineD3DSurface *iface);
1106 ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface);
1107 HRESULT WINAPI IWineD3DSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
1108 HRESULT WINAPI IWineD3DSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
1109 HRESULT WINAPI IWineD3DSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
1110 HRESULT WINAPI IWineD3DSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
1111 HRESULT WINAPI IWineD3DSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
1112 DWORD WINAPI IWineD3DSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
1113 DWORD WINAPI IWineD3DSurfaceImpl_GetPriority(IWineD3DSurface *iface);
1114 void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface);
1115 WINED3DRESOURCETYPE WINAPI IWineD3DSurfaceImpl_GetType(IWineD3DSurface *iface);
1116 HRESULT WINAPI IWineD3DSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
1117 HRESULT WINAPI IWineD3DSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
1118 HRESULT WINAPI IWineD3DSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
1119 HRESULT WINAPI IWineD3DSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
1120 HRESULT WINAPI IWineD3DSurfaceImpl_IsLost(IWineD3DSurface *iface);
1121 HRESULT WINAPI IWineD3DSurfaceImpl_Restore(IWineD3DSurface *iface);
1122 HRESULT WINAPI IWineD3DSurfaceImpl_SetPixelFormat(IWineD3DSurface *iface, WINED3DFORMAT Format, BYTE *Surface, DWORD Size);
1123 HRESULT WINAPI IWineD3DSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
1124 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
1125 HRESULT WINAPI IWineD3DSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, WINEDDCOLORKEY *CKey);
1126 HRESULT WINAPI IWineD3DSurfaceImpl_CleanDirtyRect(IWineD3DSurface *iface);
1127 extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect);
1128 HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
1129 void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target);
1130 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription);
1131 const void *WINAPI IWineD3DSurfaceImpl_GetData(IWineD3DSurface *iface);
1132 HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
1133 HRESULT WINAPI IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter);
1134 HRESULT WINAPI IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty, IWineD3DSurface *Source, RECT *rsrc, DWORD trans);
1135 HRESULT WINAPI IWineD3DSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
1136 HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC);
1137 HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC);
1138 DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface);
1139 HRESULT WINAPI IWineD3DSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
1140 HRESULT WINAPI IWineD3DSurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem);
1141 HRESULT WINAPI IWineD3DSurfaceImpl_SetOverlayPosition(IWineD3DSurface *iface, LONG X, LONG Y);
1142 HRESULT WINAPI IWineD3DSurfaceImpl_GetOverlayPosition(IWineD3DSurface *iface, LONG *X, LONG *Y);
1143 HRESULT WINAPI IWineD3DSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface *iface, DWORD Flags, IWineD3DSurface *Ref);
1144 HRESULT WINAPI IWineD3DSurfaceImpl_UpdateOverlay(IWineD3DSurface *iface, RECT *SrcRect, IWineD3DSurface *DstSurface, RECT *DstRect, DWORD Flags, WINEDDOVERLAYFX *FX);
1145 HRESULT WINAPI IWineD3DSurfaceImpl_SetClipper(IWineD3DSurface *iface, IWineD3DClipper *clipper);
1146 HRESULT WINAPI IWineD3DSurfaceImpl_GetClipper(IWineD3DSurface *iface, IWineD3DClipper **clipper);
1148 /* Surface flags: */
1149 #define SFLAG_OVERSIZE 0x00000001 /* Surface is bigger than gl size, blts only */
1150 #define SFLAG_CONVERTED 0x00000002 /* Converted for color keying or Palettized */
1151 #define SFLAG_DIBSECTION 0x00000004 /* Has a DIB section attached for getdc */
1152 #define SFLAG_LOCKABLE 0x00000008 /* Surface can be locked */
1153 #define SFLAG_DISCARD 0x00000010 /* ??? */
1154 #define SFLAG_LOCKED 0x00000020 /* Surface is locked atm */
1155 #define SFLAG_INTEXTURE 0x00000040 /* The GL texture contains the newest surface content */
1156 #define SFLAG_INDRAWABLE 0x00000080 /* The gl drawable contains the most up to date data */
1157 #define SFLAG_INSYSMEM 0x00000100 /* The system memory copy is most up to date */
1158 #define SFLAG_NONPOW2 0x00000200 /* Surface sizes are not a power of 2 */
1159 #define SFLAG_DYNLOCK 0x00000400 /* Surface is often locked by the app */
1160 #define SFLAG_DYNCHANGE 0x00000C00 /* Surface contents are changed very often, implies DYNLOCK */
1161 #define SFLAG_DCINUSE 0x00001000 /* Set between GetDC and ReleaseDC calls */
1162 #define SFLAG_LOST 0x00002000 /* Surface lost flag for DDraw */
1163 #define SFLAG_USERPTR 0x00004000 /* The application allocated the memory for this surface */
1164 #define SFLAG_GLCKEY 0x00008000 /* The gl texture was created with a color key */
1165 #define SFLAG_CLIENT 0x00010000 /* GL_APPLE_client_storage is used on that texture */
1166 #define SFLAG_ALLOCATED 0x00020000 /* A gl texture is allocated for this surface */
1168 /* In some conditions the surface memory must not be freed:
1169 * SFLAG_OVERSIZE: Not all data can be kept in GL
1170 * SFLAG_CONVERTED: Converting the data back would take too long
1171 * SFLAG_DIBSECTION: The dib code manages the memory
1172 * SFLAG_LOCKED: The app requires access to the surface data
1173 * SFLAG_DYNLOCK: Avoid freeing the data for performance
1174 * SFLAG_DYNCHANGE: Same reason as DYNLOCK
1175 * SFLAG_CLIENT: OpenGL uses our memory as backup
1177 #define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
1178 SFLAG_CONVERTED | \
1179 SFLAG_DIBSECTION | \
1180 SFLAG_LOCKED | \
1181 SFLAG_DYNLOCK | \
1182 SFLAG_DYNCHANGE | \
1183 SFLAG_USERPTR | \
1184 SFLAG_CLIENT)
1186 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
1188 /*****************************************************************************
1189 * IWineD3DVertexDeclaration implementation structure
1191 typedef struct IWineD3DVertexDeclarationImpl {
1192 /* IUnknown Information */
1193 const IWineD3DVertexDeclarationVtbl *lpVtbl;
1194 LONG ref;
1196 IUnknown *parent;
1197 IWineD3DDeviceImpl *wineD3DDevice;
1199 WINED3DVERTEXELEMENT *pDeclarationWine;
1200 UINT declarationWNumElements;
1201 } IWineD3DVertexDeclarationImpl;
1203 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
1205 /*****************************************************************************
1206 * IWineD3DStateBlock implementation structure
1209 /* Internal state Block for Begin/End/Capture/Create/Apply info */
1210 /* Note: Very long winded but gl Lists are not flexible enough */
1211 /* to resolve everything we need, so doing it manually for now */
1212 typedef struct SAVEDSTATES {
1213 BOOL indices;
1214 BOOL material;
1215 BOOL fvf;
1216 BOOL streamSource[MAX_STREAMS];
1217 BOOL streamFreq[MAX_STREAMS];
1218 BOOL textures[MAX_SAMPLERS];
1219 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
1220 BOOL viewport;
1221 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
1222 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1223 BOOL samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1224 BOOL clipplane[MAX_CLIPPLANES];
1225 BOOL vertexDecl;
1226 BOOL pixelShader;
1227 BOOL pixelShaderConstantsB[MAX_CONST_B];
1228 BOOL pixelShaderConstantsI[MAX_CONST_I];
1229 BOOL *pixelShaderConstantsF;
1230 BOOL vertexShader;
1231 BOOL vertexShaderConstantsB[MAX_CONST_B];
1232 BOOL vertexShaderConstantsI[MAX_CONST_I];
1233 BOOL *vertexShaderConstantsF;
1234 BOOL scissorRect;
1235 } SAVEDSTATES;
1237 typedef struct {
1238 struct list entry;
1239 DWORD count;
1240 DWORD idx[13];
1241 } constants_entry;
1243 struct IWineD3DStateBlockImpl
1245 /* IUnknown fields */
1246 const IWineD3DStateBlockVtbl *lpVtbl;
1247 LONG ref; /* Note: Ref counting not required */
1249 /* IWineD3DStateBlock information */
1250 IUnknown *parent;
1251 IWineD3DDeviceImpl *wineD3DDevice;
1252 WINED3DSTATEBLOCKTYPE blockType;
1254 /* Array indicating whether things have been set or changed */
1255 SAVEDSTATES changed;
1256 SAVEDSTATES set;
1257 struct list set_vconstantsF;
1258 struct list set_pconstantsF;
1260 /* Drawing - Vertex Shader or FVF related */
1261 DWORD fvf;
1262 /* Vertex Shader Declaration */
1263 IWineD3DVertexDeclaration *vertexDecl;
1265 IWineD3DVertexShader *vertexShader;
1267 /* Vertex Shader Constants */
1268 BOOL vertexShaderConstantB[MAX_CONST_B];
1269 INT vertexShaderConstantI[MAX_CONST_I * 4];
1270 float *vertexShaderConstantF;
1272 /* Stream Source */
1273 BOOL streamIsUP;
1274 UINT streamStride[MAX_STREAMS];
1275 UINT streamOffset[MAX_STREAMS];
1276 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
1277 UINT streamFreq[MAX_STREAMS];
1278 UINT streamFlags[MAX_STREAMS]; /*0 | WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA */
1280 /* Indices */
1281 IWineD3DIndexBuffer* pIndexData;
1282 UINT baseVertexIndex;
1283 UINT loadBaseVertexIndex; /* non-indexed drawing needs 0 here, indexed baseVertexIndex */
1285 /* Transform */
1286 WINED3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
1288 /* Light hashmap . Collisions are handled using standard wine double linked lists */
1289 #define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
1290 #define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
1291 struct list lightMap[LIGHTMAP_SIZE]; /* Mashmap containing the lights */
1292 PLIGHTINFOEL *activeLights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
1294 /* Clipping */
1295 double clipplane[MAX_CLIPPLANES][4];
1296 WINED3DCLIPSTATUS clip_status;
1298 /* ViewPort */
1299 WINED3DVIEWPORT viewport;
1301 /* Material */
1302 WINED3DMATERIAL material;
1304 /* Pixel Shader */
1305 IWineD3DPixelShader *pixelShader;
1307 /* Pixel Shader Constants */
1308 BOOL pixelShaderConstantB[MAX_CONST_B];
1309 INT pixelShaderConstantI[MAX_CONST_I * 4];
1310 float *pixelShaderConstantF;
1312 /* RenderState */
1313 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
1315 /* Texture */
1316 IWineD3DBaseTexture *textures[MAX_SAMPLERS];
1317 int textureDimensions[MAX_SAMPLERS];
1319 /* Texture State Stage */
1320 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
1321 DWORD lowest_disabled_stage;
1322 /* Sampler States */
1323 DWORD samplerState[MAX_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
1325 /* Current GLSL Shader Program */
1326 struct glsl_shader_prog_link *glsl_program;
1328 /* Scissor test rectangle */
1329 RECT scissorRect;
1332 extern void stateblock_savedstates_set(
1333 IWineD3DStateBlock* iface,
1334 SAVEDSTATES* states,
1335 BOOL value);
1337 extern void stateblock_savedstates_copy(
1338 IWineD3DStateBlock* iface,
1339 SAVEDSTATES* dest,
1340 SAVEDSTATES* source);
1342 extern void stateblock_copy(
1343 IWineD3DStateBlock* destination,
1344 IWineD3DStateBlock* source);
1346 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
1348 /*****************************************************************************
1349 * IWineD3DQueryImpl implementation structure (extends IUnknown)
1351 typedef struct IWineD3DQueryImpl
1353 const IWineD3DQueryVtbl *lpVtbl;
1354 LONG ref; /* Note: Ref counting not required */
1356 IUnknown *parent;
1357 /*TODO: replace with iface usage */
1358 #if 0
1359 IWineD3DDevice *wineD3DDevice;
1360 #else
1361 IWineD3DDeviceImpl *wineD3DDevice;
1362 #endif
1364 /* IWineD3DQuery fields */
1365 WINED3DQUERYTYPE type;
1366 /* TODO: Think about using a IUnknown instead of a void* */
1367 void *extendedData;
1370 } IWineD3DQueryImpl;
1372 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
1374 /* Datastructures for IWineD3DQueryImpl.extendedData */
1375 typedef struct WineQueryOcclusionData {
1376 GLuint queryId;
1377 } WineQueryOcclusionData;
1379 typedef struct WineQueryEventData {
1380 GLuint fenceId;
1381 } WineQueryEventData;
1383 /*****************************************************************************
1384 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1387 typedef struct IWineD3DSwapChainImpl
1389 /*IUnknown part*/
1390 const IWineD3DSwapChainVtbl *lpVtbl;
1391 LONG ref; /* Note: Ref counting not required */
1393 IUnknown *parent;
1394 IWineD3DDeviceImpl *wineD3DDevice;
1396 /* IWineD3DSwapChain fields */
1397 IWineD3DSurface **backBuffer;
1398 IWineD3DSurface *frontBuffer;
1399 BOOL wantsDepthStencilBuffer;
1400 WINED3DPRESENT_PARAMETERS presentParms;
1401 DWORD orig_width, orig_height;
1402 WINED3DFORMAT orig_fmt;
1404 long prev_time, frames; /* Performance tracking */
1405 unsigned int vSyncCounter;
1407 WineD3DContext **context; /* Later a array for multithreading */
1408 unsigned int num_contexts;
1410 HWND win_handle;
1411 Window win;
1412 } IWineD3DSwapChainImpl;
1414 extern const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
1416 /*****************************************************************************
1417 * Utility function prototypes
1420 /* Trace routines */
1421 const char* debug_d3dformat(WINED3DFORMAT fmt);
1422 const char* debug_d3ddevicetype(WINED3DDEVTYPE devtype);
1423 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
1424 const char* debug_d3dusage(DWORD usage);
1425 const char* debug_d3dusagequery(DWORD usagequery);
1426 const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method);
1427 const char* debug_d3ddecltype(WINED3DDECLTYPE type);
1428 const char* debug_d3ddeclusage(BYTE usage);
1429 const char* debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType);
1430 const char* debug_d3drenderstate(DWORD state);
1431 const char* debug_d3dsamplerstate(DWORD state);
1432 const char* debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type);
1433 const char* debug_d3dtexturestate(DWORD state);
1434 const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype);
1435 const char* debug_d3dpool(WINED3DPOOL pool);
1436 const char *debug_fbostatus(GLenum status);
1437 const char *debug_glerror(GLenum error);
1439 /* Routines for GL <-> D3D values */
1440 GLenum StencilOp(DWORD op);
1441 GLenum CompareFunc(DWORD func);
1442 void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
1443 void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx);
1444 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords);
1446 void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height);
1447 GLenum surface_get_gl_buffer(IWineD3DSurface *iface, IWineD3DSwapChain *swapchain);
1449 int D3DFmtMakeGlCfg(WINED3DFORMAT BackBufferFormat, WINED3DFORMAT StencilBufferFormat, int *attribs, int* nAttribs, BOOL alternate);
1451 /* Math utils */
1452 void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2);
1454 /*****************************************************************************
1455 * To enable calling of inherited functions, requires prototypes
1457 * Note: Only require classes which are subclassed, ie resource, basetexture,
1459 /*** IUnknown methods ***/
1460 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1461 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1462 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1463 /*** IWineD3DResource methods ***/
1464 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1465 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1466 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1467 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1468 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1469 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1470 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1471 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
1472 extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
1473 /*** class static members ***/
1474 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
1476 /*** IUnknown methods ***/
1477 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1478 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1479 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1480 /*** IWineD3DResource methods ***/
1481 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1482 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1483 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1484 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1485 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1486 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1487 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1488 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
1489 extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
1490 /*** IWineD3DBaseTexture methods ***/
1491 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1492 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1493 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
1494 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1495 extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
1496 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1497 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1498 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
1500 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset, GLint *vbo);
1501 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
1502 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
1503 extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
1504 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1505 /*** class static members ***/
1506 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
1508 struct SHADER_OPCODE_ARG;
1509 typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
1511 /* Struct to maintain a list of GLSL shader programs and their associated pixel and
1512 * vertex shaders. A list of this type is maintained on the DeviceImpl, and is only
1513 * used if the user is using GLSL shaders. */
1514 struct glsl_shader_prog_link {
1515 struct list vshader_entry;
1516 struct list pshader_entry;
1517 GLhandleARB programId;
1518 GLhandleARB *vuniformF_locations;
1519 GLhandleARB *puniformF_locations;
1520 GLhandleARB vshader;
1521 GLhandleARB pshader;
1524 typedef struct {
1525 GLhandleARB vshader;
1526 GLhandleARB pshader;
1527 } glsl_program_key_t;
1529 /* TODO: Make this dynamic, based on shader limits ? */
1530 #define MAX_REG_ADDR 1
1531 #define MAX_REG_TEMP 32
1532 #define MAX_REG_TEXCRD 8
1533 #define MAX_REG_INPUT 12
1534 #define MAX_REG_OUTPUT 12
1535 #define MAX_ATTRIBS 16
1536 #define MAX_CONST_I 16
1537 #define MAX_CONST_B 16
1539 /* FIXME: This needs to go up to 2048 for
1540 * Shader model 3 according to msdn (and for software shaders) */
1541 #define MAX_LABELS 16
1543 typedef struct semantic {
1544 DWORD usage;
1545 DWORD reg;
1546 } semantic;
1548 typedef struct local_constant {
1549 struct list entry;
1550 unsigned int idx;
1551 DWORD value[4];
1552 } local_constant;
1554 typedef struct shader_reg_maps {
1556 char texcoord[MAX_REG_TEXCRD]; /* pixel < 3.0 */
1557 char temporary[MAX_REG_TEMP]; /* pixel, vertex */
1558 char address[MAX_REG_ADDR]; /* vertex */
1559 char packed_input[MAX_REG_INPUT]; /* pshader >= 3.0 */
1560 char packed_output[MAX_REG_OUTPUT]; /* vertex >= 3.0 */
1561 char attributes[MAX_ATTRIBS]; /* vertex */
1562 char labels[MAX_LABELS]; /* pixel, vertex */
1564 /* Sampler usage tokens
1565 * Use 0 as default (bit 31 is always 1 on a valid token) */
1566 DWORD samplers[MAX_SAMPLERS];
1567 char bumpmat;
1569 /* Whether or not a loop is used in this shader */
1570 char loop;
1572 /* Whether or not this shader uses fog */
1573 char fog;
1575 } shader_reg_maps;
1577 #define SHADER_PGMSIZE 65535
1578 typedef struct SHADER_BUFFER {
1579 char* buffer;
1580 unsigned int bsize;
1581 unsigned int lineNo;
1582 BOOL newline;
1583 } SHADER_BUFFER;
1585 /* Undocumented opcode controls */
1586 #define INST_CONTROLS_SHIFT 16
1587 #define INST_CONTROLS_MASK 0x00ff0000
1589 typedef enum COMPARISON_TYPE {
1590 COMPARISON_GT = 1,
1591 COMPARISON_EQ = 2,
1592 COMPARISON_GE = 3,
1593 COMPARISON_LT = 4,
1594 COMPARISON_NE = 5,
1595 COMPARISON_LE = 6
1596 } COMPARISON_TYPE;
1598 typedef struct SHADER_OPCODE {
1599 unsigned int opcode;
1600 const char* name;
1601 const char* glname;
1602 char dst_token;
1603 CONST UINT num_params;
1604 SHADER_HANDLER hw_fct;
1605 SHADER_HANDLER hw_glsl_fct;
1606 DWORD min_version;
1607 DWORD max_version;
1608 } SHADER_OPCODE;
1610 typedef struct SHADER_OPCODE_ARG {
1611 IWineD3DBaseShader* shader;
1612 shader_reg_maps* reg_maps;
1613 CONST SHADER_OPCODE* opcode;
1614 DWORD opcode_token;
1615 DWORD dst;
1616 DWORD dst_addr;
1617 DWORD predicate;
1618 DWORD src[4];
1619 DWORD src_addr[4];
1620 SHADER_BUFFER* buffer;
1621 } SHADER_OPCODE_ARG;
1623 typedef struct SHADER_LIMITS {
1624 unsigned int temporary;
1625 unsigned int texcoord;
1626 unsigned int sampler;
1627 unsigned int constant_int;
1628 unsigned int constant_float;
1629 unsigned int constant_bool;
1630 unsigned int address;
1631 unsigned int packed_output;
1632 unsigned int packed_input;
1633 unsigned int attributes;
1634 unsigned int label;
1635 } SHADER_LIMITS;
1637 /** Keeps track of details for TEX_M#x# shader opcodes which need to
1638 maintain state information between multiple codes */
1639 typedef struct SHADER_PARSE_STATE {
1640 unsigned int current_row;
1641 DWORD texcoord_w[2];
1642 } SHADER_PARSE_STATE;
1644 /* Base Shader utility functions.
1645 * (may move callers into the same file in the future) */
1646 extern int shader_addline(
1647 SHADER_BUFFER* buffer,
1648 const char* fmt, ...);
1650 extern const SHADER_OPCODE* shader_get_opcode(
1651 IWineD3DBaseShader *iface,
1652 const DWORD code);
1654 extern void shader_delete_constant_list(
1655 struct list* clist);
1657 void delete_glsl_program_entry(IWineD3DDevice *iface, struct glsl_shader_prog_link *entry);
1659 /* Vertex shader utility functions */
1660 extern BOOL vshader_get_input(
1661 IWineD3DVertexShader* iface,
1662 BYTE usage_req, BYTE usage_idx_req,
1663 unsigned int* regnum);
1665 extern BOOL vshader_input_is_color(
1666 IWineD3DVertexShader* iface,
1667 unsigned int regnum);
1669 extern HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object);
1671 /* ARB_[vertex/fragment]_program helper functions */
1672 extern void shader_arb_load_constants(
1673 IWineD3DDevice* device,
1674 char usePixelShader,
1675 char useVertexShader);
1677 /* ARB shader program Prototypes */
1678 extern void shader_hw_def(SHADER_OPCODE_ARG *arg);
1680 /* ARB pixel shader prototypes */
1681 extern void pshader_hw_bem(SHADER_OPCODE_ARG* arg);
1682 extern void pshader_hw_cnd(SHADER_OPCODE_ARG* arg);
1683 extern void pshader_hw_cmp(SHADER_OPCODE_ARG* arg);
1684 extern void pshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1685 extern void pshader_hw_tex(SHADER_OPCODE_ARG* arg);
1686 extern void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg);
1687 extern void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg);
1688 extern void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg);
1689 extern void pshader_hw_texbem(SHADER_OPCODE_ARG* arg);
1690 extern void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG* arg);
1691 extern void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg);
1692 extern void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg);
1693 extern void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg);
1694 extern void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg);
1695 extern void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1697 /* ARB vertex shader prototypes */
1698 extern void vshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
1699 extern void vshader_hw_mnxn(SHADER_OPCODE_ARG* arg);
1700 extern void vshader_hw_rsq_rcp(SHADER_OPCODE_ARG* arg);
1702 /* GLSL helper functions */
1703 extern void shader_glsl_add_instruction_modifiers(SHADER_OPCODE_ARG *arg);
1704 extern void shader_glsl_load_constants(
1705 IWineD3DDevice* device,
1706 char usePixelShader,
1707 char useVertexShader);
1709 /** The following translate DirectX pixel/vertex shader opcodes to GLSL lines */
1710 extern void shader_glsl_cross(SHADER_OPCODE_ARG* arg);
1711 extern void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg);
1712 extern void shader_glsl_arith(SHADER_OPCODE_ARG* arg);
1713 extern void shader_glsl_mov(SHADER_OPCODE_ARG* arg);
1714 extern void shader_glsl_mad(SHADER_OPCODE_ARG* arg);
1715 extern void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg);
1716 extern void shader_glsl_lrp(SHADER_OPCODE_ARG* arg);
1717 extern void shader_glsl_dot(SHADER_OPCODE_ARG* arg);
1718 extern void shader_glsl_rcp(SHADER_OPCODE_ARG* arg);
1719 extern void shader_glsl_cnd(SHADER_OPCODE_ARG* arg);
1720 extern void shader_glsl_compare(SHADER_OPCODE_ARG* arg);
1721 extern void shader_glsl_def(SHADER_OPCODE_ARG* arg);
1722 extern void shader_glsl_defi(SHADER_OPCODE_ARG* arg);
1723 extern void shader_glsl_defb(SHADER_OPCODE_ARG* arg);
1724 extern void shader_glsl_expp(SHADER_OPCODE_ARG* arg);
1725 extern void shader_glsl_cmp(SHADER_OPCODE_ARG* arg);
1726 extern void shader_glsl_lit(SHADER_OPCODE_ARG* arg);
1727 extern void shader_glsl_dst(SHADER_OPCODE_ARG* arg);
1728 extern void shader_glsl_sincos(SHADER_OPCODE_ARG* arg);
1729 extern void shader_glsl_loop(SHADER_OPCODE_ARG* arg);
1730 extern void shader_glsl_end(SHADER_OPCODE_ARG* arg);
1731 extern void shader_glsl_if(SHADER_OPCODE_ARG* arg);
1732 extern void shader_glsl_ifc(SHADER_OPCODE_ARG* arg);
1733 extern void shader_glsl_else(SHADER_OPCODE_ARG* arg);
1734 extern void shader_glsl_break(SHADER_OPCODE_ARG* arg);
1735 extern void shader_glsl_breakc(SHADER_OPCODE_ARG* arg);
1736 extern void shader_glsl_rep(SHADER_OPCODE_ARG* arg);
1737 extern void shader_glsl_call(SHADER_OPCODE_ARG* arg);
1738 extern void shader_glsl_callnz(SHADER_OPCODE_ARG* arg);
1739 extern void shader_glsl_label(SHADER_OPCODE_ARG* arg);
1740 extern void shader_glsl_pow(SHADER_OPCODE_ARG* arg);
1742 /** GLSL Pixel Shader Prototypes */
1743 extern void pshader_glsl_tex(SHADER_OPCODE_ARG* arg);
1744 extern void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg);
1745 extern void pshader_glsl_texdp3tex(SHADER_OPCODE_ARG* arg);
1746 extern void pshader_glsl_texdp3(SHADER_OPCODE_ARG* arg);
1747 extern void pshader_glsl_texdepth(SHADER_OPCODE_ARG* arg);
1748 extern void pshader_glsl_texm3x2depth(SHADER_OPCODE_ARG* arg);
1749 extern void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg);
1750 extern void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg);
1751 extern void pshader_glsl_texm3x3(SHADER_OPCODE_ARG* arg);
1752 extern void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg);
1753 extern void pshader_glsl_texm3x3tex(SHADER_OPCODE_ARG* arg);
1754 extern void pshader_glsl_texm3x3spec(SHADER_OPCODE_ARG* arg);
1755 extern void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg);
1756 extern void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg);
1757 extern void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg);
1758 extern void pshader_glsl_bem(SHADER_OPCODE_ARG* arg);
1759 extern void pshader_glsl_texreg2ar(SHADER_OPCODE_ARG* arg);
1760 extern void pshader_glsl_texreg2gb(SHADER_OPCODE_ARG* arg);
1761 extern void pshader_glsl_texreg2rgb(SHADER_OPCODE_ARG* arg);
1762 extern void pshader_glsl_dp2add(SHADER_OPCODE_ARG* arg);
1763 extern void pshader_glsl_input_pack(
1764 SHADER_BUFFER* buffer,
1765 semantic* semantics_out);
1767 /** GLSL Vertex Shader Prototypes */
1768 extern void vshader_glsl_output_unpack(
1769 SHADER_BUFFER* buffer,
1770 semantic* semantics_out);
1772 /*****************************************************************************
1773 * IDirect3DBaseShader implementation structure
1775 typedef struct IWineD3DBaseShaderClass
1777 DWORD hex_version;
1778 SHADER_LIMITS limits;
1779 SHADER_PARSE_STATE parse_state;
1780 CONST SHADER_OPCODE *shader_ins;
1781 CONST DWORD *function;
1782 UINT functionLength;
1783 GLuint prgId;
1784 BOOL is_compiled;
1786 /* Type of shader backend */
1787 int shader_mode;
1789 /* Programs this shader is linked with */
1790 struct list linked_programs;
1792 /* Immediate constants (override global ones) */
1793 struct list constantsB;
1794 struct list constantsF;
1795 struct list constantsI;
1796 shader_reg_maps reg_maps;
1798 /* Pointer to the parent device */
1799 IWineD3DDevice *device;
1801 } IWineD3DBaseShaderClass;
1803 typedef struct IWineD3DBaseShaderImpl {
1804 /* IUnknown */
1805 const IWineD3DBaseShaderVtbl *lpVtbl;
1806 LONG ref;
1808 /* IWineD3DBaseShader */
1809 IWineD3DBaseShaderClass baseShader;
1810 } IWineD3DBaseShaderImpl;
1812 extern HRESULT shader_get_registers_used(
1813 IWineD3DBaseShader *iface,
1814 shader_reg_maps* reg_maps,
1815 semantic* semantics_in,
1816 semantic* semantics_out,
1817 CONST DWORD* pToken,
1818 IWineD3DStateBlockImpl *stateBlock);
1820 extern void shader_generate_glsl_declarations(
1821 IWineD3DBaseShader *iface,
1822 shader_reg_maps* reg_maps,
1823 SHADER_BUFFER* buffer,
1824 WineD3D_GL_Info* gl_info);
1826 extern void shader_generate_arb_declarations(
1827 IWineD3DBaseShader *iface,
1828 shader_reg_maps* reg_maps,
1829 SHADER_BUFFER* buffer,
1830 WineD3D_GL_Info* gl_info);
1832 extern void shader_generate_main(
1833 IWineD3DBaseShader *iface,
1834 SHADER_BUFFER* buffer,
1835 shader_reg_maps* reg_maps,
1836 CONST DWORD* pFunction);
1838 extern void shader_dump_ins_modifiers(
1839 const DWORD output);
1841 extern void shader_dump_param(
1842 IWineD3DBaseShader *iface,
1843 const DWORD param,
1844 const DWORD addr_token,
1845 int input);
1847 extern void shader_trace_init(
1848 IWineD3DBaseShader *iface,
1849 const DWORD* pFunction);
1851 extern int shader_get_param(
1852 IWineD3DBaseShader* iface,
1853 const DWORD* pToken,
1854 DWORD* param,
1855 DWORD* addr_token);
1857 extern int shader_skip_unrecognized(
1858 IWineD3DBaseShader* iface,
1859 const DWORD* pToken);
1861 extern void print_glsl_info_log(
1862 WineD3D_GL_Info *gl_info,
1863 GLhandleARB obj);
1865 static inline int shader_get_regtype(const DWORD param) {
1866 return (((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT) |
1867 ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2));
1870 extern unsigned int shader_get_float_offset(const DWORD reg);
1872 static inline BOOL shader_is_pshader_version(DWORD token) {
1873 return 0xFFFF0000 == (token & 0xFFFF0000);
1876 static inline BOOL shader_is_vshader_version(DWORD token) {
1877 return 0xFFFE0000 == (token & 0xFFFF0000);
1880 static inline BOOL shader_is_comment(DWORD token) {
1881 return WINED3DSIO_COMMENT == (token & WINED3DSI_OPCODE_MASK);
1884 /* TODO: vFace (ps_3_0) */
1885 static inline BOOL shader_is_scalar(DWORD param) {
1886 DWORD reg_type = shader_get_regtype(param);
1888 switch (reg_type) {
1889 case WINED3DSPR_RASTOUT:
1890 if ((param & WINED3DSP_REGNUM_MASK) != 0) {
1891 /* oFog & oPts */
1892 return TRUE;
1894 /* oPos */
1895 return FALSE;
1897 case WINED3DSPR_DEPTHOUT: /* oDepth */
1898 case WINED3DSPR_CONSTBOOL: /* b# */
1899 case WINED3DSPR_LOOP: /* aL */
1900 case WINED3DSPR_PREDICATE: /* p0 */
1901 return TRUE;
1903 default:
1904 return FALSE;
1908 /* Internally used shader constants. Applications can use constants 0 to GL_LIMITS(vshader_constantsF) - 1,
1909 * so upload them above that
1911 #define ARB_SHADER_PRIVCONST_BASE GL_LIMITS(vshader_constantsF)
1912 #define ARB_SHADER_PRIVCONST_POS ARB_SHADER_PRIVCONST_BASE + 0
1914 /*****************************************************************************
1915 * IDirect3DVertexShader implementation structure
1917 typedef struct IWineD3DVertexShaderImpl {
1918 /* IUnknown parts*/
1919 const IWineD3DVertexShaderVtbl *lpVtbl;
1920 LONG ref; /* Note: Ref counting not required */
1922 /* IWineD3DBaseShader */
1923 IWineD3DBaseShaderClass baseShader;
1925 /* IWineD3DVertexShaderImpl */
1926 IUnknown *parent;
1928 DWORD usage;
1930 /* Vertex shader input and output semantics */
1931 semantic semantics_in [MAX_ATTRIBS];
1932 semantic semantics_out [MAX_REG_OUTPUT];
1934 /* run time datas... */
1935 VSHADERDATA *data;
1936 #if 0 /* needs reworking */
1937 /* run time datas */
1938 VSHADERINPUTDATA input;
1939 VSHADEROUTPUTDATA output;
1940 #endif
1941 } IWineD3DVertexShaderImpl;
1942 extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
1943 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
1945 /*****************************************************************************
1946 * IDirect3DPixelShader implementation structure
1948 typedef struct IWineD3DPixelShaderImpl {
1949 /* IUnknown parts */
1950 const IWineD3DPixelShaderVtbl *lpVtbl;
1951 LONG ref; /* Note: Ref counting not required */
1953 /* IWineD3DBaseShader */
1954 IWineD3DBaseShaderClass baseShader;
1956 /* IWineD3DPixelShaderImpl */
1957 IUnknown *parent;
1959 /* Pixel shader input semantics */
1960 semantic semantics_in [MAX_REG_INPUT];
1962 /* run time data */
1963 PSHADERDATA *data;
1965 /* Some information about the shader behavior */
1966 char needsbumpmat;
1967 UINT bumpenvmatconst;
1969 #if 0 /* needs reworking */
1970 PSHADERINPUTDATA input;
1971 PSHADEROUTPUTDATA output;
1972 #endif
1973 } IWineD3DPixelShaderImpl;
1975 extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
1976 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
1978 /*****************************************************************************
1979 * IWineD3DPalette implementation structure
1981 struct IWineD3DPaletteImpl {
1982 /* IUnknown parts */
1983 const IWineD3DPaletteVtbl *lpVtbl;
1984 LONG ref;
1986 IUnknown *parent;
1987 IWineD3DDeviceImpl *wineD3DDevice;
1989 /* IWineD3DPalette */
1990 HPALETTE hpal;
1991 WORD palVersion; /*| */
1992 WORD palNumEntries; /*| LOGPALETTE */
1993 PALETTEENTRY palents[256]; /*| */
1994 /* This is to store the palette in 'screen format' */
1995 int screen_palents[256];
1996 DWORD Flags;
1999 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
2000 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
2002 /* DirectDraw utility functions */
2003 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
2005 /*****************************************************************************
2006 * Pixel format management
2008 typedef struct {
2009 WINED3DFORMAT format;
2010 DWORD alphaMask, redMask, greenMask, blueMask;
2011 UINT bpp;
2012 BOOL isFourcc;
2013 GLint glInternal, glGammaInternal, glFormat, glType;
2014 } PixelFormatDesc;
2016 const PixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt);
2018 static inline BOOL use_vs(IWineD3DDeviceImpl *device) {
2019 return (device->vs_selected_mode != SHADER_NONE
2020 && device->stateBlock->vertexShader
2021 && ((IWineD3DVertexShaderImpl *)device->stateBlock->vertexShader)->baseShader.function
2022 && !device->strided_streams.u.s.position_transformed);
2025 static inline BOOL use_ps(IWineD3DDeviceImpl *device) {
2026 return (device->ps_selected_mode != SHADER_NONE
2027 && device->stateBlock->pixelShader
2028 && ((IWineD3DPixelShaderImpl *)device->stateBlock->pixelShader)->baseShader.function);
2031 void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED3DRECT *src_rect,
2032 IWineD3DSurface *dst_surface, WINED3DRECT *dst_rect, WINED3DTEXTUREFILTERTYPE filter, BOOL flip);
2034 #endif