TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / d3dx9_36 / texture.c
blob38349e2e33eee8bed80e0a6d480a6b85a70616af
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 "wine/unicode.h"
23 #include "wine/debug.h"
24 #include "d3dx9_36_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
28 /* Returns TRUE if num is a power of 2, FALSE if not, or if 0 */
29 static BOOL is_pow2(UINT num)
31 return !(num & (num - 1));
34 /* Returns the smallest power of 2 which is greater than or equal to num */
35 static UINT make_pow2(UINT num)
37 UINT result = 1;
39 /* In the unlikely event somebody passes a large value, make sure we don't enter an infinite loop */
40 if (num >= 0x80000000)
41 return 0x80000000;
43 while (result < num)
44 result <<= 1;
46 return result;
49 static HRESULT get_surface(D3DRESOURCETYPE type, struct IDirect3DBaseTexture9 *tex,
50 int face, UINT level, struct IDirect3DSurface9 **surf)
52 switch (type)
54 case D3DRTYPE_TEXTURE:
55 return IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) tex, level, surf);
56 case D3DRTYPE_CUBETEXTURE:
57 return IDirect3DCubeTexture9_GetCubeMapSurface((IDirect3DCubeTexture9*) tex, face, level, surf);
58 default:
59 ERR("Unexpected texture type\n");
60 return E_NOTIMPL;
64 HRESULT WINAPI D3DXFilterTexture(IDirect3DBaseTexture9 *texture,
65 const PALETTEENTRY *palette,
66 UINT srclevel,
67 DWORD filter)
69 UINT level;
70 HRESULT hr;
71 D3DRESOURCETYPE type;
73 TRACE("(%p, %p, %u, %#x)\n", texture, palette, srclevel, filter);
75 if (!texture)
76 return D3DERR_INVALIDCALL;
78 if ((filter & 0xFFFF) > D3DX_FILTER_BOX && filter != D3DX_DEFAULT)
79 return D3DERR_INVALIDCALL;
81 if (srclevel == D3DX_DEFAULT)
82 srclevel = 0;
83 else if (srclevel >= IDirect3DBaseTexture9_GetLevelCount(texture))
84 return D3DERR_INVALIDCALL;
86 switch (type = IDirect3DBaseTexture9_GetType(texture))
88 case D3DRTYPE_TEXTURE:
89 case D3DRTYPE_CUBETEXTURE:
91 IDirect3DSurface9 *topsurf, *mipsurf;
92 D3DSURFACE_DESC desc;
93 int i, numfaces;
95 if (type == D3DRTYPE_TEXTURE)
97 numfaces = 1;
98 IDirect3DTexture9_GetLevelDesc((IDirect3DTexture9*) texture, srclevel, &desc);
100 else
102 numfaces = 6;
103 IDirect3DCubeTexture9_GetLevelDesc((IDirect3DTexture9*) texture, srclevel, &desc);
106 if (filter == D3DX_DEFAULT)
108 if (is_pow2(desc.Width) && is_pow2(desc.Height))
109 filter = D3DX_FILTER_BOX;
110 else
111 filter = D3DX_FILTER_BOX | D3DX_FILTER_DITHER;
114 for (i = 0; i < numfaces; i++)
116 level = srclevel + 1;
117 hr = get_surface(type, texture, i, srclevel, &topsurf);
119 if (FAILED(hr))
120 return D3DERR_INVALIDCALL;
122 while (get_surface(type, texture, i, level, &mipsurf) == D3D_OK)
124 hr = D3DXLoadSurfaceFromSurface(mipsurf, palette, NULL, topsurf, palette, NULL, filter, 0);
125 IDirect3DSurface9_Release(topsurf);
126 topsurf = mipsurf;
128 if (FAILED(hr))
129 break;
131 level++;
134 IDirect3DSurface9_Release(topsurf);
135 if (FAILED(hr))
136 return hr;
139 return D3D_OK;
142 case D3DRTYPE_VOLUMETEXTURE:
144 D3DVOLUME_DESC desc;
145 int level, level_count;
146 IDirect3DVolume9 *top_volume, *mip_volume;
147 IDirect3DVolumeTexture9 *volume_texture = (IDirect3DVolumeTexture9*) texture;
149 IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, srclevel, &desc);
151 if (filter == D3DX_DEFAULT)
153 if (is_pow2(desc.Width) && is_pow2(desc.Height) && is_pow2(desc.Depth))
154 filter = D3DX_FILTER_BOX;
155 else
156 filter = D3DX_FILTER_BOX | D3DX_FILTER_DITHER;
159 hr = IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, srclevel, &top_volume);
160 if (FAILED(hr))
161 return hr;
163 level_count = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
164 for (level = srclevel + 1; level < level_count; level++)
166 IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, level, &mip_volume);
167 hr = D3DXLoadVolumeFromVolume(mip_volume, palette, NULL, top_volume, palette, NULL, filter, 0);
168 IDirect3DVolume9_Release(top_volume);
169 top_volume = mip_volume;
171 if (FAILED(hr))
172 break;
175 IDirect3DVolume9_Release(top_volume);
176 if (FAILED(hr))
177 return hr;
179 return D3D_OK;
182 default:
183 return D3DERR_INVALIDCALL;
187 static D3DFORMAT get_luminance_replacement_format(D3DFORMAT format)
189 static const struct
191 D3DFORMAT luminance_format;
192 D3DFORMAT replacement_format;
193 } luminance_replacements[] =
195 {D3DFMT_L8, D3DFMT_X8R8G8B8},
196 {D3DFMT_A8L8, D3DFMT_A8R8G8B8},
197 {D3DFMT_A4L4, D3DFMT_A4R4G4B4},
198 {D3DFMT_L16, D3DFMT_A16B16G16R16}
200 unsigned int i;
202 for (i = 0; i < sizeof(luminance_replacements) / sizeof(luminance_replacements[0]); ++i)
203 if (format == luminance_replacements[i].luminance_format)
204 return luminance_replacements[i].replacement_format;
205 return format;
208 HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UINT *width, UINT *height,
209 UINT *miplevels, DWORD usage, D3DFORMAT *format, D3DPOOL pool)
211 UINT w = (width && *width) ? *width : 1;
212 UINT h = (height && *height) ? *height : 1;
213 D3DCAPS9 caps;
214 D3DDEVICE_CREATION_PARAMETERS params;
215 IDirect3D9 *d3d = NULL;
216 D3DDISPLAYMODE mode;
217 HRESULT hr;
218 D3DFORMAT usedformat = D3DFMT_UNKNOWN;
219 const struct pixel_format_desc *fmt;
221 TRACE("(%p, %p, %p, %p, %u, %p, %u)\n", device, width, height, miplevels, usage, format, pool);
223 if (!device)
224 return D3DERR_INVALIDCALL;
226 /* usage */
227 if (usage == D3DX_DEFAULT)
228 usage = 0;
229 if (usage & (D3DUSAGE_WRITEONLY | D3DUSAGE_DONOTCLIP | D3DUSAGE_POINTS | D3DUSAGE_RTPATCHES | D3DUSAGE_NPATCHES))
230 return D3DERR_INVALIDCALL;
232 /* pool */
233 if ((pool != D3DPOOL_DEFAULT) && (pool != D3DPOOL_MANAGED) && (pool != D3DPOOL_SYSTEMMEM) && (pool != D3DPOOL_SCRATCH))
234 return D3DERR_INVALIDCALL;
236 /* format */
237 if (format)
239 TRACE("Requested format %x\n", *format);
240 usedformat = *format;
243 hr = IDirect3DDevice9_GetDirect3D(device, &d3d);
245 if (FAILED(hr))
246 goto cleanup;
248 hr = IDirect3DDevice9_GetCreationParameters(device, &params);
250 if (FAILED(hr))
251 goto cleanup;
253 hr = IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
255 if (FAILED(hr))
256 goto cleanup;
258 if ((usedformat == D3DFMT_UNKNOWN) || (usedformat == D3DX_DEFAULT))
259 usedformat = D3DFMT_A8R8G8B8;
261 fmt = get_format_info(usedformat);
263 hr = IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType, mode.Format,
264 usage, D3DRTYPE_TEXTURE, usedformat);
265 if (FAILED(hr))
267 BOOL allow_24bits;
268 int bestscore = INT_MIN, i = 0, j;
269 unsigned int channels;
270 const struct pixel_format_desc *curfmt, *bestfmt = NULL;
272 TRACE("Requested format is not supported, looking for a fallback.\n");
274 if (!fmt)
276 FIXME("Pixel format %x not handled\n", usedformat);
277 goto cleanup;
279 fmt = get_format_info(get_luminance_replacement_format(usedformat));
281 allow_24bits = fmt->bytes_per_pixel == 3;
282 channels = !!fmt->bits[0] + !!fmt->bits[1] + !!fmt->bits[2] + !!fmt->bits[3];
283 usedformat = D3DFMT_UNKNOWN;
285 while ((curfmt = get_format_info_idx(i)))
287 unsigned int curchannels = !!curfmt->bits[0] + !!curfmt->bits[1]
288 + !!curfmt->bits[2] + !!curfmt->bits[3];
289 int score;
291 i++;
293 if (curchannels < channels)
294 continue;
295 if (curfmt->bytes_per_pixel == 3 && !allow_24bits)
296 continue;
298 hr = IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
299 mode.Format, usage, D3DRTYPE_TEXTURE, curfmt->format);
300 if (FAILED(hr))
301 continue;
303 /* This format can be used, let's evaluate it.
304 Weights chosen quite arbitrarily... */
305 score = 512 * (curfmt->type == fmt->type);
306 score -= 32 * (curchannels - channels);
308 for (j = 0; j < 4; j++)
310 int diff = curfmt->bits[j] - fmt->bits[j];
311 score -= (diff < 0 ? -diff * 8 : diff) * (j == 0 ? 1 : 2);
314 if (score > bestscore)
316 bestscore = score;
317 usedformat = curfmt->format;
318 bestfmt = curfmt;
321 fmt = bestfmt;
322 hr = D3D_OK;
325 if (FAILED(IDirect3DDevice9_GetDeviceCaps(device, &caps)))
326 return D3DERR_INVALIDCALL;
328 if ((w == D3DX_DEFAULT) && (h == D3DX_DEFAULT))
329 w = h = 256;
330 else if (w == D3DX_DEFAULT)
331 w = (height ? h : 256);
332 else if (h == D3DX_DEFAULT)
333 h = (width ? w : 256);
335 if (fmt->block_width != 1 || fmt->block_height != 1)
337 if (w < fmt->block_width)
338 w = fmt->block_width;
339 if (h < fmt->block_height)
340 h = fmt->block_height;
343 if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && (!is_pow2(w)))
344 w = make_pow2(w);
346 if (w > caps.MaxTextureWidth)
347 w = caps.MaxTextureWidth;
349 if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && (!is_pow2(h)))
350 h = make_pow2(h);
352 if (h > caps.MaxTextureHeight)
353 h = caps.MaxTextureHeight;
355 if (caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY)
357 if (w > h)
358 h = w;
359 else
360 w = h;
363 if (width)
364 *width = w;
366 if (height)
367 *height = h;
369 if (miplevels && (usage & D3DUSAGE_AUTOGENMIPMAP))
371 if (*miplevels > 1)
372 *miplevels = 0;
374 else if (miplevels)
376 UINT max_mipmaps = 1;
378 if (!width && !height)
379 max_mipmaps = 9; /* number of mipmaps in a 256x256 texture */
380 else
382 UINT max_dimen = max(w, h);
384 while (max_dimen > 1)
386 max_dimen >>= 1;
387 max_mipmaps++;
391 if (*miplevels == 0 || *miplevels > max_mipmaps)
392 *miplevels = max_mipmaps;
395 cleanup:
397 if (d3d)
398 IDirect3D9_Release(d3d);
400 if (FAILED(hr))
401 return hr;
403 if (usedformat == D3DFMT_UNKNOWN)
405 WARN("Couldn't find a suitable pixel format\n");
406 return D3DERR_NOTAVAILABLE;
409 TRACE("Format chosen: %x\n", usedformat);
410 if (format)
411 *format = usedformat;
413 return D3D_OK;
416 HRESULT WINAPI D3DXCheckCubeTextureRequirements(struct IDirect3DDevice9 *device, UINT *size,
417 UINT *miplevels, DWORD usage, D3DFORMAT *format, D3DPOOL pool)
419 D3DCAPS9 caps;
420 UINT s = (size && *size) ? *size : 256;
421 HRESULT hr;
423 TRACE("(%p, %p, %p, %u, %p, %u)\n", device, size, miplevels, usage, format, pool);
425 if (s == D3DX_DEFAULT)
426 s = 256;
428 if (!device || FAILED(IDirect3DDevice9_GetDeviceCaps(device, &caps)))
429 return D3DERR_INVALIDCALL;
431 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
432 return D3DERR_NOTAVAILABLE;
434 /* ensure width/height is power of 2 */
435 if ((caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2) && (!is_pow2(s)))
436 s = make_pow2(s);
438 hr = D3DXCheckTextureRequirements(device, &s, &s, miplevels, usage, format, pool);
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 = D3DXCheckTextureRequirements(device, &w, &h, NULL, usage, format, pool);
471 if (d == D3DX_DEFAULT)
472 d = 1;
474 /* ensure width/height is power of 2 */
475 if ((caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2) &&
476 (!is_pow2(w) || !is_pow2(h) || !is_pow2(d)))
478 w = make_pow2(w);
479 h = make_pow2(h);
480 d = make_pow2(d);
483 if (w > caps.MaxVolumeExtent)
484 w = caps.MaxVolumeExtent;
485 if (h > caps.MaxVolumeExtent)
486 h = caps.MaxVolumeExtent;
487 if (d > caps.MaxVolumeExtent)
488 d = caps.MaxVolumeExtent;
490 if (miplevels)
492 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
493 *miplevels = 1;
494 else if ((usage & D3DUSAGE_AUTOGENMIPMAP))
496 if (*miplevels > 1)
497 *miplevels = 0;
499 else
501 UINT max_mipmaps = 1;
502 UINT max_dimen = max(max(w, h), d);
504 while (max_dimen > 1)
506 max_dimen >>= 1;
507 max_mipmaps++;
510 if (*miplevels == 0 || *miplevels > max_mipmaps)
511 *miplevels = max_mipmaps;
515 if (width)
516 *width = w;
517 if (height)
518 *height = h;
519 if (depth)
520 *depth = d;
522 return hr;
525 HRESULT WINAPI D3DXCreateTexture(struct IDirect3DDevice9 *device, UINT width, UINT height,
526 UINT miplevels, DWORD usage, D3DFORMAT format, D3DPOOL pool, struct IDirect3DTexture9 **texture)
528 HRESULT hr;
530 TRACE("device %p, width %u, height %u, miplevels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
531 device, width, height, miplevels, usage, format, pool, texture);
533 if (!device || !texture)
534 return D3DERR_INVALIDCALL;
536 if (FAILED(hr = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, usage, &format, pool)))
537 return hr;
539 return IDirect3DDevice9_CreateTexture(device, width, height, miplevels, usage, format, pool, texture, NULL);
542 static D3DFORMAT get_alpha_replacement_format(D3DFORMAT format)
544 static const struct
546 D3DFORMAT orig_format;
547 D3DFORMAT replacement_format;
549 replacement_formats[] =
551 {D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8},
552 {D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5},
553 {D3DFMT_X4R4G4B4, D3DFMT_A4R4G4B4},
554 {D3DFMT_X8B8G8R8, D3DFMT_A8B8G8R8},
555 {D3DFMT_L8, D3DFMT_A8L8},
557 unsigned int i;
559 for (i = 0; i < sizeof(replacement_formats) / sizeof(replacement_formats[0]); ++i)
560 if (replacement_formats[i].orig_format == format)
561 return replacement_formats[i].replacement_format;
562 return format;
565 HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(struct IDirect3DDevice9 *device, const void *srcdata,
566 UINT srcdatasize, UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format,
567 D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
568 PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
570 IDirect3DTexture9 **texptr;
571 IDirect3DTexture9 *buftex;
572 IDirect3DSurface9 *surface;
573 BOOL dynamic_texture, format_specified = FALSE;
574 D3DXIMAGE_INFO imginfo;
575 UINT loaded_miplevels, skip_levels;
576 D3DCAPS9 caps;
577 HRESULT hr;
579 TRACE("device %p, srcdata %p, srcdatasize %u, width %u, height %u, miplevels %u,"
580 " usage %#x, format %#x, pool %#x, filter %#x, mipfilter %#x, colorkey %#x,"
581 " srcinfo %p, palette %p, texture %p.\n",
582 device, srcdata, srcdatasize, width, height, miplevels, usage, format, pool,
583 filter, mipfilter, colorkey, srcinfo, palette, texture);
585 /* check for invalid parameters */
586 if (!device || !texture || !srcdata || !srcdatasize)
587 return D3DERR_INVALIDCALL;
589 hr = D3DXGetImageInfoFromFileInMemory(srcdata, srcdatasize, &imginfo);
590 if (FAILED(hr))
592 FIXME("Unrecognized file format, returning failure.\n");
593 *texture = NULL;
594 return hr;
597 /* handle default values */
598 if (width == 0 || width == D3DX_DEFAULT_NONPOW2)
599 width = imginfo.Width;
601 if (height == 0 || height == D3DX_DEFAULT_NONPOW2)
602 height = imginfo.Height;
604 if (width == D3DX_DEFAULT)
605 width = make_pow2(imginfo.Width);
607 if (height == D3DX_DEFAULT)
608 height = make_pow2(imginfo.Height);
610 if (format == D3DFMT_UNKNOWN || format == D3DX_DEFAULT)
611 format = imginfo.Format;
612 else
613 format_specified = TRUE;
615 if (width == D3DX_FROM_FILE)
617 width = imginfo.Width;
620 if (height == D3DX_FROM_FILE)
622 height = imginfo.Height;
625 if (format == D3DFMT_FROM_FILE)
627 format = imginfo.Format;
630 if (miplevels == D3DX_FROM_FILE)
632 miplevels = imginfo.MipLevels;
635 skip_levels = mipfilter != D3DX_DEFAULT ? mipfilter >> D3DX_SKIP_DDS_MIP_LEVELS_SHIFT : 0;
636 if (skip_levels && imginfo.MipLevels > skip_levels)
638 TRACE("Skipping the first %u (of %u) levels of a DDS mipmapped texture.\n",
639 skip_levels, imginfo.MipLevels);
640 TRACE("Texture level 0 dimensions are %ux%u.\n", imginfo.Width, imginfo.Height);
641 width >>= skip_levels;
642 height >>= skip_levels;
643 miplevels -= skip_levels;
645 else
647 skip_levels = 0;
650 /* fix texture creation parameters */
651 hr = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, usage, &format, pool);
652 if (FAILED(hr))
654 FIXME("Couldn't find suitable texture parameters.\n");
655 *texture = NULL;
656 return hr;
659 if (colorkey && !format_specified)
660 format = get_alpha_replacement_format(format);
662 if (imginfo.MipLevels < miplevels && (D3DFMT_DXT1 <= imginfo.Format && imginfo.Format <= D3DFMT_DXT5))
664 FIXME("Generation of mipmaps for compressed pixel formats is not implemented yet.\n");
665 miplevels = imginfo.MipLevels;
667 if (imginfo.ResourceType == D3DRTYPE_VOLUMETEXTURE
668 && D3DFMT_DXT1 <= imginfo.Format && imginfo.Format <= D3DFMT_DXT5 && miplevels > 1)
670 FIXME("Generation of mipmaps for compressed pixel formats is not implemented yet.\n");
671 miplevels = 1;
674 if (FAILED(IDirect3DDevice9_GetDeviceCaps(device, &caps)))
675 return D3DERR_INVALIDCALL;
677 /* Create the to-be-filled texture */
678 dynamic_texture = (caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) && (usage & D3DUSAGE_DYNAMIC);
679 if (pool == D3DPOOL_DEFAULT && !dynamic_texture)
681 hr = D3DXCreateTexture(device, width, height, miplevels, usage, format, D3DPOOL_SYSTEMMEM, &buftex);
682 texptr = &buftex;
684 else
686 hr = D3DXCreateTexture(device, width, height, miplevels, usage, format, pool, texture);
687 texptr = texture;
690 if (FAILED(hr))
692 FIXME("Texture creation failed.\n");
693 *texture = NULL;
694 return hr;
697 TRACE("Texture created correctly. Now loading the texture data into it.\n");
698 if (imginfo.ImageFileFormat != D3DXIFF_DDS)
700 IDirect3DTexture9_GetSurfaceLevel(*texptr, 0, &surface);
701 hr = D3DXLoadSurfaceFromFileInMemory(surface, palette, NULL, srcdata, srcdatasize, NULL, filter, colorkey, NULL);
702 IDirect3DSurface9_Release(surface);
703 loaded_miplevels = min(IDirect3DTexture9_GetLevelCount(*texptr), imginfo.MipLevels);
705 else
707 hr = load_texture_from_dds(*texptr, srcdata, palette, filter, colorkey, &imginfo, skip_levels,
708 &loaded_miplevels);
711 if (FAILED(hr))
713 FIXME("Texture loading failed.\n");
714 IDirect3DTexture9_Release(*texptr);
715 *texture = NULL;
716 return hr;
719 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) *texptr, palette, loaded_miplevels - 1, mipfilter);
720 if (FAILED(hr))
722 FIXME("Texture filtering failed.\n");
723 IDirect3DTexture9_Release(*texptr);
724 *texture = NULL;
725 return hr;
728 /* Move the data to the actual texture if necessary */
729 if (texptr == &buftex)
731 hr = D3DXCreateTexture(device, width, height, miplevels, usage, format, pool, texture);
733 if (FAILED(hr))
735 IDirect3DTexture9_Release(buftex);
736 *texture = NULL;
737 return hr;
740 IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9*)buftex, (IDirect3DBaseTexture9*)(*texture));
741 IDirect3DTexture9_Release(buftex);
744 if (srcinfo)
745 *srcinfo = imginfo;
747 return D3D_OK;
750 HRESULT WINAPI D3DXCreateTextureFromFileInMemory(struct IDirect3DDevice9 *device,
751 const void *srcdata, UINT srcdatasize, struct IDirect3DTexture9 **texture)
753 TRACE("(%p, %p, %d, %p)\n", device, srcdata, srcdatasize, texture);
755 return D3DXCreateTextureFromFileInMemoryEx(device, srcdata, srcdatasize, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
756 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
759 HRESULT WINAPI D3DXCreateTextureFromFileExW(struct IDirect3DDevice9 *device, const WCHAR *srcfile,
760 UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format,
761 D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
762 PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
764 void *buffer;
765 HRESULT hr;
766 DWORD size;
768 TRACE("device %p, srcfile %s, width %u, height %u, miplevels %u, usage %#x, format %#x, "
769 "pool %#x, filter %#x, mipfilter %#x, colorkey 0x%08x, srcinfo %p, palette %p, texture %p.\n",
770 device, debugstr_w(srcfile), width, height, miplevels, usage, format,
771 pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
773 if (!srcfile)
774 return D3DERR_INVALIDCALL;
776 hr = map_view_of_file(srcfile, &buffer, &size);
777 if (FAILED(hr))
778 return D3DXERR_INVALIDDATA;
780 hr = D3DXCreateTextureFromFileInMemoryEx(device, buffer, size, width, height, miplevels, usage, format, pool,
781 filter, mipfilter, colorkey, srcinfo, palette, texture);
783 UnmapViewOfFile(buffer);
785 return hr;
788 HRESULT WINAPI D3DXCreateTextureFromFileExA(struct IDirect3DDevice9 *device, const char *srcfile,
789 UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format,
790 D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
791 PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
793 WCHAR *widename;
794 HRESULT hr;
795 DWORD len;
797 TRACE("device %p, srcfile %s, width %u, height %u, miplevels %u, usage %#x, format %#x, "
798 "pool %#x, filter %#x, mipfilter %#x, colorkey 0x%08x, srcinfo %p, palette %p, texture %p.\n",
799 device, debugstr_a(srcfile), width, height, miplevels, usage, format,
800 pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
802 if (!device || !srcfile || !texture)
803 return D3DERR_INVALIDCALL;
805 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
806 widename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*widename));
807 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, widename, len);
809 hr = D3DXCreateTextureFromFileExW(device, widename, width, height, miplevels,
810 usage, format, pool, filter, mipfilter,
811 colorkey, srcinfo, palette, texture);
813 HeapFree(GetProcessHeap(), 0, widename);
814 return hr;
817 HRESULT WINAPI D3DXCreateTextureFromFileA(struct IDirect3DDevice9 *device,
818 const char *srcfile, struct IDirect3DTexture9 **texture)
820 TRACE("(%p, %s, %p)\n", device, debugstr_a(srcfile), texture);
822 return D3DXCreateTextureFromFileExA(device, srcfile, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
823 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
826 HRESULT WINAPI D3DXCreateTextureFromFileW(struct IDirect3DDevice9 *device,
827 const WCHAR *srcfile, struct IDirect3DTexture9 **texture)
829 TRACE("(%p, %s, %p)\n", device, debugstr_w(srcfile), texture);
831 return D3DXCreateTextureFromFileExW(device, srcfile, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
832 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
836 HRESULT WINAPI D3DXCreateTextureFromResourceA(struct IDirect3DDevice9 *device,
837 HMODULE srcmodule, const char *resource, struct IDirect3DTexture9 **texture)
839 TRACE("(%p, %s): relay\n", srcmodule, debugstr_a(resource));
841 return D3DXCreateTextureFromResourceExA(device, srcmodule, resource, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
842 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
845 HRESULT WINAPI D3DXCreateTextureFromResourceW(struct IDirect3DDevice9 *device,
846 HMODULE srcmodule, const WCHAR *resource, struct IDirect3DTexture9 **texture)
848 TRACE("(%p, %s): relay\n", srcmodule, debugstr_w(resource));
850 return D3DXCreateTextureFromResourceExW(device, srcmodule, resource, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
851 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
854 HRESULT WINAPI D3DXCreateTextureFromResourceExA(struct IDirect3DDevice9 *device, HMODULE srcmodule,
855 const char *resource, UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format,
856 D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
857 PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
859 HRSRC resinfo;
860 void *buffer;
861 DWORD size;
863 TRACE("device %p, srcmodule %p, resource %s, width %u, height %u, miplevels %u, usage %#x, format %#x, "
864 "pool %#x, filter %#x, mipfilter %#x, colorkey 0x%08x, srcinfo %p, palette %p, texture %p.\n",
865 device, srcmodule, debugstr_a(resource), width, height, miplevels, usage, format,
866 pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
868 if (!device || !texture)
869 return D3DERR_INVALIDCALL;
871 if (!(resinfo = FindResourceA(srcmodule, resource, (const char *)RT_RCDATA))
872 /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
873 && !(resinfo = FindResourceA(srcmodule, resource, (const char *)RT_BITMAP)))
874 return D3DXERR_INVALIDDATA;
876 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
877 return D3DXERR_INVALIDDATA;
879 return D3DXCreateTextureFromFileInMemoryEx(device, buffer, size, width, height, miplevels,
880 usage, format, pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
883 HRESULT WINAPI D3DXCreateTextureFromResourceExW(struct IDirect3DDevice9 *device, HMODULE srcmodule,
884 const WCHAR *resource, UINT width, UINT height, UINT miplevels, DWORD usage, D3DFORMAT format,
885 D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
886 PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
888 HRSRC resinfo;
889 void *buffer;
890 DWORD size;
892 TRACE("device %p, srcmodule %p, resource %s, width %u, height %u, miplevels %u, usage %#x, format %#x, "
893 "pool %#x, filter %#x, mipfilter %#x, colorkey 0x%08x, srcinfo %p, palette %p, texture %p.\n",
894 device, srcmodule, debugstr_w(resource), width, height, miplevels, usage, format,
895 pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
897 if (!device || !texture)
898 return D3DERR_INVALIDCALL;
900 if (!(resinfo = FindResourceW(srcmodule, resource, (const WCHAR *)RT_RCDATA))
901 /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
902 && !(resinfo = FindResourceW(srcmodule, resource, (const WCHAR *)RT_BITMAP)))
903 return D3DXERR_INVALIDDATA;
905 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
906 return D3DXERR_INVALIDDATA;
908 return D3DXCreateTextureFromFileInMemoryEx(device, buffer, size, width, height, miplevels,
909 usage, format, pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
912 HRESULT WINAPI D3DXCreateCubeTexture(struct IDirect3DDevice9 *device, UINT size, UINT miplevels,
913 DWORD usage, D3DFORMAT format, D3DPOOL pool, struct IDirect3DCubeTexture9 **texture)
915 HRESULT hr;
917 TRACE("(%p, %u, %u, %#x, %#x, %#x, %p)\n", device, size, miplevels, usage, format,
918 pool, texture);
920 if (!device || !texture)
921 return D3DERR_INVALIDCALL;
923 hr = D3DXCheckCubeTextureRequirements(device, &size, &miplevels, usage, &format, pool);
925 if (FAILED(hr))
927 TRACE("D3DXCheckCubeTextureRequirements failed\n");
928 return hr;
931 return IDirect3DDevice9_CreateCubeTexture(device, size, miplevels, usage, format, pool, texture, NULL);
934 HRESULT WINAPI D3DXCreateCubeTextureFromFileInMemory(struct IDirect3DDevice9 *device,
935 const void *data, UINT datasize, struct IDirect3DCubeTexture9 **texture)
937 TRACE("(%p, %p, %u, %p)\n", device, data, datasize, texture);
939 return D3DXCreateCubeTextureFromFileInMemoryEx(device, data, datasize, D3DX_DEFAULT, D3DX_DEFAULT,
940 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, texture);
943 HRESULT WINAPI D3DXCreateVolumeTexture(struct IDirect3DDevice9 *device, UINT width, UINT height, UINT depth,
944 UINT miplevels, DWORD usage, D3DFORMAT format, D3DPOOL pool, struct IDirect3DVolumeTexture9 **texture)
946 HRESULT hr;
948 TRACE("(%p, %u, %u, %u, %u, %#x, %#x, %#x, %p)\n", device, width, height, depth,
949 miplevels, usage, format, pool, texture);
951 if (!device || !texture)
952 return D3DERR_INVALIDCALL;
954 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth,
955 &miplevels, usage, &format, pool);
957 if (FAILED(hr))
959 TRACE("D3DXCheckVolumeTextureRequirements failed\n");
960 return hr;
963 return IDirect3DDevice9_CreateVolumeTexture(device, width, height, depth, miplevels,
964 usage, format, pool, texture, NULL);
967 HRESULT WINAPI D3DXCreateVolumeTextureFromFileA(IDirect3DDevice9 *device,
968 const char *filename,
969 IDirect3DVolumeTexture9 **volume_texture)
971 int len;
972 HRESULT hr;
973 void *data;
974 DWORD data_size;
975 WCHAR *filenameW;
977 TRACE("(%p, %s, %p): relay\n",
978 device, debugstr_a(filename), volume_texture);
980 if (!filename) return D3DERR_INVALIDCALL;
982 len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
983 filenameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
984 if (!filenameW) return E_OUTOFMEMORY;
985 MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, len);
987 hr = map_view_of_file(filenameW, &data, &data_size);
988 HeapFree(GetProcessHeap(), 0, filenameW);
989 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
991 hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, data, data_size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
992 D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, volume_texture);
994 UnmapViewOfFile(data);
995 return hr;
998 HRESULT WINAPI D3DXCreateVolumeTextureFromFileW(IDirect3DDevice9 *device,
999 const WCHAR *filename,
1000 IDirect3DVolumeTexture9 **volume_texture)
1002 HRESULT hr;
1003 void *data;
1004 DWORD data_size;
1006 TRACE("(%p, %s, %p): relay\n",
1007 device, debugstr_w(filename), volume_texture);
1009 if (!filename) return D3DERR_INVALIDCALL;
1011 hr = map_view_of_file(filename, &data, &data_size);
1012 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
1014 hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, data, data_size, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1015 D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, volume_texture);
1017 UnmapViewOfFile(data);
1018 return hr;
1021 HRESULT WINAPI D3DXCreateVolumeTextureFromFileExA(IDirect3DDevice9 *device,
1022 const char *filename,
1023 UINT width,
1024 UINT height,
1025 UINT depth,
1026 UINT mip_levels,
1027 DWORD usage,
1028 D3DFORMAT format,
1029 D3DPOOL pool,
1030 DWORD filter,
1031 DWORD mip_filter,
1032 D3DCOLOR color_key,
1033 D3DXIMAGE_INFO *src_info,
1034 PALETTEENTRY *palette,
1035 IDirect3DVolumeTexture9 **volume_texture)
1037 int len;
1038 HRESULT hr;
1039 WCHAR *filenameW;
1040 void *data;
1041 DWORD data_size;
1043 TRACE("(%p, %s, %u, %u, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p): relay\n",
1044 device, debugstr_a(filename), width, height, depth, mip_levels,
1045 usage, format, pool, filter, mip_filter, color_key, src_info,
1046 palette, volume_texture);
1048 if (!filename) return D3DERR_INVALIDCALL;
1050 len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
1051 filenameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1052 if (!filenameW) return E_OUTOFMEMORY;
1053 MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, len);
1055 hr = map_view_of_file(filenameW, &data, &data_size);
1056 HeapFree(GetProcessHeap(), 0, filenameW);
1057 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
1059 hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, data, data_size, width, height, depth,
1060 mip_levels, usage, format, pool, filter, mip_filter, color_key, src_info, palette,
1061 volume_texture);
1063 UnmapViewOfFile(data);
1064 return hr;
1067 HRESULT WINAPI D3DXCreateVolumeTextureFromFileExW(IDirect3DDevice9 *device,
1068 const WCHAR *filename,
1069 UINT width,
1070 UINT height,
1071 UINT depth,
1072 UINT mip_levels,
1073 DWORD usage,
1074 D3DFORMAT format,
1075 D3DPOOL pool,
1076 DWORD filter,
1077 DWORD mip_filter,
1078 D3DCOLOR color_key,
1079 D3DXIMAGE_INFO *src_info,
1080 PALETTEENTRY *palette,
1081 IDirect3DVolumeTexture9 **volume_texture)
1083 HRESULT hr;
1084 void *data;
1085 DWORD data_size;
1087 TRACE("(%p, %s, %u, %u, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p): relay\n",
1088 device, debugstr_w(filename), width, height, depth, mip_levels,
1089 usage, format, pool, filter, mip_filter, color_key, src_info,
1090 palette, volume_texture);
1092 if (!filename) return D3DERR_INVALIDCALL;
1094 hr = map_view_of_file(filename, &data, &data_size);
1095 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
1097 hr = D3DXCreateVolumeTextureFromFileInMemoryEx(device, data, data_size, width, height, depth,
1098 mip_levels, usage, format, pool, filter, mip_filter, color_key, src_info, palette,
1099 volume_texture);
1101 UnmapViewOfFile(data);
1102 return hr;
1105 HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device,
1106 const void *data,
1107 UINT data_size,
1108 IDirect3DVolumeTexture9 **volume_texture)
1110 TRACE("(%p, %p, %u, %p): relay\n", device, data, data_size, volume_texture);
1112 return D3DXCreateVolumeTextureFromFileInMemoryEx(device, data, data_size, D3DX_DEFAULT, D3DX_DEFAULT,
1113 D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT,
1114 0, NULL, NULL, volume_texture);
1117 HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *device,
1118 const void *data,
1119 UINT data_size,
1120 UINT width,
1121 UINT height,
1122 UINT depth,
1123 UINT mip_levels,
1124 DWORD usage,
1125 D3DFORMAT format,
1126 D3DPOOL pool,
1127 DWORD filter,
1128 DWORD mip_filter,
1129 D3DCOLOR color_key,
1130 D3DXIMAGE_INFO *info,
1131 PALETTEENTRY *palette,
1132 IDirect3DVolumeTexture9 **volume_texture)
1134 HRESULT hr;
1135 D3DCAPS9 caps;
1136 D3DXIMAGE_INFO image_info;
1137 BOOL dynamic_texture;
1138 BOOL file_width = FALSE;
1139 BOOL file_height = FALSE;
1140 BOOL file_depth = FALSE;
1141 BOOL file_format = FALSE;
1142 BOOL file_mip_levels = FALSE;
1143 IDirect3DVolumeTexture9 *tex, *buftex;
1145 TRACE("(%p, %p, %u, %u, %u, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p)\n",
1146 device, data, data_size, width, height, depth, mip_levels, usage, format, pool,
1147 filter, mip_filter, color_key, info, palette, volume_texture);
1149 if (!device || !data || !data_size || !volume_texture)
1150 return D3DERR_INVALIDCALL;
1152 hr = D3DXGetImageInfoFromFileInMemory(data, data_size, &image_info);
1153 if (FAILED(hr)) return hr;
1155 if (image_info.ImageFileFormat != D3DXIFF_DDS)
1156 return D3DXERR_INVALIDDATA;
1158 if (width == 0 || width == D3DX_DEFAULT_NONPOW2)
1159 width = image_info.Width;
1160 if (width == D3DX_DEFAULT)
1161 width = make_pow2(image_info.Width);
1163 if (height == 0 || height == D3DX_DEFAULT_NONPOW2)
1164 height = image_info.Height;
1165 if (height == D3DX_DEFAULT)
1166 height = make_pow2(image_info.Height);
1168 if (depth == 0 || depth == D3DX_DEFAULT_NONPOW2)
1169 depth = image_info.Depth;
1170 if (depth == D3DX_DEFAULT)
1171 depth = make_pow2(image_info.Depth);
1173 if (format == D3DFMT_UNKNOWN || format == D3DX_DEFAULT)
1174 format = image_info.Format;
1176 if (width == D3DX_FROM_FILE)
1178 file_width = TRUE;
1179 width = image_info.Width;
1182 if (height == D3DX_FROM_FILE)
1184 file_height = TRUE;
1185 height = image_info.Height;
1188 if (depth == D3DX_FROM_FILE)
1190 file_depth = TRUE;
1191 depth = image_info.Depth;
1194 if (format == D3DFMT_FROM_FILE)
1196 file_format = TRUE;
1197 format = image_info.Format;
1200 if (mip_levels == D3DX_FROM_FILE)
1202 file_mip_levels = TRUE;
1203 mip_levels = image_info.MipLevels;
1206 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mip_levels, usage, &format, pool);
1207 if (FAILED(hr)) return hr;
1209 if ((file_width && width != image_info.Width)
1210 || (file_height && height != image_info.Height)
1211 || (file_depth && depth != image_info.Depth)
1212 || (file_format && format != image_info.Format)
1213 || (file_mip_levels && mip_levels != image_info.MipLevels))
1214 return D3DERR_NOTAVAILABLE;
1216 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1217 if (FAILED(hr))
1218 return D3DERR_INVALIDCALL;
1220 if (mip_levels > image_info.MipLevels)
1222 FIXME("Generation of mipmaps for volume textures is not implemented yet.\n");
1223 mip_levels = image_info.MipLevels;
1226 dynamic_texture = (caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) && (usage & D3DUSAGE_DYNAMIC);
1227 if (pool == D3DPOOL_DEFAULT && !dynamic_texture)
1229 hr = D3DXCreateVolumeTexture(device, width, height, depth, mip_levels, usage, format, D3DPOOL_SYSTEMMEM, &buftex);
1230 tex = buftex;
1232 else
1234 hr = D3DXCreateVolumeTexture(device, width, height, depth, mip_levels, usage, format, pool, &tex);
1235 buftex = NULL;
1238 if (FAILED(hr)) return hr;
1240 hr = load_volume_texture_from_dds(tex, data, palette, filter, color_key, &image_info);
1241 if (FAILED(hr))
1243 IDirect3DVolumeTexture9_Release(tex);
1244 return hr;
1247 if (buftex)
1249 hr = D3DXCreateVolumeTexture(device, width, height, depth, mip_levels, usage, format, pool, &tex);
1250 if (FAILED(hr))
1252 IDirect3DVolumeTexture9_Release(buftex);
1253 return hr;
1256 IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)buftex, (IDirect3DBaseTexture9 *)tex);
1257 IDirect3DVolumeTexture9_Release(buftex);
1260 if (info)
1261 *info = image_info;
1263 *volume_texture = tex;
1264 return D3D_OK;
1267 static inline void fill_texture(const struct pixel_format_desc *format, BYTE *pos, const D3DXVECTOR4 *value)
1269 DWORD c;
1271 for (c = 0; c < format->bytes_per_pixel; c++)
1272 pos[c] = 0;
1274 for (c = 0; c < 4; c++)
1276 float comp_value;
1277 DWORD i, v = 0, mask32 = format->bits[c] == 32 ? ~0U : ((1 << format->bits[c]) - 1);
1279 switch (c)
1281 case 0: /* Alpha */
1282 comp_value = value->w;
1283 break;
1284 case 1: /* Red */
1285 comp_value = value->x;
1286 break;
1287 case 2: /* Green */
1288 comp_value = value->y;
1289 break;
1290 case 3: /* Blue */
1291 comp_value = value->z;
1292 break;
1295 if (format->type == FORMAT_ARGBF16)
1296 v = float_32_to_16(comp_value);
1297 else if (format->type == FORMAT_ARGBF)
1298 v = *(DWORD *)&comp_value;
1299 else if (format->type == FORMAT_ARGB)
1300 v = comp_value * ((1 << format->bits[c]) - 1) + 0.5f;
1301 else
1302 FIXME("Unhandled format type %#x\n", format->type);
1304 for (i = 0; i < format->bits[c] + format->shift[c]; i += 8)
1306 BYTE byte, mask;
1308 if (format->shift[c] > i)
1310 mask = mask32 << (format->shift[c] - i);
1311 byte = (v << (format->shift[c] - i)) & mask;
1313 else
1315 mask = mask32 >> (i - format->shift[c]);
1316 byte = (v >> (i - format->shift[c])) & mask;
1318 pos[i / 8] |= byte;
1323 HRESULT WINAPI D3DXFillTexture(struct IDirect3DTexture9 *texture, LPD3DXFILL2D function, void *funcdata)
1325 DWORD miplevels;
1326 DWORD m, x, y;
1327 D3DSURFACE_DESC desc;
1328 D3DLOCKED_RECT lock_rect;
1329 D3DXVECTOR4 value;
1330 D3DXVECTOR2 coord, size;
1331 const struct pixel_format_desc *format;
1332 BYTE *data;
1334 if (texture == NULL || function == NULL)
1335 return D3DERR_INVALIDCALL;
1337 miplevels = IDirect3DBaseTexture9_GetLevelCount(texture);
1339 for (m = 0; m < miplevels; m++)
1341 if (FAILED(IDirect3DTexture9_GetLevelDesc(texture, m, &desc)))
1342 return D3DERR_INVALIDCALL;
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(IDirect3DTexture9_LockRect(texture, m, &lock_rect, NULL, D3DLOCK_DISCARD)))
1352 return D3DERR_INVALIDCALL;
1354 size.x = 1.0f / desc.Width;
1355 size.y = 1.0f / desc.Height;
1357 data = lock_rect.pBits;
1359 for (y = 0; y < desc.Height; y++)
1361 /* The callback function expects the coordinates of the center
1362 of the texel */
1363 coord.y = (y + 0.5f) / desc.Height;
1365 for (x = 0; x < desc.Width; x++)
1367 coord.x = (x + 0.5f) / desc.Width;
1369 function(&value, &coord, &size, funcdata);
1371 fill_texture(format, data + y * lock_rect.Pitch + x * format->bytes_per_pixel, &value);
1374 IDirect3DTexture9_UnlockRect(texture, m);
1377 return D3D_OK;
1380 HRESULT WINAPI D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device,
1381 const void *src_data,
1382 UINT src_data_size,
1383 UINT size,
1384 UINT mip_levels,
1385 DWORD usage,
1386 D3DFORMAT format,
1387 D3DPOOL pool,
1388 DWORD filter,
1389 DWORD mip_filter,
1390 D3DCOLOR color_key,
1391 D3DXIMAGE_INFO *src_info,
1392 PALETTEENTRY *palette,
1393 IDirect3DCubeTexture9 **cube_texture)
1395 HRESULT hr;
1396 D3DCAPS9 caps;
1397 UINT loaded_miplevels;
1398 D3DXIMAGE_INFO img_info;
1399 BOOL dynamic_texture;
1400 BOOL file_size = FALSE;
1401 BOOL file_format = FALSE;
1402 BOOL file_mip_levels = FALSE;
1403 IDirect3DCubeTexture9 *tex, *buftex;
1405 TRACE("(%p, %p, %u, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p)\n", device,
1406 src_data, src_data_size, size, mip_levels, usage, format, pool, filter, mip_filter,
1407 color_key, src_info, palette, cube_texture);
1409 if (!device || !cube_texture || !src_data || !src_data_size)
1410 return D3DERR_INVALIDCALL;
1412 hr = D3DXGetImageInfoFromFileInMemory(src_data, src_data_size, &img_info);
1413 if (FAILED(hr))
1414 return hr;
1416 if (img_info.ImageFileFormat != D3DXIFF_DDS)
1417 return D3DXERR_INVALIDDATA;
1419 if (img_info.Width != img_info.Height)
1420 return D3DXERR_INVALIDDATA;
1422 if (size == 0 || size == D3DX_DEFAULT_NONPOW2)
1423 size = img_info.Width;
1424 if (size == D3DX_DEFAULT)
1425 size = make_pow2(img_info.Width);
1427 if (format == D3DFMT_UNKNOWN || format == D3DX_DEFAULT)
1428 format = img_info.Format;
1430 if (size == D3DX_FROM_FILE)
1432 file_size = TRUE;
1433 size = img_info.Width;
1436 if (format == D3DFMT_FROM_FILE)
1438 file_format = TRUE;
1439 format = img_info.Format;
1442 if (mip_levels == D3DX_FROM_FILE)
1444 file_mip_levels = TRUE;
1445 mip_levels = img_info.MipLevels;
1448 hr = D3DXCheckCubeTextureRequirements(device, &size, &mip_levels, usage, &format, pool);
1449 if (FAILED(hr))
1450 return hr;
1452 if ((file_size && size != img_info.Width)
1453 || (file_format && format != img_info.Format)
1454 || (file_mip_levels && mip_levels != img_info.MipLevels))
1455 return D3DERR_NOTAVAILABLE;
1457 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1458 if (FAILED(hr))
1459 return D3DERR_INVALIDCALL;
1461 if (mip_levels > img_info.MipLevels && (D3DFMT_DXT1 <= img_info.Format && img_info.Format <= D3DFMT_DXT5))
1463 FIXME("Generation of mipmaps for compressed pixel formats is not supported yet.\n");
1464 mip_levels = img_info.MipLevels;
1467 dynamic_texture = (caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) && (usage & D3DUSAGE_DYNAMIC);
1468 if (pool == D3DPOOL_DEFAULT && !dynamic_texture)
1470 hr = D3DXCreateCubeTexture(device, size, mip_levels, usage, format, D3DPOOL_SYSTEMMEM, &buftex);
1471 tex = buftex;
1473 else
1475 hr = D3DXCreateCubeTexture(device, size, mip_levels, usage, format, pool, &tex);
1476 buftex = NULL;
1478 if (FAILED(hr))
1479 return hr;
1481 hr = load_cube_texture_from_dds(tex, src_data, palette, filter, color_key, &img_info);
1482 if (FAILED(hr))
1484 IDirect3DCubeTexture9_Release(tex);
1485 return hr;
1488 loaded_miplevels = min(IDirect3DCubeTexture9_GetLevelCount(tex), img_info.MipLevels);
1489 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, palette, loaded_miplevels - 1, mip_filter);
1490 if (FAILED(hr))
1492 IDirect3DCubeTexture9_Release(tex);
1493 return hr;
1496 if (buftex)
1498 hr = D3DXCreateCubeTexture(device, size, mip_levels, usage, format, pool, &tex);
1499 if (FAILED(hr))
1501 IDirect3DCubeTexture9_Release(buftex);
1502 return hr;
1505 IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)buftex, (IDirect3DBaseTexture9 *)tex);
1506 IDirect3DCubeTexture9_Release(buftex);
1509 if (src_info)
1510 *src_info = img_info;
1512 *cube_texture = tex;
1513 return D3D_OK;
1517 HRESULT WINAPI D3DXCreateCubeTextureFromFileA(IDirect3DDevice9 *device,
1518 const char *src_filename,
1519 IDirect3DCubeTexture9 **cube_texture)
1521 int len;
1522 HRESULT hr;
1523 WCHAR *filename;
1524 void *data;
1525 DWORD data_size;
1527 TRACE("(%p, %s, %p): relay\n", device, wine_dbgstr_a(src_filename), cube_texture);
1529 if (!src_filename) return D3DERR_INVALIDCALL;
1531 len = MultiByteToWideChar(CP_ACP, 0, src_filename, -1, NULL, 0);
1532 filename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1533 if (!filename) return E_OUTOFMEMORY;
1534 MultiByteToWideChar(CP_ACP, 0, src_filename, -1, filename, len);
1536 hr = map_view_of_file(filename, &data, &data_size);
1537 if (FAILED(hr))
1539 HeapFree(GetProcessHeap(), 0, filename);
1540 return D3DXERR_INVALIDDATA;
1543 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, data, data_size, D3DX_DEFAULT, D3DX_DEFAULT,
1544 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, cube_texture);
1546 UnmapViewOfFile(data);
1547 HeapFree(GetProcessHeap(), 0, filename);
1548 return hr;
1551 HRESULT WINAPI D3DXCreateCubeTextureFromFileW(IDirect3DDevice9 *device,
1552 const WCHAR *src_filename,
1553 IDirect3DCubeTexture9 **cube_texture)
1555 HRESULT hr;
1556 void *data;
1557 DWORD data_size;
1559 TRACE("(%p, %s, %p): relay\n", device, wine_dbgstr_w(src_filename), cube_texture);
1561 hr = map_view_of_file(src_filename, &data, &data_size);
1562 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
1564 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, data, data_size, D3DX_DEFAULT, D3DX_DEFAULT,
1565 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, cube_texture);
1567 UnmapViewOfFile(data);
1568 return hr;
1571 HRESULT WINAPI D3DXCreateCubeTextureFromFileExA(IDirect3DDevice9 *device,
1572 const char *src_filename,
1573 UINT size,
1574 UINT mip_levels,
1575 DWORD usage,
1576 D3DFORMAT format,
1577 D3DPOOL pool,
1578 DWORD filter,
1579 DWORD mip_filter,
1580 D3DCOLOR color_key,
1581 D3DXIMAGE_INFO *image_info,
1582 PALETTEENTRY *palette,
1583 IDirect3DCubeTexture9 **cube_texture)
1585 int len;
1586 HRESULT hr;
1587 WCHAR *filename;
1588 void *data;
1589 DWORD data_size;
1591 TRACE("(%p, %s, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p): relay\n",
1592 device, wine_dbgstr_a(src_filename), size, mip_levels, usage, format,
1593 pool, filter, mip_filter, color_key, image_info, palette, cube_texture);
1595 if (!src_filename) return D3DERR_INVALIDCALL;
1597 len = MultiByteToWideChar(CP_ACP, 0, src_filename, -1, NULL, 0);
1598 filename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1599 if (!filename) return E_OUTOFMEMORY;
1600 MultiByteToWideChar(CP_ACP, 0, src_filename, -1, filename, len);
1602 hr = map_view_of_file(filename, &data, &data_size);
1603 if (FAILED(hr))
1605 HeapFree(GetProcessHeap(), 0, filename);
1606 return D3DXERR_INVALIDDATA;
1609 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, data, data_size, size, mip_levels,
1610 usage, format, pool, filter, mip_filter, color_key, image_info, palette, cube_texture);
1612 UnmapViewOfFile(data);
1613 HeapFree(GetProcessHeap(), 0, filename);
1614 return hr;
1617 HRESULT WINAPI D3DXCreateCubeTextureFromFileExW(IDirect3DDevice9 *device,
1618 const WCHAR *src_filename,
1619 UINT size,
1620 UINT mip_levels,
1621 DWORD usage,
1622 D3DFORMAT format,
1623 D3DPOOL pool,
1624 DWORD filter,
1625 DWORD mip_filter,
1626 D3DCOLOR color_key,
1627 D3DXIMAGE_INFO *image_info,
1628 PALETTEENTRY *palette,
1629 IDirect3DCubeTexture9 **cube_texture)
1631 HRESULT hr;
1632 void *data;
1633 DWORD data_size;
1635 TRACE("(%p, %s, %u, %u, %#x, %#x, %#x, %#x, %#x, %#x, %p, %p, %p): relay\n",
1636 device, wine_dbgstr_w(src_filename), size, mip_levels, usage, format,
1637 pool, filter, mip_filter, color_key, image_info, palette, cube_texture);
1639 hr = map_view_of_file(src_filename, &data, &data_size);
1640 if (FAILED(hr)) return D3DXERR_INVALIDDATA;
1642 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, data, data_size, size, mip_levels,
1643 usage, format, pool, filter, mip_filter, color_key, image_info, palette, cube_texture);
1645 UnmapViewOfFile(data);
1646 return hr;
1649 enum cube_coord
1651 XCOORD = 0,
1652 XCOORDINV = 1,
1653 YCOORD = 2,
1654 YCOORDINV = 3,
1655 ZERO = 4,
1656 ONE = 5
1659 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
1661 switch (coord)
1663 case XCOORD:
1664 return x + 0.5f;
1665 case XCOORDINV:
1666 return size - x - 0.5f;
1667 case YCOORD:
1668 return y + 0.5f;
1669 case YCOORDINV:
1670 return size - y - 0.5f;
1671 case ZERO:
1672 return 0.0f;
1673 case ONE:
1674 return size;
1675 default:
1676 ERR("Unexpected coordinate value\n");
1677 return 0.0f;
1681 HRESULT WINAPI D3DXFillCubeTexture(struct IDirect3DCubeTexture9 *texture, LPD3DXFILL3D function, void *funcdata)
1683 DWORD miplevels;
1684 DWORD m, x, y, f;
1685 D3DSURFACE_DESC desc;
1686 D3DLOCKED_RECT lock_rect;
1687 D3DXVECTOR4 value;
1688 D3DXVECTOR3 coord, size;
1689 const struct pixel_format_desc *format;
1690 BYTE *data;
1691 static const enum cube_coord coordmap[6][3] =
1693 {ONE, YCOORDINV, XCOORDINV},
1694 {ZERO, YCOORDINV, XCOORD},
1695 {XCOORD, ONE, YCOORD},
1696 {XCOORD, ZERO, YCOORDINV},
1697 {XCOORD, YCOORDINV, ONE},
1698 {XCOORDINV, YCOORDINV, ZERO}
1701 if (texture == NULL || function == NULL)
1702 return D3DERR_INVALIDCALL;
1704 miplevels = IDirect3DBaseTexture9_GetLevelCount(texture);
1706 for (m = 0; m < miplevels; m++)
1708 if (FAILED(IDirect3DCubeTexture9_GetLevelDesc(texture, m, &desc)))
1709 return D3DERR_INVALIDCALL;
1711 format = get_format_info(desc.Format);
1712 if (format->type != FORMAT_ARGB && format->type != FORMAT_ARGBF16 && format->type != FORMAT_ARGBF)
1714 FIXME("Unsupported texture format %#x\n", desc.Format);
1715 return D3DERR_INVALIDCALL;
1718 for (f = 0; f < 6; f++)
1720 if (FAILED(IDirect3DCubeTexture9_LockRect(texture, f, m, &lock_rect, NULL, D3DLOCK_DISCARD)))
1721 return D3DERR_INVALIDCALL;
1723 size.x = (f == 0) || (f == 1) ? 0.0f : 2.0f / desc.Width;
1724 size.y = (f == 2) || (f == 3) ? 0.0f : 2.0f / desc.Width;
1725 size.z = (f == 4) || (f == 5) ? 0.0f : 2.0f / desc.Width;
1727 data = lock_rect.pBits;
1729 for (y = 0; y < desc.Height; y++)
1731 for (x = 0; x < desc.Width; x++)
1733 coord.x = get_cube_coord(coordmap[f][0], x, y, desc.Width) / desc.Width * 2.0f - 1.0f;
1734 coord.y = get_cube_coord(coordmap[f][1], x, y, desc.Width) / desc.Width * 2.0f - 1.0f;
1735 coord.z = get_cube_coord(coordmap[f][2], x, y, desc.Width) / desc.Width * 2.0f - 1.0f;
1737 function(&value, &coord, &size, funcdata);
1739 fill_texture(format, data + y * lock_rect.Pitch + x * format->bytes_per_pixel, &value);
1742 IDirect3DCubeTexture9_UnlockRect(texture, f, m);
1746 return D3D_OK;
1749 HRESULT WINAPI D3DXFillVolumeTexture(struct IDirect3DVolumeTexture9 *texture, LPD3DXFILL3D function, void *funcdata)
1751 DWORD miplevels;
1752 DWORD m, x, y, z;
1753 D3DVOLUME_DESC desc;
1754 D3DLOCKED_BOX lock_box;
1755 D3DXVECTOR4 value;
1756 D3DXVECTOR3 coord, size;
1757 const struct pixel_format_desc *format;
1758 BYTE *data;
1760 if (texture == NULL || function == NULL)
1761 return D3DERR_INVALIDCALL;
1763 miplevels = IDirect3DBaseTexture9_GetLevelCount(texture);
1765 for (m = 0; m < miplevels; m++)
1767 if (FAILED(IDirect3DVolumeTexture9_GetLevelDesc(texture, m, &desc)))
1768 return D3DERR_INVALIDCALL;
1770 format = get_format_info(desc.Format);
1771 if (format->type != FORMAT_ARGB && format->type != FORMAT_ARGBF16 && format->type != FORMAT_ARGBF)
1773 FIXME("Unsupported texture format %#x\n", desc.Format);
1774 return D3DERR_INVALIDCALL;
1777 if (FAILED(IDirect3DVolumeTexture9_LockBox(texture, m, &lock_box, NULL, D3DLOCK_DISCARD)))
1778 return D3DERR_INVALIDCALL;
1780 size.x = 1.0f / desc.Width;
1781 size.y = 1.0f / desc.Height;
1782 size.z = 1.0f / desc.Depth;
1784 data = lock_box.pBits;
1786 for (z = 0; z < desc.Depth; z++)
1788 /* The callback function expects the coordinates of the center
1789 of the texel */
1790 coord.z = (z + 0.5f) / desc.Depth;
1792 for (y = 0; y < desc.Height; y++)
1794 coord.y = (y + 0.5f) / desc.Height;
1796 for (x = 0; x < desc.Width; x++)
1798 coord.x = (x + 0.5f) / desc.Width;
1800 function(&value, &coord, &size, funcdata);
1802 fill_texture(format, data + z * lock_box.SlicePitch + y * lock_box.RowPitch
1803 + x * format->bytes_per_pixel, &value);
1807 IDirect3DVolumeTexture9_UnlockBox(texture, m);
1810 return D3D_OK;
1813 HRESULT WINAPI D3DXSaveTextureToFileA(const char *dst_filename, D3DXIMAGE_FILEFORMAT file_format,
1814 IDirect3DBaseTexture9 *src_texture, const PALETTEENTRY *src_palette)
1816 int len;
1817 WCHAR *filename;
1818 HRESULT hr;
1819 ID3DXBuffer *buffer;
1821 TRACE("(%s, %#x, %p, %p): relay\n",
1822 wine_dbgstr_a(dst_filename), file_format, src_texture, src_palette);
1824 if (!dst_filename) return D3DERR_INVALIDCALL;
1826 len = MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, NULL, 0);
1827 filename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1828 if (!filename) return E_OUTOFMEMORY;
1829 MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, filename, len);
1831 hr = D3DXSaveTextureToFileInMemory(&buffer, file_format, src_texture, src_palette);
1832 if (SUCCEEDED(hr))
1834 hr = write_buffer_to_file(filename, buffer);
1835 ID3DXBuffer_Release(buffer);
1838 HeapFree(GetProcessHeap(), 0, filename);
1839 return hr;
1842 HRESULT WINAPI D3DXSaveTextureToFileW(const WCHAR *dst_filename, D3DXIMAGE_FILEFORMAT file_format,
1843 IDirect3DBaseTexture9 *src_texture, const PALETTEENTRY *src_palette)
1845 HRESULT hr;
1846 ID3DXBuffer *buffer;
1848 TRACE("(%s, %#x, %p, %p): relay\n",
1849 wine_dbgstr_w(dst_filename), file_format, src_texture, src_palette);
1851 if (!dst_filename) return D3DERR_INVALIDCALL;
1853 hr = D3DXSaveTextureToFileInMemory(&buffer, file_format, src_texture, src_palette);
1854 if (SUCCEEDED(hr))
1856 hr = write_buffer_to_file(dst_filename, buffer);
1857 ID3DXBuffer_Release(buffer);
1860 return hr;
1863 HRESULT WINAPI D3DXSaveTextureToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE_FILEFORMAT file_format,
1864 IDirect3DBaseTexture9 *src_texture, const PALETTEENTRY *src_palette)
1866 HRESULT hr;
1867 D3DRESOURCETYPE type;
1868 IDirect3DSurface9 *surface;
1870 TRACE("(%p, %#x, %p, %p)\n",
1871 dst_buffer, file_format, src_texture, src_palette);
1873 if (!dst_buffer || !src_texture) return D3DERR_INVALIDCALL;
1875 if (file_format == D3DXIFF_DDS)
1877 FIXME("DDS file format isn't supported yet\n");
1878 return E_NOTIMPL;
1881 type = IDirect3DBaseTexture9_GetType(src_texture);
1882 switch (type)
1884 case D3DRTYPE_TEXTURE:
1885 case D3DRTYPE_CUBETEXTURE:
1886 hr = get_surface(type, src_texture, D3DCUBEMAP_FACE_POSITIVE_X, 0, &surface);
1887 break;
1888 case D3DRTYPE_VOLUMETEXTURE:
1889 FIXME("Volume textures aren't supported yet\n");
1890 return E_NOTIMPL;
1891 default:
1892 return D3DERR_INVALIDCALL;
1895 if (SUCCEEDED(hr))
1897 hr = D3DXSaveSurfaceToFileInMemory(dst_buffer, file_format, surface, src_palette, NULL);
1898 IDirect3DSurface9_Release(surface);
1901 return hr;