VirtualBox

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

Last change on this file since 20817 was 20612, checked in by vboxsync, 16 years ago

crOpenGL: update wine to 1.1.23

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