From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/texture.c | 36 +++++------- dlls/d3dx9_36/texture.c | 105 +++++++++++++++++++++++++--------- 2 files changed, 90 insertions(+), 51 deletions(-)
diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index 622d4ebc2e7..99f0038251b 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -3162,7 +3162,6 @@ static void test_save_texture_to_dds_file(IDirect3DDevice9 *device) uint32_t expected_caps; uint32_t expected_caps2; uint32_t expected_buffer_size; - BOOL todo_hr; } tests[] = { /* Paletted format tests. */ @@ -3186,7 +3185,6 @@ static void test_save_texture_to_dds_file(IDirect3DDevice9 *device) (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_MIPMAPCOUNT | DDSD_DEPTH), 4, 4, 0, 4, 3, (DDSCAPS_TEXTURE | DDSCAPS_PALETTE | DDSCAPS_MIPMAP | DDSCAPS_COMPLEX), DDSCAPS2_VOLUME, PALETTED_DDS_FILE_HEADER_SIZE + 73, - .todo_hr = TRUE }, /* D3DFMT_A8R8G8B8 textures with multiple levels. */ { @@ -3210,7 +3208,6 @@ static void test_save_texture_to_dds_file(IDirect3DDevice9 *device) */ { D3DRTYPE_VOLUMETEXTURE, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, 4, 4, 4, 3, NULL, D3DERR_INVALIDCALL, - .todo_hr = TRUE }, /* D3DPOOL_SYSTEMMEM can be saved. */ { @@ -3219,7 +3216,6 @@ static void test_save_texture_to_dds_file(IDirect3DDevice9 *device) (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_DEPTH | DDSD_MIPMAPCOUNT), 4, 4, 0, 4, 3, (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP | DDSCAPS_ALPHA | DDSCAPS_COMPLEX), DDSCAPS2_VOLUME, DDS_FILE_HEADER_SIZE + 292, - .todo_hr = TRUE }, /* Single mip level, no mip flags. */ { @@ -3242,7 +3238,6 @@ static void test_save_texture_to_dds_file(IDirect3DDevice9 *device) (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_DEPTH), 4, 4, 0, 4, 0, (DDSCAPS_TEXTURE | DDSCAPS_ALPHA), DDSCAPS2_VOLUME, DDS_FILE_HEADER_SIZE + 256, - .todo_hr = TRUE }, /* 10. */ /* Volume texture with a depth of 1. */ @@ -3252,7 +3247,6 @@ static void test_save_texture_to_dds_file(IDirect3DDevice9 *device) (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT), 4, 4, 0, 0, 0, (DDSCAPS_TEXTURE | DDSCAPS_ALPHA), 0, DDS_FILE_HEADER_SIZE + 64, - .todo_hr = TRUE }, }; struct @@ -3302,7 +3296,7 @@ static void test_save_texture_to_dds_file(IDirect3DDevice9 *device) }
hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, save_tex, tests[i].palette); - todo_wine_if(tests[i].todo_hr) ok(hr == tests[i].expected_hr, "Unexpected hr %#lx.\n", hr); + ok(hr == tests[i].expected_hr, "Unexpected hr %#lx.\n", hr); if (SUCCEEDED(hr)) { ok(ID3DXBuffer_GetBufferSize(buffer) == tests[i].expected_buffer_size, "Unexpected buffer size %lu.\n", @@ -3473,25 +3467,21 @@ static void test_D3DXSaveTextureToFileInMemory(IDirect3DDevice9 *device) ID3DXBuffer_Release(buffer); }
- todo_wine { hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)volume_texture, NULL); ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK); - if (SUCCEEDED(hr)) - { - buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer); - buffer_size = ID3DXBuffer_GetBufferSize(buffer); - hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info); - ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
- ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256); - ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256); - ok(info.Depth == 256, "Got depth %u, expected %u\n", info.Depth, 256); - ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9); - ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE); - ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS); - ID3DXBuffer_Release(buffer); - } - } + buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer); + buffer_size = ID3DXBuffer_GetBufferSize(buffer); + hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info); + ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK); + + ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256); + ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256); + ok(info.Depth == 256, "Got depth %u, expected %u\n", info.Depth, 256); + ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9); + ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE); + ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS); + ID3DXBuffer_Release(buffer);
IDirect3DVolumeTexture9_Release(volume_texture);
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 25f8ef6c6b4..9464cae6fa2 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1940,9 +1940,26 @@ HRESULT WINAPI D3DXSaveTextureToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE break; }
+ case D3DRTYPE_VOLUMETEXTURE: + { + IDirect3DVolumeTexture9 *texture = (IDirect3DVolumeTexture9 *)src_texture; + D3DVOLUME_DESC desc; + + hr = IDirect3DVolumeTexture9_GetLevelDesc(texture, 0, &desc); + if (FAILED(hr)) + break; + + fmt_desc = get_format_info(desc.Format); + if (is_unknown_format(fmt_desc)) + return E_NOTIMPL; + + set_volume_struct(&size, desc.Width, desc.Height, desc.Depth); + break; + }
default: - return E_NOTIMPL; + assert(0); /* Should not happen. */ + return E_FAIL; }
if (is_index_format(fmt_desc) && !src_palette) @@ -1970,51 +1987,83 @@ HRESULT WINAPI D3DXSaveTextureToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE if (FAILED(hr)) goto exit;
- for (j = 0; j < image.layer_count; ++j) + if (type != D3DRTYPE_VOLUMETEXTURE) { + for (j = 0; j < image.layer_count; ++j) + { + for (i = 0; i < levels; ++i) + { + IDirect3DSurface9 *src_surface, *tmp_surface; + struct d3dx_pixels src_pixels, dst_pixels; + D3DSURFACE_DESC src_surface_desc; + D3DLOCKED_RECT src_locked_rect; + RECT src_rect; + + hr = d3dx_image_get_pixels(&image, j, i, &dst_pixels); + if (FAILED(hr)) + goto exit; + + hr = get_surface(type, src_texture, j, i, &src_surface); + if (FAILED(hr)) + goto exit; + + hr = lock_surface(src_surface, NULL, &src_locked_rect, &tmp_surface, FALSE); + if (FAILED(hr)) + { + IDirect3DSurface9_Release(src_surface); + goto exit; + } + + IDirect3DSurface9_GetDesc(src_surface, &src_surface_desc); + SetRect(&src_rect, 0, 0, src_surface_desc.Width, src_surface_desc.Height); + set_d3dx_pixels(&src_pixels, src_locked_rect.pBits, src_locked_rect.Pitch, 0, src_palette, + src_surface_desc.Width, src_surface_desc.Height, 1, &src_rect); + + hr = d3dx_load_pixels_from_pixels(&dst_pixels, fmt_desc, &src_pixels, fmt_desc, D3DX_FILTER_NONE, 0); + if (FAILED(hr)) + { + unlock_surface(src_surface, NULL, tmp_surface, FALSE); + IDirect3DSurface9_Release(src_surface); + goto exit; + } + + hr = unlock_surface(src_surface, NULL, tmp_surface, FALSE); + IDirect3DSurface9_Release(src_surface); + if (FAILED(hr)) + goto exit; + } + } + } + else + { + IDirect3DVolumeTexture9 *volume_tex = (IDirect3DVolumeTexture9 *)src_texture; + for (i = 0; i < levels; ++i) { - IDirect3DSurface9 *src_surface, *tmp_surface; struct d3dx_pixels src_pixels, dst_pixels; - D3DSURFACE_DESC src_surface_desc; - D3DLOCKED_RECT src_locked_rect; + D3DVOLUME_DESC src_volume_desc; + D3DLOCKED_BOX src_locked_box; RECT src_rect;
- hr = d3dx_image_get_pixels(&image, j, i, &dst_pixels); + hr = d3dx_image_get_pixels(&image, 0, i, &dst_pixels); if (FAILED(hr)) goto exit;
- hr = get_surface(type, src_texture, j, i, &src_surface); + hr = IDirect3DVolumeTexture9_LockBox(volume_tex, i, &src_locked_box, NULL, D3DLOCK_READONLY); if (FAILED(hr)) goto exit;
- hr = lock_surface(src_surface, NULL, &src_locked_rect, &tmp_surface, FALSE); - if (FAILED(hr)) - { - IDirect3DSurface9_Release(src_surface); - goto exit; - } - - IDirect3DSurface9_GetDesc(src_surface, &src_surface_desc); - SetRect(&src_rect, 0, 0, src_surface_desc.Width, src_surface_desc.Height); - set_d3dx_pixels(&src_pixels, src_locked_rect.pBits, src_locked_rect.Pitch, 0, src_palette, - src_surface_desc.Width, src_surface_desc.Height, 1, &src_rect); + IDirect3DVolumeTexture9_GetLevelDesc(volume_tex, i, &src_volume_desc); + SetRect(&src_rect, 0, 0, src_volume_desc.Width, src_volume_desc.Height); + set_d3dx_pixels(&src_pixels, src_locked_box.pBits, src_locked_box.RowPitch, src_locked_box.SlicePitch, + src_palette, src_volume_desc.Width, src_volume_desc.Height, src_volume_desc.Depth, &src_rect);
hr = d3dx_load_pixels_from_pixels(&dst_pixels, fmt_desc, &src_pixels, fmt_desc, D3DX_FILTER_NONE, 0); - if (FAILED(hr)) - { - unlock_surface(src_surface, NULL, tmp_surface, FALSE); - IDirect3DSurface9_Release(src_surface); - goto exit; - } - - hr = unlock_surface(src_surface, NULL, tmp_surface, FALSE); - IDirect3DSurface9_Release(src_surface); + IDirect3DVolumeTexture9_UnlockBox(volume_tex, i); if (FAILED(hr)) goto exit; } } - *dst_buffer = buffer;
exit: