server: Add RIM_TYPEHID type / hid member to rawinput union.
[wine.git] / dlls / d3dx9_36 / texture.c
blob6af445890472bd222e09d04c19685b7836878405
1 /*
2 * Copyright 2009 Tony Wasserka
3 * Copyright 2010 Christian Costa
4 * Copyright 2010 Owen Rudge for CodeWeavers
5 * Copyright 2010 Matteo Bruni for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <assert.h>
23 #include "d3dx9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
27 /* Returns TRUE if num is a power of 2, FALSE if not, or if 0 */
28 static BOOL is_pow2(UINT num)
30 return !(num & (num - 1));
33 static HRESULT get_surface(D3DRESOURCETYPE type, struct IDirect3DBaseTexture9 *tex,
34 int face, UINT level, struct IDirect3DSurface9 **surf)
36 switch (type)
38 case D3DRTYPE_TEXTURE:
39 return IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) tex, level, surf);
40 case D3DRTYPE_CUBETEXTURE:
41 return IDirect3DCubeTexture9_GetCubeMapSurface((IDirect3DCubeTexture9*) tex, face, level, surf);
42 default:
43 ERR("Unexpected texture type\n");
44 return E_NOTIMPL;
48 HRESULT WINAPI D3DXFilterTexture(IDirect3DBaseTexture9 *texture,
49 const PALETTEENTRY *palette,
50 UINT srclevel,
51 DWORD filter)
53 UINT level;
54 HRESULT hr;
55 D3DRESOURCETYPE type;
57 TRACE("(%p, %p, %u, %#x)\n", texture, palette, srclevel, filter);
59 if (!texture)
60 return D3DERR_INVALIDCALL;
62 if ((filter & 0xFFFF) > D3DX_FILTER_BOX && filter != D3DX_DEFAULT)
63 return D3DERR_INVALIDCALL;
65 if (srclevel == D3DX_DEFAULT)
66 srclevel = 0;
67 else if (srclevel >= IDirect3DBaseTexture9_GetLevelCount(texture))
68 return D3DERR_INVALIDCALL;
70 switch (type = IDirect3DBaseTexture9_GetType(texture))
72 case D3DRTYPE_TEXTURE:
73 case D3DRTYPE_CUBETEXTURE:
75 IDirect3DSurface9 *topsurf, *mipsurf;
76 D3DSURFACE_DESC desc;
77 int i, numfaces;
79 if (type == D3DRTYPE_TEXTURE)
81 numfaces = 1;
82 IDirect3DTexture9_GetLevelDesc((IDirect3DTexture9*) texture, srclevel, &desc);
84 else
86 numfaces = 6;
87 IDirect3DCubeTexture9_GetLevelDesc((IDirect3DTexture9*) texture, srclevel, &desc);
90 if (filter == D3DX_DEFAULT)
92 if (is_pow2(desc.Width) && is_pow2(desc.Height))
93 filter = D3DX_FILTER_BOX;
94 else
95 filter = D3DX_FILTER_BOX | D3DX_FILTER_DITHER;
98 for (i = 0; i < numfaces; i++)
100 level = srclevel + 1;
101 hr = get_surface(type, texture, i, srclevel, &topsurf);
103 if (FAILED(hr))
104 return D3DERR_INVALIDCALL;
106 while (get_surface(type, texture, i, level, &mipsurf) == D3D_OK)
108 hr = D3DXLoadSurfaceFromSurface(mipsurf, palette, NULL, topsurf, palette, NULL, filter, 0);
109 IDirect3DSurface9_Release(topsurf);
110 topsurf = mipsurf;
112 if (FAILED(hr))
113 break;
115 level++;
118 IDirect3DSurface9_Release(topsurf);
119 if (FAILED(hr))
120 return hr;
123 return D3D_OK;
126 case D3DRTYPE_VOLUMETEXTURE:
128 D3DVOLUME_DESC desc;
129 int level, level_count;
130 IDirect3DVolume9 *top_volume, *mip_volume;
131 IDirect3DVolumeTexture9 *volume_texture = (IDirect3DVolumeTexture9*) texture;
133 IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, srclevel, &desc);
135 if (filter == D3DX_DEFAULT)
137 if (is_pow2(desc.Width) && is_pow2(desc.Height) && is_pow2(desc.Depth))
138 filter = D3DX_FILTER_BOX;
139 else
140 filter = D3DX_FILTER_BOX | D3DX_FILTER_DITHER;
143 hr = IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, srclevel, &top_volume);
144 if (FAILED(hr))
145 return hr;
147 level_count = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
148 for (level = srclevel + 1; level < level_count; level++)
150 IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, level, &mip_volume);
151 hr = D3DXLoadVolumeFromVolume(mip_volume, palette, NULL, top_volume, palette, NULL, filter, 0);
152 IDirect3DVolume9_Release(top_volume);
153 top_volume = mip_volume;
155 if (FAILED(hr))
156 break;
159 IDirect3DVolume9_Release(top_volume);
160 if (FAILED(hr))
161 return hr;
163 return D3D_OK;
166 default:
167 return D3DERR_INVALIDCALL;
171 static D3DFORMAT get_replacement_format(D3DFORMAT format)
173 static const struct
175 D3DFORMAT format;
176 D3DFORMAT replacement_format;
178 replacements[] =
180 {D3DFMT_L8, D3DFMT_X8R8G8B8},
181 {D3DFMT_A8L8, D3DFMT_A8R8G8B8},
182 {D3DFMT_A4L4, D3DFMT_A4R4G4B4},
183 {D3DFMT_L16, D3DFMT_A16B16G16R16},
184 {D3DFMT_DXT1, D3DFMT_A8R8G8B8},
185 {D3DFMT_DXT2, D3DFMT_A8R8G8B8},
186 {D3DFMT_DXT3, D3DFMT_A8R8G8B8},
187 {D3DFMT_DXT4, D3DFMT_A8R8G8B8},
188 {D3DFMT_DXT5, D3DFMT_A8R8G8B8},
190 unsigned int i;
192 for (i = 0; i < ARRAY_SIZE(replacements); ++i)
193 if (format == replacements[i].format)
194 return replacements[i].replacement_format;
195 return format;
198 static HRESULT check_texture_requirements(struct IDirect3DDevice9 *device, UINT *width, UINT *height,
199 UINT *miplevels, DWORD usage, D3DFORMAT *format, D3DPOOL pool, D3DRESOURCETYPE resource_type)
201 UINT w = (width && *width) ? *width : 1;
202 UINT h = (height && *height) ? *height : 1;
203 D3DCAPS9 caps;
204 D3DDEVICE_CREATION_PARAMETERS params;
205 IDirect3D9 *d3d = NULL;
206 D3DDISPLAYMODE mode;
207 HRESULT hr;
208 D3DFORMAT usedformat = D3DFMT_UNKNOWN;
209 const struct pixel_format_desc *fmt;
211 if (!device)
212 return D3DERR_INVALIDCALL;
214 /* usage */
215 if (usage == D3DX_DEFAULT)
216 usage = 0;
217 if (usage & (D3DUSAGE_WRITEONLY | D3DUSAGE_DONOTCLIP | D3DUSAGE_POINTS | D3DUSAGE_RTPATCHES | D3DUSAGE_NPATCHES))
218 return D3DERR_INVALIDCALL;
220 /* pool */
221 if ((pool != D3DPOOL_DEFAULT) && (pool != D3DPOOL_MANAGED) && (pool != D3DPOOL_SYSTEMMEM) && (pool != D3DPOOL_SCRATCH))
222 return D3DERR_INVALIDCALL;
224 /* format */
225 if (format)
227 TRACE("Requested format %x\n", *format);
228 usedformat = *format;
231 hr = IDirect3DDevice9_GetDirect3D(device, &d3d);
233 if (FAILED(hr))
234 goto cleanup;
236 hr = IDirect3DDevice9_GetCreationParameters(device, &params);
238 if (FAILED(hr))
239 goto cleanup;
241 hr = IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
243 if (FAILED(hr))
244 goto cleanup;
246 if ((usedformat == D3DFMT_UNKNOWN) || (usedformat == D3DX_DEFAULT))
247 usedformat = D3DFMT_A8R8G8B8;
249 fmt = get_format_info(usedformat);
251 hr = IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType, mode.Format,
252 usage, resource_type, usedformat);
253 if (FAILED(hr))
255 BOOL allow_24bits;
256 int bestscore = INT_MIN, i = 0, j;
257 unsigned int channels;
258 const struct pixel_format_desc *curfmt, *bestfmt = NULL;
260 TRACE("Requested format is not supported, looking for a fallback.\n");
262 if (!fmt)
264 FIXME("Pixel format %x not handled\n", usedformat);
265 goto cleanup;
267 fmt = get_format_info(get_replacement_format(usedformat));
269 allow_24bits = fmt->bytes_per_pixel == 3;
270 channels = !!fmt->bits[0] + !!fmt->bits[1] + !!fmt->bits[2] + !!fmt->bits[3];
271 usedformat = D3DFMT_UNKNOWN;
273 while ((curfmt = get_format_info_idx(i)))
275 unsigned int curchannels = !!curfmt->bits[0] + !!curfmt->bits[1]
276 + !!curfmt->bits[2] + !!curfmt->bits[3];
277 int score;
279 i++;
281 if (curchannels < channels)
282 continue;
283 if (curfmt->bytes_per_pixel == 3 && !allow_24bits)
284 continue;
286 hr = IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
287 mode.Format, usage, resource_type, curfmt->format);
288 if (FAILED(hr))
289 continue;
291 /* This format can be used, let's evaluate it.
292 Weights chosen quite arbitrarily... */
293 score = 512 * (curfmt->type == fmt->type);
294 score -= 32 * (curchannels - channels);
296 for (j = 0; j < 4; j++)
298 int diff = curfmt->bits[j] - fmt->bits[j];
299 score -= (diff < 0 ? -diff * 8 : diff) * (j == 0 ? 1 : 2);
302 if (score > bestscore)
304 bestscore = score;
305 usedformat = curfmt->format;
306 bestfmt = curfmt;
309 if (!bestfmt)
311 hr = D3DERR_NOTAVAILABLE;
312 goto cleanup;
314 fmt = bestfmt;
315 hr = D3D_OK;
318 if (FAILED(IDirect3DDevice9_GetDeviceCaps(device, &caps)))
319 return D3DERR_INVALIDCALL;
321 if ((w == D3DX_DEFAULT) && (h == D3DX_DEFAULT))
322 w = h = 256;
323 else if (w == D3DX_DEFAULT)
324 w = (height ? h : 256);
325 else if (h == D3DX_DEFAULT)
326 h = (width ? w : 256);
328 assert(!(fmt->block_width & (fmt->block_width - 1)));
329 assert(!(fmt->block_height & (fmt->block_height - 1)));
330 if (w & (fmt->block_width - 1))
331 w = (w + fmt->block_width) & ~(fmt->block_width - 1);
332 if (h & (fmt->block_height - 1))
333 h = (h + fmt->block_height) & ~(fmt->block_height - 1);
335 if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && (!is_pow2(w)))
336 w = make_pow2(w);
338 if (w > caps.MaxTextureWidth)
339 w = caps.MaxTextureWidth;
341 if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && (!is_pow2(h)))
342 h = make_pow2(h);
344 if (h > caps.MaxTextureHeight)
345 h = caps.MaxTextureHeight;
347 if (caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY)
349 if (w > h)
350 h = w;
351 else
352 w = h;
355 if (width)
356 *width = w;
358 if (height)
359 *height = h;
361 if (miplevels && (usage & D3DUSAGE_AUTOGENMIPMAP))
363 if (*miplevels > 1)
364 *miplevels = 0;
366 else if (miplevels)
368 UINT max_mipmaps = 1;
370 if (!width && !height)
371 max_mipmaps = 9; /* number of mipmaps in a 256x256 texture */
372 else
374 UINT max_dimen = max(w, h);
376 while (max_dimen > 1)
378 max_dimen >>= 1;
379 max_mipmaps++;
383 if (*miplevels == 0 || *miplevels > max_mipmaps)
384 *miplevels = max_mipmaps;
387 cleanup:
389 if (d3d)
390 IDirect3D9_Release(d3d);
392 if (FAILED(hr))
393 return hr;
395 if (usedformat == D3DFMT_UNKNOWN)
397 WARN("Couldn't find a suitable pixel format\n");
398 return D3DERR_NOTAVAILABLE;
401 TRACE("Format chosen: %x\n", usedformat);
402 if (format)
403 *format = usedformat;
405 return D3D_OK;
408 HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UINT *width, UINT *height,
409 UINT *miplevels, DWORD usage, D3DFORMAT *format, D3DPOOL pool)
411 TRACE("device %p, width %p, height %p, miplevels %p, usage %u, format %p, pool %u.\n",
412 device, width, height, miplevels, usage, format, pool);
414 return check_texture_requirements(device, width, height, miplevels, usage, format, pool, D3DRTYPE_TEXTURE);
417 HRESULT WINAPI D3DXCheckCubeTextureRequirements(struct IDirect3DDevice9 *device, UINT *size,
418 UINT *miplevels, DWORD usage, D3DFORMAT *format, D3DPOOL pool)
420 D3DCAPS9 caps;
421 UINT s = (size && *size) ? *size : 256;
422 HRESULT hr;
424 TRACE("(%p, %p, %p, %u, %p, %u)\n", device, size, miplevels, usage, format, pool);
426 if (s == D3DX_DEFAULT)
427 s = 256;
429 if (!device || FAILED(IDirect3DDevice9_GetDeviceCaps(device, &caps)))
430 return D3DERR_INVALIDCALL;
432 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
433 return D3DERR_NOTAVAILABLE;
435 if ((caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2) && (!is_pow2(s)))
436 s = make_pow2(s);
438 hr = check_texture_requirements(device, &s, &s, miplevels, usage, format, pool, D3DRTYPE_CUBETEXTURE);
440 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP))
442 if(miplevels)
443 *miplevels = 1;
446 if (size)
447 *size = s;
449 return hr;
452 HRESULT WINAPI D3DXCheckVolumeTextureRequirements(struct IDirect3DDevice9 *device, UINT *width, UINT *height,
453 UINT *depth, UINT *miplevels, DWORD usage, D3DFORMAT *format, D3DPOOL pool)
455 D3DCAPS9 caps;
456 UINT w = width ? *width : D3DX_DEFAULT;
457 UINT h = height ? *height : D3DX_DEFAULT;
458 UINT d = (depth && *depth) ? *depth : 1;
459 HRESULT hr;
461 TRACE("(%p, %p, %p, %p, %p, %u, %p, %u)\n", device, width, height, depth, miplevels,
462 usage, format, pool);
464 if (!device || FAILED(IDirect3DDevice9_GetDeviceCaps(device, &caps)))
465 return D3DERR_INVALIDCALL;
467 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
468 return D3DERR_NOTAVAILABLE;
470 hr = check_texture_requirements(device, &w, &h, NULL, usage, format, pool, D3DRTYPE_VOLUMETEXTURE);
471 if (d == D3DX_DEFAULT)
472 d = 1;
474 if ((caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2) &&
475 (!is_pow2(w) || !is_pow2(h) || !is_pow2(d)))
477 w = make_pow2(w);
478 h = make_pow2(h);
479 d = make_pow2(d);
482 if (w > caps.MaxVolumeExtent)
483 w = caps.MaxVolumeExtent;
484 if (h > caps.MaxVolumeExtent)
485 h = caps.MaxVolumeExtent;
486 if (d > caps.MaxVolumeExtent)
487 d = caps.MaxVolumeExtent;
489 if (miplevels)
491 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
492 *miplevels = 1;
493 else if ((usage & D3DUSAGE_AUTOGENMIPMAP))
495 if (*miplevels > 1)
496 *miplevels = 0;
498 else
500 UINT max_mipmaps = 1;
501 UINT max_dimen = max(max(w, h), d);
503 while (max_dimen > 1)
505 max_dimen >>= 1;
506 max_mipmaps++;
509 if (*miplevels == 0 || *miplevels > max_mipmaps)
510 *miplevels = max_mipmaps;
514 if (width)
515 *width = w;
516 if (height)
517 *height = h;
518 if (depth)
519 *depth = d;
521 return hr;
524 HRESULT WINAPI D3DXCreateTexture(struct IDirect3DDevice9 *device, UINT width, UINT height,
525 UINT miplevels, DWORD usage, D3DFORMAT format, D3DPOOL pool, struct IDirect3DTexture9 **texture)
527 HRESULT hr;
529 TRACE("device %p, width %u, height %u, miplevels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
530 device, width, height, miplevels, usage, format, pool, texture);
532 if (!device || !texture)
533 return D3DERR_INVALIDCALL;
535 if (FAILED(hr = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, usage, &format, pool)))
536 return hr;
538 return IDirect3DDevice9_CreateTexture(device, width, height, miplevels, usage, format, pool, texture, NULL);
541 static D3DFORMAT get_alpha_replacement_format(D3DFORMAT format)
543 static const struct
545 D3DFORMAT orig_format;
546 D3DFORMAT replacement_format;
548 replacement_formats[] =
550 {D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8},
551 {D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5},
552 {D3DFMT_X4R4G4B4, D3DFMT_A4R4G4B4},
553 {D3DFMT_X8B8G8R8, D3DFMT_A8B8G8R8},
554 {D3DFMT_L8, D3DFMT_A8L8},
556 unsigned int i;
558 for (i = 0; i < ARRAY_SIZE(replacement_formats); ++i)
559 if (replacement_formats[i].orig_format == format)
560 return replacement_formats[i].replacement_format;
561 return format;
564 HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(struct IDirect3DDevice9 *device, const void *srcdata,
565 UINT srcdatasize, UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format,
566 D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
567 PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
569 BOOL dynamic_texture, format_specified = FALSE;
570 unsigned int loaded_miplevels, skip_levels;
571 IDirect3DSurface9 *surface;
572 IDirect3DTexture9 **texptr;
573 IDirect3DTexture9 *buftex;
574 D3DXIMAGE_INFO imginfo;
575 D3DCAPS9 caps;
576 HRESULT hr;
578 TRACE("device %p, srcdata %p, srcdatasize %u, width %u, height %u, miplevels %u,"
579 " usage %#x, format %#x, pool %#x, filter %#x, mipfilter %#x, colorkey %#x,"
580 " srcinfo %p, palette %p, texture %p.\n",
581 device, srcdata, srcdatasize, width, height, miplevels, usage, format, pool,
582 filter, mipfilter, colorkey, srcinfo, palette, texture);
584 /* check for invalid parameters */
585 if (!device || !texture || !srcdata || !srcdatasize)
586 return D3DERR_INVALIDCALL;
588 hr = D3DXGetImageInfoFromFileInMemory(srcdata, srcdatasize, &imginfo);
589 if (FAILED(hr))
591 FIXME("Unrecognized file format, returning failure.\n");
592 *texture = NULL;
593 return hr;
596 /* handle default values */
597 if (width == 0 || width == D3DX_DEFAULT_NONPOW2)
598 width = imginfo.Width;
600 if (height == 0 || height == D3DX_DEFAULT_NONPOW2)
601 height = imginfo.Height;
603 if (width == D3DX_DEFAULT)
604 width = make_pow2(imginfo.Width);
606 if (height == D3DX_DEFAULT)
607 height = make_pow2(imginfo.Height);
609 if (format == D3DFMT_UNKNOWN || format == D3DX_DEFAULT)
610 format = imginfo.Format;
611 else
612 format_specified = TRUE;
614 if (width == D3DX_FROM_FILE)
616 width = imginfo.Width;
619 if (height == D3DX_FROM_FILE)
621 height = imginfo.Height;
624 if (format == D3DFMT_FROM_FILE)
626 format = imginfo.Format;
629 if (miplevels == D3DX_FROM_FILE)
631 miplevels = imginfo.MipLevels;
634 skip_levels = mipfilter != D3DX_DEFAULT ? mipfilter >> D3DX_SKIP_DDS_MIP_LEVELS_SHIFT : 0;
635 if (skip_levels && imginfo.MipLevels > skip_levels)
637 TRACE("Skipping the first %u (of %u) levels of a DDS mipmapped texture.\n",
638 skip_levels, imginfo.MipLevels);
639 TRACE("Texture level 0 dimensions are %ux%u.\n", imginfo.Width, imginfo.Height);
640 width >>= skip_levels;
641 height >>= skip_levels;
642 miplevels -= skip_levels;
644 else
646 skip_levels = 0;
649 /* Fix up texture creation parameters. */
650 hr = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, usage, &format, pool);
651 if (FAILED(hr))
653 FIXME("Couldn't find suitable texture parameters.\n");
654 *texture = NULL;
655 return hr;
658 if (colorkey && !format_specified)
659 format = get_alpha_replacement_format(format);
661 if (imginfo.ResourceType == D3DRTYPE_VOLUMETEXTURE
662 && D3DFMT_DXT1 <= imginfo.Format && imginfo.Format <= D3DFMT_DXT5 && miplevels > 1)
664 FIXME("Generation of mipmaps for compressed volume textures is not implemented yet.\n");
665 miplevels = 1;
668 if (FAILED(IDirect3DDevice9_GetDeviceCaps(device, &caps)))
669 return D3DERR_INVALIDCALL;
671 /* Create the to-be-filled texture */
672 dynamic_texture = (caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) && (usage & D3DUSAGE_DYNAMIC);
673 if (pool == D3DPOOL_DEFAULT && !dynamic_texture)
675 hr = D3DXCreateTexture(device, width, height, miplevels, 0, format, D3DPOOL_SYSTEMMEM, &buftex);
676 texptr = &buftex;
678 else
680 hr = D3DXCreateTexture(device, width, height, miplevels, usage, format, pool, texture);
681 texptr = texture;
684 if (FAILED(hr))
686 FIXME("Texture creation failed.\n");
687 *texture = NULL;
688 return hr;
691 TRACE("Texture created correctly. Now loading the texture data into it.\n");
692 if (imginfo.ImageFileFormat != D3DXIFF_DDS)
694 IDirect3DTexture9_GetSurfaceLevel(*texptr, 0, &surface);
695 hr = D3DXLoadSurfaceFromFileInMemory(surface, palette, NULL, srcdata, srcdatasize, NULL, filter, colorkey, NULL);
696 IDirect3DSurface9_Release(surface);
697 loaded_miplevels = min(IDirect3DTexture9_GetLevelCount(*texptr), imginfo.MipLevels);
699 else
701 hr = load_texture_from_dds(*texptr, srcdata, palette, filter, colorkey, &imginfo, skip_levels,
702 &loaded_miplevels);
705 if (FAILED(hr))
707 FIXME("Texture loading failed.\n");
708 IDirect3DTexture9_Release(*texptr);
709 *texture = NULL;
710 return hr;
713 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) *texptr, palette, loaded_miplevels - 1, mipfilter);
714 if (FAILED(hr))
716 FIXME("Texture filtering failed.\n");
717 IDirect3DTexture9_Release(*texptr);
718 *texture = NULL;
719 return hr;
722 /* Move the data to the actual texture if necessary */
723 if (texptr == &buftex)
725 hr = D3DXCreateTexture(device, width, height, miplevels, usage, format, pool, texture);
727 if (FAILED(hr))
729 IDirect3DTexture9_Release(buftex);
730 *texture = NULL;
731 return hr;
734 IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9*)buftex, (IDirect3DBaseTexture9*)(*texture));
735 IDirect3DTexture9_Release(buftex);
738 if (srcinfo)
739 *srcinfo = imginfo;
741 return D3D_OK;
744 HRESULT WINAPI D3DXCreateTextureFromFileInMemory(struct IDirect3DDevice9 *device,
745 const void *srcdata, UINT srcdatasize, struct IDirect3DTexture9 **texture)
747 TRACE("(%p, %p, %d, %p)\n", device, srcdata, srcdatasize, texture);
749 return D3DXCreateTextureFromFileInMemoryEx(device, srcdata, srcdatasize, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
750 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
753 HRESULT WINAPI D3DXCreateTextureFromFileExW(struct IDirect3DDevice9 *device, const WCHAR *srcfile,
754 UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format,
755 D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
756 PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
758 void *buffer;
759 HRESULT hr;
760 DWORD size;
762 TRACE("device %p, srcfile %s, width %u, height %u, miplevels %u, usage %#x, format %#x, "
763 "pool %#x, filter %#x, mipfilter %#x, colorkey 0x%08x, srcinfo %p, palette %p, texture %p.\n",
764 device, debugstr_w(srcfile), width, height, miplevels, usage, format,
765 pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
767 if (!srcfile)
768 return D3DERR_INVALIDCALL;
770 hr = map_view_of_file(srcfile, &buffer, &size);
771 if (FAILED(hr))
773 WARN("Failed to open file.\n");
774 return D3DXERR_INVALIDDATA;
777 hr = D3DXCreateTextureFromFileInMemoryEx(device, buffer, size, width, height, miplevels, usage, format, pool,
778 filter, mipfilter, colorkey, srcinfo, palette, texture);
780 UnmapViewOfFile(buffer);
782 return hr;
785 HRESULT WINAPI D3DXCreateTextureFromFileExA(struct IDirect3DDevice9 *device, const char *srcfile,
786 UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format,
787 D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
788 PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
790 WCHAR *widename;
791 HRESULT hr;
792 DWORD len;
794 TRACE("device %p, srcfile %s, width %u, height %u, miplevels %u, usage %#x, format %#x, "
795 "pool %#x, filter %#x, mipfilter %#x, colorkey 0x%08x, srcinfo %p, palette %p, texture %p.\n",
796 device, debugstr_a(srcfile), width, height, miplevels, usage, format,
797 pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
799 if (!device || !srcfile || !texture)
800 return D3DERR_INVALIDCALL;
802 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
803 widename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*widename));
804 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, widename, len);
806 hr = D3DXCreateTextureFromFileExW(device, widename, width, height, miplevels,
807 usage, format, pool, filter, mipfilter,
808 colorkey, srcinfo, palette, texture);
810 HeapFree(GetProcessHeap(), 0, widename);
811 return hr;
814 HRESULT WINAPI D3DXCreateTextureFromFileA(struct IDirect3DDevice9 *device,
815 const char *srcfile, struct IDirect3DTexture9 **texture)
817 TRACE("(%p, %s, %p)\n", device, debugstr_a(srcfile), texture);
819 return D3DXCreateTextureFromFileExA(device, srcfile, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
820 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
823 HRESULT WINAPI D3DXCreateTextureFromFileW(struct IDirect3DDevice9 *device,
824 const WCHAR *srcfile, struct IDirect3DTexture9 **texture)
826 TRACE("(%p, %s, %p)\n", device, debugstr_w(srcfile), texture);
828 return D3DXCreateTextureFromFileExW(device, srcfile, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
829 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
833 HRESULT WINAPI D3DXCreateTextureFromResourceA(struct IDirect3DDevice9 *device,
834 HMODULE srcmodule, const char *resource, struct IDirect3DTexture9 **texture)
836 TRACE("(%p, %s): relay\n", srcmodule, debugstr_a(resource));
838 return D3DXCreateTextureFromResourceExA(device, srcmodule, resource, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
839 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
842 HRESULT WINAPI D3DXCreateTextureFromResourceW(struct IDirect3DDevice9 *device,
843 HMODULE srcmodule, const WCHAR *resource, struct IDirect3DTexture9 **texture)
845 TRACE("(%p, %s): relay\n", srcmodule, debugstr_w(resource));
847 return D3DXCreateTextureFromResourceExW(device, srcmodule, resource, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
848 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
851 HRESULT WINAPI D3DXCreateTextureFromResourceExA(struct IDirect3DDevice9 *device, HMODULE srcmodule,
852 const char *resource, UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format,
853 D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
854 PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
856 HRSRC resinfo;
857 void *buffer;
858 DWORD size;
860 TRACE("device %p, srcmodule %p, resource %s, width %u, height %u, miplevels %u, usage %#x, format %#x, "
861 "pool %#x, filter %#x, mipfilter %#x, colorkey 0x%08x, srcinfo %p, palette %p, texture %p.\n",
862 device, srcmodule, debugstr_a(resource), width, height, miplevels, usage, format,
863 pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
865 if (!device || !texture)
866 return D3DERR_INVALIDCALL;
868 if (!(resinfo = FindResourceA(srcmodule, resource, (const char *)RT_RCDATA))
869 /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
870 && !(resinfo = FindResourceA(srcmodule, resource, (const char *)RT_BITMAP)))
871 return D3DXERR_INVALIDDATA;
873 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
874 return D3DXERR_INVALIDDATA;
876 return D3DXCreateTextureFromFileInMemoryEx(device, buffer, size, width, height, miplevels,
877 usage, format, pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
880 HRESULT WINAPI D3DXCreateTextureFromResourceExW(struct IDirect3DDevice9 *device, HMODULE srcmodule,
881 const WCHAR *resource, UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format,
882 D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
883 PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
885 HRSRC resinfo;
886 void *buffer;
887 DWORD size;
889 TRACE("device %p, srcmodule %p, resource %s, width %u, height %u, miplevels %u, usage %#x, format %#x, "
890 "pool %#x, filter %#x, mipfilter %#x, colorkey 0x%08x, srcinfo %p, palette %p, texture %p.\n",
891 device, srcmodule, debugstr_w(resource), width, height, miplevels, usage, format,
892 pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
894 if (!device || !texture)
895 return D3DERR_INVALIDCALL;
897 if (!(resinfo = FindResourceW(srcmodule, resource, (const WCHAR *)RT_RCDATA))
898 /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
899 && !(resinfo = FindResourceW(srcmodule, resource, (const WCHAR *)RT_BITMAP)))
900 return D3DXERR_INVALIDDATA;
902 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
903 return D3DXERR_INVALIDDATA;
905 return D3DXCreateTextureFromFileInMemoryEx(device, buffer, size, width, height, miplevels,
906 usage, format, pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
909 HRESULT WINAPI D3DXCreateCubeTexture(struct IDirect3DDevice9 *device, UINT size, UINT miplevels,
910 DWORD usage, D3DFORMAT format, D3DPOOL pool, struct IDirect3DCubeTexture9 **texture)
912 HRESULT hr;
914 TRACE("(%p, %u, %u, %#x, %#x, %#x, %p)\n", device, size, miplevels, usage, format,
915 pool, texture);
917 if (!device || !texture)
918 return D3DERR_INVALIDCALL;
920 hr = D3DXCheckCubeTextureRequirements(device, &size, &miplevels, usage, &format, pool);
922 if (FAILED(hr))
924 TRACE("D3DXCheckCubeTextureRequirements failed\n");
925 return hr;
928 return IDirect3DDevice9_CreateCubeTexture(device, size, miplevels, usage, format, pool, texture, NULL);
931 HRESULT WINAPI D3DXCreateCubeTextureFromFileInMemory(struct IDirect3DDevice9 *device,
932 const void *data, UINT datasize, struct IDirect3DCubeTexture9 **texture)
934 TRACE("(%p, %p, %u, %p)\n", device, data, datasize, texture);
936 return D3DXCreateCubeTextureFromFileInMemoryEx(device, data, datasize, D3DX_DEFAULT, D3DX_DEFAULT,
937 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
940 HRESULT WINAPI D3DXCreateVolumeTexture(struct IDirect3DDevice9 *device, UINT width, UINT height, UINT depth,
941 UINT miplevels, DWORD usage, D3DFORMAT format, D3DPOOL pool, struct IDirect3DVolumeTexture9 **texture)
943 HRESULT hr;
945 TRACE("(%p, %u, %u, %u, %u, %#x, %#x, %#x, %p)\n", device, width, height, depth,
946 miplevels, usage, format, pool, texture);
948 if (!device || !texture)
949 return D3DERR_INVALIDCALL;
951 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth,
952 &miplevels, usage, &format, pool);
954 if (FAILED(hr))
956 TRACE("D3DXCheckVolumeTextureRequirements failed\n");
957 return hr;
960 return IDirect3DDevice9_CreateVolumeTexture(device, width, height, depth, miplevels,
961 usage, format, pool, texture, NULL);
964 HRESULT WINAPI D3DXCreateVolumeTextureFromFileA(IDirect3DDevice9 *device,
965 const char *filename,
966 IDirect3DVolumeTexture9 **volume_texture)
968 int len;
969 HRESULT hr;
970 void *data;
971 DWORD data_size;
972 WCHAR *filenameW;
974 TRACE("(%p, %s, %p): relay\n",
975 device, debugstr_a(filename), volume_texture);
977 if (!filename) return D3DERR_INVALIDCALL;
979 len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
980 filenameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
981 if (!filenameW) return E_OUTOFMEMORY;
982 MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, len);
984 hr = map_view_of_file(filenameW, &data, &data_size);
985 HeapFree(GetProcessHeap(), 0, filenameW);
986 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
988 hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, data, data_size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
989 D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, volume_texture);
991 UnmapViewOfFile(data);
992 return hr;
995 HRESULT WINAPI D3DXCreateVolumeTextureFromFileW(IDirect3DDevice9 *device,
996 const WCHAR *filename,
997 IDirect3DVolumeTexture9 **volume_texture)
999 HRESULT hr;
1000 void *data;
1001 DWORD data_size;
1003 TRACE("(%p, %s, %p): relay\n",
1004 device, debugstr_w(filename), volume_texture);
1006 if (!filename) return D3DERR_INVALIDCALL;
1008 hr = map_view_of_file(filename, &data, &data_size);
1009 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
1011 hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, data, data_size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1012 D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, volume_texture);
1014 UnmapViewOfFile(data);
1015 return hr;
1018 HRESULT WINAPI D3DXCreateVolumeTextureFromFileExA(IDirect3DDevice9 *device,
1019 const char *filename,
1020 UINT width,
1021 UINT height,
1022 UINT depth,
1023 UINT mip_levels,
1024 DWORD usage,
1025 D3DFORMAT format,
1026 D3DPOOL pool,
1027 DWORD filter,
1028 DWORD mip_filter,
1029 D3DCOLOR color_key,
1030 D3DXIMAGE_INFO *src_info,
1031 PALETTEENTRY *palette,
1032 IDirect3DVolumeTexture9 **volume_texture)
1034 int len;
1035 HRESULT hr;
1036 WCHAR *filenameW;
1037 void *data;
1038 DWORD data_size;
1040 TRACE("(%p, %s, %u, %u, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p): relay\n",
1041 device, debugstr_a(filename), width, height, depth, mip_levels,
1042 usage, format, pool, filter, mip_filter, color_key, src_info,
1043 palette, volume_texture);
1045 if (!filename) return D3DERR_INVALIDCALL;
1047 len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
1048 filenameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1049 if (!filenameW) return E_OUTOFMEMORY;
1050 MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, len);
1052 hr = map_view_of_file(filenameW, &data, &data_size);
1053 HeapFree(GetProcessHeap(), 0, filenameW);
1054 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
1056 hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, data, data_size, width, height, depth,
1057 mip_levels, usage, format, pool, filter, mip_filter, color_key, src_info, palette,
1058 volume_texture);
1060 UnmapViewOfFile(data);
1061 return hr;
1064 HRESULT WINAPI D3DXCreateVolumeTextureFromFileExW(IDirect3DDevice9 *device,
1065 const WCHAR *filename,
1066 UINT width,
1067 UINT height,
1068 UINT depth,
1069 UINT mip_levels,
1070 DWORD usage,
1071 D3DFORMAT format,
1072 D3DPOOL pool,
1073 DWORD filter,
1074 DWORD mip_filter,
1075 D3DCOLOR color_key,
1076 D3DXIMAGE_INFO *src_info,
1077 PALETTEENTRY *palette,
1078 IDirect3DVolumeTexture9 **volume_texture)
1080 HRESULT hr;
1081 void *data;
1082 DWORD data_size;
1084 TRACE("(%p, %s, %u, %u, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p): relay\n",
1085 device, debugstr_w(filename), width, height, depth, mip_levels,
1086 usage, format, pool, filter, mip_filter, color_key, src_info,
1087 palette, volume_texture);
1089 if (!filename) return D3DERR_INVALIDCALL;
1091 hr = map_view_of_file(filename, &data, &data_size);
1092 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
1094 hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, data, data_size, width, height, depth,
1095 mip_levels, usage, format, pool, filter, mip_filter, color_key, src_info, palette,
1096 volume_texture);
1098 UnmapViewOfFile(data);
1099 return hr;
1102 HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device,
1103 const void *data,
1104 UINT data_size,
1105 IDirect3DVolumeTexture9 **volume_texture)
1107 TRACE("(%p, %p, %u, %p): relay\n", device, data, data_size, volume_texture);
1109 return D3DXCreateVolumeTextureFromFileInMemoryEx(device, data, data_size, D3DX_DEFAULT, D3DX_DEFAULT,
1110 D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT,
1111 0, NULL, NULL, volume_texture);
1114 HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *device,
1115 const void *data,
1116 UINT data_size,
1117 UINT width,
1118 UINT height,
1119 UINT depth,
1120 UINT mip_levels,
1121 DWORD usage,
1122 D3DFORMAT format,
1123 D3DPOOL pool,
1124 DWORD filter,
1125 DWORD mip_filter,
1126 D3DCOLOR color_key,
1127 D3DXIMAGE_INFO *info,
1128 PALETTEENTRY *palette,
1129 IDirect3DVolumeTexture9 **volume_texture)
1131 HRESULT hr;
1132 D3DCAPS9 caps;
1133 D3DXIMAGE_INFO image_info;
1134 BOOL dynamic_texture;
1135 BOOL file_width = FALSE;
1136 BOOL file_height = FALSE;
1137 BOOL file_depth = FALSE;
1138 BOOL file_format = FALSE;
1139 BOOL file_mip_levels = FALSE;
1140 IDirect3DVolumeTexture9 *tex, *buftex;
1142 TRACE("(%p, %p, %u, %u, %u, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p)\n",
1143 device, data, data_size, width, height, depth, mip_levels, usage, format, pool,
1144 filter, mip_filter, color_key, info, palette, volume_texture);
1146 if (!device || !data || !data_size || !volume_texture)
1147 return D3DERR_INVALIDCALL;
1149 hr = D3DXGetImageInfoFromFileInMemory(data, data_size, &image_info);
1150 if (FAILED(hr)) return hr;
1152 if (image_info.ImageFileFormat != D3DXIFF_DDS)
1153 return D3DXERR_INVALIDDATA;
1155 if (width == 0 || width == D3DX_DEFAULT_NONPOW2)
1156 width = image_info.Width;
1157 if (width == D3DX_DEFAULT)
1158 width = make_pow2(image_info.Width);
1160 if (height == 0 || height == D3DX_DEFAULT_NONPOW2)
1161 height = image_info.Height;
1162 if (height == D3DX_DEFAULT)
1163 height = make_pow2(image_info.Height);
1165 if (depth == 0 || depth == D3DX_DEFAULT_NONPOW2)
1166 depth = image_info.Depth;
1167 if (depth == D3DX_DEFAULT)
1168 depth = make_pow2(image_info.Depth);
1170 if (format == D3DFMT_UNKNOWN || format == D3DX_DEFAULT)
1171 format = image_info.Format;
1173 if (width == D3DX_FROM_FILE)
1175 file_width = TRUE;
1176 width = image_info.Width;
1179 if (height == D3DX_FROM_FILE)
1181 file_height = TRUE;
1182 height = image_info.Height;
1185 if (depth == D3DX_FROM_FILE)
1187 file_depth = TRUE;
1188 depth = image_info.Depth;
1191 if (format == D3DFMT_FROM_FILE)
1193 file_format = TRUE;
1194 format = image_info.Format;
1197 if (mip_levels == D3DX_FROM_FILE)
1199 file_mip_levels = TRUE;
1200 mip_levels = image_info.MipLevels;
1203 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mip_levels, usage, &format, pool);
1204 if (FAILED(hr)) return hr;
1206 if ((file_width && width != image_info.Width)
1207 || (file_height && height != image_info.Height)
1208 || (file_depth && depth != image_info.Depth)
1209 || (file_format && format != image_info.Format)
1210 || (file_mip_levels && mip_levels != image_info.MipLevels))
1211 return D3DERR_NOTAVAILABLE;
1213 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1214 if (FAILED(hr))
1215 return D3DERR_INVALIDCALL;
1217 if (mip_levels > image_info.MipLevels)
1219 FIXME("Generation of mipmaps for volume textures is not implemented yet.\n");
1220 mip_levels = image_info.MipLevels;
1223 dynamic_texture = (caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) && (usage & D3DUSAGE_DYNAMIC);
1224 if (pool == D3DPOOL_DEFAULT && !dynamic_texture)
1226 hr = D3DXCreateVolumeTexture(device, width, height, depth, mip_levels, 0, format, D3DPOOL_SYSTEMMEM, &buftex);
1227 tex = buftex;
1229 else
1231 hr = D3DXCreateVolumeTexture(device, width, height, depth, mip_levels, usage, format, pool, &tex);
1232 buftex = NULL;
1234 if (FAILED(hr)) return hr;
1236 hr = load_volume_texture_from_dds(tex, data, palette, filter, color_key, &image_info);
1237 if (FAILED(hr))
1239 IDirect3DVolumeTexture9_Release(tex);
1240 return hr;
1243 if (buftex)
1245 hr = D3DXCreateVolumeTexture(device, width, height, depth, mip_levels, usage, format, pool, &tex);
1246 if (FAILED(hr))
1248 IDirect3DVolumeTexture9_Release(buftex);
1249 return hr;
1252 IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)buftex, (IDirect3DBaseTexture9 *)tex);
1253 IDirect3DVolumeTexture9_Release(buftex);
1256 if (info)
1257 *info = image_info;
1259 *volume_texture = tex;
1260 return D3D_OK;
1263 static inline void fill_texture(const struct pixel_format_desc *format, BYTE *pos, const D3DXVECTOR4 *value)
1265 DWORD c;
1267 for (c = 0; c < format->bytes_per_pixel; c++)
1268 pos[c] = 0;
1270 for (c = 0; c < 4; c++)
1272 float comp_value;
1273 DWORD i, v = 0, mask32 = format->bits[c] == 32 ? ~0U : ((1 << format->bits[c]) - 1);
1275 switch (c)
1277 case 0: /* Alpha */
1278 comp_value = value->w;
1279 break;
1280 case 1: /* Red */
1281 comp_value = value->x;
1282 break;
1283 case 2: /* Green */
1284 comp_value = value->y;
1285 break;
1286 case 3: /* Blue */
1287 comp_value = value->z;
1288 break;
1291 if (format->type == FORMAT_ARGBF16)
1292 v = float_32_to_16(comp_value);
1293 else if (format->type == FORMAT_ARGBF)
1294 v = *(DWORD *)&comp_value;
1295 else if (format->type == FORMAT_ARGB)
1296 v = comp_value * ((1 << format->bits[c]) - 1) + 0.5f;
1297 else
1298 FIXME("Unhandled format type %#x\n", format->type);
1300 for (i = 0; i < format->bits[c] + format->shift[c]; i += 8)
1302 BYTE byte, mask;
1304 if (format->shift[c] > i)
1306 mask = mask32 << (format->shift[c] - i);
1307 byte = (v << (format->shift[c] - i)) & mask;
1309 else
1311 mask = mask32 >> (i - format->shift[c]);
1312 byte = (v >> (i - format->shift[c])) & mask;
1314 pos[i / 8] |= byte;
1319 HRESULT WINAPI D3DXFillTexture(struct IDirect3DTexture9 *texture, LPD3DXFILL2D function, void *funcdata)
1321 IDirect3DSurface9 *surface, *temp_surface;
1322 DWORD miplevels;
1323 DWORD m, x, y;
1324 D3DSURFACE_DESC desc;
1325 D3DLOCKED_RECT lock_rect;
1326 D3DXVECTOR4 value;
1327 D3DXVECTOR2 coord, size;
1328 const struct pixel_format_desc *format;
1329 BYTE *data;
1330 HRESULT hr;
1332 TRACE("texture %p, function %p, funcdata %p.\n", texture, function, funcdata);
1334 if (!texture || !function)
1335 return D3DERR_INVALIDCALL;
1337 miplevels = IDirect3DBaseTexture9_GetLevelCount(texture);
1339 for (m = 0; m < miplevels; m++)
1341 if (FAILED(hr = IDirect3DTexture9_GetLevelDesc(texture, m, &desc)))
1342 return hr;
1344 format = get_format_info(desc.Format);
1345 if (format->type != FORMAT_ARGB && format->type != FORMAT_ARGBF16 && format->type != FORMAT_ARGBF)
1347 FIXME("Unsupported texture format %#x.\n", desc.Format);
1348 return D3DERR_INVALIDCALL;
1351 if (FAILED(hr = IDirect3DTexture9_GetSurfaceLevel(texture, m, &surface)))
1352 return hr;
1353 if (FAILED(hr = lock_surface(surface, NULL, &lock_rect, &temp_surface, TRUE)))
1355 IDirect3DSurface9_Release(surface);
1356 return hr;
1359 size.x = 1.0f / desc.Width;
1360 size.y = 1.0f / desc.Height;
1362 data = lock_rect.pBits;
1364 for (y = 0; y < desc.Height; y++)
1366 /* The callback function expects the coordinates of the center
1367 of the texel */
1368 coord.y = (y + 0.5f) / desc.Height;
1370 for (x = 0; x < desc.Width; x++)
1372 coord.x = (x + 0.5f) / desc.Width;
1374 function(&value, &coord, &size, funcdata);
1376 fill_texture(format, data + y * lock_rect.Pitch + x * format->bytes_per_pixel, &value);
1379 if (FAILED(hr = unlock_surface(surface, NULL, temp_surface, TRUE)))
1381 IDirect3DSurface9_Release(surface);
1382 return hr;
1384 IDirect3DSurface9_Release(surface);
1387 return D3D_OK;
1390 HRESULT WINAPI D3DXFillTextureTX(struct IDirect3DTexture9 *texture, ID3DXTextureShader *texture_shader)
1392 FIXME("texture %p, texture_shader %p stub.\n", texture, texture_shader);
1393 return E_NOTIMPL;
1396 HRESULT WINAPI D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device,
1397 const void *src_data,
1398 UINT src_data_size,
1399 UINT size,
1400 UINT mip_levels,
1401 DWORD usage,
1402 D3DFORMAT format,
1403 D3DPOOL pool,
1404 DWORD filter,
1405 DWORD mip_filter,
1406 D3DCOLOR color_key,
1407 D3DXIMAGE_INFO *src_info,
1408 PALETTEENTRY *palette,
1409 IDirect3DCubeTexture9 **cube_texture)
1411 HRESULT hr;
1412 D3DCAPS9 caps;
1413 UINT loaded_miplevels;
1414 D3DXIMAGE_INFO img_info;
1415 BOOL dynamic_texture;
1416 BOOL file_size = FALSE;
1417 BOOL file_format = FALSE;
1418 BOOL file_mip_levels = FALSE;
1419 IDirect3DCubeTexture9 *tex, *buftex;
1421 TRACE("(%p, %p, %u, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p)\n", device,
1422 src_data, src_data_size, size, mip_levels, usage, format, pool, filter, mip_filter,
1423 color_key, src_info, palette, cube_texture);
1425 if (!device || !cube_texture || !src_data || !src_data_size)
1426 return D3DERR_INVALIDCALL;
1428 hr = D3DXGetImageInfoFromFileInMemory(src_data, src_data_size, &img_info);
1429 if (FAILED(hr))
1430 return hr;
1432 if (img_info.ImageFileFormat != D3DXIFF_DDS)
1433 return D3DXERR_INVALIDDATA;
1435 if (img_info.Width != img_info.Height)
1436 return D3DXERR_INVALIDDATA;
1438 if (size == 0 || size == D3DX_DEFAULT_NONPOW2)
1439 size = img_info.Width;
1440 if (size == D3DX_DEFAULT)
1441 size = make_pow2(img_info.Width);
1443 if (format == D3DFMT_UNKNOWN || format == D3DX_DEFAULT)
1444 format = img_info.Format;
1446 if (size == D3DX_FROM_FILE)
1448 file_size = TRUE;
1449 size = img_info.Width;
1452 if (format == D3DFMT_FROM_FILE)
1454 file_format = TRUE;
1455 format = img_info.Format;
1458 if (mip_levels == D3DX_FROM_FILE)
1460 file_mip_levels = TRUE;
1461 mip_levels = img_info.MipLevels;
1464 hr = D3DXCheckCubeTextureRequirements(device, &size, &mip_levels, usage, &format, pool);
1465 if (FAILED(hr))
1466 return hr;
1468 if ((file_size && size != img_info.Width)
1469 || (file_format && format != img_info.Format)
1470 || (file_mip_levels && mip_levels != img_info.MipLevels))
1471 return D3DERR_NOTAVAILABLE;
1473 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1474 if (FAILED(hr))
1475 return D3DERR_INVALIDCALL;
1477 dynamic_texture = (caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) && (usage & D3DUSAGE_DYNAMIC);
1478 if (pool == D3DPOOL_DEFAULT && !dynamic_texture)
1480 hr = D3DXCreateCubeTexture(device, size, mip_levels, 0, format, D3DPOOL_SYSTEMMEM, &buftex);
1481 tex = buftex;
1483 else
1485 hr = D3DXCreateCubeTexture(device, size, mip_levels, usage, format, pool, &tex);
1486 buftex = NULL;
1488 if (FAILED(hr))
1489 return hr;
1491 hr = load_cube_texture_from_dds(tex, src_data, palette, filter, color_key, &img_info);
1492 if (FAILED(hr))
1494 IDirect3DCubeTexture9_Release(tex);
1495 return hr;
1498 loaded_miplevels = min(IDirect3DCubeTexture9_GetLevelCount(tex), img_info.MipLevels);
1499 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, palette, loaded_miplevels - 1, mip_filter);
1500 if (FAILED(hr))
1502 IDirect3DCubeTexture9_Release(tex);
1503 return hr;
1506 if (buftex)
1508 hr = D3DXCreateCubeTexture(device, size, mip_levels, usage, format, pool, &tex);
1509 if (FAILED(hr))
1511 IDirect3DCubeTexture9_Release(buftex);
1512 return hr;
1515 IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)buftex, (IDirect3DBaseTexture9 *)tex);
1516 IDirect3DCubeTexture9_Release(buftex);
1519 if (src_info)
1520 *src_info = img_info;
1522 *cube_texture = tex;
1523 return D3D_OK;
1527 HRESULT WINAPI D3DXCreateCubeTextureFromFileA(IDirect3DDevice9 *device,
1528 const char *src_filename,
1529 IDirect3DCubeTexture9 **cube_texture)
1531 int len;
1532 HRESULT hr;
1533 WCHAR *filename;
1534 void *data;
1535 DWORD data_size;
1537 TRACE("(%p, %s, %p): relay\n", device, wine_dbgstr_a(src_filename), cube_texture);
1539 if (!src_filename) return D3DERR_INVALIDCALL;
1541 len = MultiByteToWideChar(CP_ACP, 0, src_filename, -1, NULL, 0);
1542 filename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1543 if (!filename) return E_OUTOFMEMORY;
1544 MultiByteToWideChar(CP_ACP, 0, src_filename, -1, filename, len);
1546 hr = map_view_of_file(filename, &data, &data_size);
1547 if (FAILED(hr))
1549 HeapFree(GetProcessHeap(), 0, filename);
1550 return D3DXERR_INVALIDDATA;
1553 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, data, data_size, D3DX_DEFAULT, D3DX_DEFAULT,
1554 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, cube_texture);
1556 UnmapViewOfFile(data);
1557 HeapFree(GetProcessHeap(), 0, filename);
1558 return hr;
1561 HRESULT WINAPI D3DXCreateCubeTextureFromFileW(IDirect3DDevice9 *device,
1562 const WCHAR *src_filename,
1563 IDirect3DCubeTexture9 **cube_texture)
1565 HRESULT hr;
1566 void *data;
1567 DWORD data_size;
1569 TRACE("(%p, %s, %p): relay\n", device, wine_dbgstr_w(src_filename), cube_texture);
1571 hr = map_view_of_file(src_filename, &data, &data_size);
1572 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
1574 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, data, data_size, D3DX_DEFAULT, D3DX_DEFAULT,
1575 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, cube_texture);
1577 UnmapViewOfFile(data);
1578 return hr;
1581 HRESULT WINAPI D3DXCreateCubeTextureFromFileExA(IDirect3DDevice9 *device,
1582 const char *src_filename,
1583 UINT size,
1584 UINT mip_levels,
1585 DWORD usage,
1586 D3DFORMAT format,
1587 D3DPOOL pool,
1588 DWORD filter,
1589 DWORD mip_filter,
1590 D3DCOLOR color_key,
1591 D3DXIMAGE_INFO *image_info,
1592 PALETTEENTRY *palette,
1593 IDirect3DCubeTexture9 **cube_texture)
1595 int len;
1596 HRESULT hr;
1597 WCHAR *filename;
1598 void *data;
1599 DWORD data_size;
1601 TRACE("(%p, %s, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p): relay\n",
1602 device, wine_dbgstr_a(src_filename), size, mip_levels, usage, format,
1603 pool, filter, mip_filter, color_key, image_info, palette, cube_texture);
1605 if (!src_filename) return D3DERR_INVALIDCALL;
1607 len = MultiByteToWideChar(CP_ACP, 0, src_filename, -1, NULL, 0);
1608 filename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1609 if (!filename) return E_OUTOFMEMORY;
1610 MultiByteToWideChar(CP_ACP, 0, src_filename, -1, filename, len);
1612 hr = map_view_of_file(filename, &data, &data_size);
1613 if (FAILED(hr))
1615 HeapFree(GetProcessHeap(), 0, filename);
1616 return D3DXERR_INVALIDDATA;
1619 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, data, data_size, size, mip_levels,
1620 usage, format, pool, filter, mip_filter, color_key, image_info, palette, cube_texture);
1622 UnmapViewOfFile(data);
1623 HeapFree(GetProcessHeap(), 0, filename);
1624 return hr;
1627 HRESULT WINAPI D3DXCreateCubeTextureFromFileExW(IDirect3DDevice9 *device,
1628 const WCHAR *src_filename,
1629 UINT size,
1630 UINT mip_levels,
1631 DWORD usage,
1632 D3DFORMAT format,
1633 D3DPOOL pool,
1634 DWORD filter,
1635 DWORD mip_filter,
1636 D3DCOLOR color_key,
1637 D3DXIMAGE_INFO *image_info,
1638 PALETTEENTRY *palette,
1639 IDirect3DCubeTexture9 **cube_texture)
1641 HRESULT hr;
1642 void *data;
1643 DWORD data_size;
1645 TRACE("(%p, %s, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p): relay\n",
1646 device, wine_dbgstr_w(src_filename), size, mip_levels, usage, format,
1647 pool, filter, mip_filter, color_key, image_info, palette, cube_texture);
1649 hr = map_view_of_file(src_filename, &data, &data_size);
1650 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
1652 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, data, data_size, size, mip_levels,
1653 usage, format, pool, filter, mip_filter, color_key, image_info, palette, cube_texture);
1655 UnmapViewOfFile(data);
1656 return hr;
1659 enum cube_coord
1661 XCOORD = 0,
1662 XCOORDINV = 1,
1663 YCOORD = 2,
1664 YCOORDINV = 3,
1665 ZERO = 4,
1666 ONE = 5
1669 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
1671 switch (coord)
1673 case XCOORD:
1674 return x + 0.5f;
1675 case XCOORDINV:
1676 return size - x - 0.5f;
1677 case YCOORD:
1678 return y + 0.5f;
1679 case YCOORDINV:
1680 return size - y - 0.5f;
1681 case ZERO:
1682 return 0.0f;
1683 case ONE:
1684 return size;
1685 default:
1686 ERR("Unexpected coordinate value\n");
1687 return 0.0f;
1691 HRESULT WINAPI D3DXFillCubeTexture(struct IDirect3DCubeTexture9 *texture, LPD3DXFILL3D function, void *funcdata)
1693 DWORD miplevels;
1694 DWORD m, x, y, f;
1695 D3DSURFACE_DESC desc;
1696 D3DLOCKED_RECT lock_rect;
1697 D3DXVECTOR4 value;
1698 D3DXVECTOR3 coord, size;
1699 const struct pixel_format_desc *format;
1700 BYTE *data;
1701 static const enum cube_coord coordmap[6][3] =
1703 {ONE, YCOORDINV, XCOORDINV},
1704 {ZERO, YCOORDINV, XCOORD},
1705 {XCOORD, ONE, YCOORD},
1706 {XCOORD, ZERO, YCOORDINV},
1707 {XCOORD, YCOORDINV, ONE},
1708 {XCOORDINV, YCOORDINV, ZERO}
1711 if (texture == NULL || function == NULL)
1712 return D3DERR_INVALIDCALL;
1714 miplevels = IDirect3DBaseTexture9_GetLevelCount(texture);
1716 for (m = 0; m < miplevels; m++)
1718 if (FAILED(IDirect3DCubeTexture9_GetLevelDesc(texture, m, &desc)))
1719 return D3DERR_INVALIDCALL;
1721 format = get_format_info(desc.Format);
1722 if (format->type != FORMAT_ARGB && format->type != FORMAT_ARGBF16 && format->type != FORMAT_ARGBF)
1724 FIXME("Unsupported texture format %#x\n", desc.Format);
1725 return D3DERR_INVALIDCALL;
1728 for (f = 0; f < 6; f++)
1730 if (FAILED(IDirect3DCubeTexture9_LockRect(texture, f, m, &lock_rect, NULL, D3DLOCK_DISCARD)))
1731 return D3DERR_INVALIDCALL;
1733 size.x = (f == 0) || (f == 1) ? 0.0f : 2.0f / desc.Width;
1734 size.y = (f == 2) || (f == 3) ? 0.0f : 2.0f / desc.Width;
1735 size.z = (f == 4) || (f == 5) ? 0.0f : 2.0f / desc.Width;
1737 data = lock_rect.pBits;
1739 for (y = 0; y < desc.Height; y++)
1741 for (x = 0; x < desc.Width; x++)
1743 coord.x = get_cube_coord(coordmap[f][0], x, y, desc.Width) / desc.Width * 2.0f - 1.0f;
1744 coord.y = get_cube_coord(coordmap[f][1], x, y, desc.Width) / desc.Width * 2.0f - 1.0f;
1745 coord.z = get_cube_coord(coordmap[f][2], x, y, desc.Width) / desc.Width * 2.0f - 1.0f;
1747 function(&value, &coord, &size, funcdata);
1749 fill_texture(format, data + y * lock_rect.Pitch + x * format->bytes_per_pixel, &value);
1752 IDirect3DCubeTexture9_UnlockRect(texture, f, m);
1756 return D3D_OK;
1759 HRESULT WINAPI D3DXFillCubeTextureTX(struct IDirect3DCubeTexture9 *texture, ID3DXTextureShader *texture_shader)
1761 FIXME("texture %p, texture_shader %p stub.\n", texture, texture_shader);
1762 return E_NOTIMPL;
1765 HRESULT WINAPI D3DXFillVolumeTexture(struct IDirect3DVolumeTexture9 *texture, LPD3DXFILL3D function, void *funcdata)
1767 DWORD miplevels;
1768 DWORD m, x, y, z;
1769 D3DVOLUME_DESC desc;
1770 D3DLOCKED_BOX lock_box;
1771 D3DXVECTOR4 value;
1772 D3DXVECTOR3 coord, size;
1773 const struct pixel_format_desc *format;
1774 BYTE *data;
1776 if (texture == NULL || function == NULL)
1777 return D3DERR_INVALIDCALL;
1779 miplevels = IDirect3DBaseTexture9_GetLevelCount(texture);
1781 for (m = 0; m < miplevels; m++)
1783 if (FAILED(IDirect3DVolumeTexture9_GetLevelDesc(texture, m, &desc)))
1784 return D3DERR_INVALIDCALL;
1786 format = get_format_info(desc.Format);
1787 if (format->type != FORMAT_ARGB && format->type != FORMAT_ARGBF16 && format->type != FORMAT_ARGBF)
1789 FIXME("Unsupported texture format %#x\n", desc.Format);
1790 return D3DERR_INVALIDCALL;
1793 if (FAILED(IDirect3DVolumeTexture9_LockBox(texture, m, &lock_box, NULL, D3DLOCK_DISCARD)))
1794 return D3DERR_INVALIDCALL;
1796 size.x = 1.0f / desc.Width;
1797 size.y = 1.0f / desc.Height;
1798 size.z = 1.0f / desc.Depth;
1800 data = lock_box.pBits;
1802 for (z = 0; z < desc.Depth; z++)
1804 /* The callback function expects the coordinates of the center
1805 of the texel */
1806 coord.z = (z + 0.5f) / desc.Depth;
1808 for (y = 0; y < desc.Height; y++)
1810 coord.y = (y + 0.5f) / desc.Height;
1812 for (x = 0; x < desc.Width; x++)
1814 coord.x = (x + 0.5f) / desc.Width;
1816 function(&value, &coord, &size, funcdata);
1818 fill_texture(format, data + z * lock_box.SlicePitch + y * lock_box.RowPitch
1819 + x * format->bytes_per_pixel, &value);
1823 IDirect3DVolumeTexture9_UnlockBox(texture, m);
1826 return D3D_OK;
1829 HRESULT WINAPI D3DXFillVolumeTextureTX(struct IDirect3DVolumeTexture9 *texture, ID3DXTextureShader *texture_shader)
1831 FIXME("texture %p, texture_shader %p stub.\n", texture, texture_shader);
1832 return E_NOTIMPL;
1835 HRESULT WINAPI D3DXSaveTextureToFileA(const char *dst_filename, D3DXIMAGE_FILEFORMAT file_format,
1836 IDirect3DBaseTexture9 *src_texture, const PALETTEENTRY *src_palette)
1838 int len;
1839 WCHAR *filename;
1840 HRESULT hr;
1841 ID3DXBuffer *buffer;
1843 TRACE("(%s, %#x, %p, %p): relay\n",
1844 wine_dbgstr_a(dst_filename), file_format, src_texture, src_palette);
1846 if (!dst_filename) return D3DERR_INVALIDCALL;
1848 len = MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, NULL, 0);
1849 filename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1850 if (!filename) return E_OUTOFMEMORY;
1851 MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, filename, len);
1853 hr = D3DXSaveTextureToFileInMemory(&buffer, file_format, src_texture, src_palette);
1854 if (SUCCEEDED(hr))
1856 hr = write_buffer_to_file(filename, buffer);
1857 ID3DXBuffer_Release(buffer);
1860 HeapFree(GetProcessHeap(), 0, filename);
1861 return hr;
1864 HRESULT WINAPI D3DXSaveTextureToFileW(const WCHAR *dst_filename, D3DXIMAGE_FILEFORMAT file_format,
1865 IDirect3DBaseTexture9 *src_texture, const PALETTEENTRY *src_palette)
1867 HRESULT hr;
1868 ID3DXBuffer *buffer;
1870 TRACE("(%s, %#x, %p, %p): relay\n",
1871 wine_dbgstr_w(dst_filename), file_format, src_texture, src_palette);
1873 if (!dst_filename) return D3DERR_INVALIDCALL;
1875 hr = D3DXSaveTextureToFileInMemory(&buffer, file_format, src_texture, src_palette);
1876 if (SUCCEEDED(hr))
1878 hr = write_buffer_to_file(dst_filename, buffer);
1879 ID3DXBuffer_Release(buffer);
1882 return hr;
1885 HRESULT WINAPI D3DXSaveTextureToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE_FILEFORMAT file_format,
1886 IDirect3DBaseTexture9 *src_texture, const PALETTEENTRY *src_palette)
1888 HRESULT hr;
1889 D3DRESOURCETYPE type;
1890 IDirect3DSurface9 *surface;
1892 TRACE("(%p, %#x, %p, %p)\n",
1893 dst_buffer, file_format, src_texture, src_palette);
1895 if (!dst_buffer || !src_texture) return D3DERR_INVALIDCALL;
1897 if (file_format == D3DXIFF_DDS)
1899 FIXME("DDS file format isn't supported yet\n");
1900 return E_NOTIMPL;
1903 type = IDirect3DBaseTexture9_GetType(src_texture);
1904 switch (type)
1906 case D3DRTYPE_TEXTURE:
1907 case D3DRTYPE_CUBETEXTURE:
1908 hr = get_surface(type, src_texture, D3DCUBEMAP_FACE_POSITIVE_X, 0, &surface);
1909 break;
1910 case D3DRTYPE_VOLUMETEXTURE:
1911 FIXME("Volume textures aren't supported yet\n");
1912 return E_NOTIMPL;
1913 default:
1914 return D3DERR_INVALIDCALL;
1917 if (SUCCEEDED(hr))
1919 hr = D3DXSaveSurfaceToFileInMemory(dst_buffer, file_format, surface, src_palette, NULL);
1920 IDirect3DSurface9_Release(surface);
1923 return hr;
1926 HRESULT WINAPI D3DXComputeNormalMap(IDirect3DTexture9 *texture, IDirect3DTexture9 *src_texture,
1927 const PALETTEENTRY *src_palette, DWORD flags, DWORD channel, float amplitude)
1929 FIXME("texture %p, src_texture %p, src_palette %p, flags %#x, channel %u, amplitude %.8e stub.\n",
1930 texture, src_texture, src_palette, flags, channel, amplitude);
1932 return D3D_OK;