From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/surface.c | 6 +++ dlls/d3dx9_36/tests/texture.c | 32 ++++++------- dlls/d3dx9_36/texture.c | 89 ++++++++++++++++++++++------------- 3 files changed, 76 insertions(+), 51 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index 3af573fb0e9..e3bc77bd52e 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -448,6 +448,12 @@ HRESULT d3dx_init_dds_header(struct dds_header *header, D3DRESOURCETYPE resource header->miplevels = mip_levels; }
+ if (resource_type == D3DRTYPE_CUBETEXTURE) + { + header->caps |= DDS_CAPS_COMPLEX; + header->caps2 |= (DDS_CAPS2_CUBEMAP | DDS_CAPS2_CUBEMAP_ALL_FACES); + } + if (header->pixel_format.flags & DDS_PF_ALPHA || header->pixel_format.flags & DDS_PF_ALPHA_ONLY) header->caps |= DDSCAPS_ALPHA; if (header->pixel_format.flags & DDS_PF_INDEXED) diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index 0a0843074d3..71ff20648b3 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -3177,7 +3177,7 @@ static void test_save_texture_to_dds_file(IDirect3DDevice9 *device) (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_MIPMAPCOUNT), 4, 4, 0, 0, 3, (DDSCAPS_TEXTURE | DDSCAPS_PALETTE | DDSCAPS_MIPMAP | DDSCAPS_COMPLEX), (DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES), - PALETTED_DDS_FILE_HEADER_SIZE + (126), .todo_hr = TRUE + PALETTED_DDS_FILE_HEADER_SIZE + (126) }, { D3DRTYPE_VOLUMETEXTURE, D3DFMT_P8, D3DPOOL_SCRATCH, 4, 4, 4, 3, test_palette, D3D_OK, { 32, DDS_PF_INDEXED, 0, 8, 0, 0, 0, 0 }, @@ -3196,7 +3196,7 @@ static void test_save_texture_to_dds_file(IDirect3DDevice9 *device) (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_MIPMAPCOUNT), 4, 4, 0, 0, 3, (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP | DDSCAPS_ALPHA | DDSCAPS_COMPLEX), (DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES), - DDS_FILE_HEADER_SIZE + (504), .todo_hr = TRUE + DDS_FILE_HEADER_SIZE + (504) }, /* 5 */ /* @@ -3224,7 +3224,7 @@ static void test_save_texture_to_dds_file(IDirect3DDevice9 *device) { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT), 4, 4, 0, 0, 0, (DDSCAPS_TEXTURE | DDSCAPS_ALPHA | DDSCAPS_COMPLEX), (DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES), - DDS_FILE_HEADER_SIZE + (384), .todo_hr = TRUE + DDS_FILE_HEADER_SIZE + (384) }, { D3DRTYPE_VOLUMETEXTURE, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, 4, 4, 4, 1, NULL, D3D_OK, { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, @@ -3416,24 +3416,20 @@ static void test_D3DXSaveTextureToFileInMemory(IDirect3DDevice9 *device) ID3DXBuffer_Release(buffer); }
- todo_wine { hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)cube_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.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9); - ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE); - 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.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9); + ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE); + ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS); + ID3DXBuffer_Release(buffer);
IDirect3DCubeTexture9_Release(cube_texture);
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 55419fbf1ba..b55c9c696c9 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1857,7 +1857,7 @@ HRESULT WINAPI D3DXSaveTextureToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE IDirect3DBaseTexture9 *src_texture, const PALETTEENTRY *src_palette) { const struct pixel_format_desc *fmt_desc = NULL; - unsigned int levels, file_size, i; + unsigned int levels, file_size, i, j; struct d3dx_image image = { 0 }; D3DRESOURCETYPE type; ID3DXBuffer *buffer; @@ -1923,6 +1923,24 @@ HRESULT WINAPI D3DXSaveTextureToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE break; }
+ case D3DRTYPE_CUBETEXTURE: + { + IDirect3DCubeTexture9 *texture = (IDirect3DCubeTexture9 *)src_texture; + D3DSURFACE_DESC desc; + + hr = IDirect3DCubeTexture9_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, 1); + break; + } + + default: return E_NOTIMPL; } @@ -1931,6 +1949,8 @@ HRESULT WINAPI D3DXSaveTextureToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE return E_NOTIMPL;
file_size = d3dx_calculate_layer_pixels_size(fmt_desc->format, size.width, size.height, size.depth, levels); + if (type == D3DRTYPE_CUBETEXTURE) + file_size *= 6; file_size += is_index_format(fmt_desc) ? sizeof(struct dds_header) + DDS_PALETTE_SIZE : sizeof(struct dds_header);
hr = D3DXCreateBuffer(file_size, &buffer); @@ -1950,46 +1970,49 @@ HRESULT WINAPI D3DXSaveTextureToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE if (FAILED(hr)) goto exit;
- for (i = 0; i < levels; ++i) + for (j = 0; j < image.layer_count; ++j) { - 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; + 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, 0, i, &dst_pixels); - if (FAILED(hr)) - goto exit; + hr = d3dx_image_get_pixels(&image, j, i, &dst_pixels); + if (FAILED(hr)) + goto exit;
- hr = get_surface(type, src_texture, 0, i, &src_surface); - 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; - } + hr = lock_surface(src_surface, NULL, &src_locked_rect, &tmp_surface, FALSE); + if (FAILED(hr)) + { + IDirect3DSurface9_Release(src_surface); + goto exit; + }
- IDirect3DTexture9_GetLevelDesc((IDirect3DTexture9 *)src_texture, i, &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); + IDirect3DTexture9_GetLevelDesc((IDirect3DTexture9 *)src_texture, i, &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); + 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); - goto exit; + if (FAILED(hr)) + goto exit; } - - hr = unlock_surface(src_surface, NULL, tmp_surface, FALSE); - IDirect3DSurface9_Release(src_surface); - if (FAILED(hr)) - goto exit; }
*dst_buffer = buffer;