blob: f062c97f5ab419c116a207f1f5b45befcf247a26 [file] [log] [blame]
Raphael Junqueira01968612003-11-14 03:50:35 +00001/*
2 * Direct3D wine internal private include file
3 *
4 * Copyright 2002-2003 The wine-d3d team
5 * Copyright 2002-2003 Raphael Junqueira
Henri Verbeet7420a962009-05-01 09:13:54 +02006 * Copyright 2002-2003, 2004 Jason Edmeades
Oliver Stieber46e7c302005-06-23 11:05:24 +00007 * Copyright 2005 Oliver Stieber
Raphael Junqueira01968612003-11-14 03:50:35 +00008 *
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
Jonathan Ernst360a3f92006-05-18 14:49:52 +020021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Raphael Junqueira01968612003-11-14 03:50:35 +000022 */
23
24#ifndef __WINE_WINED3D_PRIVATE_H
25#define __WINE_WINED3D_PRIVATE_H
26
27#include <stdarg.h>
Jason Edmeades0a944ae2004-11-29 17:53:42 +000028#include <math.h>
Jason Edmeades24ab49e2004-09-23 04:34:27 +000029#define NONAMELESSUNION
30#define NONAMELESSSTRUCT
Jason Edmeades289562e2004-11-23 13:52:46 +000031#define COBJMACROS
Raphael Junqueira01968612003-11-14 03:50:35 +000032#include "windef.h"
33#include "winbase.h"
Jason Edmeades24ab49e2004-09-23 04:34:27 +000034#include "winreg.h"
Raphael Junqueira01968612003-11-14 03:50:35 +000035#include "wingdi.h"
36#include "winuser.h"
37#include "wine/debug.h"
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +000038#include "wine/unicode.h"
Raphael Junqueira01968612003-11-14 03:50:35 +000039
Henri Verbeeta6917b12008-11-25 11:57:39 +010040#include "objbase.h"
Henri Verbeeta6917b12008-11-25 11:57:39 +010041#include "wine/wined3d.h"
Henri Verbeet8899f342008-11-20 13:32:00 +010042#include "wined3d_gl.h"
Jason Green0c59ca62006-06-09 03:33:01 -040043#include "wine/list.h"
Raphael Junqueira01968612003-11-14 03:50:35 +000044
Henri Verbeet89139b72008-12-03 14:53:43 +010045/* Texture format fixups */
46
47enum fixup_channel_source
48{
49 CHANNEL_SOURCE_ZERO = 0,
50 CHANNEL_SOURCE_ONE = 1,
51 CHANNEL_SOURCE_X = 2,
52 CHANNEL_SOURCE_Y = 3,
53 CHANNEL_SOURCE_Z = 4,
54 CHANNEL_SOURCE_W = 5,
55 CHANNEL_SOURCE_YUV0 = 6,
56 CHANNEL_SOURCE_YUV1 = 7,
57};
58
59enum yuv_fixup
60{
61 YUV_FIXUP_YUY2 = 0,
62 YUV_FIXUP_UYVY = 1,
63 YUV_FIXUP_YV12 = 2,
64};
65
66#include <pshpack2.h>
67struct color_fixup_desc
68{
69 unsigned x_sign_fixup : 1;
70 unsigned x_source : 3;
71 unsigned y_sign_fixup : 1;
72 unsigned y_source : 3;
73 unsigned z_sign_fixup : 1;
74 unsigned z_source : 3;
75 unsigned w_sign_fixup : 1;
76 unsigned w_source : 3;
77};
78#include <poppack.h>
79
80static const struct color_fixup_desc COLOR_FIXUP_IDENTITY =
81 {0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W};
82
83static inline struct color_fixup_desc create_color_fixup_desc(
84 int sign0, enum fixup_channel_source src0, int sign1, enum fixup_channel_source src1,
85 int sign2, enum fixup_channel_source src2, int sign3, enum fixup_channel_source src3)
86{
87 struct color_fixup_desc fixup =
88 {
89 sign0, src0,
90 sign1, src1,
91 sign2, src2,
92 sign3, src3,
93 };
94 return fixup;
95}
96
97static inline struct color_fixup_desc create_yuv_fixup_desc(enum yuv_fixup yuv_fixup)
98{
99 struct color_fixup_desc fixup =
100 {
101 0, yuv_fixup & (1 << 0) ? CHANNEL_SOURCE_YUV1 : CHANNEL_SOURCE_YUV0,
102 0, yuv_fixup & (1 << 1) ? CHANNEL_SOURCE_YUV1 : CHANNEL_SOURCE_YUV0,
103 0, yuv_fixup & (1 << 2) ? CHANNEL_SOURCE_YUV1 : CHANNEL_SOURCE_YUV0,
104 0, yuv_fixup & (1 << 3) ? CHANNEL_SOURCE_YUV1 : CHANNEL_SOURCE_YUV0,
105 };
106 return fixup;
107}
108
109static inline BOOL is_identity_fixup(struct color_fixup_desc fixup)
110{
111 return !memcmp(&fixup, &COLOR_FIXUP_IDENTITY, sizeof(fixup));
112}
113
114static inline BOOL is_yuv_fixup(struct color_fixup_desc fixup)
115{
116 return fixup.x_source == CHANNEL_SOURCE_YUV0 || fixup.x_source == CHANNEL_SOURCE_YUV1;
117}
118
119static inline enum yuv_fixup get_yuv_fixup(struct color_fixup_desc fixup)
120{
121 enum yuv_fixup yuv_fixup = 0;
122 if (fixup.x_source == CHANNEL_SOURCE_YUV1) yuv_fixup |= (1 << 0);
123 if (fixup.y_source == CHANNEL_SOURCE_YUV1) yuv_fixup |= (1 << 1);
124 if (fixup.z_source == CHANNEL_SOURCE_YUV1) yuv_fixup |= (1 << 2);
125 if (fixup.w_source == CHANNEL_SOURCE_YUV1) yuv_fixup |= (1 << 3);
126 return yuv_fixup;
127}
128
H. Verbeet2a82ed82007-02-27 20:51:48 +0100129/* Hash table functions */
Henri Verbeeteb78c2a2008-11-25 14:36:08 +0100130typedef unsigned int (hash_function_t)(const void *key);
131typedef BOOL (compare_function_t)(const void *keya, const void *keyb);
H. Verbeet2a82ed82007-02-27 20:51:48 +0100132
H. Verbeetb917bda2008-08-21 18:35:34 +0200133struct hash_table_entry_t {
H. Verbeet2a82ed82007-02-27 20:51:48 +0100134 void *key;
135 void *value;
136 unsigned int hash;
137 struct list entry;
H. Verbeetb917bda2008-08-21 18:35:34 +0200138};
H. Verbeet2a82ed82007-02-27 20:51:48 +0100139
Henri Verbeetb4f43e32008-08-29 02:12:10 +0200140struct hash_table_t {
H. Verbeet2a82ed82007-02-27 20:51:48 +0100141 hash_function_t *hash_function;
142 compare_function_t *compare_function;
143 struct list *buckets;
144 unsigned int bucket_count;
H. Verbeetb917bda2008-08-21 18:35:34 +0200145 struct hash_table_entry_t *entries;
H. Verbeet2a82ed82007-02-27 20:51:48 +0100146 unsigned int entry_count;
147 struct list free_entries;
148 unsigned int count;
149 unsigned int grow_size;
150 unsigned int shrink_size;
Henri Verbeetb4f43e32008-08-29 02:12:10 +0200151};
H. Verbeet2a82ed82007-02-27 20:51:48 +0100152
Henri Verbeetb4f43e32008-08-29 02:12:10 +0200153struct hash_table_t *hash_table_create(hash_function_t *hash_function, compare_function_t *compare_function);
154void hash_table_destroy(struct hash_table_t *table, void (*free_value)(void *value, void *cb), void *cb);
Henri Verbeet4a19d892008-12-19 19:21:56 +0100155void hash_table_for_each_entry(struct hash_table_t *table, void (*callback)(void *value, void *context), void *context);
Henri Verbeet5532c992008-12-01 15:32:15 +0100156void *hash_table_get(const struct hash_table_t *table, const void *key);
Henri Verbeetb4f43e32008-08-29 02:12:10 +0200157void hash_table_put(struct hash_table_t *table, void *key, void *value);
158void hash_table_remove(struct hash_table_t *table, void *key);
H. Verbeet2a82ed82007-02-27 20:51:48 +0100159
Oliver Stieber18857f12005-06-24 11:53:07 +0000160/* Device caps */
Alexander Dorofeyev16597092008-03-27 00:23:04 +0200161#define MAX_PALETTES 65536
H. Verbeet5b7758f2007-06-25 22:45:40 +0200162#define MAX_STREAMS 16
163#define MAX_TEXTURES 8
164#define MAX_FRAGMENT_SAMPLERS 16
165#define MAX_VERTEX_SAMPLERS 4
166#define MAX_COMBINED_SAMPLERS (MAX_FRAGMENT_SAMPLERS + MAX_VERTEX_SAMPLERS)
167#define MAX_ACTIVE_LIGHTS 8
168#define MAX_CLIPPLANES WINED3DMAXUSERCLIPPLANES
Oliver Stieber18857f12005-06-24 11:53:07 +0000169
Oliver Stieberabb11f32005-07-05 14:05:18 +0000170/* Used for CreateStateBlock */
171#define NUM_SAVEDPIXELSTATES_R 35
172#define NUM_SAVEDPIXELSTATES_T 18
173#define NUM_SAVEDPIXELSTATES_S 12
Stefan Dösingera8e21d02007-08-19 12:50:14 +0200174#define NUM_SAVEDVERTEXSTATES_R 34
Oliver Stieberabb11f32005-07-05 14:05:18 +0000175#define NUM_SAVEDVERTEXSTATES_T 2
176#define NUM_SAVEDVERTEXSTATES_S 1
177
178extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
179extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
180extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
181extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
182extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
183extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
184
Oliver Stieberbb6f9b02005-08-03 11:00:28 +0000185typedef enum _WINELOOKUP {
186 WINELOOKUP_WARPPARAM = 0,
Stefan Dösingera22203a2008-04-06 00:31:39 +0200187 MAX_LOOKUPS = 1
Oliver Stieberbb6f9b02005-08-03 11:00:28 +0000188} WINELOOKUP;
189
Henri Verbeet50ebf262008-11-28 15:30:11 +0100190extern const int minLookup[MAX_LOOKUPS];
191extern const int maxLookup[MAX_LOOKUPS];
Oliver Stieberbb6f9b02005-08-03 11:00:28 +0000192extern DWORD *stateLookup[MAX_LOOKUPS];
193
Henri Verbeetc7880e82008-11-26 16:14:40 +0100194struct min_lookup
195{
196 GLenum mip[WINED3DTEXF_LINEAR + 1];
197};
Stefan Dösingera22203a2008-04-06 00:31:39 +0200198
Henri Verbeetc7880e82008-11-26 16:14:40 +0100199struct min_lookup minMipLookup[WINED3DTEXF_ANISOTROPIC + 1];
200const struct min_lookup minMipLookup_noFilter[WINED3DTEXF_ANISOTROPIC + 1];
201GLenum magLookup[WINED3DTEXF_ANISOTROPIC + 1];
202const GLenum magLookup_noFilter[WINED3DTEXF_ANISOTROPIC + 1];
203
204extern const struct filter_lookup filter_lookup_nofilter;
205extern struct filter_lookup filter_lookup;
Oliver Stieberbb6f9b02005-08-03 11:00:28 +0000206
Francois Gouget8320d212008-07-10 00:23:07 +0200207/* float_16_to_32() and float_32_to_16() (see implementation in
208 * surface_base.c) convert 16 bit floats in the FLOAT16 data type
Stefan Dösinger825506d2008-02-25 11:18:03 +0100209 * to standard C floats and vice versa. They do not depend on the encoding
210 * of the C float, so they are platform independent, but slow. On x86 and
Austin English6e59cd22008-04-22 01:18:14 -0500211 * other IEEE 754 compliant platforms the conversion can be accelerated by
212 * bit shifting the exponent and mantissa. There are also some SSE-based
213 * assembly routines out there.
Stefan Dösinger825506d2008-02-25 11:18:03 +0100214 *
215 * See GL_NV_half_float for a reference of the FLOAT16 / GL_HALF format
216 */
Stefan Dösingerb5f925c2007-12-19 17:18:39 +0100217static inline float float_16_to_32(const unsigned short *in) {
218 const unsigned short s = ((*in) & 0x8000);
219 const unsigned short e = ((*in) & 0x7C00) >> 10;
220 const unsigned short m = (*in) & 0x3FF;
221 const float sgn = (s ? -1.0 : 1.0);
222
223 if(e == 0) {
224 if(m == 0) return sgn * 0.0; /* +0.0 or -0.0 */
225 else return sgn * pow(2, -14.0) * ( (float) m / 1024.0);
226 } else if(e < 31) {
227 return sgn * pow(2, (float) e-15.0) * (1.0 + ((float) m / 1024.0));
228 } else {
229 if(m == 0) return sgn / 0.0; /* +INF / -INF */
230 else return 0.0 / 0.0; /* NAN */
231 }
232}
233
Raphael Junqueiracc8762a2005-07-24 17:11:33 +0000234/**
235 * Settings
236 */
Oliver Stieber9e6957b2005-09-23 11:08:03 +0000237#define VS_NONE 0
238#define VS_HW 1
Raphael Junqueira01968612003-11-14 03:50:35 +0000239
Oliver Stieber9e6957b2005-09-23 11:08:03 +0000240#define PS_NONE 0
241#define PS_HW 1
Jason Edmeades24ab49e2004-09-23 04:34:27 +0000242
Oliver Stieber9e6957b2005-09-23 11:08:03 +0000243#define VBO_NONE 0
244#define VBO_HW 1
245
246#define NP2_NONE 0
247#define NP2_REPACK 1
H. Verbeet193f6bb2006-09-26 20:31:48 +0200248#define NP2_NATIVE 2
Raphael Junqueiracc8762a2005-07-24 17:11:33 +0000249
H. Verbeetad4c2bd2006-11-17 13:23:53 +0100250#define ORM_BACKBUFFER 0
251#define ORM_PBUFFER 1
H. Verbeet6d660852006-11-17 13:24:00 +0100252#define ORM_FBO 2
H. Verbeetad4c2bd2006-11-17 13:23:53 +0100253
Jason Greend2045402006-05-23 18:22:59 -0400254#define SHADER_ARB 1
255#define SHADER_GLSL 2
Stefan Dösinger4640be82008-03-22 14:31:52 +0100256#define SHADER_ATI 3
257#define SHADER_NONE 4
Jason Greend2045402006-05-23 18:22:59 -0400258
Stefan Dösinger739d5652006-07-17 20:14:25 +0200259#define RTL_DISABLE -1
260#define RTL_AUTO 0
261#define RTL_READDRAW 1
262#define RTL_READTEX 2
263#define RTL_TEXDRAW 3
264#define RTL_TEXTEX 4
265
Roderick Colenbrander27335722008-11-23 22:51:03 +0100266#define PCI_VENDOR_NONE 0xffff /* e.g. 0x8086 for Intel and 0x10de for Nvidia */
Roderick Colenbrander52d59712008-11-23 22:33:29 +0100267#define PCI_DEVICE_NONE 0xffff /* e.g. 0x14f for a Geforce6200 */
268
H. Verbeetba8a6a32006-09-26 20:31:41 +0200269/* NOTE: When adding fields to this structure, make sure to update the default
270 * values in wined3d_main.c as well. */
Raphael Junqueiracc8762a2005-07-24 17:11:33 +0000271typedef struct wined3d_settings_s {
272/* vertex and pixel shader modes */
273 int vs_mode;
274 int ps_mode;
275 int vbo_mode;
Jason Greend2045402006-05-23 18:22:59 -0400276/* Ideally, we don't want the user to have to request GLSL. If the hardware supports GLSL,
277 we should use it. However, until it's fully implemented, we'll leave it as a registry
278 setting for developers. */
Phil Costin1b320432006-05-18 02:24:08 +0100279 BOOL glslRequested;
H. Verbeetad4c2bd2006-11-17 13:23:53 +0100280 int offscreen_rendering_mode;
Stefan Dösinger739d5652006-07-17 20:14:25 +0200281 int rendertargetlock_mode;
Roderick Colenbrander27335722008-11-23 22:51:03 +0100282 unsigned short pci_vendor_id;
Roderick Colenbrander52d59712008-11-23 22:33:29 +0100283 unsigned short pci_device_id;
Jan Zerebecki4d6cfb62006-08-08 00:03:06 +0200284/* Memory tracking and object counting */
285 unsigned int emulated_textureram;
Stefan Dösinger271fb002007-09-01 21:22:32 +0200286 char *logo;
Roderick Colenbrander042d0392008-06-02 21:06:01 +0000287 int allow_multisampling;
Raphael Junqueiracc8762a2005-07-24 17:11:33 +0000288} wined3d_settings_t;
289
290extern wined3d_settings_t wined3d_settings;
291
Henri Verbeet7420a962009-05-01 09:13:54 +0200292typedef enum _WINED3DSAMPLER_TEXTURE_TYPE
293{
294 WINED3DSTT_UNKNOWN = 0,
295 WINED3DSTT_1D = 1,
296 WINED3DSTT_2D = 2,
297 WINED3DSTT_CUBE = 3,
298 WINED3DSTT_VOLUME = 4,
299} WINED3DSAMPLER_TEXTURE_TYPE;
300
301typedef enum _WINED3DSHADER_PARAM_REGISTER_TYPE
302{
303 WINED3DSPR_TEMP = 0,
304 WINED3DSPR_INPUT = 1,
305 WINED3DSPR_CONST = 2,
306 WINED3DSPR_ADDR = 3,
307 WINED3DSPR_TEXTURE = 3,
308 WINED3DSPR_RASTOUT = 4,
309 WINED3DSPR_ATTROUT = 5,
310 WINED3DSPR_TEXCRDOUT = 6,
311 WINED3DSPR_OUTPUT = 6,
312 WINED3DSPR_CONSTINT = 7,
313 WINED3DSPR_COLOROUT = 8,
314 WINED3DSPR_DEPTHOUT = 9,
315 WINED3DSPR_SAMPLER = 10,
316 WINED3DSPR_CONST2 = 11,
317 WINED3DSPR_CONST3 = 12,
318 WINED3DSPR_CONST4 = 13,
319 WINED3DSPR_CONSTBOOL = 14,
320 WINED3DSPR_LOOP = 15,
321 WINED3DSPR_TEMPFLOAT16 = 16,
322 WINED3DSPR_MISCTYPE = 17,
323 WINED3DSPR_LABEL = 18,
324 WINED3DSPR_PREDICATE = 19,
Henri Verbeet9381a412009-05-06 10:05:46 +0200325 WINED3DSPR_IMMCONST,
Henri Verbeet7420a962009-05-01 09:13:54 +0200326} WINED3DSHADER_PARAM_REGISTER_TYPE;
327
Henri Verbeet9381a412009-05-06 10:05:46 +0200328enum wined3d_immconst_type
329{
330 WINED3D_IMMCONST_FLOAT,
331 WINED3D_IMMCONST_FLOAT4,
332};
333
Henri Verbeet7420a962009-05-01 09:13:54 +0200334typedef enum _WINED3DVS_RASTOUT_OFFSETS
335{
336 WINED3DSRO_POSITION = 0,
337 WINED3DSRO_FOG = 1,
338 WINED3DSRO_POINT_SIZE = 2,
339} WINED3DVS_RASTOUT_OFFSETS;
340
341#define WINED3DSP_NOSWIZZLE (0 | (1 << 2) | (2 << 4) | (3 << 6))
342
343typedef enum _WINED3DSHADER_PARAM_SRCMOD_TYPE
344{
345 WINED3DSPSM_NONE = 0,
346 WINED3DSPSM_NEG = 1,
347 WINED3DSPSM_BIAS = 2,
348 WINED3DSPSM_BIASNEG = 3,
349 WINED3DSPSM_SIGN = 4,
350 WINED3DSPSM_SIGNNEG = 5,
351 WINED3DSPSM_COMP = 6,
352 WINED3DSPSM_X2 = 7,
353 WINED3DSPSM_X2NEG = 8,
354 WINED3DSPSM_DZ = 9,
355 WINED3DSPSM_DW = 10,
356 WINED3DSPSM_ABS = 11,
357 WINED3DSPSM_ABSNEG = 12,
358 WINED3DSPSM_NOT = 13,
359} WINED3DSHADER_PARAM_SRCMOD_TYPE;
360
Henri Verbeet699eae02009-05-06 10:05:45 +0200361#define WINED3DSP_WRITEMASK_0 0x1 /* .x r */
362#define WINED3DSP_WRITEMASK_1 0x2 /* .y g */
363#define WINED3DSP_WRITEMASK_2 0x4 /* .z b */
364#define WINED3DSP_WRITEMASK_3 0x8 /* .w a */
365#define WINED3DSP_WRITEMASK_ALL 0xf /* all */
Henri Verbeet7420a962009-05-01 09:13:54 +0200366
367typedef enum _WINED3DSHADER_PARAM_DSTMOD_TYPE
368{
369 WINED3DSPDM_NONE = 0,
370 WINED3DSPDM_SATURATE = 1,
371 WINED3DSPDM_PARTIALPRECISION = 2,
372 WINED3DSPDM_MSAMPCENTROID = 4,
373} WINED3DSHADER_PARAM_DSTMOD_TYPE;
374
375typedef enum _WINED3DSHADER_INSTRUCTION_OPCODE_TYPE
376{
377 WINED3DSIO_NOP = 0,
378 WINED3DSIO_MOV = 1,
379 WINED3DSIO_ADD = 2,
380 WINED3DSIO_SUB = 3,
381 WINED3DSIO_MAD = 4,
382 WINED3DSIO_MUL = 5,
383 WINED3DSIO_RCP = 6,
384 WINED3DSIO_RSQ = 7,
385 WINED3DSIO_DP3 = 8,
386 WINED3DSIO_DP4 = 9,
387 WINED3DSIO_MIN = 10,
388 WINED3DSIO_MAX = 11,
389 WINED3DSIO_SLT = 12,
390 WINED3DSIO_SGE = 13,
391 WINED3DSIO_EXP = 14,
392 WINED3DSIO_LOG = 15,
393 WINED3DSIO_LIT = 16,
394 WINED3DSIO_DST = 17,
395 WINED3DSIO_LRP = 18,
396 WINED3DSIO_FRC = 19,
397 WINED3DSIO_M4x4 = 20,
398 WINED3DSIO_M4x3 = 21,
399 WINED3DSIO_M3x4 = 22,
400 WINED3DSIO_M3x3 = 23,
401 WINED3DSIO_M3x2 = 24,
402 WINED3DSIO_CALL = 25,
403 WINED3DSIO_CALLNZ = 26,
404 WINED3DSIO_LOOP = 27,
405 WINED3DSIO_RET = 28,
406 WINED3DSIO_ENDLOOP = 29,
407 WINED3DSIO_LABEL = 30,
408 WINED3DSIO_DCL = 31,
409 WINED3DSIO_POW = 32,
410 WINED3DSIO_CRS = 33,
411 WINED3DSIO_SGN = 34,
412 WINED3DSIO_ABS = 35,
413 WINED3DSIO_NRM = 36,
414 WINED3DSIO_SINCOS = 37,
415 WINED3DSIO_REP = 38,
416 WINED3DSIO_ENDREP = 39,
417 WINED3DSIO_IF = 40,
418 WINED3DSIO_IFC = 41,
419 WINED3DSIO_ELSE = 42,
420 WINED3DSIO_ENDIF = 43,
421 WINED3DSIO_BREAK = 44,
422 WINED3DSIO_BREAKC = 45,
423 WINED3DSIO_MOVA = 46,
424 WINED3DSIO_DEFB = 47,
425 WINED3DSIO_DEFI = 48,
426
427 WINED3DSIO_TEXCOORD = 64,
428 WINED3DSIO_TEXKILL = 65,
429 WINED3DSIO_TEX = 66,
430 WINED3DSIO_TEXBEM = 67,
431 WINED3DSIO_TEXBEML = 68,
432 WINED3DSIO_TEXREG2AR = 69,
433 WINED3DSIO_TEXREG2GB = 70,
434 WINED3DSIO_TEXM3x2PAD = 71,
435 WINED3DSIO_TEXM3x2TEX = 72,
436 WINED3DSIO_TEXM3x3PAD = 73,
437 WINED3DSIO_TEXM3x3TEX = 74,
438 WINED3DSIO_TEXM3x3DIFF = 75,
439 WINED3DSIO_TEXM3x3SPEC = 76,
440 WINED3DSIO_TEXM3x3VSPEC = 77,
441 WINED3DSIO_EXPP = 78,
442 WINED3DSIO_LOGP = 79,
443 WINED3DSIO_CND = 80,
444 WINED3DSIO_DEF = 81,
445 WINED3DSIO_TEXREG2RGB = 82,
446 WINED3DSIO_TEXDP3TEX = 83,
447 WINED3DSIO_TEXM3x2DEPTH = 84,
448 WINED3DSIO_TEXDP3 = 85,
449 WINED3DSIO_TEXM3x3 = 86,
450 WINED3DSIO_TEXDEPTH = 87,
451 WINED3DSIO_CMP = 88,
452 WINED3DSIO_BEM = 89,
453 WINED3DSIO_DP2ADD = 90,
454 WINED3DSIO_DSX = 91,
455 WINED3DSIO_DSY = 92,
456 WINED3DSIO_TEXLDD = 93,
457 WINED3DSIO_SETP = 94,
458 WINED3DSIO_TEXLDL = 95,
459 WINED3DSIO_BREAKP = 96,
460
461 WINED3DSIO_PHASE = 0xfffd,
462 WINED3DSIO_COMMENT = 0xfffe,
463 WINED3DSIO_END = 0Xffff,
464} WINED3DSHADER_INSTRUCTION_OPCODE_TYPE;
465
466/* Undocumented opcode control to identify projective texture lookups in ps 2.0 and later */
467#define WINED3DSI_TEXLD_PROJECT 1
468#define WINED3DSI_TEXLD_BIAS 2
469
470typedef enum COMPARISON_TYPE
471{
472 COMPARISON_GT = 1,
473 COMPARISON_EQ = 2,
474 COMPARISON_GE = 3,
475 COMPARISON_LT = 4,
476 COMPARISON_NE = 5,
477 COMPARISON_LE = 6,
478} COMPARISON_TYPE;
479
Henri Verbeet2a5a6a32009-05-05 09:38:03 +0200480#define WINED3D_SM1_VS 0xfffe
481#define WINED3D_SM1_PS 0xffff
482#define WINED3D_SM4_PS 0x0000
483#define WINED3D_SM4_VS 0x0001
484#define WINED3D_SM4_GS 0x0002
485
Henri Verbeet7420a962009-05-01 09:13:54 +0200486/* Shader version tokens, and shader end tokens */
Henri Verbeet2a5a6a32009-05-05 09:38:03 +0200487#define WINED3DPS_VERSION(major, minor) ((WINED3D_SM1_PS << 16) | ((major) << 8) | (minor))
488#define WINED3DVS_VERSION(major, minor) ((WINED3D_SM1_VS << 16) | ((major) << 8) | (minor))
Henri Verbeet7420a962009-05-01 09:13:54 +0200489
H. Verbeetdf6f4822006-11-27 20:50:37 +0100490/* Shader backends */
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200491
492/* TODO: Make this dynamic, based on shader limits ? */
493#define MAX_ATTRIBS 16
494#define MAX_REG_ADDR 1
495#define MAX_REG_TEMP 32
496#define MAX_REG_TEXCRD 8
497#define MAX_REG_INPUT 12
498#define MAX_REG_OUTPUT 12
499#define MAX_CONST_I 16
500#define MAX_CONST_B 16
501
502/* FIXME: This needs to go up to 2048 for
503 * Shader model 3 according to msdn (and for software shaders) */
504#define MAX_LABELS 16
H. Verbeetdf6f4822006-11-27 20:50:37 +0100505
Stefan Dösingera66fb402008-03-18 19:19:16 +0100506#define SHADER_PGMSIZE 65535
507typedef struct SHADER_BUFFER {
508 char* buffer;
509 unsigned int bsize;
510 unsigned int lineNo;
511 BOOL newline;
512} SHADER_BUFFER;
513
Henri Verbeet2e769542008-09-23 17:39:34 +0200514enum WINED3D_SHADER_INSTRUCTION_HANDLER
515{
516 WINED3DSIH_ABS,
517 WINED3DSIH_ADD,
518 WINED3DSIH_BEM,
519 WINED3DSIH_BREAK,
520 WINED3DSIH_BREAKC,
521 WINED3DSIH_BREAKP,
522 WINED3DSIH_CALL,
523 WINED3DSIH_CALLNZ,
524 WINED3DSIH_CMP,
525 WINED3DSIH_CND,
526 WINED3DSIH_CRS,
527 WINED3DSIH_DCL,
528 WINED3DSIH_DEF,
529 WINED3DSIH_DEFB,
530 WINED3DSIH_DEFI,
531 WINED3DSIH_DP2ADD,
532 WINED3DSIH_DP3,
533 WINED3DSIH_DP4,
534 WINED3DSIH_DST,
535 WINED3DSIH_DSX,
536 WINED3DSIH_DSY,
537 WINED3DSIH_ELSE,
538 WINED3DSIH_ENDIF,
539 WINED3DSIH_ENDLOOP,
540 WINED3DSIH_ENDREP,
541 WINED3DSIH_EXP,
542 WINED3DSIH_EXPP,
543 WINED3DSIH_FRC,
544 WINED3DSIH_IF,
545 WINED3DSIH_IFC,
546 WINED3DSIH_LABEL,
547 WINED3DSIH_LIT,
548 WINED3DSIH_LOG,
549 WINED3DSIH_LOGP,
550 WINED3DSIH_LOOP,
551 WINED3DSIH_LRP,
552 WINED3DSIH_M3x2,
553 WINED3DSIH_M3x3,
554 WINED3DSIH_M3x4,
555 WINED3DSIH_M4x3,
556 WINED3DSIH_M4x4,
557 WINED3DSIH_MAD,
558 WINED3DSIH_MAX,
559 WINED3DSIH_MIN,
560 WINED3DSIH_MOV,
561 WINED3DSIH_MOVA,
562 WINED3DSIH_MUL,
563 WINED3DSIH_NOP,
564 WINED3DSIH_NRM,
565 WINED3DSIH_PHASE,
566 WINED3DSIH_POW,
567 WINED3DSIH_RCP,
568 WINED3DSIH_REP,
569 WINED3DSIH_RET,
570 WINED3DSIH_RSQ,
571 WINED3DSIH_SETP,
572 WINED3DSIH_SGE,
573 WINED3DSIH_SGN,
574 WINED3DSIH_SINCOS,
575 WINED3DSIH_SLT,
576 WINED3DSIH_SUB,
577 WINED3DSIH_TEX,
578 WINED3DSIH_TEXBEM,
579 WINED3DSIH_TEXBEML,
580 WINED3DSIH_TEXCOORD,
581 WINED3DSIH_TEXDEPTH,
582 WINED3DSIH_TEXDP3,
583 WINED3DSIH_TEXDP3TEX,
584 WINED3DSIH_TEXKILL,
585 WINED3DSIH_TEXLDD,
586 WINED3DSIH_TEXLDL,
587 WINED3DSIH_TEXM3x2DEPTH,
588 WINED3DSIH_TEXM3x2PAD,
589 WINED3DSIH_TEXM3x2TEX,
590 WINED3DSIH_TEXM3x3,
591 WINED3DSIH_TEXM3x3DIFF,
592 WINED3DSIH_TEXM3x3PAD,
593 WINED3DSIH_TEXM3x3SPEC,
594 WINED3DSIH_TEXM3x3TEX,
595 WINED3DSIH_TEXM3x3VSPEC,
596 WINED3DSIH_TEXREG2AR,
597 WINED3DSIH_TEXREG2GB,
598 WINED3DSIH_TEXREG2RGB,
599 WINED3DSIH_TABLE_SIZE
600};
601
Henri Verbeet65622a02009-05-06 17:59:21 +0200602enum wined3d_shader_type
603{
604 WINED3D_SHADER_TYPE_PIXEL,
605 WINED3D_SHADER_TYPE_VERTEX,
606 WINED3D_SHADER_TYPE_GEOMETRY,
607};
608
609struct wined3d_shader_version
610{
611 enum wined3d_shader_type type;
612 BYTE major;
613 BYTE minor;
614};
615
616#define WINED3D_SHADER_VERSION(major, minor) (((major) << 8) | (minor))
617
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200618typedef struct shader_reg_maps
619{
Henri Verbeet65622a02009-05-06 17:59:21 +0200620 struct wined3d_shader_version shader_version;
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200621 char texcoord[MAX_REG_TEXCRD]; /* pixel < 3.0 */
622 char temporary[MAX_REG_TEMP]; /* pixel, vertex */
623 char address[MAX_REG_ADDR]; /* vertex */
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200624 char labels[MAX_LABELS]; /* pixel, vertex */
Stefan Dösingerf9276a62009-05-07 17:31:20 +0200625 DWORD *constf; /* pixel, vertex */
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200626 DWORD texcoord_mask[MAX_REG_TEXCRD]; /* vertex < 3.0 */
Henri Verbeet10fadad2009-05-27 10:24:49 +0200627 WORD input_registers; /* max(MAX_REG_INPUT, MAX_ATTRIBS), 16 */
Henri Verbeete6efb792009-05-27 10:24:50 +0200628 WORD output_registers; /* MAX_REG_OUTPUT, 12 */
Henri Verbeete0018762009-04-28 09:53:28 +0200629 WORD integer_constants; /* MAX_CONST_I, 16 */
630 WORD boolean_constants; /* MAX_CONST_B, 16 */
Stefan Dösingere70c80a2009-05-27 18:23:59 +0200631 WORD local_bool_consts; /* MAX_CONST_B, 16 */
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200632
Henri Verbeet8d4c9042009-04-29 09:55:06 +0200633 WINED3DSAMPLER_TEXTURE_TYPE sampler_type[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)];
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200634 BOOL bumpmat[MAX_TEXTURES], luminanceparams[MAX_TEXTURES];
Stefan Dösingerc7ca3792009-05-07 19:12:07 +0200635 char usesnrm, vpos, usesdsy, usestexldd, usesmova;
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200636 char usesrelconstF;
637
638 /* Whether or not loops are used in this shader, and nesting depth */
639 unsigned loop_depth;
640
641 /* Whether or not this shader uses fog */
642 char fog;
643
644} shader_reg_maps;
645
Henri Verbeet463de242009-04-15 10:06:28 +0200646struct wined3d_shader_context
647{
648 IWineD3DBaseShader *shader;
649 const struct shader_reg_maps *reg_maps;
650 SHADER_BUFFER *buffer;
Stefan Dösinger7b1d4872009-05-15 13:56:40 +0200651 void *backend_data;
Henri Verbeet463de242009-04-15 10:06:28 +0200652};
653
Henri Verbeet5e473cb2009-05-07 16:36:07 +0200654struct wined3d_shader_register
655{
656 WINED3DSHADER_PARAM_REGISTER_TYPE type;
657 UINT idx;
658 const struct wined3d_shader_src_param *rel_addr;
659 enum wined3d_immconst_type immconst_type;
660 DWORD immconst_data[4];
661};
662
Henri Verbeet7245cd22009-04-03 10:36:38 +0200663struct wined3d_shader_dst_param
664{
Henri Verbeet5e473cb2009-05-07 16:36:07 +0200665 struct wined3d_shader_register reg;
Henri Verbeet6f66c1d2009-04-07 11:09:11 +0200666 DWORD write_mask;
Henri Verbeetf0de1622009-04-06 10:10:08 +0200667 DWORD modifiers;
Henri Verbeet22e57d02009-04-10 09:15:06 +0200668 DWORD shift;
Henri Verbeet7245cd22009-04-03 10:36:38 +0200669};
670
Henri Verbeetff62cab2009-04-15 10:06:28 +0200671struct wined3d_shader_src_param
672{
Henri Verbeet5e473cb2009-05-07 16:36:07 +0200673 struct wined3d_shader_register reg;
Henri Verbeetdb5ab972009-04-21 09:35:05 +0200674 DWORD swizzle;
Henri Verbeet8ac4c982009-04-15 10:06:28 +0200675 DWORD modifiers;
Henri Verbeetff62cab2009-04-15 10:06:28 +0200676};
677
Henri Verbeetc3a01b32009-04-01 12:23:01 +0200678struct wined3d_shader_instruction
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200679{
Henri Verbeet463de242009-04-15 10:06:28 +0200680 const struct wined3d_shader_context *ctx;
Henri Verbeet44648b22009-04-02 10:41:00 +0200681 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200682 DWORD flags;
683 BOOL coissue;
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200684 DWORD predicate;
Henri Verbeet7bde2792009-04-02 10:41:00 +0200685 UINT dst_count;
Henri Verbeet7245cd22009-04-03 10:36:38 +0200686 const struct wined3d_shader_dst_param *dst;
Henri Verbeet7bde2792009-04-02 10:41:00 +0200687 UINT src_count;
Henri Verbeetff62cab2009-04-15 10:06:28 +0200688 const struct wined3d_shader_src_param *src;
Henri Verbeetc3a01b32009-04-01 12:23:01 +0200689};
Henri Verbeetde4e8cf2009-04-01 12:23:01 +0200690
Henri Verbeetd12e4892009-04-08 08:35:06 +0200691struct wined3d_shader_semantic
692{
Henri Verbeet9ec0b092009-04-08 08:35:07 +0200693 WINED3DDECLUSAGE usage;
694 UINT usage_idx;
Henri Verbeet65321dd2009-04-29 09:55:07 +0200695 WINED3DSAMPLER_TEXTURE_TYPE sampler_type;
Henri Verbeetd12e4892009-04-08 08:35:06 +0200696 struct wined3d_shader_dst_param reg;
697};
698
Henri Verbeet19cb4592009-05-27 10:24:50 +0200699struct wined3d_shader_attribute
700{
701 WINED3DDECLUSAGE usage;
702 UINT usage_idx;
703};
704
Henri Verbeet23781082009-05-04 09:49:27 +0200705struct wined3d_shader_frontend
706{
Henri Verbeet9a579a42009-05-08 17:44:25 +0200707 void *(*shader_init)(const DWORD *ptr, const struct wined3d_shader_signature *output_signature);
Henri Verbeet2a5a6a32009-05-05 09:38:03 +0200708 void (*shader_free)(void *data);
Henri Verbeet65622a02009-05-06 17:59:21 +0200709 void (*shader_read_header)(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version);
Henri Verbeet5c63d932009-05-06 17:59:21 +0200710 void (*shader_read_opcode)(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins, UINT *param_size);
711 void (*shader_read_src_param)(void *data, const DWORD **ptr, struct wined3d_shader_src_param *src_param,
712 struct wined3d_shader_src_param *src_rel_addr);
713 void (*shader_read_dst_param)(void *data, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param,
714 struct wined3d_shader_src_param *dst_rel_addr);
Henri Verbeet23781082009-05-04 09:49:27 +0200715 void (*shader_read_semantic)(const DWORD **ptr, struct wined3d_shader_semantic *semantic);
716 void (*shader_read_comment)(const DWORD **ptr, const char **comment);
Henri Verbeet454dd2e2009-05-05 09:38:03 +0200717 BOOL (*shader_is_end)(void *data, const DWORD **ptr);
Henri Verbeet23781082009-05-04 09:49:27 +0200718};
719
720extern const struct wined3d_shader_frontend sm1_shader_frontend;
Henri Verbeetef074cd2009-05-05 09:38:03 +0200721extern const struct wined3d_shader_frontend sm4_shader_frontend;
Henri Verbeet23781082009-05-04 09:49:27 +0200722
Henri Verbeetc3a01b32009-04-01 12:23:01 +0200723typedef void (*SHADER_HANDLER)(const struct wined3d_shader_instruction *);
Henri Verbeet2e769542008-09-23 17:39:34 +0200724
Stefan Dösinger5ab52022008-03-18 19:39:26 +0100725struct shader_caps {
Stefan Dösinger5ab52022008-03-18 19:39:26 +0100726 DWORD VertexShaderVersion;
727 DWORD MaxVertexShaderConst;
728
729 DWORD PixelShaderVersion;
730 float PixelShader1xMaxValue;
Stefan Dösinger754b5cf2009-03-22 12:24:28 +0100731 DWORD MaxPixelShaderConst;
Stefan Dösinger5ab52022008-03-18 19:39:26 +0100732
733 WINED3DVSHADERCAPS2_0 VS20Caps;
734 WINED3DPSHADERCAPS2_0 PS20Caps;
735
736 DWORD MaxVShaderInstructionsExecuted;
737 DWORD MaxPShaderInstructionsExecuted;
738 DWORD MaxVertexShader30InstructionSlots;
739 DWORD MaxPixelShader30InstructionSlots;
Stefan Dösinger2cb8f422009-05-08 17:24:01 +0200740
741 BOOL VSClipping;
Stefan Dösinger5ab52022008-03-18 19:39:26 +0100742};
743
Henri Verbeet57401fc2008-10-27 18:31:31 +0100744enum tex_types
745{
746 tex_1d = 0,
747 tex_2d = 1,
748 tex_3d = 2,
749 tex_cube = 3,
750 tex_rect = 4,
751 tex_type_count = 5,
752};
753
Stefan Dösinger61e581a2008-12-14 15:40:07 +0100754enum vertexprocessing_mode {
755 fixedfunction,
756 vertexshader,
757 pretransformed
758};
759
Henri Verbeet362bc0d2009-03-09 14:31:28 +0100760#define WINED3D_CONST_NUM_UNUSED ~0U
761
Stefan Dösinger61e581a2008-12-14 15:40:07 +0100762struct stb_const_desc {
Henri Verbeet59c59622009-03-25 10:12:27 +0100763 unsigned char texunit;
Stefan Dösinger61e581a2008-12-14 15:40:07 +0100764 UINT const_num;
765};
766
Stefan Dösinger690cbe72008-12-15 19:35:40 +0100767enum fogmode {
768 FOG_OFF,
769 FOG_LINEAR,
770 FOG_EXP,
771 FOG_EXP2
772};
773
Stefan Dösinger61e581a2008-12-14 15:40:07 +0100774/* Stateblock dependent parameters which have to be hardcoded
775 * into the shader code
776 */
777struct ps_compile_args {
778 struct color_fixup_desc color_fixup[MAX_FRAGMENT_SAMPLERS];
Stefan Dösinger61e581a2008-12-14 15:40:07 +0100779 enum vertexprocessing_mode vp_mode;
Stefan Dösinger690cbe72008-12-15 19:35:40 +0100780 enum fogmode fog;
Stefan Dösinger61e581a2008-12-14 15:40:07 +0100781 /* Projected textures(ps 1.0-1.3) */
782 /* Texture types(2D, Cube, 3D) in ps 1.x */
Tobias Jakobi1b335df2009-03-26 03:15:21 +0100783 BOOL srgb_correction;
Tobias Jakobi0c2514b2009-04-09 19:14:03 +0200784 WORD np2_fixup;
785 /* Bitmap for NP2 texcoord fixups (16 samplers max currently).
Tobias Jakobi1b335df2009-03-26 03:15:21 +0100786 D3D9 has a limit of 16 samplers and the fixup is superfluous
787 in D3D10 (unconditional NP2 support mandatory). */
Stefan Dösinger61e581a2008-12-14 15:40:07 +0100788};
789
Stefan Dösinger8dcd5122009-02-05 19:44:32 +0100790enum fog_src_type {
791 VS_FOG_Z = 0,
792 VS_FOG_COORD = 1
793};
794
795struct vs_compile_args {
796 WORD fog_src;
797 WORD swizzle_map; /* MAX_ATTRIBS, 16 */
798};
799
H. Verbeetdf6f4822006-11-27 20:50:37 +0100800typedef struct {
Stefan Dösingere492dd82009-05-27 18:23:16 +0200801 void (*shader_handle_instruction)(const struct wined3d_shader_instruction *);
H. Verbeetdf6f4822006-11-27 20:50:37 +0100802 void (*shader_select)(IWineD3DDevice *iface, BOOL usePS, BOOL useVS);
Henri Verbeet57401fc2008-10-27 18:31:31 +0100803 void (*shader_select_depth_blt)(IWineD3DDevice *iface, enum tex_types tex_type);
H. Verbeetb37cc082008-07-10 17:57:35 +0200804 void (*shader_deselect_depth_blt)(IWineD3DDevice *iface);
Henri Verbeetd099dde2008-12-17 17:07:25 +0100805 void (*shader_update_float_vertex_constants)(IWineD3DDevice *iface, UINT start, UINT count);
806 void (*shader_update_float_pixel_constants)(IWineD3DDevice *iface, UINT start, UINT count);
H. Verbeetdf6f4822006-11-27 20:50:37 +0100807 void (*shader_load_constants)(IWineD3DDevice *iface, char usePS, char useVS);
Tobias Jakobi9b067a62009-04-09 00:55:38 +0200808 void (*shader_load_np2fixup_constants)(IWineD3DDevice *iface, char usePS, char useVS);
Stefan Dösingercfc57252007-11-20 17:40:54 +0100809 void (*shader_destroy)(IWineD3DBaseShader *iface);
Stefan Dösingerf912f182008-02-24 11:23:53 +0100810 HRESULT (*shader_alloc_private)(IWineD3DDevice *iface);
811 void (*shader_free_private)(IWineD3DDevice *iface);
Stefan Dösinger107e80a2008-03-04 02:30:23 +0100812 BOOL (*shader_dirtifyable_constants)(IWineD3DDevice *iface);
Henri Verbeetd8f6e632008-11-25 14:36:09 +0100813 void (*shader_get_caps)(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *caps);
Henri Verbeet89139b72008-12-03 14:53:43 +0100814 BOOL (*shader_color_fixup_supported)(struct color_fixup_desc fixup);
Stefan Dösinger2fd485a2009-05-03 18:17:07 +0200815 void (*shader_add_instruction_modifiers)(const struct wined3d_shader_instruction *ins);
H. Verbeetdf6f4822006-11-27 20:50:37 +0100816} shader_backend_t;
817
818extern const shader_backend_t glsl_shader_backend;
819extern const shader_backend_t arb_program_shader_backend;
820extern const shader_backend_t none_shader_backend;
821
Jason Edmeadesc3421ea2004-09-29 21:26:47 +0000822/* X11 locking */
823
Maarten Lankhorst4eca43e2008-12-18 21:12:36 +0100824extern void (* CDECL wine_tsx11_lock_ptr)(void);
825extern void (* CDECL wine_tsx11_unlock_ptr)(void);
Jason Edmeadesc3421ea2004-09-29 21:26:47 +0000826
827/* As GLX relies on X, this is needed */
828extern int num_lock;
829
830#if 0
831#define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
832#define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
833#else
834#define ENTER_GL() wine_tsx11_lock_ptr()
835#define LEAVE_GL() wine_tsx11_unlock_ptr()
836#endif
837
838/*****************************************************************************
839 * Defines
840 */
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000841
842/* GL related defines */
843/* ------------------ */
Jason Edmeadeseba27af2004-11-28 15:04:41 +0000844#define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
845#define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
Jason Edmeadesf738c142004-12-09 11:42:34 +0000846#define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
Oliver Stieber2c0e97e2005-08-17 11:34:03 +0000847#define GL_VEND(_VendName) (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
Jason Edmeadesb5198932004-10-06 00:05:29 +0000848
Raphael Junqueira705aec52005-11-15 12:03:13 +0000849#define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
850#define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
851#define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
852#define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
853
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000854#define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
855#define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
856#define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
857#define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
858
Alexandre Julliard6800d3d2008-12-03 10:03:26 +0100859#define D3DCOLORTOGLFLOAT4(dw, vec) do { \
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000860 (vec)[0] = D3DCOLOR_R(dw); \
861 (vec)[1] = D3DCOLOR_G(dw); \
862 (vec)[2] = D3DCOLOR_B(dw); \
Alexandre Julliard6800d3d2008-12-03 10:03:26 +0100863 (vec)[3] = D3DCOLOR_A(dw); \
864} while(0)
Roderick Colenbrander54e5f9c2006-05-25 13:54:03 +0200865
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000866/* DirectX Device Limits */
867/* --------------------- */
Henri Verbeet2dcfdd52009-04-24 09:17:58 +0200868#define MAX_MIP_LEVELS 32 /* Maximum number of mipmap levels. */
Jason Edmeadesb5198932004-10-06 00:05:29 +0000869#define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
870 See MaxStreams in MSDN under GetDeviceCaps */
Henri Verbeet457037f2008-12-31 16:57:10 +0100871#define HIGHEST_TRANSFORMSTATE WINED3DTS_WORLDMATRIX(255) /* Highest value in WINED3DTRANSFORMSTATETYPE */
Jason Edmeades41427852005-01-09 17:37:02 +0000872
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000873/* Checking of API calls */
874/* --------------------- */
Henri Verbeet5284fce2008-12-02 18:41:33 +0100875#ifndef WINE_NO_DEBUG_MSGS
Ivan Gyurdiev634698c2006-04-10 00:39:07 -0400876#define checkGLcall(A) \
Alexandre Julliard6800d3d2008-12-03 10:03:26 +0100877do { \
Ivan Gyurdiev634698c2006-04-10 00:39:07 -0400878 GLint err = glGetError(); \
879 if (err == GL_NO_ERROR) { \
880 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
881 \
882 } else do { \
H. Verbeetb643ab32007-04-23 22:02:50 +0200883 FIXME(">>>>>>>>>>>>>>>>> %s (%#x) from %s @ %s / %d\n", \
884 debug_glerror(err), err, A, __FILE__, __LINE__); \
Ivan Gyurdiev634698c2006-04-10 00:39:07 -0400885 err = glGetError(); \
886 } while (err != GL_NO_ERROR); \
Alexandre Julliard6800d3d2008-12-03 10:03:26 +0100887} while(0)
Henri Verbeet5284fce2008-12-02 18:41:33 +0100888#else
Alexandre Julliard6800d3d2008-12-03 10:03:26 +0100889#define checkGLcall(A) do {} while(0)
Henri Verbeet5284fce2008-12-02 18:41:33 +0100890#endif
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000891
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000892/* Trace routines / diagnostics */
893/* ---------------------------- */
894
895/* Dump out a matrix and copy it */
Jason Edmeadeseba27af2004-11-28 15:04:41 +0000896#define conv_mat(mat,gl_mat) \
897do { \
898 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
899 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
900 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
901 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
902 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
903} while (0)
904
Jason Edmeades0a944ae2004-11-29 17:53:42 +0000905/* Macro to dump out the current state of the light chain */
906#define DUMP_LIGHT_CHAIN() \
Alexandre Julliard6800d3d2008-12-03 10:03:26 +0100907do { \
Jason Edmeades0a944ae2004-11-29 17:53:42 +0000908 PLIGHTINFOEL *el = This->stateBlock->lights;\
909 while (el) { \
910 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
911 el = el->next; \
912 } \
Alexandre Julliard6800d3d2008-12-03 10:03:26 +0100913} while(0)
Jason Edmeades0a944ae2004-11-29 17:53:42 +0000914
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000915/* Trace vector and strided data information */
Jason Edmeadesf738c142004-12-09 11:42:34 +0000916#define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
Henri Verbeet4434d002009-03-27 10:25:56 +0100917#define TRACE_STRIDED(si, name) TRACE( #name "=(data:%p, stride:%d, format:%#x, vbo %d, stream %u)\n", \
Henri Verbeetef2d7042009-03-30 11:24:54 +0200918 si->elements[name].data, si->elements[name].stride, si->elements[name].format_desc->format, \
Henri Verbeetd7c7c762009-03-27 10:25:55 +0100919 si->elements[name].buffer_object, si->elements[name].stream_idx);
Jason Edmeadesf738c142004-12-09 11:42:34 +0000920
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000921/* Defines used for optimizations */
922
923/* Only reapply what is necessary */
924#define REAPPLY_ALPHAOP 0x0001
925#define REAPPLY_ALL 0xFFFF
926
927/* Advance declaration of structures to satisfy compiler */
Jason Edmeades447d5ed2004-10-21 20:59:12 +0000928typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
Jason Edmeades41427852005-01-09 17:37:02 +0000929typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
Stefan Dösingercff4e1e2006-04-17 17:04:59 +0200930typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl;
Stefan Dösingerc1623d42007-02-12 19:18:36 +0100931typedef struct IWineD3DDeviceImpl IWineD3DDeviceImpl;
Jason Edmeades447d5ed2004-10-21 20:59:12 +0000932
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000933/* Global variables */
Jason Edmeadeseba27af2004-11-28 15:04:41 +0000934extern const float identity[16];
935
Jason Edmeades24ab49e2004-09-23 04:34:27 +0000936/*****************************************************************************
Jason Edmeadesf738c142004-12-09 11:42:34 +0000937 * Compilable extra diagnostics
938 */
939
940/* Trace information per-vertex: (extremely high amount of trace) */
941#if 0 /* NOTE: Must be 0 in cvs */
942# define VTRACE(A) TRACE A
943#else
944# define VTRACE(A)
945#endif
946
Jason Edmeadesc4de9522004-12-14 11:54:27 +0000947/* TODO: Confirm each of these works when wined3d move completed */
948#if 0 /* NOTE: Must be 0 in cvs */
949 /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
Francois Gougetef998ea2006-10-15 17:05:01 +0200950 of each frame, a check is made for the existence of C:\D3DTRACE, and if it exists d3d trace
951 is enabled, and if it doesn't exist it is disabled. */
Jason Edmeadesc4de9522004-12-14 11:54:27 +0000952# define FRAME_DEBUGGING
953 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
954 the file is deleted */
955# if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
956# define SINGLE_FRAME_DEBUGGING
957# endif
958 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
959 It can only be enabled when FRAME_DEBUGGING is also enabled
960 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
961 array is drawn. */
962# if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
963# define SHOW_FRAME_MAKEUP 1
964# endif
965 /* The following, when enabled, lets you see the makeup of the all the textures used during each
966 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
967 The contents of the textures assigned to each stage are written into
968 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
969# if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
970# define SHOW_TEXTURE_MAKEUP 0
971# endif
972extern BOOL isOn;
973extern BOOL isDumpingFrames;
974extern LONG primCounter;
975#endif
976
Henri Verbeetd7c7c762009-03-27 10:25:55 +0100977enum wined3d_ffp_idx
978{
979 WINED3D_FFP_POSITION = 0,
980 WINED3D_FFP_BLENDWEIGHT = 1,
981 WINED3D_FFP_BLENDINDICES = 2,
982 WINED3D_FFP_NORMAL = 3,
983 WINED3D_FFP_PSIZE = 4,
984 WINED3D_FFP_DIFFUSE = 5,
985 WINED3D_FFP_SPECULAR = 6,
986 WINED3D_FFP_TEXCOORD0 = 7,
987 WINED3D_FFP_TEXCOORD1 = 8,
988 WINED3D_FFP_TEXCOORD2 = 9,
989 WINED3D_FFP_TEXCOORD3 = 10,
990 WINED3D_FFP_TEXCOORD4 = 11,
991 WINED3D_FFP_TEXCOORD5 = 12,
992 WINED3D_FFP_TEXCOORD6 = 13,
993 WINED3D_FFP_TEXCOORD7 = 14,
994};
995
Henri Verbeet4434d002009-03-27 10:25:56 +0100996enum wined3d_ffp_emit_idx
997{
998 WINED3D_FFP_EMIT_FLOAT1 = 0,
999 WINED3D_FFP_EMIT_FLOAT2 = 1,
1000 WINED3D_FFP_EMIT_FLOAT3 = 2,
1001 WINED3D_FFP_EMIT_FLOAT4 = 3,
1002 WINED3D_FFP_EMIT_D3DCOLOR = 4,
1003 WINED3D_FFP_EMIT_UBYTE4 = 5,
1004 WINED3D_FFP_EMIT_SHORT2 = 6,
1005 WINED3D_FFP_EMIT_SHORT4 = 7,
1006 WINED3D_FFP_EMIT_UBYTE4N = 8,
1007 WINED3D_FFP_EMIT_SHORT2N = 9,
1008 WINED3D_FFP_EMIT_SHORT4N = 10,
1009 WINED3D_FFP_EMIT_USHORT2N = 11,
1010 WINED3D_FFP_EMIT_USHORT4N = 12,
1011 WINED3D_FFP_EMIT_UDEC3 = 13,
1012 WINED3D_FFP_EMIT_DEC3N = 14,
1013 WINED3D_FFP_EMIT_FLOAT16_2 = 15,
1014 WINED3D_FFP_EMIT_FLOAT16_4 = 16,
1015 WINED3D_FFP_EMIT_COUNT = 17
1016};
1017
Henri Verbeetd7c7c762009-03-27 10:25:55 +01001018struct wined3d_stream_info_element
1019{
Henri Verbeetef2d7042009-03-30 11:24:54 +02001020 const struct GlPixelFormatDesc *format_desc;
Henri Verbeetd7c7c762009-03-27 10:25:55 +01001021 GLsizei stride;
Henri Verbeetd7c7c762009-03-27 10:25:55 +01001022 const BYTE *data;
Henri Verbeetd7c7c762009-03-27 10:25:55 +01001023 UINT stream_idx;
1024 GLuint buffer_object;
1025};
1026
1027struct wined3d_stream_info
1028{
1029 struct wined3d_stream_info_element elements[MAX_ATTRIBS];
1030 BOOL position_transformed;
1031 WORD swizzle_map; /* MAX_ATTRIBS, 16 */
1032 WORD use_map; /* MAX_ATTRIBS, 16 */
1033};
1034
Jason Edmeadesf738c142004-12-09 11:42:34 +00001035/*****************************************************************************
1036 * Prototypes
1037 */
1038
1039/* Routine common to the draw primitive and draw indexed primitive routines */
Henri Verbeet702eeb62009-03-05 12:30:43 +01001040void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT numberOfVertices,
1041 UINT start_idx, UINT idxBytes, const void *idxData, UINT minIndex);
Stefan Dösinger9abdac62006-05-12 22:21:31 +02001042DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
1043
Henri Verbeet50ebf262008-11-28 15:30:11 +01001044typedef void (WINE_GLAPI *glAttribFunc)(const void *data);
1045typedef void (WINE_GLAPI *glMultiTexCoordFunc)(GLenum unit, const void *data);
Henri Verbeet4434d002009-03-27 10:25:56 +01001046extern glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT];
1047extern glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT];
Henri Verbeet2cc43392009-03-11 10:15:09 +01001048extern glAttribFunc specular_func_3ubv;
Henri Verbeet4434d002009-03-27 10:25:56 +01001049extern glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT];
1050extern glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT];
1051extern glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT];
Stefan Dösinger2d904492007-12-19 17:10:02 +01001052
Stefan Dösinger10ff0d82006-05-09 18:16:13 +02001053#define eps 1e-8
1054
Stefan Dösinger9abdac62006-05-12 22:21:31 +02001055#define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
1056 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
1057
Stefan Dösingerc0268c72006-12-05 23:36:10 +01001058/* Routines and structures related to state management */
Stefan Dösinger380930d2007-02-12 19:18:31 +01001059typedef struct WineD3DContext WineD3DContext;
Stefan Dösingerc739c382007-02-12 19:18:22 +01001060typedef void (*APPLYSTATEFUNC)(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *ctx);
Stefan Dösingerc0268c72006-12-05 23:36:10 +01001061
Stefan Dösinger2a24e842006-12-06 13:22:12 +01001062#define STATE_RENDER(a) (a)
1063#define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
1064
Henri Verbeeta8697d92009-01-06 11:43:45 +01001065#define STATE_TEXTURESTAGE(stage, num) (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + 1 + (stage) * (WINED3D_HIGHEST_TEXTURE_STATE + 1) + (num))
Stefan Dösinger569a2fa2006-12-19 22:43:49 +01001066#define STATE_IS_TEXTURESTAGE(a) ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
1067
Stefan Dösinger2d1aeb42006-12-19 23:14:07 +01001068/* + 1 because samplers start with 0 */
1069#define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
H. Verbeet5b7758f2007-06-25 22:45:40 +02001070#define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1))
Stefan Dösinger2d1aeb42006-12-19 23:14:07 +01001071
H. Verbeet5b7758f2007-06-25 22:45:40 +02001072#define STATE_PIXELSHADER (STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1) + 1)
Stefan Dösinger22e2a5a2006-12-19 23:22:19 +01001073#define STATE_IS_PIXELSHADER(a) ((a) == STATE_PIXELSHADER)
1074
Stefan Dösingerb58715e2006-12-28 18:57:16 +01001075#define STATE_TRANSFORM(a) (STATE_PIXELSHADER + (a))
1076#define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)))
1077
Stefan Dösingeref1ebb62007-01-02 00:35:07 +01001078#define STATE_STREAMSRC (STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)) + 1)
1079#define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
Stefan Dösinger59ae2a52007-02-19 15:25:32 +01001080#define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
1081#define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
Stefan Dösingeref1ebb62007-01-02 00:35:07 +01001082
Stefan Dösinger59ae2a52007-02-19 15:25:32 +01001083#define STATE_VDECL (STATE_INDEXBUFFER + 1)
Stefan Dösingeref1ebb62007-01-02 00:35:07 +01001084#define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
1085
1086#define STATE_VSHADER (STATE_VDECL + 1)
1087#define STATE_IS_VSHADER(a) ((a) == STATE_VSHADER)
1088
Stefan Dösingera48bbc32007-01-02 21:40:59 +01001089#define STATE_VIEWPORT (STATE_VSHADER + 1)
1090#define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
1091
Stefan Dösinger8e37fcd2007-01-06 18:17:27 +01001092#define STATE_VERTEXSHADERCONSTANT (STATE_VIEWPORT + 1)
1093#define STATE_PIXELSHADERCONSTANT (STATE_VERTEXSHADERCONSTANT + 1)
1094#define STATE_IS_VERTEXSHADERCONSTANT(a) ((a) == STATE_VERTEXSHADERCONSTANT)
1095#define STATE_IS_PIXELSHADERCONSTANT(a) ((a) == STATE_PIXELSHADERCONSTANT)
1096
Stefan Dösinger174b6322007-02-14 17:48:52 +01001097#define STATE_ACTIVELIGHT(a) (STATE_PIXELSHADERCONSTANT + (a) + 1)
H. Verbeetcb4c9b62007-07-15 23:46:06 +02001098#define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS))
Stefan Dösinger174b6322007-02-14 17:48:52 +01001099
Stefan Dösingerecfd4cb2007-02-19 15:25:16 +01001100#define STATE_SCISSORRECT (STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS - 1) + 1)
1101#define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
1102
Stefan Dösinger409aa732007-02-28 14:36:36 +01001103#define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
1104#define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(MAX_CLIPPLANES - 1))
1105
Stefan Dösinger2f4b9e42007-06-15 21:33:54 +02001106#define STATE_MATERIAL (STATE_CLIPPLANE(MAX_CLIPPLANES))
1107
Stefan Dösinger5a63b792007-09-18 11:43:09 +02001108#define STATE_FRONTFACE (STATE_MATERIAL + 1)
1109
1110#define STATE_HIGHEST (STATE_FRONTFACE)
Stefan Dösinger7532c752006-12-19 13:00:03 +01001111
Stefan Dösingerc0268c72006-12-05 23:36:10 +01001112struct StateEntry
1113{
Stefan Dösinger68dec9d2008-07-01 19:43:52 -05001114 DWORD representative;
1115 APPLYSTATEFUNC apply;
Stefan Dösingerc0268c72006-12-05 23:36:10 +01001116};
1117
Stefan Dösinger68dec9d2008-07-01 19:43:52 -05001118struct StateEntryTemplate
1119{
1120 DWORD state;
1121 struct StateEntry content;
Stefan Dösinger35f33ef2008-07-05 15:04:16 -05001122 GL_SupportedExt extension;
Stefan Dösinger68dec9d2008-07-01 19:43:52 -05001123};
1124
Stefan Dösingere4078fb2008-07-03 14:36:18 -05001125struct fragment_caps {
1126 DWORD PrimitiveMiscCaps;
1127
1128 DWORD TextureOpCaps;
1129 DWORD MaxTextureBlendStages;
1130 DWORD MaxSimultaneousTextures;
1131};
1132
Stefan Dösingerc48195e2008-07-04 15:09:49 -05001133struct fragment_pipeline {
1134 void (*enable_extension)(IWineD3DDevice *iface, BOOL enable);
Henri Verbeetd8f6e632008-11-25 14:36:09 +01001135 void (*get_caps)(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct fragment_caps *caps);
Stefan Dösingere7733ea2008-07-11 09:41:28 -05001136 HRESULT (*alloc_private)(IWineD3DDevice *iface);
1137 void (*free_private)(IWineD3DDevice *iface);
Henri Verbeet89139b72008-12-03 14:53:43 +01001138 BOOL (*color_fixup_supported)(struct color_fixup_desc fixup);
Stefan Dösingerc48195e2008-07-04 15:09:49 -05001139 const struct StateEntryTemplate *states;
Stefan Dösingeraf8d2682008-08-23 15:41:51 -05001140 BOOL ffp_proj_control;
Stefan Dösingerc48195e2008-07-04 15:09:49 -05001141};
1142
Stefan Dösinger68dec9d2008-07-01 19:43:52 -05001143extern const struct StateEntryTemplate misc_state_template[];
Stefan Dösinger141f31f2008-07-02 10:02:19 -05001144extern const struct StateEntryTemplate ffp_vertexstate_template[];
Stefan Dösingerc48195e2008-07-04 15:09:49 -05001145extern const struct fragment_pipeline ffp_fragment_pipeline;
1146extern const struct fragment_pipeline atifs_fragment_pipeline;
Stefan Dösinger14b24052008-07-28 11:41:02 -05001147extern const struct fragment_pipeline arbfp_fragment_pipeline;
Stefan Dösinger86b033b2008-07-04 16:15:18 -05001148extern const struct fragment_pipeline nvts_fragment_pipeline;
1149extern const struct fragment_pipeline nvrc_fragment_pipeline;
1150
Stefan Dösinger84258722008-03-09 19:30:08 +01001151/* "Base" state table */
Allan Tong29dd2862009-01-06 20:20:08 -05001152HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
Henri Verbeet7c0cb8c2008-12-01 15:32:14 +01001153 const WineD3D_GL_Info *gl_info, const struct StateEntryTemplate *vertex,
1154 const struct fragment_pipeline *fragment, const struct StateEntryTemplate *misc);
Stefan Dösingerc0268c72006-12-05 23:36:10 +01001155
Stefan Dösingerfc6b9772008-08-01 13:21:10 -05001156/* Shaders for color conversions in blits */
1157struct blit_shader {
1158 HRESULT (*alloc_private)(IWineD3DDevice *iface);
1159 void (*free_private)(IWineD3DDevice *iface);
Henri Verbeetafc57442009-03-24 10:09:24 +01001160 HRESULT (*set_shader)(IWineD3DDevice *iface, const struct GlPixelFormatDesc *format_desc,
1161 GLenum textype, UINT width, UINT height);
Stefan Dösingerfc6b9772008-08-01 13:21:10 -05001162 void (*unset_shader)(IWineD3DDevice *iface);
Henri Verbeet89139b72008-12-03 14:53:43 +01001163 BOOL (*color_fixup_supported)(struct color_fixup_desc fixup);
Stefan Dösingerfc6b9772008-08-01 13:21:10 -05001164};
1165
1166extern const struct blit_shader ffp_blit;
Stefan Dösinger1f4cf352008-08-19 11:09:45 -05001167extern const struct blit_shader arbfp_blit;
Stefan Dösingerfc6b9772008-08-01 13:21:10 -05001168
Stefan Dösinger1deafcb2008-12-15 19:37:36 +01001169enum fogsource {
1170 FOGSOURCE_FFP,
1171 FOGSOURCE_VS,
1172 FOGSOURCE_COORD,
1173};
1174
Henri Verbeet0d446052009-05-11 16:43:49 +02001175#define WINED3D_MAX_FBO_ENTRIES 64
1176
Stefan Dösinger380930d2007-02-12 19:18:31 +01001177/* The new context manager that should deal with onscreen and offscreen rendering */
1178struct WineD3DContext {
1179 /* State dirtification
1180 * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices
1181 * 0...numDirtyEntries - 1. isStateDirty is a redundant copy of the dirtyArray. Technically only one of them would be needed,
1182 * 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
1183 * only numDirtyEntries array elements have to be checked, not STATE_HIGHEST states.
1184 */
1185 DWORD dirtyArray[STATE_HIGHEST + 1]; /* Won't get bigger than that, a state is never marked dirty 2 times */
1186 DWORD numDirtyEntries;
1187 DWORD isStateDirty[STATE_HIGHEST/32 + 1]; /* Bitmap to find out quickly if a state is dirty */
1188
Stefan Dösinger12252d02007-02-12 19:21:10 +01001189 IWineD3DSurface *surface;
Stefan Dösinger90fe64c2007-03-04 17:31:06 +01001190 DWORD tid; /* Thread ID which owns this context at the moment */
Stefan Dösinger380930d2007-02-12 19:18:31 +01001191
Austin English3471f842008-01-09 13:37:05 -06001192 /* Stores some information about the context state for optimization */
Henri Verbeet3f12f592008-12-30 14:56:49 +01001193 WORD draw_buffer_dirty : 1;
1194 WORD last_was_rhw : 1; /* true iff last draw_primitive was in xyzrhw mode */
1195 WORD last_was_pshader : 1;
1196 WORD last_was_vshader : 1;
Henri Verbeet3f12f592008-12-30 14:56:49 +01001197 WORD namedArraysLoaded : 1;
1198 WORD numberedArraysLoaded : 1;
1199 WORD last_was_blit : 1;
1200 WORD last_was_ckey : 1;
1201 WORD fog_coord : 1;
1202 WORD isPBuffer : 1;
1203 WORD fog_enabled : 1;
1204 WORD num_untracked_materials : 2; /* Max value 2 */
Stefan Dösinger50109aa2009-01-16 15:09:18 +01001205 WORD padding : 3;
Henri Verbeet3f12f592008-12-30 14:56:49 +01001206 BYTE texShaderBumpMap; /* MAX_TEXTURES, 8 */
1207 BYTE lastWasPow2Texture; /* MAX_TEXTURES, 8 */
Henri Verbeet5ad3bba2008-12-08 10:30:02 +01001208 DWORD numbered_array_mask;
Stefan Dösinger380930d2007-02-12 19:18:31 +01001209 GLenum tracking_parm; /* Which source is tracking current colour */
Stefan Dösingerb081cba2007-06-20 14:36:32 +02001210 GLenum untracked_materials[2];
Stefan Dösinger74c56842008-06-17 01:41:49 +02001211 UINT blit_w, blit_h;
Stefan Dösinger1deafcb2008-12-15 19:37:36 +01001212 enum fogsource fog_source;
Stefan Dösinger12252d02007-02-12 19:21:10 +01001213
Stefan Dösinger107e80a2008-03-04 02:30:23 +01001214 char *vshader_const_dirty, *pshader_const_dirty;
1215
Stefan Dösinger12252d02007-02-12 19:21:10 +01001216 /* The actual opengl context */
Roderick Colenbranderac3927a2007-08-08 03:09:38 +02001217 HGLRC glCtx;
1218 HWND win_handle;
1219 HDC hdc;
1220 HPBUFFERARB pbuffer;
Stefan Dösinger67e09432008-04-08 14:20:27 +02001221 GLint aux_buffers;
H. Verbeet05931f42008-08-21 18:34:55 +02001222
1223 /* FBOs */
Henri Verbeet0d446052009-05-11 16:43:49 +02001224 UINT fbo_entry_count;
Henri Verbeet45820042008-09-18 14:57:53 +02001225 struct list fbo_list;
1226 struct fbo_entry *current_fbo;
H. Verbeet05931f42008-08-21 18:34:55 +02001227 GLuint src_fbo;
1228 GLuint dst_fbo;
Stefan Dösinger31da3c02008-12-15 19:21:37 +01001229
1230 /* Extension emulation */
Stefan Dösinger31da3c02008-12-15 19:21:37 +01001231 GLint gl_fog_source;
1232 GLfloat fog_coord_value;
1233 GLfloat color[4], fogstart, fogend, fogcolor[4];
Stefan Dösinger06295852009-05-07 11:40:44 +02001234 GLuint dummy_arbfp_prog;
Stefan Dösinger380930d2007-02-12 19:18:31 +01001235};
1236
Stefan Dösingerc1623d42007-02-12 19:18:36 +01001237typedef enum ContextUsage {
1238 CTXUSAGE_RESOURCELOAD = 1, /* Only loads textures: No State is applied */
Austin English3471f842008-01-09 13:37:05 -06001239 CTXUSAGE_DRAWPRIM = 2, /* OpenGL states are set up for blitting DirectDraw surfaces */
Stefan Dösingerc1623d42007-02-12 19:18:36 +01001240 CTXUSAGE_BLIT = 3, /* OpenGL states are set up 3D drawing */
Stefan Dösingerfdadf262007-07-09 16:57:58 +02001241 CTXUSAGE_CLEAR = 4, /* Drawable and states are set up for clearing */
Stefan Dösingerc1623d42007-02-12 19:18:36 +01001242} ContextUsage;
1243
1244void ActivateContext(IWineD3DDeviceImpl *device, IWineD3DSurface *target, ContextUsage usage);
Stefan Dösinger31da3c02008-12-15 19:21:37 +01001245WineD3DContext *getActiveContext(void);
Roderick Colenbrander57547262007-08-11 12:17:56 +02001246WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, HWND win, BOOL create_pbuffer, const WINED3DPRESENT_PARAMETERS *pPresentParms);
Stefan Dösinger12252d02007-02-12 19:21:10 +01001247void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context);
Henri Verbeet76de76e2008-09-18 14:57:53 +02001248void context_resource_released(IWineD3DDevice *iface, IWineD3DResource *resource, WINED3DRESOURCETYPE type);
Henri Verbeeta2692362008-09-18 14:57:53 +02001249void context_bind_fbo(IWineD3DDevice *iface, GLenum target, GLuint *fbo);
1250void context_attach_depth_stencil_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer);
1251void context_attach_surface_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, DWORD idx, IWineD3DSurface *surface);
Stefan Dösingerc1623d42007-02-12 19:18:36 +01001252
Stefan Dösinger7f2b8f92008-07-29 12:09:34 -05001253void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain);
1254HRESULT create_primary_opengl_context(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain);
1255
Roderick Colenbranderde97fa72006-08-19 11:58:23 +02001256/* Macros for doing basic GPU detection based on opengl capabilities */
1257#define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
1258#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])
1259#define WINE_D3D8_CAPABLE(gl_info) WINE_D3D7_CAPABLE(gl_info) && (gl_info->supported[ARB_MULTISAMPLE] && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
1260#define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER])
1261
Markus Amsler04ae4592006-12-05 00:28:58 +01001262/* Default callbacks for implicit object destruction */
1263extern ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface);
1264
Markus Amsler50a0c212006-12-05 00:29:21 +01001265extern ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pSurface);
1266
Jason Edmeadesf738c142004-12-09 11:42:34 +00001267/*****************************************************************************
Jason Edmeades0a944ae2004-11-29 17:53:42 +00001268 * Internal representation of a light
1269 */
1270typedef struct PLIGHTINFOEL PLIGHTINFOEL;
1271struct PLIGHTINFOEL {
1272 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
1273 DWORD OriginalIndex;
1274 LONG glIndex;
Jason Edmeades0a944ae2004-11-29 17:53:42 +00001275 BOOL changed;
1276 BOOL enabledChanged;
Stefan Dösinger3cc253c2007-11-29 13:22:47 +01001277 BOOL enabled;
Jason Edmeades0a944ae2004-11-29 17:53:42 +00001278
1279 /* Converted parms to speed up swapping lights */
1280 float lightPosn[4];
1281 float lightDirn[4];
1282 float exponent;
1283 float cutoff;
1284
Stefan Dösingeracadf3f2007-02-14 17:46:54 +01001285 struct list entry;
Jason Edmeades0a944ae2004-11-29 17:53:42 +00001286};
1287
Ivan Gyurdiev4d666152006-06-06 23:37:05 -04001288/* The default light parameters */
1289extern const WINED3DLIGHT WINED3D_default_light;
1290
Roderick Colenbranderd391c112007-08-11 16:25:58 +02001291typedef struct WineD3D_PixelFormat
1292{
1293 int iPixelFormat; /* WGL pixel format */
Roderick Colenbrander51a81622008-03-21 14:52:15 +01001294 int iPixelType; /* WGL pixel type e.g. WGL_TYPE_RGBA_ARB, WGL_TYPE_RGBA_FLOAT_ARB or WGL_TYPE_COLORINDEX_ARB */
Roderick Colenbranderd391c112007-08-11 16:25:58 +02001295 int redSize, greenSize, blueSize, alphaSize;
1296 int depthSize, stencilSize;
Roderick Colenbranderd44c2952008-03-16 16:37:38 +00001297 BOOL windowDrawable;
1298 BOOL pbufferDrawable;
Roderick Colenbrander31dc00a2008-04-27 17:36:34 +00001299 BOOL doubleBuffer;
1300 int auxBuffers;
Roderick Colenbrander628e4ee2008-04-28 21:44:21 +00001301 int numSamples;
Roderick Colenbranderd391c112007-08-11 16:25:58 +02001302} WineD3D_PixelFormat;
1303
Stefan Dösingera460a2d2007-06-09 14:27:41 +02001304/* The adapter structure */
1305struct WineD3DAdapter
1306{
Stefan Dösinger7f10ee42007-12-06 23:43:25 +01001307 UINT num;
Stefan Dösinger9e831a82008-03-28 23:04:17 +01001308 BOOL opengl;
Stefan Dösingera460a2d2007-06-09 14:27:41 +02001309 POINT monitorPoint;
Stefan Dösingera460a2d2007-06-09 14:27:41 +02001310 WineD3D_GL_Info gl_info;
Stefan Dösinger66930552007-06-08 15:23:04 +02001311 const char *driver;
1312 const char *description;
Roderick Colenbrander6b177c42007-08-13 16:47:17 +02001313 WCHAR DeviceName[CCHDEVICENAME]; /* DeviceName for use with e.g. ChangeDisplaySettings */
Stefan Dösingerefbdd512007-06-08 14:16:37 +02001314 int nCfgs;
Roderick Colenbranderd391c112007-08-11 16:25:58 +02001315 WineD3D_PixelFormat *cfgs;
Roderick Colenbrander7b5561c2008-05-03 14:37:09 +00001316 BOOL brokenStencil; /* Set on cards which only offer mixed depth+stencil */
Roderick Colenbrander243ac3e2007-09-23 00:46:21 +02001317 unsigned int TextureRam; /* Amount of texture memory both video ram + AGP/TurboCache/HyperMemory/.. */
1318 unsigned int UsedTextureRam;
Stefan Dösingera460a2d2007-06-09 14:27:41 +02001319};
1320
Stefan Dösingerd2016ff2007-07-27 13:22:54 +02001321extern BOOL initPixelFormats(WineD3D_GL_Info *gl_info);
Henri Verbeet53bf5c22009-03-13 10:44:17 +01001322BOOL initPixelFormatsNoGL(WineD3D_GL_Info *gl_info);
Roderick Colenbrander243ac3e2007-09-23 00:46:21 +02001323extern long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram);
Stefan Dösinger199a3462008-12-16 13:18:49 +01001324extern void add_gl_compat_wrappers(WineD3D_GL_Info *gl_info);
Stefan Dösingera460a2d2007-06-09 14:27:41 +02001325
Jason Edmeades0a944ae2004-11-29 17:53:42 +00001326/*****************************************************************************
Stefan Dösinger26ebe392007-07-04 17:57:45 +02001327 * High order patch management
1328 */
1329struct WineD3DRectPatch
1330{
1331 UINT Handle;
1332 float *mem;
1333 WineDirect3DVertexStridedData strided;
1334 WINED3DRECTPATCH_INFO RectPatchInfo;
1335 float numSegs[4];
1336 char has_normals, has_texcoords;
1337 struct list entry;
1338};
1339
1340HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This, struct WineD3DRectPatch *patch);
1341
Stefan Dösinger4640be82008-03-22 14:31:52 +01001342enum projection_types
1343{
Stefan Dösingerd4d133f2008-07-30 10:57:32 -05001344 proj_none = 0,
1345 proj_count3 = 1,
1346 proj_count4 = 2
1347};
1348
Stefan Dösingerd4d133f2008-07-30 10:57:32 -05001349enum dst_arg
1350{
1351 resultreg = 0,
1352 tempreg = 1
Stefan Dösinger4640be82008-03-22 14:31:52 +01001353};
1354
1355/*****************************************************************************
1356 * Fixed function pipeline replacements
1357 */
Stefan Dösingerf2f90b62008-12-09 20:02:18 +01001358#define ARG_UNUSED 0xff
Stefan Dösinger4640be82008-03-22 14:31:52 +01001359struct texture_stage_op
1360{
Henri Verbeet89139b72008-12-03 14:53:43 +01001361 unsigned cop : 8;
1362 unsigned carg1 : 8;
1363 unsigned carg2 : 8;
1364 unsigned carg0 : 8;
1365
1366 unsigned aop : 8;
1367 unsigned aarg1 : 8;
1368 unsigned aarg2 : 8;
1369 unsigned aarg0 : 8;
1370
Henri Verbeet4aa00e82008-12-10 10:04:40 +01001371 struct color_fixup_desc color_fixup;
Stefan Dösingerd4d133f2008-07-30 10:57:32 -05001372 unsigned tex_type : 3;
Henri Verbeet89139b72008-12-03 14:53:43 +01001373 unsigned dst : 1;
Stefan Dösingerd4d133f2008-07-30 10:57:32 -05001374 unsigned projected : 2;
Henri Verbeet89139b72008-12-03 14:53:43 +01001375 unsigned padding : 10;
Stefan Dösinger4640be82008-03-22 14:31:52 +01001376};
1377
Stefan Dösinger5c79a9f2008-11-07 17:15:29 +01001378struct ffp_frag_settings {
Stefan Dösinger294f1b42008-07-11 21:18:06 -05001379 struct texture_stage_op op[MAX_TEXTURES];
Stefan Dösinger690cbe72008-12-15 19:35:40 +01001380 enum fogmode fog;
Stefan Dösinger421b6552008-09-04 15:51:21 -05001381 /* Use an int instead of a char to get dword alignment */
Henri Verbeet81effcf2008-09-04 15:32:36 +02001382 unsigned int sRGB_write;
Stefan Dösinger294f1b42008-07-11 21:18:06 -05001383};
1384
Stefan Dösinger5c79a9f2008-11-07 17:15:29 +01001385struct ffp_frag_desc
Stefan Dösinger4640be82008-03-22 14:31:52 +01001386{
Stefan Dösinger5c79a9f2008-11-07 17:15:29 +01001387 struct ffp_frag_settings settings;
Stefan Dösinger4640be82008-03-22 14:31:52 +01001388};
1389
Stefan Dösinger5c79a9f2008-11-07 17:15:29 +01001390void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_settings *settings, BOOL ignore_textype);
Henri Verbeet5532c992008-12-01 15:32:15 +01001391const struct ffp_frag_desc *find_ffp_frag_shader(const struct hash_table_t *fragment_shaders,
Henri Verbeeteb78c2a2008-11-25 14:36:08 +01001392 const struct ffp_frag_settings *settings);
Stefan Dösinger5c79a9f2008-11-07 17:15:29 +01001393void add_ffp_frag_shader(struct hash_table_t *shaders, struct ffp_frag_desc *desc);
Henri Verbeeteb78c2a2008-11-25 14:36:08 +01001394BOOL ffp_frag_program_key_compare(const void *keya, const void *keyb);
1395unsigned int ffp_frag_program_key_hash(const void *key);
Stefan Dösinger4640be82008-03-22 14:31:52 +01001396
Stefan Dösinger26ebe392007-07-04 17:57:45 +02001397/*****************************************************************************
Jason Edmeades24ab49e2004-09-23 04:34:27 +00001398 * IWineD3D implementation structure
1399 */
1400typedef struct IWineD3DImpl
1401{
1402 /* IUnknown fields */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001403 const IWineD3DVtbl *lpVtbl;
Mike McCormack8955ac42005-07-28 10:16:21 +00001404 LONG ref; /* Note: Ref counting not required */
Jason Edmeades24ab49e2004-09-23 04:34:27 +00001405
1406 /* WineD3D Information */
Jason Edmeades289562e2004-11-23 13:52:46 +00001407 IUnknown *parent;
Jason Edmeades24ab49e2004-09-23 04:34:27 +00001408 UINT dxVersion;
Henri Verbeet2cc43392009-03-11 10:15:09 +01001409
1410 UINT adapter_count;
1411 struct WineD3DAdapter adapters[1];
Jason Edmeades24ab49e2004-09-23 04:34:27 +00001412} IWineD3DImpl;
1413
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001414extern const IWineD3DVtbl IWineD3D_Vtbl;
Jason Edmeades24ab49e2004-09-23 04:34:27 +00001415
Henri Verbeet2cc43392009-03-11 10:15:09 +01001416BOOL InitAdapters(IWineD3DImpl *This);
1417
Francois Gouget93494f22007-02-20 15:57:10 +01001418/* TODO: setup some flags in the registry to enable, disable pbuffer support
Oliver Stieber94856322005-07-19 11:39:24 +00001419(since it will break quite a few things until contexts are managed properly!) */
1420extern BOOL pbuffer_support;
1421/* allocate one pbuffer per surface */
1422extern BOOL pbuffer_per_surface;
1423
Stefan Dösingere0c87732006-04-10 19:39:53 +02001424/* A helper function that dumps a resource list */
Stefan Dösinger1fc1fe32007-11-16 20:28:45 +01001425void dumpResources(struct list *list);
Stefan Dösingere0c87732006-04-10 19:39:53 +02001426
Jason Edmeadesac490fa2004-10-07 04:22:21 +00001427/*****************************************************************************
1428 * IWineD3DDevice implementation structure
1429 */
Henri Verbeet4ff57362009-03-09 14:31:28 +01001430#define WINED3D_UNMAPPED_STAGE ~0U
1431
Henri Verbeet7420a962009-05-01 09:13:54 +02001432/* Multithreaded flag. Removed from the public header to signal that IWineD3D::CreateDevice ignores it */
1433#define WINED3DCREATE_MULTITHREADED 0x00000004
1434
Stefan Dösingerc1623d42007-02-12 19:18:36 +01001435struct IWineD3DDeviceImpl
Jason Edmeadesac490fa2004-10-07 04:22:21 +00001436{
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +00001437 /* IUnknown fields */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001438 const IWineD3DDeviceVtbl *lpVtbl;
Mike McCormack8955ac42005-07-28 10:16:21 +00001439 LONG ref; /* Note: Ref counting not required */
Jason Edmeadesac490fa2004-10-07 04:22:21 +00001440
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +00001441 /* WineD3D Information */
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001442 IUnknown *parent;
Henri Verbeeta9662932009-01-16 10:14:24 +01001443 IWineD3DDeviceParent *device_parent;
Jason Edmeadeseba27af2004-11-28 15:04:41 +00001444 IWineD3D *wineD3D;
Stefan Dösingera460a2d2007-06-09 14:27:41 +02001445 struct WineD3DAdapter *adapter;
Jason Edmeadesac490fa2004-10-07 04:22:21 +00001446
H. Verbeet61125222007-01-18 23:41:36 +01001447 /* Window styles to restore when switching fullscreen mode */
1448 LONG style;
1449 LONG exStyle;
1450
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +00001451 /* X and GL Information */
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +00001452 GLint maxConcurrentLights;
Stefan Dösinger8d9a5532007-02-27 21:32:15 +01001453 GLenum offscreenBuffer;
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +00001454
Ivan Gyurdieve020ece2006-10-07 23:25:01 -04001455 /* Selected capabilities */
1456 int vs_selected_mode;
1457 int ps_selected_mode;
H. Verbeet8a7f4272006-11-27 20:50:43 +01001458 const shader_backend_t *shader_backend;
Stefan Dösingerf912f182008-02-24 11:23:53 +01001459 void *shader_priv;
Stefan Dösingere7733ea2008-07-11 09:41:28 -05001460 void *fragment_priv;
Stefan Dösingerfc6b9772008-08-01 13:21:10 -05001461 void *blit_priv;
Stefan Dösinger98faed82008-07-01 18:23:44 -05001462 struct StateEntry StateTable[STATE_HIGHEST + 1];
Stefan Dösinger68dec9d2008-07-01 19:43:52 -05001463 /* Array of functions for states which are handled by more than one pipeline part */
1464 APPLYSTATEFUNC *multistate_funcs[STATE_HIGHEST + 1];
Stefan Dösingerc48195e2008-07-04 15:09:49 -05001465 const struct fragment_pipeline *frag_pipe;
Stefan Dösingerfc6b9772008-08-01 13:21:10 -05001466 const struct blit_shader *blitter;
Ivan Gyurdieve020ece2006-10-07 23:25:01 -04001467
Stefan Dösinger462ddaa2008-08-21 13:23:38 -05001468 unsigned int max_ffp_textures, max_ffp_texture_stages;
Stefan Dösinger754b5cf2009-03-22 12:24:28 +01001469 DWORD d3d_vshader_constantF, d3d_pshader_constantF; /* Advertised d3d caps, not GL ones */
Stefan Dösinger2cb8f422009-05-08 17:24:01 +02001470 DWORD vs_clipping;
Stefan Dösinger9a6bc682008-08-17 23:46:47 +02001471
Henri Verbeet29a0d062008-12-30 14:56:49 +01001472 WORD view_ident : 1; /* true iff view matrix is identity */
1473 WORD untransformed : 1;
1474 WORD vertexBlendUsed : 1; /* To avoid needless setting of the blend matrices */
1475 WORD isRecordingState : 1;
1476 WORD isInDraw : 1;
1477 WORD render_offscreen : 1;
1478 WORD bCursorVisible : 1;
1479 WORD haveHardwareCursor : 1;
1480 WORD d3d_initialized : 1;
1481 WORD inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */
1482 WORD softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */
1483 WORD useDrawStridedSlow : 1;
1484 WORD instancedDraw : 1;
1485 WORD padding : 3;
1486
1487 BYTE fixed_function_usage_map; /* MAX_TEXTURES, 8 */
1488
Stefan Dösinger399825c2008-08-02 18:06:01 -05001489#define DDRAW_PITCH_ALIGNMENT 8
1490#define D3D8_PITCH_ALIGNMENT 4
Stefan Dösinger6e5a5d22007-06-08 22:28:04 +02001491 unsigned char surface_alignment; /* Line Alignment of surfaces */
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +00001492
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001493 /* State block related */
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001494 IWineD3DStateBlockImpl *stateBlock;
1495 IWineD3DStateBlockImpl *updateStateBlock;
1496
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +00001497 /* Internal use fields */
Stefan Dösingerf6ed7042006-04-03 14:54:16 +02001498 WINED3DDEVICE_CREATION_PARAMETERS createParms;
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +00001499 UINT adapterNo;
Ivan Gyurdiev19c55342006-10-10 21:52:00 -04001500 WINED3DDEVTYPE devType;
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +00001501
Stefan Dösingere902cd12006-05-24 11:34:30 +02001502 IWineD3DSwapChain **swapchains;
Roderick Colenbranderf3af04a2007-08-06 16:38:00 +02001503 UINT NumberOfSwapChains;
Oliver Stieber46e7c302005-06-23 11:05:24 +00001504
Stefan Dösinger1fc1fe32007-11-16 20:28:45 +01001505 struct list resources; /* a linked list to track resources created by the device */
Stefan Dösinger09bf3d52008-01-08 20:45:59 +01001506 struct list shaders; /* a linked list to track shaders (pixel and vertex) */
Stefan Dösinger107e80a2008-03-04 02:30:23 +01001507 unsigned int highest_dirty_ps_const, highest_dirty_vs_const;
Oliver Stieberea6189e2005-07-26 10:34:15 +00001508
Jason Edmeades41427852005-01-09 17:37:02 +00001509 /* Render Target Support */
H. Verbeet8355b1a2006-12-19 19:25:22 +01001510 IWineD3DSurface **render_targets;
Stefan Dösingere4f8a2d2007-11-10 00:19:19 +01001511 IWineD3DSurface *auto_depth_stencil_buffer;
Oliver Stieberba5eb142005-03-14 10:12:52 +00001512 IWineD3DSurface *stencilBufferTarget;
Jason Edmeades41427852005-01-09 17:37:02 +00001513
Stefan Dösinger12252d02007-02-12 19:21:10 +01001514 /* Caches to avoid unneeded context changes */
1515 IWineD3DSurface *lastActiveRenderTarget;
1516 IWineD3DSwapChain *lastActiveSwapChain;
1517
Jason Edmeades41427852005-01-09 17:37:02 +00001518 /* palettes texture management */
Alexander Dorofeyev16597092008-03-27 00:23:04 +02001519 UINT NumberOfPalettes;
1520 PALETTEENTRY **palettes;
Oliver Stieberba5eb142005-03-14 10:12:52 +00001521 UINT currentPalette;
Roderick Colenbrander134aa672007-10-11 23:11:37 +02001522 UINT paletteConversionShader;
Jason Edmeades41427852005-01-09 17:37:02 +00001523
Jason Edmeadesf738c142004-12-09 11:42:34 +00001524 /* For rendering to a texture using glCopyTexImage */
H. Verbeet299c1e62006-12-19 19:25:35 +01001525 GLenum *draw_buffers;
Stefan Dösinger3d2aa7a2008-01-27 14:32:40 +01001526 GLuint depth_blt_texture;
H. Verbeete7d0ef72008-07-02 23:00:11 +02001527 GLuint depth_blt_rb;
1528 UINT depth_blt_rb_w;
1529 UINT depth_blt_rb_h;
Jason Edmeadesf738c142004-12-09 11:42:34 +00001530
Oliver Stieber2121f782005-03-02 12:16:10 +00001531 /* Cursor management */
Oliver Stieber2121f782005-03-02 12:16:10 +00001532 UINT xHotSpot;
1533 UINT yHotSpot;
1534 UINT xScreenSpace;
1535 UINT yScreenSpace;
Stefan Dösinger65e5ed62006-07-27 17:39:03 +02001536 UINT cursorWidth, cursorHeight;
1537 GLuint cursorTexture;
Andrew Riedia9c2e152007-05-14 15:37:53 -07001538 HCURSOR hardwareCursor;
Oliver Stieber2121f782005-03-02 12:16:10 +00001539
Stefan Dösinger271fb002007-09-01 21:22:32 +02001540 /* The Wine logo surface */
1541 IWineD3DSurface *logo_surface;
1542
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001543 /* Textures for when no other textures are mapped */
Oliver Stieberabb11f32005-07-05 14:05:18 +00001544 UINT dummyTextureName[MAX_TEXTURES];
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001545
Oliver Stieber329d0172005-09-21 10:55:03 +00001546 /* Device state management */
1547 HRESULT state;
Stefan Dösinger04da3ce2006-04-18 23:39:52 +02001548
1549 /* DirectDraw stuff */
Stefan Dösinger566cdcf2006-05-18 22:42:22 +02001550 DWORD ddraw_width, ddraw_height;
1551 WINED3DFORMAT ddraw_format;
Stefan Dösinger04da3ce2006-04-18 23:39:52 +02001552
Stefan Dösinger96bce8d2006-09-23 19:09:06 +02001553 /* Final position fixup constant */
1554 float posFixup[4];
Stefan Dösinger7532c752006-12-19 13:00:03 +01001555
Stefan Dösingerdf97fd32006-12-19 23:33:34 +01001556 /* With register combiners we can skip junk texture stages */
H. Verbeet5b7758f2007-06-25 22:45:40 +02001557 DWORD texUnitMap[MAX_COMBINED_SAMPLERS];
1558 DWORD rev_tex_unit_map[MAX_COMBINED_SAMPLERS];
Stefan Dösingerdf97fd32006-12-19 23:33:34 +01001559
Stefan Dösinger091f9c22007-01-02 00:21:26 +01001560 /* Stream source management */
Henri Verbeetd7c7c762009-03-27 10:25:55 +01001561 struct wined3d_stream_info strided_streams;
Henri Verbeet5532c992008-12-01 15:32:15 +01001562 const WineDirect3DVertexStridedData *up_strided;
Stefan Dösinger091f9c22007-01-02 00:21:26 +01001563
Stefan Dösingerc739c382007-02-12 19:18:22 +01001564 /* Context management */
Stefan Dösinger12252d02007-02-12 19:21:10 +01001565 WineD3DContext **contexts; /* Dynamic array containing pointers to context structures */
Stefan Dösinger13f24c32007-06-02 20:20:17 +00001566 WineD3DContext *activeContext;
1567 DWORD lastThread;
1568 UINT numContexts;
Stefan Dösinger12252d02007-02-12 19:21:10 +01001569 WineD3DContext *pbufferContext; /* The context that has a pbuffer as drawable */
1570 DWORD pbufferWidth, pbufferHeight; /* Size of the buffer drawable */
Stefan Dösinger26ebe392007-07-04 17:57:45 +02001571
1572 /* High level patch management */
1573#define PATCHMAP_SIZE 43
1574#define PATCHMAP_HASHFUNC(x) ((x) % PATCHMAP_SIZE) /* Primitive and simple function */
1575 struct list patches[PATCHMAP_SIZE];
1576 struct WineD3DRectPatch *currentPatch;
Stefan Dösingerc1623d42007-02-12 19:18:36 +01001577};
Jason Edmeadesac490fa2004-10-07 04:22:21 +00001578
Henri Verbeetd099dde2008-12-17 17:07:25 +01001579extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
Jason Edmeadesac490fa2004-10-07 04:22:21 +00001580
Henri Verbeet5e0f5412009-05-29 09:13:21 +02001581void device_resource_released(IWineD3DDeviceImpl *This, IWineD3DResource *resource);
Henri Verbeetd7c7c762009-03-27 10:25:55 +01001582void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
1583 BOOL use_vshader, struct wined3d_stream_info *stream_info, BOOL *fixup);
1584void device_stream_info_from_strided(IWineD3DDeviceImpl *This,
1585 const struct WineDirect3DVertexStridedData *strided, struct wined3d_stream_info *stream_info);
Alexander Dorofeyevf5aaabd2007-12-19 23:32:11 -08001586HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, DWORD Count,
1587 CONST WINED3DRECT* pRects, DWORD Flags, WINED3DCOLOR Color,
1588 float Z, DWORD Stencil);
H. Verbeetb9d5c182007-06-12 23:08:22 +02001589void IWineD3DDeviceImpl_FindTexUnitMap(IWineD3DDeviceImpl *This);
Stefan Dösinger7532c752006-12-19 13:00:03 +01001590void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state);
Stefan Dösinger380930d2007-02-12 19:18:31 +01001591static inline BOOL isStateDirty(WineD3DContext *context, DWORD state) {
Stefan Dösinger7532c752006-12-19 13:00:03 +01001592 DWORD idx = state >> 5;
1593 BYTE shift = state & 0x1f;
Stefan Dösinger380930d2007-02-12 19:18:31 +01001594 return context->isStateDirty[idx] & (1 << shift);
Stefan Dösinger7532c752006-12-19 13:00:03 +01001595}
1596
Stefan Dösingerd08585e2007-05-07 20:46:24 +02001597/* Support for IWineD3DResource ::Set/Get/FreePrivateData. */
Oliver Stieberfe80b4e2005-07-15 09:54:57 +00001598typedef struct PrivateData
1599{
Stefan Dösingerd08585e2007-05-07 20:46:24 +02001600 struct list entry;
Oliver Stieberfe80b4e2005-07-15 09:54:57 +00001601
1602 GUID tag;
1603 DWORD flags; /* DDSPD_* */
Oliver Stieberfe80b4e2005-07-15 09:54:57 +00001604
1605 union
1606 {
1607 LPVOID data;
1608 LPUNKNOWN object;
1609 } ptr;
1610
1611 DWORD size;
1612} PrivateData;
1613
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001614/*****************************************************************************
1615 * IWineD3DResource implementation structure
1616 */
1617typedef struct IWineD3DResourceClass
1618{
1619 /* IUnknown fields */
Mike McCormack8955ac42005-07-28 10:16:21 +00001620 LONG ref; /* Note: Ref counting not required */
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001621
1622 /* WineD3DResource Information */
Jason Edmeades289562e2004-11-23 13:52:46 +00001623 IUnknown *parent;
Stefan Dösinger913df5b2006-03-09 23:21:16 +01001624 WINED3DRESOURCETYPE resourceType;
Jason Edmeades41427852005-01-09 17:37:02 +00001625 IWineD3DDeviceImpl *wineD3DDevice;
Stefan Dösingerd75fd752006-03-28 14:20:47 +02001626 WINED3DPOOL pool;
Oliver Stieber67f2ad42005-03-29 19:01:00 +00001627 UINT size;
1628 DWORD usage;
Henri Verbeet38178542009-03-12 09:53:14 +01001629 const struct GlPixelFormatDesc *format_desc;
Kjell Rune Skaaraased96dd72008-09-29 19:52:18 +02001630 DWORD priority;
Stefan Dösinger4d4fce72007-10-22 13:02:03 +02001631 BYTE *allocatedMemory; /* Pointer to the real data location */
1632 BYTE *heapMemory; /* Pointer to the HeapAlloced block of memory */
Stefan Dösingerd08585e2007-05-07 20:46:24 +02001633 struct list privateData;
Stefan Dösinger1fc1fe32007-11-16 20:28:45 +01001634 struct list resource_list_entry;
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001635
1636} IWineD3DResourceClass;
1637
1638typedef struct IWineD3DResourceImpl
1639{
1640 /* IUnknown & WineD3DResource Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001641 const IWineD3DResourceVtbl *lpVtbl;
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001642 IWineD3DResourceClass resource;
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001643} IWineD3DResourceImpl;
1644
Henri Verbeet2acf8d72008-12-02 18:41:33 +01001645void resource_cleanup(IWineD3DResource *iface);
1646HRESULT resource_free_private_data(IWineD3DResource *iface, REFGUID guid);
1647HRESULT resource_get_device(IWineD3DResource *iface, IWineD3DDevice **device);
1648HRESULT resource_get_parent(IWineD3DResource *iface, IUnknown **parent);
1649DWORD resource_get_priority(IWineD3DResource *iface);
1650HRESULT resource_get_private_data(IWineD3DResource *iface, REFGUID guid,
1651 void *data, DWORD *data_size);
Henri Verbeete4cfbdd2009-01-13 10:31:57 +01001652HRESULT resource_init(struct IWineD3DResourceClass *resource, WINED3DRESOURCETYPE resource_type,
Henri Verbeet2dc7fc22009-03-13 10:44:18 +01001653 IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct GlPixelFormatDesc *format_desc,
1654 WINED3DPOOL pool, IUnknown *parent);
Henri Verbeet2acf8d72008-12-02 18:41:33 +01001655WINED3DRESOURCETYPE resource_get_type(IWineD3DResource *iface);
1656DWORD resource_set_priority(IWineD3DResource *iface, DWORD new_priority);
1657HRESULT resource_set_private_data(IWineD3DResource *iface, REFGUID guid,
1658 const void *data, DWORD data_size, DWORD flags);
1659
Stefan Dösinger393ed4a2007-10-22 13:30:14 +02001660/* Tests show that the start address of resources is 32 byte aligned */
1661#define RESOURCE_ALIGNMENT 32
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001662
1663/*****************************************************************************
Oliver Stieberbb6f9b02005-08-03 11:00:28 +00001664 * IWineD3DBaseTexture D3D- > openGL state map lookups
1665 */
Oliver Stieberbb6f9b02005-08-03 11:00:28 +00001666
1667typedef enum winetexturestates {
1668 WINED3DTEXSTA_ADDRESSU = 0,
1669 WINED3DTEXSTA_ADDRESSV = 1,
1670 WINED3DTEXSTA_ADDRESSW = 2,
1671 WINED3DTEXSTA_BORDERCOLOR = 3,
1672 WINED3DTEXSTA_MAGFILTER = 4,
1673 WINED3DTEXSTA_MINFILTER = 5,
1674 WINED3DTEXSTA_MIPFILTER = 6,
1675 WINED3DTEXSTA_MAXMIPLEVEL = 7,
1676 WINED3DTEXSTA_MAXANISOTROPY = 8,
1677 WINED3DTEXSTA_SRGBTEXTURE = 9,
1678 WINED3DTEXSTA_ELEMENTINDEX = 10,
1679 WINED3DTEXSTA_DMAPOFFSET = 11,
1680 WINED3DTEXSTA_TSSADDRESSW = 12,
1681 MAX_WINETEXTURESTATES = 13,
1682} winetexturestates;
1683
Stefan Dösinger4386a822009-02-17 00:25:51 +01001684enum WINED3DSRGB
1685{
1686 SRGB_ANY = 0, /* Uses the cached value(e.g. external calls) */
1687 SRGB_RGB = 1, /* Loads the rgb texture */
1688 SRGB_SRGB = 2, /* Loads the srgb texture */
1689 SRGB_BOTH = 3, /* Loads both textures */
1690};
1691
Oliver Stieberbb6f9b02005-08-03 11:00:28 +00001692/*****************************************************************************
Jason Edmeades819b0e12004-12-07 14:29:12 +00001693 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
1694 */
1695typedef struct IWineD3DBaseTextureClass
1696{
Henri Verbeet89139b72008-12-03 14:53:43 +01001697 DWORD states[MAX_WINETEXTURESTATES];
Stefan Dösingerc585b4d2009-01-16 16:22:09 +01001698 DWORD srgbstates[MAX_WINETEXTURESTATES];
Jason Edmeades819b0e12004-12-07 14:29:12 +00001699 UINT levels;
Stefan Dösingerc585b4d2009-01-16 16:22:09 +01001700 BOOL dirty, srgbDirty;
1701 UINT textureName, srgbTextureName;
Henri Verbeet89139b72008-12-03 14:53:43 +01001702 float pow2Matrix[16];
Oliver Stieberba5eb142005-03-14 10:12:52 +00001703 UINT LOD;
Stefan Dösinger63fd9a72006-04-06 19:02:16 +02001704 WINED3DTEXTUREFILTERTYPE filterType;
Stefan Dösinger666b5072006-12-19 23:26:39 +01001705 LONG bindCount;
1706 DWORD sampler;
Phil Costin622f62d2007-06-06 23:13:16 +00001707 BOOL is_srgb;
Tobias Jakobi31f8cd92009-03-26 03:12:50 +01001708 BOOL pow2Matrix_identity;
Henri Verbeetc7880e82008-11-26 16:14:40 +01001709 const struct min_lookup *minMipLookup;
1710 const GLenum *magLookup;
Stefan Dösinger4386a822009-02-17 00:25:51 +01001711 void (*internal_preload)(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb);
Jason Edmeades819b0e12004-12-07 14:29:12 +00001712} IWineD3DBaseTextureClass;
1713
Stefan Dösinger4386a822009-02-17 00:25:51 +01001714void texture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb);
1715void cubetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb);
1716void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb);
1717void surface_internal_preload(IWineD3DSurface *iface, enum WINED3DSRGB srgb);
1718
Jason Edmeades819b0e12004-12-07 14:29:12 +00001719typedef struct IWineD3DBaseTextureImpl
1720{
1721 /* IUnknown & WineD3DResource Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001722 const IWineD3DBaseTextureVtbl *lpVtbl;
Jason Edmeades819b0e12004-12-07 14:29:12 +00001723 IWineD3DResourceClass resource;
1724 IWineD3DBaseTextureClass baseTexture;
1725
1726} IWineD3DBaseTextureImpl;
1727
Henri Verbeet4d60b662008-12-02 18:41:32 +01001728void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
1729 const DWORD texture_states[WINED3D_HIGHEST_TEXTURE_STATE + 1],
1730 const DWORD sampler_states[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
Stefan Dösingerc585b4d2009-01-16 16:22:09 +01001731HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surface_desc);
Henri Verbeet4d60b662008-12-02 18:41:32 +01001732void basetexture_cleanup(IWineD3DBaseTexture *iface);
1733void basetexture_generate_mipmaps(IWineD3DBaseTexture *iface);
1734WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture *iface);
1735BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface);
1736DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface);
1737DWORD basetexture_get_lod(IWineD3DBaseTexture *iface);
Henri Verbeet87627c82009-01-12 10:17:50 +01001738void basetexture_init(struct IWineD3DBaseTextureClass *texture, UINT levels, DWORD usage);
Henri Verbeet4d60b662008-12-02 18:41:32 +01001739HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE filter_type);
1740BOOL basetexture_set_dirty(IWineD3DBaseTexture *iface, BOOL dirty);
1741DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD new_lod);
1742void basetexture_unload(IWineD3DBaseTexture *iface);
Stefan Dösingerc585b4d2009-01-16 16:22:09 +01001743static inline void basetexture_setsrgbcache(IWineD3DBaseTexture *iface, BOOL srgb) {
1744 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
1745 This->baseTexture.is_srgb = srgb;
1746}
Henri Verbeet4d60b662008-12-02 18:41:32 +01001747
Jason Edmeades819b0e12004-12-07 14:29:12 +00001748/*****************************************************************************
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001749 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
1750 */
1751typedef struct IWineD3DTextureImpl
1752{
1753 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001754 const IWineD3DTextureVtbl *lpVtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001755 IWineD3DResourceClass resource;
1756 IWineD3DBaseTextureClass baseTexture;
1757
1758 /* IWineD3DTexture */
Henri Verbeet2dcfdd52009-04-24 09:17:58 +02001759 IWineD3DSurface *surfaces[MAX_MIP_LEVELS];
Stefan Dösingerd09cbce2007-11-28 20:35:04 +01001760 UINT target;
Stefan Dösingerc088ede2008-07-08 18:59:10 -05001761 BOOL cond_np2;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001762
1763} IWineD3DTextureImpl;
1764
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001765extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001766
1767/*****************************************************************************
1768 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
1769 */
1770typedef struct IWineD3DCubeTextureImpl
1771{
1772 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001773 const IWineD3DCubeTextureVtbl *lpVtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001774 IWineD3DResourceClass resource;
1775 IWineD3DBaseTextureClass baseTexture;
1776
1777 /* IWineD3DCubeTexture */
Henri Verbeet2dcfdd52009-04-24 09:17:58 +02001778 IWineD3DSurface *surfaces[6][MAX_MIP_LEVELS];
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001779} IWineD3DCubeTextureImpl;
1780
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001781extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001782
Ivan Gyurdiev257692e2006-05-10 13:55:02 -04001783typedef struct _WINED3DVOLUMET_DESC
1784{
1785 UINT Width;
1786 UINT Height;
1787 UINT Depth;
1788} WINED3DVOLUMET_DESC;
1789
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001790/*****************************************************************************
1791 * IWineD3DVolume implementation structure (extends IUnknown)
1792 */
1793typedef struct IWineD3DVolumeImpl
1794{
Oliver Stieber67f2ad42005-03-29 19:01:00 +00001795 /* IUnknown & WineD3DResource fields */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001796 const IWineD3DVolumeVtbl *lpVtbl;
Oliver Stieber67f2ad42005-03-29 19:01:00 +00001797 IWineD3DResourceClass resource;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001798
1799 /* WineD3DVolume Information */
Ivan Gyurdiev257692e2006-05-10 13:55:02 -04001800 WINED3DVOLUMET_DESC currentDesc;
H. Verbeete43cfb12006-02-06 11:30:48 +01001801 IWineD3DBase *container;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001802 BOOL lockable;
1803 BOOL locked;
Stefan Dösingercf4b91f2006-04-07 13:12:22 +02001804 WINED3DBOX lockedBox;
1805 WINED3DBOX dirtyBox;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001806 BOOL dirty;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001807} IWineD3DVolumeImpl;
1808
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001809extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001810
Henri Verbeetfd900212009-01-14 10:01:10 +01001811void volume_add_dirty_box(IWineD3DVolume *iface, const WINED3DBOX *dirty_box);
1812
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001813/*****************************************************************************
1814 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
1815 */
1816typedef struct IWineD3DVolumeTextureImpl
1817{
1818 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001819 const IWineD3DVolumeTextureVtbl *lpVtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001820 IWineD3DResourceClass resource;
1821 IWineD3DBaseTextureClass baseTexture;
1822
1823 /* IWineD3DVolumeTexture */
Henri Verbeet2dcfdd52009-04-24 09:17:58 +02001824 IWineD3DVolume *volumes[MAX_MIP_LEVELS];
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001825} IWineD3DVolumeTextureImpl;
1826
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001827extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001828
Oliver Stieber2121f782005-03-02 12:16:10 +00001829typedef struct _WINED3DSURFACET_DESC
1830{
Stefan Dösingerb4b295c2006-03-24 17:34:26 +01001831 WINED3DMULTISAMPLE_TYPE MultiSampleType;
1832 DWORD MultiSampleQuality;
1833 UINT Width;
1834 UINT Height;
Oliver Stieber2121f782005-03-02 12:16:10 +00001835} WINED3DSURFACET_DESC;
1836
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001837/*****************************************************************************
Stefan Dösingeraf462952006-05-06 18:08:33 +02001838 * Structure for DIB Surfaces (GetDC and GDI surfaces)
1839 */
1840typedef struct wineD3DSurface_DIB {
1841 HBITMAP DIBsection;
1842 void* bitmap_data;
Roderick Colenbranderad692f22007-09-11 10:31:54 +02001843 UINT bitmap_size;
Stefan Dösingeraf462952006-05-06 18:08:33 +02001844 HGDIOBJ holdbitmap;
1845 BOOL client_memory;
1846} wineD3DSurface_DIB;
1847
H. Verbeetc9b178b2007-04-09 01:53:32 +02001848typedef struct {
1849 struct list entry;
1850 GLuint id;
1851 UINT width;
1852 UINT height;
1853} renderbuffer_entry_t;
1854
Henri Verbeet45820042008-09-18 14:57:53 +02001855struct fbo_entry
1856{
1857 struct list entry;
1858 IWineD3DSurface **render_targets;
1859 IWineD3DSurface *depth_stencil;
1860 BOOL attached;
1861 GLuint id;
1862};
1863
Stefan Dösingeraf462952006-05-06 18:08:33 +02001864/*****************************************************************************
Stefan Dösingerd93e1612007-04-28 17:59:37 +02001865 * IWineD3DClipp implementation structure
1866 */
1867typedef struct IWineD3DClipperImpl
1868{
1869 const IWineD3DClipperVtbl *lpVtbl;
1870 LONG ref;
1871
1872 IUnknown *Parent;
1873 HWND hWnd;
1874} IWineD3DClipperImpl;
1875
1876
1877/*****************************************************************************
Jason Edmeades41427852005-01-09 17:37:02 +00001878 * IWineD3DSurface implementation structure
1879 */
1880struct IWineD3DSurfaceImpl
1881{
1882 /* IUnknown & IWineD3DResource Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001883 const IWineD3DSurfaceVtbl *lpVtbl;
Jason Edmeades41427852005-01-09 17:37:02 +00001884 IWineD3DResourceClass resource;
1885
1886 /* IWineD3DSurface fields */
H. Verbeete43cfb12006-02-06 11:30:48 +01001887 IWineD3DBase *container;
Oliver Stieber2121f782005-03-02 12:16:10 +00001888 WINED3DSURFACET_DESC currentDesc;
Stefan Dösinger76764622007-02-19 15:23:36 +01001889 IWineD3DPaletteImpl *palette; /* D3D7 style palette handling */
1890 PALETTEENTRY *palette9; /* D3D8/9 style palette handling */
Jason Edmeades41427852005-01-09 17:37:02 +00001891
Oliver Stieber520c2f02005-07-11 14:25:54 +00001892 /* TODO: move this off into a management class(maybe!) */
Stefan Dösingera98ccb52006-07-23 00:03:33 +02001893 DWORD Flags;
Oliver Stieber520c2f02005-07-11 14:25:54 +00001894
1895 UINT pow2Width;
1896 UINT pow2Height;
Oliver Stieber520c2f02005-07-11 14:25:54 +00001897
Stefan Dösinger9bc62002007-11-30 20:22:33 +01001898 /* A method to retrieve the drawable size. Not in the Vtable to make it changeable */
1899 void (*get_drawable_size)(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1900
Stefan Dösingercfcdb652006-05-19 00:13:29 +02001901 /* Oversized texture */
1902 RECT glRect;
1903
Roderick Colenbranderad692f22007-09-11 10:31:54 +02001904 /* PBO */
1905 GLuint pbo;
1906
Jason Edmeades41427852005-01-09 17:37:02 +00001907 RECT lockedRect;
1908 RECT dirtyRect;
Stefan Dösinger03389ac2007-01-12 18:57:26 +01001909 int lockCount;
1910#define MAXLOCKCOUNT 50 /* After this amount of locks do not free the sysmem copy */
Oliver Stieber13621052005-07-11 20:38:27 +00001911
1912 glDescriptor glDescription;
Stefan Dösingeraf462952006-05-06 18:08:33 +02001913
1914 /* For GetDC */
1915 wineD3DSurface_DIB dib;
1916 HDC hDC;
Stefan Dösinger9b29fb62006-05-09 19:37:38 +02001917
1918 /* Color keys for DDraw */
Stefan Dösinger725057d2007-04-14 22:44:55 +02001919 WINEDDCOLORKEY DestBltCKey;
1920 WINEDDCOLORKEY DestOverlayCKey;
1921 WINEDDCOLORKEY SrcOverlayCKey;
1922 WINEDDCOLORKEY SrcBltCKey;
Stefan Dösinger9b29fb62006-05-09 19:37:38 +02001923 DWORD CKeyFlags;
1924
Stefan Dösinger725057d2007-04-14 22:44:55 +02001925 WINEDDCOLORKEY glCKey;
H. Verbeetc9b178b2007-04-09 01:53:32 +02001926
1927 struct list renderbuffers;
1928 renderbuffer_entry_t *current_renderbuffer;
Stefan Dösingerd93e1612007-04-28 17:59:37 +02001929
1930 /* DirectDraw clippers */
1931 IWineD3DClipper *clipper;
Stefan Dösingere795d842008-08-05 12:19:43 +02001932
1933 /* DirectDraw Overlay handling */
1934 RECT overlay_srcrect;
1935 RECT overlay_destrect;
1936 IWineD3DSurfaceImpl *overlay_dest;
Stefan Dösingerdff3a422008-07-30 15:28:25 -05001937 struct list overlays;
1938 struct list overlay_entry;
Jason Edmeades41427852005-01-09 17:37:02 +00001939};
1940
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001941extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
Stefan Dösinger2f724832006-05-13 22:22:16 +02001942extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
1943
1944/* Predeclare the shared Surface functions */
Stefan Dösinger84340602007-09-16 13:29:44 +02001945HRESULT WINAPI IWineD3DBaseSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
Stefan Dösinger0c916102007-09-16 13:42:18 +02001946ULONG WINAPI IWineD3DBaseSurfaceImpl_AddRef(IWineD3DSurface *iface);
Stefan Dösinger0c916102007-09-16 13:42:18 +02001947HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
1948HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
1949HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
1950HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
1951HRESULT WINAPI IWineD3DBaseSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
1952DWORD WINAPI IWineD3DBaseSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
1953DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPriority(IWineD3DSurface *iface);
Stefan Dösinger0c916102007-09-16 13:42:18 +02001954WINED3DRESOURCETYPE WINAPI IWineD3DBaseSurfaceImpl_GetType(IWineD3DSurface *iface);
Stefan Dösingerd99143c2007-09-16 14:03:39 +02001955HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
1956HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
1957HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
1958HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
1959HRESULT WINAPI IWineD3DBaseSurfaceImpl_IsLost(IWineD3DSurface *iface);
1960HRESULT WINAPI IWineD3DBaseSurfaceImpl_Restore(IWineD3DSurface *iface);
Stefan Dösingere2944172007-09-16 16:27:58 +02001961HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
1962HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
Henri Verbeetb4f0b5b2008-11-25 11:57:39 +01001963HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, const WINEDDCOLORKEY *CKey);
Stefan Dösingere2944172007-09-16 16:27:58 +02001964HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
Stefan Dösingere2944172007-09-16 16:27:58 +02001965DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPitch(IWineD3DSurface *iface);
1966HRESULT WINAPI IWineD3DBaseSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
Stefan Dösingere2944172007-09-16 16:27:58 +02001967HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetOverlayPosition(IWineD3DSurface *iface, LONG X, LONG Y);
1968HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetOverlayPosition(IWineD3DSurface *iface, LONG *X, LONG *Y);
1969HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface *iface, DWORD Flags, IWineD3DSurface *Ref);
Henri Verbeetb4f0b5b2008-11-25 11:57:39 +01001970HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlay(IWineD3DSurface *iface, const RECT *SrcRect,
1971 IWineD3DSurface *DstSurface, const RECT *DstRect, DWORD Flags, const WINEDDOVERLAYFX *FX);
Stefan Dösingere2944172007-09-16 16:27:58 +02001972HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetClipper(IWineD3DSurface *iface, IWineD3DClipper *clipper);
1973HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetClipper(IWineD3DSurface *iface, IWineD3DClipper **clipper);
Stefan Dösingere56c6612007-09-16 16:49:02 +02001974HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
Stefan Dösinger5a775642007-09-17 13:48:11 +02001975HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface);
Henri Verbeetb4f0b5b2008-11-25 11:57:39 +01001976HRESULT WINAPI IWineD3DBaseSurfaceImpl_Blt(IWineD3DSurface *iface, const RECT *DestRect, IWineD3DSurface *SrcSurface,
1977 const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter);
1978HRESULT WINAPI IWineD3DBaseSurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty,
1979 IWineD3DSurface *Source, const RECT *rsrc, DWORD trans);
Stefan Dösingera175e7b2007-10-09 22:19:39 +02001980HRESULT WINAPI IWineD3DBaseSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags);
Stefan Dösingerc585b4d2009-01-16 16:22:09 +01001981void WINAPI IWineD3DBaseSurfaceImpl_BindTexture(IWineD3DSurface *iface, BOOL srgb);
Henri Verbeet49b55f62008-11-25 11:57:39 +01001982const void *WINAPI IWineD3DBaseSurfaceImpl_GetData(IWineD3DSurface *iface);
Stefan Dösinger9aa56622007-09-16 16:33:23 +02001983
Stefan Dösinger9bc62002007-11-30 20:22:33 +01001984void get_drawable_size_swapchain(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1985void get_drawable_size_backbuffer(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1986void get_drawable_size_pbuffer(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1987void get_drawable_size_fbo(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1988
Stefan Dösinger851dd732008-07-24 11:38:51 -05001989void flip_surface(IWineD3DSurfaceImpl *front, IWineD3DSurfaceImpl *back);
1990
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02001991/* Surface flags: */
H. Verbeet4f77c292008-07-02 23:00:41 +02001992#define SFLAG_OVERSIZE 0x00000001 /* Surface is bigger than gl size, blts only */
1993#define SFLAG_CONVERTED 0x00000002 /* Converted for color keying or Palettized */
1994#define SFLAG_DIBSECTION 0x00000004 /* Has a DIB section attached for GetDC */
1995#define SFLAG_LOCKABLE 0x00000008 /* Surface can be locked */
1996#define SFLAG_DISCARD 0x00000010 /* ??? */
1997#define SFLAG_LOCKED 0x00000020 /* Surface is locked atm */
1998#define SFLAG_INTEXTURE 0x00000040 /* The GL texture contains the newest surface content */
Stefan Dösingerc585b4d2009-01-16 16:22:09 +01001999#define SFLAG_INSRGBTEX 0x00000080 /* The GL srgb texture contains the newest surface content */
2000#define SFLAG_INDRAWABLE 0x00000100 /* The gl drawable contains the most up to date data */
2001#define SFLAG_INSYSMEM 0x00000200 /* The system memory copy is most up to date */
2002#define SFLAG_NONPOW2 0x00000400 /* Surface sizes are not a power of 2 */
2003#define SFLAG_DYNLOCK 0x00000800 /* Surface is often locked by the app */
H. Verbeet4f77c292008-07-02 23:00:41 +02002004#define SFLAG_DCINUSE 0x00001000 /* Set between GetDC and ReleaseDC calls */
2005#define SFLAG_LOST 0x00002000 /* Surface lost flag for DDraw */
2006#define SFLAG_USERPTR 0x00004000 /* The application allocated the memory for this surface */
2007#define SFLAG_GLCKEY 0x00008000 /* The gl texture was created with a color key */
2008#define SFLAG_CLIENT 0x00010000 /* GL_APPLE_client_storage is used on that texture */
2009#define SFLAG_ALLOCATED 0x00020000 /* A gl texture is allocated for this surface */
Stefan Dösingerc585b4d2009-01-16 16:22:09 +01002010#define SFLAG_SRGBALLOCATED 0x00040000 /* A srgb gl texture is allocated for this surface */
2011#define SFLAG_PBO 0x00080000 /* Has a PBO attached for speeding up data transfers for dynamically locked surfaces */
2012#define SFLAG_NORMCOORD 0x00100000 /* Set if the GL texture coords are normalized(non-texture rectangle) */
2013#define SFLAG_DS_ONSCREEN 0x00200000 /* Is a depth stencil, last modified onscreen */
2014#define SFLAG_DS_OFFSCREEN 0x00400000 /* Is a depth stencil, last modified offscreen */
2015#define SFLAG_INOVERLAYDRAW 0x00800000 /* Overlay drawing is in progress. Recursion prevention */
Henri Verbeet899df562009-03-25 10:12:27 +01002016#define SFLAG_SWAPCHAIN 0x01000000 /* The surface is part of a swapchain */
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02002017
2018/* In some conditions the surface memory must not be freed:
2019 * SFLAG_OVERSIZE: Not all data can be kept in GL
2020 * SFLAG_CONVERTED: Converting the data back would take too long
2021 * SFLAG_DIBSECTION: The dib code manages the memory
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02002022 * SFLAG_LOCKED: The app requires access to the surface data
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02002023 * SFLAG_DYNLOCK: Avoid freeing the data for performance
Roderick Colenbranderad692f22007-09-11 10:31:54 +02002024 * SFLAG_PBO: PBOs don't use 'normal' memory. It is either allocated by the driver or must be NULL.
Stefan Dösinger4f5d3332007-03-31 23:02:37 +02002025 * SFLAG_CLIENT: OpenGL uses our memory as backup
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02002026 */
H. Verbeet4f77c292008-07-02 23:00:41 +02002027#define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
2028 SFLAG_CONVERTED | \
2029 SFLAG_DIBSECTION | \
2030 SFLAG_LOCKED | \
2031 SFLAG_DYNLOCK | \
H. Verbeet4f77c292008-07-02 23:00:41 +02002032 SFLAG_USERPTR | \
2033 SFLAG_PBO | \
2034 SFLAG_CLIENT)
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02002035
H. Verbeet4f77c292008-07-02 23:00:41 +02002036#define SFLAG_LOCATIONS (SFLAG_INSYSMEM | \
2037 SFLAG_INTEXTURE | \
Stefan Dösingerc585b4d2009-01-16 16:22:09 +01002038 SFLAG_INDRAWABLE | \
2039 SFLAG_INSRGBTEX)
H. Verbeet4f77c292008-07-02 23:00:41 +02002040
2041#define SFLAG_DS_LOCATIONS (SFLAG_DS_ONSCREEN | \
2042 SFLAG_DS_OFFSCREEN)
Henri Verbeet9d192c62008-09-22 14:52:52 +02002043#define SFLAG_DS_DISCARDED SFLAG_DS_LOCATIONS
H. Verbeet4f77c292008-07-02 23:00:41 +02002044
Stefan Dösinger158691e2006-05-23 00:48:54 +02002045BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
2046
Stefan Dösinger028729d2007-08-11 20:02:01 +02002047typedef enum {
2048 NO_CONVERSION,
2049 CONVERT_PALETTED,
2050 CONVERT_PALETTED_CK,
2051 CONVERT_CK_565,
2052 CONVERT_CK_5551,
2053 CONVERT_CK_4444,
2054 CONVERT_CK_4444_ARGB,
2055 CONVERT_CK_1555,
2056 CONVERT_555,
2057 CONVERT_CK_RGB24,
2058 CONVERT_CK_8888,
2059 CONVERT_CK_8888_ARGB,
2060 CONVERT_RGB32_888,
2061 CONVERT_V8U8,
Stefan Dösinger0ed81b22007-08-31 20:41:03 +02002062 CONVERT_L6V5U5,
Stefan Dösinger028729d2007-08-11 20:02:01 +02002063 CONVERT_X8L8V8U8,
2064 CONVERT_Q8W8V8U8,
2065 CONVERT_V16U16,
Stefan Dösinger86b991c2007-08-12 16:24:29 +02002066 CONVERT_A4L4,
Stefan Dösinger0dc04442008-12-15 19:14:15 +01002067 CONVERT_G16R16,
Stefan Dösinger8513f642009-04-06 15:05:27 +02002068 CONVERT_R16G16F,
2069 CONVERT_R32G32F,
Stefan Dösinger028729d2007-08-11 20:02:01 +02002070} CONVERT_TYPES;
2071
2072HRESULT 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);
2073
Alexander Dorofeyevd6ba0692008-04-03 00:12:16 +03002074BOOL palette9_changed(IWineD3DSurfaceImpl *This);
2075
Jason Edmeades41427852005-01-09 17:37:02 +00002076/*****************************************************************************
Raphael Junqueira4f02b522005-01-19 19:34:49 +00002077 * IWineD3DVertexDeclaration implementation structure
2078 */
Stefan Dösinger95921232007-11-20 21:14:10 +01002079#define MAX_ATTRIBS 16
2080
Henri Verbeet9f26fed2009-03-27 10:25:56 +01002081struct wined3d_vertex_declaration_element
2082{
Henri Verbeet4434d002009-03-27 10:25:56 +01002083 const struct GlPixelFormatDesc *format_desc;
Henri Verbeet9f26fed2009-03-27 10:25:56 +01002084 BOOL ffp_valid;
2085 WORD input_slot;
2086 WORD offset;
2087 UINT output_slot;
2088 BYTE method;
2089 BYTE usage;
2090 BYTE usage_idx;
2091};
2092
Raphael Junqueira4f02b522005-01-19 19:34:49 +00002093typedef struct IWineD3DVertexDeclarationImpl {
H. Verbeetee09e8b2007-03-12 23:21:54 +01002094 /* IUnknown Information */
2095 const IWineD3DVertexDeclarationVtbl *lpVtbl;
2096 LONG ref;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00002097
H. Verbeetee09e8b2007-03-12 23:21:54 +01002098 IUnknown *parent;
2099 IWineD3DDeviceImpl *wineD3DDevice;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00002100
Henri Verbeet9f26fed2009-03-27 10:25:56 +01002101 struct wined3d_vertex_declaration_element *elements;
2102 UINT element_count;
Stefan Dösinger06e51c22007-08-03 19:53:25 +02002103
2104 DWORD streams[MAX_STREAMS];
2105 UINT num_streams;
Stefan Dösingerb8dd5832007-07-30 12:35:33 +02002106 BOOL position_transformed;
Stefan Dösingera3c2fb92007-12-20 01:34:22 +01002107 BOOL half_float_conv_needed;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00002108} IWineD3DVertexDeclarationImpl;
2109
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002110extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00002111
Henri Verbeet4330d202009-03-27 10:25:55 +01002112HRESULT vertexdeclaration_init(IWineD3DVertexDeclarationImpl *This,
2113 const WINED3DVERTEXELEMENT *elements, UINT element_count);
2114
Raphael Junqueira4f02b522005-01-19 19:34:49 +00002115/*****************************************************************************
Jason Edmeades447d5ed2004-10-21 20:59:12 +00002116 * IWineD3DStateBlock implementation structure
2117 */
2118
2119/* Internal state Block for Begin/End/Capture/Create/Apply info */
2120/* Note: Very long winded but gl Lists are not flexible enough */
2121/* to resolve everything we need, so doing it manually for now */
2122typedef struct SAVEDSTATES {
Henri Verbeetfc398312009-01-05 10:10:16 +01002123 DWORD transform[(HIGHEST_TRANSFORMSTATE >> 5) + 1];
Henri Verbeetfd33f0f2009-01-05 10:10:16 +01002124 WORD streamSource; /* MAX_STREAMS, 16 */
2125 WORD streamFreq; /* MAX_STREAMS, 16 */
Henri Verbeetc33b3812009-01-05 10:10:16 +01002126 DWORD renderState[(WINEHIGHEST_RENDER_STATE >> 5) + 1];
Henri Verbeetbddf5e72009-01-06 11:43:45 +01002127 DWORD textureState[MAX_TEXTURES]; /* WINED3D_HIGHEST_TEXTURE_STATE + 1, 18 */
2128 WORD samplerState[MAX_COMBINED_SAMPLERS]; /* WINED3D_HIGHEST_SAMPLER_STATE + 1, 14 */
2129 DWORD textures; /* MAX_COMBINED_SAMPLERS, 20 */
Henri Verbeetfd33f0f2009-01-05 10:10:16 +01002130 DWORD clipplane; /* WINED3DMAXUSERCLIPPLANES, 32 */
2131 WORD pixelShaderConstantsB; /* MAX_CONST_B, 16 */
2132 WORD pixelShaderConstantsI; /* MAX_CONST_I, 16 */
Henri Verbeet3920d422008-12-30 14:56:49 +01002133 BOOL *pixelShaderConstantsF;
Henri Verbeetfd33f0f2009-01-05 10:10:16 +01002134 WORD vertexShaderConstantsB; /* MAX_CONST_B, 16 */
2135 WORD vertexShaderConstantsI; /* MAX_CONST_I, 16 */
Henri Verbeet3920d422008-12-30 14:56:49 +01002136 BOOL *vertexShaderConstantsF;
Henri Verbeet702eeb62009-03-05 12:30:43 +01002137 WORD primitive_type : 1;
2138 WORD indices : 1;
2139 WORD material : 1;
2140 WORD viewport : 1;
2141 WORD vertexDecl : 1;
2142 WORD pixelShader : 1;
2143 WORD vertexShader : 1;
2144 WORD scissorRect : 1;
2145 WORD padding : 1;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00002146} SAVEDSTATES;
2147
Stefan Dösinger03ffb732007-08-09 17:45:29 +02002148struct StageState {
2149 DWORD stage;
2150 DWORD state;
2151};
2152
Jason Edmeades447d5ed2004-10-21 20:59:12 +00002153struct IWineD3DStateBlockImpl
2154{
2155 /* IUnknown fields */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002156 const IWineD3DStateBlockVtbl *lpVtbl;
Mike McCormack8955ac42005-07-28 10:16:21 +00002157 LONG ref; /* Note: Ref counting not required */
Oliver Stieberabb11f32005-07-05 14:05:18 +00002158
Jason Edmeades447d5ed2004-10-21 20:59:12 +00002159 /* IWineD3DStateBlock information */
Jason Edmeades289562e2004-11-23 13:52:46 +00002160 IUnknown *parent;
Jason Edmeades41427852005-01-09 17:37:02 +00002161 IWineD3DDeviceImpl *wineD3DDevice;
Oliver Stieber7cb748f2005-07-26 18:49:30 +00002162 WINED3DSTATEBLOCKTYPE blockType;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00002163
2164 /* Array indicating whether things have been set or changed */
2165 SAVEDSTATES changed;
Oliver Stieberabb11f32005-07-05 14:05:18 +00002166
Raphael Junqueira4f02b522005-01-19 19:34:49 +00002167 /* Vertex Shader Declaration */
Oliver Stieber2c0e97e2005-08-17 11:34:03 +00002168 IWineD3DVertexDeclaration *vertexDecl;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00002169
Oliver Stieberb3563da2005-09-28 10:13:00 +00002170 IWineD3DVertexShader *vertexShader;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00002171
Oliver Stieber9b0b8032005-08-17 10:27:01 +00002172 /* Vertex Shader Constants */
Jason Green718716b2006-07-19 00:06:07 -04002173 BOOL vertexShaderConstantB[MAX_CONST_B];
2174 INT vertexShaderConstantI[MAX_CONST_I * 4];
2175 float *vertexShaderConstantF;
Oliver Stieber9b0b8032005-08-17 10:27:01 +00002176
Henri Verbeet702eeb62009-03-05 12:30:43 +01002177 /* primitive type */
2178 GLenum gl_primitive_type;
2179
Jason Edmeades289562e2004-11-23 13:52:46 +00002180 /* Stream Source */
Raphael Junqueira4f02b522005-01-19 19:34:49 +00002181 BOOL streamIsUP;
Oliver Stieberabb11f32005-07-05 14:05:18 +00002182 UINT streamStride[MAX_STREAMS];
Stefan Dösinger26ebe392007-07-04 17:57:45 +02002183 UINT streamOffset[MAX_STREAMS + 1 /* tesselated pseudo-stream */ ];
Henri Verbeetaa3027a2009-03-06 14:56:23 +01002184 IWineD3DBuffer *streamSource[MAX_STREAMS];
Stefan Dösinger26ebe392007-07-04 17:57:45 +02002185 UINT streamFreq[MAX_STREAMS + 1];
2186 UINT streamFlags[MAX_STREAMS + 1]; /*0 | WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA */
Jason Edmeadeseba27af2004-11-28 15:04:41 +00002187
Jason Edmeadesf738c142004-12-09 11:42:34 +00002188 /* Indices */
Stefan Dösinger513a4932009-04-06 16:46:12 +02002189 IWineD3DBuffer* pIndexData;
Stefan Dösingercb1c9dc2009-04-09 10:50:31 +02002190 WINED3DFORMAT IndexFmt;
Stefan Dösinger6ec6c942007-08-25 00:09:33 +02002191 INT baseVertexIndex;
2192 INT loadBaseVertexIndex; /* non-indexed drawing needs 0 here, indexed baseVertexIndex */
Jason Edmeadesf738c142004-12-09 11:42:34 +00002193
Jason Edmeadeseba27af2004-11-28 15:04:41 +00002194 /* Transform */
Ivan Gyurdievac371632006-10-12 02:21:39 -04002195 WINED3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
Jason Edmeadeseba27af2004-11-28 15:04:41 +00002196
Stefan Dösingeracadf3f2007-02-14 17:46:54 +01002197 /* Light hashmap . Collisions are handled using standard wine double linked lists */
2198#define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
2199#define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
2200 struct list lightMap[LIGHTMAP_SIZE]; /* Mashmap containing the lights */
2201 PLIGHTINFOEL *activeLights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
Oliver Stieberabb11f32005-07-05 14:05:18 +00002202
Jason Edmeades0a944ae2004-11-29 17:53:42 +00002203 /* Clipping */
2204 double clipplane[MAX_CLIPPLANES][4];
2205 WINED3DCLIPSTATUS clip_status;
2206
Jason Edmeadesf738c142004-12-09 11:42:34 +00002207 /* ViewPort */
2208 WINED3DVIEWPORT viewport;
2209
Jason Edmeades0a944ae2004-11-29 17:53:42 +00002210 /* Material */
2211 WINED3DMATERIAL material;
2212
Oliver Stieberabb11f32005-07-05 14:05:18 +00002213 /* Pixel Shader */
Oliver Stieberb3563da2005-09-28 10:13:00 +00002214 IWineD3DPixelShader *pixelShader;
Oliver Stieber2af36c62005-08-25 19:24:21 +00002215
2216 /* Pixel Shader Constants */
Jason Green718716b2006-07-19 00:06:07 -04002217 BOOL pixelShaderConstantB[MAX_CONST_B];
2218 INT pixelShaderConstantI[MAX_CONST_I * 4];
2219 float *pixelShaderConstantF;
Oliver Stieberabb11f32005-07-05 14:05:18 +00002220
Jason Edmeades2003c7a2004-12-13 13:35:38 +00002221 /* RenderState */
Oliver Stieberabb11f32005-07-05 14:05:18 +00002222 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
Jason Edmeades2003c7a2004-12-13 13:35:38 +00002223
Jason Edmeadesf738c142004-12-09 11:42:34 +00002224 /* Texture */
H. Verbeet5b7758f2007-06-25 22:45:40 +02002225 IWineD3DBaseTexture *textures[MAX_COMBINED_SAMPLERS];
Jason Edmeades2003c7a2004-12-13 13:35:38 +00002226
2227 /* Texture State Stage */
Oliver Stieber7cb748f2005-07-26 18:49:30 +00002228 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
Stefan Dösinger762af472006-12-19 23:00:58 +01002229 DWORD lowest_disabled_stage;
Oliver Stieber18857f12005-06-24 11:53:07 +00002230 /* Sampler States */
H. Verbeet5b7758f2007-06-25 22:45:40 +02002231 DWORD samplerState[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
Oliver Stieber18857f12005-06-24 11:53:07 +00002232
Stefan Dösingerd4b63bb2007-01-10 11:28:42 +01002233 /* Scissor test rectangle */
2234 RECT scissorRect;
Stefan Dösinger93155ea2007-07-31 15:04:56 +02002235
2236 /* Contained state management */
2237 DWORD contained_render_states[WINEHIGHEST_RENDER_STATE + 1];
2238 unsigned int num_contained_render_states;
Stefan Dösinger6e7a10f2007-08-14 23:44:25 +02002239 DWORD contained_transform_states[HIGHEST_TRANSFORMSTATE + 1];
Stefan Dösinger92ce0282007-07-31 15:44:13 +02002240 unsigned int num_contained_transform_states;
Stefan Dösinger4673b1c2007-08-03 20:07:30 +02002241 DWORD contained_vs_consts_i[MAX_CONST_I];
2242 unsigned int num_contained_vs_consts_i;
2243 DWORD contained_vs_consts_b[MAX_CONST_B];
2244 unsigned int num_contained_vs_consts_b;
Stefan Dösingerb21c7852007-08-03 20:26:29 +02002245 DWORD *contained_vs_consts_f;
2246 unsigned int num_contained_vs_consts_f;
Stefan Dösinger865b82a2007-08-03 20:12:54 +02002247 DWORD contained_ps_consts_i[MAX_CONST_I];
2248 unsigned int num_contained_ps_consts_i;
2249 DWORD contained_ps_consts_b[MAX_CONST_B];
2250 unsigned int num_contained_ps_consts_b;
Stefan Dösingerb21c7852007-08-03 20:26:29 +02002251 DWORD *contained_ps_consts_f;
2252 unsigned int num_contained_ps_consts_f;
Henri Verbeeta8697d92009-01-06 11:43:45 +01002253 struct StageState contained_tss_states[MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)];
Stefan Dösinger03ffb732007-08-09 17:45:29 +02002254 unsigned int num_contained_tss_states;
Stefan Dösinger59fb2922007-08-03 20:23:52 +02002255 struct StageState contained_sampler_states[MAX_COMBINED_SAMPLERS * WINED3D_HIGHEST_SAMPLER_STATE];
2256 unsigned int num_contained_sampler_states;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00002257};
2258
Jason Green75950b52006-07-23 15:08:27 -04002259extern void stateblock_savedstates_set(
2260 IWineD3DStateBlock* iface,
2261 SAVEDSTATES* states,
2262 BOOL value);
2263
Jason Green75950b52006-07-23 15:08:27 -04002264extern void stateblock_copy(
2265 IWineD3DStateBlock* destination,
2266 IWineD3DStateBlock* source);
2267
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002268extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00002269
Stefan Dösinger0e8c13e2007-12-04 01:43:24 +01002270/* Direct3D terminology with little modifications. We do not have an issued state
2271 * because only the driver knows about it, but we have a created state because d3d
2272 * allows GetData on a created issue, but opengl doesn't
2273 */
2274enum query_state {
2275 QUERY_CREATED,
2276 QUERY_SIGNALLED,
2277 QUERY_BUILDING
2278};
Jason Edmeades447d5ed2004-10-21 20:59:12 +00002279/*****************************************************************************
Oliver Stieber7b261652005-03-03 13:57:15 +00002280 * IWineD3DQueryImpl implementation structure (extends IUnknown)
2281 */
2282typedef struct IWineD3DQueryImpl
2283{
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002284 const IWineD3DQueryVtbl *lpVtbl;
Mike McCormack8955ac42005-07-28 10:16:21 +00002285 LONG ref; /* Note: Ref counting not required */
Oliver Stieber7b261652005-03-03 13:57:15 +00002286
2287 IUnknown *parent;
2288 /*TODO: replace with iface usage */
2289#if 0
2290 IWineD3DDevice *wineD3DDevice;
2291#else
2292 IWineD3DDeviceImpl *wineD3DDevice;
2293#endif
Oliver Stieber7b261652005-03-03 13:57:15 +00002294
Ivan Gyurdievf0d5b352006-10-10 21:53:30 -04002295 /* IWineD3DQuery fields */
Stefan Dösinger0e8c13e2007-12-04 01:43:24 +01002296 enum query_state state;
Ivan Gyurdievf0d5b352006-10-10 21:53:30 -04002297 WINED3DQUERYTYPE type;
Oliver Stieber5ea96a82005-09-21 09:43:13 +00002298 /* TODO: Think about using a IUnknown instead of a void* */
Oliver Stieber7b261652005-03-03 13:57:15 +00002299 void *extendedData;
2300
2301
2302} IWineD3DQueryImpl;
2303
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002304extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
Stefan Dösinger071d4af2008-02-28 21:02:58 +01002305extern const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl;
Stefan Dösinger32be5032008-02-28 21:03:41 +01002306extern const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl;
Oliver Stieber7b261652005-03-03 13:57:15 +00002307
Oliver Stieber5ea96a82005-09-21 09:43:13 +00002308/* Datastructures for IWineD3DQueryImpl.extendedData */
2309typedef struct WineQueryOcclusionData {
H. Verbeet53663892006-07-25 00:51:33 +02002310 GLuint queryId;
Stefan Dösingere184b092007-08-14 15:42:34 +02002311 WineD3DContext *ctx;
Oliver Stieber5ea96a82005-09-21 09:43:13 +00002312} WineQueryOcclusionData;
2313
Stefan Dösinger76b60b02007-03-01 00:34:33 +01002314typedef struct WineQueryEventData {
2315 GLuint fenceId;
Stefan Dösingera99907d2007-08-14 15:26:02 +02002316 WineD3DContext *ctx;
Stefan Dösinger76b60b02007-03-01 00:34:33 +01002317} WineQueryEventData;
Oliver Stieber5ea96a82005-09-21 09:43:13 +00002318
Henri Verbeet399d9922009-02-23 09:16:02 +01002319/* IWineD3DBuffer */
Henri Verbeetaa3027a2009-03-06 14:56:23 +01002320
2321/* TODO: Add tests and support for FLOAT16_4 POSITIONT, D3DCOLOR position, other
2322 * fixed function semantics as D3DCOLOR or FLOAT16 */
2323enum wined3d_buffer_conversion_type
2324{
2325 CONV_NONE,
2326 CONV_D3DCOLOR,
2327 CONV_POSITIONT,
2328 CONV_FLOAT16_2, /* Also handles FLOAT16_4 */
2329};
2330
2331#define WINED3D_BUFFER_OPTIMIZED 0x01 /* Optimize has been called for the buffer */
2332#define WINED3D_BUFFER_DIRTY 0x02 /* Buffer data has been modified */
2333#define WINED3D_BUFFER_HASDESC 0x04 /* A vertex description has been found */
2334#define WINED3D_BUFFER_CREATEBO 0x08 /* Attempt to create a buffer object next PreLoad */
Stefan Dösinger014c4bf2009-04-09 18:40:57 +02002335#define WINED3D_BUFFER_DOUBLEBUFFER 0x10 /* Use a vbo and local allocated memory */
Henri Verbeetaa3027a2009-03-06 14:56:23 +01002336
Henri Verbeet399d9922009-02-23 09:16:02 +01002337struct wined3d_buffer
2338{
2339 const struct IWineD3DBufferVtbl *vtbl;
2340 IWineD3DResourceClass resource;
2341
2342 struct wined3d_buffer_desc desc;
Henri Verbeetaa3027a2009-03-06 14:56:23 +01002343
2344 GLuint buffer_object;
2345 GLenum buffer_object_usage;
Stefan Dösinger2a7a2372009-04-06 13:38:56 +02002346 GLenum buffer_type_hint;
Henri Verbeetaa3027a2009-03-06 14:56:23 +01002347 UINT buffer_object_size;
2348 LONG bind_count;
2349 DWORD flags;
2350
2351 UINT dirty_start;
2352 UINT dirty_end;
2353 LONG lock_count;
2354
Henri Verbeetaa3027a2009-03-06 14:56:23 +01002355 /* conversion stuff */
2356 UINT conversion_count;
2357 UINT draw_count;
2358 UINT stride; /* 0 if no conversion */
2359 UINT conversion_stride; /* 0 if no shifted conversion */
2360 enum wined3d_buffer_conversion_type *conversion_map; /* NULL if no conversion */
2361 /* Extra load offsets, for FLOAT16 conversion */
2362 UINT *conversion_shift; /* NULL if no shifted conversion */
Henri Verbeet399d9922009-02-23 09:16:02 +01002363};
2364
2365extern const IWineD3DBufferVtbl wined3d_buffer_vtbl;
Henri Verbeetaa3027a2009-03-06 14:56:23 +01002366const BYTE *buffer_get_memory(IWineD3DBuffer *iface, UINT offset, GLuint *buffer_object);
Stefan Dösinger014c4bf2009-04-09 18:40:57 +02002367const BYTE *buffer_get_sysmem(struct wined3d_buffer *This);
Henri Verbeet399d9922009-02-23 09:16:02 +01002368
Henri Verbeetc796f762009-02-24 07:43:02 +01002369/* IWineD3DRendertargetView */
2370struct wined3d_rendertarget_view
2371{
2372 const struct IWineD3DRendertargetViewVtbl *vtbl;
2373 LONG refcount;
2374
2375 IWineD3DResource *resource;
2376 IUnknown *parent;
2377};
2378
2379extern const IWineD3DRendertargetViewVtbl wined3d_rendertarget_view_vtbl;
2380
Oliver Stieber7b261652005-03-03 13:57:15 +00002381/*****************************************************************************
Oliver Stieber46e7c302005-06-23 11:05:24 +00002382 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
2383 */
2384
2385typedef struct IWineD3DSwapChainImpl
2386{
2387 /*IUnknown part*/
Dmitry Timoshkov47ffd7a2006-12-14 22:47:59 +08002388 const IWineD3DSwapChainVtbl *lpVtbl;
Mike McCormack8955ac42005-07-28 10:16:21 +00002389 LONG ref; /* Note: Ref counting not required */
Oliver Stieber46e7c302005-06-23 11:05:24 +00002390
2391 IUnknown *parent;
2392 IWineD3DDeviceImpl *wineD3DDevice;
2393
2394 /* IWineD3DSwapChain fields */
Stefan Dösinger3862f8e2006-06-15 12:54:19 +02002395 IWineD3DSurface **backBuffer;
Oliver Stieber46e7c302005-06-23 11:05:24 +00002396 IWineD3DSurface *frontBuffer;
H. Verbeeta4bc52a2007-02-15 22:36:50 +01002397 WINED3DPRESENT_PARAMETERS presentParms;
Stefan Dösingerd30f1522006-12-08 16:13:15 +01002398 DWORD orig_width, orig_height;
Stefan Dösinger8e841272007-02-15 13:53:33 +01002399 WINED3DFORMAT orig_fmt;
Stefan Dösinger8d930f62008-07-01 11:17:38 -05002400 WINED3DGAMMARAMP orig_gamma;
Oliver Stieber46e7c302005-06-23 11:05:24 +00002401
Stefan Dösinger222c5312007-01-10 11:27:26 +01002402 long prev_time, frames; /* Performance tracking */
Stefan Dösingerc9b8a792007-06-03 13:20:27 +02002403 unsigned int vSyncCounter;
Stefan Dösinger222c5312007-01-10 11:27:26 +01002404
Stefan Dösinger90fe64c2007-03-04 17:31:06 +01002405 WineD3DContext **context; /* Later a array for multithreading */
2406 unsigned int num_contexts;
Oliver Stieber46e7c302005-06-23 11:05:24 +00002407
2408 HWND win_handle;
Oliver Stieber46e7c302005-06-23 11:05:24 +00002409} IWineD3DSwapChainImpl;
2410
Dmitry Timoshkov47ffd7a2006-12-14 22:47:59 +08002411extern const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
Stefan Dösingere178ddd2008-08-05 14:23:00 -05002412const IWineD3DSwapChainVtbl IWineGDISwapChain_Vtbl;
Henri Verbeet5532c992008-12-01 15:32:15 +01002413void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc);
Oliver Stieber46e7c302005-06-23 11:05:24 +00002414
Stefan Dösingere5de2fc2008-07-27 18:04:16 -05002415HRESULT WINAPI IWineD3DBaseSwapChainImpl_QueryInterface(IWineD3DSwapChain *iface, REFIID riid, LPVOID *ppobj);
2416ULONG WINAPI IWineD3DBaseSwapChainImpl_AddRef(IWineD3DSwapChain *iface);
2417ULONG WINAPI IWineD3DBaseSwapChainImpl_Release(IWineD3DSwapChain *iface);
2418HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetParent(IWineD3DSwapChain *iface, IUnknown ** ppParent);
2419HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetFrontBufferData(IWineD3DSwapChain *iface, IWineD3DSurface *pDestSurface);
2420HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetBackBuffer(IWineD3DSwapChain *iface, UINT iBackBuffer, WINED3DBACKBUFFER_TYPE Type, IWineD3DSurface **ppBackBuffer);
2421HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetRasterStatus(IWineD3DSwapChain *iface, WINED3DRASTER_STATUS *pRasterStatus);
2422HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDisplayMode(IWineD3DSwapChain *iface, WINED3DDISPLAYMODE*pMode);
2423HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDevice(IWineD3DSwapChain *iface, IWineD3DDevice**ppDevice);
2424HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetPresentParameters(IWineD3DSwapChain *iface, WINED3DPRESENT_PARAMETERS *pPresentationParameters);
2425HRESULT WINAPI IWineD3DBaseSwapChainImpl_SetGammaRamp(IWineD3DSwapChain *iface, DWORD Flags, CONST WINED3DGAMMARAMP *pRamp);
2426HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetGammaRamp(IWineD3DSwapChain *iface, WINED3DGAMMARAMP *pRamp);
2427
Stefan Dösingerb462ff02007-06-02 20:21:57 +00002428WineD3DContext *IWineD3DSwapChainImpl_CreateContextForThread(IWineD3DSwapChain *iface);
2429
Oliver Stieber46e7c302005-06-23 11:05:24 +00002430/*****************************************************************************
Jason Edmeades447d5ed2004-10-21 20:59:12 +00002431 * Utility function prototypes
2432 */
Jason Edmeades2003c7a2004-12-13 13:35:38 +00002433
2434/* Trace routines */
Oliver Stieberb220ce12005-07-13 19:38:39 +00002435const char* debug_d3dformat(WINED3DFORMAT fmt);
Ivan Gyurdiev19c55342006-10-10 21:52:00 -04002436const char* debug_d3ddevicetype(WINED3DDEVTYPE devtype);
Stefan Dösinger913df5b2006-03-09 23:21:16 +01002437const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
Jason Edmeadesc579fa62004-10-05 02:14:06 +00002438const char* debug_d3dusage(DWORD usage);
Jason Greend353ab72006-07-28 15:33:20 -04002439const char* debug_d3dusagequery(DWORD usagequery);
H. Verbeet02a8f742006-08-07 19:21:54 +02002440const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method);
Ivan Gyurdiev7e9fd0b2006-07-03 00:11:15 -06002441const char* debug_d3ddeclusage(BYTE usage);
Ivan Gyurdiev2bac4a02006-10-12 02:23:55 -04002442const char* debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType);
Jason Edmeades2003c7a2004-12-13 13:35:38 +00002443const char* debug_d3drenderstate(DWORD state);
Ivan Gyurdiev621f0752006-06-09 17:47:16 -04002444const char* debug_d3dsamplerstate(DWORD state);
H. Verbeet75108442007-04-09 01:53:38 +02002445const char* debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type);
Jason Edmeades2003c7a2004-12-13 13:35:38 +00002446const char* debug_d3dtexturestate(DWORD state);
Jason Greenac8f2c02006-07-23 22:54:30 -04002447const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype);
Stefan Dösingerd75fd752006-03-28 14:20:47 +02002448const char* debug_d3dpool(WINED3DPOOL pool);
H. Verbeetc4cc10a2007-04-16 21:19:12 +02002449const char *debug_fbostatus(GLenum status);
H. Verbeetb643ab32007-04-23 22:02:50 +02002450const char *debug_glerror(GLenum error);
Stefan Dösinger26ebe392007-07-04 17:57:45 +02002451const char *debug_d3dbasis(WINED3DBASISTYPE basis);
2452const char *debug_d3ddegree(WINED3DDEGREETYPE order);
Stefan Dösingereea2c952008-07-12 11:45:33 -05002453const char* debug_d3dtop(WINED3DTEXTUREOP d3dtop);
Henri Verbeet89139b72008-12-03 14:53:43 +01002454void dump_color_fixup_desc(struct color_fixup_desc fixup);
Stefan Dösinger68c251f2009-02-16 23:30:36 +01002455const char *debug_surflocation(DWORD flag);
Jason Edmeades2003c7a2004-12-13 13:35:38 +00002456
2457/* Routines for GL <-> D3D values */
2458GLenum StencilOp(DWORD op);
Jan Zerebeckifd15b8d2006-08-25 16:28:34 +02002459GLenum CompareFunc(DWORD func);
Stefan Dösingereea2c952008-07-12 11:45:33 -05002460BOOL is_invalid_op(IWineD3DDeviceImpl *This, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
Stefan Dösingerbd682372008-03-29 13:55:59 +01002461void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst);
Stefan Dösingeraf8d2682008-08-23 15:41:51 -05002462void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords, BOOL transformed, DWORD coordtype, BOOL ffp_can_disable_proj);
Stefan Dösinger9ee7e422008-04-23 22:23:57 +02002463void texture_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
Stefan Dösinger51e64b32008-07-04 12:06:58 -05002464void sampler_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
Stefan Dösinger88ae2fe2008-07-05 18:31:34 -05002465void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2466void apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
Stefan Dösinger2dd18632008-12-14 17:16:36 +01002467void state_fogcolor(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2468void state_fogdensity(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
Stefan Dösinger1deafcb2008-12-15 19:37:36 +01002469void state_fogstartend(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
2470void state_fog_fragpart(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
Jason Edmeadesae5a4362004-09-28 02:12:12 +00002471
Henri Verbeet9440dfe2009-01-14 10:01:11 +01002472void surface_add_dirty_rect(IWineD3DSurface *iface, const RECT *dirty_rect);
H. Verbeet1b9a5ba2007-04-16 21:20:25 +02002473GLenum surface_get_gl_buffer(IWineD3DSurface *iface, IWineD3DSwapChain *swapchain);
H. Verbeet4f77c292008-07-02 23:00:41 +02002474void surface_load_ds_location(IWineD3DSurface *iface, DWORD location);
Henri Verbeeteaf24742008-09-24 15:56:47 +02002475void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location);
2476void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height);
Stefan Dösingerc585b4d2009-01-16 16:22:09 +01002477void surface_set_texture_name(IWineD3DSurface *iface, GLuint name, BOOL srgb_name);
Henri Verbeeteaf24742008-09-24 15:56:47 +02002478void surface_set_texture_target(IWineD3DSurface *iface, GLenum target);
H. Verbeetc9b178b2007-04-09 01:53:32 +02002479
Henri Verbeetdd1f0d92009-03-24 10:09:24 +01002480BOOL getColorBits(const struct GlPixelFormatDesc *format_desc,
Henri Verbeeta56e3a12009-03-13 10:44:18 +01002481 short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize);
Henri Verbeetdd1f0d92009-03-24 10:09:24 +01002482BOOL getDepthStencilBits(const struct GlPixelFormatDesc *format_desc, short *depthSize, short *stencilSize);
Roderick Colenbrander4647cbb2007-08-09 01:04:30 +02002483
Stefan Dösinger9abdac62006-05-12 22:21:31 +02002484/* Math utils */
Andrew Talbotf3a515c2006-11-24 14:15:06 +00002485void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2);
Henri Verbeet7d29aec2008-12-12 09:33:52 +01002486UINT wined3d_log2i(UINT32 x);
Stefan Dösinger7ab6c222009-04-22 21:39:14 +02002487unsigned int count_bits(unsigned int mask);
Oliver Stieber8a6799d2005-07-07 20:35:05 +00002488
Ivan Gyurdieve9de5632006-07-09 22:51:03 -06002489typedef struct local_constant {
2490 struct list entry;
2491 unsigned int idx;
2492 DWORD value[4];
2493} local_constant;
2494
Ivan Gyurdievc93239d2006-05-08 17:09:21 -04002495typedef struct SHADER_LIMITS {
2496 unsigned int temporary;
Ivan Gyurdiev0d083162006-06-12 02:59:16 -04002497 unsigned int texcoord;
2498 unsigned int sampler;
Ivan Gyurdievc93239d2006-05-08 17:09:21 -04002499 unsigned int constant_int;
2500 unsigned int constant_float;
2501 unsigned int constant_bool;
2502 unsigned int address;
Ivan Gyurdieva1f4dfe2006-06-12 02:57:07 -04002503 unsigned int packed_output;
2504 unsigned int packed_input;
Jason Green473ce802006-05-26 11:52:33 -04002505 unsigned int attributes;
Ivan Gyurdiev33293df2006-07-10 04:35:15 -06002506 unsigned int label;
Ivan Gyurdievc93239d2006-05-08 17:09:21 -04002507} SHADER_LIMITS;
2508
Jason Green653e71d2006-05-09 22:30:11 -04002509/** Keeps track of details for TEX_M#x# shader opcodes which need to
2510 maintain state information between multiple codes */
2511typedef struct SHADER_PARSE_STATE {
2512 unsigned int current_row;
2513 DWORD texcoord_w[2];
2514} SHADER_PARSE_STATE;
2515
Alexandre Julliard57d15482007-11-28 12:55:11 +01002516#ifdef __GNUC__
2517#define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
2518#else
2519#define PRINTF_ATTR(fmt,args)
2520#endif
2521
Ivan Gyurdiev5f105602006-05-08 15:44:25 -04002522/* Base Shader utility functions.
2523 * (may move callers into the same file in the future) */
2524extern int shader_addline(
2525 SHADER_BUFFER* buffer,
Alexandre Julliard57d15482007-11-28 12:55:11 +01002526 const char* fmt, ...) PRINTF_ATTR(2,3);
Henri Verbeet67da6042009-03-10 09:19:04 +01002527int shader_vaddline(SHADER_BUFFER *buffer, const char *fmt, va_list args);
Ivan Gyurdiev5f105602006-05-08 15:44:25 -04002528
Ivan Gyurdiev5b3c5002006-07-07 00:27:38 -06002529/* Vertex shader utility functions */
2530extern BOOL vshader_get_input(
2531 IWineD3DVertexShader* iface,
2532 BYTE usage_req, BYTE usage_idx_req,
2533 unsigned int* regnum);
2534
Jason Green718716b2006-07-19 00:06:07 -04002535extern HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object);
2536
Raphael Junqueira01968612003-11-14 03:50:35 +00002537/*****************************************************************************
H. Verbeet59af5c42006-03-30 19:14:31 +02002538 * IDirect3DBaseShader implementation structure
2539 */
2540typedef struct IWineD3DBaseShaderClass
2541{
Stefan Dösingerbd975802007-11-16 21:01:33 +01002542 LONG ref;
Ivan Gyurdievc93239d2006-05-08 17:09:21 -04002543 SHADER_LIMITS limits;
Jason Green653e71d2006-05-09 22:30:11 -04002544 SHADER_PARSE_STATE parse_state;
Stefan Dösinger7a97d4e2007-11-16 21:02:29 +01002545 DWORD *function;
H. Verbeet59af5c42006-03-30 19:14:31 +02002546 UINT functionLength;
Stefan Dösinger3f16f022007-09-14 13:21:52 +02002547 UINT cur_loop_depth, cur_loop_regno;
Stefan Dösingeredb78182007-11-09 14:48:47 +01002548 BOOL load_local_constsF;
Henri Verbeet2a5a6a32009-05-05 09:38:03 +02002549 const struct wined3d_shader_frontend *frontend;
2550 void *frontend_data;
Ivan Gyurdiev77162362006-07-04 01:21:53 -06002551
H. Verbeet2c85e5e2007-02-27 20:51:53 +01002552 /* Programs this shader is linked with */
2553 struct list linked_programs;
2554
Ivan Gyurdieve9de5632006-07-09 22:51:03 -06002555 /* Immediate constants (override global ones) */
2556 struct list constantsB;
2557 struct list constantsF;
2558 struct list constantsI;
H. Verbeetef87a402006-08-05 18:15:35 +02002559 shader_reg_maps reg_maps;
Ivan Gyurdieve9de5632006-07-09 22:51:03 -06002560
Ivan Gyurdievd0032a12006-09-27 07:14:46 -04002561 /* Pointer to the parent device */
2562 IWineD3DDevice *device;
Stefan Dösinger09bf3d52008-01-08 20:45:59 +01002563 struct list shader_list_entry;
Ivan Gyurdievd0032a12006-09-27 07:14:46 -04002564
H. Verbeet59af5c42006-03-30 19:14:31 +02002565} IWineD3DBaseShaderClass;
2566
2567typedef struct IWineD3DBaseShaderImpl {
2568 /* IUnknown */
2569 const IWineD3DBaseShaderVtbl *lpVtbl;
H. Verbeet59af5c42006-03-30 19:14:31 +02002570
2571 /* IWineD3DBaseShader */
2572 IWineD3DBaseShaderClass baseShader;
2573} IWineD3DBaseShaderImpl;
2574
Henri Verbeet4997bee2008-12-09 09:52:38 +01002575void shader_buffer_init(struct SHADER_BUFFER *buffer);
2576void shader_buffer_free(struct SHADER_BUFFER *buffer);
Henri Verbeet50a87e22008-12-09 09:52:39 +01002577void shader_cleanup(IWineD3DBaseShader *iface);
Henri Verbeet65622a02009-05-06 17:59:21 +02002578void shader_dump_src_param(const struct wined3d_shader_src_param *param,
2579 const struct wined3d_shader_version *shader_version);
2580void shader_dump_dst_param(const struct wined3d_shader_dst_param *param,
2581 const struct wined3d_shader_version *shader_version);
Henri Verbeet23781082009-05-04 09:49:27 +02002582void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER *buffer,
Stefan Dösinger7b1d4872009-05-15 13:56:40 +02002583 const shader_reg_maps *reg_maps, const DWORD *pFunction, void *backend_ctx);
Henri Verbeet23781082009-05-04 09:49:27 +02002584HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, const struct wined3d_shader_frontend *fe,
Henri Verbeet19cb4592009-05-27 10:24:50 +02002585 struct shader_reg_maps *reg_maps, struct wined3d_shader_attribute *attributes,
Henri Verbeet2ee0d472009-05-27 10:24:50 +02002586 struct wined3d_shader_signature_element *input_signature,
2587 struct wined3d_shader_signature_element *output_signature, const DWORD *byte_code, DWORD constf_size);
Henri Verbeet2a5a6a32009-05-05 09:38:03 +02002588void shader_init(struct IWineD3DBaseShaderClass *shader, IWineD3DDevice *device);
Henri Verbeet2ee0d472009-05-27 10:24:50 +02002589BOOL shader_match_semantic(const char *semantic_name, WINED3DDECLUSAGE usage);
Henri Verbeetdddd1f02009-05-04 09:49:27 +02002590const struct wined3d_shader_frontend *shader_select_frontend(DWORD version_token);
Henri Verbeet2a5a6a32009-05-05 09:38:03 +02002591void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe_data, const DWORD *pFunction);
Jason Green36b0b9c2006-05-09 22:33:24 -04002592
Henri Verbeet65622a02009-05-06 17:59:21 +02002593static inline BOOL shader_is_pshader_version(enum wined3d_shader_type type)
2594{
2595 return type == WINED3D_SHADER_TYPE_PIXEL;
Ivan Gyurdiev8b7401c2006-05-14 09:43:31 -04002596}
2597
Henri Verbeet65622a02009-05-06 17:59:21 +02002598static inline BOOL shader_is_vshader_version(enum wined3d_shader_type type)
2599{
2600 return type == WINED3D_SHADER_TYPE_VERTEX;
Ivan Gyurdiev8b7401c2006-05-14 09:43:31 -04002601}
2602
Henri Verbeet96005c02009-05-07 16:36:08 +02002603static inline BOOL shader_is_scalar(const struct wined3d_shader_register *reg)
Henri Verbeetf7f61a52009-04-07 11:09:11 +02002604{
Henri Verbeet96005c02009-05-07 16:36:08 +02002605 switch (reg->type)
Henri Verbeetf7f61a52009-04-07 11:09:11 +02002606 {
H. Verbeeta79654d2007-04-12 23:55:31 +02002607 case WINED3DSPR_RASTOUT:
Henri Verbeetf7f61a52009-04-07 11:09:11 +02002608 /* oFog & oPts */
Henri Verbeet96005c02009-05-07 16:36:08 +02002609 if (reg->idx != 0) return TRUE;
H. Verbeeta79654d2007-04-12 23:55:31 +02002610 /* oPos */
2611 return FALSE;
2612
2613 case WINED3DSPR_DEPTHOUT: /* oDepth */
2614 case WINED3DSPR_CONSTBOOL: /* b# */
2615 case WINED3DSPR_LOOP: /* aL */
2616 case WINED3DSPR_PREDICATE: /* p0 */
2617 return TRUE;
2618
Stefan Dösinger81de2fa2008-02-11 12:04:57 +01002619 case WINED3DSPR_MISCTYPE:
Henri Verbeet96005c02009-05-07 16:36:08 +02002620 switch(reg->idx)
Henri Verbeetf7f61a52009-04-07 11:09:11 +02002621 {
Stefan Dösinger81de2fa2008-02-11 12:04:57 +01002622 case 0: /* vPos */
2623 return FALSE;
2624 case 1: /* vFace */
2625 return TRUE;
2626 default:
2627 return FALSE;
2628 }
2629
Henri Verbeet69cbb572009-05-07 16:36:08 +02002630 case WINED3DSPR_IMMCONST:
2631 switch(reg->immconst_type)
2632 {
2633 case WINED3D_IMMCONST_FLOAT:
2634 return TRUE;
2635 default:
2636 return FALSE;
2637 }
2638
H. Verbeeta79654d2007-04-12 23:55:31 +02002639 default:
2640 return FALSE;
2641 }
2642}
2643
Stefan Dösingeraeb0e432008-02-14 14:15:49 +01002644static inline BOOL shader_constant_is_local(IWineD3DBaseShaderImpl* This, DWORD reg) {
2645 local_constant* lconst;
2646
2647 if(This->baseShader.load_local_constsF) return FALSE;
2648 LIST_FOR_EACH_ENTRY(lconst, &This->baseShader.constantsF, local_constant, entry) {
2649 if(lconst->idx == reg) return TRUE;
2650 }
2651 return FALSE;
2652
2653}
2654
H. Verbeet59af5c42006-03-30 19:14:31 +02002655/*****************************************************************************
Stefan Dösinger8dcd5122009-02-05 19:44:32 +01002656 * IDirect3DVertexShader implementation structures
Raphael Junqueira01968612003-11-14 03:50:35 +00002657 */
Oliver Stieber2121f782005-03-02 12:16:10 +00002658typedef struct IWineD3DVertexShaderImpl {
2659 /* IUnknown parts*/
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002660 const IWineD3DVertexShaderVtbl *lpVtbl;
Raphael Junqueira01968612003-11-14 03:50:35 +00002661
H. Verbeet59af5c42006-03-30 19:14:31 +02002662 /* IWineD3DBaseShader */
2663 IWineD3DBaseShaderClass baseShader;
2664
2665 /* IWineD3DVertexShaderImpl */
Oliver Stieber2121f782005-03-02 12:16:10 +00002666 IUnknown *parent;
Raphael Junqueira01968612003-11-14 03:50:35 +00002667
Jason Green6a97f222006-07-17 01:41:53 -04002668 DWORD usage;
Oliver Stieber2c0e97e2005-08-17 11:34:03 +00002669
Stefan Dösingeraed93052008-11-20 13:27:42 +01002670 /* The GL shader */
Stefan Dösingeraad92c02009-05-26 21:06:37 +02002671 void *backend_priv;
Stefan Dösingeraed93052008-11-20 13:27:42 +01002672
Ivan Gyurdiev276609e2006-07-04 02:01:46 -06002673 /* Vertex shader input and output semantics */
Henri Verbeet19cb4592009-05-27 10:24:50 +02002674 struct wined3d_shader_attribute attributes[MAX_ATTRIBS];
Henri Verbeet2ee0d472009-05-27 10:24:50 +02002675 struct wined3d_shader_signature_element output_signature[MAX_REG_OUTPUT];
Ivan Gyurdiev276609e2006-07-04 02:01:46 -06002676
Stefan Dösingerfb0dde7b2007-11-07 19:57:49 +01002677 UINT min_rel_offset, max_rel_offset;
2678 UINT rel_offset;
2679
Stefan Dösinger95921232007-11-20 21:14:10 +01002680 UINT recompile_count;
Oliver Stieber2121f782005-03-02 12:16:10 +00002681} IWineD3DVertexShaderImpl;
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002682extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
Stefan Dösinger8dcd5122009-02-05 19:44:32 +01002683
2684void find_vs_compile_args(IWineD3DVertexShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct vs_compile_args *args);
Raphael Junqueira01968612003-11-14 03:50:35 +00002685
2686/*****************************************************************************
2687 * IDirect3DPixelShader implementation structure
2688 */
Oliver Stieber2121f782005-03-02 12:16:10 +00002689typedef struct IWineD3DPixelShaderImpl {
Oliver Stieberb3563da2005-09-28 10:13:00 +00002690 /* IUnknown parts */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002691 const IWineD3DPixelShaderVtbl *lpVtbl;
Oliver Stieberb3563da2005-09-28 10:13:00 +00002692
H. Verbeet59af5c42006-03-30 19:14:31 +02002693 /* IWineD3DBaseShader */
2694 IWineD3DBaseShaderClass baseShader;
2695
2696 /* IWineD3DPixelShaderImpl */
Oliver Stieber2121f782005-03-02 12:16:10 +00002697 IUnknown *parent;
Raphael Junqueira01968612003-11-14 03:50:35 +00002698
Ivan Gyurdiev276609e2006-07-04 02:01:46 -06002699 /* Pixel shader input semantics */
Henri Verbeet2ee0d472009-05-27 10:24:50 +02002700 struct wined3d_shader_signature_element input_signature[MAX_REG_INPUT];
Stefan Dösinger409103f2007-10-28 00:12:37 +02002701 DWORD input_reg_map[MAX_REG_INPUT];
Stefan Dösinger1b23dd12007-11-06 12:34:22 +01002702 BOOL input_reg_used[MAX_REG_INPUT];
H. Verbeeta6fa6a42008-06-19 00:36:35 +02002703 int declared_in_count;
Ivan Gyurdiev276609e2006-07-04 02:01:46 -06002704
Stefan Dösingeraed93052008-11-20 13:27:42 +01002705 /* The GL shader */
Stefan Dösinger814dd422009-05-26 21:05:59 +02002706 void *backend_priv;
Stefan Dösingeraed93052008-11-20 13:27:42 +01002707
Stefan Dösinger49a49fc2007-02-15 03:05:17 +01002708 /* Some information about the shader behavior */
Stefan Dösinger167a2712008-03-05 03:18:55 +01002709 struct stb_const_desc bumpenvmatconst[MAX_TEXTURES];
Henri Verbeet42e31a42009-03-25 10:12:27 +01002710 unsigned char numbumpenvmatconsts;
Stefan Dösinger167a2712008-03-05 03:18:55 +01002711 struct stb_const_desc luminanceconst[MAX_TEXTURES];
Stefan Dösinger9c6cdda2007-09-14 13:11:00 +02002712 char vpos_uniform;
Oliver Stieber2121f782005-03-02 12:16:10 +00002713} IWineD3DPixelShaderImpl;
2714
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002715extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
Stefan Dösingerd0d681c2009-05-26 13:43:43 +02002716void pixelshader_update_samplers(struct shader_reg_maps *reg_maps, IWineD3DBaseTexture * const *textures);
Stefan Dösingerdd890552008-11-20 02:55:17 +01002717void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct ps_compile_args *args);
Stefan Dösingercff4e1e2006-04-17 17:04:59 +02002718
Stefan Dösinger6313e0f2007-09-14 13:02:59 +02002719/* sRGB correction constants */
2720static const float srgb_cmp = 0.0031308;
2721static const float srgb_mul_low = 12.92;
2722static const float srgb_pow = 0.41666;
2723static const float srgb_mul_high = 1.055;
2724static const float srgb_sub_high = 0.055;
2725
Stefan Dösingercff4e1e2006-04-17 17:04:59 +02002726/*****************************************************************************
2727 * IWineD3DPalette implementation structure
2728 */
2729struct IWineD3DPaletteImpl {
2730 /* IUnknown parts */
2731 const IWineD3DPaletteVtbl *lpVtbl;
2732 LONG ref;
Stefan Dösingera6f71af2006-04-21 00:00:30 +02002733
2734 IUnknown *parent;
2735 IWineD3DDeviceImpl *wineD3DDevice;
2736
2737 /* IWineD3DPalette */
2738 HPALETTE hpal;
2739 WORD palVersion; /*| */
2740 WORD palNumEntries; /*| LOGPALETTE */
2741 PALETTEENTRY palents[256]; /*| */
2742 /* This is to store the palette in 'screen format' */
2743 int screen_palents[256];
2744 DWORD Flags;
Stefan Dösingercff4e1e2006-04-17 17:04:59 +02002745};
2746
2747extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
Stefan Dösingera6f71af2006-04-21 00:00:30 +02002748DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
Stefan Dösingercff4e1e2006-04-17 17:04:59 +02002749
Stefan Dösingera6206832006-04-18 23:04:51 +02002750/* DirectDraw utility functions */
2751extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
2752
Stefan Dösinger35187472006-06-21 10:36:14 +02002753/*****************************************************************************
2754 * Pixel format management
2755 */
Henri Verbeetb4510482008-12-03 14:53:42 +01002756
Henri Verbeet7420a962009-05-01 09:13:54 +02002757/* WineD3D pixel format flags */
2758#define WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING 0x1
2759#define WINED3DFMT_FLAG_FILTERING 0x2
2760#define WINED3DFMT_FLAG_DEPTH 0x4
2761#define WINED3DFMT_FLAG_STENCIL 0x8
2762#define WINED3DFMT_FLAG_RENDERTARGET 0x10
2763#define WINED3DFMT_FLAG_FOURCC 0x20
2764
Henri Verbeetb4510482008-12-03 14:53:42 +01002765struct GlPixelFormatDesc
2766{
Henri Verbeet53bf5c22009-03-13 10:44:17 +01002767 WINED3DFORMAT format;
2768 DWORD red_mask;
2769 DWORD green_mask;
2770 DWORD blue_mask;
2771 DWORD alpha_mask;
2772 UINT byte_count;
2773 WORD depth_size;
2774 WORD stencil_size;
2775
Henri Verbeet4434d002009-03-27 10:25:56 +01002776 enum wined3d_ffp_emit_idx emit_idx;
2777 GLint component_count;
2778 GLenum gl_vtx_type;
2779 GLint gl_vtx_format;
2780 GLboolean gl_normalized;
2781 unsigned int component_size;
2782
Henri Verbeetb4510482008-12-03 14:53:42 +01002783 GLint glInternal;
2784 GLint glGammaInternal;
2785 GLint rtInternal;
2786 GLint glFormat;
2787 GLint glType;
Henri Verbeetb4510482008-12-03 14:53:42 +01002788 unsigned int Flags;
2789 float heightscale;
Henri Verbeet89139b72008-12-03 14:53:43 +01002790 struct color_fixup_desc color_fixup;
Henri Verbeetb4510482008-12-03 14:53:42 +01002791};
2792
Henri Verbeeta56e3a12009-03-13 10:44:18 +01002793const struct GlPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, const WineD3D_GL_Info *gl_info);
H. Verbeet30ee0712007-03-12 23:22:00 +01002794
Henri Verbeet2b926db2008-12-30 14:56:49 +01002795static inline BOOL use_vs(IWineD3DStateBlockImpl *stateblock)
2796{
2797 return (stateblock->vertexShader
Henri Verbeetcc447ea2009-01-08 10:19:16 +01002798 && !stateblock->wineD3DDevice->strided_streams.position_transformed
Henri Verbeet2b926db2008-12-30 14:56:49 +01002799 && stateblock->wineD3DDevice->vs_selected_mode != SHADER_NONE);
H. Verbeet30ee0712007-03-12 23:22:00 +01002800}
2801
Henri Verbeet2b926db2008-12-30 14:56:49 +01002802static inline BOOL use_ps(IWineD3DStateBlockImpl *stateblock)
2803{
2804 return (stateblock->pixelShader
2805 && stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE);
H. Verbeet30ee0712007-03-12 23:22:00 +01002806}
2807
H. Verbeetd9b73692007-05-03 20:57:09 +02002808void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED3DRECT *src_rect,
H. Verbeetd7c7cbf2007-07-24 23:38:40 +02002809 IWineD3DSurface *dst_surface, WINED3DRECT *dst_rect, const WINED3DTEXTUREFILTERTYPE filter, BOOL flip);
Rico Schüller2ef75182009-05-11 21:43:54 +02002810
2811/* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */
2812#define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL"
2813
Raphael Junqueira01968612003-11-14 03:50:35 +00002814#endif