[AMSTREAM] We don't need to define WIDL_C_INLINE_WRAPPERS here anymore.
[reactos.git] / dll / directx / wine / d3dx9_36 / d3dx9_36_private.h
1 /*
2 * Copyright (C) 2002 Raphael Junqueira
3 * Copyright (C) 2008 David Adam
4 * Copyright (C) 2008 Tony Wasserka
5 *
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.
10 *
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.
15 *
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
19 *
20 */
21
22 #ifndef __WINE_D3DX9_36_PRIVATE_H
23 #define __WINE_D3DX9_36_PRIVATE_H
24
25 #include <config.h>
26 #include <wine/port.h>
27
28 #include <stdarg.h>
29
30 #define WIN32_NO_STATUS
31 #define _INC_WINDOWS
32 #define COM_NO_WINDOWS_H
33
34 #define COBJMACROS
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
37
38 #include <windef.h>
39 #include <winbase.h>
40 #include <wingdi.h>
41 #include <winuser.h>
42 #include <d3dx9.h>
43
44 #include <wine/unicode.h>
45
46 #include <wine/debug.h>
47 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
48
49 #define ULONG64_MAX (~(ULONG64)0)
50
51 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
52
53 struct vec4
54 {
55 float x, y, z, w;
56 };
57
58 struct volume
59 {
60 UINT width;
61 UINT height;
62 UINT depth;
63 };
64
65 /* for internal use */
66 enum format_type {
67 FORMAT_ARGB, /* unsigned */
68 FORMAT_ARGBF16,/* float 16 */
69 FORMAT_ARGBF, /* float */
70 FORMAT_DXT,
71 FORMAT_INDEX,
72 FORMAT_UNKNOWN
73 };
74
75 struct pixel_format_desc {
76 D3DFORMAT format;
77 BYTE bits[4];
78 BYTE shift[4];
79 UINT bytes_per_pixel;
80 UINT block_width;
81 UINT block_height;
82 UINT block_byte_count;
83 enum format_type type;
84 void (*from_rgba)(const struct vec4 *src, struct vec4 *dst);
85 void (*to_rgba)(const struct vec4 *src, struct vec4 *dst, const PALETTEENTRY *palette);
86 };
87
88 static inline BOOL is_conversion_from_supported(const struct pixel_format_desc *format)
89 {
90 if (format->type == FORMAT_ARGB || format->type == FORMAT_ARGBF16
91 || format->type == FORMAT_ARGBF)
92 return TRUE;
93 return !!format->to_rgba;
94 }
95
96 static inline BOOL is_conversion_to_supported(const struct pixel_format_desc *format)
97 {
98 if (format->type == FORMAT_ARGB || format->type == FORMAT_ARGBF16
99 || format->type == FORMAT_ARGBF)
100 return TRUE;
101 return !!format->from_rgba;
102 }
103
104 HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length) DECLSPEC_HIDDEN;
105 HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN;
106
107 HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer) DECLSPEC_HIDDEN;
108
109 const struct pixel_format_desc *get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN;
110 const struct pixel_format_desc *get_format_info_idx(int idx) DECLSPEC_HIDDEN;
111
112 void copy_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
113 BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *size,
114 const struct pixel_format_desc *format) DECLSPEC_HIDDEN;
115 void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
116 const struct volume *src_size, const struct pixel_format_desc *src_format,
117 BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size,
118 const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette) DECLSPEC_HIDDEN;
119 void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
120 const struct volume *src_size, const struct pixel_format_desc *src_format,
121 BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size,
122 const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette) DECLSPEC_HIDDEN;
123
124 HRESULT load_texture_from_dds(IDirect3DTexture9 *texture, const void *src_data, const PALETTEENTRY *palette,
125 DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info, unsigned int skip_levels,
126 unsigned int *loaded_miplevels) DECLSPEC_HIDDEN;
127 HRESULT load_cube_texture_from_dds(IDirect3DCubeTexture9 *cube_texture, const void *src_data,
128 const PALETTEENTRY *palette, DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
129 HRESULT load_volume_from_dds(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette,
130 const D3DBOX *dst_box, const void *src_data, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key,
131 const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
132 HRESULT load_volume_texture_from_dds(IDirect3DVolumeTexture9 *volume_texture, const void *src_data,
133 const PALETTEENTRY *palette, DWORD filter, DWORD color_key, const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
134 HRESULT save_dds_texture_to_memory(ID3DXBuffer **dst_buffer, IDirect3DBaseTexture9 *src_texture,
135 const PALETTEENTRY *src_palette) DECLSPEC_HIDDEN;
136
137 unsigned short float_32_to_16(const float in) DECLSPEC_HIDDEN;
138 float float_16_to_32(const unsigned short in) DECLSPEC_HIDDEN;
139
140 /* debug helpers */
141 const char *debug_d3dxparameter_class(D3DXPARAMETER_CLASS c) DECLSPEC_HIDDEN;
142 const char *debug_d3dxparameter_type(D3DXPARAMETER_TYPE t) DECLSPEC_HIDDEN;
143 const char *debug_d3dxparameter_registerset(D3DXREGISTER_SET r) DECLSPEC_HIDDEN;
144
145 /* parameter type conversion helpers */
146 static inline BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
147 {
148 switch (type)
149 {
150 case D3DXPT_FLOAT:
151 case D3DXPT_INT:
152 case D3DXPT_BOOL:
153 return !!*(DWORD *)data;
154
155 case D3DXPT_VOID:
156 return *(BOOL *)data;
157
158 default:
159 return FALSE;
160 }
161 }
162
163 static inline int get_int(D3DXPARAMETER_TYPE type, const void *data)
164 {
165 switch (type)
166 {
167 case D3DXPT_FLOAT:
168 return (int)(*(float *)data);
169
170 case D3DXPT_INT:
171 case D3DXPT_VOID:
172 return *(int *)data;
173
174 case D3DXPT_BOOL:
175 return get_bool(type, data);
176
177 default:
178 return 0;
179 }
180 }
181
182 static inline float get_float(D3DXPARAMETER_TYPE type, const void *data)
183 {
184 switch (type)
185 {
186 case D3DXPT_FLOAT:
187 case D3DXPT_VOID:
188 return *(float *)data;
189
190 case D3DXPT_INT:
191 return (float)(*(int *)data);
192
193 case D3DXPT_BOOL:
194 return (float)get_bool(type, data);
195
196 default:
197 return 0.0f;
198 }
199 }
200
201 static inline void set_number(void *outdata, D3DXPARAMETER_TYPE outtype, const void *indata, D3DXPARAMETER_TYPE intype)
202 {
203 if (outtype == intype)
204 {
205 *(DWORD *)outdata = *(DWORD *)indata;
206 return;
207 }
208
209 switch (outtype)
210 {
211 case D3DXPT_FLOAT:
212 *(float *)outdata = get_float(intype, indata);
213 break;
214
215 case D3DXPT_BOOL:
216 *(BOOL *)outdata = get_bool(intype, indata);
217 break;
218
219 case D3DXPT_INT:
220 *(int *)outdata = get_int(intype, indata);
221 break;
222
223 default:
224 *(DWORD *)outdata = 0;
225 break;
226 }
227 }
228
229 static inline BOOL is_param_type_sampler(D3DXPARAMETER_TYPE type)
230 {
231 return type == D3DXPT_SAMPLER
232 || type == D3DXPT_SAMPLER1D || type == D3DXPT_SAMPLER2D
233 || type == D3DXPT_SAMPLER3D || type == D3DXPT_SAMPLERCUBE;
234 }
235
236 struct d3dx_parameter;
237
238 enum pres_reg_tables
239 {
240 PRES_REGTAB_IMMED,
241 PRES_REGTAB_CONST,
242 PRES_REGTAB_OCONST,
243 PRES_REGTAB_OBCONST,
244 PRES_REGTAB_OICONST,
245 PRES_REGTAB_TEMP,
246 PRES_REGTAB_COUNT,
247 PRES_REGTAB_FIRST_SHADER = PRES_REGTAB_CONST,
248 };
249
250 struct d3dx_const_param_eval_output
251 {
252 struct d3dx_parameter *param;
253 enum pres_reg_tables table;
254 enum D3DXPARAMETER_CLASS constant_class;
255 unsigned int register_index;
256 unsigned int register_count;
257 BOOL direct_copy;
258 unsigned int element_count;
259 };
260
261 struct d3dx_const_tab
262 {
263 unsigned int input_count;
264 D3DXCONSTANT_DESC *inputs;
265 struct d3dx_parameter **inputs_param;
266 unsigned int const_set_count;
267 unsigned int const_set_size;
268 struct d3dx_const_param_eval_output *const_set;
269 const enum pres_reg_tables *regset2table;
270 ULONG64 update_version;
271 };
272
273 struct d3dx_regstore
274 {
275 void *tables[PRES_REGTAB_COUNT];
276 unsigned int table_sizes[PRES_REGTAB_COUNT]; /* registers count */
277 };
278
279 struct d3dx_pres_ins;
280
281 struct d3dx_preshader
282 {
283 struct d3dx_regstore regs;
284
285 unsigned int ins_count;
286 struct d3dx_pres_ins *ins;
287
288 struct d3dx_const_tab inputs;
289 };
290
291 struct d3dx_param_eval
292 {
293 D3DXPARAMETER_TYPE param_type;
294
295 struct d3dx_preshader pres;
296 struct d3dx_const_tab shader_inputs;
297
298 ULONG64 *version_counter;
299 };
300
301 struct d3dx_shared_data;
302 struct d3dx_top_level_parameter;
303
304 struct d3dx_parameter
305 {
306 char magic_string[4];
307 struct d3dx_top_level_parameter *top_level_param;
308 struct d3dx_param_eval *param_eval;
309 char *name;
310 void *data;
311 D3DXPARAMETER_CLASS class;
312 D3DXPARAMETER_TYPE type;
313 UINT rows;
314 UINT columns;
315 UINT element_count;
316 UINT member_count;
317 DWORD flags;
318 UINT bytes;
319 DWORD object_id;
320
321 struct d3dx_parameter *members;
322 char *semantic;
323 };
324
325 struct d3dx_top_level_parameter
326 {
327 struct d3dx_parameter param;
328 UINT annotation_count;
329 struct d3dx_parameter *annotations;
330 ULONG64 update_version;
331 ULONG64 *version_counter;
332 struct d3dx_shared_data *shared_data;
333 };
334
335 struct d3dx_shared_data
336 {
337 void *data;
338 struct d3dx_top_level_parameter **parameters;
339 unsigned int size, count;
340 ULONG64 update_version;
341 };
342
343 struct d3dx9_base_effect;
344
345 static inline BOOL is_top_level_parameter(struct d3dx_parameter *param)
346 {
347 return &param->top_level_param->param == param;
348 }
349
350 static inline struct d3dx_top_level_parameter
351 *top_level_parameter_from_parameter(struct d3dx_parameter *param)
352 {
353 return CONTAINING_RECORD(param, struct d3dx_top_level_parameter, param);
354 }
355
356 static inline ULONG64 next_update_version(ULONG64 *version_counter)
357 {
358 return ++*version_counter;
359 }
360
361 static inline BOOL is_top_level_param_dirty(struct d3dx_top_level_parameter *param, ULONG64 update_version)
362 {
363 struct d3dx_shared_data *shared_data;
364
365 if ((shared_data = param->shared_data))
366 return update_version < shared_data->update_version;
367 else
368 return update_version < param->update_version;
369 }
370
371 static inline BOOL is_param_dirty(struct d3dx_parameter *param, ULONG64 update_version)
372 {
373 return is_top_level_param_dirty(param->top_level_param, update_version);
374 }
375
376 struct d3dx_parameter *get_parameter_by_name(struct d3dx9_base_effect *base,
377 struct d3dx_parameter *parameter, const char *name) DECLSPEC_HIDDEN;
378
379 #ifdef __REACTOS__
380 #define SET_D3D_STATE_(_manager, _device, _method, ...) ((_manager) ? (_manager)->lpVtbl->_method((_manager), __VA_ARGS__) \
381 : (_device)->lpVtbl->_method((_device), __VA_ARGS__))
382 #define SET_D3D_STATE(_base_effect, _method, ...) SET_D3D_STATE_((_base_effect)->manager, (_base_effect)->device, _method, __VA_ARGS__)
383 #else
384 #define SET_D3D_STATE_(manager, device, method, args...) (manager ? manager->lpVtbl->method(manager, args) \
385 : device->lpVtbl->method(device, args))
386 #define SET_D3D_STATE(base_effect, args...) SET_D3D_STATE_(base_effect->manager, base_effect->device, args)
387 #endif
388
389 HRESULT d3dx_create_param_eval(struct d3dx9_base_effect *base_effect, void *byte_code,
390 unsigned int byte_code_size, D3DXPARAMETER_TYPE type,
391 struct d3dx_param_eval **peval, ULONG64 *version_counter,
392 const char **skip_constants, unsigned int skip_constants_count) DECLSPEC_HIDDEN;
393 void d3dx_free_param_eval(struct d3dx_param_eval *peval) DECLSPEC_HIDDEN;
394 HRESULT d3dx_evaluate_parameter(struct d3dx_param_eval *peval,
395 const struct d3dx_parameter *param, void *param_value) DECLSPEC_HIDDEN;
396 HRESULT d3dx_param_eval_set_shader_constants(ID3DXEffectStateManager *manager, struct IDirect3DDevice9 *device,
397 struct d3dx_param_eval *peval, BOOL update_all) DECLSPEC_HIDDEN;
398 BOOL is_param_eval_input_dirty(struct d3dx_param_eval *peval, ULONG64 update_version) DECLSPEC_HIDDEN;
399
400 struct ctab_constant {
401 D3DXCONSTANT_DESC desc;
402 WORD constantinfo_reserved;
403 struct ctab_constant *constants;
404 };
405
406 const struct ctab_constant *d3dx_shader_get_ctab_constant(ID3DXConstantTable *iface,
407 D3DXHANDLE constant) DECLSPEC_HIDDEN;
408
409 HRESULT create_dummy_skin(ID3DXSkinInfo **iface) DECLSPEC_HIDDEN;
410
411 #endif /* __WINE_D3DX9_36_PRIVATE_H */