VirtualBox

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

最後變更 在這個檔案從39150是 39130,由 vboxsync 提交於 13 年 前

wddm: fix image inversion on Mac; debugging stuff

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

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