d3dx9: Apply current transform in ID3DXSprite_Draw instead of ID3DXSprite_Flush.
[wine/d3dx9TW.git] / dlls / d3dx9_36 / texture.c
blobe939dffad5d7045abb5dc8d7631f5baff509c56d
1 /*
2 * Copyright (C) 2009 Tony Wasserka
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/debug.h"
21 #include "wine/unicode.h"
22 #include "d3dx9_36_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
26 /************************************************************
27 * D3DXFilterTexture
29 * Generates a mipmap chain from a given mipmap level of a texture using
30 * the various filters described by the D3DX_FILTER flags.
32 * PARAMS
33 * pTexture [I] pointer to the texture
34 * pPalette [I] palette to use
35 * SrcLevel [I] base source level
36 * dwFilter [I] filter to apply
38 * RETURNS
39 * Success: D3D_OK
40 * Failure: D3DXERR_INVALIDDATA, if pTexture is not lockable
41 * D3DERR_INVALIDCALL, if the parameters are invalid
43 * NOTES
44 * passing D3DX_DEFAULT for SrcLevel equals passing 0
45 * passing D3DX_DEFAULT for dwFilter equals passing D3DX_FILTER_BOX
46 * If the texture size is not a power of two, dithering will be used then additionally.
48 HRESULT WINAPI D3DXFilterTexture(LPDIRECT3DBASETEXTURE9 pTexture,
49 CONST PALETTEENTRY *pPalette,
50 UINT SrcLevel,
51 DWORD dwFilter)
53 UINT Level = SrcLevel + 1;
54 HRESULT hr;
55 TRACE("(void)\n");
57 if( !pTexture ) return D3DERR_INVALIDCALL;
58 if( (dwFilter & 0xFFFF) > D3DX_FILTER_BOX && dwFilter != D3DX_DEFAULT ) return D3DERR_INVALIDCALL;
59 if(SrcLevel >= IDirect3DBaseTexture9_GetLevelCount(pTexture)) return D3DERR_INVALIDCALL;
61 switch(IDirect3DBaseTexture9_GetType(pTexture)) {
62 case D3DRTYPE_TEXTURE:
64 IDirect3DSurface9 *pTopSurf, *pMipSurf;
65 D3DSURFACE_DESC Desc;
67 if(dwFilter == D3DX_DEFAULT) {
68 IDirect3DTexture9_GetLevelDesc((IDirect3DTexture9*)pTexture, SrcLevel, &Desc);
69 if( is_pow2(Desc.Width) && is_pow2(Desc.Height) ) dwFilter = D3DX_FILTER_BOX;
70 else dwFilter = D3DX_FILTER_BOX | D3DX_FILTER_DITHER;
73 hr = IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*)pTexture, SrcLevel, &pTopSurf);
74 if(FAILED(hr)) return D3DERR_INVALIDCALL;
76 while(IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*)pTexture, Level, &pMipSurf) == D3D_OK) {
77 hr = D3DXLoadSurfaceFromSurface(pMipSurf, pPalette, NULL, pTopSurf, pPalette, NULL, dwFilter, 0);
78 IDirect3DSurface9_Release(pMipSurf);
79 if(FAILED(hr)) break;
80 Level++;
82 IDirect3DSurface9_Release(pTopSurf);
83 if(Level == SrcLevel + 1) return D3DERR_INVALIDCALL;
85 return D3D_OK;
87 default:
88 FIXME("Implement volume and cube texture filtering\n");
89 return E_NOTIMPL;
93 /************************************************************
94 * D3DXCheckTextureRequirements
96 * Modifies input parameters so that they're supported by the device.
97 * If a parameter is NULL it is ignored.
99 * PARAMS
100 * pDevice [I ] device which will create the texture
101 * pWidth [IO] width of the texture
102 * pHeight [IO] height of the texture
103 * pMipLevels [IO] number of miplevels to use for the texture
104 * dwUsage [I ] usage of the texture
105 * pFormat [IO] format of the texture
106 * Pool [I ] pool of the texture
108 * RETURNS
109 * Success: D3D_OK
110 * Failure: D3DERR_INVALIDCALL, if there's no way to create a supported texture or
111 * if pDevice, dwUsage or Pool have invalid values
113 * NOTES
114 * If any of the pointer values (except pDevice) is NULL, it will be ignored
117 HRESULT WINAPI D3DXCheckTextureRequirements(LPDIRECT3DDEVICE9 pDevice,
118 UINT *pWidth,
119 UINT *pHeight,
120 UINT *pMipLevels,
121 DWORD dwUsage,
122 D3DFORMAT *pFormat,
123 D3DPOOL Pool)
125 D3DCAPS9 Caps;
126 TRACE("(void)\n");
128 if( !pDevice ) return D3DERR_INVALIDCALL;
130 /* usage */
131 if(dwUsage != D3DX_DEFAULT && dwUsage & (D3DUSAGE_WRITEONLY | D3DUSAGE_DONOTCLIP | D3DUSAGE_POINTS | D3DUSAGE_RTPATCHES | D3DUSAGE_NPATCHES))
132 return D3DERR_INVALIDCALL;
135 /* pool */
136 if (Pool != D3DPOOL_DEFAULT && Pool != D3DPOOL_MANAGED && Pool != D3DPOOL_SYSTEMMEM && Pool != D3DPOOL_SCRATCH)
137 return D3DERR_INVALIDCALL;
140 /* width and height */
141 IDirect3DDevice9_GetDeviceCaps(pDevice, &Caps);
142 if(pWidth && pHeight) {
143 if(*pWidth == D3DX_DEFAULT && *pHeight == D3DX_DEFAULT) *pWidth = *pHeight = 256;
144 else if(*pWidth == D3DX_DEFAULT) *pWidth = *pHeight;
145 else if(*pHeight == D3DX_DEFAULT) *pHeight = *pWidth;
147 if(*pWidth == 0) *pWidth = 1;
148 if(*pHeight == 0) *pHeight = 1;
149 } else if(pWidth) {
150 if(*pWidth == D3DX_DEFAULT) *pWidth = 256;
151 else if(*pWidth == 0) *pWidth = 1;
152 } else if(pHeight) {
153 if(*pHeight == D3DX_DEFAULT) *pHeight = 256;
154 else if(*pHeight == 0) *pHeight = 1;
157 if(pWidth) {
158 if((Caps.TextureCaps & D3DPTEXTURECAPS_POW2) && !is_pow2(*pWidth)) make_pow2(*pWidth); /* !!! */
159 if(*pWidth > Caps.MaxTextureWidth) *pWidth = Caps.MaxTextureWidth;
161 if(pHeight) {
162 if((Caps.TextureCaps & D3DPTEXTURECAPS_POW2) && !is_pow2(*pHeight)) make_pow2(*pHeight);
163 if(*pHeight > Caps.MaxTextureHeight) *pHeight = Caps.MaxTextureHeight;
165 if(pWidth && pHeight && (Caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY)) {
166 if(*pWidth > *pHeight) *pHeight = *pWidth;
167 else *pWidth = *pHeight;
171 /* miplevels */
172 if(pMipLevels) {
173 UINT MaxMipMaps = 1;
175 if( !pWidth && !pHeight ) MaxMipMaps = 9;
176 else {
177 UINT BufWidth = (pWidth) ? (*pWidth) : 1;
178 UINT BufHeight = (pHeight) ? (*pHeight) : 1;
180 while(BufWidth > 1 || BufHeight > 1) {
181 BufWidth >>= 1;
182 BufHeight >>= 1;
183 MaxMipMaps++;
186 if(*pMipLevels == 0 || *pMipLevels > MaxMipMaps) *pMipLevels = MaxMipMaps;
190 /* format */
191 if(pFormat) {
192 IDirect3D9 *pD3D;
193 D3DDEVICE_CREATION_PARAMETERS CPars;
194 D3DDISPLAYMODE Mode;
195 HRESULT hr;
197 IDirect3DDevice9_GetDirect3D(pDevice, &pD3D);
198 IDirect3DDevice9_GetCreationParameters(pDevice, &CPars);
199 IDirect3DDevice9_GetDisplayMode(pDevice, 0, &Mode);
201 if(*pFormat == D3DFMT_UNKNOWN || *pFormat == D3DX_DEFAULT) *pFormat = D3DFMT_A8R8G8B8;
202 hr = IDirect3D9_CheckDeviceFormat(pD3D, CPars.AdapterOrdinal, CPars.DeviceType, Mode.Format, dwUsage, D3DRTYPE_TEXTURE, *pFormat);
203 if(FAILED(hr)) { /* Default to A8R8G8B8 */
204 *pFormat = D3DFMT_A8R8G8B8;
205 hr = IDirect3D9_CheckDeviceFormat(pD3D, CPars.AdapterOrdinal, CPars.DeviceType, Mode.Format, dwUsage, D3DRTYPE_TEXTURE, *pFormat);
207 IDirect3D9_Release(pD3D);
209 if(FAILED(hr)) return D3DERR_INVALIDCALL;
212 return D3D_OK;
215 /************************************************************
216 * D3DXCreateTexture
218 * Changes the input parameters to make sure the texture creation is supported
219 * by the device and creates the texture upon these values
221 * PARAMS
222 * pDevice [I] device which will create the texture
223 * Width [I] width of the texture
224 * Height [I] height of the texture
225 * MipLevels [I] number of miplevels to use
226 * dwUsage [I] usage of the texture
227 * Format [I] format of the texture
228 * Pool [I] pool of the texture
229 * pTexture [O] texture to be created
231 * RETURNS
232 * Success: D3D_OK
233 * Failure: D3DERR_INVALIDCALL, if there's no way to create a supported texture or
234 * if pDevice, dwUsage or Pool have invalid values
237 HRESULT WINAPI D3DXCreateTexture(LPDIRECT3DDEVICE9 pDevice,
238 UINT Width,
239 UINT Height,
240 UINT MipLevels,
241 DWORD dwUsage,
242 D3DFORMAT Format,
243 D3DPOOL Pool,
244 LPDIRECT3DTEXTURE9 *pTexture)
246 HRESULT hr;
247 TRACE("(void)\n");
249 if( !pDevice || !pTexture) return D3DERR_INVALIDCALL;
251 hr = D3DXCheckTextureRequirements(pDevice, &Width, &Height, &MipLevels, dwUsage, &Format, Pool);
252 if(FAILED(hr)) return hr;
254 return IDirect3DDevice9_CreateTexture(pDevice, Width, Height, MipLevels, dwUsage, Format, Pool, pTexture, NULL);
257 /************************************************************
258 * D3DXCreateTextureFromFileInMemoryEx
260 * Fills a D3DXIMAGE_INFO structure with info about an image
262 * PARAMS
263 * pDevice [I] device used to create the texture
264 * pSrcData [I] pointer to the source data
265 * SrcDataSize [I] size of the source data, in bytes
266 * Width [I] width of the texture
267 * Height [I] height of the texture
268 * MipLevels [I] number of miplevels to use
269 * dwUsage [I] usage of the texture
270 * Format [I] format of the texture
271 * Pool [I] pool of the texture
272 * dwFilter [I] filter to apply when stretching
273 * dwMipFilter [I] filter to apply when generating mipmaps
274 * ColorKey [I] color key to apply
275 * pSrcInfo [O] pointer to a D3DXIMAGE_INFO structure
276 * pPalette [O] pointer to a 256-color palette to fill in
277 * ppTexture [O] pointer to the texture
279 * RETURNS
280 * Success: D3D_OK
281 * Failure: D3DXERR_INVALIDDATA
282 * D3DERR_INVALIDCALL
283 * D3DERR_NOTAVAILABLE, if a requested attribute is not available
284 * D3DERR_OUTOFVIDEOMEMORY
286 * NOTES
287 * Width, Height, MipLevels and Format can be set to D3DX_DEFAULT.
288 * We'll read them from the file then.
290 * dwFilter and dwMipFilter can be set to D3DX_DEFAULT, too. dwFilter equals
291 * to D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER and dwMipFilter equals to
292 * D3DX_FILTER_BOX then.
294 * dwUsage may only be 0, D3DUSAGE_DYNAMIC and/or D3DUSAGE_RENDERTARGET
296 * if Format is D3DFMT_UNKNOWN we'll use a format which matches the
297 * file's one best. If Format is D3DFMT_FROM_FILE, we'll only use
298 * the file's format and fail if it's not supported.
300 * ColorKey is always a 32-bit ARGB color. If it's 0, color-keying is disabled.
302 * pSrcInfo and pPalette can be NULL.
305 HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(LPDIRECT3DDEVICE9 pDevice,
306 LPCVOID pSrcData,
307 UINT SrcDataSize,
308 UINT Width,
309 UINT Height,
310 UINT MipLevels,
311 DWORD dwUsage,
312 D3DFORMAT Format,
313 D3DPOOL Pool,
314 DWORD dwFilter,
315 DWORD dwMipFilter,
316 D3DCOLOR ColorKey,
317 D3DXIMAGE_INFO *pSrcInfo,
318 PALETTEENTRY *pPalette,
319 LPDIRECT3DTEXTURE9 *ppTexture)
321 IDirect3DTexture9 **ppTexptr;
322 IDirect3DTexture9 *pBuftex;
323 IDirect3DSurface9 *pSurface;
324 BOOL WidthFromFile = FALSE, HeightFromFile = FALSE;
325 BOOL FormatFromFile = FALSE, MipLevelsFromFile = FALSE;
326 D3DXIMAGE_INFO ImgInfo;
327 HRESULT hr;
328 TRACE("(void)\n");
330 /* check for invalid parameters */
331 if( !pDevice || !ppTexture || !pSrcData || !SrcDataSize ) return D3DERR_INVALIDCALL;
332 if((dwFilter & 0xFFFF) > D3DX_FILTER_BOX && dwFilter != D3DX_DEFAULT) return D3DERR_INVALIDCALL;
333 if((dwMipFilter & 0xFFFF) > D3DX_FILTER_BOX && dwMipFilter != D3DX_DEFAULT) return D3DERR_INVALIDCALL;
334 if( !dwFilter || !dwMipFilter ) return D3DERR_INVALIDCALL;
336 hr = D3DXGetImageInfoFromFileInMemory(pSrcData, SrcDataSize, &ImgInfo);
337 if(FAILED(hr)) {
338 *ppTexture = NULL;
339 return hr;
342 /* handle default values */
343 if(Width == 0 || Width == D3DX_DEFAULT_NONPOW2) Width = ImgInfo.Width;
344 if(Height == 0 || Height == D3DX_DEFAULT_NONPOW2) Height = ImgInfo.Height;
345 if(Width == D3DX_DEFAULT) Width = make_pow2(ImgInfo.Width);
346 if(Height == D3DX_DEFAULT) Height = make_pow2(ImgInfo.Height);
347 if(Format == D3DFMT_UNKNOWN || Format == D3DX_DEFAULT) Format = ImgInfo.Format;
349 if(Width == D3DX_FROM_FILE) {
350 WidthFromFile = TRUE;
351 Width = ImgInfo.Width;
353 if(Height == D3DX_FROM_FILE) {
354 HeightFromFile = TRUE;
355 Height = ImgInfo.Height;
357 if(Format == D3DFMT_FROM_FILE) {
358 FormatFromFile = TRUE;
359 Format = ImgInfo.Format;
361 if(MipLevels == D3DX_FROM_FILE) {
362 MipLevelsFromFile = TRUE;
363 MipLevels = ImgInfo.MipLevels;
365 if(dwFilter == D3DX_DEFAULT) dwFilter = D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER;
366 if(dwMipFilter == D3DX_DEFAULT) dwMipFilter = D3DX_FILTER_BOX;
368 /* fix texture creation parameters */
369 hr = D3DXCheckTextureRequirements(pDevice, &Width, &Height, &MipLevels, dwUsage, &Format, Pool);
370 if(FAILED(hr)) {
371 *ppTexture = NULL;
372 return hr;
375 if(WidthFromFile && Width != ImgInfo.Width) return D3DERR_NOTAVAILABLE;
376 if(HeightFromFile && Height != ImgInfo.Height) return D3DERR_NOTAVAILABLE;
377 if(FormatFromFile && Format != ImgInfo.Format) return D3DERR_NOTAVAILABLE;
378 if(MipLevelsFromFile && MipLevels != ImgInfo.MipLevels) return D3DERR_NOTAVAILABLE;
380 /* Create the to-be-filled texture */
381 if(Pool != D3DPOOL_DEFAULT && dwUsage != D3DUSAGE_DYNAMIC) {
382 hr = D3DXCreateTexture(pDevice, Width, Height, MipLevels, dwUsage, Format, Pool, ppTexture);
383 ppTexptr = ppTexture;
384 } else {
385 hr = D3DXCreateTexture(pDevice, Width, Height, MipLevels, dwUsage, Format, D3DPOOL_SYSTEMMEM, &pBuftex);
386 ppTexptr = &pBuftex;
388 if(FAILED(hr)) {
389 *ppTexture = NULL;
390 return hr;
393 /* Load the file */
394 IDirect3DTexture9_GetSurfaceLevel(*ppTexptr, 0, &pSurface);
395 hr = D3DXLoadSurfaceFromFileInMemory(pSurface, pPalette, NULL, pSrcData, SrcDataSize, NULL, dwFilter, ColorKey, NULL);
396 IDirect3DSurface9_Release(pSurface);
397 if(FAILED(hr)) {
398 IDirect3DTexture9_Release(*ppTexptr);
399 *ppTexture = NULL;
400 return hr;
403 D3DXFilterTexture((IDirect3DBaseTexture9*)*ppTexptr, pPalette, 0, dwMipFilter);
405 /* Move the data to the actual texture if necessary */
406 if(ppTexptr == &pBuftex) {
407 hr = D3DXCreateTexture(pDevice, Width, Height, MipLevels, dwUsage, Format, Pool, ppTexture);
408 if(FAILED(hr)) {
409 IDirect3DTexture9_Release(pBuftex);
410 *ppTexture = NULL;
411 return hr;
413 IDirect3DDevice9_UpdateTexture(pDevice, (IDirect3DBaseTexture9*)pBuftex, (IDirect3DBaseTexture9*)(*ppTexture));
414 IDirect3DTexture9_Release(pBuftex);
416 if(pSrcInfo) *pSrcInfo = ImgInfo;
418 return D3D_OK;
421 HRESULT WINAPI D3DXCreateTextureFromFileInMemory(LPDIRECT3DDEVICE9 pDevice,
422 LPCVOID pSrcData,
423 UINT SrcDataSize,
424 LPDIRECT3DTEXTURE9 *ppTexture)
426 TRACE("(void): relay\n");
427 return D3DXCreateTextureFromFileInMemoryEx(pDevice, pSrcData, SrcDataSize, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
428 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, ppTexture);
431 HRESULT WINAPI D3DXCreateTextureFromFileA(LPDIRECT3DDEVICE9 pDevice,
432 LPCSTR pSrcFile,
433 LPDIRECT3DTEXTURE9 *ppTexture)
435 TRACE("(void): relay\n");
436 return D3DXCreateTextureFromFileExA(pDevice, pSrcFile, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
437 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, ppTexture);
440 HRESULT WINAPI D3DXCreateTextureFromFileW(LPDIRECT3DDEVICE9 pDevice,
441 LPCWSTR pSrcFile,
442 LPDIRECT3DTEXTURE9 *ppTexture)
444 TRACE("(void): relay\n");
445 return D3DXCreateTextureFromFileExW(pDevice, pSrcFile, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
446 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, ppTexture);
449 HRESULT WINAPI D3DXCreateTextureFromFileExA(LPDIRECT3DDEVICE9 pDevice,
450 LPCSTR pSrcFile,
451 UINT Width,
452 UINT Height,
453 UINT MipLevels,
454 DWORD dwUsage,
455 D3DFORMAT Format,
456 D3DPOOL Pool,
457 DWORD dwFilter,
458 DWORD dwMipFilter,
459 D3DCOLOR ColorKey,
460 D3DXIMAGE_INFO *pSrcInfo,
461 PALETTEENTRY *pPalette,
462 LPDIRECT3DTEXTURE9 *ppTexture)
464 LPWSTR pWideName;
465 HRESULT hr;
466 DWORD dwStrLength;
467 TRACE("(void): relay\n");
469 if( !pDevice || !pSrcFile || !ppTexture ) return D3DERR_INVALIDCALL;
471 dwStrLength = MultiByteToWideChar(CP_ACP, 0, pSrcFile, -1, NULL, 0);
472 pWideName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwStrLength * sizeof(WCHAR));
473 MultiByteToWideChar(CP_ACP, 0, pSrcFile, -1, pWideName, dwStrLength);
475 hr = D3DXCreateTextureFromFileExW(pDevice, pWideName, Width, Height, MipLevels,
476 dwUsage, Format, Pool, dwFilter, dwMipFilter,
477 ColorKey, pSrcInfo, pPalette, ppTexture);
478 HeapFree(GetProcessHeap(), 0, pWideName);
480 return hr;
483 HRESULT WINAPI D3DXCreateTextureFromFileExW(LPDIRECT3DDEVICE9 pDevice,
484 LPCWSTR pSrcFile,
485 UINT Width,
486 UINT Height,
487 UINT MipLevels,
488 DWORD dwUsage,
489 D3DFORMAT Format,
490 D3DPOOL Pool,
491 DWORD dwFilter,
492 DWORD dwMipFilter,
493 D3DCOLOR ColorKey,
494 D3DXIMAGE_INFO *pSrcInfo,
495 PALETTEENTRY *pPalette,
496 LPDIRECT3DTEXTURE9 *ppTexture)
498 HRESULT hr;
499 DWORD dwSize;
500 LPVOID pBuffer;
501 TRACE("(void): relay\n");
503 if( !pDevice || !pSrcFile || !ppTexture ) return D3DERR_INVALIDCALL;
505 hr = map_view_of_file(pSrcFile, &pBuffer, &dwSize);
506 if(FAILED(hr)) return D3DXERR_INVALIDDATA;
508 hr = D3DXCreateTextureFromFileInMemoryEx(pDevice, pBuffer, dwSize, Width, Height, MipLevels, dwUsage, Format,
509 Pool, dwFilter, dwMipFilter, ColorKey, pSrcInfo, pPalette, ppTexture);
510 UnmapViewOfFile(pBuffer);
512 return hr;
515 HRESULT WINAPI D3DXCreateTextureFromResourceA(LPDIRECT3DDEVICE9 pDevice,
516 HMODULE hSrcModule,
517 LPCSTR pResource,
518 LPDIRECT3DTEXTURE9 *ppTexture)
520 TRACE("(void): relay\n");
521 return D3DXCreateTextureFromResourceExA(pDevice, hSrcModule, pResource, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
522 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, ppTexture);
525 HRESULT WINAPI D3DXCreateTextureFromResourceW(LPDIRECT3DDEVICE9 pDevice,
526 HMODULE hSrcModule,
527 LPCWSTR pResource,
528 LPDIRECT3DTEXTURE9 *ppTexture)
530 TRACE("(void): relay\n");
531 return D3DXCreateTextureFromResourceExW(pDevice, hSrcModule, pResource, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
532 D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, ppTexture);
535 HRESULT WINAPI D3DXCreateTextureFromResourceExA(LPDIRECT3DDEVICE9 pDevice,
536 HMODULE hSrcModule,
537 LPCSTR pResource,
538 UINT Width,
539 UINT Height,
540 UINT MipLevels,
541 DWORD dwUsage,
542 D3DFORMAT Format,
543 D3DPOOL Pool,
544 DWORD dwFilter,
545 DWORD dwMipFilter,
546 D3DCOLOR ColorKey,
547 D3DXIMAGE_INFO *pSrcInfo,
548 PALETTEENTRY *pPalette,
549 LPDIRECT3DTEXTURE9 *ppTexture)
551 HRSRC ResInfo;
552 TRACE("(void): relay\n");
554 if( !pDevice || !ppTexture ) return D3DERR_INVALIDCALL;
556 ResInfo = FindResourceA(hSrcModule, pResource, (LPCSTR)RT_RCDATA);
557 if(ResInfo) {
558 LPVOID pBuffer;
559 HRESULT hr;
560 DWORD dwSize;
562 hr = load_resource_into_memory(hSrcModule, ResInfo, &pBuffer, &dwSize);
563 if(FAILED(hr)) return D3DXERR_INVALIDDATA;
564 return D3DXCreateTextureFromFileInMemoryEx(pDevice, pBuffer, dwSize, Width,
565 Height, MipLevels, dwUsage, Format,
566 Pool, dwFilter, dwMipFilter, ColorKey,
567 pSrcInfo, pPalette, ppTexture);
570 ResInfo = FindResourceA(hSrcModule, pResource, (LPCSTR)RT_BITMAP);
571 if(ResInfo) {
572 FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
573 return E_NOTIMPL;
575 return D3DXERR_INVALIDDATA;
578 HRESULT WINAPI D3DXCreateTextureFromResourceExW(LPDIRECT3DDEVICE9 pDevice,
579 HMODULE hSrcModule,
580 LPCWSTR pResource,
581 UINT Width,
582 UINT Height,
583 UINT MipLevels,
584 DWORD dwUsage,
585 D3DFORMAT Format,
586 D3DPOOL Pool,
587 DWORD dwFilter,
588 DWORD dwMipFilter,
589 D3DCOLOR ColorKey,
590 D3DXIMAGE_INFO *pSrcInfo,
591 PALETTEENTRY *pPalette,
592 LPDIRECT3DTEXTURE9 *ppTexture)
594 HRSRC ResInfo;
595 TRACE("(void): relay\n");
597 if( !pDevice || !ppTexture ) return D3DERR_INVALIDCALL;
599 ResInfo = FindResourceW(hSrcModule, pResource, (LPCWSTR)RT_RCDATA);
600 if(ResInfo) {
601 LPVOID pBuffer;
602 HRESULT hr;
603 DWORD dwSize;
605 hr = load_resource_into_memory(hSrcModule, ResInfo, &pBuffer, &dwSize);
606 if(FAILED(hr)) return D3DXERR_INVALIDDATA;
607 return D3DXCreateTextureFromFileInMemoryEx(pDevice, pBuffer, dwSize, Width,
608 Height, MipLevels, dwUsage, Format,
609 Pool, dwFilter, dwMipFilter, ColorKey,
610 pSrcInfo, pPalette, ppTexture);
613 ResInfo = FindResourceW(hSrcModule, pResource, (LPCWSTR)RT_BITMAP);
614 if(ResInfo) {
615 FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
616 return E_NOTIMPL;
618 return D3DXERR_INVALIDDATA;