blob: a790aea5e4e83c4a7705ada0b47980179eb032db [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
Oliver Stieber46e7c302005-06-23 11:05:24 +00006 * Copyright 2004 Jason Edmeades
7 * 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"
Ivan Gyurdiev062541c2006-10-09 19:45:12 -040041#include "wined3d_private_types.h"
Henri Verbeeta6917b12008-11-25 11:57:39 +010042#include "wine/wined3d.h"
Henri Verbeet8899f342008-11-20 13:32:00 +010043#include "wined3d_gl.h"
Jason Green0c59ca62006-06-09 03:33:01 -040044#include "wine/list.h"
Raphael Junqueira01968612003-11-14 03:50:35 +000045
H. Verbeet2a82ed82007-02-27 20:51:48 +010046/* Hash table functions */
Henri Verbeeteb78c2a2008-11-25 14:36:08 +010047typedef unsigned int (hash_function_t)(const void *key);
48typedef BOOL (compare_function_t)(const void *keya, const void *keyb);
H. Verbeet2a82ed82007-02-27 20:51:48 +010049
H. Verbeetb917bda2008-08-21 18:35:34 +020050struct hash_table_entry_t {
H. Verbeet2a82ed82007-02-27 20:51:48 +010051 void *key;
52 void *value;
53 unsigned int hash;
54 struct list entry;
H. Verbeetb917bda2008-08-21 18:35:34 +020055};
H. Verbeet2a82ed82007-02-27 20:51:48 +010056
Henri Verbeetb4f43e32008-08-29 02:12:10 +020057struct hash_table_t {
H. Verbeet2a82ed82007-02-27 20:51:48 +010058 hash_function_t *hash_function;
59 compare_function_t *compare_function;
60 struct list *buckets;
61 unsigned int bucket_count;
H. Verbeetb917bda2008-08-21 18:35:34 +020062 struct hash_table_entry_t *entries;
H. Verbeet2a82ed82007-02-27 20:51:48 +010063 unsigned int entry_count;
64 struct list free_entries;
65 unsigned int count;
66 unsigned int grow_size;
67 unsigned int shrink_size;
Henri Verbeetb4f43e32008-08-29 02:12:10 +020068};
H. Verbeet2a82ed82007-02-27 20:51:48 +010069
Henri Verbeetb4f43e32008-08-29 02:12:10 +020070struct hash_table_t *hash_table_create(hash_function_t *hash_function, compare_function_t *compare_function);
71void hash_table_destroy(struct hash_table_t *table, void (*free_value)(void *value, void *cb), void *cb);
Henri Verbeeteb78c2a2008-11-25 14:36:08 +010072void *hash_table_get(struct hash_table_t *table, const void *key);
Henri Verbeetb4f43e32008-08-29 02:12:10 +020073void hash_table_put(struct hash_table_t *table, void *key, void *value);
74void hash_table_remove(struct hash_table_t *table, void *key);
H. Verbeet2a82ed82007-02-27 20:51:48 +010075
Oliver Stieber18857f12005-06-24 11:53:07 +000076/* Device caps */
Alexander Dorofeyev16597092008-03-27 00:23:04 +020077#define MAX_PALETTES 65536
H. Verbeet5b7758f2007-06-25 22:45:40 +020078#define MAX_STREAMS 16
79#define MAX_TEXTURES 8
80#define MAX_FRAGMENT_SAMPLERS 16
81#define MAX_VERTEX_SAMPLERS 4
82#define MAX_COMBINED_SAMPLERS (MAX_FRAGMENT_SAMPLERS + MAX_VERTEX_SAMPLERS)
83#define MAX_ACTIVE_LIGHTS 8
84#define MAX_CLIPPLANES WINED3DMAXUSERCLIPPLANES
85#define MAX_LEVELS 256
Oliver Stieber18857f12005-06-24 11:53:07 +000086
Jason Green718716b2006-07-19 00:06:07 -040087#define MAX_CONST_I 16
88#define MAX_CONST_B 16
Oliver Stieber9b0b8032005-08-17 10:27:01 +000089
Oliver Stieberabb11f32005-07-05 14:05:18 +000090/* Used for CreateStateBlock */
91#define NUM_SAVEDPIXELSTATES_R 35
92#define NUM_SAVEDPIXELSTATES_T 18
93#define NUM_SAVEDPIXELSTATES_S 12
Stefan Dösingera8e21d02007-08-19 12:50:14 +020094#define NUM_SAVEDVERTEXSTATES_R 34
Oliver Stieberabb11f32005-07-05 14:05:18 +000095#define NUM_SAVEDVERTEXSTATES_T 2
96#define NUM_SAVEDVERTEXSTATES_S 1
97
98extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
99extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
100extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
101extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
102extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
103extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
104
Oliver Stieberbb6f9b02005-08-03 11:00:28 +0000105typedef enum _WINELOOKUP {
106 WINELOOKUP_WARPPARAM = 0,
Stefan Dösingera22203a2008-04-06 00:31:39 +0200107 MAX_LOOKUPS = 1
Oliver Stieberbb6f9b02005-08-03 11:00:28 +0000108} WINELOOKUP;
109
110extern int minLookup[MAX_LOOKUPS];
111extern int maxLookup[MAX_LOOKUPS];
112extern DWORD *stateLookup[MAX_LOOKUPS];
113
Stefan Dösingera22203a2008-04-06 00:31:39 +0200114typedef DWORD magLookup_t[WINED3DTEXF_ANISOTROPIC + 1];
115extern magLookup_t magLookup;
Stefan Dösinger481bcdf2008-04-06 00:37:51 +0200116extern magLookup_t magLookup_noFilter;
Stefan Dösingera22203a2008-04-06 00:31:39 +0200117
Stefan Dösinger4bb54a12008-04-06 00:18:53 +0200118typedef DWORD minMipLookup_t[WINED3DTEXF_ANISOTROPIC + 1][WINED3DTEXF_LINEAR + 1];
119extern minMipLookup_t minMipLookup;
Stefan Dösinger0cbd08b2008-04-06 00:22:08 +0200120extern minMipLookup_t minMipLookup_noFilter;
Oliver Stieberbb6f9b02005-08-03 11:00:28 +0000121
Stefan Dösingerb83dc6b2007-12-19 02:51:53 +0100122void init_type_lookup(WineD3D_GL_Info *gl_info);
123#define WINED3D_ATR_TYPE(type) GLINFO_LOCATION.glTypeLookup[type].d3dType
124#define WINED3D_ATR_SIZE(type) GLINFO_LOCATION.glTypeLookup[type].size
125#define WINED3D_ATR_GLTYPE(type) GLINFO_LOCATION.glTypeLookup[type].glType
126#define WINED3D_ATR_NORMALIZED(type) GLINFO_LOCATION.glTypeLookup[type].normalized
127#define WINED3D_ATR_TYPESIZE(type) GLINFO_LOCATION.glTypeLookup[type].typesize
Oliver Stieberbb6f9b02005-08-03 11:00:28 +0000128
Francois Gouget8320d212008-07-10 00:23:07 +0200129/* float_16_to_32() and float_32_to_16() (see implementation in
130 * surface_base.c) convert 16 bit floats in the FLOAT16 data type
Stefan Dösinger825506d2008-02-25 11:18:03 +0100131 * to standard C floats and vice versa. They do not depend on the encoding
132 * of the C float, so they are platform independent, but slow. On x86 and
Austin English6e59cd22008-04-22 01:18:14 -0500133 * other IEEE 754 compliant platforms the conversion can be accelerated by
134 * bit shifting the exponent and mantissa. There are also some SSE-based
135 * assembly routines out there.
Stefan Dösinger825506d2008-02-25 11:18:03 +0100136 *
137 * See GL_NV_half_float for a reference of the FLOAT16 / GL_HALF format
138 */
Stefan Dösingerb5f925c2007-12-19 17:18:39 +0100139static inline float float_16_to_32(const unsigned short *in) {
140 const unsigned short s = ((*in) & 0x8000);
141 const unsigned short e = ((*in) & 0x7C00) >> 10;
142 const unsigned short m = (*in) & 0x3FF;
143 const float sgn = (s ? -1.0 : 1.0);
144
145 if(e == 0) {
146 if(m == 0) return sgn * 0.0; /* +0.0 or -0.0 */
147 else return sgn * pow(2, -14.0) * ( (float) m / 1024.0);
148 } else if(e < 31) {
149 return sgn * pow(2, (float) e-15.0) * (1.0 + ((float) m / 1024.0));
150 } else {
151 if(m == 0) return sgn / 0.0; /* +INF / -INF */
152 else return 0.0 / 0.0; /* NAN */
153 }
154}
155
Raphael Junqueiracc8762a2005-07-24 17:11:33 +0000156/**
157 * Settings
158 */
Oliver Stieber9e6957b2005-09-23 11:08:03 +0000159#define VS_NONE 0
160#define VS_HW 1
Raphael Junqueira01968612003-11-14 03:50:35 +0000161
Oliver Stieber9e6957b2005-09-23 11:08:03 +0000162#define PS_NONE 0
163#define PS_HW 1
Jason Edmeades24ab49e2004-09-23 04:34:27 +0000164
Oliver Stieber9e6957b2005-09-23 11:08:03 +0000165#define VBO_NONE 0
166#define VBO_HW 1
167
168#define NP2_NONE 0
169#define NP2_REPACK 1
H. Verbeet193f6bb2006-09-26 20:31:48 +0200170#define NP2_NATIVE 2
Raphael Junqueiracc8762a2005-07-24 17:11:33 +0000171
H. Verbeetad4c2bd2006-11-17 13:23:53 +0100172#define ORM_BACKBUFFER 0
173#define ORM_PBUFFER 1
H. Verbeet6d660852006-11-17 13:24:00 +0100174#define ORM_FBO 2
H. Verbeetad4c2bd2006-11-17 13:23:53 +0100175
Jason Greend2045402006-05-23 18:22:59 -0400176#define SHADER_ARB 1
177#define SHADER_GLSL 2
Stefan Dösinger4640be82008-03-22 14:31:52 +0100178#define SHADER_ATI 3
179#define SHADER_NONE 4
Jason Greend2045402006-05-23 18:22:59 -0400180
Stefan Dösinger739d5652006-07-17 20:14:25 +0200181#define RTL_DISABLE -1
182#define RTL_AUTO 0
183#define RTL_READDRAW 1
184#define RTL_READTEX 2
185#define RTL_TEXDRAW 3
186#define RTL_TEXTEX 4
187
Roderick Colenbrander27335722008-11-23 22:51:03 +0100188#define PCI_VENDOR_NONE 0xffff /* e.g. 0x8086 for Intel and 0x10de for Nvidia */
Roderick Colenbrander52d59712008-11-23 22:33:29 +0100189#define PCI_DEVICE_NONE 0xffff /* e.g. 0x14f for a Geforce6200 */
190
H. Verbeetba8a6a32006-09-26 20:31:41 +0200191/* NOTE: When adding fields to this structure, make sure to update the default
192 * values in wined3d_main.c as well. */
Raphael Junqueiracc8762a2005-07-24 17:11:33 +0000193typedef struct wined3d_settings_s {
194/* vertex and pixel shader modes */
195 int vs_mode;
196 int ps_mode;
197 int vbo_mode;
Jason Greend2045402006-05-23 18:22:59 -0400198/* Ideally, we don't want the user to have to request GLSL. If the hardware supports GLSL,
199 we should use it. However, until it's fully implemented, we'll leave it as a registry
200 setting for developers. */
Phil Costin1b320432006-05-18 02:24:08 +0100201 BOOL glslRequested;
H. Verbeetad4c2bd2006-11-17 13:23:53 +0100202 int offscreen_rendering_mode;
Stefan Dösinger739d5652006-07-17 20:14:25 +0200203 int rendertargetlock_mode;
Roderick Colenbrander27335722008-11-23 22:51:03 +0100204 unsigned short pci_vendor_id;
Roderick Colenbrander52d59712008-11-23 22:33:29 +0100205 unsigned short pci_device_id;
Jan Zerebecki4d6cfb62006-08-08 00:03:06 +0200206/* Memory tracking and object counting */
207 unsigned int emulated_textureram;
Stefan Dösinger271fb002007-09-01 21:22:32 +0200208 char *logo;
Roderick Colenbrander042d0392008-06-02 21:06:01 +0000209 int allow_multisampling;
Raphael Junqueiracc8762a2005-07-24 17:11:33 +0000210} wined3d_settings_t;
211
212extern wined3d_settings_t wined3d_settings;
213
H. Verbeetdf6f4822006-11-27 20:50:37 +0100214/* Shader backends */
Stefan Dösinger2b2c9192007-09-21 23:53:57 +0200215struct SHADER_OPCODE_ARG;
H. Verbeetdf6f4822006-11-27 20:50:37 +0100216
Stefan Dösingera66fb402008-03-18 19:19:16 +0100217#define SHADER_PGMSIZE 65535
218typedef struct SHADER_BUFFER {
219 char* buffer;
220 unsigned int bsize;
221 unsigned int lineNo;
222 BOOL newline;
223} SHADER_BUFFER;
224
Henri Verbeet2e769542008-09-23 17:39:34 +0200225enum WINED3D_SHADER_INSTRUCTION_HANDLER
226{
227 WINED3DSIH_ABS,
228 WINED3DSIH_ADD,
229 WINED3DSIH_BEM,
230 WINED3DSIH_BREAK,
231 WINED3DSIH_BREAKC,
232 WINED3DSIH_BREAKP,
233 WINED3DSIH_CALL,
234 WINED3DSIH_CALLNZ,
235 WINED3DSIH_CMP,
236 WINED3DSIH_CND,
237 WINED3DSIH_CRS,
238 WINED3DSIH_DCL,
239 WINED3DSIH_DEF,
240 WINED3DSIH_DEFB,
241 WINED3DSIH_DEFI,
242 WINED3DSIH_DP2ADD,
243 WINED3DSIH_DP3,
244 WINED3DSIH_DP4,
245 WINED3DSIH_DST,
246 WINED3DSIH_DSX,
247 WINED3DSIH_DSY,
248 WINED3DSIH_ELSE,
249 WINED3DSIH_ENDIF,
250 WINED3DSIH_ENDLOOP,
251 WINED3DSIH_ENDREP,
252 WINED3DSIH_EXP,
253 WINED3DSIH_EXPP,
254 WINED3DSIH_FRC,
255 WINED3DSIH_IF,
256 WINED3DSIH_IFC,
257 WINED3DSIH_LABEL,
258 WINED3DSIH_LIT,
259 WINED3DSIH_LOG,
260 WINED3DSIH_LOGP,
261 WINED3DSIH_LOOP,
262 WINED3DSIH_LRP,
263 WINED3DSIH_M3x2,
264 WINED3DSIH_M3x3,
265 WINED3DSIH_M3x4,
266 WINED3DSIH_M4x3,
267 WINED3DSIH_M4x4,
268 WINED3DSIH_MAD,
269 WINED3DSIH_MAX,
270 WINED3DSIH_MIN,
271 WINED3DSIH_MOV,
272 WINED3DSIH_MOVA,
273 WINED3DSIH_MUL,
274 WINED3DSIH_NOP,
275 WINED3DSIH_NRM,
276 WINED3DSIH_PHASE,
277 WINED3DSIH_POW,
278 WINED3DSIH_RCP,
279 WINED3DSIH_REP,
280 WINED3DSIH_RET,
281 WINED3DSIH_RSQ,
282 WINED3DSIH_SETP,
283 WINED3DSIH_SGE,
284 WINED3DSIH_SGN,
285 WINED3DSIH_SINCOS,
286 WINED3DSIH_SLT,
287 WINED3DSIH_SUB,
288 WINED3DSIH_TEX,
289 WINED3DSIH_TEXBEM,
290 WINED3DSIH_TEXBEML,
291 WINED3DSIH_TEXCOORD,
292 WINED3DSIH_TEXDEPTH,
293 WINED3DSIH_TEXDP3,
294 WINED3DSIH_TEXDP3TEX,
295 WINED3DSIH_TEXKILL,
296 WINED3DSIH_TEXLDD,
297 WINED3DSIH_TEXLDL,
298 WINED3DSIH_TEXM3x2DEPTH,
299 WINED3DSIH_TEXM3x2PAD,
300 WINED3DSIH_TEXM3x2TEX,
301 WINED3DSIH_TEXM3x3,
302 WINED3DSIH_TEXM3x3DIFF,
303 WINED3DSIH_TEXM3x3PAD,
304 WINED3DSIH_TEXM3x3SPEC,
305 WINED3DSIH_TEXM3x3TEX,
306 WINED3DSIH_TEXM3x3VSPEC,
307 WINED3DSIH_TEXREG2AR,
308 WINED3DSIH_TEXREG2GB,
309 WINED3DSIH_TEXREG2RGB,
310 WINED3DSIH_TABLE_SIZE
311};
312
313typedef void (*SHADER_HANDLER) (struct SHADER_OPCODE_ARG*);
314
Stefan Dösinger5ab52022008-03-18 19:39:26 +0100315struct shader_caps {
Stefan Dösinger5ab52022008-03-18 19:39:26 +0100316 DWORD VertexShaderVersion;
317 DWORD MaxVertexShaderConst;
318
319 DWORD PixelShaderVersion;
320 float PixelShader1xMaxValue;
321
322 WINED3DVSHADERCAPS2_0 VS20Caps;
323 WINED3DPSHADERCAPS2_0 PS20Caps;
324
325 DWORD MaxVShaderInstructionsExecuted;
326 DWORD MaxPShaderInstructionsExecuted;
327 DWORD MaxVertexShader30InstructionSlots;
328 DWORD MaxPixelShader30InstructionSlots;
329};
330
Henri Verbeet57401fc2008-10-27 18:31:31 +0100331enum tex_types
332{
333 tex_1d = 0,
334 tex_2d = 1,
335 tex_3d = 2,
336 tex_cube = 3,
337 tex_rect = 4,
338 tex_type_count = 5,
339};
340
H. Verbeetdf6f4822006-11-27 20:50:37 +0100341typedef struct {
Henri Verbeet2e769542008-09-23 17:39:34 +0200342 const SHADER_HANDLER *shader_instruction_handler_table;
H. Verbeetdf6f4822006-11-27 20:50:37 +0100343 void (*shader_select)(IWineD3DDevice *iface, BOOL usePS, BOOL useVS);
Henri Verbeet57401fc2008-10-27 18:31:31 +0100344 void (*shader_select_depth_blt)(IWineD3DDevice *iface, enum tex_types tex_type);
H. Verbeetb37cc082008-07-10 17:57:35 +0200345 void (*shader_deselect_depth_blt)(IWineD3DDevice *iface);
H. Verbeetdf6f4822006-11-27 20:50:37 +0100346 void (*shader_load_constants)(IWineD3DDevice *iface, char usePS, char useVS);
Stefan Dösingerfa97fbd2007-02-08 22:31:01 +0100347 void (*shader_cleanup)(IWineD3DDevice *iface);
Stefan Dösinger2b2c9192007-09-21 23:53:57 +0200348 void (*shader_color_correction)(struct SHADER_OPCODE_ARG *arg);
Stefan Dösingercfc57252007-11-20 17:40:54 +0100349 void (*shader_destroy)(IWineD3DBaseShader *iface);
Stefan Dösingerf912f182008-02-24 11:23:53 +0100350 HRESULT (*shader_alloc_private)(IWineD3DDevice *iface);
351 void (*shader_free_private)(IWineD3DDevice *iface);
Stefan Dösinger107e80a2008-03-04 02:30:23 +0100352 BOOL (*shader_dirtifyable_constants)(IWineD3DDevice *iface);
Stefan Dösinger0bf32b12008-11-24 11:55:50 +0100353 GLuint (*shader_generate_pshader)(IWineD3DPixelShader *iface, SHADER_BUFFER *buffer);
Stefan Dösingera66fb402008-03-18 19:19:16 +0100354 void (*shader_generate_vshader)(IWineD3DVertexShader *iface, SHADER_BUFFER *buffer);
Stefan Dösinger5ab52022008-03-18 19:39:26 +0100355 void (*shader_get_caps)(WINED3DDEVTYPE devtype, WineD3D_GL_Info *gl_info, struct shader_caps *caps);
Stefan Dösingerbfe70672008-08-07 14:51:35 -0500356 BOOL (*shader_conv_supported)(WINED3DFORMAT conv);
H. Verbeetdf6f4822006-11-27 20:50:37 +0100357} shader_backend_t;
358
359extern const shader_backend_t glsl_shader_backend;
360extern const shader_backend_t arb_program_shader_backend;
361extern const shader_backend_t none_shader_backend;
362
Jason Edmeadesc3421ea2004-09-29 21:26:47 +0000363/* X11 locking */
364
365extern void (*wine_tsx11_lock_ptr)(void);
366extern void (*wine_tsx11_unlock_ptr)(void);
367
368/* As GLX relies on X, this is needed */
369extern int num_lock;
370
371#if 0
372#define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
373#define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
374#else
375#define ENTER_GL() wine_tsx11_lock_ptr()
376#define LEAVE_GL() wine_tsx11_unlock_ptr()
377#endif
378
379/*****************************************************************************
380 * Defines
381 */
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000382
383/* GL related defines */
384/* ------------------ */
Jason Edmeadeseba27af2004-11-28 15:04:41 +0000385#define GL_SUPPORT(ExtName) (GLINFO_LOCATION.supported[ExtName] != 0)
386#define GL_LIMITS(ExtName) (GLINFO_LOCATION.max_##ExtName)
Jason Edmeadesf738c142004-12-09 11:42:34 +0000387#define GL_EXTCALL(FuncName) (GLINFO_LOCATION.FuncName)
Oliver Stieber2c0e97e2005-08-17 11:34:03 +0000388#define GL_VEND(_VendName) (GLINFO_LOCATION.gl_vendor == VENDOR_##_VendName ? TRUE : FALSE)
Jason Edmeadesb5198932004-10-06 00:05:29 +0000389
Raphael Junqueira705aec52005-11-15 12:03:13 +0000390#define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
391#define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xFF)
392#define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xFF)
393#define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
394
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000395#define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
396#define D3DCOLOR_G(dw) (((float) (((dw) >> 8) & 0xFF)) / 255.0f)
397#define D3DCOLOR_B(dw) (((float) (((dw) >> 0) & 0xFF)) / 255.0f)
398#define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
399
400#define D3DCOLORTOGLFLOAT4(dw, vec) \
401 (vec)[0] = D3DCOLOR_R(dw); \
402 (vec)[1] = D3DCOLOR_G(dw); \
403 (vec)[2] = D3DCOLOR_B(dw); \
404 (vec)[3] = D3DCOLOR_A(dw);
Roderick Colenbrander54e5f9c2006-05-25 13:54:03 +0200405
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000406/* DirectX Device Limits */
407/* --------------------- */
Jason Edmeadesbcecddc2005-01-17 13:44:57 +0000408#define MAX_LEVELS 256 /* Maximum number of mipmap levels. Guessed at 256 */
409
Jason Edmeadesb5198932004-10-06 00:05:29 +0000410#define MAX_STREAMS 16 /* Maximum possible streams - used for fixed size arrays
411 See MaxStreams in MSDN under GetDeviceCaps */
Oliver Stieber7b261652005-03-03 13:57:15 +0000412 /* Maximum number of constants provided to the shaders */
Jason Edmeadeseba27af2004-11-28 15:04:41 +0000413#define HIGHEST_TRANSFORMSTATE 512
Ivan Gyurdievec782c22006-10-12 02:21:00 -0400414 /* Highest value in WINED3DTRANSFORMSTATETYPE */
Jason Edmeades41427852005-01-09 17:37:02 +0000415
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000416/* Checking of API calls */
417/* --------------------- */
Ivan Gyurdiev634698c2006-04-10 00:39:07 -0400418#define checkGLcall(A) \
419{ \
420 GLint err = glGetError(); \
421 if (err == GL_NO_ERROR) { \
422 TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__); \
423 \
424 } else do { \
H. Verbeetb643ab32007-04-23 22:02:50 +0200425 FIXME(">>>>>>>>>>>>>>>>> %s (%#x) from %s @ %s / %d\n", \
426 debug_glerror(err), err, A, __FILE__, __LINE__); \
Ivan Gyurdiev634698c2006-04-10 00:39:07 -0400427 err = glGetError(); \
428 } while (err != GL_NO_ERROR); \
429}
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000430
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000431/* Trace routines / diagnostics */
432/* ---------------------------- */
433
434/* Dump out a matrix and copy it */
Jason Edmeadeseba27af2004-11-28 15:04:41 +0000435#define conv_mat(mat,gl_mat) \
436do { \
437 TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
438 TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
439 TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
440 TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
441 memcpy(gl_mat, (mat), 16 * sizeof(float)); \
442} while (0)
443
Jason Edmeades0a944ae2004-11-29 17:53:42 +0000444/* Macro to dump out the current state of the light chain */
445#define DUMP_LIGHT_CHAIN() \
446{ \
447 PLIGHTINFOEL *el = This->stateBlock->lights;\
448 while (el) { \
449 TRACE("Light %p (glIndex %ld, d3dIndex %ld, enabled %d)\n", el, el->glIndex, el->OriginalIndex, el->lightEnabled);\
450 el = el->next; \
451 } \
452}
453
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000454/* Trace vector and strided data information */
Jason Edmeadesf738c142004-12-09 11:42:34 +0000455#define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
H. Verbeetd7596082007-05-09 19:08:37 +0200456#define TRACE_STRIDED(sd,name) TRACE( #name "=(data:%p, stride:%d, type:%d, vbo %d, stream %u)\n", \
457 sd->u.s.name.lpData, sd->u.s.name.dwStride, sd->u.s.name.dwType, sd->u.s.name.VBO, sd->u.s.name.streamNo);
Jason Edmeadesf738c142004-12-09 11:42:34 +0000458
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000459/* Defines used for optimizations */
460
461/* Only reapply what is necessary */
462#define REAPPLY_ALPHAOP 0x0001
463#define REAPPLY_ALL 0xFFFF
464
465/* Advance declaration of structures to satisfy compiler */
Jason Edmeades447d5ed2004-10-21 20:59:12 +0000466typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
Jason Edmeades41427852005-01-09 17:37:02 +0000467typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
Stefan Dösingercff4e1e2006-04-17 17:04:59 +0200468typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl;
Stefan Dösingerc1623d42007-02-12 19:18:36 +0100469typedef struct IWineD3DDeviceImpl IWineD3DDeviceImpl;
Jason Edmeades447d5ed2004-10-21 20:59:12 +0000470
Jason Edmeades2003c7a2004-12-13 13:35:38 +0000471/* Global variables */
Jason Edmeadeseba27af2004-11-28 15:04:41 +0000472extern const float identity[16];
473
Jason Edmeades24ab49e2004-09-23 04:34:27 +0000474/*****************************************************************************
Jason Edmeadesf738c142004-12-09 11:42:34 +0000475 * Compilable extra diagnostics
476 */
477
478/* Trace information per-vertex: (extremely high amount of trace) */
479#if 0 /* NOTE: Must be 0 in cvs */
480# define VTRACE(A) TRACE A
481#else
482# define VTRACE(A)
483#endif
484
485/* Checking of per-vertex related GL calls */
Ivan Gyurdiev634698c2006-04-10 00:39:07 -0400486/* --------------------- */
487#define vcheckGLcall(A) \
488{ \
489 GLint err = glGetError(); \
490 if (err == GL_NO_ERROR) { \
Jason Edmeadesf738c142004-12-09 11:42:34 +0000491 VTRACE(("%s call ok %s / %d\n", A, __FILE__, __LINE__)); \
Ivan Gyurdiev634698c2006-04-10 00:39:07 -0400492 \
493 } else do { \
H. Verbeetb643ab32007-04-23 22:02:50 +0200494 FIXME(">>>>>>>>>>>>>>>>> %s (%#x) from %s @ %s / %d\n", \
495 debug_glerror(err), err, A, __FILE__, __LINE__); \
Ivan Gyurdiev634698c2006-04-10 00:39:07 -0400496 err = glGetError(); \
497 } while (err != GL_NO_ERROR); \
Jason Edmeadesf738c142004-12-09 11:42:34 +0000498}
499
Jason Edmeadesc4de9522004-12-14 11:54:27 +0000500/* TODO: Confirm each of these works when wined3d move completed */
501#if 0 /* NOTE: Must be 0 in cvs */
502 /* 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 +0200503 of each frame, a check is made for the existence of C:\D3DTRACE, and if it exists d3d trace
504 is enabled, and if it doesn't exist it is disabled. */
Jason Edmeadesc4de9522004-12-14 11:54:27 +0000505# define FRAME_DEBUGGING
506 /* Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
507 the file is deleted */
508# if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
509# define SINGLE_FRAME_DEBUGGING
510# endif
511 /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
512 It can only be enabled when FRAME_DEBUGGING is also enabled
513 The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
514 array is drawn. */
515# if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
516# define SHOW_FRAME_MAKEUP 1
517# endif
518 /* The following, when enabled, lets you see the makeup of the all the textures used during each
519 of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
520 The contents of the textures assigned to each stage are written into
521 /tmp/texture_*_<Stage>.ppm after each primitive array is drawn. */
522# if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
523# define SHOW_TEXTURE_MAKEUP 0
524# endif
525extern BOOL isOn;
526extern BOOL isDumpingFrames;
527extern LONG primCounter;
528#endif
529
Jason Edmeadesf738c142004-12-09 11:42:34 +0000530/*****************************************************************************
531 * Prototypes
532 */
533
534/* Routine common to the draw primitive and draw indexed primitive routines */
535void drawPrimitive(IWineD3DDevice *iface,
536 int PrimitiveType,
537 long NumPrimitives,
Jason Edmeadesf738c142004-12-09 11:42:34 +0000538 /* for Indexed: */
539 long StartVertexIndex,
Oliver Stieber1be54d82005-08-19 10:05:00 +0000540 UINT numberOfVertices,
Jason Edmeadesf738c142004-12-09 11:42:34 +0000541 long StartIdx,
542 short idxBytes,
543 const void *idxData,
Stefan Dösinger04ce1412007-01-02 21:13:28 +0100544 int minIndex);
Jason Edmeadesf738c142004-12-09 11:42:34 +0000545
Stefan Dösinger7d31ab92006-06-21 15:01:38 +0200546void primitiveDeclarationConvertToStridedData(
547 IWineD3DDevice *iface,
548 BOOL useVertexShaderFunction,
549 WineDirect3DVertexStridedData *strided,
Stefan Dösinger7d31ab92006-06-21 15:01:38 +0200550 BOOL *fixup);
551
Stefan Dösinger9abdac62006-05-12 22:21:31 +0200552DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
553
Stefan Dösinger61a900f2008-08-15 18:04:20 +0200554typedef void (WINE_GLAPI *glAttribFunc)(void *data);
Henri Verbeet3a7fcec2008-09-24 15:56:48 +0200555typedef void (WINE_GLAPI *glMultiTexCoordFunc)(GLenum unit, void *data);
Stefan Dösinger2d904492007-12-19 17:10:02 +0100556extern glAttribFunc position_funcs[WINED3DDECLTYPE_UNUSED];
557extern glAttribFunc diffuse_funcs[WINED3DDECLTYPE_UNUSED];
558extern glAttribFunc specular_funcs[WINED3DDECLTYPE_UNUSED];
559extern glAttribFunc normal_funcs[WINED3DDECLTYPE_UNUSED];
Henri Verbeet3a7fcec2008-09-24 15:56:48 +0200560extern glMultiTexCoordFunc multi_texcoord_funcs[WINED3DDECLTYPE_UNUSED];
561extern glAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED];
Stefan Dösinger2d904492007-12-19 17:10:02 +0100562
Stefan Dösinger10ff0d82006-05-09 18:16:13 +0200563#define eps 1e-8
564
Stefan Dösinger9abdac62006-05-12 22:21:31 +0200565#define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
566 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
567
Stefan Dösingerc0268c72006-12-05 23:36:10 +0100568/* Routines and structures related to state management */
Stefan Dösinger380930d2007-02-12 19:18:31 +0100569typedef struct WineD3DContext WineD3DContext;
Stefan Dösingerc739c382007-02-12 19:18:22 +0100570typedef void (*APPLYSTATEFUNC)(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *ctx);
Stefan Dösingerc0268c72006-12-05 23:36:10 +0100571
Stefan Dösinger2a24e842006-12-06 13:22:12 +0100572#define STATE_RENDER(a) (a)
573#define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
574
Stefan Dösinger569a2fa2006-12-19 22:43:49 +0100575#define STATE_TEXTURESTAGE(stage, num) (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + (stage) * WINED3D_HIGHEST_TEXTURE_STATE + (num))
576#define STATE_IS_TEXTURESTAGE(a) ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
577
Stefan Dösinger2d1aeb42006-12-19 23:14:07 +0100578/* + 1 because samplers start with 0 */
579#define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
H. Verbeet5b7758f2007-06-25 22:45:40 +0200580#define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1))
Stefan Dösinger2d1aeb42006-12-19 23:14:07 +0100581
H. Verbeet5b7758f2007-06-25 22:45:40 +0200582#define STATE_PIXELSHADER (STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1) + 1)
Stefan Dösinger22e2a5a2006-12-19 23:22:19 +0100583#define STATE_IS_PIXELSHADER(a) ((a) == STATE_PIXELSHADER)
584
Stefan Dösingerb58715e2006-12-28 18:57:16 +0100585#define STATE_TRANSFORM(a) (STATE_PIXELSHADER + (a))
586#define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)))
587
Stefan Dösingeref1ebb62007-01-02 00:35:07 +0100588#define STATE_STREAMSRC (STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(255)) + 1)
589#define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
Stefan Dösinger59ae2a52007-02-19 15:25:32 +0100590#define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
591#define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
Stefan Dösingeref1ebb62007-01-02 00:35:07 +0100592
Stefan Dösinger59ae2a52007-02-19 15:25:32 +0100593#define STATE_VDECL (STATE_INDEXBUFFER + 1)
Stefan Dösingeref1ebb62007-01-02 00:35:07 +0100594#define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
595
596#define STATE_VSHADER (STATE_VDECL + 1)
597#define STATE_IS_VSHADER(a) ((a) == STATE_VSHADER)
598
Stefan Dösingera48bbc32007-01-02 21:40:59 +0100599#define STATE_VIEWPORT (STATE_VSHADER + 1)
600#define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
601
Stefan Dösinger8e37fcd2007-01-06 18:17:27 +0100602#define STATE_VERTEXSHADERCONSTANT (STATE_VIEWPORT + 1)
603#define STATE_PIXELSHADERCONSTANT (STATE_VERTEXSHADERCONSTANT + 1)
604#define STATE_IS_VERTEXSHADERCONSTANT(a) ((a) == STATE_VERTEXSHADERCONSTANT)
605#define STATE_IS_PIXELSHADERCONSTANT(a) ((a) == STATE_PIXELSHADERCONSTANT)
606
Stefan Dösinger174b6322007-02-14 17:48:52 +0100607#define STATE_ACTIVELIGHT(a) (STATE_PIXELSHADERCONSTANT + (a) + 1)
H. Verbeetcb4c9b62007-07-15 23:46:06 +0200608#define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS))
Stefan Dösinger174b6322007-02-14 17:48:52 +0100609
Stefan Dösingerecfd4cb2007-02-19 15:25:16 +0100610#define STATE_SCISSORRECT (STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS - 1) + 1)
611#define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
612
Stefan Dösinger409aa732007-02-28 14:36:36 +0100613#define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
614#define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(MAX_CLIPPLANES - 1))
615
Stefan Dösinger2f4b9e42007-06-15 21:33:54 +0200616#define STATE_MATERIAL (STATE_CLIPPLANE(MAX_CLIPPLANES))
617
Stefan Dösinger5a63b792007-09-18 11:43:09 +0200618#define STATE_FRONTFACE (STATE_MATERIAL + 1)
619
620#define STATE_HIGHEST (STATE_FRONTFACE)
Stefan Dösinger7532c752006-12-19 13:00:03 +0100621
Stefan Dösingerc0268c72006-12-05 23:36:10 +0100622struct StateEntry
623{
Stefan Dösinger68dec9d2008-07-01 19:43:52 -0500624 DWORD representative;
625 APPLYSTATEFUNC apply;
Stefan Dösingerc0268c72006-12-05 23:36:10 +0100626};
627
Stefan Dösinger68dec9d2008-07-01 19:43:52 -0500628struct StateEntryTemplate
629{
630 DWORD state;
631 struct StateEntry content;
Stefan Dösinger35f33ef2008-07-05 15:04:16 -0500632 GL_SupportedExt extension;
Stefan Dösinger68dec9d2008-07-01 19:43:52 -0500633};
634
Stefan Dösingere4078fb2008-07-03 14:36:18 -0500635struct fragment_caps {
636 DWORD PrimitiveMiscCaps;
637
638 DWORD TextureOpCaps;
639 DWORD MaxTextureBlendStages;
640 DWORD MaxSimultaneousTextures;
641};
642
Stefan Dösingerc48195e2008-07-04 15:09:49 -0500643struct fragment_pipeline {
644 void (*enable_extension)(IWineD3DDevice *iface, BOOL enable);
Stefan Dösingere4078fb2008-07-03 14:36:18 -0500645 void (*get_caps)(WINED3DDEVTYPE devtype, WineD3D_GL_Info *gl_info, struct fragment_caps *caps);
Stefan Dösingere7733ea2008-07-11 09:41:28 -0500646 HRESULT (*alloc_private)(IWineD3DDevice *iface);
647 void (*free_private)(IWineD3DDevice *iface);
Stefan Dösingerbfe70672008-08-07 14:51:35 -0500648 BOOL (*conv_supported)(WINED3DFORMAT conv);
Stefan Dösingerc48195e2008-07-04 15:09:49 -0500649 const struct StateEntryTemplate *states;
Stefan Dösingeraf8d2682008-08-23 15:41:51 -0500650 BOOL ffp_proj_control;
Stefan Dösingerc48195e2008-07-04 15:09:49 -0500651};
652
Stefan Dösinger68dec9d2008-07-01 19:43:52 -0500653extern const struct StateEntryTemplate misc_state_template[];
Stefan Dösinger141f31f2008-07-02 10:02:19 -0500654extern const struct StateEntryTemplate ffp_vertexstate_template[];
Stefan Dösingerc48195e2008-07-04 15:09:49 -0500655extern const struct fragment_pipeline ffp_fragment_pipeline;
656extern const struct fragment_pipeline atifs_fragment_pipeline;
Stefan Dösinger14b24052008-07-28 11:41:02 -0500657extern const struct fragment_pipeline arbfp_fragment_pipeline;
Stefan Dösinger86b033b2008-07-04 16:15:18 -0500658extern const struct fragment_pipeline nvts_fragment_pipeline;
659extern const struct fragment_pipeline nvrc_fragment_pipeline;
660
Stefan Dösinger84258722008-03-09 19:30:08 +0100661/* "Base" state table */
Stefan Dösinger68dec9d2008-07-01 19:43:52 -0500662void compile_state_table(struct StateEntry *StateTable,
663 APPLYSTATEFUNC **dev_multistate_funcs,
Stefan Dösinger35f33ef2008-07-05 15:04:16 -0500664 WineD3D_GL_Info *gl_info,
Stefan Dösinger68dec9d2008-07-01 19:43:52 -0500665 const struct StateEntryTemplate *vertex,
Stefan Dösingerc48195e2008-07-04 15:09:49 -0500666 const struct fragment_pipeline *fragment,
Stefan Dösinger3a2743f2008-07-02 14:56:38 -0500667 const struct StateEntryTemplate *misc);
Stefan Dösingerc0268c72006-12-05 23:36:10 +0100668
Stefan Dösingerfc6b9772008-08-01 13:21:10 -0500669/* Shaders for color conversions in blits */
670struct blit_shader {
671 HRESULT (*alloc_private)(IWineD3DDevice *iface);
672 void (*free_private)(IWineD3DDevice *iface);
673 HRESULT (*set_shader)(IWineD3DDevice *iface, WINED3DFORMAT fmt, GLenum textype, UINT width, UINT height);
674 void (*unset_shader)(IWineD3DDevice *iface);
Stefan Dösingerbfe70672008-08-07 14:51:35 -0500675 BOOL (*conv_supported)(WINED3DFORMAT conv);
Stefan Dösingerfc6b9772008-08-01 13:21:10 -0500676};
677
678extern const struct blit_shader ffp_blit;
Stefan Dösinger1f4cf352008-08-19 11:09:45 -0500679extern const struct blit_shader arbfp_blit;
Stefan Dösingerfc6b9772008-08-01 13:21:10 -0500680
Stefan Dösinger380930d2007-02-12 19:18:31 +0100681/* The new context manager that should deal with onscreen and offscreen rendering */
682struct WineD3DContext {
683 /* State dirtification
684 * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices
685 * 0...numDirtyEntries - 1. isStateDirty is a redundant copy of the dirtyArray. Technically only one of them would be needed,
686 * 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
687 * only numDirtyEntries array elements have to be checked, not STATE_HIGHEST states.
688 */
689 DWORD dirtyArray[STATE_HIGHEST + 1]; /* Won't get bigger than that, a state is never marked dirty 2 times */
690 DWORD numDirtyEntries;
691 DWORD isStateDirty[STATE_HIGHEST/32 + 1]; /* Bitmap to find out quickly if a state is dirty */
692
Stefan Dösinger12252d02007-02-12 19:21:10 +0100693 IWineD3DSurface *surface;
Stefan Dösinger90fe64c2007-03-04 17:31:06 +0100694 DWORD tid; /* Thread ID which owns this context at the moment */
Stefan Dösinger380930d2007-02-12 19:18:31 +0100695
Austin English3471f842008-01-09 13:37:05 -0600696 /* Stores some information about the context state for optimization */
H. Verbeetf037eb82008-08-03 21:17:51 +0200697 BOOL draw_buffer_dirty;
Stefan Dösinger380930d2007-02-12 19:18:31 +0100698 BOOL last_was_rhw; /* true iff last draw_primitive was in xyzrhw mode */
699 BOOL last_was_pshader;
700 BOOL last_was_vshader;
701 BOOL last_was_foggy_shader;
702 BOOL namedArraysLoaded, numberedArraysLoaded;
703 BOOL lastWasPow2Texture[MAX_TEXTURES];
704 GLenum tracking_parm; /* Which source is tracking current colour */
Stefan Dösingerb081cba2007-06-20 14:36:32 +0200705 unsigned char num_untracked_materials;
706 GLenum untracked_materials[2];
Stefan Dösingerb3f96f42007-02-15 03:04:18 +0100707 BOOL last_was_blit, last_was_ckey;
Stefan Dösinger74c56842008-06-17 01:41:49 +0200708 UINT blit_w, blit_h;
Stefan Dösinger81504d62007-05-07 21:08:14 +0200709 char texShaderBumpMap;
Stefan Dösinger98bc83b2007-08-14 02:31:10 +0200710 BOOL fog_coord;
Stefan Dösinger12252d02007-02-12 19:21:10 +0100711
Stefan Dösinger107e80a2008-03-04 02:30:23 +0100712 char *vshader_const_dirty, *pshader_const_dirty;
713
Stefan Dösinger12252d02007-02-12 19:21:10 +0100714 /* The actual opengl context */
Roderick Colenbranderac3927a2007-08-08 03:09:38 +0200715 HGLRC glCtx;
716 HWND win_handle;
717 HDC hdc;
718 HPBUFFERARB pbuffer;
Stefan Dösingerf5f501d2007-02-12 19:22:41 +0100719 BOOL isPBuffer;
Stefan Dösinger67e09432008-04-08 14:20:27 +0200720 GLint aux_buffers;
H. Verbeet05931f42008-08-21 18:34:55 +0200721
722 /* FBOs */
Henri Verbeet45820042008-09-18 14:57:53 +0200723 struct list fbo_list;
724 struct fbo_entry *current_fbo;
H. Verbeet05931f42008-08-21 18:34:55 +0200725 GLuint src_fbo;
726 GLuint dst_fbo;
Stefan Dösinger380930d2007-02-12 19:18:31 +0100727};
728
Stefan Dösingerc1623d42007-02-12 19:18:36 +0100729typedef enum ContextUsage {
730 CTXUSAGE_RESOURCELOAD = 1, /* Only loads textures: No State is applied */
Austin English3471f842008-01-09 13:37:05 -0600731 CTXUSAGE_DRAWPRIM = 2, /* OpenGL states are set up for blitting DirectDraw surfaces */
Stefan Dösingerc1623d42007-02-12 19:18:36 +0100732 CTXUSAGE_BLIT = 3, /* OpenGL states are set up 3D drawing */
Stefan Dösingerfdadf262007-07-09 16:57:58 +0200733 CTXUSAGE_CLEAR = 4, /* Drawable and states are set up for clearing */
Stefan Dösingerc1623d42007-02-12 19:18:36 +0100734} ContextUsage;
735
736void ActivateContext(IWineD3DDeviceImpl *device, IWineD3DSurface *target, ContextUsage usage);
Roderick Colenbrander57547262007-08-11 12:17:56 +0200737WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, HWND win, BOOL create_pbuffer, const WINED3DPRESENT_PARAMETERS *pPresentParms);
Stefan Dösinger12252d02007-02-12 19:21:10 +0100738void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context);
Henri Verbeet76de76e2008-09-18 14:57:53 +0200739void context_resource_released(IWineD3DDevice *iface, IWineD3DResource *resource, WINED3DRESOURCETYPE type);
Henri Verbeeta2692362008-09-18 14:57:53 +0200740void context_bind_fbo(IWineD3DDevice *iface, GLenum target, GLuint *fbo);
741void context_attach_depth_stencil_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer);
742void context_attach_surface_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, DWORD idx, IWineD3DSurface *surface);
Stefan Dösingerc1623d42007-02-12 19:18:36 +0100743
Stefan Dösinger7f2b8f92008-07-29 12:09:34 -0500744void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain);
745HRESULT create_primary_opengl_context(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain);
746
Roderick Colenbranderde97fa72006-08-19 11:58:23 +0200747/* Macros for doing basic GPU detection based on opengl capabilities */
748#define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
749#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])
750#define WINE_D3D8_CAPABLE(gl_info) WINE_D3D7_CAPABLE(gl_info) && (gl_info->supported[ARB_MULTISAMPLE] && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
751#define WINE_D3D9_CAPABLE(gl_info) WINE_D3D8_CAPABLE(gl_info) && (gl_info->supported[ARB_FRAGMENT_PROGRAM] && gl_info->supported[ARB_VERTEX_SHADER])
752
Markus Amsler04ae4592006-12-05 00:28:58 +0100753/* Default callbacks for implicit object destruction */
754extern ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface);
755
Markus Amsler50a0c212006-12-05 00:29:21 +0100756extern ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pSurface);
757
Jason Edmeadesf738c142004-12-09 11:42:34 +0000758/*****************************************************************************
Jason Edmeades0a944ae2004-11-29 17:53:42 +0000759 * Internal representation of a light
760 */
761typedef struct PLIGHTINFOEL PLIGHTINFOEL;
762struct PLIGHTINFOEL {
763 WINED3DLIGHT OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
764 DWORD OriginalIndex;
765 LONG glIndex;
Jason Edmeades0a944ae2004-11-29 17:53:42 +0000766 BOOL changed;
767 BOOL enabledChanged;
Stefan Dösinger3cc253c2007-11-29 13:22:47 +0100768 BOOL enabled;
Jason Edmeades0a944ae2004-11-29 17:53:42 +0000769
770 /* Converted parms to speed up swapping lights */
771 float lightPosn[4];
772 float lightDirn[4];
773 float exponent;
774 float cutoff;
775
Stefan Dösingeracadf3f2007-02-14 17:46:54 +0100776 struct list entry;
Jason Edmeades0a944ae2004-11-29 17:53:42 +0000777};
778
Ivan Gyurdiev4d666152006-06-06 23:37:05 -0400779/* The default light parameters */
780extern const WINED3DLIGHT WINED3D_default_light;
781
Roderick Colenbranderd391c112007-08-11 16:25:58 +0200782typedef struct WineD3D_PixelFormat
783{
784 int iPixelFormat; /* WGL pixel format */
Roderick Colenbrander51a81622008-03-21 14:52:15 +0100785 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 +0200786 int redSize, greenSize, blueSize, alphaSize;
787 int depthSize, stencilSize;
Roderick Colenbranderd44c2952008-03-16 16:37:38 +0000788 BOOL windowDrawable;
789 BOOL pbufferDrawable;
Roderick Colenbrander31dc00a2008-04-27 17:36:34 +0000790 BOOL doubleBuffer;
791 int auxBuffers;
Roderick Colenbrander628e4ee2008-04-28 21:44:21 +0000792 int numSamples;
Roderick Colenbranderd391c112007-08-11 16:25:58 +0200793} WineD3D_PixelFormat;
794
Stefan Dösingera460a2d2007-06-09 14:27:41 +0200795/* The adapter structure */
796struct WineD3DAdapter
797{
Stefan Dösinger7f10ee42007-12-06 23:43:25 +0100798 UINT num;
Stefan Dösinger9e831a82008-03-28 23:04:17 +0100799 BOOL opengl;
Stefan Dösingera460a2d2007-06-09 14:27:41 +0200800 POINT monitorPoint;
Stefan Dösingera460a2d2007-06-09 14:27:41 +0200801 WineD3D_GL_Info gl_info;
Stefan Dösinger66930552007-06-08 15:23:04 +0200802 const char *driver;
803 const char *description;
Roderick Colenbrander6b177c42007-08-13 16:47:17 +0200804 WCHAR DeviceName[CCHDEVICENAME]; /* DeviceName for use with e.g. ChangeDisplaySettings */
Stefan Dösingerefbdd512007-06-08 14:16:37 +0200805 int nCfgs;
Roderick Colenbranderd391c112007-08-11 16:25:58 +0200806 WineD3D_PixelFormat *cfgs;
Roderick Colenbrander7b5561c2008-05-03 14:37:09 +0000807 BOOL brokenStencil; /* Set on cards which only offer mixed depth+stencil */
Roderick Colenbrander243ac3e2007-09-23 00:46:21 +0200808 unsigned int TextureRam; /* Amount of texture memory both video ram + AGP/TurboCache/HyperMemory/.. */
809 unsigned int UsedTextureRam;
Stefan Dösingera460a2d2007-06-09 14:27:41 +0200810};
811
812extern BOOL InitAdapters(void);
Stefan Dösingerd2016ff2007-07-27 13:22:54 +0200813extern BOOL initPixelFormats(WineD3D_GL_Info *gl_info);
Roderick Colenbrander243ac3e2007-09-23 00:46:21 +0200814extern long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram);
Stefan Dösingera460a2d2007-06-09 14:27:41 +0200815
Jason Edmeades0a944ae2004-11-29 17:53:42 +0000816/*****************************************************************************
Stefan Dösinger26ebe392007-07-04 17:57:45 +0200817 * High order patch management
818 */
819struct WineD3DRectPatch
820{
821 UINT Handle;
822 float *mem;
823 WineDirect3DVertexStridedData strided;
824 WINED3DRECTPATCH_INFO RectPatchInfo;
825 float numSegs[4];
826 char has_normals, has_texcoords;
827 struct list entry;
828};
829
830HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This, struct WineD3DRectPatch *patch);
831
Stefan Dösinger4640be82008-03-22 14:31:52 +0100832enum projection_types
833{
Stefan Dösingerd4d133f2008-07-30 10:57:32 -0500834 proj_none = 0,
835 proj_count3 = 1,
836 proj_count4 = 2
837};
838
Stefan Dösingerd4d133f2008-07-30 10:57:32 -0500839enum dst_arg
840{
841 resultreg = 0,
842 tempreg = 1
Stefan Dösinger4640be82008-03-22 14:31:52 +0100843};
844
845/*****************************************************************************
846 * Fixed function pipeline replacements
847 */
848struct texture_stage_op
849{
Stefan Dösingerd4d133f2008-07-30 10:57:32 -0500850 unsigned cop : 5, aop : 5;
Stefan Dösinger8fe6bf02008-08-05 14:50:56 -0500851#define ARG_UNUSED 0x3f
Stefan Dösingerd4d133f2008-07-30 10:57:32 -0500852 unsigned carg1 : 6, carg2 : 6, carg0 : 6;
853 unsigned tex_type : 3;
Stefan Dösinger228f2cf2008-08-01 11:47:24 -0500854 unsigned dst : 1; /* Total of 32 bits */
Stefan Dösingerd4d133f2008-07-30 10:57:32 -0500855 unsigned aarg1 : 6, aarg2 : 6, aarg0 : 6;
856 unsigned projected : 2;
Stefan Dösinger228f2cf2008-08-01 11:47:24 -0500857 unsigned padding : 12; /* Total of 64 bits */
Stefan Dösinger4640be82008-03-22 14:31:52 +0100858 WINED3DFORMAT color_correction;
Stefan Dösinger4640be82008-03-22 14:31:52 +0100859};
860
Stefan Dösinger5c79a9f2008-11-07 17:15:29 +0100861struct ffp_frag_settings {
Stefan Dösinger294f1b42008-07-11 21:18:06 -0500862 struct texture_stage_op op[MAX_TEXTURES];
863 enum {
864 FOG_OFF,
865 FOG_LINEAR,
866 FOG_EXP,
867 FOG_EXP2
868 } fog;
Stefan Dösinger421b6552008-09-04 15:51:21 -0500869 /* Use an int instead of a char to get dword alignment */
Henri Verbeet81effcf2008-09-04 15:32:36 +0200870 unsigned int sRGB_write;
Stefan Dösinger294f1b42008-07-11 21:18:06 -0500871};
872
Stefan Dösinger5c79a9f2008-11-07 17:15:29 +0100873struct ffp_frag_desc
Stefan Dösinger4640be82008-03-22 14:31:52 +0100874{
Stefan Dösinger5c79a9f2008-11-07 17:15:29 +0100875 struct ffp_frag_settings settings;
Stefan Dösinger4640be82008-03-22 14:31:52 +0100876};
877
Stefan Dösinger5c79a9f2008-11-07 17:15:29 +0100878void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_settings *settings, BOOL ignore_textype);
Henri Verbeeteb78c2a2008-11-25 14:36:08 +0100879const struct ffp_frag_desc *find_ffp_frag_shader(struct hash_table_t *fragment_shaders,
880 const struct ffp_frag_settings *settings);
Stefan Dösinger5c79a9f2008-11-07 17:15:29 +0100881void add_ffp_frag_shader(struct hash_table_t *shaders, struct ffp_frag_desc *desc);
Henri Verbeeteb78c2a2008-11-25 14:36:08 +0100882BOOL ffp_frag_program_key_compare(const void *keya, const void *keyb);
883unsigned int ffp_frag_program_key_hash(const void *key);
Stefan Dösinger4640be82008-03-22 14:31:52 +0100884
Stefan Dösinger26ebe392007-07-04 17:57:45 +0200885/*****************************************************************************
Jason Edmeades24ab49e2004-09-23 04:34:27 +0000886 * IWineD3D implementation structure
887 */
888typedef struct IWineD3DImpl
889{
890 /* IUnknown fields */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +0000891 const IWineD3DVtbl *lpVtbl;
Mike McCormack8955ac42005-07-28 10:16:21 +0000892 LONG ref; /* Note: Ref counting not required */
Jason Edmeades24ab49e2004-09-23 04:34:27 +0000893
894 /* WineD3D Information */
Jason Edmeades289562e2004-11-23 13:52:46 +0000895 IUnknown *parent;
Jason Edmeades24ab49e2004-09-23 04:34:27 +0000896 UINT dxVersion;
897} IWineD3DImpl;
898
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +0000899extern const IWineD3DVtbl IWineD3D_Vtbl;
Jason Edmeades24ab49e2004-09-23 04:34:27 +0000900
Francois Gouget93494f22007-02-20 15:57:10 +0100901/* TODO: setup some flags in the registry to enable, disable pbuffer support
Oliver Stieber94856322005-07-19 11:39:24 +0000902(since it will break quite a few things until contexts are managed properly!) */
903extern BOOL pbuffer_support;
904/* allocate one pbuffer per surface */
905extern BOOL pbuffer_per_surface;
906
Stefan Dösingere0c87732006-04-10 19:39:53 +0200907/* A helper function that dumps a resource list */
Stefan Dösinger1fc1fe32007-11-16 20:28:45 +0100908void dumpResources(struct list *list);
Stefan Dösingere0c87732006-04-10 19:39:53 +0200909
Jason Edmeadesac490fa2004-10-07 04:22:21 +0000910/*****************************************************************************
911 * IWineD3DDevice implementation structure
912 */
Stefan Dösingerc1623d42007-02-12 19:18:36 +0100913struct IWineD3DDeviceImpl
Jason Edmeadesac490fa2004-10-07 04:22:21 +0000914{
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000915 /* IUnknown fields */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +0000916 const IWineD3DDeviceVtbl *lpVtbl;
Mike McCormack8955ac42005-07-28 10:16:21 +0000917 LONG ref; /* Note: Ref counting not required */
Jason Edmeadesac490fa2004-10-07 04:22:21 +0000918
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000919 /* WineD3D Information */
Jason Edmeadesbcecddc2005-01-17 13:44:57 +0000920 IUnknown *parent;
Jason Edmeadeseba27af2004-11-28 15:04:41 +0000921 IWineD3D *wineD3D;
Stefan Dösingera460a2d2007-06-09 14:27:41 +0200922 struct WineD3DAdapter *adapter;
Jason Edmeadesac490fa2004-10-07 04:22:21 +0000923
H. Verbeet61125222007-01-18 23:41:36 +0100924 /* Window styles to restore when switching fullscreen mode */
925 LONG style;
926 LONG exStyle;
927
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000928 /* X and GL Information */
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000929 GLint maxConcurrentLights;
Stefan Dösinger8d9a5532007-02-27 21:32:15 +0100930 GLenum offscreenBuffer;
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000931
Ivan Gyurdieve020ece2006-10-07 23:25:01 -0400932 /* Selected capabilities */
933 int vs_selected_mode;
934 int ps_selected_mode;
H. Verbeet8a7f4272006-11-27 20:50:43 +0100935 const shader_backend_t *shader_backend;
Stefan Dösingerf912f182008-02-24 11:23:53 +0100936 void *shader_priv;
Stefan Dösingere7733ea2008-07-11 09:41:28 -0500937 void *fragment_priv;
Stefan Dösingerfc6b9772008-08-01 13:21:10 -0500938 void *blit_priv;
Stefan Dösinger98faed82008-07-01 18:23:44 -0500939 struct StateEntry StateTable[STATE_HIGHEST + 1];
Stefan Dösinger68dec9d2008-07-01 19:43:52 -0500940 /* Array of functions for states which are handled by more than one pipeline part */
941 APPLYSTATEFUNC *multistate_funcs[STATE_HIGHEST + 1];
Stefan Dösingerc48195e2008-07-04 15:09:49 -0500942 const struct fragment_pipeline *frag_pipe;
Stefan Dösingerfc6b9772008-08-01 13:21:10 -0500943 const struct blit_shader *blitter;
Ivan Gyurdieve020ece2006-10-07 23:25:01 -0400944
Stefan Dösinger462ddaa2008-08-21 13:23:38 -0500945 unsigned int max_ffp_textures, max_ffp_texture_stages;
Stefan Dösinger9a6bc682008-08-17 23:46:47 +0200946
Stefan Dösingere6c9a072007-02-12 19:18:27 +0100947 /* To store */
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000948 BOOL view_ident; /* true iff view matrix is identity */
Stefan Dösingerd7f94bf2006-08-21 18:28:05 +0200949 BOOL untransformed;
Stefan Dösingeradb9b132007-04-27 00:43:15 +0200950 BOOL vertexBlendUsed; /* To avoid needless setting of the blend matrices */
Stefan Dösinger399825c2008-08-02 18:06:01 -0500951#define DDRAW_PITCH_ALIGNMENT 8
952#define D3D8_PITCH_ALIGNMENT 4
Stefan Dösinger6e5a5d22007-06-08 22:28:04 +0200953 unsigned char surface_alignment; /* Line Alignment of surfaces */
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000954
Jason Edmeades447d5ed2004-10-21 20:59:12 +0000955 /* State block related */
956 BOOL isRecordingState;
957 IWineD3DStateBlockImpl *stateBlock;
958 IWineD3DStateBlockImpl *updateStateBlock;
Stefan Dösinger9f2e0fa2007-01-06 18:41:43 +0100959 BOOL isInDraw;
Jason Edmeades447d5ed2004-10-21 20:59:12 +0000960
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000961 /* Internal use fields */
Stefan Dösingerf6ed7042006-04-03 14:54:16 +0200962 WINED3DDEVICE_CREATION_PARAMETERS createParms;
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000963 UINT adapterNo;
Ivan Gyurdiev19c55342006-10-10 21:52:00 -0400964 WINED3DDEVTYPE devType;
Jason Edmeadesb9e2bed2004-10-08 20:52:33 +0000965
Stefan Dösingere902cd12006-05-24 11:34:30 +0200966 IWineD3DSwapChain **swapchains;
Roderick Colenbranderf3af04a2007-08-06 16:38:00 +0200967 UINT NumberOfSwapChains;
Oliver Stieber46e7c302005-06-23 11:05:24 +0000968
Stefan Dösinger1fc1fe32007-11-16 20:28:45 +0100969 struct list resources; /* a linked list to track resources created by the device */
Stefan Dösinger09bf3d52008-01-08 20:45:59 +0100970 struct list shaders; /* a linked list to track shaders (pixel and vertex) */
Stefan Dösinger107e80a2008-03-04 02:30:23 +0100971 unsigned int highest_dirty_ps_const, highest_dirty_vs_const;
Oliver Stieberea6189e2005-07-26 10:34:15 +0000972
Jason Edmeades41427852005-01-09 17:37:02 +0000973 /* Render Target Support */
H. Verbeet8355b1a2006-12-19 19:25:22 +0100974 IWineD3DSurface **render_targets;
Stefan Dösingere4f8a2d2007-11-10 00:19:19 +0100975 IWineD3DSurface *auto_depth_stencil_buffer;
Oliver Stieberba5eb142005-03-14 10:12:52 +0000976 IWineD3DSurface *stencilBufferTarget;
Jason Edmeades41427852005-01-09 17:37:02 +0000977
Stefan Dösinger12252d02007-02-12 19:21:10 +0100978 /* Caches to avoid unneeded context changes */
979 IWineD3DSurface *lastActiveRenderTarget;
980 IWineD3DSwapChain *lastActiveSwapChain;
981
Jason Edmeades41427852005-01-09 17:37:02 +0000982 /* palettes texture management */
Alexander Dorofeyev16597092008-03-27 00:23:04 +0200983 UINT NumberOfPalettes;
984 PALETTEENTRY **palettes;
Oliver Stieberba5eb142005-03-14 10:12:52 +0000985 UINT currentPalette;
Roderick Colenbrander134aa672007-10-11 23:11:37 +0200986 UINT paletteConversionShader;
Jason Edmeades41427852005-01-09 17:37:02 +0000987
Jason Edmeadesf738c142004-12-09 11:42:34 +0000988 /* For rendering to a texture using glCopyTexImage */
H. Verbeet9bf04ec2006-11-17 13:23:41 +0100989 BOOL render_offscreen;
H. Verbeet299c1e62006-12-19 19:25:35 +0100990 GLenum *draw_buffers;
Stefan Dösinger3d2aa7a2008-01-27 14:32:40 +0100991 GLuint depth_blt_texture;
H. Verbeete7d0ef72008-07-02 23:00:11 +0200992 GLuint depth_blt_rb;
993 UINT depth_blt_rb_w;
994 UINT depth_blt_rb_h;
Jason Edmeadesf738c142004-12-09 11:42:34 +0000995
Oliver Stieber2121f782005-03-02 12:16:10 +0000996 /* Cursor management */
997 BOOL bCursorVisible;
998 UINT xHotSpot;
999 UINT yHotSpot;
1000 UINT xScreenSpace;
1001 UINT yScreenSpace;
Stefan Dösinger65e5ed62006-07-27 17:39:03 +02001002 UINT cursorWidth, cursorHeight;
1003 GLuint cursorTexture;
Andrew Riedia9c2e152007-05-14 15:37:53 -07001004 BOOL haveHardwareCursor;
1005 HCURSOR hardwareCursor;
Oliver Stieber2121f782005-03-02 12:16:10 +00001006
Stefan Dösinger271fb002007-09-01 21:22:32 +02001007 /* The Wine logo surface */
1008 IWineD3DSurface *logo_surface;
1009
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001010 /* Textures for when no other textures are mapped */
Oliver Stieberabb11f32005-07-05 14:05:18 +00001011 UINT dummyTextureName[MAX_TEXTURES];
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001012
Oliver Stieber2121f782005-03-02 12:16:10 +00001013 /* Debug stream management */
1014 BOOL debug;
1015
Oliver Stieber329d0172005-09-21 10:55:03 +00001016 /* Device state management */
1017 HRESULT state;
Stefan Dösingerd04f0502006-04-18 22:38:30 +02001018 BOOL d3d_initialized;
Oliver Stieber329d0172005-09-21 10:55:03 +00001019
Stefan Dösinger67b1f4a2007-02-09 16:35:45 +01001020 /* A flag to check for proper BeginScene / EndScene call pairs */
1021 BOOL inScene;
Oliver Stieber1f2a9e22005-10-29 10:30:36 +00001022
1023 /* process vertex shaders using software or hardware */
1024 BOOL softwareVertexProcessing;
Stefan Dösinger04da3ce2006-04-18 23:39:52 +02001025
1026 /* DirectDraw stuff */
Stefan Dösinger566cdcf2006-05-18 22:42:22 +02001027 DWORD ddraw_width, ddraw_height;
1028 WINED3DFORMAT ddraw_format;
Stefan Dösinger04da3ce2006-04-18 23:39:52 +02001029
Stefan Dösinger96bce8d2006-09-23 19:09:06 +02001030 /* Final position fixup constant */
1031 float posFixup[4];
Stefan Dösinger7532c752006-12-19 13:00:03 +01001032
Stefan Dösingerdf97fd32006-12-19 23:33:34 +01001033 /* With register combiners we can skip junk texture stages */
H. Verbeet5b7758f2007-06-25 22:45:40 +02001034 DWORD texUnitMap[MAX_COMBINED_SAMPLERS];
1035 DWORD rev_tex_unit_map[MAX_COMBINED_SAMPLERS];
H. Verbeetb1579b32007-06-22 20:43:24 +02001036 BOOL fixed_function_usage_map[MAX_TEXTURES];
Stefan Dösingerdf97fd32006-12-19 23:33:34 +01001037
Stefan Dösinger091f9c22007-01-02 00:21:26 +01001038 /* Stream source management */
1039 WineDirect3DVertexStridedData strided_streams;
Stefan Dösinger04ce1412007-01-02 21:13:28 +01001040 WineDirect3DVertexStridedData *up_strided;
Stefan Dösingerd5f18e62007-01-06 18:11:21 +01001041 BOOL useDrawStridedSlow;
Stefan Dösinger0feddcc2007-02-14 17:56:29 +01001042 BOOL instancedDraw;
Stefan Dösinger091f9c22007-01-02 00:21:26 +01001043
Stefan Dösingerc739c382007-02-12 19:18:22 +01001044 /* Context management */
Stefan Dösinger12252d02007-02-12 19:21:10 +01001045 WineD3DContext **contexts; /* Dynamic array containing pointers to context structures */
Stefan Dösinger13f24c32007-06-02 20:20:17 +00001046 WineD3DContext *activeContext;
1047 DWORD lastThread;
1048 UINT numContexts;
Stefan Dösinger12252d02007-02-12 19:21:10 +01001049 WineD3DContext *pbufferContext; /* The context that has a pbuffer as drawable */
1050 DWORD pbufferWidth, pbufferHeight; /* Size of the buffer drawable */
Stefan Dösinger26ebe392007-07-04 17:57:45 +02001051
1052 /* High level patch management */
1053#define PATCHMAP_SIZE 43
1054#define PATCHMAP_HASHFUNC(x) ((x) % PATCHMAP_SIZE) /* Primitive and simple function */
1055 struct list patches[PATCHMAP_SIZE];
1056 struct WineD3DRectPatch *currentPatch;
Stefan Dösingerc1623d42007-02-12 19:18:36 +01001057};
Jason Edmeadesac490fa2004-10-07 04:22:21 +00001058
Stefan Dösinger107e80a2008-03-04 02:30:23 +01001059extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl, IWineD3DDevice_DirtyConst_Vtbl;
Jason Edmeadesac490fa2004-10-07 04:22:21 +00001060
Alexander Dorofeyevf5aaabd2007-12-19 23:32:11 -08001061HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, DWORD Count,
1062 CONST WINED3DRECT* pRects, DWORD Flags, WINED3DCOLOR Color,
1063 float Z, DWORD Stencil);
H. Verbeetb9d5c182007-06-12 23:08:22 +02001064void IWineD3DDeviceImpl_FindTexUnitMap(IWineD3DDeviceImpl *This);
Stefan Dösinger7532c752006-12-19 13:00:03 +01001065void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state);
Stefan Dösinger380930d2007-02-12 19:18:31 +01001066static inline BOOL isStateDirty(WineD3DContext *context, DWORD state) {
Stefan Dösinger7532c752006-12-19 13:00:03 +01001067 DWORD idx = state >> 5;
1068 BYTE shift = state & 0x1f;
Stefan Dösinger380930d2007-02-12 19:18:31 +01001069 return context->isStateDirty[idx] & (1 << shift);
Stefan Dösinger7532c752006-12-19 13:00:03 +01001070}
1071
Stefan Dösingerd08585e2007-05-07 20:46:24 +02001072/* Support for IWineD3DResource ::Set/Get/FreePrivateData. */
Oliver Stieberfe80b4e2005-07-15 09:54:57 +00001073typedef struct PrivateData
1074{
Stefan Dösingerd08585e2007-05-07 20:46:24 +02001075 struct list entry;
Oliver Stieberfe80b4e2005-07-15 09:54:57 +00001076
1077 GUID tag;
1078 DWORD flags; /* DDSPD_* */
1079 DWORD uniqueness_value;
1080
1081 union
1082 {
1083 LPVOID data;
1084 LPUNKNOWN object;
1085 } ptr;
1086
1087 DWORD size;
1088} PrivateData;
1089
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001090/*****************************************************************************
1091 * IWineD3DResource implementation structure
1092 */
1093typedef struct IWineD3DResourceClass
1094{
1095 /* IUnknown fields */
Mike McCormack8955ac42005-07-28 10:16:21 +00001096 LONG ref; /* Note: Ref counting not required */
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001097
1098 /* WineD3DResource Information */
Jason Edmeades289562e2004-11-23 13:52:46 +00001099 IUnknown *parent;
Stefan Dösinger913df5b2006-03-09 23:21:16 +01001100 WINED3DRESOURCETYPE resourceType;
Jason Edmeades41427852005-01-09 17:37:02 +00001101 IWineD3DDeviceImpl *wineD3DDevice;
Stefan Dösingerd75fd752006-03-28 14:20:47 +02001102 WINED3DPOOL pool;
Oliver Stieber67f2ad42005-03-29 19:01:00 +00001103 UINT size;
1104 DWORD usage;
1105 WINED3DFORMAT format;
Kjell Rune Skaaraased96dd72008-09-29 19:52:18 +02001106 DWORD priority;
Stefan Dösinger4d4fce72007-10-22 13:02:03 +02001107 BYTE *allocatedMemory; /* Pointer to the real data location */
1108 BYTE *heapMemory; /* Pointer to the HeapAlloced block of memory */
Stefan Dösingerd08585e2007-05-07 20:46:24 +02001109 struct list privateData;
Stefan Dösinger1fc1fe32007-11-16 20:28:45 +01001110 struct list resource_list_entry;
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001111
1112} IWineD3DResourceClass;
1113
1114typedef struct IWineD3DResourceImpl
1115{
1116 /* IUnknown & WineD3DResource Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001117 const IWineD3DResourceVtbl *lpVtbl;
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001118 IWineD3DResourceClass resource;
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001119} IWineD3DResourceImpl;
1120
Stefan Dösinger393ed4a2007-10-22 13:30:14 +02001121/* Tests show that the start address of resources is 32 byte aligned */
1122#define RESOURCE_ALIGNMENT 32
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001123
1124/*****************************************************************************
1125 * IWineD3DVertexBuffer implementation structure (extends IWineD3DResourceImpl)
1126 */
Stefan Dösinger6d575ec2007-12-21 03:55:31 +01001127enum vbo_conversion_type {
1128 CONV_NONE = 0,
1129 CONV_D3DCOLOR = 1,
1130 CONV_POSITIONT = 2,
1131 CONV_FLOAT16_2 = 3 /* Also handles FLOAT16_4 */
1132
1133 /* TODO: Add tests and support for FLOAT16_4 POSITIONT, D3DCOLOR position, other
1134 * fixed function semantics as D3DCOLOR or FLOAT16
1135 */
1136};
1137
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001138typedef struct IWineD3DVertexBufferImpl
1139{
1140 /* IUnknown & WineD3DResource Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001141 const IWineD3DVertexBufferVtbl *lpVtbl;
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001142 IWineD3DResourceClass resource;
1143
1144 /* WineD3DVertexBuffer specifics */
Oliver Stieber6a032492005-07-13 11:34:55 +00001145 DWORD fvf;
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001146
Stefan Dösinger7d31ab92006-06-21 15:01:38 +02001147 /* Vertex buffer object support */
1148 GLuint vbo;
1149 BYTE Flags;
Stefan Dösingere328e242007-01-12 19:01:59 +01001150 LONG bindCount;
Stefan Dösingerb5f925c2007-12-19 17:18:39 +01001151 LONG vbo_size;
1152 GLenum vbo_usage;
Stefan Dösinger7d31ab92006-06-21 15:01:38 +02001153
1154 UINT dirtystart, dirtyend;
Stefan Dösingercea41b02006-06-27 13:11:13 +02001155 LONG lockcount;
Stefan Dösinger7d31ab92006-06-21 15:01:38 +02001156
Stefan Dösinger674af502006-09-23 18:02:22 +02001157 LONG declChanges, draws;
Stefan Dösinger7d31ab92006-06-21 15:01:38 +02001158 /* Last description of the buffer */
Stefan Dösinger6d575ec2007-12-21 03:55:31 +01001159 DWORD stride; /* 0 if no conversion */
1160 enum vbo_conversion_type *conv_map; /* NULL if no conversion */
Stefan Dösingerb5f925c2007-12-19 17:18:39 +01001161
1162 /* Extra load offsets, for FLOAT16 conversion */
Stefan Dösinger6d575ec2007-12-21 03:55:31 +01001163 DWORD *conv_shift; /* NULL if no shifted conversion */
1164 DWORD conv_stride; /* 0 if no shifted conversion */
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001165} IWineD3DVertexBufferImpl;
1166
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001167extern const IWineD3DVertexBufferVtbl IWineD3DVertexBuffer_Vtbl;
Jason Edmeadesdb7a5052004-10-14 00:32:04 +00001168
Stefan Dösinger8c758a62008-02-15 20:02:07 +01001169#define VBFLAG_OPTIMIZED 0x01 /* Optimize has been called for the VB */
1170#define VBFLAG_DIRTY 0x02 /* Buffer data has been modified */
1171#define VBFLAG_HASDESC 0x04 /* A vertex description has been found */
1172#define VBFLAG_CREATEVBO 0x08 /* Attempt to create a VBO next PreLoad */
Oliver Stieber67f2ad42005-03-29 19:01:00 +00001173
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001174/*****************************************************************************
Jason Edmeades73e8baf2004-11-24 18:13:41 +00001175 * IWineD3DIndexBuffer implementation structure (extends IWineD3DResourceImpl)
1176 */
1177typedef struct IWineD3DIndexBufferImpl
1178{
1179 /* IUnknown & WineD3DResource Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001180 const IWineD3DIndexBufferVtbl *lpVtbl;
Jason Edmeades73e8baf2004-11-24 18:13:41 +00001181 IWineD3DResourceClass resource;
1182
Stefan Dösinger59ae2a52007-02-19 15:25:32 +01001183 GLuint vbo;
1184 UINT dirtystart, dirtyend;
1185 LONG lockcount;
1186
Jason Edmeades73e8baf2004-11-24 18:13:41 +00001187 /* WineD3DVertexBuffer specifics */
Jason Edmeades73e8baf2004-11-24 18:13:41 +00001188} IWineD3DIndexBufferImpl;
1189
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001190extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
Jason Edmeades73e8baf2004-11-24 18:13:41 +00001191
1192/*****************************************************************************
Oliver Stieberbb6f9b02005-08-03 11:00:28 +00001193 * IWineD3DBaseTexture D3D- > openGL state map lookups
1194 */
1195#define WINED3DFUNC_NOTSUPPORTED -2
1196#define WINED3DFUNC_UNIMPLEMENTED -1
1197
1198typedef enum winetexturestates {
1199 WINED3DTEXSTA_ADDRESSU = 0,
1200 WINED3DTEXSTA_ADDRESSV = 1,
1201 WINED3DTEXSTA_ADDRESSW = 2,
1202 WINED3DTEXSTA_BORDERCOLOR = 3,
1203 WINED3DTEXSTA_MAGFILTER = 4,
1204 WINED3DTEXSTA_MINFILTER = 5,
1205 WINED3DTEXSTA_MIPFILTER = 6,
1206 WINED3DTEXSTA_MAXMIPLEVEL = 7,
1207 WINED3DTEXSTA_MAXANISOTROPY = 8,
1208 WINED3DTEXSTA_SRGBTEXTURE = 9,
1209 WINED3DTEXSTA_ELEMENTINDEX = 10,
1210 WINED3DTEXSTA_DMAPOFFSET = 11,
1211 WINED3DTEXSTA_TSSADDRESSW = 12,
1212 MAX_WINETEXTURESTATES = 13,
1213} winetexturestates;
1214
Oliver Stieberbb6f9b02005-08-03 11:00:28 +00001215/*****************************************************************************
Jason Edmeades819b0e12004-12-07 14:29:12 +00001216 * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
1217 */
1218typedef struct IWineD3DBaseTextureClass
1219{
1220 UINT levels;
Jason Edmeades41427852005-01-09 17:37:02 +00001221 BOOL dirty;
Oliver Stieberbb6f9b02005-08-03 11:00:28 +00001222 UINT textureName;
Oliver Stieberba5eb142005-03-14 10:12:52 +00001223 UINT LOD;
Stefan Dösinger63fd9a72006-04-06 19:02:16 +02001224 WINED3DTEXTUREFILTERTYPE filterType;
Oliver Stieberbb6f9b02005-08-03 11:00:28 +00001225 DWORD states[MAX_WINETEXTURESTATES];
Stefan Dösinger666b5072006-12-19 23:26:39 +01001226 LONG bindCount;
1227 DWORD sampler;
Phil Costin622f62d2007-06-06 23:13:16 +00001228 BOOL is_srgb;
1229 UINT srgb_mode_change_count;
Stefan Dösinger1c4a15d2007-09-21 23:47:40 +02001230 WINED3DFORMAT shader_conversion_group;
Stefan Dösinger26f7eae2007-11-13 22:08:13 +01001231 float pow2Matrix[16];
Stefan Dösinger4bb54a12008-04-06 00:18:53 +02001232 minMipLookup_t *minMipLookup;
Stefan Dösinger481bcdf2008-04-06 00:37:51 +02001233 magLookup_t *magLookup;
Jason Edmeades819b0e12004-12-07 14:29:12 +00001234} IWineD3DBaseTextureClass;
1235
1236typedef struct IWineD3DBaseTextureImpl
1237{
1238 /* IUnknown & WineD3DResource Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001239 const IWineD3DBaseTextureVtbl *lpVtbl;
Jason Edmeades819b0e12004-12-07 14:29:12 +00001240 IWineD3DResourceClass resource;
1241 IWineD3DBaseTextureClass baseTexture;
1242
1243} IWineD3DBaseTextureImpl;
1244
Jason Edmeades819b0e12004-12-07 14:29:12 +00001245/*****************************************************************************
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001246 * IWineD3DTexture implementation structure (extends IWineD3DBaseTextureImpl)
1247 */
1248typedef struct IWineD3DTextureImpl
1249{
1250 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001251 const IWineD3DTextureVtbl *lpVtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001252 IWineD3DResourceClass resource;
1253 IWineD3DBaseTextureClass baseTexture;
1254
1255 /* IWineD3DTexture */
Oliver Stieberba5eb142005-03-14 10:12:52 +00001256 IWineD3DSurface *surfaces[MAX_LEVELS];
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001257
1258 UINT width;
1259 UINT height;
Stefan Dösingerd09cbce2007-11-28 20:35:04 +01001260 UINT target;
Stefan Dösingerc088ede2008-07-08 18:59:10 -05001261 BOOL cond_np2;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001262
1263} IWineD3DTextureImpl;
1264
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001265extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001266
1267/*****************************************************************************
1268 * IWineD3DCubeTexture implementation structure (extends IWineD3DBaseTextureImpl)
1269 */
1270typedef struct IWineD3DCubeTextureImpl
1271{
1272 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001273 const IWineD3DCubeTextureVtbl *lpVtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001274 IWineD3DResourceClass resource;
1275 IWineD3DBaseTextureClass baseTexture;
1276
1277 /* IWineD3DCubeTexture */
Oliver Stieberba5eb142005-03-14 10:12:52 +00001278 IWineD3DSurface *surfaces[6][MAX_LEVELS];
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001279
1280 UINT edgeLength;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001281} IWineD3DCubeTextureImpl;
1282
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001283extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001284
Ivan Gyurdiev257692e2006-05-10 13:55:02 -04001285typedef struct _WINED3DVOLUMET_DESC
1286{
1287 UINT Width;
1288 UINT Height;
1289 UINT Depth;
1290} WINED3DVOLUMET_DESC;
1291
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001292/*****************************************************************************
1293 * IWineD3DVolume implementation structure (extends IUnknown)
1294 */
1295typedef struct IWineD3DVolumeImpl
1296{
Oliver Stieber67f2ad42005-03-29 19:01:00 +00001297 /* IUnknown & WineD3DResource fields */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001298 const IWineD3DVolumeVtbl *lpVtbl;
Oliver Stieber67f2ad42005-03-29 19:01:00 +00001299 IWineD3DResourceClass resource;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001300
1301 /* WineD3DVolume Information */
Ivan Gyurdiev257692e2006-05-10 13:55:02 -04001302 WINED3DVOLUMET_DESC currentDesc;
H. Verbeete43cfb12006-02-06 11:30:48 +01001303 IWineD3DBase *container;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001304 UINT bytesPerPixel;
1305
1306 BOOL lockable;
1307 BOOL locked;
Stefan Dösingercf4b91f2006-04-07 13:12:22 +02001308 WINED3DBOX lockedBox;
1309 WINED3DBOX dirtyBox;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001310 BOOL dirty;
1311
1312
1313} IWineD3DVolumeImpl;
1314
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001315extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001316
1317/*****************************************************************************
1318 * IWineD3DVolumeTexture implementation structure (extends IWineD3DBaseTextureImpl)
1319 */
1320typedef struct IWineD3DVolumeTextureImpl
1321{
1322 /* IUnknown & WineD3DResource/WineD3DBaseTexture Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001323 const IWineD3DVolumeTextureVtbl *lpVtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001324 IWineD3DResourceClass resource;
1325 IWineD3DBaseTextureClass baseTexture;
1326
1327 /* IWineD3DVolumeTexture */
Oliver Stieberba5eb142005-03-14 10:12:52 +00001328 IWineD3DVolume *volumes[MAX_LEVELS];
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001329
1330 UINT width;
1331 UINT height;
1332 UINT depth;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001333} IWineD3DVolumeTextureImpl;
1334
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001335extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001336
Oliver Stieber2121f782005-03-02 12:16:10 +00001337typedef struct _WINED3DSURFACET_DESC
1338{
Stefan Dösingerb4b295c2006-03-24 17:34:26 +01001339 WINED3DMULTISAMPLE_TYPE MultiSampleType;
1340 DWORD MultiSampleQuality;
1341 UINT Width;
1342 UINT Height;
Oliver Stieber2121f782005-03-02 12:16:10 +00001343} WINED3DSURFACET_DESC;
1344
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001345/*****************************************************************************
Stefan Dösingeraf462952006-05-06 18:08:33 +02001346 * Structure for DIB Surfaces (GetDC and GDI surfaces)
1347 */
1348typedef struct wineD3DSurface_DIB {
1349 HBITMAP DIBsection;
1350 void* bitmap_data;
Roderick Colenbranderad692f22007-09-11 10:31:54 +02001351 UINT bitmap_size;
Stefan Dösingeraf462952006-05-06 18:08:33 +02001352 HGDIOBJ holdbitmap;
1353 BOOL client_memory;
1354} wineD3DSurface_DIB;
1355
H. Verbeetc9b178b2007-04-09 01:53:32 +02001356typedef struct {
1357 struct list entry;
1358 GLuint id;
1359 UINT width;
1360 UINT height;
1361} renderbuffer_entry_t;
1362
Henri Verbeet45820042008-09-18 14:57:53 +02001363struct fbo_entry
1364{
1365 struct list entry;
1366 IWineD3DSurface **render_targets;
1367 IWineD3DSurface *depth_stencil;
1368 BOOL attached;
1369 GLuint id;
1370};
1371
Stefan Dösingeraf462952006-05-06 18:08:33 +02001372/*****************************************************************************
Stefan Dösingerd93e1612007-04-28 17:59:37 +02001373 * IWineD3DClipp implementation structure
1374 */
1375typedef struct IWineD3DClipperImpl
1376{
1377 const IWineD3DClipperVtbl *lpVtbl;
1378 LONG ref;
1379
1380 IUnknown *Parent;
1381 HWND hWnd;
1382} IWineD3DClipperImpl;
1383
1384
1385/*****************************************************************************
Jason Edmeades41427852005-01-09 17:37:02 +00001386 * IWineD3DSurface implementation structure
1387 */
1388struct IWineD3DSurfaceImpl
1389{
1390 /* IUnknown & IWineD3DResource Information */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001391 const IWineD3DSurfaceVtbl *lpVtbl;
Jason Edmeades41427852005-01-09 17:37:02 +00001392 IWineD3DResourceClass resource;
1393
1394 /* IWineD3DSurface fields */
H. Verbeete43cfb12006-02-06 11:30:48 +01001395 IWineD3DBase *container;
Oliver Stieber2121f782005-03-02 12:16:10 +00001396 WINED3DSURFACET_DESC currentDesc;
Stefan Dösinger76764622007-02-19 15:23:36 +01001397 IWineD3DPaletteImpl *palette; /* D3D7 style palette handling */
1398 PALETTEENTRY *palette9; /* D3D8/9 style palette handling */
Jason Edmeades41427852005-01-09 17:37:02 +00001399
Jason Edmeades41427852005-01-09 17:37:02 +00001400 UINT bytesPerPixel;
Oliver Stieber520c2f02005-07-11 14:25:54 +00001401
1402 /* TODO: move this off into a management class(maybe!) */
Stefan Dösingera98ccb52006-07-23 00:03:33 +02001403 DWORD Flags;
Oliver Stieber520c2f02005-07-11 14:25:54 +00001404
1405 UINT pow2Width;
1406 UINT pow2Height;
Stefan Dösinger3b486602008-08-26 14:36:30 -05001407 float heightscale;
Oliver Stieber520c2f02005-07-11 14:25:54 +00001408
Stefan Dösinger9bc62002007-11-30 20:22:33 +01001409 /* A method to retrieve the drawable size. Not in the Vtable to make it changeable */
1410 void (*get_drawable_size)(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1411
Stefan Dösingercfcdb652006-05-19 00:13:29 +02001412 /* Oversized texture */
1413 RECT glRect;
1414
Roderick Colenbranderad692f22007-09-11 10:31:54 +02001415 /* PBO */
1416 GLuint pbo;
1417
Jason Edmeades41427852005-01-09 17:37:02 +00001418 RECT lockedRect;
1419 RECT dirtyRect;
Stefan Dösinger03389ac2007-01-12 18:57:26 +01001420 int lockCount;
1421#define MAXLOCKCOUNT 50 /* After this amount of locks do not free the sysmem copy */
Oliver Stieber13621052005-07-11 20:38:27 +00001422
1423 glDescriptor glDescription;
Stefan Dösingerf6637ca2007-10-13 12:54:10 +02001424 BOOL srgb;
Stefan Dösingeraf462952006-05-06 18:08:33 +02001425
1426 /* For GetDC */
1427 wineD3DSurface_DIB dib;
1428 HDC hDC;
Stefan Dösinger9b29fb62006-05-09 19:37:38 +02001429
1430 /* Color keys for DDraw */
Stefan Dösinger725057d2007-04-14 22:44:55 +02001431 WINEDDCOLORKEY DestBltCKey;
1432 WINEDDCOLORKEY DestOverlayCKey;
1433 WINEDDCOLORKEY SrcOverlayCKey;
1434 WINEDDCOLORKEY SrcBltCKey;
Stefan Dösinger9b29fb62006-05-09 19:37:38 +02001435 DWORD CKeyFlags;
1436
Stefan Dösinger725057d2007-04-14 22:44:55 +02001437 WINEDDCOLORKEY glCKey;
H. Verbeetc9b178b2007-04-09 01:53:32 +02001438
1439 struct list renderbuffers;
1440 renderbuffer_entry_t *current_renderbuffer;
Stefan Dösingerd93e1612007-04-28 17:59:37 +02001441
1442 /* DirectDraw clippers */
1443 IWineD3DClipper *clipper;
Stefan Dösingere795d842008-08-05 12:19:43 +02001444
1445 /* DirectDraw Overlay handling */
1446 RECT overlay_srcrect;
1447 RECT overlay_destrect;
1448 IWineD3DSurfaceImpl *overlay_dest;
Stefan Dösingerdff3a422008-07-30 15:28:25 -05001449 struct list overlays;
1450 struct list overlay_entry;
Jason Edmeades41427852005-01-09 17:37:02 +00001451};
1452
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001453extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
Stefan Dösinger2f724832006-05-13 22:22:16 +02001454extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
1455
1456/* Predeclare the shared Surface functions */
Stefan Dösinger84340602007-09-16 13:29:44 +02001457HRESULT WINAPI IWineD3DBaseSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
Stefan Dösinger0c916102007-09-16 13:42:18 +02001458ULONG WINAPI IWineD3DBaseSurfaceImpl_AddRef(IWineD3DSurface *iface);
Stefan Dösinger0c916102007-09-16 13:42:18 +02001459HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
1460HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
1461HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
1462HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
1463HRESULT WINAPI IWineD3DBaseSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
1464DWORD WINAPI IWineD3DBaseSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
1465DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPriority(IWineD3DSurface *iface);
Stefan Dösinger0c916102007-09-16 13:42:18 +02001466WINED3DRESOURCETYPE WINAPI IWineD3DBaseSurfaceImpl_GetType(IWineD3DSurface *iface);
Stefan Dösingerd99143c2007-09-16 14:03:39 +02001467HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
1468HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
1469HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
1470HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
1471HRESULT WINAPI IWineD3DBaseSurfaceImpl_IsLost(IWineD3DSurface *iface);
1472HRESULT WINAPI IWineD3DBaseSurfaceImpl_Restore(IWineD3DSurface *iface);
Stefan Dösingere2944172007-09-16 16:27:58 +02001473HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
1474HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
Henri Verbeetb4f0b5b2008-11-25 11:57:39 +01001475HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, const WINEDDCOLORKEY *CKey);
Stefan Dösingere2944172007-09-16 16:27:58 +02001476HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
Stefan Dösingere2944172007-09-16 16:27:58 +02001477DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPitch(IWineD3DSurface *iface);
1478HRESULT WINAPI IWineD3DBaseSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
Stefan Dösingere2944172007-09-16 16:27:58 +02001479HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetOverlayPosition(IWineD3DSurface *iface, LONG X, LONG Y);
1480HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetOverlayPosition(IWineD3DSurface *iface, LONG *X, LONG *Y);
1481HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface *iface, DWORD Flags, IWineD3DSurface *Ref);
Henri Verbeetb4f0b5b2008-11-25 11:57:39 +01001482HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlay(IWineD3DSurface *iface, const RECT *SrcRect,
1483 IWineD3DSurface *DstSurface, const RECT *DstRect, DWORD Flags, const WINEDDOVERLAYFX *FX);
Stefan Dösingere2944172007-09-16 16:27:58 +02001484HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetClipper(IWineD3DSurface *iface, IWineD3DClipper *clipper);
1485HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetClipper(IWineD3DSurface *iface, IWineD3DClipper **clipper);
Stefan Dösingere56c6612007-09-16 16:49:02 +02001486HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
Stefan Dösinger5a775642007-09-17 13:48:11 +02001487HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface);
Henri Verbeetb4f0b5b2008-11-25 11:57:39 +01001488HRESULT WINAPI IWineD3DBaseSurfaceImpl_Blt(IWineD3DSurface *iface, const RECT *DestRect, IWineD3DSurface *SrcSurface,
1489 const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter);
1490HRESULT WINAPI IWineD3DBaseSurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty,
1491 IWineD3DSurface *Source, const RECT *rsrc, DWORD trans);
Stefan Dösingera175e7b2007-10-09 22:19:39 +02001492HRESULT WINAPI IWineD3DBaseSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags);
Stefan Dösingerf13bb402007-11-15 14:38:34 +01001493void WINAPI IWineD3DBaseSurfaceImpl_BindTexture(IWineD3DSurface *iface);
Henri Verbeet49b55f62008-11-25 11:57:39 +01001494const void *WINAPI IWineD3DBaseSurfaceImpl_GetData(IWineD3DSurface *iface);
Stefan Dösinger9aa56622007-09-16 16:33:23 +02001495
Stefan Dösinger9bc62002007-11-30 20:22:33 +01001496void get_drawable_size_swapchain(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1497void get_drawable_size_backbuffer(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1498void get_drawable_size_pbuffer(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1499void get_drawable_size_fbo(IWineD3DSurfaceImpl *This, UINT *width, UINT *height);
1500
Stefan Dösinger851dd732008-07-24 11:38:51 -05001501void flip_surface(IWineD3DSurfaceImpl *front, IWineD3DSurfaceImpl *back);
1502
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02001503/* Surface flags: */
H. Verbeet4f77c292008-07-02 23:00:41 +02001504#define SFLAG_OVERSIZE 0x00000001 /* Surface is bigger than gl size, blts only */
1505#define SFLAG_CONVERTED 0x00000002 /* Converted for color keying or Palettized */
1506#define SFLAG_DIBSECTION 0x00000004 /* Has a DIB section attached for GetDC */
1507#define SFLAG_LOCKABLE 0x00000008 /* Surface can be locked */
1508#define SFLAG_DISCARD 0x00000010 /* ??? */
1509#define SFLAG_LOCKED 0x00000020 /* Surface is locked atm */
1510#define SFLAG_INTEXTURE 0x00000040 /* The GL texture contains the newest surface content */
1511#define SFLAG_INDRAWABLE 0x00000080 /* The gl drawable contains the most up to date data */
1512#define SFLAG_INSYSMEM 0x00000100 /* The system memory copy is most up to date */
1513#define SFLAG_NONPOW2 0x00000200 /* Surface sizes are not a power of 2 */
1514#define SFLAG_DYNLOCK 0x00000400 /* Surface is often locked by the app */
1515#define SFLAG_DYNCHANGE 0x00000C00 /* Surface contents are changed very often, implies DYNLOCK */
1516#define SFLAG_DCINUSE 0x00001000 /* Set between GetDC and ReleaseDC calls */
1517#define SFLAG_LOST 0x00002000 /* Surface lost flag for DDraw */
1518#define SFLAG_USERPTR 0x00004000 /* The application allocated the memory for this surface */
1519#define SFLAG_GLCKEY 0x00008000 /* The gl texture was created with a color key */
1520#define SFLAG_CLIENT 0x00010000 /* GL_APPLE_client_storage is used on that texture */
1521#define SFLAG_ALLOCATED 0x00020000 /* A gl texture is allocated for this surface */
1522#define SFLAG_PBO 0x00040000 /* Has a PBO attached for speeding up data transfers for dynamically locked surfaces */
1523#define SFLAG_NORMCOORD 0x00080000 /* Set if the GL texture coords are normalized(non-texture rectangle) */
1524#define SFLAG_DS_ONSCREEN 0x00100000 /* Is a depth stencil, last modified onscreen */
1525#define SFLAG_DS_OFFSCREEN 0x00200000 /* Is a depth stencil, last modified offscreen */
Stefan Dösingerbab367e2008-08-20 10:48:14 -05001526#define SFLAG_INOVERLAYDRAW 0x00400000 /* Overlay drawing is in progress. Recursion prevention */
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02001527
1528/* In some conditions the surface memory must not be freed:
1529 * SFLAG_OVERSIZE: Not all data can be kept in GL
1530 * SFLAG_CONVERTED: Converting the data back would take too long
1531 * SFLAG_DIBSECTION: The dib code manages the memory
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02001532 * SFLAG_LOCKED: The app requires access to the surface data
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02001533 * SFLAG_DYNLOCK: Avoid freeing the data for performance
1534 * SFLAG_DYNCHANGE: Same reason as DYNLOCK
Roderick Colenbranderad692f22007-09-11 10:31:54 +02001535 * 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 +02001536 * SFLAG_CLIENT: OpenGL uses our memory as backup
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02001537 */
H. Verbeet4f77c292008-07-02 23:00:41 +02001538#define SFLAG_DONOTFREE (SFLAG_OVERSIZE | \
1539 SFLAG_CONVERTED | \
1540 SFLAG_DIBSECTION | \
1541 SFLAG_LOCKED | \
1542 SFLAG_DYNLOCK | \
1543 SFLAG_DYNCHANGE | \
1544 SFLAG_USERPTR | \
1545 SFLAG_PBO | \
1546 SFLAG_CLIENT)
Stefan Dösinger1cfbc902006-05-06 16:15:37 +02001547
H. Verbeet4f77c292008-07-02 23:00:41 +02001548#define SFLAG_LOCATIONS (SFLAG_INSYSMEM | \
1549 SFLAG_INTEXTURE | \
1550 SFLAG_INDRAWABLE)
1551
1552#define SFLAG_DS_LOCATIONS (SFLAG_DS_ONSCREEN | \
1553 SFLAG_DS_OFFSCREEN)
Henri Verbeet9d192c62008-09-22 14:52:52 +02001554#define SFLAG_DS_DISCARDED SFLAG_DS_LOCATIONS
H. Verbeet4f77c292008-07-02 23:00:41 +02001555
Stefan Dösinger158691e2006-05-23 00:48:54 +02001556BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
1557
Stefan Dösinger028729d2007-08-11 20:02:01 +02001558typedef enum {
1559 NO_CONVERSION,
1560 CONVERT_PALETTED,
1561 CONVERT_PALETTED_CK,
1562 CONVERT_CK_565,
1563 CONVERT_CK_5551,
1564 CONVERT_CK_4444,
1565 CONVERT_CK_4444_ARGB,
1566 CONVERT_CK_1555,
1567 CONVERT_555,
1568 CONVERT_CK_RGB24,
1569 CONVERT_CK_8888,
1570 CONVERT_CK_8888_ARGB,
1571 CONVERT_RGB32_888,
1572 CONVERT_V8U8,
Stefan Dösinger0ed81b22007-08-31 20:41:03 +02001573 CONVERT_L6V5U5,
Stefan Dösinger028729d2007-08-11 20:02:01 +02001574 CONVERT_X8L8V8U8,
1575 CONVERT_Q8W8V8U8,
1576 CONVERT_V16U16,
Stefan Dösinger86b991c2007-08-12 16:24:29 +02001577 CONVERT_A4L4,
1578 CONVERT_R32F,
Stefan Dösingerdf77e282007-12-15 23:47:10 +01001579 CONVERT_R16F,
1580 CONVERT_G16R16,
Stefan Dösinger028729d2007-08-11 20:02:01 +02001581} CONVERT_TYPES;
1582
1583HRESULT 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);
1584
Alexander Dorofeyevd6ba0692008-04-03 00:12:16 +03001585BOOL palette9_changed(IWineD3DSurfaceImpl *This);
1586
Jason Edmeades41427852005-01-09 17:37:02 +00001587/*****************************************************************************
Raphael Junqueira4f02b522005-01-19 19:34:49 +00001588 * IWineD3DVertexDeclaration implementation structure
1589 */
Stefan Dösinger95921232007-11-20 21:14:10 +01001590typedef struct attrib_declaration {
1591 DWORD usage;
1592 DWORD idx;
1593} attrib_declaration;
1594
1595#define MAX_ATTRIBS 16
1596
Raphael Junqueira4f02b522005-01-19 19:34:49 +00001597typedef struct IWineD3DVertexDeclarationImpl {
H. Verbeetee09e8b2007-03-12 23:21:54 +01001598 /* IUnknown Information */
1599 const IWineD3DVertexDeclarationVtbl *lpVtbl;
1600 LONG ref;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00001601
H. Verbeetee09e8b2007-03-12 23:21:54 +01001602 IUnknown *parent;
1603 IWineD3DDeviceImpl *wineD3DDevice;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00001604
H. Verbeetee09e8b2007-03-12 23:21:54 +01001605 WINED3DVERTEXELEMENT *pDeclarationWine;
Henri Verbeetf84680e2008-09-18 14:57:54 +02001606 BOOL *ffp_valid;
H. Verbeetee09e8b2007-03-12 23:21:54 +01001607 UINT declarationWNumElements;
Stefan Dösinger06e51c22007-08-03 19:53:25 +02001608
1609 DWORD streams[MAX_STREAMS];
1610 UINT num_streams;
Stefan Dösingerb8dd5832007-07-30 12:35:33 +02001611 BOOL position_transformed;
Stefan Dösingera3c2fb92007-12-20 01:34:22 +01001612 BOOL half_float_conv_needed;
Stefan Dösinger95921232007-11-20 21:14:10 +01001613
1614 /* Ordered array of declaration types that need swizzling in a vshader */
1615 attrib_declaration swizzled_attribs[MAX_ATTRIBS];
1616 UINT num_swizzled_attribs;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00001617} IWineD3DVertexDeclarationImpl;
1618
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001619extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00001620
1621/*****************************************************************************
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001622 * IWineD3DStateBlock implementation structure
1623 */
1624
1625/* Internal state Block for Begin/End/Capture/Create/Apply info */
1626/* Note: Very long winded but gl Lists are not flexible enough */
1627/* to resolve everything we need, so doing it manually for now */
1628typedef struct SAVEDSTATES {
Jason Edmeadesf738c142004-12-09 11:42:34 +00001629 BOOL indices;
Jason Edmeades0a944ae2004-11-29 17:53:42 +00001630 BOOL material;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001631 BOOL fvf;
Oliver Stieberabb11f32005-07-05 14:05:18 +00001632 BOOL streamSource[MAX_STREAMS];
1633 BOOL streamFreq[MAX_STREAMS];
H. Verbeet5b7758f2007-06-25 22:45:40 +02001634 BOOL textures[MAX_COMBINED_SAMPLERS];
Oliver Stieberabb11f32005-07-05 14:05:18 +00001635 BOOL transform[HIGHEST_TRANSFORMSTATE + 1];
Jason Edmeadesf738c142004-12-09 11:42:34 +00001636 BOOL viewport;
Oliver Stieberabb11f32005-07-05 14:05:18 +00001637 BOOL renderState[WINEHIGHEST_RENDER_STATE + 1];
Oliver Stieber7cb748f2005-07-26 18:49:30 +00001638 BOOL textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
H. Verbeet5b7758f2007-06-25 22:45:40 +02001639 BOOL samplerState[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
Oliver Stieberd3441622005-08-01 10:58:31 +00001640 BOOL clipplane[MAX_CLIPPLANES];
Raphael Junqueira4c385f92005-01-26 20:54:00 +00001641 BOOL vertexDecl;
Oliver Stieber2121f782005-03-02 12:16:10 +00001642 BOOL pixelShader;
Jason Green718716b2006-07-19 00:06:07 -04001643 BOOL pixelShaderConstantsB[MAX_CONST_B];
1644 BOOL pixelShaderConstantsI[MAX_CONST_I];
1645 BOOL *pixelShaderConstantsF;
Oliver Stieberabb11f32005-07-05 14:05:18 +00001646 BOOL vertexShader;
Jason Green718716b2006-07-19 00:06:07 -04001647 BOOL vertexShaderConstantsB[MAX_CONST_B];
1648 BOOL vertexShaderConstantsI[MAX_CONST_I];
1649 BOOL *vertexShaderConstantsF;
Stefan Dösingerd4b63bb2007-01-10 11:28:42 +01001650 BOOL scissorRect;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001651} SAVEDSTATES;
1652
H. Verbeet09eb0c42006-08-19 17:24:02 +02001653typedef struct {
H. Verbeet19d223c2007-02-27 20:51:58 +01001654 struct list entry;
1655 DWORD count;
1656 DWORD idx[13];
1657} constants_entry;
H. Verbeet09eb0c42006-08-19 17:24:02 +02001658
Stefan Dösinger03ffb732007-08-09 17:45:29 +02001659struct StageState {
1660 DWORD stage;
1661 DWORD state;
1662};
1663
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001664struct IWineD3DStateBlockImpl
1665{
1666 /* IUnknown fields */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001667 const IWineD3DStateBlockVtbl *lpVtbl;
Mike McCormack8955ac42005-07-28 10:16:21 +00001668 LONG ref; /* Note: Ref counting not required */
Oliver Stieberabb11f32005-07-05 14:05:18 +00001669
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001670 /* IWineD3DStateBlock information */
Jason Edmeades289562e2004-11-23 13:52:46 +00001671 IUnknown *parent;
Jason Edmeades41427852005-01-09 17:37:02 +00001672 IWineD3DDeviceImpl *wineD3DDevice;
Oliver Stieber7cb748f2005-07-26 18:49:30 +00001673 WINED3DSTATEBLOCKTYPE blockType;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001674
1675 /* Array indicating whether things have been set or changed */
1676 SAVEDSTATES changed;
H. Verbeet09eb0c42006-08-19 17:24:02 +02001677 struct list set_vconstantsF;
1678 struct list set_pconstantsF;
Oliver Stieberabb11f32005-07-05 14:05:18 +00001679
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001680 /* Drawing - Vertex Shader or FVF related */
1681 DWORD fvf;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00001682 /* Vertex Shader Declaration */
Oliver Stieber2c0e97e2005-08-17 11:34:03 +00001683 IWineD3DVertexDeclaration *vertexDecl;
Raphael Junqueira4f02b522005-01-19 19:34:49 +00001684
Oliver Stieberb3563da2005-09-28 10:13:00 +00001685 IWineD3DVertexShader *vertexShader;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001686
Oliver Stieber9b0b8032005-08-17 10:27:01 +00001687 /* Vertex Shader Constants */
Jason Green718716b2006-07-19 00:06:07 -04001688 BOOL vertexShaderConstantB[MAX_CONST_B];
1689 INT vertexShaderConstantI[MAX_CONST_I * 4];
1690 float *vertexShaderConstantF;
Oliver Stieber9b0b8032005-08-17 10:27:01 +00001691
Jason Edmeades289562e2004-11-23 13:52:46 +00001692 /* Stream Source */
Raphael Junqueira4f02b522005-01-19 19:34:49 +00001693 BOOL streamIsUP;
Oliver Stieberabb11f32005-07-05 14:05:18 +00001694 UINT streamStride[MAX_STREAMS];
Stefan Dösinger26ebe392007-07-04 17:57:45 +02001695 UINT streamOffset[MAX_STREAMS + 1 /* tesselated pseudo-stream */ ];
Oliver Stieberabb11f32005-07-05 14:05:18 +00001696 IWineD3DVertexBuffer *streamSource[MAX_STREAMS];
Stefan Dösinger26ebe392007-07-04 17:57:45 +02001697 UINT streamFreq[MAX_STREAMS + 1];
1698 UINT streamFlags[MAX_STREAMS + 1]; /*0 | WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA */
Jason Edmeadeseba27af2004-11-28 15:04:41 +00001699
Jason Edmeadesf738c142004-12-09 11:42:34 +00001700 /* Indices */
1701 IWineD3DIndexBuffer* pIndexData;
Stefan Dösinger6ec6c942007-08-25 00:09:33 +02001702 INT baseVertexIndex;
1703 INT loadBaseVertexIndex; /* non-indexed drawing needs 0 here, indexed baseVertexIndex */
Jason Edmeadesf738c142004-12-09 11:42:34 +00001704
Jason Edmeadeseba27af2004-11-28 15:04:41 +00001705 /* Transform */
Ivan Gyurdievac371632006-10-12 02:21:39 -04001706 WINED3DMATRIX transforms[HIGHEST_TRANSFORMSTATE + 1];
Jason Edmeadeseba27af2004-11-28 15:04:41 +00001707
Stefan Dösingeracadf3f2007-02-14 17:46:54 +01001708 /* Light hashmap . Collisions are handled using standard wine double linked lists */
1709#define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
1710#define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
1711 struct list lightMap[LIGHTMAP_SIZE]; /* Mashmap containing the lights */
1712 PLIGHTINFOEL *activeLights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
Oliver Stieberabb11f32005-07-05 14:05:18 +00001713
Jason Edmeades0a944ae2004-11-29 17:53:42 +00001714 /* Clipping */
1715 double clipplane[MAX_CLIPPLANES][4];
1716 WINED3DCLIPSTATUS clip_status;
1717
Jason Edmeadesf738c142004-12-09 11:42:34 +00001718 /* ViewPort */
1719 WINED3DVIEWPORT viewport;
1720
Jason Edmeades0a944ae2004-11-29 17:53:42 +00001721 /* Material */
1722 WINED3DMATERIAL material;
1723
Oliver Stieberabb11f32005-07-05 14:05:18 +00001724 /* Pixel Shader */
Oliver Stieberb3563da2005-09-28 10:13:00 +00001725 IWineD3DPixelShader *pixelShader;
Oliver Stieber2af36c62005-08-25 19:24:21 +00001726
1727 /* Pixel Shader Constants */
Jason Green718716b2006-07-19 00:06:07 -04001728 BOOL pixelShaderConstantB[MAX_CONST_B];
1729 INT pixelShaderConstantI[MAX_CONST_I * 4];
1730 float *pixelShaderConstantF;
Oliver Stieberabb11f32005-07-05 14:05:18 +00001731
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001732 /* RenderState */
Oliver Stieberabb11f32005-07-05 14:05:18 +00001733 DWORD renderState[WINEHIGHEST_RENDER_STATE + 1];
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001734
Jason Edmeadesf738c142004-12-09 11:42:34 +00001735 /* Texture */
H. Verbeet5b7758f2007-06-25 22:45:40 +02001736 IWineD3DBaseTexture *textures[MAX_COMBINED_SAMPLERS];
1737 int textureDimensions[MAX_COMBINED_SAMPLERS];
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001738
1739 /* Texture State Stage */
Oliver Stieber7cb748f2005-07-26 18:49:30 +00001740 DWORD textureState[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
Stefan Dösinger762af472006-12-19 23:00:58 +01001741 DWORD lowest_disabled_stage;
Oliver Stieber18857f12005-06-24 11:53:07 +00001742 /* Sampler States */
H. Verbeet5b7758f2007-06-25 22:45:40 +02001743 DWORD samplerState[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
Oliver Stieber18857f12005-06-24 11:53:07 +00001744
Stefan Dösingerd4b63bb2007-01-10 11:28:42 +01001745 /* Scissor test rectangle */
1746 RECT scissorRect;
Stefan Dösinger93155ea2007-07-31 15:04:56 +02001747
1748 /* Contained state management */
1749 DWORD contained_render_states[WINEHIGHEST_RENDER_STATE + 1];
1750 unsigned int num_contained_render_states;
Stefan Dösinger6e7a10f2007-08-14 23:44:25 +02001751 DWORD contained_transform_states[HIGHEST_TRANSFORMSTATE + 1];
Stefan Dösinger92ce0282007-07-31 15:44:13 +02001752 unsigned int num_contained_transform_states;
Stefan Dösinger4673b1c2007-08-03 20:07:30 +02001753 DWORD contained_vs_consts_i[MAX_CONST_I];
1754 unsigned int num_contained_vs_consts_i;
1755 DWORD contained_vs_consts_b[MAX_CONST_B];
1756 unsigned int num_contained_vs_consts_b;
Stefan Dösingerb21c7852007-08-03 20:26:29 +02001757 DWORD *contained_vs_consts_f;
1758 unsigned int num_contained_vs_consts_f;
Stefan Dösinger865b82a2007-08-03 20:12:54 +02001759 DWORD contained_ps_consts_i[MAX_CONST_I];
1760 unsigned int num_contained_ps_consts_i;
1761 DWORD contained_ps_consts_b[MAX_CONST_B];
1762 unsigned int num_contained_ps_consts_b;
Stefan Dösingerb21c7852007-08-03 20:26:29 +02001763 DWORD *contained_ps_consts_f;
1764 unsigned int num_contained_ps_consts_f;
Stefan Dösinger03ffb732007-08-09 17:45:29 +02001765 struct StageState contained_tss_states[MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE)];
1766 unsigned int num_contained_tss_states;
Stefan Dösinger59fb2922007-08-03 20:23:52 +02001767 struct StageState contained_sampler_states[MAX_COMBINED_SAMPLERS * WINED3D_HIGHEST_SAMPLER_STATE];
1768 unsigned int num_contained_sampler_states;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001769};
1770
Jason Green75950b52006-07-23 15:08:27 -04001771extern void stateblock_savedstates_set(
1772 IWineD3DStateBlock* iface,
1773 SAVEDSTATES* states,
1774 BOOL value);
1775
1776extern void stateblock_savedstates_copy(
1777 IWineD3DStateBlock* iface,
1778 SAVEDSTATES* dest,
1779 SAVEDSTATES* source);
1780
1781extern void stateblock_copy(
1782 IWineD3DStateBlock* destination,
1783 IWineD3DStateBlock* source);
1784
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001785extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001786
Stefan Dösinger0e8c13e2007-12-04 01:43:24 +01001787/* Direct3D terminology with little modifications. We do not have an issued state
1788 * because only the driver knows about it, but we have a created state because d3d
1789 * allows GetData on a created issue, but opengl doesn't
1790 */
1791enum query_state {
1792 QUERY_CREATED,
1793 QUERY_SIGNALLED,
1794 QUERY_BUILDING
1795};
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001796/*****************************************************************************
Oliver Stieber7b261652005-03-03 13:57:15 +00001797 * IWineD3DQueryImpl implementation structure (extends IUnknown)
1798 */
1799typedef struct IWineD3DQueryImpl
1800{
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001801 const IWineD3DQueryVtbl *lpVtbl;
Mike McCormack8955ac42005-07-28 10:16:21 +00001802 LONG ref; /* Note: Ref counting not required */
Oliver Stieber7b261652005-03-03 13:57:15 +00001803
1804 IUnknown *parent;
1805 /*TODO: replace with iface usage */
1806#if 0
1807 IWineD3DDevice *wineD3DDevice;
1808#else
1809 IWineD3DDeviceImpl *wineD3DDevice;
1810#endif
Oliver Stieber7b261652005-03-03 13:57:15 +00001811
Ivan Gyurdievf0d5b352006-10-10 21:53:30 -04001812 /* IWineD3DQuery fields */
Stefan Dösinger0e8c13e2007-12-04 01:43:24 +01001813 enum query_state state;
Ivan Gyurdievf0d5b352006-10-10 21:53:30 -04001814 WINED3DQUERYTYPE type;
Oliver Stieber5ea96a82005-09-21 09:43:13 +00001815 /* TODO: Think about using a IUnknown instead of a void* */
Oliver Stieber7b261652005-03-03 13:57:15 +00001816 void *extendedData;
1817
1818
1819} IWineD3DQueryImpl;
1820
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00001821extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
Stefan Dösinger071d4af2008-02-28 21:02:58 +01001822extern const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl;
Stefan Dösinger32be5032008-02-28 21:03:41 +01001823extern const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl;
Oliver Stieber7b261652005-03-03 13:57:15 +00001824
Oliver Stieber5ea96a82005-09-21 09:43:13 +00001825/* Datastructures for IWineD3DQueryImpl.extendedData */
1826typedef struct WineQueryOcclusionData {
H. Verbeet53663892006-07-25 00:51:33 +02001827 GLuint queryId;
Stefan Dösingere184b092007-08-14 15:42:34 +02001828 WineD3DContext *ctx;
Oliver Stieber5ea96a82005-09-21 09:43:13 +00001829} WineQueryOcclusionData;
1830
Stefan Dösinger76b60b02007-03-01 00:34:33 +01001831typedef struct WineQueryEventData {
1832 GLuint fenceId;
Stefan Dösingera99907d2007-08-14 15:26:02 +02001833 WineD3DContext *ctx;
Stefan Dösinger76b60b02007-03-01 00:34:33 +01001834} WineQueryEventData;
Oliver Stieber5ea96a82005-09-21 09:43:13 +00001835
Oliver Stieber7b261652005-03-03 13:57:15 +00001836/*****************************************************************************
Oliver Stieber46e7c302005-06-23 11:05:24 +00001837 * IWineD3DSwapChainImpl implementation structure (extends IUnknown)
1838 */
1839
1840typedef struct IWineD3DSwapChainImpl
1841{
1842 /*IUnknown part*/
Dmitry Timoshkov47ffd7a2006-12-14 22:47:59 +08001843 const IWineD3DSwapChainVtbl *lpVtbl;
Mike McCormack8955ac42005-07-28 10:16:21 +00001844 LONG ref; /* Note: Ref counting not required */
Oliver Stieber46e7c302005-06-23 11:05:24 +00001845
1846 IUnknown *parent;
1847 IWineD3DDeviceImpl *wineD3DDevice;
1848
1849 /* IWineD3DSwapChain fields */
Stefan Dösinger3862f8e2006-06-15 12:54:19 +02001850 IWineD3DSurface **backBuffer;
Oliver Stieber46e7c302005-06-23 11:05:24 +00001851 IWineD3DSurface *frontBuffer;
H. Verbeeta4bc52a2007-02-15 22:36:50 +01001852 WINED3DPRESENT_PARAMETERS presentParms;
Stefan Dösingerd30f1522006-12-08 16:13:15 +01001853 DWORD orig_width, orig_height;
Stefan Dösinger8e841272007-02-15 13:53:33 +01001854 WINED3DFORMAT orig_fmt;
Stefan Dösinger8d930f62008-07-01 11:17:38 -05001855 WINED3DGAMMARAMP orig_gamma;
Oliver Stieber46e7c302005-06-23 11:05:24 +00001856
Stefan Dösinger222c5312007-01-10 11:27:26 +01001857 long prev_time, frames; /* Performance tracking */
Stefan Dösingerc9b8a792007-06-03 13:20:27 +02001858 unsigned int vSyncCounter;
Stefan Dösinger222c5312007-01-10 11:27:26 +01001859
Stefan Dösinger90fe64c2007-03-04 17:31:06 +01001860 WineD3DContext **context; /* Later a array for multithreading */
1861 unsigned int num_contexts;
Oliver Stieber46e7c302005-06-23 11:05:24 +00001862
1863 HWND win_handle;
Oliver Stieber46e7c302005-06-23 11:05:24 +00001864} IWineD3DSwapChainImpl;
1865
Dmitry Timoshkov47ffd7a2006-12-14 22:47:59 +08001866extern const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
Stefan Dösingere178ddd2008-08-05 14:23:00 -05001867const IWineD3DSwapChainVtbl IWineGDISwapChain_Vtbl;
1868void x11_copy_to_screen(IWineD3DSwapChainImpl *This, LPRECT rc);
Oliver Stieber46e7c302005-06-23 11:05:24 +00001869
Stefan Dösingere5de2fc2008-07-27 18:04:16 -05001870HRESULT WINAPI IWineD3DBaseSwapChainImpl_QueryInterface(IWineD3DSwapChain *iface, REFIID riid, LPVOID *ppobj);
1871ULONG WINAPI IWineD3DBaseSwapChainImpl_AddRef(IWineD3DSwapChain *iface);
1872ULONG WINAPI IWineD3DBaseSwapChainImpl_Release(IWineD3DSwapChain *iface);
1873HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetParent(IWineD3DSwapChain *iface, IUnknown ** ppParent);
1874HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetFrontBufferData(IWineD3DSwapChain *iface, IWineD3DSurface *pDestSurface);
1875HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetBackBuffer(IWineD3DSwapChain *iface, UINT iBackBuffer, WINED3DBACKBUFFER_TYPE Type, IWineD3DSurface **ppBackBuffer);
1876HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetRasterStatus(IWineD3DSwapChain *iface, WINED3DRASTER_STATUS *pRasterStatus);
1877HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDisplayMode(IWineD3DSwapChain *iface, WINED3DDISPLAYMODE*pMode);
1878HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDevice(IWineD3DSwapChain *iface, IWineD3DDevice**ppDevice);
1879HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetPresentParameters(IWineD3DSwapChain *iface, WINED3DPRESENT_PARAMETERS *pPresentationParameters);
1880HRESULT WINAPI IWineD3DBaseSwapChainImpl_SetGammaRamp(IWineD3DSwapChain *iface, DWORD Flags, CONST WINED3DGAMMARAMP *pRamp);
1881HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetGammaRamp(IWineD3DSwapChain *iface, WINED3DGAMMARAMP *pRamp);
1882
Stefan Dösingerb462ff02007-06-02 20:21:57 +00001883WineD3DContext *IWineD3DSwapChainImpl_CreateContextForThread(IWineD3DSwapChain *iface);
1884
Oliver Stieber46e7c302005-06-23 11:05:24 +00001885/*****************************************************************************
Jason Edmeades447d5ed2004-10-21 20:59:12 +00001886 * Utility function prototypes
1887 */
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001888
1889/* Trace routines */
Oliver Stieberb220ce12005-07-13 19:38:39 +00001890const char* debug_d3dformat(WINED3DFORMAT fmt);
Ivan Gyurdiev19c55342006-10-10 21:52:00 -04001891const char* debug_d3ddevicetype(WINED3DDEVTYPE devtype);
Stefan Dösinger913df5b2006-03-09 23:21:16 +01001892const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
Jason Edmeadesc579fa62004-10-05 02:14:06 +00001893const char* debug_d3dusage(DWORD usage);
Jason Greend353ab72006-07-28 15:33:20 -04001894const char* debug_d3dusagequery(DWORD usagequery);
H. Verbeet02a8f742006-08-07 19:21:54 +02001895const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method);
1896const char* debug_d3ddecltype(WINED3DDECLTYPE type);
Ivan Gyurdiev7e9fd0b2006-07-03 00:11:15 -06001897const char* debug_d3ddeclusage(BYTE usage);
Ivan Gyurdiev2bac4a02006-10-12 02:23:55 -04001898const char* debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType);
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001899const char* debug_d3drenderstate(DWORD state);
Ivan Gyurdiev621f0752006-06-09 17:47:16 -04001900const char* debug_d3dsamplerstate(DWORD state);
H. Verbeet75108442007-04-09 01:53:38 +02001901const char* debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type);
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001902const char* debug_d3dtexturestate(DWORD state);
Jason Greenac8f2c02006-07-23 22:54:30 -04001903const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype);
Stefan Dösingerd75fd752006-03-28 14:20:47 +02001904const char* debug_d3dpool(WINED3DPOOL pool);
H. Verbeetc4cc10a2007-04-16 21:19:12 +02001905const char *debug_fbostatus(GLenum status);
H. Verbeetb643ab32007-04-23 22:02:50 +02001906const char *debug_glerror(GLenum error);
Stefan Dösinger26ebe392007-07-04 17:57:45 +02001907const char *debug_d3dbasis(WINED3DBASISTYPE basis);
1908const char *debug_d3ddegree(WINED3DDEGREETYPE order);
Stefan Dösingereea2c952008-07-12 11:45:33 -05001909const char* debug_d3dtop(WINED3DTEXTUREOP d3dtop);
Jason Edmeades2003c7a2004-12-13 13:35:38 +00001910
1911/* Routines for GL <-> D3D values */
1912GLenum StencilOp(DWORD op);
Jan Zerebeckifd15b8d2006-08-25 16:28:34 +02001913GLenum CompareFunc(DWORD func);
Stefan Dösingereea2c952008-07-12 11:45:33 -05001914BOOL is_invalid_op(IWineD3DDeviceImpl *This, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
Stefan Dösingerbd682372008-03-29 13:55:59 +01001915void 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 -05001916void 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 +02001917void texture_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
Stefan Dösinger51e64b32008-07-04 12:06:58 -05001918void sampler_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
Stefan Dösinger88ae2fe2008-07-05 18:31:34 -05001919void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
1920void apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
Jason Edmeadesae5a4362004-09-28 02:12:12 +00001921
Henri Verbeeteaf24742008-09-24 15:56:47 +02001922void surface_force_reload(IWineD3DSurface *iface);
H. Verbeet1b9a5ba2007-04-16 21:20:25 +02001923GLenum surface_get_gl_buffer(IWineD3DSurface *iface, IWineD3DSwapChain *swapchain);
H. Verbeet4f77c292008-07-02 23:00:41 +02001924void surface_load_ds_location(IWineD3DSurface *iface, DWORD location);
Henri Verbeeteaf24742008-09-24 15:56:47 +02001925void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location);
1926void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height);
1927void surface_set_texture_name(IWineD3DSurface *iface, GLuint name);
1928void surface_set_texture_target(IWineD3DSurface *iface, GLenum target);
H. Verbeetc9b178b2007-04-09 01:53:32 +02001929
Roderick Colenbrander4647cbb2007-08-09 01:04:30 +02001930BOOL getColorBits(WINED3DFORMAT fmt, short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize);
1931BOOL getDepthStencilBits(WINED3DFORMAT fmt, short *depthSize, short *stencilSize);
1932
Stefan Dösinger9abdac62006-05-12 22:21:31 +02001933/* Math utils */
Andrew Talbotf3a515c2006-11-24 14:15:06 +00001934void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2);
Stefan Dösinger8273cfd2007-09-13 12:25:29 +02001935unsigned int count_bits(unsigned int mask);
Oliver Stieber8a6799d2005-07-07 20:35:05 +00001936
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001937/*****************************************************************************
1938 * To enable calling of inherited functions, requires prototypes
Jason Edmeades33025b22005-01-18 11:42:29 +00001939 *
1940 * Note: Only require classes which are subclassed, ie resource, basetexture,
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001941 */
1942 /*** IUnknown methods ***/
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001943 extern HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, void** ppvObject);
1944 extern ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface);
1945 extern ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface);
1946 /*** IWineD3DResource methods ***/
1947 extern HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent);
1948 extern HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice ** ppDevice);
1949 extern HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1950 extern HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1951 extern HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid);
1952 extern DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew);
1953 extern DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface);
1954 extern void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface);
Stefan Dösingere59ddb02008-01-12 22:56:30 +01001955 extern void WINAPI IWineD3DResourceImpl_UnLoad(IWineD3DResource *iface);
Stefan Dösinger913df5b2006-03-09 23:21:16 +01001956 extern WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface);
Oliver Stieber67f2ad42005-03-29 19:01:00 +00001957 /*** class static members ***/
1958 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface);
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001959
1960 /*** IUnknown methods ***/
1961 extern HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, void** ppvObject);
1962 extern ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface);
1963 extern ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface);
1964 /*** IWineD3DResource methods ***/
1965 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent);
1966 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice ** ppDevice);
1967 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void * pData, DWORD SizeOfData, DWORD Flags);
1968 extern HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void * pData, DWORD * pSizeOfData);
1969 extern HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid);
1970 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew);
1971 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface);
1972 extern void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface);
Stefan Dösingera0f2e6e2008-01-25 18:18:06 +01001973 extern void WINAPI IWineD3DBaseTextureImpl_UnLoad(IWineD3DBaseTexture *iface);
Stefan Dösinger913df5b2006-03-09 23:21:16 +01001974 extern WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface);
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001975 /*** IWineD3DBaseTexture methods ***/
1976 extern DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew);
1977 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface);
1978 extern DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface);
Stefan Dösinger63fd9a72006-04-06 19:02:16 +02001979 extern HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType);
1980 extern WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface);
Jason Edmeadesbcecddc2005-01-17 13:44:57 +00001981 extern void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface);
1982 extern BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL);
1983 extern BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface);
Raphael Junqueiracc8762a2005-07-24 17:11:33 +00001984
Stefan Dösinger7d31ab92006-06-21 15:01:38 +02001985 extern BYTE* WINAPI IWineD3DVertexBufferImpl_GetMemory(IWineD3DVertexBuffer* iface, DWORD iOffset, GLint *vbo);
Raphael Junqueiracc8762a2005-07-24 17:11:33 +00001986 extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
Oliver Stieber67f2ad42005-03-29 19:01:00 +00001987 extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
Oliver Stieberbb6f9b02005-08-03 11:00:28 +00001988 extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
Oliver Stieber67f2ad42005-03-29 19:01:00 +00001989 /*** class static members ***/
1990 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
Jason Edmeades41427852005-01-09 17:37:02 +00001991
H. Verbeet3ee642b2006-03-28 21:10:32 +02001992
Ivan Gyurdieva42925e2006-06-12 02:55:30 -04001993/* TODO: Make this dynamic, based on shader limits ? */
1994#define MAX_REG_ADDR 1
1995#define MAX_REG_TEMP 32
1996#define MAX_REG_TEXCRD 8
Ivan Gyurdieva1f4dfe2006-06-12 02:57:07 -04001997#define MAX_REG_INPUT 12
1998#define MAX_REG_OUTPUT 12
Jason Green34d271b2006-06-16 16:07:31 -04001999#define MAX_CONST_I 16
2000#define MAX_CONST_B 16
Ivan Gyurdiev9bae7752006-06-12 02:53:32 -04002001
Ivan Gyurdiev33293df2006-07-10 04:35:15 -06002002/* FIXME: This needs to go up to 2048 for
2003 * Shader model 3 according to msdn (and for software shaders) */
2004#define MAX_LABELS 16
2005
Ivan Gyurdiev5b3c5002006-07-07 00:27:38 -06002006typedef struct semantic {
2007 DWORD usage;
2008 DWORD reg;
2009} semantic;
2010
Ivan Gyurdieve9de5632006-07-09 22:51:03 -06002011typedef struct local_constant {
2012 struct list entry;
2013 unsigned int idx;
2014 DWORD value[4];
2015} local_constant;
2016
Ivan Gyurdieva42925e2006-06-12 02:55:30 -04002017typedef struct shader_reg_maps {
2018
2019 char texcoord[MAX_REG_TEXCRD]; /* pixel < 3.0 */
2020 char temporary[MAX_REG_TEMP]; /* pixel, vertex */
2021 char address[MAX_REG_ADDR]; /* vertex */
Ivan Gyurdieva1f4dfe2006-06-12 02:57:07 -04002022 char packed_input[MAX_REG_INPUT]; /* pshader >= 3.0 */
2023 char packed_output[MAX_REG_OUTPUT]; /* vertex >= 3.0 */
Ivan Gyurdieva42925e2006-06-12 02:55:30 -04002024 char attributes[MAX_ATTRIBS]; /* vertex */
Ivan Gyurdiev33293df2006-07-10 04:35:15 -06002025 char labels[MAX_LABELS]; /* pixel, vertex */
Stefan Dösinger54fa7122007-12-06 22:10:11 +01002026 DWORD texcoord_mask[MAX_REG_TEXCRD]; /* vertex < 3.0 */
Ivan Gyurdieva42925e2006-06-12 02:55:30 -04002027
Ivan Gyurdiev0d083162006-06-12 02:59:16 -04002028 /* Sampler usage tokens
2029 * Use 0 as default (bit 31 is always 1 on a valid token) */
H. Verbeet5b7758f2007-06-25 22:45:40 +02002030 DWORD samplers[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)];
Stefan Dösinger167a2712008-03-05 03:18:55 +01002031 BOOL bumpmat[MAX_TEXTURES], luminanceparams[MAX_TEXTURES];
Stefan Dösinger8f3accc2007-10-13 13:03:56 +02002032 char usesnrm, vpos, usesdsy;
Stefan Dösingeredb78182007-11-09 14:48:47 +01002033 char usesrelconstF;
Ivan Gyurdiev0d083162006-06-12 02:59:16 -04002034
Stefan Dösinger3f16f022007-09-14 13:21:52 +02002035 /* Whether or not loops are used in this shader, and nesting depth */
2036 unsigned loop_depth;
Jason Greencc06ed32006-06-13 22:32:14 -04002037
Jason Green6a97f222006-07-17 01:41:53 -04002038 /* Whether or not this shader uses fog */
2039 char fog;
2040
Jason Green0c59ca62006-06-09 03:33:01 -04002041} shader_reg_maps;
2042
Ivan Gyurdiev6ede5642006-07-10 03:11:35 -06002043/* Undocumented opcode controls */
2044#define INST_CONTROLS_SHIFT 16
2045#define INST_CONTROLS_MASK 0x00ff0000
2046
2047typedef enum COMPARISON_TYPE {
2048 COMPARISON_GT = 1,
2049 COMPARISON_EQ = 2,
2050 COMPARISON_GE = 3,
2051 COMPARISON_LT = 4,
2052 COMPARISON_NE = 5,
2053 COMPARISON_LE = 6
2054} COMPARISON_TYPE;
2055
Ivan Gyurdievcdfe8482006-05-09 18:05:26 -04002056typedef struct SHADER_OPCODE {
2057 unsigned int opcode;
2058 const char* name;
2059 const char* glname;
Ivan Gyurdiev8c6ee8d2006-06-12 06:57:04 -04002060 char dst_token;
Ivan Gyurdievcdfe8482006-05-09 18:05:26 -04002061 CONST UINT num_params;
Henri Verbeet2e769542008-09-23 17:39:34 +02002062 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
Ivan Gyurdievcdfe8482006-05-09 18:05:26 -04002063 DWORD min_version;
2064 DWORD max_version;
2065} SHADER_OPCODE;
2066
2067typedef struct SHADER_OPCODE_ARG {
2068 IWineD3DBaseShader* shader;
Jason Green0c59ca62006-06-09 03:33:01 -04002069 shader_reg_maps* reg_maps;
Ivan Gyurdievcdfe8482006-05-09 18:05:26 -04002070 CONST SHADER_OPCODE* opcode;
Ivan Gyurdiev6ede5642006-07-10 03:11:35 -06002071 DWORD opcode_token;
Ivan Gyurdievcdfe8482006-05-09 18:05:26 -04002072 DWORD dst;
Ivan Gyurdiev03b67e32006-05-17 02:04:30 -04002073 DWORD dst_addr;
Ivan Gyurdiev42b89792006-05-17 21:09:56 -04002074 DWORD predicate;
Ivan Gyurdievcdfe8482006-05-09 18:05:26 -04002075 DWORD src[4];
Ivan Gyurdiev03b67e32006-05-17 02:04:30 -04002076 DWORD src_addr[4];
Ivan Gyurdievcdfe8482006-05-09 18:05:26 -04002077 SHADER_BUFFER* buffer;
2078} SHADER_OPCODE_ARG;
2079
Ivan Gyurdievc93239d2006-05-08 17:09:21 -04002080typedef struct SHADER_LIMITS {
2081 unsigned int temporary;
Ivan Gyurdiev0d083162006-06-12 02:59:16 -04002082 unsigned int texcoord;
2083 unsigned int sampler;
Ivan Gyurdievc93239d2006-05-08 17:09:21 -04002084 unsigned int constant_int;
2085 unsigned int constant_float;
2086 unsigned int constant_bool;
2087 unsigned int address;
Ivan Gyurdieva1f4dfe2006-06-12 02:57:07 -04002088 unsigned int packed_output;
2089 unsigned int packed_input;
Jason Green473ce802006-05-26 11:52:33 -04002090 unsigned int attributes;
Ivan Gyurdiev33293df2006-07-10 04:35:15 -06002091 unsigned int label;
Ivan Gyurdievc93239d2006-05-08 17:09:21 -04002092} SHADER_LIMITS;
2093
Jason Green653e71d2006-05-09 22:30:11 -04002094/** Keeps track of details for TEX_M#x# shader opcodes which need to
2095 maintain state information between multiple codes */
2096typedef struct SHADER_PARSE_STATE {
2097 unsigned int current_row;
2098 DWORD texcoord_w[2];
2099} SHADER_PARSE_STATE;
2100
Alexandre Julliard57d15482007-11-28 12:55:11 +01002101#ifdef __GNUC__
2102#define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
2103#else
2104#define PRINTF_ATTR(fmt,args)
2105#endif
2106
Ivan Gyurdiev5f105602006-05-08 15:44:25 -04002107/* Base Shader utility functions.
2108 * (may move callers into the same file in the future) */
2109extern int shader_addline(
2110 SHADER_BUFFER* buffer,
Alexandre Julliard57d15482007-11-28 12:55:11 +01002111 const char* fmt, ...) PRINTF_ATTR(2,3);
Ivan Gyurdiev5f105602006-05-08 15:44:25 -04002112
Ivan Gyurdiev1d0c6722006-05-09 07:57:36 -04002113extern const SHADER_OPCODE* shader_get_opcode(
2114 IWineD3DBaseShader *iface,
2115 const DWORD code);
2116
Ivan Gyurdiev5b3c5002006-07-07 00:27:38 -06002117/* Vertex shader utility functions */
2118extern BOOL vshader_get_input(
2119 IWineD3DVertexShader* iface,
2120 BYTE usage_req, BYTE usage_idx_req,
2121 unsigned int* regnum);
2122
2123extern BOOL vshader_input_is_color(
2124 IWineD3DVertexShader* iface,
2125 unsigned int regnum);
2126
Jason Green718716b2006-07-19 00:06:07 -04002127extern HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object);
2128
Jason Greencc06ed32006-06-13 22:32:14 -04002129/* GLSL helper functions */
Jason Greencc06ed32006-06-13 22:32:14 -04002130extern void shader_glsl_add_instruction_modifiers(SHADER_OPCODE_ARG *arg);
Jason Greend5d45682006-06-09 03:37:45 -04002131
Raphael Junqueira01968612003-11-14 03:50:35 +00002132/*****************************************************************************
H. Verbeet59af5c42006-03-30 19:14:31 +02002133 * IDirect3DBaseShader implementation structure
2134 */
2135typedef struct IWineD3DBaseShaderClass
2136{
Stefan Dösingerbd975802007-11-16 21:01:33 +01002137 LONG ref;
Ivan Gyurdievc93239d2006-05-08 17:09:21 -04002138 DWORD hex_version;
2139 SHADER_LIMITS limits;
Jason Green653e71d2006-05-09 22:30:11 -04002140 SHADER_PARSE_STATE parse_state;
H. Verbeet59af5c42006-03-30 19:14:31 +02002141 CONST SHADER_OPCODE *shader_ins;
Stefan Dösinger7a97d4e2007-11-16 21:02:29 +01002142 DWORD *function;
H. Verbeet59af5c42006-03-30 19:14:31 +02002143 UINT functionLength;
H. Verbeetef87a402006-08-05 18:15:35 +02002144 BOOL is_compiled;
Stefan Dösinger3f16f022007-09-14 13:21:52 +02002145 UINT cur_loop_depth, cur_loop_regno;
Stefan Dösingeredb78182007-11-09 14:48:47 +01002146 BOOL load_local_constsF;
Ivan Gyurdiev77162362006-07-04 01:21:53 -06002147
2148 /* Type of shader backend */
2149 int shader_mode;
2150
H. Verbeet2c85e5e2007-02-27 20:51:53 +01002151 /* Programs this shader is linked with */
2152 struct list linked_programs;
2153
Ivan Gyurdieve9de5632006-07-09 22:51:03 -06002154 /* Immediate constants (override global ones) */
2155 struct list constantsB;
2156 struct list constantsF;
2157 struct list constantsI;
H. Verbeetef87a402006-08-05 18:15:35 +02002158 shader_reg_maps reg_maps;
Ivan Gyurdieve9de5632006-07-09 22:51:03 -06002159
Stefan Dösinger1c4a15d2007-09-21 23:47:40 +02002160 /* Pixel formats of sampled textures, for format conversion. This
2161 * represents the formats found during compilation, it is not initialized
2162 * on the first parser pass. It is needed to check if the shader
2163 * needs recompilation to adjust the format conversion
2164 */
2165 WINED3DFORMAT sampled_format[MAX_COMBINED_SAMPLERS];
2166 UINT sampled_samplers[MAX_COMBINED_SAMPLERS];
2167 UINT num_sampled_samplers;
2168
2169 UINT recompile_count;
2170
Ivan Gyurdievd0032a12006-09-27 07:14:46 -04002171 /* Pointer to the parent device */
2172 IWineD3DDevice *device;
Stefan Dösinger09bf3d52008-01-08 20:45:59 +01002173 struct list shader_list_entry;
Ivan Gyurdievd0032a12006-09-27 07:14:46 -04002174
H. Verbeet59af5c42006-03-30 19:14:31 +02002175} IWineD3DBaseShaderClass;
2176
2177typedef struct IWineD3DBaseShaderImpl {
2178 /* IUnknown */
2179 const IWineD3DBaseShaderVtbl *lpVtbl;
H. Verbeet59af5c42006-03-30 19:14:31 +02002180
2181 /* IWineD3DBaseShader */
2182 IWineD3DBaseShaderClass baseShader;
2183} IWineD3DBaseShaderImpl;
2184
Stefan Dösingerbd975802007-11-16 21:01:33 +01002185HRESULT WINAPI IWineD3DBaseShaderImpl_QueryInterface(IWineD3DBaseShader *iface, REFIID riid, LPVOID *ppobj);
2186ULONG WINAPI IWineD3DBaseShaderImpl_AddRef(IWineD3DBaseShader *iface);
2187ULONG WINAPI IWineD3DBaseShaderImpl_Release(IWineD3DBaseShader *iface);
2188
Ivan Gyurdieve9de5632006-07-09 22:51:03 -06002189extern HRESULT shader_get_registers_used(
Ivan Gyurdiev9bae7752006-06-12 02:53:32 -04002190 IWineD3DBaseShader *iface,
2191 shader_reg_maps* reg_maps,
Ivan Gyurdiev5b3c5002006-07-07 00:27:38 -06002192 semantic* semantics_in,
2193 semantic* semantics_out,
Stefan Dösinger760456d2006-08-27 19:16:01 +02002194 CONST DWORD* pToken,
2195 IWineD3DStateBlockImpl *stateBlock);
Ivan Gyurdiev9bae7752006-06-12 02:53:32 -04002196
2197extern void shader_generate_main(
Jason Green36b0b9c2006-05-09 22:33:24 -04002198 IWineD3DBaseShader *iface,
2199 SHADER_BUFFER* buffer,
Ivan Gyurdiev9bae7752006-06-12 02:53:32 -04002200 shader_reg_maps* reg_maps,
Jason Green36b0b9c2006-05-09 22:33:24 -04002201 CONST DWORD* pFunction);
2202
Ivan Gyurdievc61af3a2006-05-10 13:53:07 -04002203extern void shader_dump_ins_modifiers(
2204 const DWORD output);
2205
Ivan Gyurdiev8b7401c2006-05-14 09:43:31 -04002206extern void shader_dump_param(
2207 IWineD3DBaseShader *iface,
2208 const DWORD param,
Ivan Gyurdiev746d1b12006-05-17 02:05:49 -04002209 const DWORD addr_token,
Ivan Gyurdiev8b7401c2006-05-14 09:43:31 -04002210 int input);
2211
Ivan Gyurdiev17b0d262006-06-12 02:54:30 -04002212extern void shader_trace_init(
2213 IWineD3DBaseShader *iface,
2214 const DWORD* pFunction);
2215
Ivan Gyurdiev404eff72006-05-17 02:02:36 -04002216extern int shader_get_param(
2217 IWineD3DBaseShader* iface,
2218 const DWORD* pToken,
2219 DWORD* param,
2220 DWORD* addr_token);
2221
2222extern int shader_skip_unrecognized(
2223 IWineD3DBaseShader* iface,
2224 const DWORD* pToken);
2225
Andrew Talbot2f5f3822007-03-17 10:39:40 +00002226static inline int shader_get_regtype(const DWORD param) {
Ivan Gyurdiev17c9d952006-10-09 19:47:12 -04002227 return (((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT) |
2228 ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2));
Ivan Gyurdiev4b307942006-04-28 05:20:48 -04002229}
2230
Stefan Dösinger54fa7122007-12-06 22:10:11 +01002231static inline int shader_get_writemask(const DWORD param) {
2232 return param & WINED3DSP_WRITEMASK_ALL;
2233}
2234
Ivan Gyurdievaec2e3e2006-06-06 02:40:08 -04002235extern unsigned int shader_get_float_offset(const DWORD reg);
2236
Andrew Talbot2f5f3822007-03-17 10:39:40 +00002237static inline BOOL shader_is_pshader_version(DWORD token) {
Ivan Gyurdiev8b7401c2006-05-14 09:43:31 -04002238 return 0xFFFF0000 == (token & 0xFFFF0000);
2239}
2240
Andrew Talbot2f5f3822007-03-17 10:39:40 +00002241static inline BOOL shader_is_vshader_version(DWORD token) {
Ivan Gyurdiev8b7401c2006-05-14 09:43:31 -04002242 return 0xFFFE0000 == (token & 0xFFFF0000);
2243}
2244
Andrew Talbot2f5f3822007-03-17 10:39:40 +00002245static inline BOOL shader_is_comment(DWORD token) {
Ivan Gyurdiev29aa3162006-10-12 23:34:13 -04002246 return WINED3DSIO_COMMENT == (token & WINED3DSI_OPCODE_MASK);
Ivan Gyurdiev8b7401c2006-05-14 09:43:31 -04002247}
2248
H. Verbeeta79654d2007-04-12 23:55:31 +02002249static inline BOOL shader_is_scalar(DWORD param) {
2250 DWORD reg_type = shader_get_regtype(param);
Stefan Dösinger81de2fa2008-02-11 12:04:57 +01002251 DWORD reg_num;
H. Verbeeta79654d2007-04-12 23:55:31 +02002252
2253 switch (reg_type) {
2254 case WINED3DSPR_RASTOUT:
2255 if ((param & WINED3DSP_REGNUM_MASK) != 0) {
2256 /* oFog & oPts */
2257 return TRUE;
2258 }
2259 /* oPos */
2260 return FALSE;
2261
2262 case WINED3DSPR_DEPTHOUT: /* oDepth */
2263 case WINED3DSPR_CONSTBOOL: /* b# */
2264 case WINED3DSPR_LOOP: /* aL */
2265 case WINED3DSPR_PREDICATE: /* p0 */
2266 return TRUE;
2267
Stefan Dösinger81de2fa2008-02-11 12:04:57 +01002268 case WINED3DSPR_MISCTYPE:
2269 reg_num = param & WINED3DSP_REGNUM_MASK;
2270 switch(reg_num) {
2271 case 0: /* vPos */
2272 return FALSE;
2273 case 1: /* vFace */
2274 return TRUE;
2275 default:
2276 return FALSE;
2277 }
2278
H. Verbeeta79654d2007-04-12 23:55:31 +02002279 default:
2280 return FALSE;
2281 }
2282}
2283
Stefan Dösingeraeb0e432008-02-14 14:15:49 +01002284static inline BOOL shader_constant_is_local(IWineD3DBaseShaderImpl* This, DWORD reg) {
2285 local_constant* lconst;
2286
2287 if(This->baseShader.load_local_constsF) return FALSE;
2288 LIST_FOR_EACH_ENTRY(lconst, &This->baseShader.constantsF, local_constant, entry) {
2289 if(lconst->idx == reg) return TRUE;
2290 }
2291 return FALSE;
2292
2293}
2294
H. Verbeet59af5c42006-03-30 19:14:31 +02002295/*****************************************************************************
Raphael Junqueira01968612003-11-14 03:50:35 +00002296 * IDirect3DVertexShader implementation structure
2297 */
Oliver Stieber2121f782005-03-02 12:16:10 +00002298typedef struct IWineD3DVertexShaderImpl {
2299 /* IUnknown parts*/
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002300 const IWineD3DVertexShaderVtbl *lpVtbl;
Raphael Junqueira01968612003-11-14 03:50:35 +00002301
H. Verbeet59af5c42006-03-30 19:14:31 +02002302 /* IWineD3DBaseShader */
2303 IWineD3DBaseShaderClass baseShader;
2304
2305 /* IWineD3DVertexShaderImpl */
Oliver Stieber2121f782005-03-02 12:16:10 +00002306 IUnknown *parent;
Raphael Junqueira01968612003-11-14 03:50:35 +00002307
Jason Green6a97f222006-07-17 01:41:53 -04002308 DWORD usage;
Oliver Stieber2c0e97e2005-08-17 11:34:03 +00002309
Stefan Dösingeraed93052008-11-20 13:27:42 +01002310 /* The GL shader */
2311 GLuint prgId;
2312
Ivan Gyurdiev276609e2006-07-04 02:01:46 -06002313 /* Vertex shader input and output semantics */
Ivan Gyurdiev5b3c5002006-07-07 00:27:38 -06002314 semantic semantics_in [MAX_ATTRIBS];
2315 semantic semantics_out [MAX_REG_OUTPUT];
Ivan Gyurdiev276609e2006-07-04 02:01:46 -06002316
Stefan Dösinger95921232007-11-20 21:14:10 +01002317 /* Ordered array of attributes that are swizzled */
2318 attrib_declaration swizzled_attribs [MAX_ATTRIBS];
2319 UINT num_swizzled_attribs;
2320
Stefan Dösingerfb0dde7b2007-11-07 19:57:49 +01002321 UINT min_rel_offset, max_rel_offset;
2322 UINT rel_offset;
2323
Stefan Dösinger95921232007-11-20 21:14:10 +01002324 UINT recompile_count;
Oliver Stieber2121f782005-03-02 12:16:10 +00002325} IWineD3DVertexShaderImpl;
H. Verbeetd4132cf2006-03-28 21:10:44 +02002326extern const SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[];
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002327extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
Stefan Dösingerff767f42008-11-24 11:52:12 +01002328HRESULT IWineD3DVertexShaderImpl_CompileShader(IWineD3DVertexShader *iface);
Raphael Junqueira01968612003-11-14 03:50:35 +00002329
2330/*****************************************************************************
2331 * IDirect3DPixelShader implementation structure
2332 */
Stefan Dösinger3febe732007-10-26 02:11:00 +02002333
2334enum vertexprocessing_mode {
2335 fixedfunction,
2336 vertexshader,
2337 pretransformed
2338};
2339
Stefan Dösinger167a2712008-03-05 03:18:55 +01002340struct stb_const_desc {
2341 char texunit;
2342 UINT const_num;
2343};
2344
Stefan Dösingerdd890552008-11-20 02:55:17 +01002345/* Stateblock dependent parameters which have to be hardcoded
2346 * into the shader code
2347 */
2348struct ps_compile_args {
2349 BOOL srgb_correction;
2350 WINED3DFORMAT format_conversion[MAX_FRAGMENT_SAMPLERS];
2351 enum vertexprocessing_mode vp_mode;
Stefan Dösinger0bf32b12008-11-24 11:55:50 +01002352 /* Projected textures(ps 1.0-1.3) */
2353 /* Texture types(2D, Cube, 3D) in ps 1.x */
2354};
2355
2356struct ps_compiled_shader {
2357 struct ps_compile_args args;
2358 GLuint prgId;
Stefan Dösingerdd890552008-11-20 02:55:17 +01002359};
2360
Oliver Stieber2121f782005-03-02 12:16:10 +00002361typedef struct IWineD3DPixelShaderImpl {
Oliver Stieberb3563da2005-09-28 10:13:00 +00002362 /* IUnknown parts */
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002363 const IWineD3DPixelShaderVtbl *lpVtbl;
Oliver Stieberb3563da2005-09-28 10:13:00 +00002364
H. Verbeet59af5c42006-03-30 19:14:31 +02002365 /* IWineD3DBaseShader */
2366 IWineD3DBaseShaderClass baseShader;
2367
2368 /* IWineD3DPixelShaderImpl */
Oliver Stieber2121f782005-03-02 12:16:10 +00002369 IUnknown *parent;
Raphael Junqueira01968612003-11-14 03:50:35 +00002370
Ivan Gyurdiev276609e2006-07-04 02:01:46 -06002371 /* Pixel shader input semantics */
Ivan Gyurdiev5b3c5002006-07-07 00:27:38 -06002372 semantic semantics_in [MAX_REG_INPUT];
Stefan Dösinger409103f2007-10-28 00:12:37 +02002373 DWORD input_reg_map[MAX_REG_INPUT];
Stefan Dösinger1b23dd12007-11-06 12:34:22 +01002374 BOOL input_reg_used[MAX_REG_INPUT];
H. Verbeeta6fa6a42008-06-19 00:36:35 +02002375 int declared_in_count;
Ivan Gyurdiev276609e2006-07-04 02:01:46 -06002376
Stefan Dösingeraed93052008-11-20 13:27:42 +01002377 /* The GL shader */
Stefan Dösinger0bf32b12008-11-24 11:55:50 +01002378 struct ps_compiled_shader *gl_shaders;
2379 UINT num_gl_shaders;
Stefan Dösingeraed93052008-11-20 13:27:42 +01002380
Stefan Dösinger49a49fc2007-02-15 03:05:17 +01002381 /* Some information about the shader behavior */
Stefan Dösinger167a2712008-03-05 03:18:55 +01002382 struct stb_const_desc bumpenvmatconst[MAX_TEXTURES];
2383 char numbumpenvmatconsts;
2384 struct stb_const_desc luminanceconst[MAX_TEXTURES];
Stefan Dösinger9c6cdda2007-09-14 13:11:00 +02002385 char vpos_uniform;
Oliver Stieber2121f782005-03-02 12:16:10 +00002386} IWineD3DPixelShaderImpl;
2387
H. Verbeetd4132cf2006-03-28 21:10:44 +02002388extern const SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[];
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +00002389extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
Stefan Dösinger0bf32b12008-11-24 11:55:50 +01002390GLuint find_gl_pshader(IWineD3DPixelShaderImpl *shader, struct ps_compile_args *args);
Stefan Dösingerdd890552008-11-20 02:55:17 +01002391void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct ps_compile_args *args);
Stefan Dösingercff4e1e2006-04-17 17:04:59 +02002392
Stefan Dösinger6313e0f2007-09-14 13:02:59 +02002393/* sRGB correction constants */
2394static const float srgb_cmp = 0.0031308;
2395static const float srgb_mul_low = 12.92;
2396static const float srgb_pow = 0.41666;
2397static const float srgb_mul_high = 1.055;
2398static const float srgb_sub_high = 0.055;
2399
Stefan Dösingercff4e1e2006-04-17 17:04:59 +02002400/*****************************************************************************
2401 * IWineD3DPalette implementation structure
2402 */
2403struct IWineD3DPaletteImpl {
2404 /* IUnknown parts */
2405 const IWineD3DPaletteVtbl *lpVtbl;
2406 LONG ref;
Stefan Dösingera6f71af2006-04-21 00:00:30 +02002407
2408 IUnknown *parent;
2409 IWineD3DDeviceImpl *wineD3DDevice;
2410
2411 /* IWineD3DPalette */
2412 HPALETTE hpal;
2413 WORD palVersion; /*| */
2414 WORD palNumEntries; /*| LOGPALETTE */
2415 PALETTEENTRY palents[256]; /*| */
2416 /* This is to store the palette in 'screen format' */
2417 int screen_palents[256];
2418 DWORD Flags;
Stefan Dösingercff4e1e2006-04-17 17:04:59 +02002419};
2420
2421extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
Stefan Dösingera6f71af2006-04-21 00:00:30 +02002422DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
Stefan Dösingercff4e1e2006-04-17 17:04:59 +02002423
Stefan Dösingera6206832006-04-18 23:04:51 +02002424/* DirectDraw utility functions */
2425extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
2426
Stefan Dösinger35187472006-06-21 10:36:14 +02002427/*****************************************************************************
2428 * Pixel format management
2429 */
2430typedef struct {
2431 WINED3DFORMAT format;
2432 DWORD alphaMask, redMask, greenMask, blueMask;
2433 UINT bpp;
Roderick Colenbrander4647cbb2007-08-09 01:04:30 +02002434 short depthSize, stencilSize;
Stefan Dösinger35187472006-06-21 10:36:14 +02002435 BOOL isFourcc;
Stefan Dösingera0131a32007-07-23 11:13:37 +02002436} StaticPixelFormatDesc;
Stefan Dösinger35187472006-06-21 10:36:14 +02002437
Stefan Dösingera0131a32007-07-23 11:13:37 +02002438const StaticPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt,
Henri Verbeeteb78c2a2008-11-25 14:36:08 +01002439 const WineD3D_GL_Info *gl_info, const GlPixelFormatDesc **glDesc);
H. Verbeet30ee0712007-03-12 23:22:00 +01002440
Andrew Talbot2f5f3822007-03-17 10:39:40 +00002441static inline BOOL use_vs(IWineD3DDeviceImpl *device) {
H. Verbeet30ee0712007-03-12 23:22:00 +01002442 return (device->vs_selected_mode != SHADER_NONE
2443 && device->stateBlock->vertexShader
2444 && ((IWineD3DVertexShaderImpl *)device->stateBlock->vertexShader)->baseShader.function
2445 && !device->strided_streams.u.s.position_transformed);
2446}
2447
Andrew Talbot2f5f3822007-03-17 10:39:40 +00002448static inline BOOL use_ps(IWineD3DDeviceImpl *device) {
H. Verbeet30ee0712007-03-12 23:22:00 +01002449 return (device->ps_selected_mode != SHADER_NONE
2450 && device->stateBlock->pixelShader
2451 && ((IWineD3DPixelShaderImpl *)device->stateBlock->pixelShader)->baseShader.function);
2452}
2453
H. Verbeetd9b73692007-05-03 20:57:09 +02002454void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED3DRECT *src_rect,
H. Verbeetd7c7cbf2007-07-24 23:38:40 +02002455 IWineD3DSurface *dst_surface, WINED3DRECT *dst_rect, const WINED3DTEXTUREFILTERTYPE filter, BOOL flip);
Raphael Junqueira01968612003-11-14 03:50:35 +00002456#endif