VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h@ 30585

Last change on this file since 30585 was 28475, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.43

  • Property svn:eol-style set to native
File size: 118.0 KB
Line 
1/*
2 * Direct3D wine internal private include file
3 *
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
8 *
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.
13 *
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.
18 *
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
22 */
23
24/*
25 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
26 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
27 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
28 * a choice of LGPL license versions is made available with the language indicating
29 * that LGPLv2 or any later version may be used, or where a choice of which version
30 * of the LGPL is applied is otherwise unspecified.
31 */
32
33#ifndef __WINE_WINED3D_PRIVATE_H
34#define __WINE_WINED3D_PRIVATE_H
35
36#include <stdarg.h>
37#include <math.h>
38#include <limits.h>
39#define NONAMELESSUNION
40#define NONAMELESSSTRUCT
41#define COBJMACROS
42#include "windef.h"
43#include "winbase.h"
44#include "winreg.h"
45#include "wingdi.h"
46#include "winuser.h"
47#include "wine/debug.h"
48#include "wine/unicode.h"
49
50#include "objbase.h"
51#include "wine/wined3d.h"
52#include "wined3d_gl.h"
53#include "wine/list.h"
54#include "wine/rbtree.h"
55
56/* Driver quirks */
57#define WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT 0x00000001
58#define WINED3D_QUIRK_SET_TEXCOORD_W 0x00000002
59#define WINED3D_QUIRK_GLSL_CLIP_VARYING 0x00000004
60#define WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA 0x00000008
61#define WINED3D_QUIRK_NV_CLIP_BROKEN 0x00000010
62#define WINED3D_QUIRK_FBO_TEX_UPDATE 0x00000020
63
64/* Texture format fixups */
65
66enum fixup_channel_source
67{
68 CHANNEL_SOURCE_ZERO = 0,
69 CHANNEL_SOURCE_ONE = 1,
70 CHANNEL_SOURCE_X = 2,
71 CHANNEL_SOURCE_Y = 3,
72 CHANNEL_SOURCE_Z = 4,
73 CHANNEL_SOURCE_W = 5,
74 CHANNEL_SOURCE_COMPLEX0 = 6,
75 CHANNEL_SOURCE_COMPLEX1 = 7,
76};
77
78enum complex_fixup
79{
80 COMPLEX_FIXUP_NONE = 0,
81 COMPLEX_FIXUP_YUY2 = 1,
82 COMPLEX_FIXUP_UYVY = 2,
83 COMPLEX_FIXUP_YV12 = 3,
84 COMPLEX_FIXUP_P8 = 4,
85};
86
87#include <pshpack2.h>
88struct color_fixup_desc
89{
90 unsigned x_sign_fixup : 1;
91 unsigned x_source : 3;
92 unsigned y_sign_fixup : 1;
93 unsigned y_source : 3;
94 unsigned z_sign_fixup : 1;
95 unsigned z_source : 3;
96 unsigned w_sign_fixup : 1;
97 unsigned w_source : 3;
98};
99#include <poppack.h>
100
101static const struct color_fixup_desc COLOR_FIXUP_IDENTITY =
102 {0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W};
103
104static inline struct color_fixup_desc create_color_fixup_desc(
105 int sign0, enum fixup_channel_source src0, int sign1, enum fixup_channel_source src1,
106 int sign2, enum fixup_channel_source src2, int sign3, enum fixup_channel_source src3)
107{
108 struct color_fixup_desc fixup =
109 {
110 sign0, src0,
111 sign1, src1,
112 sign2, src2,
113 sign3, src3,
114 };
115 return fixup;
116}
117
118static inline struct color_fixup_desc create_complex_fixup_desc(enum complex_fixup complex_fixup)
119{
120 struct color_fixup_desc fixup =
121 {
122 0, complex_fixup & (1 << 0) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
123 0, complex_fixup & (1 << 1) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
124 0, complex_fixup & (1 << 2) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
125 0, complex_fixup & (1 << 3) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
126 };
127 return fixup;
128}
129
130static inline BOOL is_identity_fixup(struct color_fixup_desc fixup)
131{
132 return !memcmp(&fixup, &COLOR_FIXUP_IDENTITY, sizeof(fixup));
133}
134
135static inline BOOL is_complex_fixup(struct color_fixup_desc fixup)
136{
137 return fixup.x_source == CHANNEL_SOURCE_COMPLEX0 || fixup.x_source == CHANNEL_SOURCE_COMPLEX1;
138}
139
140static inline enum complex_fixup get_complex_fixup(struct color_fixup_desc fixup)
141{
142 enum complex_fixup complex_fixup = 0;
143 if (fixup.x_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1 << 0);
144 if (fixup.y_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1 << 1);
145 if (fixup.z_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1 << 2);
146 if (fixup.w_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1 << 3);
147 return complex_fixup;
148}
149
150void *wined3d_rb_alloc(size_t size) DECLSPEC_HIDDEN;
151void *wined3d_rb_realloc(void *ptr, size_t size) DECLSPEC_HIDDEN;
152void wined3d_rb_free(void *ptr) DECLSPEC_HIDDEN;
153
154/* Device caps */
155#define MAX_PALETTES 65536
156#define MAX_STREAMS 16
157#define MAX_TEXTURES 8
158#define MAX_FRAGMENT_SAMPLERS 16
159#define MAX_VERTEX_SAMPLERS 4
160#define MAX_COMBINED_SAMPLERS (MAX_FRAGMENT_SAMPLERS + MAX_VERTEX_SAMPLERS)
161#define MAX_ACTIVE_LIGHTS 8
162#define MAX_CLIPPLANES WINED3DMAXUSERCLIPPLANES
163
164struct min_lookup
165{
166 GLenum mip[WINED3DTEXF_LINEAR + 1];
167};
168
169const struct min_lookup minMipLookup[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN;
170const struct min_lookup minMipLookup_noFilter[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN;
171const struct min_lookup minMipLookup_noMip[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN;
172const GLenum magLookup[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN;
173const GLenum magLookup_noFilter[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN;
174
175static inline GLenum wined3d_gl_mag_filter(const GLenum mag_lookup[], WINED3DTEXTUREFILTERTYPE mag_filter)
176{
177 return mag_lookup[mag_filter];
178}
179
180static inline GLenum wined3d_gl_min_mip_filter(const struct min_lookup min_mip_lookup[],
181 WINED3DTEXTUREFILTERTYPE min_filter, WINED3DTEXTUREFILTERTYPE mip_filter)
182{
183 return min_mip_lookup[min_filter].mip[mip_filter];
184}
185
186/* float_16_to_32() and float_32_to_16() (see implementation in
187 * surface_base.c) convert 16 bit floats in the FLOAT16 data type
188 * to standard C floats and vice versa. They do not depend on the encoding
189 * of the C float, so they are platform independent, but slow. On x86 and
190 * other IEEE 754 compliant platforms the conversion can be accelerated by
191 * bit shifting the exponent and mantissa. There are also some SSE-based
192 * assembly routines out there.
193 *
194 * See GL_NV_half_float for a reference of the FLOAT16 / GL_HALF format
195 */
196static inline float float_16_to_32(const unsigned short *in) {
197 unsigned long fNaN = 0x7fc00000;
198 unsigned long fNegInf = 0xff800000;
199 unsigned long fInf = 0x7f800000;
200
201 const unsigned short s = ((*in) & 0x8000);
202 const unsigned short e = ((*in) & 0x7C00) >> 10;
203 const unsigned short m = (*in) & 0x3FF;
204 const float sgn = (s ? -1.0f : 1.0f);
205
206 if(e == 0) {
207 if(m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
208 else return sgn * pow(2, -14.0f) * ((float)m / 1024.0f);
209 } else if(e < 31) {
210 return sgn * pow(2, (float)e - 15.0f) * (1.0f + ((float)m / 1024.0f));
211 } else {
212 if(m == 0) return sgn>0? *(float*)(&fInf) : *(float*)(&fNegInf); //sgn / 0.0f; /* +INF / -INF */
213 else return *(float*)(&fNaN); //0.0f / 0.0f; /* NAN */
214 }
215}
216
217static inline float float_24_to_32(DWORD in)
218{
219 const float sgn = in & 0x800000 ? -1.0f : 1.0f;
220 const unsigned short e = (in & 0x780000) >> 19;
221 const unsigned short m = in & 0x7ffff;
222 unsigned long fNaN = 0x7fc00000;
223 unsigned long fNegInf = 0xff800000;
224 unsigned long fInf = 0x7f800000;
225
226 if (e == 0)
227 {
228 if (m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
229 else return sgn * pow(2, -6.0f) * ((float)m / 524288.0f);
230 }
231 else if (e < 15)
232 {
233 return sgn * pow(2, (float)e - 7.0f) * (1.0f + ((float)m / 524288.0f));
234 }
235 else
236 {
237 if (m == 0) return sgn>0? *(float*)(&fInf) : *(float*)(&fNegInf); //sgn / 0.0f; /* +INF / -INF */
238 else return *(float*)(&fNaN); //0.0f / 0.0f; /* NAN */
239 }
240}
241
242/**
243 * Settings
244 */
245#define VS_NONE 0
246#define VS_HW 1
247
248#define PS_NONE 0
249#define PS_HW 1
250
251#define VBO_NONE 0
252#define VBO_HW 1
253
254#define ORM_BACKBUFFER 0
255#define ORM_FBO 1
256
257#define SHADER_ARB 1
258#define SHADER_GLSL 2
259#define SHADER_ATI 3
260#define SHADER_NONE 4
261
262#define RTL_DISABLE -1
263#define RTL_READDRAW 1
264#define RTL_READTEX 2
265
266#define PCI_VENDOR_NONE 0xffff /* e.g. 0x8086 for Intel and 0x10de for Nvidia */
267#define PCI_DEVICE_NONE 0xffff /* e.g. 0x14f for a Geforce6200 */
268
269/* NOTE: When adding fields to this structure, make sure to update the default
270 * values in wined3d_main.c as well. */
271typedef struct wined3d_settings_s {
272/* vertex and pixel shader modes */
273 int vs_mode;
274 int ps_mode;
275/* Ideally, we don't want the user to have to request GLSL. If the hardware supports GLSL,
276 we should use it. However, until it's fully implemented, we'll leave it as a registry
277 setting for developers. */
278 BOOL glslRequested;
279 int offscreen_rendering_mode;
280 int rendertargetlock_mode;
281 unsigned short pci_vendor_id;
282 unsigned short pci_device_id;
283/* Memory tracking and object counting */
284 unsigned int emulated_textureram;
285 char *logo;
286 int allow_multisampling;
287 BOOL strict_draw_ordering;
288} wined3d_settings_t;
289
290extern wined3d_settings_t wined3d_settings DECLSPEC_HIDDEN;
291
292typedef enum _WINED3DSAMPLER_TEXTURE_TYPE
293{
294 WINED3DSTT_UNKNOWN = 0,
295 WINED3DSTT_1D = 1,
296 WINED3DSTT_2D = 2,
297 WINED3DSTT_CUBE = 3,
298 WINED3DSTT_VOLUME = 4,
299} WINED3DSAMPLER_TEXTURE_TYPE;
300
301typedef enum _WINED3DSHADER_PARAM_REGISTER_TYPE
302{
303 WINED3DSPR_TEMP = 0,
304 WINED3DSPR_INPUT = 1,
305 WINED3DSPR_CONST = 2,
306 WINED3DSPR_ADDR = 3,
307 WINED3DSPR_TEXTURE = 3,
308 WINED3DSPR_RASTOUT = 4,
309 WINED3DSPR_ATTROUT = 5,
310 WINED3DSPR_TEXCRDOUT = 6,
311 WINED3DSPR_OUTPUT = 6,
312 WINED3DSPR_CONSTINT = 7,
313 WINED3DSPR_COLOROUT = 8,
314 WINED3DSPR_DEPTHOUT = 9,
315 WINED3DSPR_SAMPLER = 10,
316 WINED3DSPR_CONST2 = 11,
317 WINED3DSPR_CONST3 = 12,
318 WINED3DSPR_CONST4 = 13,
319 WINED3DSPR_CONSTBOOL = 14,
320 WINED3DSPR_LOOP = 15,
321 WINED3DSPR_TEMPFLOAT16 = 16,
322 WINED3DSPR_MISCTYPE = 17,
323 WINED3DSPR_LABEL = 18,
324 WINED3DSPR_PREDICATE = 19,
325 WINED3DSPR_IMMCONST,
326 WINED3DSPR_CONSTBUFFER,
327} WINED3DSHADER_PARAM_REGISTER_TYPE;
328
329enum wined3d_immconst_type
330{
331 WINED3D_IMMCONST_FLOAT,
332 WINED3D_IMMCONST_FLOAT4,
333};
334
335#define WINED3DSP_NOSWIZZLE (0 | (1 << 2) | (2 << 4) | (3 << 6))
336
337typedef enum _WINED3DSHADER_PARAM_SRCMOD_TYPE
338{
339 WINED3DSPSM_NONE = 0,
340 WINED3DSPSM_NEG = 1,
341 WINED3DSPSM_BIAS = 2,
342 WINED3DSPSM_BIASNEG = 3,
343 WINED3DSPSM_SIGN = 4,
344 WINED3DSPSM_SIGNNEG = 5,
345 WINED3DSPSM_COMP = 6,
346 WINED3DSPSM_X2 = 7,
347 WINED3DSPSM_X2NEG = 8,
348 WINED3DSPSM_DZ = 9,
349 WINED3DSPSM_DW = 10,
350 WINED3DSPSM_ABS = 11,
351 WINED3DSPSM_ABSNEG = 12,
352 WINED3DSPSM_NOT = 13,
353} WINED3DSHADER_PARAM_SRCMOD_TYPE;
354
355#define WINED3DSP_WRITEMASK_0 0x1 /* .x r */
356#define WINED3DSP_WRITEMASK_1 0x2 /* .y g */
357#define WINED3DSP_WRITEMASK_2 0x4 /* .z b */
358#define WINED3DSP_WRITEMASK_3 0x8 /* .w a */
359#define WINED3DSP_WRITEMASK_ALL 0xf /* all */
360
361typedef enum _WINED3DSHADER_PARAM_DSTMOD_TYPE
362{
363 WINED3DSPDM_NONE = 0,
364 WINED3DSPDM_SATURATE = 1,
365 WINED3DSPDM_PARTIALPRECISION = 2,
366 WINED3DSPDM_MSAMPCENTROID = 4,
367} WINED3DSHADER_PARAM_DSTMOD_TYPE;
368
369/* Undocumented opcode control to identify projective texture lookups in ps 2.0 and later */
370#define WINED3DSI_TEXLD_PROJECT 1
371#define WINED3DSI_TEXLD_BIAS 2
372
373typedef enum COMPARISON_TYPE
374{
375 COMPARISON_GT = 1,
376 COMPARISON_EQ = 2,
377 COMPARISON_GE = 3,
378 COMPARISON_LT = 4,
379 COMPARISON_NE = 5,
380 COMPARISON_LE = 6,
381} COMPARISON_TYPE;
382
383#define WINED3D_SM1_VS 0xfffe
384#define WINED3D_SM1_PS 0xffff
385#define WINED3D_SM4_PS 0x0000
386#define WINED3D_SM4_VS 0x0001
387#define WINED3D_SM4_GS 0x0002
388
389/* Shader version tokens, and shader end tokens */
390#define WINED3DPS_VERSION(major, minor) ((WINED3D_SM1_PS << 16) | ((major) << 8) | (minor))
391#define WINED3DVS_VERSION(major, minor) ((WINED3D_SM1_VS << 16) | ((major) << 8) | (minor))
392
393/* Shader backends */
394
395/* TODO: Make this dynamic, based on shader limits ? */
396#define MAX_ATTRIBS 16
397#define MAX_REG_ADDR 1
398#define MAX_REG_TEMP 32
399#define MAX_REG_TEXCRD 8
400#define MAX_REG_INPUT 12
401#define MAX_REG_OUTPUT 12
402#define MAX_CONST_I 16
403#define MAX_CONST_B 16
404
405/* FIXME: This needs to go up to 2048 for
406 * Shader model 3 according to msdn (and for software shaders) */
407#define MAX_LABELS 16
408
409#define SHADER_PGMSIZE 65535
410
411struct wined3d_shader_buffer
412{
413 char *buffer;
414 unsigned int bsize;
415 unsigned int lineNo;
416 BOOL newline;
417};
418
419enum WINED3D_SHADER_INSTRUCTION_HANDLER
420{
421 WINED3DSIH_ABS,
422 WINED3DSIH_ADD,
423 WINED3DSIH_BEM,
424 WINED3DSIH_BREAK,
425 WINED3DSIH_BREAKC,
426 WINED3DSIH_BREAKP,
427 WINED3DSIH_CALL,
428 WINED3DSIH_CALLNZ,
429 WINED3DSIH_CMP,
430 WINED3DSIH_CND,
431 WINED3DSIH_CRS,
432 WINED3DSIH_CUT,
433 WINED3DSIH_DCL,
434 WINED3DSIH_DEF,
435 WINED3DSIH_DEFB,
436 WINED3DSIH_DEFI,
437 WINED3DSIH_DP2ADD,
438 WINED3DSIH_DP3,
439 WINED3DSIH_DP4,
440 WINED3DSIH_DST,
441 WINED3DSIH_DSX,
442 WINED3DSIH_DSY,
443 WINED3DSIH_ELSE,
444 WINED3DSIH_EMIT,
445 WINED3DSIH_ENDIF,
446 WINED3DSIH_ENDLOOP,
447 WINED3DSIH_ENDREP,
448 WINED3DSIH_EXP,
449 WINED3DSIH_EXPP,
450 WINED3DSIH_FRC,
451 WINED3DSIH_IADD,
452 WINED3DSIH_IF,
453 WINED3DSIH_IFC,
454 WINED3DSIH_IGE,
455 WINED3DSIH_LABEL,
456 WINED3DSIH_LIT,
457 WINED3DSIH_LOG,
458 WINED3DSIH_LOGP,
459 WINED3DSIH_LOOP,
460 WINED3DSIH_LRP,
461 WINED3DSIH_LT,
462 WINED3DSIH_M3x2,
463 WINED3DSIH_M3x3,
464 WINED3DSIH_M3x4,
465 WINED3DSIH_M4x3,
466 WINED3DSIH_M4x4,
467 WINED3DSIH_MAD,
468 WINED3DSIH_MAX,
469 WINED3DSIH_MIN,
470 WINED3DSIH_MOV,
471 WINED3DSIH_MOVA,
472 WINED3DSIH_MUL,
473 WINED3DSIH_NOP,
474 WINED3DSIH_NRM,
475 WINED3DSIH_PHASE,
476 WINED3DSIH_POW,
477 WINED3DSIH_RCP,
478 WINED3DSIH_REP,
479 WINED3DSIH_RET,
480 WINED3DSIH_RSQ,
481 WINED3DSIH_SETP,
482 WINED3DSIH_SGE,
483 WINED3DSIH_SGN,
484 WINED3DSIH_SINCOS,
485 WINED3DSIH_SLT,
486 WINED3DSIH_SUB,
487 WINED3DSIH_TEX,
488 WINED3DSIH_TEXBEM,
489 WINED3DSIH_TEXBEML,
490 WINED3DSIH_TEXCOORD,
491 WINED3DSIH_TEXDEPTH,
492 WINED3DSIH_TEXDP3,
493 WINED3DSIH_TEXDP3TEX,
494 WINED3DSIH_TEXKILL,
495 WINED3DSIH_TEXLDD,
496 WINED3DSIH_TEXLDL,
497 WINED3DSIH_TEXM3x2DEPTH,
498 WINED3DSIH_TEXM3x2PAD,
499 WINED3DSIH_TEXM3x2TEX,
500 WINED3DSIH_TEXM3x3,
501 WINED3DSIH_TEXM3x3DIFF,
502 WINED3DSIH_TEXM3x3PAD,
503 WINED3DSIH_TEXM3x3SPEC,
504 WINED3DSIH_TEXM3x3TEX,
505 WINED3DSIH_TEXM3x3VSPEC,
506 WINED3DSIH_TEXREG2AR,
507 WINED3DSIH_TEXREG2GB,
508 WINED3DSIH_TEXREG2RGB,
509 WINED3DSIH_TABLE_SIZE
510};
511
512enum wined3d_shader_type
513{
514 WINED3D_SHADER_TYPE_PIXEL,
515 WINED3D_SHADER_TYPE_VERTEX,
516 WINED3D_SHADER_TYPE_GEOMETRY,
517};
518
519struct wined3d_shader_version
520{
521 enum wined3d_shader_type type;
522 BYTE major;
523 BYTE minor;
524};
525
526#define WINED3D_SHADER_VERSION(major, minor) (((major) << 8) | (minor))
527
528typedef struct shader_reg_maps
529{
530 struct wined3d_shader_version shader_version;
531 BYTE texcoord; /* MAX_REG_TEXCRD, 8 */
532 BYTE address; /* MAX_REG_ADDR, 1 */
533 WORD labels; /* MAX_LABELS, 16 */
534 DWORD temporary; /* MAX_REG_TEMP, 32 */
535 DWORD *constf; /* pixel, vertex */
536 DWORD texcoord_mask[MAX_REG_TEXCRD]; /* vertex < 3.0 */
537 WORD input_registers; /* max(MAX_REG_INPUT, MAX_ATTRIBS), 16 */
538 WORD output_registers; /* MAX_REG_OUTPUT, 12 */
539 WORD integer_constants; /* MAX_CONST_I, 16 */
540 WORD boolean_constants; /* MAX_CONST_B, 16 */
541 WORD local_int_consts; /* MAX_CONST_I, 16 */
542 WORD local_bool_consts; /* MAX_CONST_B, 16 */
543
544 WINED3DSAMPLER_TEXTURE_TYPE sampler_type[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)];
545 BYTE bumpmat; /* MAX_TEXTURES, 8 */
546 BYTE luminanceparams; /* MAX_TEXTURES, 8 */
547
548 WORD usesnrm : 1;
549 WORD vpos : 1;
550 WORD usesdsx : 1;
551 WORD usesdsy : 1;
552 WORD usestexldd : 1;
553 WORD usesmova : 1;
554 WORD usesfacing : 1;
555 WORD usesrelconstF : 1;
556 WORD fog : 1;
557 WORD usestexldl : 1;
558 WORD usesifc : 1;
559 WORD usescall : 1;
560 WORD padding : 4;
561
562 /* Whether or not loops are used in this shader, and nesting depth */
563 unsigned loop_depth;
564 unsigned highest_render_target;
565
566} shader_reg_maps;
567
568struct wined3d_shader_context
569{
570 IWineD3DBaseShader *shader;
571 const struct wined3d_gl_info *gl_info;
572 const struct shader_reg_maps *reg_maps;
573 struct wined3d_shader_buffer *buffer;
574 void *backend_data;
575};
576
577struct wined3d_shader_register
578{
579 WINED3DSHADER_PARAM_REGISTER_TYPE type;
580 UINT idx;
581 UINT array_idx;
582 const struct wined3d_shader_src_param *rel_addr;
583 enum wined3d_immconst_type immconst_type;
584 DWORD immconst_data[4];
585};
586
587struct wined3d_shader_dst_param
588{
589 struct wined3d_shader_register reg;
590 DWORD write_mask;
591 DWORD modifiers;
592 DWORD shift;
593};
594
595struct wined3d_shader_src_param
596{
597 struct wined3d_shader_register reg;
598 DWORD swizzle;
599 DWORD modifiers;
600};
601
602struct wined3d_shader_instruction
603{
604 const struct wined3d_shader_context *ctx;
605 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
606 DWORD flags;
607 BOOL coissue;
608 DWORD predicate;
609 UINT dst_count;
610 const struct wined3d_shader_dst_param *dst;
611 UINT src_count;
612 const struct wined3d_shader_src_param *src;
613};
614
615struct wined3d_shader_semantic
616{
617 WINED3DDECLUSAGE usage;
618 UINT usage_idx;
619 WINED3DSAMPLER_TEXTURE_TYPE sampler_type;
620 struct wined3d_shader_dst_param reg;
621};
622
623struct wined3d_shader_attribute
624{
625 WINED3DDECLUSAGE usage;
626 UINT usage_idx;
627};
628
629struct wined3d_shader_loop_control
630{
631 unsigned int count;
632 unsigned int start;
633 int step;
634};
635
636struct wined3d_shader_frontend
637{
638 void *(*shader_init)(const DWORD *ptr, const struct wined3d_shader_signature *output_signature);
639 void (*shader_free)(void *data);
640 void (*shader_read_header)(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version);
641 void (*shader_read_opcode)(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins, UINT *param_size);
642 void (*shader_read_src_param)(void *data, const DWORD **ptr, struct wined3d_shader_src_param *src_param,
643 struct wined3d_shader_src_param *src_rel_addr);
644 void (*shader_read_dst_param)(void *data, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param,
645 struct wined3d_shader_src_param *dst_rel_addr);
646 void (*shader_read_semantic)(const DWORD **ptr, struct wined3d_shader_semantic *semantic);
647 void (*shader_read_comment)(const DWORD **ptr, const char **comment, UINT *comment_size);
648 BOOL (*shader_is_end)(void *data, const DWORD **ptr);
649};
650
651extern const struct wined3d_shader_frontend sm1_shader_frontend DECLSPEC_HIDDEN;
652extern const struct wined3d_shader_frontend sm4_shader_frontend DECLSPEC_HIDDEN;
653
654typedef void (*SHADER_HANDLER)(const struct wined3d_shader_instruction *);
655
656struct shader_caps {
657 DWORD VertexShaderVersion;
658 DWORD MaxVertexShaderConst;
659
660 DWORD PixelShaderVersion;
661 float PixelShader1xMaxValue;
662 DWORD MaxPixelShaderConst;
663
664 WINED3DVSHADERCAPS2_0 VS20Caps;
665 WINED3DPSHADERCAPS2_0 PS20Caps;
666
667 DWORD MaxVShaderInstructionsExecuted;
668 DWORD MaxPShaderInstructionsExecuted;
669 DWORD MaxVertexShader30InstructionSlots;
670 DWORD MaxPixelShader30InstructionSlots;
671
672 BOOL VSClipping;
673};
674
675enum tex_types
676{
677 tex_1d = 0,
678 tex_2d = 1,
679 tex_3d = 2,
680 tex_cube = 3,
681 tex_rect = 4,
682 tex_type_count = 5,
683};
684
685enum vertexprocessing_mode {
686 fixedfunction,
687 vertexshader,
688 pretransformed
689};
690
691#define WINED3D_CONST_NUM_UNUSED ~0U
692
693enum fogmode {
694 FOG_OFF,
695 FOG_LINEAR,
696 FOG_EXP,
697 FOG_EXP2
698};
699
700/* Stateblock dependent parameters which have to be hardcoded
701 * into the shader code
702 */
703struct ps_compile_args {
704 struct color_fixup_desc color_fixup[MAX_FRAGMENT_SAMPLERS];
705 enum vertexprocessing_mode vp_mode;
706 enum fogmode fog;
707 /* Projected textures(ps 1.0-1.3) */
708 /* Texture types(2D, Cube, 3D) in ps 1.x */
709 BOOL srgb_correction;
710 WORD np2_fixup;
711 /* Bitmap for NP2 texcoord fixups (16 samplers max currently).
712 D3D9 has a limit of 16 samplers and the fixup is superfluous
713 in D3D10 (unconditional NP2 support mandatory). */
714};
715
716enum fog_src_type {
717 VS_FOG_Z = 0,
718 VS_FOG_COORD = 1
719};
720
721struct vs_compile_args {
722 BYTE fog_src;
723 BYTE clip_enabled;
724 WORD swizzle_map; /* MAX_ATTRIBS, 16 */
725};
726
727struct wined3d_context;
728
729typedef struct {
730 void (*shader_handle_instruction)(const struct wined3d_shader_instruction *);
731 void (*shader_select)(const struct wined3d_context *context, BOOL usePS, BOOL useVS);
732 void (*shader_select_depth_blt)(IWineD3DDevice *iface, enum tex_types tex_type);
733 void (*shader_deselect_depth_blt)(IWineD3DDevice *iface);
734 void (*shader_update_float_vertex_constants)(IWineD3DDevice *iface, UINT start, UINT count);
735 void (*shader_update_float_pixel_constants)(IWineD3DDevice *iface, UINT start, UINT count);
736 void (*shader_load_constants)(const struct wined3d_context *context, char usePS, char useVS);
737 void (*shader_load_np2fixup_constants)(IWineD3DDevice *iface, char usePS, char useVS);
738 void (*shader_destroy)(IWineD3DBaseShader *iface);
739 HRESULT (*shader_alloc_private)(IWineD3DDevice *iface);
740 void (*shader_free_private)(IWineD3DDevice *iface);
741 BOOL (*shader_dirtifyable_constants)(IWineD3DDevice *iface);
742 void (*shader_get_caps)(const struct wined3d_gl_info *gl_info, struct shader_caps *caps);
743 BOOL (*shader_color_fixup_supported)(struct color_fixup_desc fixup);
744 void (*shader_add_instruction_modifiers)(const struct wined3d_shader_instruction *ins);
745} shader_backend_t;
746
747extern const shader_backend_t glsl_shader_backend DECLSPEC_HIDDEN;
748extern const shader_backend_t arb_program_shader_backend DECLSPEC_HIDDEN;
749extern const shader_backend_t none_shader_backend DECLSPEC_HIDDEN;
750
751/* X11 locking */
752
753extern void (* CDECL wine_tsx11_lock_ptr)(void) DECLSPEC_HIDDEN;
754extern void (* CDECL wine_tsx11_unlock_ptr)(void) DECLSPEC_HIDDEN;
755
756/* As GLX relies on X, this is needed */
757extern int num_lock DECLSPEC_HIDDEN;
758
759#if 0
760#define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
761#define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
762#else
763#define ENTER_GL() wine_tsx11_lock_ptr()
764#define LEAVE_GL() wine_tsx11_unlock_ptr()
765#endif
766
767/*****************************************************************************
768 * Defines
769 */
770
771/* GL related defines */
772/* ------------------ */
773#define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
774
775#define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
776#define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
777#define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
778#define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
779
780#define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
781#define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
782#define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
783#define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
784
785#define D3DCOLORTOGLFLOAT4(dw, vec) do { \
786 (vec)[0] = D3DCOLOR_R(dw); \
787 (vec)[1] = D3DCOLOR_G(dw); \
788 (vec)[2] = D3DCOLOR_B(dw); \
789 (vec)[3] = D3DCOLOR_A(dw); \
790} while(0)
791
792/* DirectX Device Limits */
793/* --------------------- */
794#define MAX_MIP_LEVELS 32 /* Maximum number of mipmap levels. */
795#define HIGHEST_TRANSFORMSTATE WINED3DTS_WORLDMATRIX(255) /* Highest value in WINED3DTRANSFORMSTATETYPE */
796
797/* Checking of API calls */
798/* --------------------- */
799#ifndef WINE_NO_DEBUG_MSGS
800#define checkGLcall(A) \
801do { \
802 GLint err; \
803 if(!__WINE_IS_DEBUG_ON(_FIXME, __wine_dbch___default)) break; \
804 err = glGetError(); \
805 if (err == GL_NO_ERROR) { \
806 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
807 \
808 } else do { \
809 ERR(">>>>>>>>>>>>>>>>> %s (%#x) from %s @ %s / %d\n", \
810 debug_glerror(err), err, A, __FILE__, __LINE__); \
811 err = glGetError(); \
812 } while (err != GL_NO_ERROR); \
813} while(0)
814#else
815#define checkGLcall(A) do {} while(0)
816#endif
817
818/* Trace routines / diagnostics */
819/* ---------------------------- */
820
821/* Dump out a matrix and copy it */
822#define conv_mat(mat,gl_mat) \
823do { \
824 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
825 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
826 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
827 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
828 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
829} while (0)
830
831/* Trace vector and strided data information */
832#define TRACE_STRIDED(si, name) do { if (si->use_map & (1 << name)) \
833 TRACE( #name "=(data:%p, stride:%d, format:%#x, vbo %d, stream %u)\n", \
834 si->elements[name].data, si->elements[name].stride, si->elements[name].format_desc->format, \
835 si->elements[name].buffer_object, si->elements[name].stream_idx); } while(0)
836
837/* Advance declaration of structures to satisfy compiler */
838typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
839typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
840typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl;
841typedef struct IWineD3DDeviceImpl IWineD3DDeviceImpl;
842typedef struct IWineD3DSwapChainImpl IWineD3DSwapChainImpl;
843
844/* Global variables */
845extern const float identity[16] DECLSPEC_HIDDEN;
846
847/*****************************************************************************
848 * Compilable extra diagnostics
849 */
850
851/* TODO: Confirm each of these works when wined3d move completed */
852#if 0 /* NOTE: Must be 0 in cvs */
853 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
854 of each frame, a check is made for the existence of C:\D3DTRACE, and if it exists d3d trace
855 is enabled, and if it doesn't exist it is disabled. */
856# define FRAME_DEBUGGING
857 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
858 the file is deleted */
859# if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
860# define SINGLE_FRAME_DEBUGGING
861# endif
862 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
863 It can only be enabled when FRAME_DEBUGGING is also enabled
864 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
865 array is drawn. */
866# if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
867# define SHOW_FRAME_MAKEUP 1
868# endif
869 /* The following, when enabled, lets you see the makeup of the all the textures used during each
870 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
871 The contents of the textures assigned to each stage are written into
872 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
873# if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
874# define SHOW_TEXTURE_MAKEUP 0
875# endif
876extern BOOL isOn;
877extern BOOL isDumpingFrames;
878extern LONG primCounter;
879#endif
880
881enum wined3d_ffp_idx
882{
883 WINED3D_FFP_POSITION = 0,
884 WINED3D_FFP_BLENDWEIGHT = 1,
885 WINED3D_FFP_BLENDINDICES = 2,
886 WINED3D_FFP_NORMAL = 3,
887 WINED3D_FFP_PSIZE = 4,
888 WINED3D_FFP_DIFFUSE = 5,
889 WINED3D_FFP_SPECULAR = 6,
890 WINED3D_FFP_TEXCOORD0 = 7,
891 WINED3D_FFP_TEXCOORD1 = 8,
892 WINED3D_FFP_TEXCOORD2 = 9,
893 WINED3D_FFP_TEXCOORD3 = 10,
894 WINED3D_FFP_TEXCOORD4 = 11,
895 WINED3D_FFP_TEXCOORD5 = 12,
896 WINED3D_FFP_TEXCOORD6 = 13,
897 WINED3D_FFP_TEXCOORD7 = 14,
898};
899
900enum wined3d_ffp_emit_idx
901{
902 WINED3D_FFP_EMIT_FLOAT1 = 0,
903 WINED3D_FFP_EMIT_FLOAT2 = 1,
904 WINED3D_FFP_EMIT_FLOAT3 = 2,
905 WINED3D_FFP_EMIT_FLOAT4 = 3,
906 WINED3D_FFP_EMIT_D3DCOLOR = 4,
907 WINED3D_FFP_EMIT_UBYTE4 = 5,
908 WINED3D_FFP_EMIT_SHORT2 = 6,
909 WINED3D_FFP_EMIT_SHORT4 = 7,
910 WINED3D_FFP_EMIT_UBYTE4N = 8,
911 WINED3D_FFP_EMIT_SHORT2N = 9,
912 WINED3D_FFP_EMIT_SHORT4N = 10,
913 WINED3D_FFP_EMIT_USHORT2N = 11,
914 WINED3D_FFP_EMIT_USHORT4N = 12,
915 WINED3D_FFP_EMIT_UDEC3 = 13,
916 WINED3D_FFP_EMIT_DEC3N = 14,
917 WINED3D_FFP_EMIT_FLOAT16_2 = 15,
918 WINED3D_FFP_EMIT_FLOAT16_4 = 16,
919 WINED3D_FFP_EMIT_COUNT = 17
920};
921
922struct wined3d_stream_info_element
923{
924 const struct wined3d_format_desc *format_desc;
925 GLsizei stride;
926 const BYTE *data;
927 UINT stream_idx;
928 GLuint buffer_object;
929};
930
931struct wined3d_stream_info
932{
933 struct wined3d_stream_info_element elements[MAX_ATTRIBS];
934 BOOL position_transformed;
935 WORD swizzle_map; /* MAX_ATTRIBS, 16 */
936 WORD use_map; /* MAX_ATTRIBS, 16 */
937};
938
939/*****************************************************************************
940 * Prototypes
941 */
942
943/* Routine common to the draw primitive and draw indexed primitive routines */
944void drawPrimitive(IWineD3DDevice *iface, UINT index_count,
945 UINT start_idx, UINT idxBytes, const void *idxData) DECLSPEC_HIDDEN;
946DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) DECLSPEC_HIDDEN;
947
948typedef void (WINE_GLAPI *glAttribFunc)(const void *data);
949typedef void (WINE_GLAPI *glMultiTexCoordFunc)(GLenum unit, const void *data);
950extern glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
951extern glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
952extern glAttribFunc specular_func_3ubv DECLSPEC_HIDDEN;
953extern glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
954extern glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
955extern glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
956
957#define eps 1e-8
958
959#define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
960 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
961
962/* Routines and structures related to state management */
963
964#define STATE_RENDER(a) (a)
965#define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
966
967#define STATE_TEXTURESTAGE(stage, num) (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + 1 + (stage) * (WINED3D_HIGHEST_TEXTURE_STATE + 1) + (num))
968#define STATE_IS_TEXTURESTAGE(a) ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
969
970/* + 1 because samplers start with 0 */
971#define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
972#define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1))
973
974#define STATE_PIXELSHADER (STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1) + 1)
975#define STATE_IS_PIXELSHADER(a) ((a) == STATE_PIXELSHADER)
976
977#define STATE_TRANSFORM(a) (STATE_PIXELSHADER + (a))
978#define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)))
979
980#define STATE_STREAMSRC (STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)) + 1)
981#define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
982#define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
983#define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
984
985#define STATE_VDECL (STATE_INDEXBUFFER + 1)
986#define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
987
988#define STATE_VSHADER (STATE_VDECL + 1)
989#define STATE_IS_VSHADER(a) ((a) == STATE_VSHADER)
990
991#define STATE_VIEWPORT (STATE_VSHADER + 1)
992#define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
993
994#define STATE_VERTEXSHADERCONSTANT (STATE_VIEWPORT + 1)
995#define STATE_PIXELSHADERCONSTANT (STATE_VERTEXSHADERCONSTANT + 1)
996#define STATE_IS_VERTEXSHADERCONSTANT(a) ((a) == STATE_VERTEXSHADERCONSTANT)
997#define STATE_IS_PIXELSHADERCONSTANT(a) ((a) == STATE_PIXELSHADERCONSTANT)
998
999#define STATE_ACTIVELIGHT(a) (STATE_PIXELSHADERCONSTANT + (a) + 1)
1000#define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS))
1001
1002#define STATE_SCISSORRECT (STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS - 1) + 1)
1003#define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
1004
1005#define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
1006#define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(MAX_CLIPPLANES - 1))
1007
1008#define STATE_MATERIAL (STATE_CLIPPLANE(MAX_CLIPPLANES))
1009#define STATE_IS_MATERIAL(a) ((a) == STATE_MATERIAL)
1010
1011#define STATE_FRONTFACE (STATE_MATERIAL + 1)
1012#define STATE_IS_FRONTFACE(a) ((a) == STATE_FRONTFACE)
1013
1014#define STATE_HIGHEST (STATE_FRONTFACE)
1015
1016enum fogsource {
1017 FOGSOURCE_FFP,
1018 FOGSOURCE_VS,
1019 FOGSOURCE_COORD,
1020};
1021
1022#define WINED3D_MAX_FBO_ENTRIES 64
1023
1024struct wined3d_occlusion_query
1025{
1026 struct list entry;
1027 GLuint id;
1028 struct wined3d_context *context;
1029};
1030
1031union wined3d_gl_query_object
1032{
1033 GLuint id;
1034 GLsync sync;
1035};
1036
1037struct wined3d_event_query
1038{
1039 struct list entry;
1040 union wined3d_gl_query_object object;
1041 struct wined3d_context *context;
1042};
1043
1044enum wined3d_event_query_result
1045{
1046 WINED3D_EVENT_QUERY_OK,
1047 WINED3D_EVENT_QUERY_WAITING,
1048 WINED3D_EVENT_QUERY_NOT_STARTED,
1049 WINED3D_EVENT_QUERY_WRONG_THREAD,
1050 WINED3D_EVENT_QUERY_ERROR
1051};
1052
1053void wined3d_event_query_destroy(struct wined3d_event_query *query) DECLSPEC_HIDDEN;
1054enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_event_query *query, IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN;
1055enum wined3d_event_query_result wined3d_event_query_finish(struct wined3d_event_query *query, IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN;
1056void wined3d_event_query_issue(struct wined3d_event_query *query, IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN;
1057HRESULT wined3d_event_query_supported(const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
1058
1059struct wined3d_context
1060{
1061 const struct wined3d_gl_info *gl_info;
1062 /* State dirtification
1063 * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices
1064 * 0...numDirtyEntries - 1. isStateDirty is a redundant copy of the dirtyArray. Technically only one of them would be needed,
1065 * 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
1066 * only numDirtyEntries array elements have to be checked, not STATE_HIGHEST states.
1067 */
1068 DWORD dirtyArray[STATE_HIGHEST + 1]; /* Won't get bigger than that, a state is never marked dirty 2 times */
1069 DWORD numDirtyEntries;
1070 DWORD isStateDirty[STATE_HIGHEST / (sizeof(DWORD) * CHAR_BIT) + 1]; /* Bitmap to find out quickly if a state is dirty */
1071
1072 IWineD3DSwapChainImpl *swapchain;
1073 IWineD3DSurface *current_rt;
1074 DWORD tid; /* Thread ID which owns this context at the moment */
1075
1076 /* Stores some information about the context state for optimization */
1077 WORD render_offscreen : 1;
1078 WORD draw_buffer_dirty : 1;
1079 WORD last_was_rhw : 1; /* true iff last draw_primitive was in xyzrhw mode */
1080 WORD last_was_pshader : 1;
1081 WORD last_was_vshader : 1;
1082 WORD namedArraysLoaded : 1;
1083 WORD numberedArraysLoaded : 1;
1084 WORD last_was_blit : 1;
1085 WORD last_was_ckey : 1;
1086 WORD fog_coord : 1;
1087 WORD fog_enabled : 1;
1088 WORD num_untracked_materials : 2; /* Max value 2 */
1089 WORD current : 1;
1090 WORD destroyed : 1;
1091 WORD valid : 1;
1092 BYTE texShaderBumpMap; /* MAX_TEXTURES, 8 */
1093 BYTE lastWasPow2Texture; /* MAX_TEXTURES, 8 */
1094 DWORD numbered_array_mask;
1095 GLenum tracking_parm; /* Which source is tracking current colour */
1096 GLenum untracked_materials[2];
1097 UINT blit_w, blit_h;
1098 enum fogsource fog_source;
1099
1100 char *vshader_const_dirty, *pshader_const_dirty;
1101
1102 /* The actual opengl context */
1103 UINT level;
1104 HGLRC restore_ctx;
1105 HDC restore_dc;
1106 HGLRC glCtx;
1107 HWND win_handle;
1108 HDC hdc;
1109 int pixel_format;
1110 GLint aux_buffers;
1111
1112 /* FBOs */
1113 UINT fbo_entry_count;
1114 struct list fbo_list;
1115 struct list fbo_destroy_list;
1116 struct fbo_entry *current_fbo;
1117 GLuint src_fbo;
1118 GLuint dst_fbo;
1119 GLuint fbo_read_binding;
1120 GLuint fbo_draw_binding;
1121 BOOL rebind_fbo;
1122
1123 /* Queries */
1124 GLuint *free_occlusion_queries;
1125 UINT free_occlusion_query_size;
1126 UINT free_occlusion_query_count;
1127 struct list occlusion_queries;
1128
1129 union wined3d_gl_query_object *free_event_queries;
1130 UINT free_event_query_size;
1131 UINT free_event_query_count;
1132 struct list event_queries;
1133
1134 /* Extension emulation */
1135 GLint gl_fog_source;
1136 GLfloat fog_coord_value;
1137 GLfloat color[4], fogstart, fogend, fogcolor[4];
1138 GLuint dummy_arbfp_prog;
1139};
1140
1141typedef void (*APPLYSTATEFUNC)(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *ctx);
1142
1143struct StateEntry
1144{
1145 DWORD representative;
1146 APPLYSTATEFUNC apply;
1147};
1148
1149struct StateEntryTemplate
1150{
1151 DWORD state;
1152 struct StateEntry content;
1153 GL_SupportedExt extension;
1154};
1155
1156struct fragment_caps
1157{
1158 DWORD PrimitiveMiscCaps;
1159 DWORD TextureOpCaps;
1160 DWORD MaxTextureBlendStages;
1161 DWORD MaxSimultaneousTextures;
1162};
1163
1164struct fragment_pipeline
1165{
1166 void (*enable_extension)(IWineD3DDevice *iface, BOOL enable);
1167 void (*get_caps)(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps);
1168 HRESULT (*alloc_private)(IWineD3DDevice *iface);
1169 void (*free_private)(IWineD3DDevice *iface);
1170 BOOL (*color_fixup_supported)(struct color_fixup_desc fixup);
1171 const struct StateEntryTemplate *states;
1172 BOOL ffp_proj_control;
1173};
1174
1175extern const struct StateEntryTemplate misc_state_template[] DECLSPEC_HIDDEN;
1176extern const struct StateEntryTemplate ffp_vertexstate_template[] DECLSPEC_HIDDEN;
1177extern const struct fragment_pipeline ffp_fragment_pipeline DECLSPEC_HIDDEN;
1178extern const struct fragment_pipeline atifs_fragment_pipeline DECLSPEC_HIDDEN;
1179extern const struct fragment_pipeline arbfp_fragment_pipeline DECLSPEC_HIDDEN;
1180extern const struct fragment_pipeline nvts_fragment_pipeline DECLSPEC_HIDDEN;
1181extern const struct fragment_pipeline nvrc_fragment_pipeline DECLSPEC_HIDDEN;
1182
1183/* "Base" state table */
1184HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
1185 const struct wined3d_gl_info *gl_info, const struct StateEntryTemplate *vertex,
1186 const struct fragment_pipeline *fragment, const struct StateEntryTemplate *misc) DECLSPEC_HIDDEN;
1187
1188enum blit_operation
1189{
1190 BLIT_OP_BLIT,
1191 BLIT_OP_COLOR_FILL
1192};
1193
1194/* Shaders for color conversions in blits */
1195struct blit_shader
1196{
1197 HRESULT (*alloc_private)(IWineD3DDevice *iface);
1198 void (*free_private)(IWineD3DDevice *iface);
1199 HRESULT (*set_shader)(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface);
1200 void (*unset_shader)(IWineD3DDevice *iface);
1201 BOOL (*blit_supported)(const struct wined3d_gl_info *gl_info, enum blit_operation blit_op,
1202 const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool, const struct wined3d_format_desc *src_format_desc,
1203 const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool, const struct wined3d_format_desc *dst_format_desc);
1204 HRESULT (*color_fill)(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect, DWORD fill_color);
1205};
1206
1207extern const struct blit_shader ffp_blit DECLSPEC_HIDDEN;
1208extern const struct blit_shader arbfp_blit DECLSPEC_HIDDEN;
1209extern const struct blit_shader cpu_blit DECLSPEC_HIDDEN;
1210
1211/* Temporary blit_shader helper functions */
1212HRESULT arbfp_blit_surface(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *src_surface, const RECT *src_rect,
1213 IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect_in, enum blit_operation blit_op,
1214 DWORD Filter) DECLSPEC_HIDDEN;
1215
1216typedef enum ContextUsage {
1217 CTXUSAGE_RESOURCELOAD = 1, /* Only loads textures: No State is applied */
1218 CTXUSAGE_DRAWPRIM = 2, /* OpenGL states are set up for blitting DirectDraw surfaces */
1219 CTXUSAGE_BLIT = 3, /* OpenGL states are set up 3D drawing */
1220 CTXUSAGE_CLEAR = 4, /* Drawable and states are set up for clearing */
1221} ContextUsage;
1222
1223struct wined3d_context *context_acquire(IWineD3DDeviceImpl *This,
1224 IWineD3DSurface *target, enum ContextUsage usage) DECLSPEC_HIDDEN;
1225void context_alloc_event_query(struct wined3d_context *context,
1226 struct wined3d_event_query *query) DECLSPEC_HIDDEN;
1227void context_alloc_occlusion_query(struct wined3d_context *context,
1228 struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
1229void context_resource_released(IWineD3DDevice *iface,
1230 IWineD3DResource *resource, WINED3DRESOURCETYPE type) DECLSPEC_HIDDEN;
1231void context_bind_fbo(struct wined3d_context *context, GLenum target, GLuint *fbo) DECLSPEC_HIDDEN;
1232void context_attach_depth_stencil_fbo(struct wined3d_context *context,
1233 GLenum fbo_target, IWineD3DSurfaceImpl *depth_stencil, BOOL use_render_buffer) DECLSPEC_HIDDEN;
1234void context_attach_surface_fbo(const struct wined3d_context *context,
1235 GLenum fbo_target, DWORD idx, IWineD3DSurfaceImpl *surface) DECLSPEC_HIDDEN;
1236struct wined3d_context *context_create(IWineD3DSwapChainImpl *swapchain, IWineD3DSurfaceImpl *target,
1237 const struct wined3d_format_desc *ds_format_desc) DECLSPEC_HIDDEN;
1238void context_destroy(IWineD3DDeviceImpl *This, struct wined3d_context *context) DECLSPEC_HIDDEN;
1239void context_free_event_query(struct wined3d_event_query *query) DECLSPEC_HIDDEN;
1240void context_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
1241struct wined3d_context *context_get_current(void) DECLSPEC_HIDDEN;
1242DWORD context_get_tls_idx(void) DECLSPEC_HIDDEN;
1243void context_release(struct wined3d_context *context) DECLSPEC_HIDDEN;
1244BOOL context_set_current(struct wined3d_context *ctx) DECLSPEC_HIDDEN;
1245void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer) DECLSPEC_HIDDEN;
1246void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN;
1247void context_surface_update(struct wined3d_context *context, IWineD3DSurfaceImpl *surface) DECLSPEC_HIDDEN;
1248
1249/* Macros for doing basic GPU detection based on opengl capabilities */
1250#define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
1251#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])
1252#define WINE_D3D8_CAPABLE(gl_info) WINE_D3D7_CAPABLE(gl_info) && (gl_info->supported[ARB_MULTISAMPLE] && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
1253#define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER])
1254#define WINE_D3D10_CAPABLE(gl_info) WINE_D3D9_CAPABLE(gl_info) && (gl_info->supported[EXT_GPU_SHADER4])
1255
1256/*****************************************************************************
1257 * Internal representation of a light
1258 */
1259struct wined3d_light_info
1260{
1261 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
1262 DWORD OriginalIndex;
1263 LONG glIndex;
1264 BOOL enabled;
1265
1266 /* Converted parms to speed up swapping lights */
1267 float lightPosn[4];
1268 float lightDirn[4];
1269 float exponent;
1270 float cutoff;
1271
1272 struct list entry;
1273};
1274
1275/* The default light parameters */
1276extern const WINED3DLIGHT WINED3D_default_light DECLSPEC_HIDDEN;
1277
1278typedef struct WineD3D_PixelFormat
1279{
1280 int iPixelFormat; /* WGL pixel format */
1281 int iPixelType; /* WGL pixel type e.g. WGL_TYPE_RGBA_ARB, WGL_TYPE_RGBA_FLOAT_ARB or WGL_TYPE_COLORINDEX_ARB */
1282 int redSize, greenSize, blueSize, alphaSize, colorSize;
1283 int depthSize, stencilSize;
1284 BOOL windowDrawable;
1285 BOOL doubleBuffer;
1286 int auxBuffers;
1287 int numSamples;
1288} WineD3D_PixelFormat;
1289
1290enum wined3d_gl_vendor
1291{
1292 GL_VENDOR_UNKNOWN,
1293 GL_VENDOR_APPLE,
1294 GL_VENDOR_FGLRX,
1295 GL_VENDOR_INTEL,
1296 GL_VENDOR_MESA,
1297 GL_VENDOR_NVIDIA,
1298};
1299
1300
1301enum wined3d_pci_vendor
1302{
1303 HW_VENDOR_SOFTWARE = 0x0000,
1304 HW_VENDOR_ATI = 0x1002,
1305 HW_VENDOR_NVIDIA = 0x10de,
1306 HW_VENDOR_INTEL = 0x8086,
1307};
1308
1309enum wined3d_pci_device
1310{
1311 CARD_WINE = 0x0000,
1312
1313 CARD_ATI_RAGE_128PRO = 0x5246,
1314 CARD_ATI_RADEON_7200 = 0x5144,
1315 CARD_ATI_RADEON_8500 = 0x514c,
1316 CARD_ATI_RADEON_9500 = 0x4144,
1317 CARD_ATI_RADEON_XPRESS_200M = 0x5955,
1318 CARD_ATI_RADEON_X700 = 0x5e4c,
1319 CARD_ATI_RADEON_X1600 = 0x71c2,
1320 CARD_ATI_RADEON_HD2350 = 0x94c7,
1321 CARD_ATI_RADEON_HD2600 = 0x9581,
1322 CARD_ATI_RADEON_HD2900 = 0x9400,
1323 CARD_ATI_RADEON_HD3200 = 0x9620,
1324 CARD_ATI_RADEON_HD4350 = 0x954f,
1325 CARD_ATI_RADEON_HD4550 = 0x9540,
1326 CARD_ATI_RADEON_HD4600 = 0x9495,
1327 CARD_ATI_RADEON_HD4650 = 0x9498,
1328 CARD_ATI_RADEON_HD4670 = 0x9490,
1329 CARD_ATI_RADEON_HD4700 = 0x944e,
1330 CARD_ATI_RADEON_HD4770 = 0x94b3,
1331 CARD_ATI_RADEON_HD4800 = 0x944c, /* Picked one value between 9440, 944c, 9442, 9460 */
1332 CARD_ATI_RADEON_HD4830 = 0x944c,
1333 CARD_ATI_RADEON_HD4850 = 0x9442,
1334 CARD_ATI_RADEON_HD4870 = 0x9440,
1335 CARD_ATI_RADEON_HD4890 = 0x9460,
1336 CARD_ATI_RADEON_HD5700 = 0x68BE, /* Picked HD5750 */
1337 CARD_ATI_RADEON_HD5750 = 0x68BE,
1338 CARD_ATI_RADEON_HD5770 = 0x68B8,
1339 CARD_ATI_RADEON_HD5800 = 0x6898, /* Picked HD5850 */
1340 CARD_ATI_RADEON_HD5850 = 0x6898,
1341 CARD_ATI_RADEON_HD5870 = 0x6899,
1342
1343 CARD_NVIDIA_RIVA_128 = 0x0018,
1344 CARD_NVIDIA_RIVA_TNT = 0x0020,
1345 CARD_NVIDIA_RIVA_TNT2 = 0x0028,
1346 CARD_NVIDIA_GEFORCE = 0x0100,
1347 CARD_NVIDIA_GEFORCE2_MX = 0x0110,
1348 CARD_NVIDIA_GEFORCE2 = 0x0150,
1349 CARD_NVIDIA_GEFORCE3 = 0x0200,
1350 CARD_NVIDIA_GEFORCE4_MX = 0x0170,
1351 CARD_NVIDIA_GEFORCE4_TI4200 = 0x0253,
1352 CARD_NVIDIA_GEFORCEFX_5200 = 0x0320,
1353 CARD_NVIDIA_GEFORCEFX_5600 = 0x0312,
1354 CARD_NVIDIA_GEFORCEFX_5800 = 0x0302,
1355 CARD_NVIDIA_GEFORCE_6200 = 0x014f,
1356 CARD_NVIDIA_GEFORCE_6600GT = 0x0140,
1357 CARD_NVIDIA_GEFORCE_6800 = 0x0041,
1358 CARD_NVIDIA_GEFORCE_7400 = 0x01d8,
1359 CARD_NVIDIA_GEFORCE_7300 = 0x01d7, /* GeForce Go 7300 */
1360 CARD_NVIDIA_GEFORCE_7600 = 0x0391,
1361 CARD_NVIDIA_GEFORCE_7800GT = 0x0092,
1362 CARD_NVIDIA_GEFORCE_8100 = 0x084F,
1363 CARD_NVIDIA_GEFORCE_8200 = 0x0849, /* Other PCI ID 0x084B */
1364 CARD_NVIDIA_GEFORCE_8300GS = 0x0423,
1365 CARD_NVIDIA_GEFORCE_8400GS = 0x0404,
1366 CARD_NVIDIA_GEFORCE_8500GT = 0x0421,
1367 CARD_NVIDIA_GEFORCE_8600GT = 0x0402,
1368 CARD_NVIDIA_GEFORCE_8600MGT = 0x0407,
1369 CARD_NVIDIA_GEFORCE_8800GTS = 0x0193,
1370 CARD_NVIDIA_GEFORCE_9200 = 0x086d,
1371 CARD_NVIDIA_GEFORCE_9400GT = 0x042c,
1372 CARD_NVIDIA_GEFORCE_9500GT = 0x0640,
1373 CARD_NVIDIA_GEFORCE_9600GT = 0x0622,
1374 CARD_NVIDIA_GEFORCE_9800GT = 0x0614,
1375 CARD_NVIDIA_GEFORCE_GTX260 = 0x05e2,
1376 CARD_NVIDIA_GEFORCE_GTX275 = 0x05e6,
1377 CARD_NVIDIA_GEFORCE_GTX280 = 0x05e1,
1378 CARD_NVIDIA_GEFORCE_GT240 = 0x0ca3,
1379
1380 CARD_INTEL_845G = 0x2562,
1381 CARD_INTEL_I830G = 0x3577,
1382 CARD_INTEL_I855G = 0x3582,
1383 CARD_INTEL_I865G = 0x2572,
1384 CARD_INTEL_I915G = 0x2582,
1385 CARD_INTEL_I915GM = 0x2592,
1386 CARD_INTEL_I945GM = 0x27a2, /* Same as GMA 950? */
1387 CARD_INTEL_X3100 = 0x2a02, /* Found in Macs. Same as GMA 965? */
1388};
1389
1390struct wined3d_fbo_ops
1391{
1392 PGLFNGLISRENDERBUFFERPROC glIsRenderbuffer;
1393 PGLFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
1394 PGLFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
1395 PGLFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
1396 PGLFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
1397 PGLFNRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample;
1398 PGLFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv;
1399 PGLFNGLISFRAMEBUFFERPROC glIsFramebuffer;
1400 PGLFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
1401 PGLFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
1402 PGLFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
1403 PGLFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
1404 PGLFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D;
1405 PGLFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
1406 PGLFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D;
1407 PGLFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
1408 PGLFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv;
1409 PGLFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
1410 PGLFNGLGENERATEMIPMAPPROC glGenerateMipmap;
1411};
1412
1413struct wined3d_gl_limits
1414{
1415 UINT buffers;
1416 UINT lights;
1417 UINT textures;
1418 UINT texture_stages;
1419 UINT fragment_samplers;
1420 UINT vertex_samplers;
1421 UINT combined_samplers;
1422 UINT general_combiners;
1423 UINT sampler_stages;
1424 UINT clipplanes;
1425 UINT texture_size;
1426 UINT texture3d_size;
1427 float pointsize_max;
1428 float pointsize_min;
1429 UINT point_sprite_units;
1430 UINT blends;
1431 UINT anisotropy;
1432 float shininess;
1433
1434 UINT glsl_varyings;
1435 UINT glsl_vs_float_constants;
1436 UINT glsl_ps_float_constants;
1437
1438 UINT arb_vs_float_constants;
1439 UINT arb_vs_native_constants;
1440 UINT arb_vs_instructions;
1441 UINT arb_vs_temps;
1442 UINT arb_ps_float_constants;
1443 UINT arb_ps_local_constants;
1444 UINT arb_ps_native_constants;
1445 UINT arb_ps_instructions;
1446 UINT arb_ps_temps;
1447};
1448
1449struct wined3d_gl_info
1450{
1451 DWORD glsl_version;
1452 UINT vidmem;
1453 struct wined3d_gl_limits limits;
1454 DWORD reserved_glsl_constants;
1455 DWORD quirks;
1456 BOOL supported[WINED3D_GL_EXT_COUNT];
1457 GLint wrap_lookup[WINED3DTADDRESS_MIRRORONCE - WINED3DTADDRESS_WRAP + 1];
1458
1459 struct wined3d_fbo_ops fbo_ops;
1460#define USE_GL_FUNC(type, pfn, ext, replace) type pfn;
1461 /* GL function pointers */
1462 GL_EXT_FUNCS_GEN
1463 /* WGL function pointers */
1464 WGL_EXT_FUNCS_GEN
1465#undef USE_GL_FUNC
1466
1467 struct wined3d_format_desc *gl_formats;
1468};
1469
1470struct wined3d_driver_info
1471{
1472 enum wined3d_pci_vendor vendor;
1473 enum wined3d_pci_device device;
1474 const char *name;
1475 const char *description;
1476 DWORD version_high;
1477 DWORD version_low;
1478};
1479
1480/* The adapter structure */
1481struct wined3d_adapter
1482{
1483 UINT ordinal;
1484 BOOL opengl;
1485 POINT monitorPoint;
1486 struct wined3d_gl_info gl_info;
1487 struct wined3d_driver_info driver_info;
1488 WCHAR DeviceName[CCHDEVICENAME]; /* DeviceName for use with e.g. ChangeDisplaySettings */
1489 int nCfgs;
1490 WineD3D_PixelFormat *cfgs;
1491 BOOL brokenStencil; /* Set on cards which only offer mixed depth+stencil */
1492 unsigned int TextureRam; /* Amount of texture memory both video ram + AGP/TurboCache/HyperMemory/.. */
1493 unsigned int UsedTextureRam;
1494 LUID luid;
1495
1496 const struct fragment_pipeline *fragment_pipe;
1497 const shader_backend_t *shader_backend;
1498 const struct blit_shader *blitter;
1499};
1500
1501BOOL initPixelFormats(struct wined3d_gl_info *gl_info, enum wined3d_pci_vendor vendor) DECLSPEC_HIDDEN;
1502BOOL initPixelFormatsNoGL(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
1503extern long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram) DECLSPEC_HIDDEN;
1504extern void add_gl_compat_wrappers(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
1505
1506/*****************************************************************************
1507 * High order patch management
1508 */
1509struct WineD3DRectPatch
1510{
1511 UINT Handle;
1512 float *mem;
1513 WineDirect3DVertexStridedData strided;
1514 WINED3DRECTPATCH_INFO RectPatchInfo;
1515 float numSegs[4];
1516 char has_normals, has_texcoords;
1517 struct list entry;
1518};
1519
1520HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This, struct WineD3DRectPatch *patch) DECLSPEC_HIDDEN;
1521
1522enum projection_types
1523{
1524 proj_none = 0,
1525 proj_count3 = 1,
1526 proj_count4 = 2
1527};
1528
1529enum dst_arg
1530{
1531 resultreg = 0,
1532 tempreg = 1
1533};
1534
1535/*****************************************************************************
1536 * Fixed function pipeline replacements
1537 */
1538#define ARG_UNUSED 0xff
1539
1540struct texture_stage_op
1541{
1542 unsigned cop : 8;
1543 unsigned carg1 : 8;
1544 unsigned carg2 : 8;
1545 unsigned carg0 : 8;
1546
1547 unsigned aop : 8;
1548 unsigned aarg1 : 8;
1549 unsigned aarg2 : 8;
1550 unsigned aarg0 : 8;
1551
1552 struct color_fixup_desc color_fixup;
1553 unsigned tex_type : 3;
1554 unsigned dst : 1;
1555 unsigned projected : 2;
1556 unsigned padding : 10;
1557};
1558
1559struct ffp_frag_settings {
1560 struct texture_stage_op op[MAX_TEXTURES];
1561 enum fogmode fog;
1562 /* Use shorts instead of chars to get dword alignment */
1563 unsigned short sRGB_write;
1564 unsigned short emul_clipplanes;
1565};
1566
1567struct ffp_frag_desc
1568{
1569 struct wine_rb_entry entry;
1570 struct ffp_frag_settings settings;
1571};
1572
1573extern const struct wine_rb_functions wined3d_ffp_frag_program_rb_functions DECLSPEC_HIDDEN;
1574extern const struct wined3d_parent_ops wined3d_null_parent_ops DECLSPEC_HIDDEN;
1575
1576void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_settings *settings,
1577 BOOL ignore_textype) DECLSPEC_HIDDEN;
1578const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
1579 const struct ffp_frag_settings *settings) DECLSPEC_HIDDEN;
1580void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc) DECLSPEC_HIDDEN;
1581
1582/*****************************************************************************
1583 * IWineD3D implementation structure
1584 */
1585typedef struct IWineD3DImpl
1586{
1587 /* IUnknown fields */
1588 const IWineD3DVtbl *lpVtbl;
1589 LONG ref; /* Note: Ref counting not required */
1590
1591 /* WineD3D Information */
1592 IUnknown *parent;
1593 UINT dxVersion;
1594
1595 UINT adapter_count;
1596 struct wined3d_adapter adapters[1];
1597} IWineD3DImpl;
1598
1599HRESULT wined3d_init(IWineD3DImpl *wined3d, UINT version, IUnknown *parent) DECLSPEC_HIDDEN;
1600BOOL wined3d_register_window(HWND window, struct IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN;
1601void wined3d_unregister_window(HWND window) DECLSPEC_HIDDEN;
1602
1603/*****************************************************************************
1604 * IWineD3DDevice implementation structure
1605 */
1606#define WINED3D_UNMAPPED_STAGE ~0U
1607
1608/* Multithreaded flag. Removed from the public header to signal that IWineD3D::CreateDevice ignores it */
1609#define WINED3DCREATE_MULTITHREADED 0x00000004
1610
1611struct IWineD3DDeviceImpl
1612{
1613 /* IUnknown fields */
1614 const IWineD3DDeviceVtbl *lpVtbl;
1615 LONG ref; /* Note: Ref counting not required */
1616
1617 /* WineD3D Information */
1618 IUnknown *parent;
1619 IWineD3DDeviceParent *device_parent;
1620 IWineD3D *wined3d;
1621 struct wined3d_adapter *adapter;
1622
1623 /* Window styles to restore when switching fullscreen mode */
1624 LONG style;
1625 LONG exStyle;
1626
1627 /* X and GL Information */
1628 GLint maxConcurrentLights;
1629 GLenum offscreenBuffer;
1630
1631 /* Selected capabilities */
1632 int vs_selected_mode;
1633 int ps_selected_mode;
1634 const shader_backend_t *shader_backend;
1635 void *shader_priv;
1636 void *fragment_priv;
1637 void *blit_priv;
1638 struct StateEntry StateTable[STATE_HIGHEST + 1];
1639 /* Array of functions for states which are handled by more than one pipeline part */
1640 APPLYSTATEFUNC *multistate_funcs[STATE_HIGHEST + 1];
1641 const struct fragment_pipeline *frag_pipe;
1642 const struct blit_shader *blitter;
1643
1644 unsigned int max_ffp_textures;
1645 DWORD d3d_vshader_constantF, d3d_pshader_constantF; /* Advertised d3d caps, not GL ones */
1646 DWORD vs_clipping;
1647
1648 WORD view_ident : 1; /* true iff view matrix is identity */
1649 WORD untransformed : 1;
1650 WORD vertexBlendUsed : 1; /* To avoid needless setting of the blend matrices */
1651 WORD isRecordingState : 1;
1652 WORD isInDraw : 1;
1653 WORD bCursorVisible : 1;
1654 WORD haveHardwareCursor : 1;
1655 WORD d3d_initialized : 1;
1656 WORD inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */
1657 WORD softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */
1658 WORD useDrawStridedSlow : 1;
1659 WORD instancedDraw : 1;
1660 WORD filter_messages : 1;
1661 WORD padding : 3;
1662
1663 BYTE fixed_function_usage_map; /* MAX_TEXTURES, 8 */
1664
1665#define DDRAW_PITCH_ALIGNMENT 8
1666#define D3D8_PITCH_ALIGNMENT 4
1667 unsigned char surface_alignment; /* Line Alignment of surfaces */
1668
1669 /* State block related */
1670 IWineD3DStateBlockImpl *stateBlock;
1671 IWineD3DStateBlockImpl *updateStateBlock;
1672
1673 /* Internal use fields */
1674 WINED3DDEVICE_CREATION_PARAMETERS createParms;
1675 WINED3DDEVTYPE devType;
1676 HWND focus_window;
1677
1678 IWineD3DSwapChain **swapchains;
1679 UINT NumberOfSwapChains;
1680
1681 struct list resources; /* a linked list to track resources created by the device */
1682 struct list shaders; /* a linked list to track shaders (pixel and vertex) */
1683 unsigned int highest_dirty_ps_const, highest_dirty_vs_const;
1684
1685 /* Render Target Support */
1686 IWineD3DSurface **render_targets;
1687 IWineD3DSurface *auto_depth_stencil_buffer;
1688 IWineD3DSurface *stencilBufferTarget;
1689
1690 /* palettes texture management */
1691 UINT NumberOfPalettes;
1692 PALETTEENTRY **palettes;
1693 UINT currentPalette;
1694
1695 /* For rendering to a texture using glCopyTexImage */
1696 GLenum *draw_buffers;
1697 GLuint depth_blt_texture;
1698 GLuint depth_blt_rb;
1699 UINT depth_blt_rb_w;
1700 UINT depth_blt_rb_h;
1701
1702 /* Cursor management */
1703 UINT xHotSpot;
1704 UINT yHotSpot;
1705 UINT xScreenSpace;
1706 UINT yScreenSpace;
1707 UINT cursorWidth, cursorHeight;
1708 GLuint cursorTexture;
1709 HCURSOR hardwareCursor;
1710
1711 /* The Wine logo surface */
1712 IWineD3DSurface *logo_surface;
1713
1714 /* Textures for when no other textures are mapped */
1715 UINT dummyTextureName[MAX_TEXTURES];
1716
1717 /* DirectDraw stuff */
1718 DWORD ddraw_width, ddraw_height;
1719 WINED3DFORMAT ddraw_format;
1720
1721 /* Final position fixup constant */
1722 float posFixup[4];
1723
1724 /* With register combiners we can skip junk texture stages */
1725 DWORD texUnitMap[MAX_COMBINED_SAMPLERS];
1726 DWORD rev_tex_unit_map[MAX_COMBINED_SAMPLERS];
1727
1728 /* Stream source management */
1729 struct wined3d_stream_info strided_streams;
1730 const WineDirect3DVertexStridedData *up_strided;
1731 struct wined3d_event_query *buffer_queries[MAX_ATTRIBS];
1732 unsigned int num_buffer_queries;
1733
1734 /* Context management */
1735 struct wined3d_context **contexts;
1736 UINT numContexts;
1737
1738 /* High level patch management */
1739#define PATCHMAP_SIZE 43
1740#define PATCHMAP_HASHFUNC(x) ((x) % PATCHMAP_SIZE) /* Primitive and simple function */
1741 struct list patches[PATCHMAP_SIZE];
1742 struct WineD3DRectPatch *currentPatch;
1743};
1744
1745BOOL device_context_add(IWineD3DDeviceImpl *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
1746void device_context_remove(IWineD3DDeviceImpl *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
1747HRESULT device_init(IWineD3DDeviceImpl *device, IWineD3DImpl *wined3d,
1748 UINT adapter_idx, WINED3DDEVTYPE device_type, HWND focus_window, DWORD flags,
1749 IUnknown *parent, IWineD3DDeviceParent *device_parent) DECLSPEC_HIDDEN;
1750void device_preload_textures(IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN;
1751LRESULT device_process_message(IWineD3DDeviceImpl *device, HWND window,
1752 UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc) DECLSPEC_HIDDEN;
1753void device_resource_add(IWineD3DDeviceImpl *This, IWineD3DResource *resource) DECLSPEC_HIDDEN;
1754void device_resource_released(IWineD3DDeviceImpl *This, IWineD3DResource *resource) DECLSPEC_HIDDEN;
1755void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
1756 BOOL use_vshader, struct wined3d_stream_info *stream_info, BOOL *fixup) DECLSPEC_HIDDEN;
1757void device_update_stream_info(IWineD3DDeviceImpl *device, const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
1758HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, DWORD Count,
1759 const WINED3DRECT *pRects, DWORD Flags, WINED3DCOLOR Color, float Z, DWORD Stencil) DECLSPEC_HIDDEN;
1760void IWineD3DDeviceImpl_FindTexUnitMap(IWineD3DDeviceImpl *This) DECLSPEC_HIDDEN;
1761void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state) DECLSPEC_HIDDEN;
1762
1763static inline BOOL isStateDirty(struct wined3d_context *context, DWORD state)
1764{
1765 DWORD idx = state / (sizeof(*context->isStateDirty) * CHAR_BIT);
1766 BYTE shift = state & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
1767 return context->isStateDirty[idx] & (1 << shift);
1768}
1769
1770/* Support for IWineD3DResource ::Set/Get/FreePrivateData. */
1771typedef struct PrivateData
1772{
1773 struct list entry;
1774
1775 GUID tag;
1776 DWORD flags; /* DDSPD_* */
1777
1778 union
1779 {
1780 LPVOID data;
1781 LPUNKNOWN object;
1782 } ptr;
1783
1784 DWORD size;
1785} PrivateData;
1786
1787/*****************************************************************************
1788 * IWineD3DResource implementation structure
1789 */
1790typedef struct IWineD3DResourceClass
1791{
1792 /* IUnknown fields */
1793 LONG ref; /* Note: Ref counting not required */
1794
1795 /* WineD3DResource Information */
1796 IUnknown *parent;
1797 WINED3DRESOURCETYPE resourceType;
1798 IWineD3DDeviceImpl *device;
1799 WINED3DPOOL pool;
1800 UINT size;
1801 DWORD usage;
1802 const struct wined3d_format_desc *format_desc;
1803 DWORD priority;
1804 BYTE *allocatedMemory; /* Pointer to the real data location */
1805 BYTE *heapMemory; /* Pointer to the HeapAlloced block of memory */
1806 struct list privateData;
1807 struct list resource_list_entry;
1808 const struct wined3d_parent_ops *parent_ops;
1809} IWineD3DResourceClass;
1810
1811typedef struct IWineD3DResourceImpl
1812{
1813 /* IUnknown & WineD3DResource Information */
1814 const IWineD3DResourceVtbl *lpVtbl;
1815 IWineD3DResourceClass resource;
1816} IWineD3DResourceImpl;
1817
1818void resource_cleanup(IWineD3DResource *iface) DECLSPEC_HIDDEN;
1819HRESULT resource_free_private_data(IWineD3DResource *iface, REFGUID guid) DECLSPEC_HIDDEN;
1820HRESULT resource_get_parent(IWineD3DResource *iface, IUnknown **parent) DECLSPEC_HIDDEN;
1821DWORD resource_get_priority(IWineD3DResource *iface) DECLSPEC_HIDDEN;
1822HRESULT resource_get_private_data(IWineD3DResource *iface, REFGUID guid,
1823 void *data, DWORD *data_size) DECLSPEC_HIDDEN;
1824HRESULT resource_init(IWineD3DResource *iface, WINED3DRESOURCETYPE resource_type,
1825 IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct wined3d_format_desc *format_desc,
1826 WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
1827WINED3DRESOURCETYPE resource_get_type(IWineD3DResource *iface) DECLSPEC_HIDDEN;
1828DWORD resource_set_priority(IWineD3DResource *iface, DWORD new_priority) DECLSPEC_HIDDEN;
1829HRESULT resource_set_private_data(IWineD3DResource *iface, REFGUID guid,
1830 const void *data, DWORD data_size, DWORD flags) DECLSPEC_HIDDEN;
1831
1832/* Tests show that the start address of resources is 32 byte aligned */
1833#define RESOURCE_ALIGNMENT 16
1834
1835/*****************************************************************************
1836 * IWineD3DBaseTexture D3D- > openGL state map lookups
1837 */
1838
1839typedef enum winetexturestates {
1840 WINED3DTEXSTA_ADDRESSU = 0,
1841 WINED3DTEXSTA_ADDRESSV = 1,
1842 WINED3DTEXSTA_ADDRESSW = 2,
1843 WINED3DTEXSTA_BORDERCOLOR = 3,
1844 WINED3DTEXSTA_MAGFILTER = 4,
1845 WINED3DTEXSTA_MINFILTER = 5,
1846 WINED3DTEXSTA_MIPFILTER = 6,
1847 WINED3DTEXSTA_MAXMIPLEVEL = 7,
1848 WINED3DTEXSTA_MAXANISOTROPY = 8,
1849 WINED3DTEXSTA_SRGBTEXTURE = 9,
1850 WINED3DTEXSTA_ELEMENTINDEX = 10,
1851 WINED3DTEXSTA_DMAPOFFSET = 11,
1852 WINED3DTEXSTA_TSSADDRESSW = 12,
1853 MAX_WINETEXTURESTATES = 13,
1854} winetexturestates;
1855
1856enum WINED3DSRGB
1857{
1858 SRGB_ANY = 0, /* Uses the cached value(e.g. external calls) */
1859 SRGB_RGB = 1, /* Loads the rgb texture */
1860 SRGB_SRGB = 2, /* Loads the srgb texture */
1861 SRGB_BOTH = 3, /* Loads both textures */
1862};
1863
1864struct gl_texture
1865{
1866 DWORD states[MAX_WINETEXTURESTATES];
1867 BOOL dirty;
1868 GLuint name;
1869};
1870
1871/*****************************************************************************
1872 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
1873 */
1874typedef struct IWineD3DBaseTextureClass
1875{
1876 struct gl_texture texture_rgb, texture_srgb;
1877 UINT levels;
1878 float pow2Matrix[16];
1879 UINT LOD;
1880 WINED3DTEXTUREFILTERTYPE filterType;
1881 LONG bindCount;
1882 DWORD sampler;
1883 BOOL is_srgb;
1884 BOOL pow2Matrix_identity;
1885 const struct min_lookup *minMipLookup;
1886 const GLenum *magLookup;
1887 void (*internal_preload)(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb);
1888} IWineD3DBaseTextureClass;
1889
1890void surface_internal_preload(IWineD3DSurface *iface, enum WINED3DSRGB srgb) DECLSPEC_HIDDEN;
1891BOOL surface_init_sysmem(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
1892BOOL surface_is_offscreen(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
1893void surface_prepare_texture(IWineD3DSurfaceImpl *surface,
1894 const struct wined3d_gl_info *gl_info, BOOL srgb) DECLSPEC_HIDDEN;
1895
1896typedef struct IWineD3DBaseTextureImpl
1897{
1898 /* IUnknown & WineD3DResource Information */
1899 const IWineD3DBaseTextureVtbl *lpVtbl;
1900 IWineD3DResourceClass resource;
1901 IWineD3DBaseTextureClass baseTexture;
1902
1903} IWineD3DBaseTextureImpl;
1904
1905void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
1906 const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
1907 const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1],
1908 const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
1909HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surface_desc) DECLSPEC_HIDDEN;
1910void basetexture_cleanup(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
1911void basetexture_generate_mipmaps(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
1912WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
1913BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
1914DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
1915DWORD basetexture_get_lod(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
1916HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type,
1917 IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct wined3d_format_desc *format_desc,
1918 WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
1919HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface,
1920 WINED3DTEXTUREFILTERTYPE filter_type) DECLSPEC_HIDDEN;
1921BOOL basetexture_set_dirty(IWineD3DBaseTexture *iface, BOOL dirty) DECLSPEC_HIDDEN;
1922DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD new_lod) DECLSPEC_HIDDEN;
1923void basetexture_unload(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
1924
1925/*****************************************************************************
1926 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
1927 */
1928typedef struct IWineD3DTextureImpl
1929{
1930 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
1931 const IWineD3DTextureVtbl *lpVtbl;
1932 IWineD3DResourceClass resource;
1933 IWineD3DBaseTextureClass baseTexture;
1934
1935 /* IWineD3DTexture */
1936 IWineD3DSurface *surfaces[MAX_MIP_LEVELS];
1937 UINT target;
1938 BOOL cond_np2;
1939
1940} IWineD3DTextureImpl;
1941
1942HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
1943 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
1944 IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
1945
1946/*****************************************************************************
1947 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
1948 */
1949typedef struct IWineD3DCubeTextureImpl
1950{
1951 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
1952 const IWineD3DCubeTextureVtbl *lpVtbl;
1953 IWineD3DResourceClass resource;
1954 IWineD3DBaseTextureClass baseTexture;
1955
1956 /* IWineD3DCubeTexture */
1957 IWineD3DSurface *surfaces[6][MAX_MIP_LEVELS];
1958} IWineD3DCubeTextureImpl;
1959
1960HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
1961 IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
1962 IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
1963
1964typedef struct _WINED3DVOLUMET_DESC
1965{
1966 UINT Width;
1967 UINT Height;
1968 UINT Depth;
1969} WINED3DVOLUMET_DESC;
1970
1971/*****************************************************************************
1972 * IWineD3DVolume implementation structure (extends IUnknown)
1973 */
1974typedef struct IWineD3DVolumeImpl
1975{
1976 /* IUnknown & WineD3DResource fields */
1977 const IWineD3DVolumeVtbl *lpVtbl;
1978 IWineD3DResourceClass resource;
1979
1980 /* WineD3DVolume Information */
1981 WINED3DVOLUMET_DESC currentDesc;
1982 IWineD3DBase *container;
1983 BOOL lockable;
1984 BOOL locked;
1985 WINED3DBOX lockedBox;
1986 WINED3DBOX dirtyBox;
1987 BOOL dirty;
1988} IWineD3DVolumeImpl;
1989
1990void volume_add_dirty_box(IWineD3DVolume *iface, const WINED3DBOX *dirty_box) DECLSPEC_HIDDEN;
1991HRESULT volume_init(IWineD3DVolumeImpl *volume, IWineD3DDeviceImpl *device, UINT width,
1992 UINT height, UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
1993 IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
1994
1995/*****************************************************************************
1996 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
1997 */
1998typedef struct IWineD3DVolumeTextureImpl
1999{
2000 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
2001 const IWineD3DVolumeTextureVtbl *lpVtbl;
2002 IWineD3DResourceClass resource;
2003 IWineD3DBaseTextureClass baseTexture;
2004
2005 /* IWineD3DVolumeTexture */
2006 IWineD3DVolume *volumes[MAX_MIP_LEVELS];
2007} IWineD3DVolumeTextureImpl;
2008
2009HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height,
2010 UINT depth, UINT levels, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
2011 WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
2012
2013typedef struct _WINED3DSURFACET_DESC
2014{
2015 WINED3DMULTISAMPLE_TYPE MultiSampleType;
2016 DWORD MultiSampleQuality;
2017 UINT Width;
2018 UINT Height;
2019} WINED3DSURFACET_DESC;
2020
2021/*****************************************************************************
2022 * Structure for DIB Surfaces (GetDC and GDI surfaces)
2023 */
2024typedef struct wineD3DSurface_DIB {
2025 HBITMAP DIBsection;
2026 void* bitmap_data;
2027 UINT bitmap_size;
2028 HGDIOBJ holdbitmap;
2029 BOOL client_memory;
2030} wineD3DSurface_DIB;
2031
2032typedef struct {
2033 struct list entry;
2034 GLuint id;
2035 UINT width;
2036 UINT height;
2037} renderbuffer_entry_t;
2038
2039struct fbo_entry
2040{
2041 struct list entry;
2042 IWineD3DSurfaceImpl **render_targets;
2043 IWineD3DSurfaceImpl *depth_stencil;
2044 BOOL attached;
2045 GLuint id;
2046};
2047
2048/*****************************************************************************
2049 * IWineD3DClipp implementation structure
2050 */
2051typedef struct IWineD3DClipperImpl
2052{
2053 const IWineD3DClipperVtbl *lpVtbl;
2054 LONG ref;
2055
2056 IUnknown *Parent;
2057 HWND hWnd;
2058} IWineD3DClipperImpl;
2059
2060
2061/*****************************************************************************
2062 * IWineD3DSurface implementation structure
2063 */
2064struct IWineD3DSurfaceImpl
2065{
2066 /* IUnknown & IWineD3DResource Information */
2067 const IWineD3DSurfaceVtbl *lpVtbl;
2068 IWineD3DResourceClass resource;
2069
2070 /* IWineD3DSurface fields */
2071 IWineD3DBase *container;
2072 WINED3DSURFACET_DESC currentDesc;
2073 IWineD3DPaletteImpl *palette; /* D3D7 style palette handling */
2074 PALETTEENTRY *palette9; /* D3D8/9 style palette handling */
2075
2076 /* TODO: move this off into a management class(maybe!) */
2077 DWORD Flags;
2078
2079 UINT pow2Width;
2080 UINT pow2Height;
2081
2082 /* A method to retrieve the drawable size. Not in the Vtable to make it changeable */
2083 void (*get_drawable_size)(struct wined3d_context *context, UINT *width, UINT *height);
2084
2085 /* PBO */
2086 GLuint pbo;
2087 GLuint texture_name;
2088 GLuint texture_name_srgb;
2089 GLint texture_level;
2090 GLenum texture_target;
2091
2092 RECT lockedRect;
2093 RECT dirtyRect;
2094 int lockCount;
2095#define MAXLOCKCOUNT 50 /* After this amount of locks do not free the sysmem copy */
2096
2097 /* For GetDC */
2098 wineD3DSurface_DIB dib;
2099 HDC hDC;
2100
2101 /* Color keys for DDraw */
2102 WINEDDCOLORKEY DestBltCKey;
2103 WINEDDCOLORKEY DestOverlayCKey;
2104 WINEDDCOLORKEY SrcOverlayCKey;
2105 WINEDDCOLORKEY SrcBltCKey;
2106 DWORD CKeyFlags;
2107
2108 WINEDDCOLORKEY glCKey;
2109
2110 struct list renderbuffers;
2111 renderbuffer_entry_t *current_renderbuffer;
2112
2113 /* DirectDraw clippers */
2114 IWineD3DClipper *clipper;
2115
2116 /* DirectDraw Overlay handling */
2117 RECT overlay_srcrect;
2118 RECT overlay_destrect;
2119 IWineD3DSurfaceImpl *overlay_dest;
2120 struct list overlays;
2121 struct list overlay_entry;
2122};
2123
2124extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl DECLSPEC_HIDDEN;
2125extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl DECLSPEC_HIDDEN;
2126
2127UINT surface_calculate_size(const struct wined3d_format_desc *format_desc,
2128 UINT alignment, UINT width, UINT height) DECLSPEC_HIDDEN;
2129void surface_gdi_cleanup(IWineD3DSurfaceImpl *This) DECLSPEC_HIDDEN;
2130HRESULT surface_init(IWineD3DSurfaceImpl *surface, WINED3DSURFTYPE surface_type, UINT alignment,
2131 UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type,
2132 UINT multisample_quality, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
2133 WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
2134
2135/* Predeclare the shared Surface functions */
2136HRESULT WINAPI IWineD3DBaseSurfaceImpl_QueryInterface(IWineD3DSurface *iface,
2137 REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN;
2138ULONG WINAPI IWineD3DBaseSurfaceImpl_AddRef(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
2139HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent) DECLSPEC_HIDDEN;
2140HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPrivateData(IWineD3DSurface *iface,
2141 REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) DECLSPEC_HIDDEN;
2142HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPrivateData(IWineD3DSurface *iface,
2143 REFGUID refguid, void *pData, DWORD *pSizeOfData) DECLSPEC_HIDDEN;
2144HRESULT WINAPI IWineD3DBaseSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid) DECLSPEC_HIDDEN;
2145DWORD WINAPI IWineD3DBaseSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew) DECLSPEC_HIDDEN;
2146DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPriority(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
2147WINED3DRESOURCETYPE WINAPI IWineD3DBaseSurfaceImpl_GetType(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
2148HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetContainer(IWineD3DSurface* iface,
2149 REFIID riid, void **ppContainer) DECLSPEC_HIDDEN;
2150HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc) DECLSPEC_HIDDEN;
2151HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags) DECLSPEC_HIDDEN;
2152HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags) DECLSPEC_HIDDEN;
2153HRESULT WINAPI IWineD3DBaseSurfaceImpl_IsLost(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
2154HRESULT WINAPI IWineD3DBaseSurfaceImpl_Restore(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
2155HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal) DECLSPEC_HIDDEN;
2156HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal) DECLSPEC_HIDDEN;
2157HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetColorKey(IWineD3DSurface *iface,
2158 DWORD Flags, const WINEDDCOLORKEY *CKey) DECLSPEC_HIDDEN;
2159HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container) DECLSPEC_HIDDEN;
2160DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPitch(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
2161HRESULT WINAPI IWineD3DBaseSurfaceImpl_RealizePalette(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
2162HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetOverlayPosition(IWineD3DSurface *iface, LONG X, LONG Y) DECLSPEC_HIDDEN;
2163HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetOverlayPosition(IWineD3DSurface *iface, LONG *X, LONG *Y) DECLSPEC_HIDDEN;
2164HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface *iface,
2165 DWORD Flags, IWineD3DSurface *Ref) DECLSPEC_HIDDEN;
2166HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlay(IWineD3DSurface *iface, const RECT *SrcRect,
2167 IWineD3DSurface *DstSurface, const RECT *DstRect, DWORD Flags, const WINEDDOVERLAYFX *FX) DECLSPEC_HIDDEN;
2168HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetClipper(IWineD3DSurface *iface, IWineD3DClipper *clipper) DECLSPEC_HIDDEN;
2169HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetClipper(IWineD3DSurface *iface, IWineD3DClipper **clipper) DECLSPEC_HIDDEN;
2170HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format) DECLSPEC_HIDDEN;
2171HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
2172HRESULT WINAPI IWineD3DBaseSurfaceImpl_Blt(IWineD3DSurface *iface, const RECT *DestRect, IWineD3DSurface *SrcSurface,
2173 const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter) DECLSPEC_HIDDEN;
2174HRESULT WINAPI IWineD3DBaseSurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty,
2175 IWineD3DSurface *Source, const RECT *rsrc, DWORD trans) DECLSPEC_HIDDEN;
2176HRESULT WINAPI IWineD3DBaseSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DLOCKED_RECT *pLockedRect,
2177 const RECT *pRect, DWORD Flags) DECLSPEC_HIDDEN;
2178void WINAPI IWineD3DBaseSurfaceImpl_BindTexture(IWineD3DSurface *iface, BOOL srgb) DECLSPEC_HIDDEN;
2179const void *WINAPI IWineD3DBaseSurfaceImpl_GetData(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
2180
2181void get_drawable_size_swapchain(struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
2182void get_drawable_size_backbuffer(struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
2183void get_drawable_size_fbo(struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
2184
2185void draw_textured_quad(IWineD3DSurfaceImpl *src_surface, const RECT *src_rect,
2186 const RECT *dst_rect, WINED3DTEXTUREFILTERTYPE Filter) DECLSPEC_HIDDEN;
2187void flip_surface(IWineD3DSurfaceImpl *front, IWineD3DSurfaceImpl *back) DECLSPEC_HIDDEN;
2188
2189/* Surface flags: */
2190#define SFLAG_CONVERTED 0x00000002 /* Converted for color keying or Palettized */
2191#define SFLAG_DIBSECTION 0x00000004 /* Has a DIB section attached for GetDC */
2192#define SFLAG_LOCKABLE 0x00000008 /* Surface can be locked */
2193#define SFLAG_DISCARD 0x00000010 /* ??? */
2194#define SFLAG_LOCKED 0x00000020 /* Surface is locked atm */
2195#define SFLAG_INTEXTURE 0x00000040 /* The GL texture contains the newest surface content */
2196#define SFLAG_INSRGBTEX 0x00000080 /* The GL srgb texture contains the newest surface content */
2197#define SFLAG_INDRAWABLE 0x00000100 /* The gl drawable contains the most up to date data */
2198#define SFLAG_INSYSMEM 0x00000200 /* The system memory copy is most up to date */
2199#define SFLAG_NONPOW2 0x00000400 /* Surface sizes are not a power of 2 */
2200#define SFLAG_DYNLOCK 0x00000800 /* Surface is often locked by the app */
2201#define SFLAG_DCINUSE 0x00001000 /* Set between GetDC and ReleaseDC calls */
2202#define SFLAG_LOST 0x00002000 /* Surface lost flag for DDraw */
2203#define SFLAG_USERPTR 0x00004000 /* The application allocated the memory for this surface */
2204#define SFLAG_GLCKEY 0x00008000 /* The gl texture was created with a color key */
2205#define SFLAG_CLIENT 0x00010000 /* GL_APPLE_client_storage is used on that texture */
2206#define SFLAG_ALLOCATED 0x00020000 /* A gl texture is allocated for this surface */
2207#define SFLAG_SRGBALLOCATED 0x00040000 /* A srgb gl texture is allocated for this surface */
2208#define SFLAG_PBO 0x00080000 /* Has a PBO attached for speeding up data transfers for dynamically locked surfaces */
2209#define SFLAG_NORMCOORD 0x00100000 /* Set if the GL texture coords are normalized(non-texture rectangle) */
2210#define SFLAG_DS_ONSCREEN 0x00200000 /* Is a depth stencil, last modified onscreen */
2211#define SFLAG_DS_OFFSCREEN 0x00400000 /* Is a depth stencil, last modified offscreen */
2212#define SFLAG_INOVERLAYDRAW 0x00800000 /* Overlay drawing is in progress. Recursion prevention */
2213#define SFLAG_SWAPCHAIN 0x01000000 /* The surface is part of a swapchain */
2214
2215/* In some conditions the surface memory must not be freed:
2216 * SFLAG_CONVERTED: Converting the data back would take too long
2217 * SFLAG_DIBSECTION: The dib code manages the memory
2218 * SFLAG_LOCKED: The app requires access to the surface data
2219 * SFLAG_DYNLOCK: Avoid freeing the data for performance
2220 * SFLAG_PBO: PBOs don't use 'normal' memory. It is either allocated by the driver or must be NULL.
2221 * SFLAG_CLIENT: OpenGL uses our memory as backup
2222 */
2223#define SFLAG_DONOTFREE (SFLAG_CONVERTED | \
2224 SFLAG_DIBSECTION | \
2225 SFLAG_LOCKED | \
2226 SFLAG_DYNLOCK | \
2227 SFLAG_USERPTR | \
2228 SFLAG_PBO | \
2229 SFLAG_CLIENT)
2230
2231#define SFLAG_LOCATIONS (SFLAG_INSYSMEM | \
2232 SFLAG_INTEXTURE | \
2233 SFLAG_INDRAWABLE | \
2234 SFLAG_INSRGBTEX)
2235
2236#define SFLAG_DS_LOCATIONS (SFLAG_DS_ONSCREEN | \
2237 SFLAG_DS_OFFSCREEN)
2238#define SFLAG_DS_DISCARDED SFLAG_DS_LOCATIONS
2239
2240typedef enum {
2241 NO_CONVERSION,
2242 CONVERT_PALETTED,
2243 CONVERT_PALETTED_CK,
2244 CONVERT_CK_565,
2245 CONVERT_CK_5551,
2246 CONVERT_CK_4444,
2247 CONVERT_CK_4444_ARGB,
2248 CONVERT_CK_1555,
2249 CONVERT_555,
2250 CONVERT_CK_RGB24,
2251 CONVERT_CK_8888,
2252 CONVERT_CK_8888_ARGB,
2253 CONVERT_RGB32_888,
2254 CONVERT_V8U8,
2255 CONVERT_L6V5U5,
2256 CONVERT_X8L8V8U8,
2257 CONVERT_Q8W8V8U8,
2258 CONVERT_V16U16,
2259 CONVERT_A4L4,
2260 CONVERT_G16R16,
2261 CONVERT_R16G16F,
2262 CONVERT_R32G32F,
2263 CONVERT_D15S1,
2264 CONVERT_D24X4S4,
2265 CONVERT_D24FS8,
2266} CONVERT_TYPES;
2267
2268HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing,
2269 struct wined3d_format_desc *desc, CONVERT_TYPES *convert) DECLSPEC_HIDDEN;
2270void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey) DECLSPEC_HIDDEN;
2271
2272BOOL palette9_changed(IWineD3DSurfaceImpl *This) DECLSPEC_HIDDEN;
2273
2274/*****************************************************************************
2275 * IWineD3DVertexDeclaration implementation structure
2276 */
2277
2278struct wined3d_vertex_declaration_element
2279{
2280 const struct wined3d_format_desc *format_desc;
2281 BOOL ffp_valid;
2282 WORD input_slot;
2283 WORD offset;
2284 UINT output_slot;
2285 BYTE method;
2286 BYTE usage;
2287 BYTE usage_idx;
2288};
2289
2290typedef struct IWineD3DVertexDeclarationImpl {
2291 /* IUnknown Information */
2292 const IWineD3DVertexDeclarationVtbl *lpVtbl;
2293 LONG ref;
2294
2295 IUnknown *parent;
2296 const struct wined3d_parent_ops *parent_ops;
2297 IWineD3DDeviceImpl *device;
2298
2299 struct wined3d_vertex_declaration_element *elements;
2300 UINT element_count;
2301
2302 DWORD streams[MAX_STREAMS];
2303 UINT num_streams;
2304 BOOL position_transformed;
2305 BOOL half_float_conv_needed;
2306} IWineD3DVertexDeclarationImpl;
2307
2308HRESULT vertexdeclaration_init(IWineD3DVertexDeclarationImpl *declaration, IWineD3DDeviceImpl *device,
2309 const WINED3DVERTEXELEMENT *elements, UINT element_count,
2310 IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
2311
2312/*****************************************************************************
2313 * IWineD3DStateBlock implementation structure
2314 */
2315
2316/* Internal state Block for Begin/End/Capture/Create/Apply info */
2317/* Note: Very long winded but gl Lists are not flexible enough */
2318/* to resolve everything we need, so doing it manually for now */
2319typedef struct SAVEDSTATES {
2320 DWORD transform[(HIGHEST_TRANSFORMSTATE >> 5) + 1];
2321 WORD streamSource; /* MAX_STREAMS, 16 */
2322 WORD streamFreq; /* MAX_STREAMS, 16 */
2323 DWORD renderState[(WINEHIGHEST_RENDER_STATE >> 5) + 1];
2324 DWORD textureState[MAX_TEXTURES]; /* WINED3D_HIGHEST_TEXTURE_STATE + 1, 18 */
2325 WORD samplerState[MAX_COMBINED_SAMPLERS]; /* WINED3D_HIGHEST_SAMPLER_STATE + 1, 14 */
2326 DWORD clipplane; /* WINED3DMAXUSERCLIPPLANES, 32 */
2327 WORD pixelShaderConstantsB; /* MAX_CONST_B, 16 */
2328 WORD pixelShaderConstantsI; /* MAX_CONST_I, 16 */
2329 BOOL *pixelShaderConstantsF;
2330 WORD vertexShaderConstantsB; /* MAX_CONST_B, 16 */
2331 WORD vertexShaderConstantsI; /* MAX_CONST_I, 16 */
2332 BOOL *vertexShaderConstantsF;
2333 DWORD textures : 20; /* MAX_COMBINED_SAMPLERS, 20 */
2334 DWORD primitive_type : 1;
2335 DWORD indices : 1;
2336 DWORD material : 1;
2337 DWORD viewport : 1;
2338 DWORD vertexDecl : 1;
2339 DWORD pixelShader : 1;
2340 DWORD vertexShader : 1;
2341 DWORD scissorRect : 1;
2342 DWORD padding : 4;
2343} SAVEDSTATES;
2344
2345struct StageState {
2346 DWORD stage;
2347 DWORD state;
2348};
2349
2350struct IWineD3DStateBlockImpl
2351{
2352 /* IUnknown fields */
2353 const IWineD3DStateBlockVtbl *lpVtbl;
2354 LONG ref; /* Note: Ref counting not required */
2355
2356 /* IWineD3DStateBlock information */
2357 IWineD3DDeviceImpl *device;
2358 WINED3DSTATEBLOCKTYPE blockType;
2359
2360 /* Array indicating whether things have been set or changed */
2361 SAVEDSTATES changed;
2362
2363 /* Vertex Shader Declaration */
2364 IWineD3DVertexDeclaration *vertexDecl;
2365
2366 IWineD3DVertexShader *vertexShader;
2367
2368 /* Vertex Shader Constants */
2369 BOOL vertexShaderConstantB[MAX_CONST_B];
2370 INT vertexShaderConstantI[MAX_CONST_I * 4];
2371 float *vertexShaderConstantF;
2372
2373 /* primitive type */
2374 GLenum gl_primitive_type;
2375
2376 /* Stream Source */
2377 BOOL streamIsUP;
2378 UINT streamStride[MAX_STREAMS];
2379 UINT streamOffset[MAX_STREAMS + 1 /* tesselated pseudo-stream */ ];
2380 IWineD3DBuffer *streamSource[MAX_STREAMS];
2381 UINT streamFreq[MAX_STREAMS + 1];
2382 UINT streamFlags[MAX_STREAMS + 1]; /*0 | WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA */
2383
2384 /* Indices */
2385 IWineD3DBuffer* pIndexData;
2386 WINED3DFORMAT IndexFmt;
2387 INT baseVertexIndex;
2388 INT loadBaseVertexIndex; /* non-indexed drawing needs 0 here, indexed baseVertexIndex */
2389
2390 /* Transform */
2391 WINED3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
2392
2393 /* Light hashmap . Collisions are handled using standard wine double linked lists */
2394#define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
2395#define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
2396 struct list lightMap[LIGHTMAP_SIZE]; /* Hash map containing the lights */
2397 const struct wined3d_light_info *activeLights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
2398
2399 /* Clipping */
2400 double clipplane[MAX_CLIPPLANES][4];
2401 WINED3DCLIPSTATUS clip_status;
2402
2403 /* ViewPort */
2404 WINED3DVIEWPORT viewport;
2405
2406 /* Material */
2407 WINED3DMATERIAL material;
2408
2409 /* Pixel Shader */
2410 IWineD3DPixelShader *pixelShader;
2411
2412 /* Pixel Shader Constants */
2413 BOOL pixelShaderConstantB[MAX_CONST_B];
2414 INT pixelShaderConstantI[MAX_CONST_I * 4];
2415 float *pixelShaderConstantF;
2416
2417 /* RenderState */
2418 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
2419
2420 /* Texture */
2421 IWineD3DBaseTexture *textures[MAX_COMBINED_SAMPLERS];
2422
2423 /* Texture State Stage */
2424 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
2425 DWORD lowest_disabled_stage;
2426 /* Sampler States */
2427 DWORD samplerState[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
2428
2429 /* Scissor test rectangle */
2430 RECT scissorRect;
2431
2432 /* Contained state management */
2433 DWORD contained_render_states[WINEHIGHEST_RENDER_STATE + 1];
2434 unsigned int num_contained_render_states;
2435 DWORD contained_transform_states[HIGHEST_TRANSFORMSTATE + 1];
2436 unsigned int num_contained_transform_states;
2437 DWORD contained_vs_consts_i[MAX_CONST_I];
2438 unsigned int num_contained_vs_consts_i;
2439 DWORD contained_vs_consts_b[MAX_CONST_B];
2440 unsigned int num_contained_vs_consts_b;
2441 DWORD *contained_vs_consts_f;
2442 unsigned int num_contained_vs_consts_f;
2443 DWORD contained_ps_consts_i[MAX_CONST_I];
2444 unsigned int num_contained_ps_consts_i;
2445 DWORD contained_ps_consts_b[MAX_CONST_B];
2446 unsigned int num_contained_ps_consts_b;
2447 DWORD *contained_ps_consts_f;
2448 unsigned int num_contained_ps_consts_f;
2449 struct StageState contained_tss_states[MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)];
2450 unsigned int num_contained_tss_states;
2451 struct StageState contained_sampler_states[MAX_COMBINED_SAMPLERS * WINED3D_HIGHEST_SAMPLER_STATE];
2452 unsigned int num_contained_sampler_states;
2453};
2454
2455HRESULT stateblock_init(IWineD3DStateBlockImpl *stateblock,
2456 IWineD3DDeviceImpl *device, WINED3DSTATEBLOCKTYPE type) DECLSPEC_HIDDEN;
2457void stateblock_init_contained_states(IWineD3DStateBlockImpl *object) DECLSPEC_HIDDEN;
2458
2459static inline void stateblock_apply_state(DWORD state, IWineD3DStateBlockImpl *stateblock,
2460 struct wined3d_context *context)
2461{
2462 const struct StateEntry *statetable = stateblock->device->StateTable;
2463 DWORD rep = statetable[state].representative;
2464 statetable[rep].apply(rep, stateblock, context);
2465}
2466
2467/* Direct3D terminology with little modifications. We do not have an issued state
2468 * because only the driver knows about it, but we have a created state because d3d
2469 * allows GetData on a created issue, but opengl doesn't
2470 */
2471enum query_state {
2472 QUERY_CREATED,
2473 QUERY_SIGNALLED,
2474 QUERY_BUILDING
2475};
2476/*****************************************************************************
2477 * IWineD3DQueryImpl implementation structure (extends IUnknown)
2478 */
2479typedef struct IWineD3DQueryImpl
2480{
2481 const IWineD3DQueryVtbl *lpVtbl;
2482 LONG ref; /* Note: Ref counting not required */
2483
2484 IUnknown *parent;
2485 IWineD3DDeviceImpl *device;
2486
2487 /* IWineD3DQuery fields */
2488 enum query_state state;
2489 WINED3DQUERYTYPE type;
2490 /* TODO: Think about using a IUnknown instead of a void* */
2491 void *extendedData;
2492} IWineD3DQueryImpl;
2493
2494HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device,
2495 WINED3DQUERYTYPE type, IUnknown *parent) DECLSPEC_HIDDEN;
2496
2497/* IWineD3DBuffer */
2498
2499/* TODO: Add tests and support for FLOAT16_4 POSITIONT, D3DCOLOR position, other
2500 * fixed function semantics as D3DCOLOR or FLOAT16 */
2501enum wined3d_buffer_conversion_type
2502{
2503 CONV_NONE,
2504 CONV_D3DCOLOR,
2505 CONV_POSITIONT,
2506 CONV_FLOAT16_2, /* Also handles FLOAT16_4 */
2507};
2508
2509struct wined3d_map_range
2510{
2511 UINT offset;
2512 UINT size;
2513};
2514
2515#define WINED3D_BUFFER_OPTIMIZED 0x01 /* Optimize has been called for the buffer */
2516#define WINED3D_BUFFER_HASDESC 0x02 /* A vertex description has been found */
2517#define WINED3D_BUFFER_CREATEBO 0x04 /* Attempt to create a buffer object next PreLoad */
2518#define WINED3D_BUFFER_DOUBLEBUFFER 0x08 /* Use a vbo and local allocated memory */
2519#define WINED3D_BUFFER_FLUSH 0x10 /* Manual unmap flushing */
2520#define WINED3D_BUFFER_DISCARD 0x20 /* A DISCARD lock has occurred since the last PreLoad */
2521#define WINED3D_BUFFER_NOSYNC 0x40 /* All locks since the last PreLoad had NOOVERWRITE set */
2522#define WINED3D_BUFFER_APPLESYNC 0x80 /* Using sync as in GL_APPLE_flush_buffer_range */
2523
2524struct wined3d_buffer
2525{
2526 const struct IWineD3DBufferVtbl *vtbl;
2527 IWineD3DResourceClass resource;
2528
2529 struct wined3d_buffer_desc desc;
2530
2531 GLuint buffer_object;
2532 GLenum buffer_object_usage;
2533 GLenum buffer_type_hint;
2534 UINT buffer_object_size;
2535 LONG bind_count;
2536 DWORD flags;
2537
2538 LONG lock_count;
2539 struct wined3d_map_range *maps;
2540 ULONG maps_size, modified_areas;
2541 struct wined3d_event_query *query;
2542
2543 /* conversion stuff */
2544 UINT decl_change_count, full_conversion_count;
2545 UINT draw_count;
2546 UINT stride; /* 0 if no conversion */
2547 UINT conversion_stride; /* 0 if no shifted conversion */
2548 enum wined3d_buffer_conversion_type *conversion_map; /* NULL if no conversion */
2549 /* Extra load offsets, for FLOAT16 conversion */
2550 UINT *conversion_shift; /* NULL if no shifted conversion */
2551};
2552
2553const BYTE *buffer_get_memory(IWineD3DBuffer *iface, GLuint *buffer_object) DECLSPEC_HIDDEN;
2554BYTE *buffer_get_sysmem(struct wined3d_buffer *This) DECLSPEC_HIDDEN;
2555HRESULT buffer_init(struct wined3d_buffer *buffer, IWineD3DDeviceImpl *device,
2556 UINT size, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, GLenum bind_hint,
2557 const char *data, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
2558
2559/* IWineD3DRendertargetView */
2560struct wined3d_rendertarget_view
2561{
2562 const struct IWineD3DRendertargetViewVtbl *vtbl;
2563 LONG refcount;
2564
2565 IWineD3DResource *resource;
2566 IUnknown *parent;
2567};
2568
2569void wined3d_rendertarget_view_init(struct wined3d_rendertarget_view *view,
2570 IWineD3DResource *resource, IUnknown *parent) DECLSPEC_HIDDEN;
2571
2572/*****************************************************************************
2573 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
2574 */
2575
2576struct IWineD3DSwapChainImpl
2577{
2578 /*IUnknown part*/
2579 const IWineD3DSwapChainVtbl *lpVtbl;
2580 LONG ref; /* Note: Ref counting not required */
2581
2582 IUnknown *parent;
2583 IWineD3DDeviceImpl *device;
2584
2585 /* IWineD3DSwapChain fields */
2586 IWineD3DSurface **backBuffer;
2587 IWineD3DSurface *frontBuffer;
2588 WINED3DPRESENT_PARAMETERS presentParms;
2589 DWORD orig_width, orig_height;
2590 WINED3DFORMAT orig_fmt;
2591 WINED3DGAMMARAMP orig_gamma;
2592 BOOL render_to_fbo;
2593 const struct wined3d_format_desc *ds_format;
2594
2595 long prev_time, frames; /* Performance tracking */
2596 unsigned int vSyncCounter;
2597
2598 struct wined3d_context **context;
2599 unsigned int num_contexts;
2600
2601 HWND win_handle;
2602 HWND device_window;
2603};
2604
2605const IWineD3DSwapChainVtbl IWineGDISwapChain_Vtbl DECLSPEC_HIDDEN;
2606void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc) DECLSPEC_HIDDEN;
2607
2608HRESULT WINAPI IWineD3DBaseSwapChainImpl_QueryInterface(IWineD3DSwapChain *iface,
2609 REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN;
2610ULONG WINAPI IWineD3DBaseSwapChainImpl_AddRef(IWineD3DSwapChain *iface) DECLSPEC_HIDDEN;
2611ULONG WINAPI IWineD3DBaseSwapChainImpl_Release(IWineD3DSwapChain *iface) DECLSPEC_HIDDEN;
2612HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetParent(IWineD3DSwapChain *iface, IUnknown **ppParent) DECLSPEC_HIDDEN;
2613HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetFrontBufferData(IWineD3DSwapChain *iface,
2614 IWineD3DSurface *pDestSurface) DECLSPEC_HIDDEN;
2615HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetBackBuffer(IWineD3DSwapChain *iface, UINT iBackBuffer,
2616 WINED3DBACKBUFFER_TYPE Type, IWineD3DSurface **ppBackBuffer) DECLSPEC_HIDDEN;
2617HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetRasterStatus(IWineD3DSwapChain *iface,
2618 WINED3DRASTER_STATUS *pRasterStatus) DECLSPEC_HIDDEN;
2619HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDisplayMode(IWineD3DSwapChain *iface,
2620 WINED3DDISPLAYMODE *pMode) DECLSPEC_HIDDEN;
2621HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDevice(IWineD3DSwapChain *iface,
2622 IWineD3DDevice **ppDevice) DECLSPEC_HIDDEN;
2623HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetPresentParameters(IWineD3DSwapChain *iface,
2624 WINED3DPRESENT_PARAMETERS *pPresentationParameters) DECLSPEC_HIDDEN;
2625HRESULT WINAPI IWineD3DBaseSwapChainImpl_SetGammaRamp(IWineD3DSwapChain *iface,
2626 DWORD Flags, const WINED3DGAMMARAMP *pRamp) DECLSPEC_HIDDEN;
2627HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetGammaRamp(IWineD3DSwapChain *iface,
2628 WINED3DGAMMARAMP *pRamp) DECLSPEC_HIDDEN;
2629
2630struct wined3d_context *swapchain_create_context_for_thread(IWineD3DSwapChain *iface) DECLSPEC_HIDDEN;
2631HRESULT swapchain_init(IWineD3DSwapChainImpl *swapchain, WINED3DSURFTYPE surface_type,
2632 IWineD3DDeviceImpl *device, WINED3DPRESENT_PARAMETERS *present_parameters, IUnknown *parent) DECLSPEC_HIDDEN;
2633void swapchain_restore_fullscreen_window(IWineD3DSwapChainImpl *swapchain) DECLSPEC_HIDDEN;
2634void swapchain_setup_fullscreen_window(IWineD3DSwapChainImpl *swapchain, UINT w, UINT h) DECLSPEC_HIDDEN;
2635
2636#define DEFAULT_REFRESH_RATE 0
2637
2638/*****************************************************************************
2639 * Utility function prototypes
2640 */
2641
2642/* Trace routines */
2643const char *debug_d3dformat(WINED3DFORMAT fmt) DECLSPEC_HIDDEN;
2644const char *debug_d3ddevicetype(WINED3DDEVTYPE devtype) DECLSPEC_HIDDEN;
2645const char *debug_d3dresourcetype(WINED3DRESOURCETYPE res) DECLSPEC_HIDDEN;
2646const char *debug_d3dusage(DWORD usage) DECLSPEC_HIDDEN;
2647const char *debug_d3dusagequery(DWORD usagequery) DECLSPEC_HIDDEN;
2648const char *debug_d3ddeclmethod(WINED3DDECLMETHOD method) DECLSPEC_HIDDEN;
2649const char *debug_d3ddeclusage(BYTE usage) DECLSPEC_HIDDEN;
2650const char *debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType) DECLSPEC_HIDDEN;
2651const char *debug_d3drenderstate(DWORD state) DECLSPEC_HIDDEN;
2652const char *debug_d3dsamplerstate(DWORD state) DECLSPEC_HIDDEN;
2653const char *debug_d3dstate(DWORD state) DECLSPEC_HIDDEN;
2654const char *debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type) DECLSPEC_HIDDEN;
2655const char *debug_d3dtexturestate(DWORD state) DECLSPEC_HIDDEN;
2656const char *debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype) DECLSPEC_HIDDEN;
2657const char *debug_d3dpool(WINED3DPOOL pool) DECLSPEC_HIDDEN;
2658const char *debug_fbostatus(GLenum status) DECLSPEC_HIDDEN;
2659const char *debug_glerror(GLenum error) DECLSPEC_HIDDEN;
2660const char *debug_d3dbasis(WINED3DBASISTYPE basis) DECLSPEC_HIDDEN;
2661const char *debug_d3ddegree(WINED3DDEGREETYPE order) DECLSPEC_HIDDEN;
2662const char *debug_d3dtop(WINED3DTEXTUREOP d3dtop) DECLSPEC_HIDDEN;
2663void dump_color_fixup_desc(struct color_fixup_desc fixup) DECLSPEC_HIDDEN;
2664const char *debug_surflocation(DWORD flag) DECLSPEC_HIDDEN;
2665
2666/* Color conversion routines */
2667DWORD color_convert_argb_to_fmt(DWORD color, WINED3DFORMAT destfmt) DECLSPEC_HIDDEN;
2668
2669/* Routines for GL <-> D3D values */
2670GLenum StencilOp(DWORD op) DECLSPEC_HIDDEN;
2671GLenum CompareFunc(DWORD func) DECLSPEC_HIDDEN;
2672BOOL is_invalid_op(IWineD3DDeviceImpl *This, int stage, WINED3DTEXTUREOP op,
2673 DWORD arg1, DWORD arg2, DWORD arg3) DECLSPEC_HIDDEN;
2674void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op,
2675 DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst) DECLSPEC_HIDDEN;
2676void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords,
2677 BOOL transformed, WINED3DFORMAT coordtype, BOOL ffp_can_disable_proj) DECLSPEC_HIDDEN;
2678void texture_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock,
2679 struct wined3d_context *context) DECLSPEC_HIDDEN;
2680void sampler_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock,
2681 struct wined3d_context *context) DECLSPEC_HIDDEN;
2682void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock,
2683 struct wined3d_context *context) DECLSPEC_HIDDEN;
2684void apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock,
2685 struct wined3d_context *context) DECLSPEC_HIDDEN;
2686void state_fogcolor(DWORD state, IWineD3DStateBlockImpl *stateblock,
2687 struct wined3d_context *context) DECLSPEC_HIDDEN;
2688void state_fogdensity(DWORD state, IWineD3DStateBlockImpl *stateblock,
2689 struct wined3d_context *context) DECLSPEC_HIDDEN;
2690void state_fogstartend(DWORD state, IWineD3DStateBlockImpl *stateblock,
2691 struct wined3d_context *context) DECLSPEC_HIDDEN;
2692void state_fog_fragpart(DWORD state, IWineD3DStateBlockImpl *stateblock,
2693 struct wined3d_context *context) DECLSPEC_HIDDEN;
2694
2695void surface_add_dirty_rect(IWineD3DSurface *iface, const RECT *dirty_rect) DECLSPEC_HIDDEN;
2696GLenum surface_get_gl_buffer(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
2697void surface_load_ds_location(IWineD3DSurface *iface, struct wined3d_context *context, DWORD location) DECLSPEC_HIDDEN;
2698void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location) DECLSPEC_HIDDEN;
2699void surface_set_compatible_renderbuffer(IWineD3DSurface *iface,
2700 unsigned int width, unsigned int height) DECLSPEC_HIDDEN;
2701void surface_set_texture_name(IWineD3DSurface *iface, GLuint name, BOOL srgb_name) DECLSPEC_HIDDEN;
2702void surface_set_texture_target(IWineD3DSurface *iface, GLenum target) DECLSPEC_HIDDEN;
2703
2704BOOL getColorBits(const struct wined3d_format_desc *format_desc,
2705 short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize) DECLSPEC_HIDDEN;
2706BOOL getDepthStencilBits(const struct wined3d_format_desc *format_desc,
2707 short *depthSize, short *stencilSize) DECLSPEC_HIDDEN;
2708
2709/* Math utils */
2710void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2) DECLSPEC_HIDDEN;
2711UINT wined3d_log2i(UINT32 x) DECLSPEC_HIDDEN;
2712unsigned int count_bits(unsigned int mask) DECLSPEC_HIDDEN;
2713
2714void select_shader_mode(const struct wined3d_gl_info *gl_info, int *ps_selected, int *vs_selected) DECLSPEC_HIDDEN;
2715
2716typedef struct local_constant {
2717 struct list entry;
2718 unsigned int idx;
2719 DWORD value[4];
2720} local_constant;
2721
2722typedef struct SHADER_LIMITS {
2723 unsigned int temporary;
2724 unsigned int texcoord;
2725 unsigned int sampler;
2726 unsigned int constant_int;
2727 unsigned int constant_float;
2728 unsigned int constant_bool;
2729 unsigned int address;
2730 unsigned int packed_output;
2731 unsigned int packed_input;
2732 unsigned int attributes;
2733 unsigned int label;
2734} SHADER_LIMITS;
2735
2736/* Keeps track of details for TEX_M#x# shader opcodes which need to
2737 * maintain state information between multiple codes */
2738typedef struct SHADER_PARSE_STATE {
2739 unsigned int current_row;
2740 DWORD texcoord_w[2];
2741} SHADER_PARSE_STATE;
2742
2743#ifdef __GNUC__
2744#define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
2745#else
2746#define PRINTF_ATTR(fmt,args)
2747#endif
2748
2749/* Base Shader utility functions. */
2750int shader_addline(struct wined3d_shader_buffer *buffer, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
2751int shader_vaddline(struct wined3d_shader_buffer *buffer, const char *fmt, va_list args) DECLSPEC_HIDDEN;
2752
2753/* Vertex shader utility functions */
2754extern BOOL vshader_get_input(IWineD3DVertexShader *iface,
2755 BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum) DECLSPEC_HIDDEN;
2756
2757/*****************************************************************************
2758 * IDirect3DBaseShader implementation structure
2759 */
2760typedef struct IWineD3DBaseShaderClass
2761{
2762 LONG ref;
2763 SHADER_LIMITS limits;
2764 SHADER_PARSE_STATE parse_state;
2765 DWORD *function;
2766 UINT functionLength;
2767 UINT cur_loop_depth, cur_loop_regno;
2768 BOOL load_local_constsF;
2769 const struct wined3d_shader_frontend *frontend;
2770 void *frontend_data;
2771 void *backend_data;
2772
2773 IUnknown *parent;
2774 const struct wined3d_parent_ops *parent_ops;
2775
2776 /* Programs this shader is linked with */
2777 struct list linked_programs;
2778
2779 /* Immediate constants (override global ones) */
2780 struct list constantsB;
2781 struct list constantsF;
2782 struct list constantsI;
2783 shader_reg_maps reg_maps;
2784
2785 struct wined3d_shader_signature_element input_signature[max(MAX_ATTRIBS, MAX_REG_INPUT)];
2786 struct wined3d_shader_signature_element output_signature[MAX_REG_OUTPUT];
2787
2788 /* Pointer to the parent device */
2789 IWineD3DDevice *device;
2790 struct list shader_list_entry;
2791
2792} IWineD3DBaseShaderClass;
2793
2794typedef struct IWineD3DBaseShaderImpl {
2795 /* IUnknown */
2796 const IWineD3DBaseShaderVtbl *lpVtbl;
2797
2798 /* IWineD3DBaseShader */
2799 IWineD3DBaseShaderClass baseShader;
2800} IWineD3DBaseShaderImpl;
2801
2802void shader_buffer_clear(struct wined3d_shader_buffer *buffer) DECLSPEC_HIDDEN;
2803BOOL shader_buffer_init(struct wined3d_shader_buffer *buffer) DECLSPEC_HIDDEN;
2804void shader_buffer_free(struct wined3d_shader_buffer *buffer) DECLSPEC_HIDDEN;
2805void shader_dump_src_param(const struct wined3d_shader_src_param *param,
2806 const struct wined3d_shader_version *shader_version) DECLSPEC_HIDDEN;
2807void shader_dump_dst_param(const struct wined3d_shader_dst_param *param,
2808 const struct wined3d_shader_version *shader_version) DECLSPEC_HIDDEN;
2809unsigned int shader_find_free_input_register(const struct shader_reg_maps *reg_maps, unsigned int max) DECLSPEC_HIDDEN;
2810void shader_generate_main(IWineD3DBaseShader *iface, struct wined3d_shader_buffer *buffer,
2811 const shader_reg_maps *reg_maps, const DWORD *pFunction, void *backend_ctx) DECLSPEC_HIDDEN;
2812BOOL shader_match_semantic(const char *semantic_name, WINED3DDECLUSAGE usage) DECLSPEC_HIDDEN;
2813
2814static inline BOOL shader_is_pshader_version(enum wined3d_shader_type type)
2815{
2816 return type == WINED3D_SHADER_TYPE_PIXEL;
2817}
2818
2819static inline BOOL shader_is_vshader_version(enum wined3d_shader_type type)
2820{
2821 return type == WINED3D_SHADER_TYPE_VERTEX;
2822}
2823
2824static inline BOOL shader_is_scalar(const struct wined3d_shader_register *reg)
2825{
2826 switch (reg->type)
2827 {
2828 case WINED3DSPR_RASTOUT:
2829 /* oFog & oPts */
2830 if (reg->idx != 0) return TRUE;
2831 /* oPos */
2832 return FALSE;
2833
2834 case WINED3DSPR_DEPTHOUT: /* oDepth */
2835 case WINED3DSPR_CONSTBOOL: /* b# */
2836 case WINED3DSPR_LOOP: /* aL */
2837 case WINED3DSPR_PREDICATE: /* p0 */
2838 return TRUE;
2839
2840 case WINED3DSPR_MISCTYPE:
2841 switch(reg->idx)
2842 {
2843 case 0: /* vPos */
2844 return FALSE;
2845 case 1: /* vFace */
2846 return TRUE;
2847 default:
2848 return FALSE;
2849 }
2850
2851 case WINED3DSPR_IMMCONST:
2852 switch(reg->immconst_type)
2853 {
2854 case WINED3D_IMMCONST_FLOAT:
2855 return TRUE;
2856 default:
2857 return FALSE;
2858 }
2859
2860 default:
2861 return FALSE;
2862 }
2863}
2864
2865static inline BOOL shader_constant_is_local(IWineD3DBaseShaderImpl* This, DWORD reg) {
2866 local_constant* lconst;
2867
2868 if(This->baseShader.load_local_constsF) return FALSE;
2869 LIST_FOR_EACH_ENTRY(lconst, &This->baseShader.constantsF, local_constant, entry) {
2870 if(lconst->idx == reg) return TRUE;
2871 }
2872 return FALSE;
2873
2874}
2875
2876/*****************************************************************************
2877 * IDirect3DVertexShader implementation structures
2878 */
2879typedef struct IWineD3DVertexShaderImpl {
2880 /* IUnknown parts */
2881 const IWineD3DVertexShaderVtbl *lpVtbl;
2882
2883 /* IWineD3DBaseShader */
2884 IWineD3DBaseShaderClass baseShader;
2885
2886 /* Vertex shader attributes. */
2887 struct wined3d_shader_attribute attributes[MAX_ATTRIBS];
2888
2889 UINT min_rel_offset, max_rel_offset;
2890 UINT rel_offset;
2891} IWineD3DVertexShaderImpl;
2892
2893void find_vs_compile_args(IWineD3DVertexShaderImpl *shader, IWineD3DStateBlockImpl *stateblock,
2894 struct vs_compile_args *args) DECLSPEC_HIDDEN;
2895HRESULT vertexshader_init(IWineD3DVertexShaderImpl *shader, IWineD3DDeviceImpl *device,
2896 const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
2897 IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
2898
2899struct wined3d_geometryshader
2900{
2901 const struct IWineD3DGeometryShaderVtbl *vtbl;
2902 IWineD3DBaseShaderClass base_shader;
2903};
2904
2905HRESULT geometryshader_init(struct wined3d_geometryshader *shader, IWineD3DDeviceImpl *device,
2906 const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
2907 IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
2908
2909/*****************************************************************************
2910 * IDirect3DPixelShader implementation structure
2911 */
2912
2913/* Using additional shader constants (uniforms in GLSL / program environment
2914 * or local parameters in ARB) is costly:
2915 * ARB only knows float4 parameters and GLSL compiler are not really smart
2916 * when it comes to efficiently pack float2 uniforms, so no space is wasted
2917 * (in fact most compilers map a float2 to a full float4 uniform).
2918 *
2919 * For NP2 texcoord fixup we only need 2 floats (width and height) for each
2920 * 2D texture used in the shader. We therefore pack fixup info for 2 textures
2921 * into a single shader constant (uniform / program parameter).
2922 *
2923 * This structure is shared between the GLSL and the ARB backend.*/
2924struct ps_np2fixup_info {
2925 unsigned char idx[MAX_FRAGMENT_SAMPLERS]; /* indices to the real constant */
2926 WORD active; /* bitfield indicating if we can apply the fixup */
2927 WORD num_consts;
2928};
2929
2930typedef struct IWineD3DPixelShaderImpl {
2931 /* IUnknown parts */
2932 const IWineD3DPixelShaderVtbl *lpVtbl;
2933
2934 /* IWineD3DBaseShader */
2935 IWineD3DBaseShaderClass baseShader;
2936
2937 /* Pixel shader input semantics */
2938 DWORD input_reg_map[MAX_REG_INPUT];
2939 BOOL input_reg_used[MAX_REG_INPUT];
2940 unsigned int declared_in_count;
2941
2942 /* Some information about the shader behavior */
2943 char vpos_uniform;
2944
2945 BOOL color0_mov;
2946 DWORD color0_reg;
2947
2948} IWineD3DPixelShaderImpl;
2949
2950HRESULT pixelshader_init(IWineD3DPixelShaderImpl *shader, IWineD3DDeviceImpl *device,
2951 const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
2952 IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
2953void pixelshader_update_samplers(struct shader_reg_maps *reg_maps,
2954 IWineD3DBaseTexture * const *textures) DECLSPEC_HIDDEN;
2955void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock,
2956 struct ps_compile_args *args) DECLSPEC_HIDDEN;
2957
2958/* sRGB correction constants */
2959static const float srgb_cmp = 0.0031308f;
2960static const float srgb_mul_low = 12.92f;
2961static const float srgb_pow = 0.41666f;
2962static const float srgb_mul_high = 1.055f;
2963static const float srgb_sub_high = 0.055f;
2964
2965/*****************************************************************************
2966 * IWineD3DPalette implementation structure
2967 */
2968struct IWineD3DPaletteImpl {
2969 /* IUnknown parts */
2970 const IWineD3DPaletteVtbl *lpVtbl;
2971 LONG ref;
2972
2973 IUnknown *parent;
2974 IWineD3DDeviceImpl *device;
2975
2976 /* IWineD3DPalette */
2977 HPALETTE hpal;
2978 WORD palVersion; /*| */
2979 WORD palNumEntries; /*| LOGPALETTE */
2980 PALETTEENTRY palents[256]; /*| */
2981 /* This is to store the palette in 'screen format' */
2982 int screen_palents[256];
2983 DWORD Flags;
2984};
2985
2986HRESULT wined3d_palette_init(IWineD3DPaletteImpl *palette, IWineD3DDeviceImpl *device,
2987 DWORD flags, const PALETTEENTRY *entries, IUnknown *parent) DECLSPEC_HIDDEN;
2988
2989/* DirectDraw utility functions */
2990extern WINED3DFORMAT pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN;
2991
2992/*****************************************************************************
2993 * Pixel format management
2994 */
2995
2996/* WineD3D pixel format flags */
2997#define WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING 0x1
2998#define WINED3DFMT_FLAG_FILTERING 0x2
2999#define WINED3DFMT_FLAG_DEPTH 0x4
3000#define WINED3DFMT_FLAG_STENCIL 0x8
3001#define WINED3DFMT_FLAG_RENDERTARGET 0x10
3002#define WINED3DFMT_FLAG_FOURCC 0x20
3003#define WINED3DFMT_FLAG_FBO_ATTACHABLE 0x40
3004#define WINED3DFMT_FLAG_COMPRESSED 0x80
3005#define WINED3DFMT_FLAG_GETDC 0x100
3006#define WINED3DFMT_FLAG_FLOAT 0x200
3007
3008struct wined3d_format_desc
3009{
3010 WINED3DFORMAT format;
3011 DWORD red_mask;
3012 DWORD green_mask;
3013 DWORD blue_mask;
3014 DWORD alpha_mask;
3015 UINT byte_count;
3016 WORD depth_size;
3017 WORD stencil_size;
3018
3019 UINT block_width;
3020 UINT block_height;
3021 UINT block_byte_count;
3022
3023 enum wined3d_ffp_emit_idx emit_idx;
3024 GLint component_count;
3025 GLenum gl_vtx_type;
3026 GLint gl_vtx_format;
3027 GLboolean gl_normalized;
3028 unsigned int component_size;
3029
3030 GLint glInternal;
3031 GLint glGammaInternal;
3032 GLint rtInternal;
3033 GLint glFormat;
3034 GLint glType;
3035 UINT conv_byte_count;
3036 unsigned int Flags;
3037 float heightscale;
3038 struct color_fixup_desc color_fixup;
3039 void (*convert)(const BYTE *src, BYTE *dst, UINT pitch, UINT width, UINT height);
3040};
3041
3042const struct wined3d_format_desc *getFormatDescEntry(WINED3DFORMAT fmt,
3043 const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
3044
3045static inline BOOL use_vs(IWineD3DStateBlockImpl *stateblock)
3046{
3047 /* Check stateblock->vertexDecl to allow this to be used from
3048 * IWineD3DDeviceImpl_FindTexUnitMap(). This is safe because
3049 * stateblock->vertexShader implies a vertex declaration instead of ddraw
3050 * style strided data. */
3051 return (stateblock->vertexShader
3052 && !((IWineD3DVertexDeclarationImpl *)stateblock->vertexDecl)->position_transformed
3053 && stateblock->device->vs_selected_mode != SHADER_NONE);
3054}
3055
3056static inline BOOL use_ps(IWineD3DStateBlockImpl *stateblock)
3057{
3058 return (stateblock->pixelShader && stateblock->device->ps_selected_mode != SHADER_NONE);
3059}
3060
3061void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface,
3062 const RECT *src_rect, IWineD3DSurface *dst_surface, const RECT *dst_rect,
3063 const WINED3DTEXTUREFILTERTYPE filter) DECLSPEC_HIDDEN;
3064
3065/* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */
3066#define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL"
3067
3068#define WINEMAKEFOURCC(ch0, ch1, ch2, ch3) \
3069 ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
3070 ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))
3071
3072#define MAKEDWORD_VERSION(maj, min) (((maj & 0xffff) << 16) | (min & 0xffff))
3073
3074#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette