2 * Direct3D wine internal private include file
4 * Copyright 2002-2003 The wine-d3d team
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2002-2003, 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"
41 #include "wine/wined3d.h"
42 #include "wined3d_gl.h"
43 #include "wine/list.h"
44 #include "wine/rbtree.h"
46 /* Texture format fixups */
48 enum fixup_channel_source
50 CHANNEL_SOURCE_ZERO = 0,
51 CHANNEL_SOURCE_ONE = 1,
56 CHANNEL_SOURCE_YUV0 = 6,
57 CHANNEL_SOURCE_YUV1 = 7,
68 struct color_fixup_desc
70 unsigned x_sign_fixup : 1;
71 unsigned x_source : 3;
72 unsigned y_sign_fixup : 1;
73 unsigned y_source : 3;
74 unsigned z_sign_fixup : 1;
75 unsigned z_source : 3;
76 unsigned w_sign_fixup : 1;
77 unsigned w_source : 3;
81 static const struct color_fixup_desc COLOR_FIXUP_IDENTITY =
82 {0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W};
84 static inline struct color_fixup_desc create_color_fixup_desc(
85 int sign0, enum fixup_channel_source src0, int sign1, enum fixup_channel_source src1,
86 int sign2, enum fixup_channel_source src2, int sign3, enum fixup_channel_source src3)
88 struct color_fixup_desc fixup =
98 static inline struct color_fixup_desc create_yuv_fixup_desc(enum yuv_fixup yuv_fixup)
100 struct color_fixup_desc fixup =
102 0, yuv_fixup & (1 << 0) ? CHANNEL_SOURCE_YUV1 : CHANNEL_SOURCE_YUV0,
103 0, yuv_fixup & (1 << 1) ? CHANNEL_SOURCE_YUV1 : CHANNEL_SOURCE_YUV0,
104 0, yuv_fixup & (1 << 2) ? CHANNEL_SOURCE_YUV1 : CHANNEL_SOURCE_YUV0,
105 0, yuv_fixup & (1 << 3) ? CHANNEL_SOURCE_YUV1 : CHANNEL_SOURCE_YUV0,
110 static inline BOOL is_identity_fixup(struct color_fixup_desc fixup)
112 return !memcmp(&fixup, &COLOR_FIXUP_IDENTITY, sizeof(fixup));
115 static inline BOOL is_yuv_fixup(struct color_fixup_desc fixup)
117 return fixup.x_source == CHANNEL_SOURCE_YUV0 || fixup.x_source == CHANNEL_SOURCE_YUV1;
120 static inline enum yuv_fixup get_yuv_fixup(struct color_fixup_desc fixup)
122 enum yuv_fixup yuv_fixup = 0;
123 if (fixup.x_source == CHANNEL_SOURCE_YUV1) yuv_fixup |= (1 << 0);
124 if (fixup.y_source == CHANNEL_SOURCE_YUV1) yuv_fixup |= (1 << 1);
125 if (fixup.z_source == CHANNEL_SOURCE_YUV1) yuv_fixup |= (1 << 2);
126 if (fixup.w_source == CHANNEL_SOURCE_YUV1) yuv_fixup |= (1 << 3);
130 void *wined3d_rb_alloc(size_t size);
131 void *wined3d_rb_realloc(void *ptr, size_t size);
132 void wined3d_rb_free(void *ptr);
135 #define MAX_PALETTES 65536
136 #define MAX_STREAMS 16
137 #define MAX_TEXTURES 8
138 #define MAX_FRAGMENT_SAMPLERS 16
139 #define MAX_VERTEX_SAMPLERS 4
140 #define MAX_COMBINED_SAMPLERS (MAX_FRAGMENT_SAMPLERS + MAX_VERTEX_SAMPLERS)
141 #define MAX_ACTIVE_LIGHTS 8
142 #define MAX_CLIPPLANES WINED3DMAXUSERCLIPPLANES
144 /* Used for CreateStateBlock */
145 #define NUM_SAVEDPIXELSTATES_R 35
146 #define NUM_SAVEDPIXELSTATES_T 18
147 #define NUM_SAVEDPIXELSTATES_S 12
148 #define NUM_SAVEDVERTEXSTATES_R 34
149 #define NUM_SAVEDVERTEXSTATES_T 2
150 #define NUM_SAVEDVERTEXSTATES_S 1
152 extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
153 extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
154 extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
155 extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
156 extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
157 extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
159 typedef enum _WINELOOKUP {
160 WINELOOKUP_WARPPARAM = 0,
164 extern const int minLookup[MAX_LOOKUPS];
165 extern const int maxLookup[MAX_LOOKUPS];
166 extern DWORD *stateLookup[MAX_LOOKUPS];
170 GLenum mip[WINED3DTEXF_LINEAR + 1];
173 struct min_lookup minMipLookup[WINED3DTEXF_ANISOTROPIC + 1];
174 const struct min_lookup minMipLookup_noFilter[WINED3DTEXF_ANISOTROPIC + 1];
175 GLenum magLookup[WINED3DTEXF_ANISOTROPIC + 1];
176 const GLenum magLookup_noFilter[WINED3DTEXF_ANISOTROPIC + 1];
178 extern const struct filter_lookup filter_lookup_nofilter;
179 extern struct filter_lookup filter_lookup;
181 /* float_16_to_32() and float_32_to_16() (see implementation in
182 * surface_base.c) convert 16 bit floats in the FLOAT16 data type
183 * to standard C floats and vice versa. They do not depend on the encoding
184 * of the C float, so they are platform independent, but slow. On x86 and
185 * other IEEE 754 compliant platforms the conversion can be accelerated by
186 * bit shifting the exponent and mantissa. There are also some SSE-based
187 * assembly routines out there.
189 * See GL_NV_half_float for a reference of the FLOAT16 / GL_HALF format
191 static inline float float_16_to_32(const unsigned short *in) {
192 const unsigned short s = ((*in) & 0x8000);
193 const unsigned short e = ((*in) & 0x7C00) >> 10;
194 const unsigned short m = (*in) & 0x3FF;
195 const float sgn = (s ? -1.0 : 1.0);
198 if(m == 0) return sgn * 0.0; /* +0.0 or -0.0 */
199 else return sgn * pow(2, -14.0) * ( (float) m / 1024.0);
201 return sgn * pow(2, (float) e-15.0) * (1.0 + ((float) m / 1024.0));
203 if(m == 0) return sgn / 0.0; /* +INF / -INF */
204 else return 0.0 / 0.0; /* NAN */
224 #define ORM_BACKBUFFER 0
225 #define ORM_PBUFFER 1
229 #define SHADER_GLSL 2
231 #define SHADER_NONE 4
233 #define RTL_DISABLE -1
235 #define RTL_READDRAW 1
236 #define RTL_READTEX 2
237 #define RTL_TEXDRAW 3
240 #define PCI_VENDOR_NONE 0xffff /* e.g. 0x8086 for Intel and 0x10de for Nvidia */
241 #define PCI_DEVICE_NONE 0xffff /* e.g. 0x14f for a Geforce6200 */
243 /* NOTE: When adding fields to this structure, make sure to update the default
244 * values in wined3d_main.c as well. */
245 typedef struct wined3d_settings_s {
246 /* vertex and pixel shader modes */
250 /* Ideally, we don't want the user to have to request GLSL. If the hardware supports GLSL,
251 we should use it. However, until it's fully implemented, we'll leave it as a registry
252 setting for developers. */
254 int offscreen_rendering_mode;
255 int rendertargetlock_mode;
256 unsigned short pci_vendor_id;
257 unsigned short pci_device_id;
258 /* Memory tracking and object counting */
259 unsigned int emulated_textureram;
261 int allow_multisampling;
262 } wined3d_settings_t;
264 extern wined3d_settings_t wined3d_settings;
266 typedef enum _WINED3DSAMPLER_TEXTURE_TYPE
268 WINED3DSTT_UNKNOWN = 0,
272 WINED3DSTT_VOLUME = 4,
273 } WINED3DSAMPLER_TEXTURE_TYPE;
275 typedef enum _WINED3DSHADER_PARAM_REGISTER_TYPE
278 WINED3DSPR_INPUT = 1,
279 WINED3DSPR_CONST = 2,
281 WINED3DSPR_TEXTURE = 3,
282 WINED3DSPR_RASTOUT = 4,
283 WINED3DSPR_ATTROUT = 5,
284 WINED3DSPR_TEXCRDOUT = 6,
285 WINED3DSPR_OUTPUT = 6,
286 WINED3DSPR_CONSTINT = 7,
287 WINED3DSPR_COLOROUT = 8,
288 WINED3DSPR_DEPTHOUT = 9,
289 WINED3DSPR_SAMPLER = 10,
290 WINED3DSPR_CONST2 = 11,
291 WINED3DSPR_CONST3 = 12,
292 WINED3DSPR_CONST4 = 13,
293 WINED3DSPR_CONSTBOOL = 14,
294 WINED3DSPR_LOOP = 15,
295 WINED3DSPR_TEMPFLOAT16 = 16,
296 WINED3DSPR_MISCTYPE = 17,
297 WINED3DSPR_LABEL = 18,
298 WINED3DSPR_PREDICATE = 19,
300 } WINED3DSHADER_PARAM_REGISTER_TYPE;
302 enum wined3d_immconst_type
304 WINED3D_IMMCONST_FLOAT,
305 WINED3D_IMMCONST_FLOAT4,
308 typedef enum _WINED3DVS_RASTOUT_OFFSETS
310 WINED3DSRO_POSITION = 0,
312 WINED3DSRO_POINT_SIZE = 2,
313 } WINED3DVS_RASTOUT_OFFSETS;
315 #define WINED3DSP_NOSWIZZLE (0 | (1 << 2) | (2 << 4) | (3 << 6))
317 typedef enum _WINED3DSHADER_PARAM_SRCMOD_TYPE
319 WINED3DSPSM_NONE = 0,
321 WINED3DSPSM_BIAS = 2,
322 WINED3DSPSM_BIASNEG = 3,
323 WINED3DSPSM_SIGN = 4,
324 WINED3DSPSM_SIGNNEG = 5,
325 WINED3DSPSM_COMP = 6,
327 WINED3DSPSM_X2NEG = 8,
330 WINED3DSPSM_ABS = 11,
331 WINED3DSPSM_ABSNEG = 12,
332 WINED3DSPSM_NOT = 13,
333 } WINED3DSHADER_PARAM_SRCMOD_TYPE;
335 #define WINED3DSP_WRITEMASK_0 0x1 /* .x r */
336 #define WINED3DSP_WRITEMASK_1 0x2 /* .y g */
337 #define WINED3DSP_WRITEMASK_2 0x4 /* .z b */
338 #define WINED3DSP_WRITEMASK_3 0x8 /* .w a */
339 #define WINED3DSP_WRITEMASK_ALL 0xf /* all */
341 typedef enum _WINED3DSHADER_PARAM_DSTMOD_TYPE
343 WINED3DSPDM_NONE = 0,
344 WINED3DSPDM_SATURATE = 1,
345 WINED3DSPDM_PARTIALPRECISION = 2,
346 WINED3DSPDM_MSAMPCENTROID = 4,
347 } WINED3DSHADER_PARAM_DSTMOD_TYPE;
349 typedef enum _WINED3DSHADER_INSTRUCTION_OPCODE_TYPE
371 WINED3DSIO_M4x4 = 20,
372 WINED3DSIO_M4x3 = 21,
373 WINED3DSIO_M3x4 = 22,
374 WINED3DSIO_M3x3 = 23,
375 WINED3DSIO_M3x2 = 24,
376 WINED3DSIO_CALL = 25,
377 WINED3DSIO_CALLNZ = 26,
378 WINED3DSIO_LOOP = 27,
380 WINED3DSIO_ENDLOOP = 29,
381 WINED3DSIO_LABEL = 30,
388 WINED3DSIO_SINCOS = 37,
390 WINED3DSIO_ENDREP = 39,
393 WINED3DSIO_ELSE = 42,
394 WINED3DSIO_ENDIF = 43,
395 WINED3DSIO_BREAK = 44,
396 WINED3DSIO_BREAKC = 45,
397 WINED3DSIO_MOVA = 46,
398 WINED3DSIO_DEFB = 47,
399 WINED3DSIO_DEFI = 48,
401 WINED3DSIO_TEXCOORD = 64,
402 WINED3DSIO_TEXKILL = 65,
404 WINED3DSIO_TEXBEM = 67,
405 WINED3DSIO_TEXBEML = 68,
406 WINED3DSIO_TEXREG2AR = 69,
407 WINED3DSIO_TEXREG2GB = 70,
408 WINED3DSIO_TEXM3x2PAD = 71,
409 WINED3DSIO_TEXM3x2TEX = 72,
410 WINED3DSIO_TEXM3x3PAD = 73,
411 WINED3DSIO_TEXM3x3TEX = 74,
412 WINED3DSIO_TEXM3x3DIFF = 75,
413 WINED3DSIO_TEXM3x3SPEC = 76,
414 WINED3DSIO_TEXM3x3VSPEC = 77,
415 WINED3DSIO_EXPP = 78,
416 WINED3DSIO_LOGP = 79,
419 WINED3DSIO_TEXREG2RGB = 82,
420 WINED3DSIO_TEXDP3TEX = 83,
421 WINED3DSIO_TEXM3x2DEPTH = 84,
422 WINED3DSIO_TEXDP3 = 85,
423 WINED3DSIO_TEXM3x3 = 86,
424 WINED3DSIO_TEXDEPTH = 87,
427 WINED3DSIO_DP2ADD = 90,
430 WINED3DSIO_TEXLDD = 93,
431 WINED3DSIO_SETP = 94,
432 WINED3DSIO_TEXLDL = 95,
433 WINED3DSIO_BREAKP = 96,
435 WINED3DSIO_PHASE = 0xfffd,
436 WINED3DSIO_COMMENT = 0xfffe,
437 WINED3DSIO_END = 0Xffff,
438 } WINED3DSHADER_INSTRUCTION_OPCODE_TYPE;
440 /* Undocumented opcode control to identify projective texture lookups in ps 2.0 and later */
441 #define WINED3DSI_TEXLD_PROJECT 1
442 #define WINED3DSI_TEXLD_BIAS 2
444 typedef enum COMPARISON_TYPE
454 #define WINED3D_SM1_VS 0xfffe
455 #define WINED3D_SM1_PS 0xffff
456 #define WINED3D_SM4_PS 0x0000
457 #define WINED3D_SM4_VS 0x0001
458 #define WINED3D_SM4_GS 0x0002
460 /* Shader version tokens, and shader end tokens */
461 #define WINED3DPS_VERSION(major, minor) ((WINED3D_SM1_PS << 16) | ((major) << 8) | (minor))
462 #define WINED3DVS_VERSION(major, minor) ((WINED3D_SM1_VS << 16) | ((major) << 8) | (minor))
464 /* Shader backends */
466 /* TODO: Make this dynamic, based on shader limits ? */
467 #define MAX_ATTRIBS 16
468 #define MAX_REG_ADDR 1
469 #define MAX_REG_TEMP 32
470 #define MAX_REG_TEXCRD 8
471 #define MAX_REG_INPUT 12
472 #define MAX_REG_OUTPUT 12
473 #define MAX_CONST_I 16
474 #define MAX_CONST_B 16
476 /* FIXME: This needs to go up to 2048 for
477 * Shader model 3 according to msdn (and for software shaders) */
478 #define MAX_LABELS 16
480 #define SHADER_PGMSIZE 65535
481 typedef struct SHADER_BUFFER {
488 enum WINED3D_SHADER_INSTRUCTION_HANDLER
557 WINED3DSIH_TEXDP3TEX,
561 WINED3DSIH_TEXM3x2DEPTH,
562 WINED3DSIH_TEXM3x2PAD,
563 WINED3DSIH_TEXM3x2TEX,
565 WINED3DSIH_TEXM3x3DIFF,
566 WINED3DSIH_TEXM3x3PAD,
567 WINED3DSIH_TEXM3x3SPEC,
568 WINED3DSIH_TEXM3x3TEX,
569 WINED3DSIH_TEXM3x3VSPEC,
570 WINED3DSIH_TEXREG2AR,
571 WINED3DSIH_TEXREG2GB,
572 WINED3DSIH_TEXREG2RGB,
573 WINED3DSIH_TABLE_SIZE
576 enum wined3d_shader_type
578 WINED3D_SHADER_TYPE_PIXEL,
579 WINED3D_SHADER_TYPE_VERTEX,
580 WINED3D_SHADER_TYPE_GEOMETRY,
583 struct wined3d_shader_version
585 enum wined3d_shader_type type;
590 #define WINED3D_SHADER_VERSION(major, minor) (((major) << 8) | (minor))
592 typedef struct shader_reg_maps
594 struct wined3d_shader_version shader_version;
595 char texcoord[MAX_REG_TEXCRD]; /* pixel < 3.0 */
596 char temporary[MAX_REG_TEMP]; /* pixel, vertex */
597 char address[MAX_REG_ADDR]; /* vertex */
598 char labels[MAX_LABELS]; /* pixel, vertex */
599 DWORD *constf; /* pixel, vertex */
600 DWORD texcoord_mask[MAX_REG_TEXCRD]; /* vertex < 3.0 */
601 WORD input_registers; /* max(MAX_REG_INPUT, MAX_ATTRIBS), 16 */
602 WORD output_registers; /* MAX_REG_OUTPUT, 12 */
603 WORD integer_constants; /* MAX_CONST_I, 16 */
604 WORD boolean_constants; /* MAX_CONST_B, 16 */
605 WORD local_bool_consts; /* MAX_CONST_B, 16 */
607 WINED3DSAMPLER_TEXTURE_TYPE sampler_type[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)];
608 BOOL bumpmat[MAX_TEXTURES], luminanceparams[MAX_TEXTURES];
609 char usesnrm, vpos, usesdsx, usesdsy, usestexldd, usesmova;
612 /* Whether or not loops are used in this shader, and nesting depth */
615 /* Whether or not this shader uses fog */
620 struct wined3d_shader_context
622 IWineD3DBaseShader *shader;
623 const struct shader_reg_maps *reg_maps;
624 SHADER_BUFFER *buffer;
628 struct wined3d_shader_register
630 WINED3DSHADER_PARAM_REGISTER_TYPE type;
632 const struct wined3d_shader_src_param *rel_addr;
633 enum wined3d_immconst_type immconst_type;
634 DWORD immconst_data[4];
637 struct wined3d_shader_dst_param
639 struct wined3d_shader_register reg;
645 struct wined3d_shader_src_param
647 struct wined3d_shader_register reg;
652 struct wined3d_shader_instruction
654 const struct wined3d_shader_context *ctx;
655 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
660 const struct wined3d_shader_dst_param *dst;
662 const struct wined3d_shader_src_param *src;
665 struct wined3d_shader_semantic
667 WINED3DDECLUSAGE usage;
669 WINED3DSAMPLER_TEXTURE_TYPE sampler_type;
670 struct wined3d_shader_dst_param reg;
673 struct wined3d_shader_attribute
675 WINED3DDECLUSAGE usage;
679 struct wined3d_shader_frontend
681 void *(*shader_init)(const DWORD *ptr, const struct wined3d_shader_signature *output_signature);
682 void (*shader_free)(void *data);
683 void (*shader_read_header)(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version);
684 void (*shader_read_opcode)(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins, UINT *param_size);
685 void (*shader_read_src_param)(void *data, const DWORD **ptr, struct wined3d_shader_src_param *src_param,
686 struct wined3d_shader_src_param *src_rel_addr);
687 void (*shader_read_dst_param)(void *data, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param,
688 struct wined3d_shader_src_param *dst_rel_addr);
689 void (*shader_read_semantic)(const DWORD **ptr, struct wined3d_shader_semantic *semantic);
690 void (*shader_read_comment)(const DWORD **ptr, const char **comment);
691 BOOL (*shader_is_end)(void *data, const DWORD **ptr);
694 extern const struct wined3d_shader_frontend sm1_shader_frontend;
695 extern const struct wined3d_shader_frontend sm4_shader_frontend;
697 typedef void (*SHADER_HANDLER)(const struct wined3d_shader_instruction *);
700 DWORD VertexShaderVersion;
701 DWORD MaxVertexShaderConst;
703 DWORD PixelShaderVersion;
704 float PixelShader1xMaxValue;
705 DWORD MaxPixelShaderConst;
707 WINED3DVSHADERCAPS2_0 VS20Caps;
708 WINED3DPSHADERCAPS2_0 PS20Caps;
710 DWORD MaxVShaderInstructionsExecuted;
711 DWORD MaxPShaderInstructionsExecuted;
712 DWORD MaxVertexShader30InstructionSlots;
713 DWORD MaxPixelShader30InstructionSlots;
728 enum vertexprocessing_mode {
734 #define WINED3D_CONST_NUM_UNUSED ~0U
736 struct stb_const_desc {
737 unsigned char texunit;
748 /* Stateblock dependent parameters which have to be hardcoded
749 * into the shader code
751 struct ps_compile_args {
752 struct color_fixup_desc color_fixup[MAX_FRAGMENT_SAMPLERS];
753 enum vertexprocessing_mode vp_mode;
755 /* Projected textures(ps 1.0-1.3) */
756 /* Texture types(2D, Cube, 3D) in ps 1.x */
757 BOOL srgb_correction;
759 /* Bitmap for NP2 texcoord fixups (16 samplers max currently).
760 D3D9 has a limit of 16 samplers and the fixup is superfluous
761 in D3D10 (unconditional NP2 support mandatory). */
769 struct vs_compile_args {
771 WORD swizzle_map; /* MAX_ATTRIBS, 16 */
775 void (*shader_handle_instruction)(const struct wined3d_shader_instruction *);
776 void (*shader_select)(IWineD3DDevice *iface, BOOL usePS, BOOL useVS);
777 void (*shader_select_depth_blt)(IWineD3DDevice *iface, enum tex_types tex_type);
778 void (*shader_deselect_depth_blt)(IWineD3DDevice *iface);
779 void (*shader_update_float_vertex_constants)(IWineD3DDevice *iface, UINT start, UINT count);
780 void (*shader_update_float_pixel_constants)(IWineD3DDevice *iface, UINT start, UINT count);
781 void (*shader_load_constants)(IWineD3DDevice *iface, char usePS, char useVS);
782 void (*shader_load_np2fixup_constants)(IWineD3DDevice *iface, char usePS, char useVS);
783 void (*shader_destroy)(IWineD3DBaseShader *iface);
784 HRESULT (*shader_alloc_private)(IWineD3DDevice *iface);
785 void (*shader_free_private)(IWineD3DDevice *iface);
786 BOOL (*shader_dirtifyable_constants)(IWineD3DDevice *iface);
787 void (*shader_get_caps)(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *caps);
788 BOOL (*shader_color_fixup_supported)(struct color_fixup_desc fixup);
789 void (*shader_add_instruction_modifiers)(const struct wined3d_shader_instruction *ins);
792 extern const shader_backend_t glsl_shader_backend;
793 extern const shader_backend_t arb_program_shader_backend;
794 extern const shader_backend_t none_shader_backend;
798 extern void (* CDECL wine_tsx11_lock_ptr)(void);
799 extern void (* CDECL wine_tsx11_unlock_ptr)(void);
801 /* As GLX relies on X, this is needed */
805 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
806 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
808 #define ENTER_GL() wine_tsx11_lock_ptr()
809 #define LEAVE_GL() wine_tsx11_unlock_ptr()
812 /*****************************************************************************
816 /* GL related defines */
817 /* ------------------ */
818 #define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
819 #define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
820 #define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
821 #define GL_VEND(_VendName) (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
823 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
824 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
825 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
826 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
828 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
829 #define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
830 #define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
831 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
833 #define D3DCOLORTOGLFLOAT4(dw, vec) do { \
834 (vec)[0] = D3DCOLOR_R(dw); \
835 (vec)[1] = D3DCOLOR_G(dw); \
836 (vec)[2] = D3DCOLOR_B(dw); \
837 (vec)[3] = D3DCOLOR_A(dw); \
840 /* DirectX Device Limits */
841 /* --------------------- */
842 #define MAX_MIP_LEVELS 32 /* Maximum number of mipmap levels. */
843 #define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
844 See MaxStreams in MSDN under GetDeviceCaps */
845 #define HIGHEST_TRANSFORMSTATE WINED3DTS_WORLDMATRIX(255) /* Highest value in WINED3DTRANSFORMSTATETYPE */
847 /* Checking of API calls */
848 /* --------------------- */
849 #ifndef WINE_NO_DEBUG_MSGS
850 #define checkGLcall(A) \
852 GLint err = glGetError(); \
853 if (err == GL_NO_ERROR) { \
854 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
857 FIXME(">>>>>>>>>>>>>>>>> %s (%#x) from %s @ %s / %d\n", \
858 debug_glerror(err), err, A, __FILE__, __LINE__); \
859 err = glGetError(); \
860 } while (err != GL_NO_ERROR); \
863 #define checkGLcall(A) do {} while(0)
866 /* Trace routines / diagnostics */
867 /* ---------------------------- */
869 /* Dump out a matrix and copy it */
870 #define conv_mat(mat,gl_mat) \
872 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
873 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
874 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
875 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
876 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
879 /* Macro to dump out the current state of the light chain */
880 #define DUMP_LIGHT_CHAIN() \
882 PLIGHTINFOEL *el = This->stateBlock->lights;\
884 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
889 /* Trace vector and strided data information */
890 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
891 #define TRACE_STRIDED(si, name) TRACE( #name "=(data:%p, stride:%d, format:%#x, vbo %d, stream %u)\n", \
892 si->elements[name].data, si->elements[name].stride, si->elements[name].format_desc->format, \
893 si->elements[name].buffer_object, si->elements[name].stream_idx);
895 /* Defines used for optimizations */
897 /* Only reapply what is necessary */
898 #define REAPPLY_ALPHAOP 0x0001
899 #define REAPPLY_ALL 0xFFFF
901 /* Advance declaration of structures to satisfy compiler */
902 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
903 typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
904 typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl;
905 typedef struct IWineD3DDeviceImpl IWineD3DDeviceImpl;
907 /* Global variables */
908 extern const float identity[16];
910 /*****************************************************************************
911 * Compilable extra diagnostics
914 /* Trace information per-vertex: (extremely high amount of trace) */
915 #if 0 /* NOTE: Must be 0 in cvs */
916 # define VTRACE(A) TRACE A
921 /* TODO: Confirm each of these works when wined3d move completed */
922 #if 0 /* NOTE: Must be 0 in cvs */
923 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
924 of each frame, a check is made for the existence of C:\D3DTRACE, and if it exists d3d trace
925 is enabled, and if it doesn't exist it is disabled. */
926 # define FRAME_DEBUGGING
927 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
928 the file is deleted */
929 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
930 # define SINGLE_FRAME_DEBUGGING
932 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
933 It can only be enabled when FRAME_DEBUGGING is also enabled
934 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
936 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
937 # define SHOW_FRAME_MAKEUP 1
939 /* The following, when enabled, lets you see the makeup of the all the textures used during each
940 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
941 The contents of the textures assigned to each stage are written into
942 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
943 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
944 # define SHOW_TEXTURE_MAKEUP 0
947 extern BOOL isDumpingFrames;
948 extern LONG primCounter;
953 WINED3D_FFP_POSITION = 0,
954 WINED3D_FFP_BLENDWEIGHT = 1,
955 WINED3D_FFP_BLENDINDICES = 2,
956 WINED3D_FFP_NORMAL = 3,
957 WINED3D_FFP_PSIZE = 4,
958 WINED3D_FFP_DIFFUSE = 5,
959 WINED3D_FFP_SPECULAR = 6,
960 WINED3D_FFP_TEXCOORD0 = 7,
961 WINED3D_FFP_TEXCOORD1 = 8,
962 WINED3D_FFP_TEXCOORD2 = 9,
963 WINED3D_FFP_TEXCOORD3 = 10,
964 WINED3D_FFP_TEXCOORD4 = 11,
965 WINED3D_FFP_TEXCOORD5 = 12,
966 WINED3D_FFP_TEXCOORD6 = 13,
967 WINED3D_FFP_TEXCOORD7 = 14,
970 enum wined3d_ffp_emit_idx
972 WINED3D_FFP_EMIT_FLOAT1 = 0,
973 WINED3D_FFP_EMIT_FLOAT2 = 1,
974 WINED3D_FFP_EMIT_FLOAT3 = 2,
975 WINED3D_FFP_EMIT_FLOAT4 = 3,
976 WINED3D_FFP_EMIT_D3DCOLOR = 4,
977 WINED3D_FFP_EMIT_UBYTE4 = 5,
978 WINED3D_FFP_EMIT_SHORT2 = 6,
979 WINED3D_FFP_EMIT_SHORT4 = 7,
980 WINED3D_FFP_EMIT_UBYTE4N = 8,
981 WINED3D_FFP_EMIT_SHORT2N = 9,
982 WINED3D_FFP_EMIT_SHORT4N = 10,
983 WINED3D_FFP_EMIT_USHORT2N = 11,
984 WINED3D_FFP_EMIT_USHORT4N = 12,
985 WINED3D_FFP_EMIT_UDEC3 = 13,
986 WINED3D_FFP_EMIT_DEC3N = 14,
987 WINED3D_FFP_EMIT_FLOAT16_2 = 15,
988 WINED3D_FFP_EMIT_FLOAT16_4 = 16,
989 WINED3D_FFP_EMIT_COUNT = 17
992 struct wined3d_stream_info_element
994 const struct GlPixelFormatDesc *format_desc;
998 GLuint buffer_object;
1001 struct wined3d_stream_info
1003 struct wined3d_stream_info_element elements[MAX_ATTRIBS];
1004 BOOL position_transformed;
1005 WORD swizzle_map; /* MAX_ATTRIBS, 16 */
1006 WORD use_map; /* MAX_ATTRIBS, 16 */
1009 /*****************************************************************************
1013 /* Routine common to the draw primitive and draw indexed primitive routines */
1014 void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT numberOfVertices,
1015 UINT start_idx, UINT idxBytes, const void *idxData, UINT minIndex);
1016 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
1018 typedef void (WINE_GLAPI *glAttribFunc)(const void *data);
1019 typedef void (WINE_GLAPI *glMultiTexCoordFunc)(GLenum unit, const void *data);
1020 extern glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT];
1021 extern glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT];
1022 extern glAttribFunc specular_func_3ubv;
1023 extern glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT];
1024 extern glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT];
1025 extern glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT];
1029 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
1030 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
1032 /* Routines and structures related to state management */
1033 typedef struct WineD3DContext WineD3DContext;
1034 typedef void (*APPLYSTATEFUNC)(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *ctx);
1036 #define STATE_RENDER(a) (a)
1037 #define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
1039 #define STATE_TEXTURESTAGE(stage, num) (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + 1 + (stage) * (WINED3D_HIGHEST_TEXTURE_STATE + 1) + (num))
1040 #define STATE_IS_TEXTURESTAGE(a) ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
1042 /* + 1 because samplers start with 0 */
1043 #define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
1044 #define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1))
1046 #define STATE_PIXELSHADER (STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1) + 1)
1047 #define STATE_IS_PIXELSHADER(a) ((a) == STATE_PIXELSHADER)
1049 #define STATE_TRANSFORM(a) (STATE_PIXELSHADER + (a))
1050 #define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)))
1052 #define STATE_STREAMSRC (STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)) + 1)
1053 #define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
1054 #define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
1055 #define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
1057 #define STATE_VDECL (STATE_INDEXBUFFER + 1)
1058 #define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
1060 #define STATE_VSHADER (STATE_VDECL + 1)
1061 #define STATE_IS_VSHADER(a) ((a) == STATE_VSHADER)
1063 #define STATE_VIEWPORT (STATE_VSHADER + 1)
1064 #define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
1066 #define STATE_VERTEXSHADERCONSTANT (STATE_VIEWPORT + 1)
1067 #define STATE_PIXELSHADERCONSTANT (STATE_VERTEXSHADERCONSTANT + 1)
1068 #define STATE_IS_VERTEXSHADERCONSTANT(a) ((a) == STATE_VERTEXSHADERCONSTANT)
1069 #define STATE_IS_PIXELSHADERCONSTANT(a) ((a) == STATE_PIXELSHADERCONSTANT)
1071 #define STATE_ACTIVELIGHT(a) (STATE_PIXELSHADERCONSTANT + (a) + 1)
1072 #define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS))
1074 #define STATE_SCISSORRECT (STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS - 1) + 1)
1075 #define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
1077 #define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
1078 #define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(MAX_CLIPPLANES - 1))
1080 #define STATE_MATERIAL (STATE_CLIPPLANE(MAX_CLIPPLANES))
1082 #define STATE_FRONTFACE (STATE_MATERIAL + 1)
1084 #define STATE_HIGHEST (STATE_FRONTFACE)
1088 DWORD representative;
1089 APPLYSTATEFUNC apply;
1092 struct StateEntryTemplate
1095 struct StateEntry content;
1096 GL_SupportedExt extension;
1099 struct fragment_caps {
1100 DWORD PrimitiveMiscCaps;
1102 DWORD TextureOpCaps;
1103 DWORD MaxTextureBlendStages;
1104 DWORD MaxSimultaneousTextures;
1107 struct fragment_pipeline {
1108 void (*enable_extension)(IWineD3DDevice *iface, BOOL enable);
1109 void (*get_caps)(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct fragment_caps *caps);
1110 HRESULT (*alloc_private)(IWineD3DDevice *iface);
1111 void (*free_private)(IWineD3DDevice *iface);
1112 BOOL (*color_fixup_supported)(struct color_fixup_desc fixup);
1113 const struct StateEntryTemplate *states;
1114 BOOL ffp_proj_control;
1117 extern const struct StateEntryTemplate misc_state_template[];
1118 extern const struct StateEntryTemplate ffp_vertexstate_template[];
1119 extern const struct fragment_pipeline ffp_fragment_pipeline;
1120 extern const struct fragment_pipeline atifs_fragment_pipeline;
1121 extern const struct fragment_pipeline arbfp_fragment_pipeline;
1122 extern const struct fragment_pipeline nvts_fragment_pipeline;
1123 extern const struct fragment_pipeline nvrc_fragment_pipeline;
1125 /* "Base" state table */
1126 HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
1127 const WineD3D_GL_Info *gl_info, const struct StateEntryTemplate *vertex,
1128 const struct fragment_pipeline *fragment, const struct StateEntryTemplate *misc);
1130 /* Shaders for color conversions in blits */
1131 struct blit_shader {
1132 HRESULT (*alloc_private)(IWineD3DDevice *iface);
1133 void (*free_private)(IWineD3DDevice *iface);
1134 HRESULT (*set_shader)(IWineD3DDevice *iface, const struct GlPixelFormatDesc *format_desc,
1135 GLenum textype, UINT width, UINT height);
1136 void (*unset_shader)(IWineD3DDevice *iface);
1137 BOOL (*color_fixup_supported)(struct color_fixup_desc fixup);
1140 extern const struct blit_shader ffp_blit;
1141 extern const struct blit_shader arbfp_blit;
1149 #define WINED3D_MAX_FBO_ENTRIES 64
1151 /* The new context manager that should deal with onscreen and offscreen rendering */
1152 struct WineD3DContext {
1153 /* State dirtification
1154 * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices
1155 * 0...numDirtyEntries - 1. isStateDirty is a redundant copy of the dirtyArray. Technically only one of them would be needed,
1156 * 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
1157 * only numDirtyEntries array elements have to be checked, not STATE_HIGHEST states.
1159 DWORD dirtyArray[STATE_HIGHEST + 1]; /* Won't get bigger than that, a state is never marked dirty 2 times */
1160 DWORD numDirtyEntries;
1161 DWORD isStateDirty[STATE_HIGHEST/32 + 1]; /* Bitmap to find out quickly if a state is dirty */
1163 IWineD3DSurface *surface;
1164 DWORD tid; /* Thread ID which owns this context at the moment */
1166 /* Stores some information about the context state for optimization */
1167 WORD draw_buffer_dirty : 1;
1168 WORD last_was_rhw : 1; /* true iff last draw_primitive was in xyzrhw mode */
1169 WORD last_was_pshader : 1;
1170 WORD last_was_vshader : 1;
1171 WORD namedArraysLoaded : 1;
1172 WORD numberedArraysLoaded : 1;
1173 WORD last_was_blit : 1;
1174 WORD last_was_ckey : 1;
1177 WORD fog_enabled : 1;
1178 WORD num_untracked_materials : 2; /* Max value 2 */
1180 BYTE texShaderBumpMap; /* MAX_TEXTURES, 8 */
1181 BYTE lastWasPow2Texture; /* MAX_TEXTURES, 8 */
1182 DWORD numbered_array_mask;
1183 GLenum tracking_parm; /* Which source is tracking current colour */
1184 GLenum untracked_materials[2];
1185 UINT blit_w, blit_h;
1186 enum fogsource fog_source;
1188 char *vshader_const_dirty, *pshader_const_dirty;
1190 /* The actual opengl context */
1194 HPBUFFERARB pbuffer;
1198 UINT fbo_entry_count;
1199 struct list fbo_list;
1200 struct fbo_entry *current_fbo;
1204 /* Extension emulation */
1205 GLint gl_fog_source;
1206 GLfloat fog_coord_value;
1207 GLfloat color[4], fogstart, fogend, fogcolor[4];
1208 GLuint dummy_arbfp_prog;
1211 typedef enum ContextUsage {
1212 CTXUSAGE_RESOURCELOAD = 1, /* Only loads textures: No State is applied */
1213 CTXUSAGE_DRAWPRIM = 2, /* OpenGL states are set up for blitting DirectDraw surfaces */
1214 CTXUSAGE_BLIT = 3, /* OpenGL states are set up 3D drawing */
1215 CTXUSAGE_CLEAR = 4, /* Drawable and states are set up for clearing */
1218 void ActivateContext(IWineD3DDeviceImpl *device, IWineD3DSurface *target, ContextUsage usage);
1219 WineD3DContext *getActiveContext(void);
1220 WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, HWND win, BOOL create_pbuffer, const WINED3DPRESENT_PARAMETERS *pPresentParms);
1221 void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context);
1222 void context_resource_released(IWineD3DDevice *iface, IWineD3DResource *resource, WINED3DRESOURCETYPE type);
1223 void context_bind_fbo(IWineD3DDevice *iface, GLenum target, GLuint *fbo);
1224 void context_attach_depth_stencil_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer);
1225 void context_attach_surface_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, DWORD idx, IWineD3DSurface *surface);
1227 void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain);
1228 HRESULT create_primary_opengl_context(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain);
1230 /* Macros for doing basic GPU detection based on opengl capabilities */
1231 #define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
1232 #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])
1233 #define WINE_D3D8_CAPABLE(gl_info) WINE_D3D7_CAPABLE(gl_info) && (gl_info->supported[ARB_MULTISAMPLE] && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
1234 #define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER])
1236 /* Default callbacks for implicit object destruction */
1237 extern ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface);
1239 extern ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pSurface);
1241 /*****************************************************************************
1242 * Internal representation of a light
1244 typedef struct PLIGHTINFOEL PLIGHTINFOEL;
1245 struct PLIGHTINFOEL {
1246 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
1247 DWORD OriginalIndex;
1250 BOOL enabledChanged;
1253 /* Converted parms to speed up swapping lights */
1262 /* The default light parameters */
1263 extern const WINED3DLIGHT WINED3D_default_light;
1265 typedef struct WineD3D_PixelFormat
1267 int iPixelFormat; /* WGL pixel format */
1268 int iPixelType; /* WGL pixel type e.g. WGL_TYPE_RGBA_ARB, WGL_TYPE_RGBA_FLOAT_ARB or WGL_TYPE_COLORINDEX_ARB */
1269 int redSize, greenSize, blueSize, alphaSize;
1270 int depthSize, stencilSize;
1271 BOOL windowDrawable;
1272 BOOL pbufferDrawable;
1276 } WineD3D_PixelFormat;
1278 /* The adapter structure */
1279 struct WineD3DAdapter
1284 WineD3D_GL_Info gl_info;
1286 const char *description;
1287 WCHAR DeviceName[CCHDEVICENAME]; /* DeviceName for use with e.g. ChangeDisplaySettings */
1289 WineD3D_PixelFormat *cfgs;
1290 BOOL brokenStencil; /* Set on cards which only offer mixed depth+stencil */
1291 unsigned int TextureRam; /* Amount of texture memory both video ram + AGP/TurboCache/HyperMemory/.. */
1292 unsigned int UsedTextureRam;
1295 extern BOOL initPixelFormats(WineD3D_GL_Info *gl_info);
1296 BOOL initPixelFormatsNoGL(WineD3D_GL_Info *gl_info);
1297 extern long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram);
1298 extern void add_gl_compat_wrappers(WineD3D_GL_Info *gl_info);
1300 /*****************************************************************************
1301 * High order patch management
1303 struct WineD3DRectPatch
1307 WineDirect3DVertexStridedData strided;
1308 WINED3DRECTPATCH_INFO RectPatchInfo;
1310 char has_normals, has_texcoords;
1314 HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This, struct WineD3DRectPatch *patch);
1316 enum projection_types
1329 /*****************************************************************************
1330 * Fixed function pipeline replacements
1332 #define ARG_UNUSED 0xff
1333 struct texture_stage_op
1345 struct color_fixup_desc color_fixup;
1346 unsigned tex_type : 3;
1348 unsigned projected : 2;
1349 unsigned padding : 10;
1352 struct ffp_frag_settings {
1353 struct texture_stage_op op[MAX_TEXTURES];
1355 /* Use an int instead of a char to get dword alignment */
1356 unsigned int sRGB_write;
1359 struct ffp_frag_desc
1361 struct wine_rb_entry entry;
1362 struct ffp_frag_settings settings;
1365 extern const struct wine_rb_functions wined3d_ffp_frag_program_rb_functions;
1367 void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_settings *settings, BOOL ignore_textype);
1368 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
1369 const struct ffp_frag_settings *settings);
1370 void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc);
1372 /*****************************************************************************
1373 * IWineD3D implementation structure
1375 typedef struct IWineD3DImpl
1377 /* IUnknown fields */
1378 const IWineD3DVtbl *lpVtbl;
1379 LONG ref; /* Note: Ref counting not required */
1381 /* WineD3D Information */
1386 struct WineD3DAdapter adapters[1];
1389 extern const IWineD3DVtbl IWineD3D_Vtbl;
1391 BOOL InitAdapters(IWineD3DImpl *This);
1393 /* TODO: setup some flags in the registry to enable, disable pbuffer support
1394 (since it will break quite a few things until contexts are managed properly!) */
1395 extern BOOL pbuffer_support;
1396 /* allocate one pbuffer per surface */
1397 extern BOOL pbuffer_per_surface;
1399 /* A helper function that dumps a resource list */
1400 void dumpResources(struct list *list);
1402 /*****************************************************************************
1403 * IWineD3DDevice implementation structure
1405 #define WINED3D_UNMAPPED_STAGE ~0U
1407 /* Multithreaded flag. Removed from the public header to signal that IWineD3D::CreateDevice ignores it */
1408 #define WINED3DCREATE_MULTITHREADED 0x00000004
1410 struct IWineD3DDeviceImpl
1412 /* IUnknown fields */
1413 const IWineD3DDeviceVtbl *lpVtbl;
1414 LONG ref; /* Note: Ref counting not required */
1416 /* WineD3D Information */
1418 IWineD3DDeviceParent *device_parent;
1420 struct WineD3DAdapter *adapter;
1422 /* Window styles to restore when switching fullscreen mode */
1426 /* X and GL Information */
1427 GLint maxConcurrentLights;
1428 GLenum offscreenBuffer;
1430 /* Selected capabilities */
1431 int vs_selected_mode;
1432 int ps_selected_mode;
1433 const shader_backend_t *shader_backend;
1435 void *fragment_priv;
1437 struct StateEntry StateTable[STATE_HIGHEST + 1];
1438 /* Array of functions for states which are handled by more than one pipeline part */
1439 APPLYSTATEFUNC *multistate_funcs[STATE_HIGHEST + 1];
1440 const struct fragment_pipeline *frag_pipe;
1441 const struct blit_shader *blitter;
1443 unsigned int max_ffp_textures, max_ffp_texture_stages;
1444 DWORD d3d_vshader_constantF, d3d_pshader_constantF; /* Advertised d3d caps, not GL ones */
1447 WORD view_ident : 1; /* true iff view matrix is identity */
1448 WORD untransformed : 1;
1449 WORD vertexBlendUsed : 1; /* To avoid needless setting of the blend matrices */
1450 WORD isRecordingState : 1;
1452 WORD render_offscreen : 1;
1453 WORD bCursorVisible : 1;
1454 WORD haveHardwareCursor : 1;
1455 WORD d3d_initialized : 1;
1456 WORD inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */
1457 WORD softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */
1458 WORD useDrawStridedSlow : 1;
1459 WORD instancedDraw : 1;
1462 BYTE fixed_function_usage_map; /* MAX_TEXTURES, 8 */
1464 #define DDRAW_PITCH_ALIGNMENT 8
1465 #define D3D8_PITCH_ALIGNMENT 4
1466 unsigned char surface_alignment; /* Line Alignment of surfaces */
1468 /* State block related */
1469 IWineD3DStateBlockImpl *stateBlock;
1470 IWineD3DStateBlockImpl *updateStateBlock;
1472 /* Internal use fields */
1473 WINED3DDEVICE_CREATION_PARAMETERS createParms;
1475 WINED3DDEVTYPE devType;
1477 IWineD3DSwapChain **swapchains;
1478 UINT NumberOfSwapChains;
1480 struct list resources; /* a linked list to track resources created by the device */
1481 struct list shaders; /* a linked list to track shaders (pixel and vertex) */
1482 unsigned int highest_dirty_ps_const, highest_dirty_vs_const;
1484 /* Render Target Support */
1485 IWineD3DSurface **render_targets;
1486 IWineD3DSurface *auto_depth_stencil_buffer;
1487 IWineD3DSurface *stencilBufferTarget;
1489 /* Caches to avoid unneeded context changes */
1490 IWineD3DSurface *lastActiveRenderTarget;
1491 IWineD3DSwapChain *lastActiveSwapChain;
1493 /* palettes texture management */
1494 UINT NumberOfPalettes;
1495 PALETTEENTRY **palettes;
1496 UINT currentPalette;
1497 UINT paletteConversionShader;
1499 /* For rendering to a texture using glCopyTexImage */
1500 GLenum *draw_buffers;
1501 GLuint depth_blt_texture;
1502 GLuint depth_blt_rb;
1503 UINT depth_blt_rb_w;
1504 UINT depth_blt_rb_h;
1506 /* Cursor management */
1511 UINT cursorWidth, cursorHeight;
1512 GLuint cursorTexture;
1513 HCURSOR hardwareCursor;
1515 /* The Wine logo surface */
1516 IWineD3DSurface *logo_surface;
1518 /* Textures for when no other textures are mapped */
1519 UINT dummyTextureName[MAX_TEXTURES];
1521 /* Device state management */
1524 /* DirectDraw stuff */
1525 DWORD ddraw_width, ddraw_height;
1526 WINED3DFORMAT ddraw_format;
1528 /* Final position fixup constant */
1531 /* With register combiners we can skip junk texture stages */
1532 DWORD texUnitMap[MAX_COMBINED_SAMPLERS];
1533 DWORD rev_tex_unit_map[MAX_COMBINED_SAMPLERS];
1535 /* Stream source management */
1536 struct wined3d_stream_info strided_streams;
1537 const WineDirect3DVertexStridedData *up_strided;
1539 /* Context management */
1540 WineD3DContext **contexts; /* Dynamic array containing pointers to context structures */
1541 WineD3DContext *activeContext;
1544 WineD3DContext *pbufferContext; /* The context that has a pbuffer as drawable */
1545 DWORD pbufferWidth, pbufferHeight; /* Size of the buffer drawable */
1547 /* High level patch management */
1548 #define PATCHMAP_SIZE 43
1549 #define PATCHMAP_HASHFUNC(x) ((x) % PATCHMAP_SIZE) /* Primitive and simple function */
1550 struct list patches[PATCHMAP_SIZE];
1551 struct WineD3DRectPatch *currentPatch;
1554 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
1556 void device_resource_add(IWineD3DDeviceImpl *This, IWineD3DResource *resource);
1557 void device_resource_released(IWineD3DDeviceImpl *This, IWineD3DResource *resource);
1558 void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
1559 BOOL use_vshader, struct wined3d_stream_info *stream_info, BOOL *fixup);
1560 void device_stream_info_from_strided(IWineD3DDeviceImpl *This,
1561 const struct WineDirect3DVertexStridedData *strided, struct wined3d_stream_info *stream_info);
1562 HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, DWORD Count,
1563 CONST WINED3DRECT* pRects, DWORD Flags, WINED3DCOLOR Color,
1564 float Z, DWORD Stencil);
1565 void IWineD3DDeviceImpl_FindTexUnitMap(IWineD3DDeviceImpl *This);
1566 void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state);
1567 static inline BOOL isStateDirty(WineD3DContext *context, DWORD state) {
1568 DWORD idx = state >> 5;
1569 BYTE shift = state & 0x1f;
1570 return context->isStateDirty[idx] & (1 << shift);
1573 /* Support for IWineD3DResource ::Set/Get/FreePrivateData. */
1574 typedef struct PrivateData
1579 DWORD flags; /* DDSPD_* */
1590 /*****************************************************************************
1591 * IWineD3DResource implementation structure
1593 typedef struct IWineD3DResourceClass
1595 /* IUnknown fields */
1596 LONG ref; /* Note: Ref counting not required */
1598 /* WineD3DResource Information */
1600 WINED3DRESOURCETYPE resourceType;
1601 IWineD3DDeviceImpl *wineD3DDevice;
1605 const struct GlPixelFormatDesc *format_desc;
1607 BYTE *allocatedMemory; /* Pointer to the real data location */
1608 BYTE *heapMemory; /* Pointer to the HeapAlloced block of memory */
1609 struct list privateData;
1610 struct list resource_list_entry;
1612 } IWineD3DResourceClass;
1614 typedef struct IWineD3DResourceImpl
1616 /* IUnknown & WineD3DResource Information */
1617 const IWineD3DResourceVtbl *lpVtbl;
1618 IWineD3DResourceClass resource;
1619 } IWineD3DResourceImpl;
1621 void resource_cleanup(IWineD3DResource *iface);
1622 HRESULT resource_free_private_data(IWineD3DResource *iface, REFGUID guid);
1623 HRESULT resource_get_device(IWineD3DResource *iface, IWineD3DDevice **device);
1624 HRESULT resource_get_parent(IWineD3DResource *iface, IUnknown **parent);
1625 DWORD resource_get_priority(IWineD3DResource *iface);
1626 HRESULT resource_get_private_data(IWineD3DResource *iface, REFGUID guid,
1627 void *data, DWORD *data_size);
1628 HRESULT resource_init(IWineD3DResource *iface, WINED3DRESOURCETYPE resource_type,
1629 IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct GlPixelFormatDesc *format_desc,
1630 WINED3DPOOL pool, IUnknown *parent);
1631 WINED3DRESOURCETYPE resource_get_type(IWineD3DResource *iface);
1632 DWORD resource_set_priority(IWineD3DResource *iface, DWORD new_priority);
1633 HRESULT resource_set_private_data(IWineD3DResource *iface, REFGUID guid,
1634 const void *data, DWORD data_size, DWORD flags);
1636 /* Tests show that the start address of resources is 32 byte aligned */
1637 #define RESOURCE_ALIGNMENT 32
1639 /*****************************************************************************
1640 * IWineD3DBaseTexture D3D- > openGL state map lookups
1643 typedef enum winetexturestates {
1644 WINED3DTEXSTA_ADDRESSU = 0,
1645 WINED3DTEXSTA_ADDRESSV = 1,
1646 WINED3DTEXSTA_ADDRESSW = 2,
1647 WINED3DTEXSTA_BORDERCOLOR = 3,
1648 WINED3DTEXSTA_MAGFILTER = 4,
1649 WINED3DTEXSTA_MINFILTER = 5,
1650 WINED3DTEXSTA_MIPFILTER = 6,
1651 WINED3DTEXSTA_MAXMIPLEVEL = 7,
1652 WINED3DTEXSTA_MAXANISOTROPY = 8,
1653 WINED3DTEXSTA_SRGBTEXTURE = 9,
1654 WINED3DTEXSTA_ELEMENTINDEX = 10,
1655 WINED3DTEXSTA_DMAPOFFSET = 11,
1656 WINED3DTEXSTA_TSSADDRESSW = 12,
1657 MAX_WINETEXTURESTATES = 13,
1658 } winetexturestates;
1662 SRGB_ANY = 0, /* Uses the cached value(e.g. external calls) */
1663 SRGB_RGB = 1, /* Loads the rgb texture */
1664 SRGB_SRGB = 2, /* Loads the srgb texture */
1665 SRGB_BOTH = 3, /* Loads both textures */
1668 /*****************************************************************************
1669 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
1671 typedef struct IWineD3DBaseTextureClass
1673 DWORD states[MAX_WINETEXTURESTATES];
1674 DWORD srgbstates[MAX_WINETEXTURESTATES];
1676 BOOL dirty, srgbDirty;
1677 UINT textureName, srgbTextureName;
1678 float pow2Matrix[16];
1680 WINED3DTEXTUREFILTERTYPE filterType;
1684 BOOL pow2Matrix_identity;
1685 const struct min_lookup *minMipLookup;
1686 const GLenum *magLookup;
1687 void (*internal_preload)(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb);
1688 } IWineD3DBaseTextureClass;
1690 void surface_internal_preload(IWineD3DSurface *iface, enum WINED3DSRGB srgb);
1692 typedef struct IWineD3DBaseTextureImpl
1694 /* IUnknown & WineD3DResource Information */
1695 const IWineD3DBaseTextureVtbl *lpVtbl;
1696 IWineD3DResourceClass resource;
1697 IWineD3DBaseTextureClass baseTexture;
1699 } IWineD3DBaseTextureImpl;
1701 void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
1702 const DWORD texture_states[WINED3D_HIGHEST_TEXTURE_STATE + 1],
1703 const DWORD sampler_states[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
1704 HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surface_desc);
1705 void basetexture_cleanup(IWineD3DBaseTexture *iface);
1706 void basetexture_generate_mipmaps(IWineD3DBaseTexture *iface);
1707 WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture *iface);
1708 BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface);
1709 DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface);
1710 DWORD basetexture_get_lod(IWineD3DBaseTexture *iface);
1711 HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type,
1712 IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct GlPixelFormatDesc *format_desc,
1713 WINED3DPOOL pool, IUnknown *parent);
1714 HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE filter_type);
1715 BOOL basetexture_set_dirty(IWineD3DBaseTexture *iface, BOOL dirty);
1716 DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD new_lod);
1717 void basetexture_unload(IWineD3DBaseTexture *iface);
1718 static inline void basetexture_setsrgbcache(IWineD3DBaseTexture *iface, BOOL srgb) {
1719 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
1720 This->baseTexture.is_srgb = srgb;
1723 /*****************************************************************************
1724 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
1726 typedef struct IWineD3DTextureImpl
1728 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
1729 const IWineD3DTextureVtbl *lpVtbl;
1730 IWineD3DResourceClass resource;
1731 IWineD3DBaseTextureClass baseTexture;
1733 /* IWineD3DTexture */
1734 IWineD3DSurface *surfaces[MAX_MIP_LEVELS];
1738 } IWineD3DTextureImpl;
1740 extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
1742 HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
1743 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent);
1745 /*****************************************************************************
1746 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
1748 typedef struct IWineD3DCubeTextureImpl
1750 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
1751 const IWineD3DCubeTextureVtbl *lpVtbl;
1752 IWineD3DResourceClass resource;
1753 IWineD3DBaseTextureClass baseTexture;
1755 /* IWineD3DCubeTexture */
1756 IWineD3DSurface *surfaces[6][MAX_MIP_LEVELS];
1757 } IWineD3DCubeTextureImpl;
1759 extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
1761 HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
1762 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent);
1764 typedef struct _WINED3DVOLUMET_DESC
1769 } WINED3DVOLUMET_DESC;
1771 /*****************************************************************************
1772 * IWineD3DVolume implementation structure (extends IUnknown)
1774 typedef struct IWineD3DVolumeImpl
1776 /* IUnknown & WineD3DResource fields */
1777 const IWineD3DVolumeVtbl *lpVtbl;
1778 IWineD3DResourceClass resource;
1780 /* WineD3DVolume Information */
1781 WINED3DVOLUMET_DESC currentDesc;
1782 IWineD3DBase *container;
1785 WINED3DBOX lockedBox;
1786 WINED3DBOX dirtyBox;
1788 } IWineD3DVolumeImpl;
1790 extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
1792 void volume_add_dirty_box(IWineD3DVolume *iface, const WINED3DBOX *dirty_box);
1794 /*****************************************************************************
1795 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
1797 typedef struct IWineD3DVolumeTextureImpl
1799 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
1800 const IWineD3DVolumeTextureVtbl *lpVtbl;
1801 IWineD3DResourceClass resource;
1802 IWineD3DBaseTextureClass baseTexture;
1804 /* IWineD3DVolumeTexture */
1805 IWineD3DVolume *volumes[MAX_MIP_LEVELS];
1806 } IWineD3DVolumeTextureImpl;
1808 extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
1810 HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height, UINT depth, UINT levels,
1811 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent);
1813 typedef struct _WINED3DSURFACET_DESC
1815 WINED3DMULTISAMPLE_TYPE MultiSampleType;
1816 DWORD MultiSampleQuality;
1819 } WINED3DSURFACET_DESC;
1821 /*****************************************************************************
1822 * Structure for DIB Surfaces (GetDC and GDI surfaces)
1824 typedef struct wineD3DSurface_DIB {
1830 } wineD3DSurface_DIB;
1837 } renderbuffer_entry_t;
1842 IWineD3DSurface **render_targets;
1843 IWineD3DSurface *depth_stencil;
1848 /*****************************************************************************
1849 * IWineD3DClipp implementation structure
1851 typedef struct IWineD3DClipperImpl
1853 const IWineD3DClipperVtbl *lpVtbl;
1858 } IWineD3DClipperImpl;
1861 /*****************************************************************************
1862 * IWineD3DSurface implementation structure
1864 struct IWineD3DSurfaceImpl
1866 /* IUnknown & IWineD3DResource Information */
1867 const IWineD3DSurfaceVtbl *lpVtbl;
1868 IWineD3DResourceClass resource;
1870 /* IWineD3DSurface fields */
1871 IWineD3DBase *container;
1872 WINED3DSURFACET_DESC currentDesc;
1873 IWineD3DPaletteImpl *palette; /* D3D7 style palette handling */
1874 PALETTEENTRY *palette9; /* D3D8/9 style palette handling */
1876 /* TODO: move this off into a management class(maybe!) */
1882 /* A method to retrieve the drawable size. Not in the Vtable to make it changeable */
1883 void (*get_drawable_size)(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1885 /* Oversized texture */
1894 #define MAXLOCKCOUNT 50 /* After this amount of locks do not free the sysmem copy */
1896 glDescriptor glDescription;
1899 wineD3DSurface_DIB dib;
1902 /* Color keys for DDraw */
1903 WINEDDCOLORKEY DestBltCKey;
1904 WINEDDCOLORKEY DestOverlayCKey;
1905 WINEDDCOLORKEY SrcOverlayCKey;
1906 WINEDDCOLORKEY SrcBltCKey;
1909 WINEDDCOLORKEY glCKey;
1911 struct list renderbuffers;
1912 renderbuffer_entry_t *current_renderbuffer;
1914 /* DirectDraw clippers */
1915 IWineD3DClipper *clipper;
1917 /* DirectDraw Overlay handling */
1918 RECT overlay_srcrect;
1919 RECT overlay_destrect;
1920 IWineD3DSurfaceImpl *overlay_dest;
1921 struct list overlays;
1922 struct list overlay_entry;
1925 extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
1926 extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
1928 /* Predeclare the shared Surface functions */
1929 HRESULT WINAPI IWineD3DBaseSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
1930 ULONG WINAPI IWineD3DBaseSurfaceImpl_AddRef(IWineD3DSurface *iface);
1931 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
1932 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
1933 HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
1934 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
1935 HRESULT WINAPI IWineD3DBaseSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
1936 DWORD WINAPI IWineD3DBaseSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
1937 DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPriority(IWineD3DSurface *iface);
1938 WINED3DRESOURCETYPE WINAPI IWineD3DBaseSurfaceImpl_GetType(IWineD3DSurface *iface);
1939 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
1940 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
1941 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
1942 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
1943 HRESULT WINAPI IWineD3DBaseSurfaceImpl_IsLost(IWineD3DSurface *iface);
1944 HRESULT WINAPI IWineD3DBaseSurfaceImpl_Restore(IWineD3DSurface *iface);
1945 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
1946 HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
1947 HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, const WINEDDCOLORKEY *CKey);
1948 HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
1949 DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPitch(IWineD3DSurface *iface);
1950 HRESULT WINAPI IWineD3DBaseSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
1951 HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetOverlayPosition(IWineD3DSurface *iface, LONG X, LONG Y);
1952 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetOverlayPosition(IWineD3DSurface *iface, LONG *X, LONG *Y);
1953 HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface *iface, DWORD Flags, IWineD3DSurface *Ref);
1954 HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlay(IWineD3DSurface *iface, const RECT *SrcRect,
1955 IWineD3DSurface *DstSurface, const RECT *DstRect, DWORD Flags, const WINEDDOVERLAYFX *FX);
1956 HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetClipper(IWineD3DSurface *iface, IWineD3DClipper *clipper);
1957 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetClipper(IWineD3DSurface *iface, IWineD3DClipper **clipper);
1958 HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
1959 HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface);
1960 HRESULT WINAPI IWineD3DBaseSurfaceImpl_Blt(IWineD3DSurface *iface, const RECT *DestRect, IWineD3DSurface *SrcSurface,
1961 const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter);
1962 HRESULT WINAPI IWineD3DBaseSurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty,
1963 IWineD3DSurface *Source, const RECT *rsrc, DWORD trans);
1964 HRESULT WINAPI IWineD3DBaseSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags);
1965 void WINAPI IWineD3DBaseSurfaceImpl_BindTexture(IWineD3DSurface *iface, BOOL srgb);
1966 const void *WINAPI IWineD3DBaseSurfaceImpl_GetData(IWineD3DSurface *iface);
1968 void get_drawable_size_swapchain(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1969 void get_drawable_size_backbuffer(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1970 void get_drawable_size_pbuffer(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1971 void get_drawable_size_fbo(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1973 void flip_surface(IWineD3DSurfaceImpl *front, IWineD3DSurfaceImpl *back);
1975 /* Surface flags: */
1976 #define SFLAG_OVERSIZE 0x00000001 /* Surface is bigger than gl size, blts only */
1977 #define SFLAG_CONVERTED 0x00000002 /* Converted for color keying or Palettized */
1978 #define SFLAG_DIBSECTION 0x00000004 /* Has a DIB section attached for GetDC */
1979 #define SFLAG_LOCKABLE 0x00000008 /* Surface can be locked */
1980 #define SFLAG_DISCARD 0x00000010 /* ??? */
1981 #define SFLAG_LOCKED 0x00000020 /* Surface is locked atm */
1982 #define SFLAG_INTEXTURE 0x00000040 /* The GL texture contains the newest surface content */
1983 #define SFLAG_INSRGBTEX 0x00000080 /* The GL srgb texture contains the newest surface content */
1984 #define SFLAG_INDRAWABLE 0x00000100 /* The gl drawable contains the most up to date data */
1985 #define SFLAG_INSYSMEM 0x00000200 /* The system memory copy is most up to date */
1986 #define SFLAG_NONPOW2 0x00000400 /* Surface sizes are not a power of 2 */
1987 #define SFLAG_DYNLOCK 0x00000800 /* Surface is often locked by the app */
1988 #define SFLAG_DCINUSE 0x00001000 /* Set between GetDC and ReleaseDC calls */
1989 #define SFLAG_LOST 0x00002000 /* Surface lost flag for DDraw */
1990 #define SFLAG_USERPTR 0x00004000 /* The application allocated the memory for this surface */
1991 #define SFLAG_GLCKEY 0x00008000 /* The gl texture was created with a color key */
1992 #define SFLAG_CLIENT 0x00010000 /* GL_APPLE_client_storage is used on that texture */
1993 #define SFLAG_ALLOCATED 0x00020000 /* A gl texture is allocated for this surface */
1994 #define SFLAG_SRGBALLOCATED 0x00040000 /* A srgb gl texture is allocated for this surface */
1995 #define SFLAG_PBO 0x00080000 /* Has a PBO attached for speeding up data transfers for dynamically locked surfaces */
1996 #define SFLAG_NORMCOORD 0x00100000 /* Set if the GL texture coords are normalized(non-texture rectangle) */
1997 #define SFLAG_DS_ONSCREEN 0x00200000 /* Is a depth stencil, last modified onscreen */
1998 #define SFLAG_DS_OFFSCREEN 0x00400000 /* Is a depth stencil, last modified offscreen */
1999 #define SFLAG_INOVERLAYDRAW 0x00800000 /* Overlay drawing is in progress. Recursion prevention */
2000 #define SFLAG_SWAPCHAIN 0x01000000 /* The surface is part of a swapchain */
2002 /* In some conditions the surface memory must not be freed:
2003 * SFLAG_OVERSIZE: Not all data can be kept in GL
2004 * SFLAG_CONVERTED: Converting the data back would take too long
2005 * SFLAG_DIBSECTION: The dib code manages the memory
2006 * SFLAG_LOCKED: The app requires access to the surface data
2007 * SFLAG_DYNLOCK: Avoid freeing the data for performance
2008 * SFLAG_PBO: PBOs don't use 'normal' memory. It is either allocated by the driver or must be NULL.
2009 * SFLAG_CLIENT: OpenGL uses our memory as backup
2011 #define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
2013 SFLAG_DIBSECTION | \
2020 #define SFLAG_LOCATIONS (SFLAG_INSYSMEM | \
2022 SFLAG_INDRAWABLE | \
2025 #define SFLAG_DS_LOCATIONS (SFLAG_DS_ONSCREEN | \
2027 #define SFLAG_DS_DISCARDED SFLAG_DS_LOCATIONS
2029 BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
2034 CONVERT_PALETTED_CK,
2038 CONVERT_CK_4444_ARGB,
2043 CONVERT_CK_8888_ARGB,
2056 HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, GLenum *format, GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp, BOOL srgb_mode);
2058 BOOL palette9_changed(IWineD3DSurfaceImpl *This);
2060 /*****************************************************************************
2061 * IWineD3DVertexDeclaration implementation structure
2063 #define MAX_ATTRIBS 16
2065 struct wined3d_vertex_declaration_element
2067 const struct GlPixelFormatDesc *format_desc;
2077 typedef struct IWineD3DVertexDeclarationImpl {
2078 /* IUnknown Information */
2079 const IWineD3DVertexDeclarationVtbl *lpVtbl;
2083 IWineD3DDeviceImpl *wineD3DDevice;
2085 struct wined3d_vertex_declaration_element *elements;
2088 DWORD streams[MAX_STREAMS];
2090 BOOL position_transformed;
2091 BOOL half_float_conv_needed;
2092 } IWineD3DVertexDeclarationImpl;
2094 extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
2096 HRESULT vertexdeclaration_init(IWineD3DVertexDeclarationImpl *This,
2097 const WINED3DVERTEXELEMENT *elements, UINT element_count);
2099 /*****************************************************************************
2100 * IWineD3DStateBlock implementation structure
2103 /* Internal state Block for Begin/End/Capture/Create/Apply info */
2104 /* Note: Very long winded but gl Lists are not flexible enough */
2105 /* to resolve everything we need, so doing it manually for now */
2106 typedef struct SAVEDSTATES {
2107 DWORD transform[(HIGHEST_TRANSFORMSTATE >> 5) + 1];
2108 WORD streamSource; /* MAX_STREAMS, 16 */
2109 WORD streamFreq; /* MAX_STREAMS, 16 */
2110 DWORD renderState[(WINEHIGHEST_RENDER_STATE >> 5) + 1];
2111 DWORD textureState[MAX_TEXTURES]; /* WINED3D_HIGHEST_TEXTURE_STATE + 1, 18 */
2112 WORD samplerState[MAX_COMBINED_SAMPLERS]; /* WINED3D_HIGHEST_SAMPLER_STATE + 1, 14 */
2113 DWORD textures; /* MAX_COMBINED_SAMPLERS, 20 */
2114 DWORD clipplane; /* WINED3DMAXUSERCLIPPLANES, 32 */
2115 WORD pixelShaderConstantsB; /* MAX_CONST_B, 16 */
2116 WORD pixelShaderConstantsI; /* MAX_CONST_I, 16 */
2117 BOOL *pixelShaderConstantsF;
2118 WORD vertexShaderConstantsB; /* MAX_CONST_B, 16 */
2119 WORD vertexShaderConstantsI; /* MAX_CONST_I, 16 */
2120 BOOL *vertexShaderConstantsF;
2121 WORD primitive_type : 1;
2125 WORD vertexDecl : 1;
2126 WORD pixelShader : 1;
2127 WORD vertexShader : 1;
2128 WORD scissorRect : 1;
2137 struct IWineD3DStateBlockImpl
2139 /* IUnknown fields */
2140 const IWineD3DStateBlockVtbl *lpVtbl;
2141 LONG ref; /* Note: Ref counting not required */
2143 /* IWineD3DStateBlock information */
2145 IWineD3DDeviceImpl *wineD3DDevice;
2146 WINED3DSTATEBLOCKTYPE blockType;
2148 /* Array indicating whether things have been set or changed */
2149 SAVEDSTATES changed;
2151 /* Vertex Shader Declaration */
2152 IWineD3DVertexDeclaration *vertexDecl;
2154 IWineD3DVertexShader *vertexShader;
2156 /* Vertex Shader Constants */
2157 BOOL vertexShaderConstantB[MAX_CONST_B];
2158 INT vertexShaderConstantI[MAX_CONST_I * 4];
2159 float *vertexShaderConstantF;
2161 /* primitive type */
2162 GLenum gl_primitive_type;
2166 UINT streamStride[MAX_STREAMS];
2167 UINT streamOffset[MAX_STREAMS + 1 /* tesselated pseudo-stream */ ];
2168 IWineD3DBuffer *streamSource[MAX_STREAMS];
2169 UINT streamFreq[MAX_STREAMS + 1];
2170 UINT streamFlags[MAX_STREAMS + 1]; /*0 | WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA */
2173 IWineD3DBuffer* pIndexData;
2174 WINED3DFORMAT IndexFmt;
2175 INT baseVertexIndex;
2176 INT loadBaseVertexIndex; /* non-indexed drawing needs 0 here, indexed baseVertexIndex */
2179 WINED3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
2181 /* Light hashmap . Collisions are handled using standard wine double linked lists */
2182 #define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
2183 #define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
2184 struct list lightMap[LIGHTMAP_SIZE]; /* Mashmap containing the lights */
2185 PLIGHTINFOEL *activeLights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
2188 double clipplane[MAX_CLIPPLANES][4];
2189 WINED3DCLIPSTATUS clip_status;
2192 WINED3DVIEWPORT viewport;
2195 WINED3DMATERIAL material;
2198 IWineD3DPixelShader *pixelShader;
2200 /* Pixel Shader Constants */
2201 BOOL pixelShaderConstantB[MAX_CONST_B];
2202 INT pixelShaderConstantI[MAX_CONST_I * 4];
2203 float *pixelShaderConstantF;
2206 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
2209 IWineD3DBaseTexture *textures[MAX_COMBINED_SAMPLERS];
2211 /* Texture State Stage */
2212 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
2213 DWORD lowest_disabled_stage;
2214 /* Sampler States */
2215 DWORD samplerState[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
2217 /* Scissor test rectangle */
2220 /* Contained state management */
2221 DWORD contained_render_states[WINEHIGHEST_RENDER_STATE + 1];
2222 unsigned int num_contained_render_states;
2223 DWORD contained_transform_states[HIGHEST_TRANSFORMSTATE + 1];
2224 unsigned int num_contained_transform_states;
2225 DWORD contained_vs_consts_i[MAX_CONST_I];
2226 unsigned int num_contained_vs_consts_i;
2227 DWORD contained_vs_consts_b[MAX_CONST_B];
2228 unsigned int num_contained_vs_consts_b;
2229 DWORD *contained_vs_consts_f;
2230 unsigned int num_contained_vs_consts_f;
2231 DWORD contained_ps_consts_i[MAX_CONST_I];
2232 unsigned int num_contained_ps_consts_i;
2233 DWORD contained_ps_consts_b[MAX_CONST_B];
2234 unsigned int num_contained_ps_consts_b;
2235 DWORD *contained_ps_consts_f;
2236 unsigned int num_contained_ps_consts_f;
2237 struct StageState contained_tss_states[MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)];
2238 unsigned int num_contained_tss_states;
2239 struct StageState contained_sampler_states[MAX_COMBINED_SAMPLERS * WINED3D_HIGHEST_SAMPLER_STATE];
2240 unsigned int num_contained_sampler_states;
2243 extern void stateblock_savedstates_set(
2244 IWineD3DStateBlock* iface,
2245 SAVEDSTATES* states,
2248 extern void stateblock_copy(
2249 IWineD3DStateBlock* destination,
2250 IWineD3DStateBlock* source);
2252 extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
2254 /* Direct3D terminology with little modifications. We do not have an issued state
2255 * because only the driver knows about it, but we have a created state because d3d
2256 * allows GetData on a created issue, but opengl doesn't
2263 /*****************************************************************************
2264 * IWineD3DQueryImpl implementation structure (extends IUnknown)
2266 typedef struct IWineD3DQueryImpl
2268 const IWineD3DQueryVtbl *lpVtbl;
2269 LONG ref; /* Note: Ref counting not required */
2272 /*TODO: replace with iface usage */
2274 IWineD3DDevice *wineD3DDevice;
2276 IWineD3DDeviceImpl *wineD3DDevice;
2279 /* IWineD3DQuery fields */
2280 enum query_state state;
2281 WINED3DQUERYTYPE type;
2282 /* TODO: Think about using a IUnknown instead of a void* */
2286 } IWineD3DQueryImpl;
2288 extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
2289 extern const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl;
2290 extern const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl;
2292 /* Datastructures for IWineD3DQueryImpl.extendedData */
2293 typedef struct WineQueryOcclusionData {
2295 WineD3DContext *ctx;
2296 } WineQueryOcclusionData;
2298 typedef struct WineQueryEventData {
2300 WineD3DContext *ctx;
2301 } WineQueryEventData;
2303 /* IWineD3DBuffer */
2305 /* TODO: Add tests and support for FLOAT16_4 POSITIONT, D3DCOLOR position, other
2306 * fixed function semantics as D3DCOLOR or FLOAT16 */
2307 enum wined3d_buffer_conversion_type
2312 CONV_FLOAT16_2, /* Also handles FLOAT16_4 */
2315 #define WINED3D_BUFFER_OPTIMIZED 0x01 /* Optimize has been called for the buffer */
2316 #define WINED3D_BUFFER_DIRTY 0x02 /* Buffer data has been modified */
2317 #define WINED3D_BUFFER_HASDESC 0x04 /* A vertex description has been found */
2318 #define WINED3D_BUFFER_CREATEBO 0x08 /* Attempt to create a buffer object next PreLoad */
2319 #define WINED3D_BUFFER_DOUBLEBUFFER 0x10 /* Use a vbo and local allocated memory */
2321 struct wined3d_buffer
2323 const struct IWineD3DBufferVtbl *vtbl;
2324 IWineD3DResourceClass resource;
2326 struct wined3d_buffer_desc desc;
2328 GLuint buffer_object;
2329 GLenum buffer_object_usage;
2330 GLenum buffer_type_hint;
2331 UINT buffer_object_size;
2339 /* conversion stuff */
2340 UINT conversion_count;
2342 UINT stride; /* 0 if no conversion */
2343 UINT conversion_stride; /* 0 if no shifted conversion */
2344 enum wined3d_buffer_conversion_type *conversion_map; /* NULL if no conversion */
2345 /* Extra load offsets, for FLOAT16 conversion */
2346 UINT *conversion_shift; /* NULL if no shifted conversion */
2349 extern const IWineD3DBufferVtbl wined3d_buffer_vtbl;
2350 const BYTE *buffer_get_memory(IWineD3DBuffer *iface, UINT offset, GLuint *buffer_object);
2351 const BYTE *buffer_get_sysmem(struct wined3d_buffer *This);
2353 /* IWineD3DRendertargetView */
2354 struct wined3d_rendertarget_view
2356 const struct IWineD3DRendertargetViewVtbl *vtbl;
2359 IWineD3DResource *resource;
2363 extern const IWineD3DRendertargetViewVtbl wined3d_rendertarget_view_vtbl;
2365 /*****************************************************************************
2366 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
2369 typedef struct IWineD3DSwapChainImpl
2372 const IWineD3DSwapChainVtbl *lpVtbl;
2373 LONG ref; /* Note: Ref counting not required */
2376 IWineD3DDeviceImpl *wineD3DDevice;
2378 /* IWineD3DSwapChain fields */
2379 IWineD3DSurface **backBuffer;
2380 IWineD3DSurface *frontBuffer;
2381 WINED3DPRESENT_PARAMETERS presentParms;
2382 DWORD orig_width, orig_height;
2383 WINED3DFORMAT orig_fmt;
2384 WINED3DGAMMARAMP orig_gamma;
2386 long prev_time, frames; /* Performance tracking */
2387 unsigned int vSyncCounter;
2389 WineD3DContext **context; /* Later a array for multithreading */
2390 unsigned int num_contexts;
2393 } IWineD3DSwapChainImpl;
2395 extern const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
2396 const IWineD3DSwapChainVtbl IWineGDISwapChain_Vtbl;
2397 void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc);
2399 HRESULT WINAPI IWineD3DBaseSwapChainImpl_QueryInterface(IWineD3DSwapChain *iface, REFIID riid, LPVOID *ppobj);
2400 ULONG WINAPI IWineD3DBaseSwapChainImpl_AddRef(IWineD3DSwapChain *iface);
2401 ULONG WINAPI IWineD3DBaseSwapChainImpl_Release(IWineD3DSwapChain *iface);
2402 HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetParent(IWineD3DSwapChain *iface, IUnknown ** ppParent);
2403 HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetFrontBufferData(IWineD3DSwapChain *iface, IWineD3DSurface *pDestSurface);
2404 HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetBackBuffer(IWineD3DSwapChain *iface, UINT iBackBuffer, WINED3DBACKBUFFER_TYPE Type, IWineD3DSurface **ppBackBuffer);
2405 HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetRasterStatus(IWineD3DSwapChain *iface, WINED3DRASTER_STATUS *pRasterStatus);
2406 HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDisplayMode(IWineD3DSwapChain *iface, WINED3DDISPLAYMODE*pMode);
2407 HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDevice(IWineD3DSwapChain *iface, IWineD3DDevice**ppDevice);
2408 HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetPresentParameters(IWineD3DSwapChain *iface, WINED3DPRESENT_PARAMETERS *pPresentationParameters);
2409 HRESULT WINAPI IWineD3DBaseSwapChainImpl_SetGammaRamp(IWineD3DSwapChain *iface, DWORD Flags, CONST WINED3DGAMMARAMP *pRamp);
2410 HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetGammaRamp(IWineD3DSwapChain *iface, WINED3DGAMMARAMP *pRamp);
2412 WineD3DContext *IWineD3DSwapChainImpl_CreateContextForThread(IWineD3DSwapChain *iface);
2414 /*****************************************************************************
2415 * Utility function prototypes
2418 /* Trace routines */
2419 const char* debug_d3dformat(WINED3DFORMAT fmt);
2420 const char* debug_d3ddevicetype(WINED3DDEVTYPE devtype);
2421 const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
2422 const char* debug_d3dusage(DWORD usage);
2423 const char* debug_d3dusagequery(DWORD usagequery);
2424 const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method);
2425 const char* debug_d3ddeclusage(BYTE usage);
2426 const char* debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType);
2427 const char* debug_d3drenderstate(DWORD state);
2428 const char* debug_d3dsamplerstate(DWORD state);
2429 const char* debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type);
2430 const char* debug_d3dtexturestate(DWORD state);
2431 const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype);
2432 const char* debug_d3dpool(WINED3DPOOL pool);
2433 const char *debug_fbostatus(GLenum status);
2434 const char *debug_glerror(GLenum error);
2435 const char *debug_d3dbasis(WINED3DBASISTYPE basis);
2436 const char *debug_d3ddegree(WINED3DDEGREETYPE order);
2437 const char* debug_d3dtop(WINED3DTEXTUREOP d3dtop);
2438 void dump_color_fixup_desc(struct color_fixup_desc fixup);
2439 const char *debug_surflocation(DWORD flag);
2441 /* Routines for GL <-> D3D values */
2442 GLenum StencilOp(DWORD op);
2443 GLenum CompareFunc(DWORD func);
2444 BOOL is_invalid_op(IWineD3DDeviceImpl *This, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
2445 void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst);
2446 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords, BOOL transformed, DWORD coordtype, BOOL ffp_can_disable_proj);
2447 void texture_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2448 void sampler_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2449 void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2450 void apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2451 void state_fogcolor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2452 void state_fogdensity(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2453 void state_fogstartend(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2454 void state_fog_fragpart(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2456 void surface_add_dirty_rect(IWineD3DSurface *iface, const RECT *dirty_rect);
2457 GLenum surface_get_gl_buffer(IWineD3DSurface *iface, IWineD3DSwapChain *swapchain);
2458 void surface_load_ds_location(IWineD3DSurface *iface, DWORD location);
2459 void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location);
2460 void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height);
2461 void surface_set_texture_name(IWineD3DSurface *iface, GLuint name, BOOL srgb_name);
2462 void surface_set_texture_target(IWineD3DSurface *iface, GLenum target);
2464 BOOL getColorBits(const struct GlPixelFormatDesc *format_desc,
2465 short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize);
2466 BOOL getDepthStencilBits(const struct GlPixelFormatDesc *format_desc, short *depthSize, short *stencilSize);
2469 void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2);
2470 UINT wined3d_log2i(UINT32 x);
2471 unsigned int count_bits(unsigned int mask);
2473 typedef struct local_constant {
2479 typedef struct SHADER_LIMITS {
2480 unsigned int temporary;
2481 unsigned int texcoord;
2482 unsigned int sampler;
2483 unsigned int constant_int;
2484 unsigned int constant_float;
2485 unsigned int constant_bool;
2486 unsigned int address;
2487 unsigned int packed_output;
2488 unsigned int packed_input;
2489 unsigned int attributes;
2493 /** Keeps track of details for TEX_M#x# shader opcodes which need to
2494 maintain state information between multiple codes */
2495 typedef struct SHADER_PARSE_STATE {
2496 unsigned int current_row;
2497 DWORD texcoord_w[2];
2498 } SHADER_PARSE_STATE;
2501 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
2503 #define PRINTF_ATTR(fmt,args)
2506 /* Base Shader utility functions.
2507 * (may move callers into the same file in the future) */
2508 extern int shader_addline(
2509 SHADER_BUFFER* buffer,
2510 const char* fmt, ...) PRINTF_ATTR(2,3);
2511 int shader_vaddline(SHADER_BUFFER *buffer, const char *fmt, va_list args);
2513 /* Vertex shader utility functions */
2514 extern BOOL vshader_get_input(
2515 IWineD3DVertexShader* iface,
2516 BYTE usage_req, BYTE usage_idx_req,
2517 unsigned int* regnum);
2519 extern HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object);
2521 /*****************************************************************************
2522 * IDirect3DBaseShader implementation structure
2524 typedef struct IWineD3DBaseShaderClass
2527 SHADER_LIMITS limits;
2528 SHADER_PARSE_STATE parse_state;
2530 UINT functionLength;
2531 UINT cur_loop_depth, cur_loop_regno;
2532 BOOL load_local_constsF;
2533 const struct wined3d_shader_frontend *frontend;
2534 void *frontend_data;
2536 /* Programs this shader is linked with */
2537 struct list linked_programs;
2539 /* Immediate constants (override global ones) */
2540 struct list constantsB;
2541 struct list constantsF;
2542 struct list constantsI;
2543 shader_reg_maps reg_maps;
2545 /* Pointer to the parent device */
2546 IWineD3DDevice *device;
2547 struct list shader_list_entry;
2549 } IWineD3DBaseShaderClass;
2551 typedef struct IWineD3DBaseShaderImpl {
2553 const IWineD3DBaseShaderVtbl *lpVtbl;
2555 /* IWineD3DBaseShader */
2556 IWineD3DBaseShaderClass baseShader;
2557 } IWineD3DBaseShaderImpl;
2559 void shader_buffer_init(struct SHADER_BUFFER *buffer);
2560 void shader_buffer_free(struct SHADER_BUFFER *buffer);
2561 void shader_cleanup(IWineD3DBaseShader *iface);
2562 void shader_dump_src_param(const struct wined3d_shader_src_param *param,
2563 const struct wined3d_shader_version *shader_version);
2564 void shader_dump_dst_param(const struct wined3d_shader_dst_param *param,
2565 const struct wined3d_shader_version *shader_version);
2566 void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER *buffer,
2567 const shader_reg_maps *reg_maps, const DWORD *pFunction, void *backend_ctx);
2568 HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, const struct wined3d_shader_frontend *fe,
2569 struct shader_reg_maps *reg_maps, struct wined3d_shader_attribute *attributes,
2570 struct wined3d_shader_signature_element *input_signature,
2571 struct wined3d_shader_signature_element *output_signature, const DWORD *byte_code, DWORD constf_size);
2572 void shader_init(struct IWineD3DBaseShaderClass *shader, IWineD3DDevice *device);
2573 BOOL shader_match_semantic(const char *semantic_name, WINED3DDECLUSAGE usage);
2574 const struct wined3d_shader_frontend *shader_select_frontend(DWORD version_token);
2575 void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe_data, const DWORD *pFunction);
2577 static inline BOOL shader_is_pshader_version(enum wined3d_shader_type type)
2579 return type == WINED3D_SHADER_TYPE_PIXEL;
2582 static inline BOOL shader_is_vshader_version(enum wined3d_shader_type type)
2584 return type == WINED3D_SHADER_TYPE_VERTEX;
2587 static inline BOOL shader_is_scalar(const struct wined3d_shader_register *reg)
2591 case WINED3DSPR_RASTOUT:
2593 if (reg->idx != 0) return TRUE;
2597 case WINED3DSPR_DEPTHOUT: /* oDepth */
2598 case WINED3DSPR_CONSTBOOL: /* b# */
2599 case WINED3DSPR_LOOP: /* aL */
2600 case WINED3DSPR_PREDICATE: /* p0 */
2603 case WINED3DSPR_MISCTYPE:
2614 case WINED3DSPR_IMMCONST:
2615 switch(reg->immconst_type)
2617 case WINED3D_IMMCONST_FLOAT:
2628 static inline BOOL shader_constant_is_local(IWineD3DBaseShaderImpl* This, DWORD reg) {
2629 local_constant* lconst;
2631 if(This->baseShader.load_local_constsF) return FALSE;
2632 LIST_FOR_EACH_ENTRY(lconst, &This->baseShader.constantsF, local_constant, entry) {
2633 if(lconst->idx == reg) return TRUE;
2639 /*****************************************************************************
2640 * IDirect3DVertexShader implementation structures
2642 typedef struct IWineD3DVertexShaderImpl {
2644 const IWineD3DVertexShaderVtbl *lpVtbl;
2646 /* IWineD3DBaseShader */
2647 IWineD3DBaseShaderClass baseShader;
2649 /* IWineD3DVertexShaderImpl */
2657 /* Vertex shader input and output semantics */
2658 struct wined3d_shader_attribute attributes[MAX_ATTRIBS];
2659 struct wined3d_shader_signature_element output_signature[MAX_REG_OUTPUT];
2661 UINT min_rel_offset, max_rel_offset;
2664 UINT recompile_count;
2665 } IWineD3DVertexShaderImpl;
2666 extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
2668 void find_vs_compile_args(IWineD3DVertexShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct vs_compile_args *args);
2670 /*****************************************************************************
2671 * IDirect3DPixelShader implementation structure
2673 typedef struct IWineD3DPixelShaderImpl {
2674 /* IUnknown parts */
2675 const IWineD3DPixelShaderVtbl *lpVtbl;
2677 /* IWineD3DBaseShader */
2678 IWineD3DBaseShaderClass baseShader;
2680 /* IWineD3DPixelShaderImpl */
2683 /* Pixel shader input semantics */
2684 struct wined3d_shader_signature_element input_signature[MAX_REG_INPUT];
2685 DWORD input_reg_map[MAX_REG_INPUT];
2686 BOOL input_reg_used[MAX_REG_INPUT];
2687 int declared_in_count;
2692 /* Some information about the shader behavior */
2693 struct stb_const_desc bumpenvmatconst[MAX_TEXTURES];
2694 unsigned char numbumpenvmatconsts;
2695 struct stb_const_desc luminanceconst[MAX_TEXTURES];
2701 } IWineD3DPixelShaderImpl;
2703 extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
2704 void pixelshader_update_samplers(struct shader_reg_maps *reg_maps, IWineD3DBaseTexture * const *textures);
2705 void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct ps_compile_args *args);
2707 /* sRGB correction constants */
2708 static const float srgb_cmp = 0.0031308;
2709 static const float srgb_mul_low = 12.92;
2710 static const float srgb_pow = 0.41666;
2711 static const float srgb_mul_high = 1.055;
2712 static const float srgb_sub_high = 0.055;
2714 /*****************************************************************************
2715 * IWineD3DPalette implementation structure
2717 struct IWineD3DPaletteImpl {
2718 /* IUnknown parts */
2719 const IWineD3DPaletteVtbl *lpVtbl;
2723 IWineD3DDeviceImpl *wineD3DDevice;
2725 /* IWineD3DPalette */
2727 WORD palVersion; /*| */
2728 WORD palNumEntries; /*| LOGPALETTE */
2729 PALETTEENTRY palents[256]; /*| */
2730 /* This is to store the palette in 'screen format' */
2731 int screen_palents[256];
2735 extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
2736 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
2738 /* DirectDraw utility functions */
2739 extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
2741 /*****************************************************************************
2742 * Pixel format management
2745 /* WineD3D pixel format flags */
2746 #define WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING 0x1
2747 #define WINED3DFMT_FLAG_FILTERING 0x2
2748 #define WINED3DFMT_FLAG_DEPTH 0x4
2749 #define WINED3DFMT_FLAG_STENCIL 0x8
2750 #define WINED3DFMT_FLAG_RENDERTARGET 0x10
2751 #define WINED3DFMT_FLAG_FOURCC 0x20
2752 #define WINED3DFMT_FLAG_FBO_ATTACHABLE 0x40
2754 struct GlPixelFormatDesc
2756 WINED3DFORMAT format;
2765 enum wined3d_ffp_emit_idx emit_idx;
2766 GLint component_count;
2768 GLint gl_vtx_format;
2769 GLboolean gl_normalized;
2770 unsigned int component_size;
2773 GLint glGammaInternal;
2779 struct color_fixup_desc color_fixup;
2782 const struct GlPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, const WineD3D_GL_Info *gl_info);
2784 static inline BOOL use_vs(IWineD3DStateBlockImpl *stateblock)
2786 return (stateblock->vertexShader
2787 && !stateblock->wineD3DDevice->strided_streams.position_transformed
2788 && stateblock->wineD3DDevice->vs_selected_mode != SHADER_NONE);
2791 static inline BOOL use_ps(IWineD3DStateBlockImpl *stateblock)
2793 return (stateblock->pixelShader
2794 && stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE);
2797 void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED3DRECT *src_rect,
2798 IWineD3DSurface *dst_surface, WINED3DRECT *dst_rect, const WINED3DTEXTUREFILTERTYPE filter, BOOL flip);
2800 /* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */
2801 #define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL"