https://git.reactos.org/?p=reactos.git;a=commitdiff;h=de19dd3e3877ba3103cab…
commit de19dd3e3877ba3103cabaace6b7a3a10fc7f82b
Author: winesync <ros-dev(a)reactos.org>
AuthorDate: Wed Feb 5 22:11:39 2020 +0100
Commit: Jérôme Gardou <zefklop(a)users.noreply.github.com>
CommitDate: Wed Feb 26 18:19:18 2020 +0100
[WINESYNC] d3dx9_36: Improve D3DXSaveTextureToFile to save simple texture to dds
file.
wine-staging patch by Christian Costa <titan.costa(a)gmail.com>
---
dll/directx/wine/d3dx9_36/d3dx9_private.h | 2 +
dll/directx/wine/d3dx9_36/surface.c | 62 +++++++++++++
dll/directx/wine/d3dx9_36/texture.c | 5 +-
...eToFile_to_save_simple_texture_to_dds_file.diff | 102 +++++++++++++++++++++
4 files changed, 167 insertions(+), 4 deletions(-)
diff --git a/dll/directx/wine/d3dx9_36/d3dx9_private.h
b/dll/directx/wine/d3dx9_36/d3dx9_private.h
index 1c1613024dc..5fc7f506760 100644
--- a/dll/directx/wine/d3dx9_36/d3dx9_private.h
+++ b/dll/directx/wine/d3dx9_36/d3dx9_private.h
@@ -125,6 +125,8 @@ HRESULT lock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT
*lock,
IDirect3DSurface9 **temp_surface, BOOL write) DECLSPEC_HIDDEN;
HRESULT unlock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock,
IDirect3DSurface9 *temp_surface, BOOL update) DECLSPEC_HIDDEN;
+HRESULT save_dds_texture_to_memory(ID3DXBuffer **dst_buffer, IDirect3DBaseTexture9
*src_texture,
+ const PALETTEENTRY *src_palette) DECLSPEC_HIDDEN;
unsigned short float_32_to_16(const float in) DECLSPEC_HIDDEN;
float float_16_to_32(const unsigned short in) DECLSPEC_HIDDEN;
diff --git a/dll/directx/wine/d3dx9_36/surface.c b/dll/directx/wine/d3dx9_36/surface.c
index 185d4f44c0d..d236feb0b83 100644
--- a/dll/directx/wine/d3dx9_36/surface.c
+++ b/dll/directx/wine/d3dx9_36/surface.c
@@ -612,6 +612,68 @@ static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer,
IDirect3DSur
return D3D_OK;
}
+static HRESULT get_surface(D3DRESOURCETYPE type, struct IDirect3DBaseTexture9 *tex,
+ int face, UINT level, struct IDirect3DSurface9 **surf)
+{
+ switch (type)
+ {
+ case D3DRTYPE_TEXTURE:
+ return IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) tex, level,
surf);
+ case D3DRTYPE_CUBETEXTURE:
+ return IDirect3DCubeTexture9_GetCubeMapSurface((IDirect3DCubeTexture9*) tex,
face, level, surf);
+ default:
+ ERR("Unexpected texture type\n");
+ return E_NOTIMPL;
+ }
+}
+
+HRESULT save_dds_texture_to_memory(ID3DXBuffer **dst_buffer, IDirect3DBaseTexture9
*src_texture, const PALETTEENTRY *src_palette)
+{
+ HRESULT hr;
+ D3DRESOURCETYPE type;
+ UINT mip_levels;
+ IDirect3DSurface9 *surface;
+
+ type = IDirect3DBaseTexture9_GetType(src_texture);
+
+ if ((type != D3DRTYPE_TEXTURE) && (type != D3DRTYPE_CUBETEXTURE) &&
(type != D3DRTYPE_VOLUMETEXTURE))
+ return D3DERR_INVALIDCALL;
+
+ if (type == D3DRTYPE_CUBETEXTURE)
+ {
+ FIXME("Cube texture not supported yet\n");
+ return E_NOTIMPL;
+ }
+ else if (type == D3DRTYPE_VOLUMETEXTURE)
+ {
+ FIXME("Volume texture not supported yet\n");
+ return E_NOTIMPL;
+ }
+
+ mip_levels = IDirect3DTexture9_GetLevelCount(src_texture);
+
+ if (mip_levels > 1)
+ {
+ FIXME("Mipmap not supported yet\n");
+ return E_NOTIMPL;
+ }
+
+ if (src_palette)
+ {
+ FIXME("Saving surfaces with palettized pixel formats not implemented
yet\n");
+ return E_NOTIMPL;
+ }
+
+ hr = get_surface(type, src_texture, D3DCUBEMAP_FACE_POSITIVE_X, 0, &surface);
+
+ if (SUCCEEDED(hr))
+ {
+ hr = save_dds_surface_to_memory(dst_buffer, surface, NULL);
+ IDirect3DSurface9_Release(surface);
+ }
+
+ return hr;
+}
HRESULT load_volume_from_dds(IDirect3DVolume9 *dst_volume, const PALETTEENTRY
*dst_palette,
const D3DBOX *dst_box, const void *src_data, const D3DBOX *src_box, DWORD filter,
D3DCOLOR color_key,
const D3DXIMAGE_INFO *src_info)
diff --git a/dll/directx/wine/d3dx9_36/texture.c b/dll/directx/wine/d3dx9_36/texture.c
index e2dfab84205..9f0e541cb61 100644
--- a/dll/directx/wine/d3dx9_36/texture.c
+++ b/dll/directx/wine/d3dx9_36/texture.c
@@ -1906,10 +1906,7 @@ HRESULT WINAPI D3DXSaveTextureToFileInMemory(ID3DXBuffer
**dst_buffer, D3DXIMAGE
if (!dst_buffer || !src_texture) return D3DERR_INVALIDCALL;
if (file_format == D3DXIFF_DDS)
- {
- FIXME("DDS file format isn't supported yet\n");
- return E_NOTIMPL;
- }
+ return save_dds_texture_to_memory(dst_buffer, src_texture, src_palette);
type = IDirect3DBaseTexture9_GetType(src_texture);
switch (type)
diff --git
a/sdk/tools/winesync/d3dx9_staging/0013-d3dx9_36__Improve_D3DXSaveTextureToFile_to_save_simple_texture_to_dds_file.diff
b/sdk/tools/winesync/d3dx9_staging/0013-d3dx9_36__Improve_D3DXSaveTextureToFile_to_save_simple_texture_to_dds_file.diff
new file mode 100644
index 00000000000..f8a3bc77f8c
--- /dev/null
+++
b/sdk/tools/winesync/d3dx9_staging/0013-d3dx9_36__Improve_D3DXSaveTextureToFile_to_save_simple_texture_to_dds_file.diff
@@ -0,0 +1,102 @@
+diff --git a/dll/directx/wine/d3dx9_36/d3dx9_private.h
b/dll/directx/wine/d3dx9_36/d3dx9_private.h
+index 5a28f2e..158aae3 100644
+--- a/dll/directx/wine/d3dx9_36/d3dx9_private.h
++++ b/dll/directx/wine/d3dx9_36/d3dx9_private.h
+@@ -125,6 +125,8 @@ HRESULT lock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT
*lock,
+ IDirect3DSurface9 **temp_surface, BOOL write) DECLSPEC_HIDDEN;
+ HRESULT unlock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock,
+ IDirect3DSurface9 *temp_surface, BOOL update) DECLSPEC_HIDDEN;
++HRESULT save_dds_texture_to_memory(ID3DXBuffer **dst_buffer, IDirect3DBaseTexture9
*src_texture,
++ const PALETTEENTRY *src_palette) DECLSPEC_HIDDEN;
+
+ unsigned short float_32_to_16(const float in) DECLSPEC_HIDDEN;
+ float float_16_to_32(const unsigned short in) DECLSPEC_HIDDEN;
+diff --git a/dll/directx/wine/d3dx9_36/surface.c b/dll/directx/wine/d3dx9_36/surface.c
+index 185d4f4..d236feb 100644
+--- a/dll/directx/wine/d3dx9_36/surface.c
++++ b/dll/directx/wine/d3dx9_36/surface.c
+@@ -612,6 +612,68 @@ static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer,
IDirect3DSur
+ return D3D_OK;
+ }
+
++static HRESULT get_surface(D3DRESOURCETYPE type, struct IDirect3DBaseTexture9 *tex,
++ int face, UINT level, struct IDirect3DSurface9 **surf)
++{
++ switch (type)
++ {
++ case D3DRTYPE_TEXTURE:
++ return IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) tex, level,
surf);
++ case D3DRTYPE_CUBETEXTURE:
++ return IDirect3DCubeTexture9_GetCubeMapSurface((IDirect3DCubeTexture9*) tex,
face, level, surf);
++ default:
++ ERR("Unexpected texture type\n");
++ return E_NOTIMPL;
++ }
++}
++
++HRESULT save_dds_texture_to_memory(ID3DXBuffer **dst_buffer, IDirect3DBaseTexture9
*src_texture, const PALETTEENTRY *src_palette)
++{
++ HRESULT hr;
++ D3DRESOURCETYPE type;
++ UINT mip_levels;
++ IDirect3DSurface9 *surface;
++
++ type = IDirect3DBaseTexture9_GetType(src_texture);
++
++ if ((type != D3DRTYPE_TEXTURE) && (type != D3DRTYPE_CUBETEXTURE) &&
(type != D3DRTYPE_VOLUMETEXTURE))
++ return D3DERR_INVALIDCALL;
++
++ if (type == D3DRTYPE_CUBETEXTURE)
++ {
++ FIXME("Cube texture not supported yet\n");
++ return E_NOTIMPL;
++ }
++ else if (type == D3DRTYPE_VOLUMETEXTURE)
++ {
++ FIXME("Volume texture not supported yet\n");
++ return E_NOTIMPL;
++ }
++
++ mip_levels = IDirect3DTexture9_GetLevelCount(src_texture);
++
++ if (mip_levels > 1)
++ {
++ FIXME("Mipmap not supported yet\n");
++ return E_NOTIMPL;
++ }
++
++ if (src_palette)
++ {
++ FIXME("Saving surfaces with palettized pixel formats not implemented
yet\n");
++ return E_NOTIMPL;
++ }
++
++ hr = get_surface(type, src_texture, D3DCUBEMAP_FACE_POSITIVE_X, 0, &surface);
++
++ if (SUCCEEDED(hr))
++ {
++ hr = save_dds_surface_to_memory(dst_buffer, surface, NULL);
++ IDirect3DSurface9_Release(surface);
++ }
++
++ return hr;
++}
+ HRESULT load_volume_from_dds(IDirect3DVolume9 *dst_volume, const PALETTEENTRY
*dst_palette,
+ const D3DBOX *dst_box, const void *src_data, const D3DBOX *src_box, DWORD filter,
D3DCOLOR color_key,
+ const D3DXIMAGE_INFO *src_info)
+diff --git a/dll/directx/wine/d3dx9_36/texture.c b/dll/directx/wine/d3dx9_36/texture.c
+index e2dfab8..9f0e541 100644
+--- a/dll/directx/wine/d3dx9_36/texture.c
++++ b/dll/directx/wine/d3dx9_36/texture.c
+@@ -1906,10 +1906,7 @@ HRESULT WINAPI D3DXSaveTextureToFileInMemory(ID3DXBuffer
**dst_buffer, D3DXIMAGE
+ if (!dst_buffer || !src_texture) return D3DERR_INVALIDCALL;
+
+ if (file_format == D3DXIFF_DDS)
+- {
+- FIXME("DDS file format isn't supported yet\n");
+- return E_NOTIMPL;
+- }
++ return save_dds_texture_to_memory(dst_buffer, src_texture, src_palette);
+
+ type = IDirect3DBaseTexture9_GetType(src_texture);
+ switch (type)