VirtualBox

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

Last change on this file since 41283 was 41109, checked in by vboxsync, 13 years ago

crOpenGL,wined3d,wddm: second part of fixing resource leakage, basics for cr commands submission from r0 miniport driver (for r0 visible region reporting, WPF 3D rendering fixes w/o Aero, etc.)

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

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