usp10: Merge GSUB_initialize_script_cache() and GPOS_expand_script_cache().
[wine.git] / dlls / d3dx9_36 / d3dx9_private.h
blob5ac5e63aeb6e8c572027a23627a4086d7146419f
1 /*
2 * Copyright (C) 2002 Raphael Junqueira
3 * Copyright (C) 2008 David Adam
4 * Copyright (C) 2008 Tony Wasserka
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #ifndef __WINE_D3DX9_PRIVATE_H
23 #define __WINE_D3DX9_PRIVATE_H
25 #define NONAMELESSUNION
26 #include "wine/debug.h"
28 #define COBJMACROS
29 #include "d3dx9.h"
31 #define ULONG64_MAX (~(ULONG64)0)
33 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
35 struct vec4
37 float x, y, z, w;
40 struct volume
42 UINT width;
43 UINT height;
44 UINT depth;
47 /* for internal use */
48 enum format_type {
49 FORMAT_ARGB, /* unsigned */
50 FORMAT_ARGBF16,/* float 16 */
51 FORMAT_ARGBF, /* float */
52 FORMAT_DXT,
53 FORMAT_INDEX,
54 FORMAT_UNKNOWN
57 struct pixel_format_desc {
58 D3DFORMAT format;
59 BYTE bits[4];
60 BYTE shift[4];
61 UINT bytes_per_pixel;
62 UINT block_width;
63 UINT block_height;
64 UINT block_byte_count;
65 enum format_type type;
66 void (*from_rgba)(const struct vec4 *src, struct vec4 *dst);
67 void (*to_rgba)(const struct vec4 *src, struct vec4 *dst, const PALETTEENTRY *palette);
70 static inline BOOL is_conversion_from_supported(const struct pixel_format_desc *format)
72 if (format->type == FORMAT_ARGB || format->type == FORMAT_ARGBF16
73 || format->type == FORMAT_ARGBF)
74 return TRUE;
75 return !!format->to_rgba;
78 static inline BOOL is_conversion_to_supported(const struct pixel_format_desc *format)
80 if (format->type == FORMAT_ARGB || format->type == FORMAT_ARGBF16
81 || format->type == FORMAT_ARGBF)
82 return TRUE;
83 return !!format->from_rgba;
86 HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length) DECLSPEC_HIDDEN;
87 HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN;
89 HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer) DECLSPEC_HIDDEN;
91 const struct pixel_format_desc *get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN;
92 const struct pixel_format_desc *get_format_info_idx(int idx) DECLSPEC_HIDDEN;
94 void copy_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
95 BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *size,
96 const struct pixel_format_desc *format) DECLSPEC_HIDDEN;
97 void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
98 const struct volume *src_size, const struct pixel_format_desc *src_format,
99 BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size,
100 const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette) DECLSPEC_HIDDEN;
101 void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
102 const struct volume *src_size, const struct pixel_format_desc *src_format,
103 BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size,
104 const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette) DECLSPEC_HIDDEN;
106 HRESULT load_texture_from_dds(IDirect3DTexture9 *texture, const void *src_data, const PALETTEENTRY *palette,
107 DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info, unsigned int skip_levels,
108 unsigned int *loaded_miplevels) DECLSPEC_HIDDEN;
109 HRESULT load_cube_texture_from_dds(IDirect3DCubeTexture9 *cube_texture, const void *src_data,
110 const PALETTEENTRY *palette, DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
111 HRESULT load_volume_from_dds(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette,
112 const D3DBOX *dst_box, const void *src_data, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key,
113 const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
114 HRESULT load_volume_texture_from_dds(IDirect3DVolumeTexture9 *volume_texture, const void *src_data,
115 const PALETTEENTRY *palette, DWORD filter, DWORD color_key, const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
117 unsigned short float_32_to_16(const float in) DECLSPEC_HIDDEN;
118 float float_16_to_32(const unsigned short in) DECLSPEC_HIDDEN;
120 /* debug helpers */
121 const char *debug_d3dxparameter_class(D3DXPARAMETER_CLASS c) DECLSPEC_HIDDEN;
122 const char *debug_d3dxparameter_type(D3DXPARAMETER_TYPE t) DECLSPEC_HIDDEN;
123 const char *debug_d3dxparameter_registerset(D3DXREGISTER_SET r) DECLSPEC_HIDDEN;
125 /* parameter type conversion helpers */
126 static inline BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
128 switch (type)
130 case D3DXPT_FLOAT:
131 case D3DXPT_INT:
132 case D3DXPT_BOOL:
133 return !!*(DWORD *)data;
135 case D3DXPT_VOID:
136 return *(BOOL *)data;
138 default:
139 return FALSE;
143 static inline int get_int(D3DXPARAMETER_TYPE type, const void *data)
145 switch (type)
147 case D3DXPT_FLOAT:
148 return (int)(*(float *)data);
150 case D3DXPT_INT:
151 case D3DXPT_VOID:
152 return *(int *)data;
154 case D3DXPT_BOOL:
155 return get_bool(type, data);
157 default:
158 return 0;
162 static inline float get_float(D3DXPARAMETER_TYPE type, const void *data)
164 switch (type)
166 case D3DXPT_FLOAT:
167 case D3DXPT_VOID:
168 return *(float *)data;
170 case D3DXPT_INT:
171 return (float)(*(int *)data);
173 case D3DXPT_BOOL:
174 return (float)get_bool(type, data);
176 default:
177 return 0.0f;
181 static inline void set_number(void *outdata, D3DXPARAMETER_TYPE outtype, const void *indata, D3DXPARAMETER_TYPE intype)
183 if (outtype == intype)
185 *(DWORD *)outdata = *(DWORD *)indata;
186 return;
189 switch (outtype)
191 case D3DXPT_FLOAT:
192 *(float *)outdata = get_float(intype, indata);
193 break;
195 case D3DXPT_BOOL:
196 *(BOOL *)outdata = get_bool(intype, indata);
197 break;
199 case D3DXPT_INT:
200 *(int *)outdata = get_int(intype, indata);
201 break;
203 default:
204 *(DWORD *)outdata = 0;
205 break;
209 static inline BOOL is_param_type_sampler(D3DXPARAMETER_TYPE type)
211 return type == D3DXPT_SAMPLER
212 || type == D3DXPT_SAMPLER1D || type == D3DXPT_SAMPLER2D
213 || type == D3DXPT_SAMPLER3D || type == D3DXPT_SAMPLERCUBE;
216 struct d3dx_parameter;
218 enum pres_reg_tables
220 PRES_REGTAB_IMMED,
221 PRES_REGTAB_CONST,
222 PRES_REGTAB_OCONST,
223 PRES_REGTAB_OBCONST,
224 PRES_REGTAB_OICONST,
225 PRES_REGTAB_TEMP,
226 PRES_REGTAB_COUNT,
227 PRES_REGTAB_FIRST_SHADER = PRES_REGTAB_CONST,
230 struct d3dx_const_param_eval_output
232 struct d3dx_parameter *param;
233 enum pres_reg_tables table;
234 enum D3DXPARAMETER_CLASS constant_class;
235 unsigned int register_index;
236 unsigned int register_count;
237 BOOL direct_copy;
238 unsigned int element_count;
241 struct d3dx_const_tab
243 unsigned int input_count;
244 D3DXCONSTANT_DESC *inputs;
245 struct d3dx_parameter **inputs_param;
246 unsigned int const_set_count;
247 unsigned int const_set_size;
248 struct d3dx_const_param_eval_output *const_set;
249 const enum pres_reg_tables *regset2table;
250 ULONG64 update_version;
253 struct d3dx_regstore
255 void *tables[PRES_REGTAB_COUNT];
256 unsigned int table_sizes[PRES_REGTAB_COUNT]; /* registers count */
259 struct d3dx_pres_ins;
261 struct d3dx_preshader
263 struct d3dx_regstore regs;
265 unsigned int ins_count;
266 struct d3dx_pres_ins *ins;
268 struct d3dx_const_tab inputs;
271 struct d3dx_param_eval
273 D3DXPARAMETER_TYPE param_type;
275 struct d3dx_preshader pres;
276 struct d3dx_const_tab shader_inputs;
278 ULONG64 *version_counter;
281 struct d3dx_shared_data;
282 struct d3dx_top_level_parameter;
284 struct d3dx_parameter
286 char magic_string[4];
287 struct d3dx_top_level_parameter *top_level_param;
288 struct d3dx_param_eval *param_eval;
289 char *name;
290 void *data;
291 D3DXPARAMETER_CLASS class;
292 D3DXPARAMETER_TYPE type;
293 UINT rows;
294 UINT columns;
295 UINT element_count;
296 UINT member_count;
297 DWORD flags;
298 UINT bytes;
299 DWORD object_id;
301 struct d3dx_parameter *members;
302 char *semantic;
305 struct d3dx_top_level_parameter
307 struct d3dx_parameter param;
308 UINT annotation_count;
309 struct d3dx_parameter *annotations;
310 ULONG64 update_version;
311 ULONG64 *version_counter;
312 struct d3dx_shared_data *shared_data;
315 struct d3dx_shared_data
317 void *data;
318 struct d3dx_top_level_parameter **parameters;
319 unsigned int size, count;
320 ULONG64 update_version;
323 struct d3dx9_base_effect;
325 static inline BOOL is_top_level_parameter(struct d3dx_parameter *param)
327 return &param->top_level_param->param == param;
330 static inline struct d3dx_top_level_parameter
331 *top_level_parameter_from_parameter(struct d3dx_parameter *param)
333 return CONTAINING_RECORD(param, struct d3dx_top_level_parameter, param);
336 static inline ULONG64 next_update_version(ULONG64 *version_counter)
338 return ++*version_counter;
341 static inline BOOL is_top_level_param_dirty(struct d3dx_top_level_parameter *param, ULONG64 update_version)
343 struct d3dx_shared_data *shared_data;
345 if ((shared_data = param->shared_data))
346 return update_version < shared_data->update_version;
347 else
348 return update_version < param->update_version;
351 static inline BOOL is_param_dirty(struct d3dx_parameter *param, ULONG64 update_version)
353 return is_top_level_param_dirty(param->top_level_param, update_version);
356 struct d3dx_parameter *get_parameter_by_name(struct d3dx9_base_effect *base,
357 struct d3dx_parameter *parameter, const char *name) DECLSPEC_HIDDEN;
359 #define SET_D3D_STATE_(manager, device, method, args...) (manager ? manager->lpVtbl->method(manager, args) \
360 : device->lpVtbl->method(device, args))
361 #define SET_D3D_STATE(base_effect, args...) SET_D3D_STATE_(base_effect->manager, base_effect->device, args)
363 HRESULT d3dx_create_param_eval(struct d3dx9_base_effect *base_effect, void *byte_code,
364 unsigned int byte_code_size, D3DXPARAMETER_TYPE type,
365 struct d3dx_param_eval **peval, ULONG64 *version_counter,
366 const char **skip_constants, unsigned int skip_constants_count) DECLSPEC_HIDDEN;
367 void d3dx_free_param_eval(struct d3dx_param_eval *peval) DECLSPEC_HIDDEN;
368 HRESULT d3dx_evaluate_parameter(struct d3dx_param_eval *peval,
369 const struct d3dx_parameter *param, void *param_value) DECLSPEC_HIDDEN;
370 HRESULT d3dx_param_eval_set_shader_constants(ID3DXEffectStateManager *manager, struct IDirect3DDevice9 *device,
371 struct d3dx_param_eval *peval, BOOL update_all) DECLSPEC_HIDDEN;
372 BOOL is_param_eval_input_dirty(struct d3dx_param_eval *peval, ULONG64 update_version) DECLSPEC_HIDDEN;
374 struct ctab_constant {
375 D3DXCONSTANT_DESC desc;
376 WORD constantinfo_reserved;
377 struct ctab_constant *constants;
380 const struct ctab_constant *d3dx_shader_get_ctab_constant(ID3DXConstantTable *iface,
381 D3DXHANDLE constant) DECLSPEC_HIDDEN;
383 #endif /* __WINE_D3DX9_PRIVATE_H */