setupapi: Use SetupGetIntField() in SetupGetSourceFileLocation().
[wine.git] / dlls / d3dx9_36 / d3dx9_private.h
blob34a9f6eec7f1c158905e33c2b5d94a60d5b60b3c
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 #include <stdint.h>
26 #include "wine/debug.h"
27 #include "wine/rbtree.h"
29 #define COBJMACROS
30 #include "d3dx9.h"
32 #define ULONG64_MAX (~(ULONG64)0)
34 #define FOURCC_TX_1 0x54580100
36 struct vec4
38 float x, y, z, w;
41 struct volume
43 UINT width;
44 UINT height;
45 UINT depth;
48 static inline void set_volume_struct(struct volume *volume, uint32_t width, uint32_t height, uint32_t depth)
50 volume->width = width;
51 volume->height = height;
52 volume->depth = depth;
55 /* for internal use */
56 enum format_type {
57 FORMAT_ARGB, /* unsigned */
58 FORMAT_ARGBF16,/* float 16 */
59 FORMAT_ARGBF, /* float */
60 FORMAT_DXT,
61 FORMAT_INDEX,
62 FORMAT_UNKNOWN
65 struct pixel_format_desc {
66 D3DFORMAT format;
67 BYTE bits[4];
68 BYTE shift[4];
69 UINT bytes_per_pixel;
70 UINT block_width;
71 UINT block_height;
72 UINT block_byte_count;
73 enum format_type type;
74 void (*from_rgba)(const struct vec4 *src, struct vec4 *dst);
75 void (*to_rgba)(const struct vec4 *src, struct vec4 *dst, const PALETTEENTRY *palette);
78 struct d3dx_pixels
80 const void *data;
81 uint32_t row_pitch;
82 uint32_t slice_pitch;
83 const PALETTEENTRY *palette;
85 struct volume size;
86 RECT unaligned_rect;
89 static inline void set_d3dx_pixels(struct d3dx_pixels *pixels, const void *data, uint32_t row_pitch,
90 uint32_t slice_pitch, const PALETTEENTRY *palette, uint32_t width, uint32_t height, uint32_t depth,
91 const RECT *unaligned_rect)
93 pixels->data = data;
94 pixels->row_pitch = row_pitch;
95 pixels->slice_pitch = slice_pitch;
96 pixels->palette = palette;
97 set_volume_struct(&pixels->size, width, height, depth);
98 pixels->unaligned_rect = *unaligned_rect;
101 #define D3DX_IMAGE_INFO_ONLY 1
102 struct d3dx_image
104 D3DRESOURCETYPE resource_type;
105 D3DFORMAT format;
107 struct volume size;
108 uint32_t mip_levels;
110 BYTE *pixels;
113 * image_buf and palette are pointers to allocated memory used to store
114 * image data. If they are non-NULL, they need to be freed when no longer
115 * in use.
117 void *image_buf;
118 PALETTEENTRY *palette;
120 D3DXIMAGE_FILEFORMAT image_file_format;
123 HRESULT d3dx_image_init(const void *src_data, uint32_t src_data_size, struct d3dx_image *image,
124 uint32_t starting_mip_level, uint32_t flags);
125 void d3dx_image_cleanup(struct d3dx_image *image);
126 HRESULT d3dx_image_get_pixels(struct d3dx_image *image, uint32_t mip_level, struct d3dx_pixels *pixels);
127 void d3dximage_info_from_d3dx_image(D3DXIMAGE_INFO *info, struct d3dx_image *image);
129 struct d3dx_include_from_file
131 ID3DXInclude ID3DXInclude_iface;
134 extern CRITICAL_SECTION from_file_mutex;
135 extern const struct ID3DXIncludeVtbl d3dx_include_from_file_vtbl;
137 static inline BOOL is_conversion_from_supported(const struct pixel_format_desc *format)
139 if (format->type == FORMAT_ARGB || format->type == FORMAT_ARGBF16
140 || format->type == FORMAT_ARGBF || format->type == FORMAT_DXT)
141 return TRUE;
142 return !!format->to_rgba;
145 static inline BOOL is_conversion_to_supported(const struct pixel_format_desc *format)
147 if (format->type == FORMAT_ARGB || format->type == FORMAT_ARGBF16
148 || format->type == FORMAT_ARGBF || format->type == FORMAT_DXT)
149 return TRUE;
150 return !!format->from_rgba;
153 HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length);
154 HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length);
156 HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer);
158 const struct pixel_format_desc *get_format_info(D3DFORMAT format);
159 const struct pixel_format_desc *get_format_info_idx(int idx);
161 void format_to_vec4(const struct pixel_format_desc *format, const BYTE *src, struct vec4 *dst);
163 void copy_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
164 BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *size,
165 const struct pixel_format_desc *format);
166 void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
167 const struct volume *src_size, const struct pixel_format_desc *src_format,
168 BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size,
169 const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette);
170 void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
171 const struct volume *src_size, const struct pixel_format_desc *src_format,
172 BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size,
173 const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette);
175 HRESULT load_cube_texture_from_dds(IDirect3DCubeTexture9 *cube_texture, const void *src_data,
176 const PALETTEENTRY *palette, DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info);
177 HRESULT lock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, D3DLOCKED_RECT *lock,
178 IDirect3DSurface9 **temp_surface, BOOL write);
179 HRESULT unlock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect,
180 IDirect3DSurface9 *temp_surface, BOOL update);
181 HRESULT d3dx_pixels_init(const void *data, uint32_t row_pitch, uint32_t slice_pitch,
182 const PALETTEENTRY *palette, D3DFORMAT format, uint32_t left, uint32_t top, uint32_t right, uint32_t bottom,
183 uint32_t front, uint32_t back, struct d3dx_pixels *pixels);
184 HRESULT d3dx_load_pixels_from_pixels(struct d3dx_pixels *dst_pixels,
185 const struct pixel_format_desc *dst_desc, struct d3dx_pixels *src_pixels,
186 const struct pixel_format_desc *src_desc, uint32_t filter_flags, uint32_t color_key);
187 void get_aligned_rect(uint32_t left, uint32_t top, uint32_t right, uint32_t bottom, uint32_t width, uint32_t height,
188 const struct pixel_format_desc *fmt_desc, RECT *aligned_rect);
190 unsigned short float_32_to_16(const float in);
191 float float_16_to_32(const unsigned short in);
193 /* debug helpers */
194 const char *debug_d3dxparameter_class(D3DXPARAMETER_CLASS c);
195 const char *debug_d3dxparameter_type(D3DXPARAMETER_TYPE t);
196 const char *debug_d3dxparameter_registerset(D3DXREGISTER_SET r);
198 /* parameter type conversion helpers */
199 static inline BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
201 switch (type)
203 case D3DXPT_FLOAT:
204 case D3DXPT_INT:
205 case D3DXPT_BOOL:
206 return !!*(DWORD *)data;
208 case D3DXPT_VOID:
209 return *(BOOL *)data;
211 default:
212 return FALSE;
216 static inline int get_int(D3DXPARAMETER_TYPE type, const void *data)
218 switch (type)
220 case D3DXPT_FLOAT:
221 return (int)(*(float *)data);
223 case D3DXPT_INT:
224 case D3DXPT_VOID:
225 return *(int *)data;
227 case D3DXPT_BOOL:
228 return get_bool(type, data);
230 default:
231 return 0;
235 static inline float get_float(D3DXPARAMETER_TYPE type, const void *data)
237 switch (type)
239 case D3DXPT_FLOAT:
240 case D3DXPT_VOID:
241 return *(float *)data;
243 case D3DXPT_INT:
244 return (float)(*(int *)data);
246 case D3DXPT_BOOL:
247 return (float)get_bool(type, data);
249 default:
250 return 0.0f;
254 static inline void set_number(void *outdata, D3DXPARAMETER_TYPE outtype, const void *indata, D3DXPARAMETER_TYPE intype)
256 if (outtype == intype)
258 *(DWORD *)outdata = *(DWORD *)indata;
259 return;
262 switch (outtype)
264 case D3DXPT_FLOAT:
265 *(float *)outdata = get_float(intype, indata);
266 break;
268 case D3DXPT_BOOL:
269 *(BOOL *)outdata = get_bool(intype, indata);
270 break;
272 case D3DXPT_INT:
273 *(int *)outdata = get_int(intype, indata);
274 break;
276 default:
277 *(DWORD *)outdata = 0;
278 break;
282 static inline BOOL is_param_type_sampler(D3DXPARAMETER_TYPE type)
284 return type == D3DXPT_SAMPLER
285 || type == D3DXPT_SAMPLER1D || type == D3DXPT_SAMPLER2D
286 || type == D3DXPT_SAMPLER3D || type == D3DXPT_SAMPLERCUBE;
289 /* Returns the smallest power of 2 which is greater than or equal to num */
290 static inline uint32_t make_pow2(uint32_t num)
292 DWORD index;
294 return BitScanReverse(&index, num - 1) ? 1u << (index + 1) : 1;
297 struct d3dx_parameter;
299 enum pres_reg_tables
301 PRES_REGTAB_IMMED,
302 PRES_REGTAB_CONST,
303 PRES_REGTAB_INPUT,
304 PRES_REGTAB_OCONST,
305 PRES_REGTAB_OBCONST,
306 PRES_REGTAB_OICONST,
307 PRES_REGTAB_TEMP,
308 PRES_REGTAB_COUNT,
309 PRES_REGTAB_FIRST_SHADER = PRES_REGTAB_CONST,
312 struct d3dx_const_param_eval_output
314 struct d3dx_parameter *param;
315 enum pres_reg_tables table;
316 enum D3DXPARAMETER_CLASS constant_class;
317 unsigned int register_index;
318 unsigned int register_count;
319 BOOL direct_copy;
320 unsigned int element_count;
323 struct d3dx_const_tab
325 unsigned int input_count;
326 D3DXCONSTANT_DESC *inputs;
327 struct d3dx_parameter **inputs_param;
328 unsigned int const_set_count;
329 unsigned int const_set_size;
330 struct d3dx_const_param_eval_output *const_set;
331 const enum pres_reg_tables *regset2table;
332 ULONG64 update_version;
335 struct d3dx_regstore
337 void *tables[PRES_REGTAB_COUNT];
338 unsigned int table_sizes[PRES_REGTAB_COUNT]; /* registers count */
341 struct d3dx_pres_ins;
343 struct d3dx_preshader
345 struct d3dx_regstore regs;
347 unsigned int ins_count;
348 struct d3dx_pres_ins *ins;
350 struct d3dx_const_tab inputs;
353 struct d3dx_param_eval
355 D3DXPARAMETER_TYPE param_type;
357 struct d3dx_preshader pres;
358 struct d3dx_const_tab shader_inputs;
360 ULONG64 *version_counter;
363 struct param_rb_entry
365 struct wine_rb_entry entry;
366 char *full_name;
367 struct d3dx_parameter *param;
370 struct d3dx_shared_data;
371 struct d3dx_top_level_parameter;
373 struct d3dx_parameter
375 char magic_string[4];
376 struct d3dx_top_level_parameter *top_level_param;
377 struct d3dx_param_eval *param_eval;
378 char *name;
379 void *data;
380 D3DXPARAMETER_CLASS class;
381 D3DXPARAMETER_TYPE type;
382 unsigned int rows;
383 unsigned int columns;
384 unsigned int element_count;
385 unsigned int member_count;
386 uint32_t flags;
387 unsigned int bytes;
388 unsigned int object_id;
390 struct d3dx_parameter *members;
391 char *semantic;
393 char *full_name;
394 struct wine_rb_entry rb_entry;
397 struct d3dx_top_level_parameter
399 struct d3dx_parameter param;
400 unsigned int annotation_count;
401 struct d3dx_parameter *annotations;
402 ULONG64 update_version;
403 ULONG64 *version_counter;
404 struct d3dx_shared_data *shared_data;
407 struct d3dx_shared_data
409 void *data;
410 struct d3dx_top_level_parameter **parameters;
411 unsigned int size, count;
412 ULONG64 update_version;
415 struct d3dx_effect;
417 static inline BOOL is_top_level_parameter(struct d3dx_parameter *param)
419 return &param->top_level_param->param == param;
422 static inline struct d3dx_top_level_parameter
423 *top_level_parameter_from_parameter(struct d3dx_parameter *param)
425 return CONTAINING_RECORD(param, struct d3dx_top_level_parameter, param);
428 static inline ULONG64 next_update_version(ULONG64 *version_counter)
430 return ++*version_counter;
433 static inline BOOL is_top_level_param_dirty(struct d3dx_top_level_parameter *param, ULONG64 update_version)
435 struct d3dx_shared_data *shared_data;
437 if ((shared_data = param->shared_data))
438 return update_version < shared_data->update_version;
439 else
440 return update_version < param->update_version;
443 static inline BOOL is_param_dirty(struct d3dx_parameter *param, ULONG64 update_version)
445 return is_top_level_param_dirty(param->top_level_param, update_version);
448 struct d3dx_parameters_store
450 struct wine_rb_tree tree;
451 struct d3dx_top_level_parameter *parameters;
452 unsigned int count;
454 char *full_name_tmp;
455 unsigned int full_name_tmp_size;
458 HRESULT d3dx_init_parameters_store(struct d3dx_parameters_store *store, unsigned int count);
459 void d3dx_parameters_store_cleanup(struct d3dx_parameters_store *store);
460 struct d3dx_parameter *get_parameter_by_name(struct d3dx_parameters_store *store,
461 struct d3dx_parameter *parameter, const char *name);
463 #define SET_D3D_STATE_(manager, device, method, ...) (manager ? manager->lpVtbl->method(manager, __VA_ARGS__) \
464 : device->lpVtbl->method(device, __VA_ARGS__))
465 #define SET_D3D_STATE(base_effect, ...) SET_D3D_STATE_(base_effect->manager, base_effect->device, __VA_ARGS__)
467 HRESULT d3dx_create_param_eval(struct d3dx_parameters_store *parameters, void *byte_code,
468 unsigned int byte_code_size, D3DXPARAMETER_TYPE type,
469 struct d3dx_param_eval **peval, ULONG64 *version_counter,
470 const char **skip_constants, unsigned int skip_constants_count);
471 void d3dx_free_param_eval(struct d3dx_param_eval *peval);
472 HRESULT d3dx_evaluate_parameter(struct d3dx_param_eval *peval,
473 const struct d3dx_parameter *param, void *param_value);
474 HRESULT d3dx_param_eval_set_shader_constants(ID3DXEffectStateManager *manager, struct IDirect3DDevice9 *device,
475 struct d3dx_param_eval *peval, BOOL update_all);
476 BOOL is_param_eval_input_dirty(struct d3dx_param_eval *peval, ULONG64 update_version);
478 struct ctab_constant {
479 D3DXCONSTANT_DESC desc;
480 WORD constantinfo_reserved;
481 struct ctab_constant *constants;
484 const struct ctab_constant *d3dx_shader_get_ctab_constant(ID3DXConstantTable *iface,
485 D3DXHANDLE constant);
487 #endif /* __WINE_D3DX9_PRIVATE_H */