Commit 13801e63 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

d3dx10: Add support for loading MipLevels data in load_texture_data.

parent d1c03fe4
...@@ -1138,7 +1138,7 @@ static void check_resource_info(ID3D10Resource *resource, const struct test_imag ...@@ -1138,7 +1138,7 @@ static void check_resource_info(ID3D10Resource *resource, const struct test_imag
ok_(__FILE__, line)(desc_2d.Height == expected_height, ok_(__FILE__, line)(desc_2d.Height == expected_height,
"Got unexpected Height %u, expected %u.\n", "Got unexpected Height %u, expected %u.\n",
desc_2d.Height, expected_height); desc_2d.Height, expected_height);
todo_wine_if(expected_mip_levels != 1) todo_wine_if(expected_mip_levels != image->expected_info.MipLevels)
ok_(__FILE__, line)(desc_2d.MipLevels == expected_mip_levels, ok_(__FILE__, line)(desc_2d.MipLevels == expected_mip_levels,
"Got unexpected MipLevels %u, expected %u.\n", "Got unexpected MipLevels %u, expected %u.\n",
desc_2d.MipLevels, expected_mip_levels); desc_2d.MipLevels, expected_mip_levels);
......
...@@ -816,7 +816,7 @@ static HRESULT convert_image(IWICImagingFactory *factory, IWICBitmapFrameDecode ...@@ -816,7 +816,7 @@ static HRESULT convert_image(IWICImagingFactory *factory, IWICBitmapFrameDecode
HRESULT load_texture_data(const void *data, SIZE_T size, D3DX10_IMAGE_LOAD_INFO *load_info, HRESULT load_texture_data(const void *data, SIZE_T size, D3DX10_IMAGE_LOAD_INFO *load_info,
D3D10_SUBRESOURCE_DATA **resource_data) D3D10_SUBRESOURCE_DATA **resource_data)
{ {
unsigned int stride, frame_size, i; unsigned int stride, frame_size, i, j;
IWICDdsFrameDecode *dds_frame = NULL; IWICDdsFrameDecode *dds_frame = NULL;
IWICBitmapFrameDecode *frame = NULL; IWICBitmapFrameDecode *frame = NULL;
IWICImagingFactory *factory = NULL; IWICImagingFactory *factory = NULL;
...@@ -884,25 +884,29 @@ HRESULT load_texture_data(const void *data, SIZE_T size, D3DX10_IMAGE_LOAD_INFO ...@@ -884,25 +884,29 @@ HRESULT load_texture_data(const void *data, SIZE_T size, D3DX10_IMAGE_LOAD_INFO
for (i = 0; i < img_info.ArraySize; ++i) for (i = 0; i < img_info.ArraySize; ++i)
{ {
if (FAILED(hr = IWICDdsDecoder_GetFrame(dds_decoder, i, 0, 0, &frame))) for (j = 0; j < img_info.MipLevels; ++j)
goto end;
if (FAILED(hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICDdsFrameDecode, (void **)&dds_frame)))
goto end;
if (FAILED(hr = dds_get_frame_info(dds_frame, &img_info, &format_info, &stride, &frame_size)))
goto end;
if (!i)
{ {
img_info.Width = (img_info.Width + format_info.BlockWidth - 1) & ~(format_info.BlockWidth - 1); if (FAILED(hr = IWICDdsDecoder_GetFrame(dds_decoder, i, j, 0, &frame)))
img_info.Height = (img_info.Height + format_info.BlockHeight - 1) & ~(format_info.BlockHeight - 1); goto end;
} if (FAILED(hr = IWICBitmapFrameDecode_QueryInterface(frame,
&IID_IWICDdsFrameDecode, (void **)&dds_frame)))
goto end;
if (FAILED(hr = dds_get_frame_info(dds_frame, &img_info, &format_info, &stride, &frame_size)))
goto end;
size += sizeof(**resource_data) + frame_size; if (!i && !j)
{
img_info.Width = (img_info.Width + format_info.BlockWidth - 1) & ~(format_info.BlockWidth - 1);
img_info.Height = (img_info.Height + format_info.BlockHeight - 1) & ~(format_info.BlockHeight - 1);
}
IWICDdsFrameDecode_Release(dds_frame); size += sizeof(**resource_data) + frame_size;
dds_frame = NULL;
IWICBitmapFrameDecode_Release(frame); IWICDdsFrameDecode_Release(dds_frame);
frame = NULL; dds_frame = NULL;
IWICBitmapFrameDecode_Release(frame);
frame = NULL;
}
} }
if (!(res_data = malloc(size))) if (!(res_data = malloc(size)))
...@@ -915,41 +919,45 @@ HRESULT load_texture_data(const void *data, SIZE_T size, D3DX10_IMAGE_LOAD_INFO ...@@ -915,41 +919,45 @@ HRESULT load_texture_data(const void *data, SIZE_T size, D3DX10_IMAGE_LOAD_INFO
size = 0; size = 0;
for (i = 0; i < img_info.ArraySize; ++i) for (i = 0; i < img_info.ArraySize; ++i)
{ {
if (FAILED(hr = IWICDdsDecoder_GetFrame(dds_decoder, i, 0, 0, &frame))) for (j = 0; j < img_info.MipLevels; ++j)
goto end;
if (FAILED(hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICDdsFrameDecode, (void **)&dds_frame)))
goto end;
if (FAILED(hr = dds_get_frame_info(dds_frame, &img_info, &format_info, &stride, &frame_size)))
goto end;
buffer = res_data + sizeof(**resource_data) * img_info.ArraySize + size;
size += frame_size;
if (img_info.Format == format_info.DxgiFormat)
{ {
if (FAILED(hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, stride, frame_size, buffer))) if (FAILED(hr = IWICDdsDecoder_GetFrame(dds_decoder, i, j, 0, &frame)))
goto end; goto end;
} if (FAILED(hr = IWICBitmapFrameDecode_QueryInterface(frame,
else &IID_IWICDdsFrameDecode, (void **)&dds_frame)))
{
if (!(dst_format = dxgi_format_to_wic_guid(img_info.Format)))
{
hr = E_FAIL;
FIXME("Unsupported DXGI format %#x.\n", img_info.Format);
goto end; goto end;
} if (FAILED(hr = dds_get_frame_info(dds_frame, &img_info, &format_info, &stride, &frame_size)))
if (FAILED(hr = convert_image(factory, frame, dst_format, stride, frame_size, buffer)))
goto end; goto end;
}
IWICDdsFrameDecode_Release(dds_frame); buffer = res_data + sizeof(**resource_data) * img_info.ArraySize * img_info.MipLevels + size;
dds_frame = NULL; size += frame_size;
IWICBitmapFrameDecode_Release(frame);
frame = NULL;
(*resource_data)[i].pSysMem = buffer; if (img_info.Format == format_info.DxgiFormat)
(*resource_data)[i].SysMemPitch = stride; {
(*resource_data)[i].SysMemSlicePitch = frame_size; if (FAILED(hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, stride, frame_size, buffer)))
goto end;
}
else
{
if (!(dst_format = dxgi_format_to_wic_guid(img_info.Format)))
{
hr = E_FAIL;
FIXME("Unsupported DXGI format %#x.\n", img_info.Format);
goto end;
}
if (FAILED(hr = convert_image(factory, frame, dst_format, stride, frame_size, buffer)))
goto end;
}
IWICDdsFrameDecode_Release(dds_frame);
dds_frame = NULL;
IWICBitmapFrameDecode_Release(frame);
frame = NULL;
(*resource_data)[i * img_info.MipLevels + j].pSysMem = buffer;
(*resource_data)[i * img_info.MipLevels + j].SysMemPitch = stride;
(*resource_data)[i * img_info.MipLevels + j].SysMemSlicePitch = frame_size;
}
} }
} }
else else
...@@ -984,7 +992,7 @@ HRESULT load_texture_data(const void *data, SIZE_T size, D3DX10_IMAGE_LOAD_INFO ...@@ -984,7 +992,7 @@ HRESULT load_texture_data(const void *data, SIZE_T size, D3DX10_IMAGE_LOAD_INFO
load_info->Width = img_info.Width; load_info->Width = img_info.Width;
load_info->Height = img_info.Height; load_info->Height = img_info.Height;
load_info->MipLevels = 1; load_info->MipLevels = img_info.MipLevels;
load_info->Format = img_info.Format; load_info->Format = img_info.Format;
load_info->Usage = D3D10_USAGE_DEFAULT; load_info->Usage = D3D10_USAGE_DEFAULT;
load_info->BindFlags = D3D10_BIND_SHADER_RESOURCE; load_info->BindFlags = D3D10_BIND_SHADER_RESOURCE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment