Alexandre Julliard pushed to branch master at wine / wine
Commits:
-
2b042ca3
by Connor McAdams at 2024-07-24T20:15:44+02:00
-
093b2c96
by Connor McAdams at 2024-07-24T20:15:44+02:00
-
d714f1b2
by Connor McAdams at 2024-07-24T20:15:44+02:00
-
ecb2f3ce
by Connor McAdams at 2024-07-24T20:15:44+02:00
-
15e9113c
by Connor McAdams at 2024-07-24T20:15:44+02:00
-
416f11ea
by Connor McAdams at 2024-07-24T20:15:44+02:00
-
f023fd35
by Connor McAdams at 2024-07-24T20:15:44+02:00
-
0c1c8c29
by Connor McAdams at 2024-07-24T20:15:44+02:00
7 changed files:
- dlls/d3dx9_36/d3dx9_private.h
- dlls/d3dx9_36/surface.c
- dlls/d3dx9_36/tests/d3dx9_test_images.h
- dlls/d3dx9_36/tests/surface.c
- dlls/d3dx9_36/tests/texture.c
- dlls/d3dx9_36/texture.c
- dlls/d3dx9_36/volume.c
Changes:
| ... | ... | @@ -106,8 +106,10 @@ struct d3dx_image |
| 106 | 106 | |
| 107 | 107 | struct volume size;
|
| 108 | 108 | uint32_t mip_levels;
|
| 109 | + uint32_t layer_count;
|
|
| 109 | 110 | |
| 110 | 111 | BYTE *pixels;
|
| 112 | + uint32_t layer_pitch;
|
|
| 111 | 113 | |
| 112 | 114 | /*
|
| 113 | 115 | * image_buf and palette are pointers to allocated memory used to store
|
| ... | ... | @@ -123,7 +125,8 @@ struct d3dx_image |
| 123 | 125 | HRESULT d3dx_image_init(const void *src_data, uint32_t src_data_size, struct d3dx_image *image,
|
| 124 | 126 | uint32_t starting_mip_level, uint32_t flags);
|
| 125 | 127 | void d3dx_image_cleanup(struct d3dx_image *image);
|
| 126 | -HRESULT d3dx_image_get_pixels(struct d3dx_image *image, uint32_t mip_level, struct d3dx_pixels *pixels);
|
|
| 128 | +HRESULT d3dx_image_get_pixels(struct d3dx_image *image, uint32_t layer, uint32_t mip_level,
|
|
| 129 | + struct d3dx_pixels *pixels);
|
|
| 127 | 130 | void d3dximage_info_from_d3dx_image(D3DXIMAGE_INFO *info, struct d3dx_image *image);
|
| 128 | 131 | |
| 129 | 132 | struct d3dx_include_from_file
|
| ... | ... | @@ -172,8 +175,6 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic |
| 172 | 175 | BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size,
|
| 173 | 176 | const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette);
|
| 174 | 177 | |
| 175 | -HRESULT load_cube_texture_from_dds(IDirect3DCubeTexture9 *cube_texture, const void *src_data,
|
|
| 176 | - const PALETTEENTRY *palette, DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info);
|
|
| 177 | 178 | HRESULT lock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, D3DLOCKED_RECT *lock,
|
| 178 | 179 | IDirect3DSurface9 **temp_surface, BOOL write);
|
| 179 | 180 | HRESULT unlock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect,
|
| ... | ... | @@ -475,6 +475,23 @@ static HRESULT d3dx_calculate_pixels_size(D3DFORMAT format, uint32_t width, uint |
| 475 | 475 | return D3D_OK;
|
| 476 | 476 | }
|
| 477 | 477 | |
| 478 | +static uint32_t d3dx_calculate_layer_pixels_size(D3DFORMAT format, uint32_t width, uint32_t height, uint32_t depth,
|
|
| 479 | + uint32_t mip_levels)
|
|
| 480 | +{
|
|
| 481 | + uint32_t layer_size, row_pitch, slice_pitch, i;
|
|
| 482 | + struct volume dims = { width, height, depth };
|
|
| 483 | + |
|
| 484 | + layer_size = 0;
|
|
| 485 | + for (i = 0; i < mip_levels; ++i)
|
|
| 486 | + {
|
|
| 487 | + d3dx_calculate_pixels_size(format, dims.width, dims.height, &row_pitch, &slice_pitch);
|
|
| 488 | + layer_size += slice_pitch * dims.depth;
|
|
| 489 | + d3dx_get_next_mip_level_size(&dims);
|
|
| 490 | + }
|
|
| 491 | + |
|
| 492 | + return layer_size;
|
|
| 493 | +}
|
|
| 494 | + |
|
| 478 | 495 | static UINT calculate_dds_file_size(D3DFORMAT format, UINT width, UINT height, UINT depth,
|
| 479 | 496 | UINT miplevels, UINT faces)
|
| 480 | 497 | {
|
| ... | ... | @@ -566,65 +583,11 @@ static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer, IDirect3DSur |
| 566 | 583 | return D3D_OK;
|
| 567 | 584 | }
|
| 568 | 585 | |
| 569 | -HRESULT load_cube_texture_from_dds(IDirect3DCubeTexture9 *cube_texture, const void *src_data,
|
|
| 570 | - const PALETTEENTRY *palette, DWORD filter, DWORD color_key, const D3DXIMAGE_INFO *src_info)
|
|
| 571 | -{
|
|
| 572 | - HRESULT hr;
|
|
| 573 | - int face;
|
|
| 574 | - UINT mip_level;
|
|
| 575 | - UINT size;
|
|
| 576 | - RECT src_rect;
|
|
| 577 | - UINT src_pitch;
|
|
| 578 | - UINT mip_levels;
|
|
| 579 | - UINT mip_level_size;
|
|
| 580 | - IDirect3DSurface9 *surface;
|
|
| 581 | - const struct dds_header *header = src_data;
|
|
| 582 | - const BYTE *pixels = (BYTE *)(header + 1);
|
|
| 583 | - |
|
| 584 | - if (src_info->ResourceType != D3DRTYPE_CUBETEXTURE)
|
|
| 585 | - return D3DXERR_INVALIDDATA;
|
|
| 586 | - |
|
| 587 | - if ((header->caps2 & DDS_CAPS2_CUBEMAP_ALL_FACES) != DDS_CAPS2_CUBEMAP_ALL_FACES)
|
|
| 588 | - {
|
|
| 589 | - WARN("Only full cubemaps are supported\n");
|
|
| 590 | - return D3DXERR_INVALIDDATA;
|
|
| 591 | - }
|
|
| 592 | - |
|
| 593 | - mip_levels = min(src_info->MipLevels, IDirect3DCubeTexture9_GetLevelCount(cube_texture));
|
|
| 594 | - for (face = D3DCUBEMAP_FACE_POSITIVE_X; face <= D3DCUBEMAP_FACE_NEGATIVE_Z; face++)
|
|
| 595 | - {
|
|
| 596 | - size = src_info->Width;
|
|
| 597 | - for (mip_level = 0; mip_level < src_info->MipLevels; mip_level++)
|
|
| 598 | - {
|
|
| 599 | - hr = d3dx_calculate_pixels_size(src_info->Format, size, size, &src_pitch, &mip_level_size);
|
|
| 600 | - if (FAILED(hr)) return hr;
|
|
| 601 | - |
|
| 602 | - /* if texture has fewer mip levels than DDS file, skip excessive mip levels */
|
|
| 603 | - if (mip_level < mip_levels)
|
|
| 604 | - {
|
|
| 605 | - SetRect(&src_rect, 0, 0, size, size);
|
|
| 606 | - |
|
| 607 | - IDirect3DCubeTexture9_GetCubeMapSurface(cube_texture, face, mip_level, &surface);
|
|
| 608 | - hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
|
|
| 609 | - NULL, &src_rect, filter, color_key);
|
|
| 610 | - IDirect3DSurface9_Release(surface);
|
|
| 611 | - if (FAILED(hr)) return hr;
|
|
| 612 | - }
|
|
| 613 | - |
|
| 614 | - pixels += mip_level_size;
|
|
| 615 | - size = max(1, size / 2);
|
|
| 616 | - }
|
|
| 617 | - }
|
|
| 618 | - |
|
| 619 | - return D3D_OK;
|
|
| 620 | -}
|
|
| 621 | - |
|
| 622 | 586 | static HRESULT d3dx_initialize_image_from_dds(const void *src_data, uint32_t src_data_size,
|
| 623 | 587 | struct d3dx_image *image, uint32_t starting_mip_level)
|
| 624 | 588 | {
|
| 625 | 589 | const struct dds_header *header = src_data;
|
| 626 | 590 | uint32_t expected_src_data_size;
|
| 627 | - uint32_t faces = 1;
|
|
| 628 | 591 | |
| 629 | 592 | if (src_data_size < sizeof(*header) || header->pixel_format.size != sizeof(header->pixel_format))
|
| 630 | 593 | return D3DXERR_INVALIDDATA;
|
| ... | ... | @@ -633,6 +596,7 @@ static HRESULT d3dx_initialize_image_from_dds(const void *src_data, uint32_t src |
| 633 | 596 | set_volume_struct(&image->size, header->width, header->height, 1);
|
| 634 | 597 | image->mip_levels = header->miplevels ? header->miplevels : 1;
|
| 635 | 598 | image->format = dds_pixel_format_to_d3dformat(&header->pixel_format);
|
| 599 | + image->layer_count = 1;
|
|
| 636 | 600 | |
| 637 | 601 | if (image->format == D3DFMT_UNKNOWN)
|
| 638 | 602 | return D3DXERR_INVALIDDATA;
|
| ... | ... | @@ -651,14 +615,15 @@ static HRESULT d3dx_initialize_image_from_dds(const void *src_data, uint32_t src |
| 651 | 615 | return D3DXERR_INVALIDDATA;
|
| 652 | 616 | }
|
| 653 | 617 | |
| 654 | - faces = 6;
|
|
| 618 | + image->layer_count = 6;
|
|
| 655 | 619 | image->resource_type = D3DRTYPE_CUBETEXTURE;
|
| 656 | 620 | }
|
| 657 | 621 | else
|
| 658 | 622 | image->resource_type = D3DRTYPE_TEXTURE;
|
| 659 | 623 | |
| 660 | - expected_src_data_size = calculate_dds_file_size(image->format, image->size.width, image->size.height,
|
|
| 661 | - image->size.depth, image->mip_levels, faces);
|
|
| 624 | + image->layer_pitch = d3dx_calculate_layer_pixels_size(image->format, image->size.width, image->size.height,
|
|
| 625 | + image->size.depth, image->mip_levels);
|
|
| 626 | + expected_src_data_size = (image->layer_pitch * image->layer_count) + sizeof(*header);
|
|
| 662 | 627 | if (src_data_size < expected_src_data_size)
|
| 663 | 628 | {
|
| 664 | 629 | WARN("File is too short %u, expected at least %u bytes.\n", src_data_size, expected_src_data_size);
|
| ... | ... | @@ -1020,6 +985,7 @@ static HRESULT d3dx_initialize_image_from_wic(const void *src_data, uint32_t src |
| 1020 | 985 | |
| 1021 | 986 | image->size.depth = 1;
|
| 1022 | 987 | image->mip_levels = 1;
|
| 988 | + image->layer_count = 1;
|
|
| 1023 | 989 | image->resource_type = D3DRTYPE_TEXTURE;
|
| 1024 | 990 | |
| 1025 | 991 | exit:
|
| ... | ... | @@ -1055,7 +1021,8 @@ void d3dx_image_cleanup(struct d3dx_image *image) |
| 1055 | 1021 | free(image->palette);
|
| 1056 | 1022 | }
|
| 1057 | 1023 | |
| 1058 | -HRESULT d3dx_image_get_pixels(struct d3dx_image *image, uint32_t mip_level, struct d3dx_pixels *pixels)
|
|
| 1024 | +HRESULT d3dx_image_get_pixels(struct d3dx_image *image, uint32_t layer, uint32_t mip_level,
|
|
| 1025 | + struct d3dx_pixels *pixels)
|
|
| 1059 | 1026 | {
|
| 1060 | 1027 | struct volume mip_level_size = image->size;
|
| 1061 | 1028 | const BYTE *pixels_ptr = image->pixels;
|
| ... | ... | @@ -1069,6 +1036,12 @@ HRESULT d3dx_image_get_pixels(struct d3dx_image *image, uint32_t mip_level, stru |
| 1069 | 1036 | return E_FAIL;
|
| 1070 | 1037 | }
|
| 1071 | 1038 | |
| 1039 | + if (layer >= image->layer_count)
|
|
| 1040 | + {
|
|
| 1041 | + ERR("Tried to retrieve layer %u, but image only has %u layers.\n", layer, image->layer_count);
|
|
| 1042 | + return E_FAIL;
|
|
| 1043 | + }
|
|
| 1044 | + |
|
| 1072 | 1045 | slice_pitch = row_pitch = 0;
|
| 1073 | 1046 | for (i = 0; i < image->mip_levels; i++)
|
| 1074 | 1047 | {
|
| ... | ... | @@ -1083,6 +1056,7 @@ HRESULT d3dx_image_get_pixels(struct d3dx_image *image, uint32_t mip_level, stru |
| 1083 | 1056 | d3dx_get_next_mip_level_size(&mip_level_size);
|
| 1084 | 1057 | }
|
| 1085 | 1058 | |
| 1059 | + pixels_ptr += (layer * image->layer_pitch);
|
|
| 1086 | 1060 | SetRect(&unaligned_rect, 0, 0, mip_level_size.width, mip_level_size.height);
|
| 1087 | 1061 | set_d3dx_pixels(pixels, pixels_ptr, row_pitch, slice_pitch, image->palette, mip_level_size.width,
|
| 1088 | 1062 | mip_level_size.height, mip_level_size.depth, &unaligned_rect);
|
| ... | ... | @@ -1294,7 +1268,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(IDirect3DSurface9 *pDestSurface, |
| 1294 | 1268 | else
|
| 1295 | 1269 | SetRect(&src_rect, 0, 0, img_info.Width, img_info.Height);
|
| 1296 | 1270 | |
| 1297 | - hr = d3dx_image_get_pixels(&image, 0, &pixels);
|
|
| 1271 | + hr = d3dx_image_get_pixels(&image, 0, 0, &pixels);
|
|
| 1298 | 1272 | if (FAILED(hr))
|
| 1299 | 1273 | goto exit;
|
| 1300 | 1274 |
| ... | ... | @@ -254,6 +254,99 @@ static const uint8_t dds_cube_map[] = |
| 254 | 254 | 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x55
|
| 255 | 255 | };
|
| 256 | 256 | |
| 257 | +/* 4x2 cube map DDS file. */
|
|
| 258 | +static const uint8_t dds_cube_map_4_2[] =
|
|
| 259 | +{
|
|
| 260 | + 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x0f,0x10,0x00,0x00,0x02,0x00,0x00,0x00,
|
|
| 261 | + 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 262 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 263 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 264 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
|
|
| 265 | + 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
|
|
| 266 | + 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
|
|
| 267 | + 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 268 | + 0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,
|
|
| 269 | + 0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,
|
|
| 270 | + 0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,
|
|
| 271 | + 0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,
|
|
| 272 | + 0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
|
|
| 273 | + 0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
|
|
| 274 | + 0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,
|
|
| 275 | + 0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,
|
|
| 276 | + 0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,
|
|
| 277 | + 0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,
|
|
| 278 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 279 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 280 | +};
|
|
| 281 | + |
|
| 282 | +/* 2x4 cube map DDS file. */
|
|
| 283 | +static const uint8_t dds_cube_map_2_4[] =
|
|
| 284 | +{
|
|
| 285 | + 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x0f,0x10,0x00,0x00,0x04,0x00,0x00,0x00,
|
|
| 286 | + 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 287 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 288 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 289 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
|
|
| 290 | + 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
|
|
| 291 | + 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
|
|
| 292 | + 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 293 | + 0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,
|
|
| 294 | + 0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,
|
|
| 295 | + 0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,
|
|
| 296 | + 0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,
|
|
| 297 | + 0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
|
|
| 298 | + 0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
|
|
| 299 | + 0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,
|
|
| 300 | + 0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,
|
|
| 301 | + 0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,
|
|
| 302 | + 0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,
|
|
| 303 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 304 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 305 | +};
|
|
| 306 | + |
|
| 307 | +/* 4x4 cube map DDS file with 2 mips. */
|
|
| 308 | +static const uint8_t dds_cube_map_4_4[] =
|
|
| 309 | +{
|
|
| 310 | + 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x0f,0x10,0x02,0x00,0x04,0x00,0x00,0x00,
|
|
| 311 | + 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
|
|
| 312 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 313 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 314 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
|
|
| 315 | + 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
|
|
| 316 | + 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
|
|
| 317 | + 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 318 | + 0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,
|
|
| 319 | + 0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,
|
|
| 320 | + 0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,
|
|
| 321 | + 0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,
|
|
| 322 | + 0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,
|
|
| 323 | + 0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
|
|
| 324 | + 0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
|
|
| 325 | + 0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
|
|
| 326 | + 0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
|
|
| 327 | + 0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,
|
|
| 328 | + 0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,
|
|
| 329 | + 0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,
|
|
| 330 | + 0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,
|
|
| 331 | + 0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,
|
|
| 332 | + 0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
|
|
| 333 | + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,
|
|
| 334 | + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,
|
|
| 335 | + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,
|
|
| 336 | + 0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,
|
|
| 337 | + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
| 338 | + 0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,
|
|
| 339 | + 0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,
|
|
| 340 | + 0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,
|
|
| 341 | + 0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,
|
|
| 342 | + 0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,
|
|
| 343 | + 0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,
|
|
| 344 | + 0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,
|
|
| 345 | + 0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,
|
|
| 346 | + 0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,
|
|
| 347 | + 0x00,0x80,0x80,0x00,0x00,0x80,0x80,0x00,0x00,0x80,0x80,0x00,0x00,0x80,0x80,0x00,
|
|
| 348 | +};
|
|
| 349 | + |
|
| 257 | 350 | /* 4x4x2 volume map dds, 2 mipmaps */
|
| 258 | 351 | static const uint8_t dds_volume_map[] =
|
| 259 | 352 | {
|
| ... | ... | @@ -251,7 +251,7 @@ static void test_dds_header_handling(void) |
| 251 | 251 | BYTE data[4096 * 1024];
|
| 252 | 252 | } *dds;
|
| 253 | 253 | |
| 254 | - struct
|
|
| 254 | + static const struct
|
|
| 255 | 255 | {
|
| 256 | 256 | struct dds_pixel_format pixel_format;
|
| 257 | 257 | DWORD flags;
|
| ... | ... | @@ -355,7 +355,7 @@ static void test_dds_header_handling(void) |
| 355 | 355 | { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 9, 262146, { D3D_OK, 9 } },
|
| 356 | 356 | { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 10, 262146, { D3D_OK, 10 } },
|
| 357 | 357 | };
|
| 358 | - struct
|
|
| 358 | + static const struct
|
|
| 359 | 359 | {
|
| 360 | 360 | uint32_t flags;
|
| 361 | 361 | uint32_t width;
|
| ... | ... | @@ -375,40 +375,40 @@ static void test_dds_header_handling(void) |
| 375 | 375 | D3DRESOURCETYPE resource_type;
|
| 376 | 376 | }
|
| 377 | 377 | expected;
|
| 378 | + uint32_t pixel_data_size;
|
|
| 378 | 379 | BOOL todo_hr;
|
| 379 | 380 | BOOL todo_info;
|
| 380 | - uint32_t pixel_data_size;
|
|
| 381 | 381 | } info_tests[] = {
|
| 382 | 382 | /* Depth value set to 4, but no caps bits are set. Depth is ignored. */
|
| 383 | 383 | { (DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT), 4, 4, 4, (4 * 4), 3, 0, 0,
|
| 384 | - { D3D_OK, 4, 4, 1, 3, D3DRTYPE_TEXTURE, }, FALSE, FALSE, 292 },
|
|
| 384 | + { D3D_OK, 4, 4, 1, 3, D3DRTYPE_TEXTURE, }, 292 },
|
|
| 385 | 385 | /* The volume texture caps2 field is ignored. */
|
| 386 | 386 | { (DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT), 4, 4, 4, (4 * 4), 3,
|
| 387 | 387 | (DDS_CAPS_TEXTURE | DDS_CAPS_COMPLEX), DDS_CAPS2_VOLUME,
|
| 388 | - { D3D_OK, 4, 4, 1, 3, D3DRTYPE_TEXTURE, }, FALSE, FALSE, 292 },
|
|
| 388 | + { D3D_OK, 4, 4, 1, 3, D3DRTYPE_TEXTURE, }, 292 },
|
|
| 389 | 389 | /*
|
| 390 | 390 | * The DDS_DEPTH flag is the only thing checked to determine if a DDS
|
| 391 | 391 | * file represents a volume texture.
|
| 392 | 392 | */
|
| 393 | 393 | { (DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT | DDS_DEPTH), 4, 4, 4, (4 * 4), 3,
|
| 394 | 394 | 0, 0,
|
| 395 | - { D3D_OK, 4, 4, 4, 3, D3DRTYPE_VOLUMETEXTURE, }, FALSE, FALSE, 292 },
|
|
| 395 | + { D3D_OK, 4, 4, 4, 3, D3DRTYPE_VOLUMETEXTURE, }, 292 },
|
|
| 396 | 396 | /* Even if the depth field is set to 0, it's still a volume texture. */
|
| 397 | 397 | { (DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT | DDS_DEPTH), 4, 4, 0, (4 * 4), 3,
|
| 398 | 398 | 0, 0,
|
| 399 | - { D3D_OK, 4, 4, 1, 3, D3DRTYPE_VOLUMETEXTURE, }, FALSE, FALSE, 292 },
|
|
| 399 | + { D3D_OK, 4, 4, 1, 3, D3DRTYPE_VOLUMETEXTURE, }, 292 },
|
|
| 400 | 400 | /* The DDS_DEPTH flag overrides cubemap caps. */
|
| 401 | 401 | { (DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT | DDS_DEPTH), 4, 4, 4, (4 * 4), 3,
|
| 402 | 402 | (DDS_CAPS_TEXTURE | DDS_CAPS_COMPLEX), (DDS_CAPS2_CUBEMAP | DDS_CAPS2_CUBEMAP_ALL_FACES),
|
| 403 | - { D3D_OK, 4, 4, 4, 3, D3DRTYPE_VOLUMETEXTURE, }, FALSE, FALSE, (292 * 6) },
|
|
| 403 | + { D3D_OK, 4, 4, 4, 3, D3DRTYPE_VOLUMETEXTURE, }, (292 * 6) },
|
|
| 404 | 404 | /* Cubemap where width field does not equal height. */
|
| 405 | 405 | { (DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT), 4, 5, 1, (4 * 4), 1,
|
| 406 | 406 | (DDS_CAPS_TEXTURE | DDS_CAPS_COMPLEX), (DDS_CAPS2_CUBEMAP | DDS_CAPS2_CUBEMAP_ALL_FACES),
|
| 407 | - { D3D_OK, 4, 5, 1, 1, D3DRTYPE_CUBETEXTURE, }, FALSE, FALSE, (80 * 6) },
|
|
| 407 | + { D3D_OK, 4, 5, 1, 1, D3DRTYPE_CUBETEXTURE, }, (80 * 6) },
|
|
| 408 | 408 | /* Partial cubemaps are not supported. */
|
| 409 | 409 | { (DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT), 4, 4, 1, (4 * 4), 1,
|
| 410 | 410 | (DDS_CAPS_TEXTURE | DDS_CAPS_COMPLEX), (DDS_CAPS2_CUBEMAP | DDS_CAPS2_CUBEMAP_POSITIVEX),
|
| 411 | - { D3DXERR_INVALIDDATA, }, FALSE, FALSE, (64 * 6) },
|
|
| 411 | + { D3DXERR_INVALIDDATA, }, (64 * 6) },
|
|
| 412 | 412 | };
|
| 413 | 413 | |
| 414 | 414 | dds = calloc(1, sizeof(*dds));
|
| ... | ... | @@ -48,6 +48,38 @@ static inline void expect_vec4_(unsigned int line, const D3DXVECTOR4 *expected, |
| 48 | 48 | got->x, got->y, got->z, got->w);
|
| 49 | 49 | }
|
| 50 | 50 | |
| 51 | +static inline void check_surface_desc(uint32_t line, D3DFORMAT format, uint32_t usage, D3DPOOL pool,
|
|
| 52 | + D3DMULTISAMPLE_TYPE multi_sample_type, uint32_t multi_sample_quality, uint32_t width, uint32_t height,
|
|
| 53 | + const D3DSURFACE_DESC *desc, BOOL wine_todo)
|
|
| 54 | +{
|
|
| 55 | + const D3DSURFACE_DESC expected_desc = { format, D3DRTYPE_SURFACE, usage, pool, multi_sample_type,
|
|
| 56 | + multi_sample_quality, width, height };
|
|
| 57 | + BOOL matched;
|
|
| 58 | + |
|
| 59 | + matched = !memcmp(&expected_desc, desc, sizeof(*desc));
|
|
| 60 | + todo_wine_if(wine_todo) ok_(__FILE__, line)(matched, "Got unexpected surface desc values.\n");
|
|
| 61 | + if (matched)
|
|
| 62 | + return;
|
|
| 63 | + |
|
| 64 | + todo_wine_if(wine_todo && desc->Format != format)
|
|
| 65 | + ok_(__FILE__, line)(desc->Format == format, "Expected surface format %d, got %d.\n", format, desc->Format);
|
|
| 66 | + ok_(__FILE__, line)(desc->Type == D3DRTYPE_SURFACE, "Expected D3DRTYPE_SURFACE, got %d.\n", desc->Type);
|
|
| 67 | + todo_wine_if(wine_todo && desc->Usage != usage)
|
|
| 68 | + ok_(__FILE__, line)(desc->Usage == usage, "Expected usage %u, got %lu.\n", usage, desc->Usage);
|
|
| 69 | + todo_wine_if(wine_todo && desc->Pool != pool)
|
|
| 70 | + ok_(__FILE__, line)(desc->Pool == pool, "Expected pool %d, got %d.\n", pool, desc->Pool);
|
|
| 71 | + todo_wine_if(wine_todo && desc->MultiSampleType != multi_sample_type)
|
|
| 72 | + ok_(__FILE__, line)(desc->MultiSampleType == multi_sample_type, "Expected multi sample type %d, got %d.\n",
|
|
| 73 | + multi_sample_type, desc->MultiSampleType);
|
|
| 74 | + todo_wine_if(wine_todo && desc->MultiSampleQuality != multi_sample_quality)
|
|
| 75 | + ok_(__FILE__, line)(desc->MultiSampleQuality == multi_sample_quality, "Expected multi sample quality %u, got %lu.\n",
|
|
| 76 | + multi_sample_quality, desc->MultiSampleQuality);
|
|
| 77 | + todo_wine_if(wine_todo && desc->Width != width)
|
|
| 78 | + ok_(__FILE__, line)(desc->Width == width, "Expected width %d, got %d.\n", width, desc->Width);
|
|
| 79 | + todo_wine_if(wine_todo && desc->Height != height)
|
|
| 80 | + ok_(__FILE__, line)(desc->Height == height, "Expected height %d, got %d.\n", height, desc->Height);
|
|
| 81 | +}
|
|
| 82 | + |
|
| 51 | 83 | #define check_texture_level_desc(tex, level, format, usage, pool, multi_sample_type, multi_sample_quality, width, \
|
| 52 | 84 | height, wine_todo) \
|
| 53 | 85 | check_texture_level_desc_(__LINE__, tex, level, format, usage, pool, multi_sample_type, multi_sample_quality, \
|
| ... | ... | @@ -56,10 +88,7 @@ static inline void check_texture_level_desc_(uint32_t line, IDirect3DTexture9 *t |
| 56 | 88 | uint32_t usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multi_sample_type,
|
| 57 | 89 | uint32_t multi_sample_quality, uint32_t width, uint32_t height, BOOL wine_todo)
|
| 58 | 90 | {
|
| 59 | - const D3DSURFACE_DESC expected_desc = { format, D3DRTYPE_SURFACE, usage, pool, multi_sample_type,
|
|
| 60 | - multi_sample_quality, width, height };
|
|
| 61 | 91 | D3DSURFACE_DESC desc;
|
| 62 | - BOOL matched;
|
|
| 63 | 92 | HRESULT hr;
|
| 64 | 93 | |
| 65 | 94 | hr = IDirect3DTexture9_GetLevelDesc(tex, level, &desc);
|
| ... | ... | @@ -68,28 +97,28 @@ static inline void check_texture_level_desc_(uint32_t line, IDirect3DTexture9 *t |
| 68 | 97 | if (FAILED(hr))
|
| 69 | 98 | return;
|
| 70 | 99 | |
| 71 | - matched = !memcmp(&expected_desc, &desc, sizeof(desc));
|
|
| 72 | - todo_wine_if(wine_todo) ok_(__FILE__, line)(matched, "Got unexpected surface desc values.\n");
|
|
| 73 | - if (matched)
|
|
| 100 | + check_surface_desc(line, format, usage, pool, multi_sample_type, multi_sample_quality, width, height, &desc,
|
|
| 101 | + wine_todo);
|
|
| 102 | +}
|
|
| 103 | + |
|
| 104 | +#define check_cube_texture_level_desc(tex, level, format, usage, pool, multi_sample_type, multi_sample_quality, size, \
|
|
| 105 | + wine_todo) \
|
|
| 106 | + check_cube_texture_level_desc_(__LINE__, tex, level, format, usage, pool, multi_sample_type, multi_sample_quality, \
|
|
| 107 | + size, wine_todo)
|
|
| 108 | +static inline void check_cube_texture_level_desc_(uint32_t line, IDirect3DCubeTexture9 *tex, uint32_t level,
|
|
| 109 | + D3DFORMAT format, uint32_t usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multi_sample_type,
|
|
| 110 | + uint32_t multi_sample_quality, uint32_t size, BOOL wine_todo)
|
|
| 111 | +{
|
|
| 112 | + D3DSURFACE_DESC desc;
|
|
| 113 | + HRESULT hr;
|
|
| 114 | + |
|
| 115 | + hr = IDirect3DCubeTexture9_GetLevelDesc(tex, level, &desc);
|
|
| 116 | + todo_wine_if(wine_todo && FAILED(hr))
|
|
| 117 | + ok_(__FILE__, line)(hr == S_OK, "Failed to get cube texture level desc with hr %#lx.\n", hr);
|
|
| 118 | + if (FAILED(hr))
|
|
| 74 | 119 | return;
|
| 75 | 120 | |
| 76 | - todo_wine_if(wine_todo && desc.Format != format)
|
|
| 77 | - ok_(__FILE__, line)(desc.Format == format, "Expected surface format %d, got %d.\n", format, desc.Format);
|
|
| 78 | - ok_(__FILE__, line)(desc.Type == D3DRTYPE_SURFACE, "Expected D3DRTYPE_SURFACE, got %d.\n", desc.Type);
|
|
| 79 | - todo_wine_if(wine_todo && desc.Usage != usage)
|
|
| 80 | - ok_(__FILE__, line)(desc.Usage == usage, "Expected usage %u, got %lu.\n", usage, desc.Usage);
|
|
| 81 | - todo_wine_if(wine_todo && desc.Pool != pool)
|
|
| 82 | - ok_(__FILE__, line)(desc.Pool == pool, "Expected pool %d, got %d.\n", pool, desc.Pool);
|
|
| 83 | - todo_wine_if(wine_todo && desc.MultiSampleType != multi_sample_type)
|
|
| 84 | - ok_(__FILE__, line)(desc.MultiSampleType == multi_sample_type, "Expected multi sample type %d, got %d.\n",
|
|
| 85 | - multi_sample_type, desc.MultiSampleType);
|
|
| 86 | - todo_wine_if(wine_todo && desc.MultiSampleQuality != multi_sample_quality)
|
|
| 87 | - ok_(__FILE__, line)(desc.MultiSampleQuality == multi_sample_quality, "Expected multi sample quality %u, got %lu.\n",
|
|
| 88 | - multi_sample_quality, desc.MultiSampleQuality);
|
|
| 89 | - todo_wine_if(wine_todo && desc.Width != width)
|
|
| 90 | - ok_(__FILE__, line)(desc.Width == width, "Expected width %u, got %u.\n", width, desc.Width);
|
|
| 91 | - todo_wine_if(wine_todo && desc.Height != height)
|
|
| 92 | - ok_(__FILE__, line)(desc.Height == height, "Expected height %u, got %u.\n", height, desc.Height);
|
|
| 121 | + check_surface_desc(line, format, usage, pool, multi_sample_type, multi_sample_quality, size, size, &desc, wine_todo);
|
|
| 93 | 122 | }
|
| 94 | 123 | |
| 95 | 124 | #define check_volume_texture_level_desc(tex, level, format, usage, pool, width, height, depth, wine_todo) \
|
| ... | ... | @@ -177,21 +206,11 @@ static void release_surface_readback(struct surface_readback *rb) |
| 177 | 206 | IDirect3DSurface9_Release(rb->surface);
|
| 178 | 207 | }
|
| 179 | 208 | |
| 180 | -static void get_texture_surface_readback(IDirect3DDevice9 *device, IDirect3DTexture9 *texture, uint32_t mip_level,
|
|
| 181 | - struct surface_readback *rb)
|
|
| 209 | +static void get_surface_readback(IDirect3DDevice9 *device, IDirect3DSurface9 *surface, struct surface_readback *rb)
|
|
| 182 | 210 | {
|
| 183 | - IDirect3DSurface9 *surface;
|
|
| 184 | 211 | D3DSURFACE_DESC desc;
|
| 185 | 212 | HRESULT hr;
|
| 186 | 213 | |
| 187 | - memset(rb, 0, sizeof(*rb));
|
|
| 188 | - hr = IDirect3DTexture9_GetSurfaceLevel(texture, mip_level, &surface);
|
|
| 189 | - if (FAILED(hr))
|
|
| 190 | - {
|
|
| 191 | - trace("Failed to get surface for mip level %d, hr %#lx.\n", mip_level, hr);
|
|
| 192 | - return;
|
|
| 193 | - }
|
|
| 194 | - |
|
| 195 | 214 | hr = IDirect3DSurface9_GetDesc(surface, &desc);
|
| 196 | 215 | if (FAILED(hr))
|
| 197 | 216 | {
|
| ... | ... | @@ -219,7 +238,6 @@ static void get_texture_surface_readback(IDirect3DDevice9 *device, IDirect3DText |
| 219 | 238 | trace("Can't lock the readback surface, hr %#lx.\n", hr);
|
| 220 | 239 | |
| 221 | 240 | exit:
|
| 222 | - IDirect3DSurface9_Release(surface);
|
|
| 223 | 241 | if (FAILED(hr))
|
| 224 | 242 | {
|
| 225 | 243 | if (rb->surface)
|
| ... | ... | @@ -228,6 +246,42 @@ exit: |
| 228 | 246 | }
|
| 229 | 247 | }
|
| 230 | 248 | |
| 249 | +static void get_texture_surface_readback(IDirect3DDevice9 *device, IDirect3DTexture9 *texture, uint32_t mip_level,
|
|
| 250 | + struct surface_readback *rb)
|
|
| 251 | +{
|
|
| 252 | + IDirect3DSurface9 *surface;
|
|
| 253 | + HRESULT hr;
|
|
| 254 | + |
|
| 255 | + memset(rb, 0, sizeof(*rb));
|
|
| 256 | + hr = IDirect3DTexture9_GetSurfaceLevel(texture, mip_level, &surface);
|
|
| 257 | + if (FAILED(hr))
|
|
| 258 | + {
|
|
| 259 | + trace("Failed to get surface for mip level %d, hr %#lx.\n", mip_level, hr);
|
|
| 260 | + return;
|
|
| 261 | + }
|
|
| 262 | + |
|
| 263 | + get_surface_readback(device, surface, rb);
|
|
| 264 | + IDirect3DSurface9_Release(surface);
|
|
| 265 | +}
|
|
| 266 | + |
|
| 267 | +static void get_cube_texture_surface_readback(IDirect3DDevice9 *device, IDirect3DCubeTexture9 *texture, uint32_t face,
|
|
| 268 | + uint32_t mip_level, struct surface_readback *rb)
|
|
| 269 | +{
|
|
| 270 | + IDirect3DSurface9 *surface;
|
|
| 271 | + HRESULT hr;
|
|
| 272 | + |
|
| 273 | + memset(rb, 0, sizeof(*rb));
|
|
| 274 | + hr = IDirect3DCubeTexture9_GetCubeMapSurface(texture, face, mip_level, &surface);
|
|
| 275 | + if (FAILED(hr))
|
|
| 276 | + {
|
|
| 277 | + trace("Failed to get surface for face %d mip level %d, hr %#lx.\n", face, mip_level, hr);
|
|
| 278 | + return;
|
|
| 279 | + }
|
|
| 280 | + |
|
| 281 | + get_surface_readback(device, surface, rb);
|
|
| 282 | + IDirect3DSurface9_Release(surface);
|
|
| 283 | +}
|
|
| 284 | + |
|
| 231 | 285 | #define check_readback_pixel_4bpp(rb, x, y, color, todo) _check_readback_pixel_4bpp(__LINE__, rb, x, y, color, todo)
|
| 232 | 286 | static inline void _check_readback_pixel_4bpp(uint32_t line, struct surface_readback *rb, uint32_t x,
|
| 233 | 287 | uint32_t y, uint32_t expected_color, BOOL todo)
|
| ... | ... | @@ -2367,6 +2421,12 @@ static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device) |
| 2367 | 2421 | hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), NULL);
|
| 2368 | 2422 | ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
|
| 2369 | 2423 | |
| 2424 | + hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit), &cube_texture);
|
|
| 2425 | + ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
|
|
| 2426 | + |
|
| 2427 | + hr = D3DXCreateCubeTextureFromFileInMemory(device, bmp_32bpp_4_4_argb, sizeof(bmp_32bpp_4_4_argb), &cube_texture);
|
|
| 2428 | + ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
|
|
| 2429 | + |
|
| 2370 | 2430 | hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
|
| 2371 | 2431 | if (SUCCEEDED(hr))
|
| 2372 | 2432 | {
|
| ... | ... | @@ -2385,7 +2445,20 @@ static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device) |
| 2385 | 2445 | |
| 2386 | 2446 | static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
|
| 2387 | 2447 | {
|
| 2448 | + static const uint32_t dds_cube_map_non_square_expected[] =
|
|
| 2449 | + {
|
|
| 2450 | + 0xffff0000, 0xff00ff00, 0xff0000ff, 0xffffff00, 0xffff00ff, 0xff000000,
|
|
| 2451 | + };
|
|
| 2452 | + static const uint32_t dds_cube_map_4_4_expected[] =
|
|
| 2453 | + {
|
|
| 2454 | + 0xffff0000, 0xff00ff00, 0xff0000ff, 0xffffff00, 0xffff00ff, 0xff00ffff,
|
|
| 2455 | + 0xffffffff, 0xff000000, 0xff800000, 0xff008000, 0xff000080, 0xff808000
|
|
| 2456 | + };
|
|
| 2388 | 2457 | IDirect3DCubeTexture9 *cube_texture;
|
| 2458 | + struct surface_readback surface_rb;
|
|
| 2459 | + D3DSURFACE_DESC desc;
|
|
| 2460 | + D3DXIMAGE_INFO info;
|
|
| 2461 | + uint32_t i, x, y;
|
|
| 2389 | 2462 | HRESULT hr;
|
| 2390 | 2463 | |
| 2391 | 2464 | hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map, sizeof(dds_cube_map), D3DX_DEFAULT,
|
| ... | ... | @@ -2405,6 +2478,176 @@ static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic |
| 2405 | 2478 | D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &cube_texture);
|
| 2406 | 2479 | ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
|
| 2407 | 2480 | IDirect3DCubeTexture9_Release(cube_texture);
|
| 2481 | + |
|
| 2482 | + /*
|
|
| 2483 | + * Cubemap file with a width of 4 and a height of 2. The largest value is
|
|
| 2484 | + * used for the size of the created cubemap.
|
|
| 2485 | + */
|
|
| 2486 | + hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map_4_2, sizeof(dds_cube_map_4_2), D3DX_DEFAULT, 1,
|
|
| 2487 | + D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT, 0, &info, NULL, &cube_texture);
|
|
| 2488 | + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
|
|
| 2489 | + |
|
| 2490 | + check_texture_mip_levels(cube_texture, 1, FALSE);
|
|
| 2491 | + check_image_info(&info, 4, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_CUBETEXTURE, D3DXIFF_DDS, FALSE);
|
|
| 2492 | + check_cube_texture_level_desc(cube_texture, 0, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 4, FALSE);
|
|
| 2493 | + |
|
| 2494 | + IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &desc);
|
|
| 2495 | + for (i = 0; i < 6; ++i)
|
|
| 2496 | + {
|
|
| 2497 | + const uint32_t expected_color = dds_cube_map_non_square_expected[i];
|
|
| 2498 | + |
|
| 2499 | + winetest_push_context("Face %u", i);
|
|
| 2500 | + get_cube_texture_surface_readback(device, cube_texture, i, 0, &surface_rb);
|
|
| 2501 | + for (y = 0; y < desc.Height; ++y)
|
|
| 2502 | + {
|
|
| 2503 | + for (x = 0; x < desc.Width; ++x)
|
|
| 2504 | + {
|
|
| 2505 | + if (y < info.Height)
|
|
| 2506 | + check_readback_pixel_4bpp(&surface_rb, x, y, expected_color, FALSE);
|
|
| 2507 | + else
|
|
| 2508 | + check_readback_pixel_4bpp(&surface_rb, x, y, 0xff000000, FALSE);
|
|
| 2509 | + }
|
|
| 2510 | + }
|
|
| 2511 | + release_surface_readback(&surface_rb);
|
|
| 2512 | + winetest_pop_context();
|
|
| 2513 | + }
|
|
| 2514 | + IDirect3DCubeTexture9_Release(cube_texture);
|
|
| 2515 | + |
|
| 2516 | + /*
|
|
| 2517 | + * Load the same cubemap, but this time with a point filter. Source image
|
|
| 2518 | + * is scaled to cover the entire 4x4 cubemap texture faces.
|
|
| 2519 | + */
|
|
| 2520 | + hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map_4_2, sizeof(dds_cube_map_4_2), D3DX_DEFAULT, 1,
|
|
| 2521 | + D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_FILTER_POINT, D3DX_DEFAULT, 0, &info, NULL, &cube_texture);
|
|
| 2522 | + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
|
|
| 2523 | + |
|
| 2524 | + check_texture_mip_levels(cube_texture, 1, FALSE);
|
|
| 2525 | + check_image_info(&info, 4, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_CUBETEXTURE, D3DXIFF_DDS, FALSE);
|
|
| 2526 | + check_cube_texture_level_desc(cube_texture, 0, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 4, FALSE);
|
|
| 2527 | + |
|
| 2528 | + IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &desc);
|
|
| 2529 | + for (i = 0; i < 6; ++i)
|
|
| 2530 | + {
|
|
| 2531 | + const uint32_t expected_color = dds_cube_map_non_square_expected[i];
|
|
| 2532 | + |
|
| 2533 | + winetest_push_context("Face %u", i);
|
|
| 2534 | + get_cube_texture_surface_readback(device, cube_texture, i, 0, &surface_rb);
|
|
| 2535 | + for (y = 0; y < desc.Height; ++y)
|
|
| 2536 | + {
|
|
| 2537 | + for (x = 0; x < desc.Width; ++x)
|
|
| 2538 | + {
|
|
| 2539 | + check_readback_pixel_4bpp(&surface_rb, x, y, expected_color, FALSE);
|
|
| 2540 | + }
|
|
| 2541 | + }
|
|
| 2542 | + release_surface_readback(&surface_rb);
|
|
| 2543 | + winetest_pop_context();
|
|
| 2544 | + }
|
|
| 2545 | + IDirect3DCubeTexture9_Release(cube_texture);
|
|
| 2546 | + |
|
| 2547 | + /*
|
|
| 2548 | + * Cubemap file with a width of 2 and a height of 4.
|
|
| 2549 | + */
|
|
| 2550 | + hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map_2_4, sizeof(dds_cube_map_2_4), D3DX_DEFAULT, 1,
|
|
| 2551 | + D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT, 0, &info, NULL, &cube_texture);
|
|
| 2552 | + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
|
|
| 2553 | + |
|
| 2554 | + check_texture_mip_levels(cube_texture, 1, FALSE);
|
|
| 2555 | + check_image_info(&info, 2, 4, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_CUBETEXTURE, D3DXIFF_DDS, FALSE);
|
|
| 2556 | + check_cube_texture_level_desc(cube_texture, 0, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 4, FALSE);
|
|
| 2557 | + |
|
| 2558 | + IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &desc);
|
|
| 2559 | + for (i = 0; i < 6; ++i)
|
|
| 2560 | + {
|
|
| 2561 | + const uint32_t expected_color = dds_cube_map_non_square_expected[i];
|
|
| 2562 | + |
|
| 2563 | + winetest_push_context("Face %u", i);
|
|
| 2564 | + get_cube_texture_surface_readback(device, cube_texture, i, 0, &surface_rb);
|
|
| 2565 | + for (y = 0; y < desc.Height; ++y)
|
|
| 2566 | + {
|
|
| 2567 | + for (x = 0; x < desc.Width; ++x)
|
|
| 2568 | + {
|
|
| 2569 | + if (x < info.Width)
|
|
| 2570 | + check_readback_pixel_4bpp(&surface_rb, x, y, expected_color, FALSE);
|
|
| 2571 | + else
|
|
| 2572 | + check_readback_pixel_4bpp(&surface_rb, x, y, 0xff000000, FALSE);
|
|
| 2573 | + }
|
|
| 2574 | + }
|
|
| 2575 | + release_surface_readback(&surface_rb);
|
|
| 2576 | + winetest_pop_context();
|
|
| 2577 | + }
|
|
| 2578 | + IDirect3DCubeTexture9_Release(cube_texture);
|
|
| 2579 | + |
|
| 2580 | + /* Multi-mip cubemap DDS file. */
|
|
| 2581 | + hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map_4_4, sizeof(dds_cube_map_4_4), D3DX_DEFAULT, D3DX_FROM_FILE,
|
|
| 2582 | + D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, &info, NULL, &cube_texture);
|
|
| 2583 | + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
|
|
| 2584 | + |
|
| 2585 | + check_texture_mip_levels(cube_texture, 2, FALSE);
|
|
| 2586 | + check_image_info(&info, 4, 4, 1, 2, D3DFMT_X8R8G8B8, D3DRTYPE_CUBETEXTURE, D3DXIFF_DDS, FALSE);
|
|
| 2587 | + check_cube_texture_level_desc(cube_texture, 0, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 4, FALSE);
|
|
| 2588 | + check_cube_texture_level_desc(cube_texture, 1, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 2, FALSE);
|
|
| 2589 | + |
|
| 2590 | + for (i = 0; i < 6; ++i)
|
|
| 2591 | + {
|
|
| 2592 | + uint32_t mip_level;
|
|
| 2593 | + |
|
| 2594 | + for (mip_level = 0; mip_level < 2; ++mip_level)
|
|
| 2595 | + {
|
|
| 2596 | + const uint32_t expected_color = dds_cube_map_4_4_expected[(i * 2) + mip_level];
|
|
| 2597 | + |
|
| 2598 | + winetest_push_context("Face %u, mip level %u", i, mip_level);
|
|
| 2599 | + IDirect3DCubeTexture9_GetLevelDesc(cube_texture, mip_level, &desc);
|
|
| 2600 | + get_cube_texture_surface_readback(device, cube_texture, i, mip_level, &surface_rb);
|
|
| 2601 | + for (y = 0; y < desc.Height; ++y)
|
|
| 2602 | + {
|
|
| 2603 | + for (x = 0; x < desc.Width; ++x)
|
|
| 2604 | + {
|
|
| 2605 | + check_readback_pixel_4bpp(&surface_rb, x, y, expected_color, FALSE);
|
|
| 2606 | + }
|
|
| 2607 | + }
|
|
| 2608 | + release_surface_readback(&surface_rb);
|
|
| 2609 | + winetest_pop_context();
|
|
| 2610 | + }
|
|
| 2611 | + }
|
|
| 2612 | + IDirect3DCubeTexture9_Release(cube_texture);
|
|
| 2613 | + |
|
| 2614 | + /* Skip level bits are bits 30-26. Bit 31 needs to be ignored. */
|
|
| 2615 | + hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map_4_4, sizeof(dds_cube_map_4_4), D3DX_DEFAULT,
|
|
| 2616 | + D3DX_FROM_FILE, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT,
|
|
| 2617 | + D3DX_FILTER_POINT | (0x20u << D3DX_SKIP_DDS_MIP_LEVELS_SHIFT), 0, &info, NULL, &cube_texture);
|
|
| 2618 | + ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
|
|
| 2619 | + |
|
| 2620 | + check_image_info(&info, 4, 4, 1, 2, D3DFMT_X8R8G8B8, D3DRTYPE_CUBETEXTURE, D3DXIFF_DDS, FALSE);
|
|
| 2621 | + IDirect3DCubeTexture9_Release(cube_texture);
|
|
| 2622 | + |
|
| 2623 | + /* Multi-mip cubemap DDS file with mip skipping. */
|
|
| 2624 | + hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map_4_4, sizeof(dds_cube_map_4_4), D3DX_DEFAULT,
|
|
| 2625 | + D3DX_FROM_FILE, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT,
|
|
| 2626 | + D3DX_SKIP_DDS_MIP_LEVELS(1, D3DX_DEFAULT), 0, &info, NULL, &cube_texture);
|
|
| 2627 | + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
|
|
| 2628 | + |
|
| 2629 | + check_texture_mip_levels(cube_texture, 1, FALSE);
|
|
| 2630 | + check_image_info(&info, 2, 2, 1, 1, D3DFMT_X8R8G8B8, D3DRTYPE_CUBETEXTURE, D3DXIFF_DDS, FALSE);
|
|
| 2631 | + check_cube_texture_level_desc(cube_texture, 0, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, 0, 0, 2, FALSE);
|
|
| 2632 | + |
|
| 2633 | + for (i = 0; i < 6; ++i)
|
|
| 2634 | + {
|
|
| 2635 | + const uint32_t expected_color = dds_cube_map_4_4_expected[(i * 2) + 1];
|
|
| 2636 | + |
|
| 2637 | + winetest_push_context("Face %u", i);
|
|
| 2638 | + IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &desc);
|
|
| 2639 | + get_cube_texture_surface_readback(device, cube_texture, i, 0, &surface_rb);
|
|
| 2640 | + for (y = 0; y < desc.Height; ++y)
|
|
| 2641 | + {
|
|
| 2642 | + for (x = 0; x < desc.Width; ++x)
|
|
| 2643 | + {
|
|
| 2644 | + check_readback_pixel_4bpp(&surface_rb, x, y, expected_color, FALSE);
|
|
| 2645 | + }
|
|
| 2646 | + }
|
|
| 2647 | + release_surface_readback(&surface_rb);
|
|
| 2648 | + winetest_pop_context();
|
|
| 2649 | + }
|
|
| 2650 | + IDirect3DCubeTexture9_Release(cube_texture);
|
|
| 2408 | 2651 | }
|
| 2409 | 2652 | |
| 2410 | 2653 | static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device)
|
| ... | ... | @@ -656,7 +656,7 @@ HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(struct IDirect3DDevice9 *devi |
| 656 | 656 | D3DLOCKED_RECT dst_locked_rect;
|
| 657 | 657 | RECT dst_rect;
|
| 658 | 658 | |
| 659 | - hr = d3dx_image_get_pixels(&image, i, &src_pixels);
|
|
| 659 | + hr = d3dx_image_get_pixels(&image, 0, i, &src_pixels);
|
|
| 660 | 660 | if (FAILED(hr))
|
| 661 | 661 | break;
|
| 662 | 662 | |
| ... | ... | @@ -1185,7 +1185,7 @@ HRESULT WINAPI D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9 *devic |
| 1185 | 1185 | D3DLOCKED_BOX dst_locked_box;
|
| 1186 | 1186 | RECT dst_rect;
|
| 1187 | 1187 | |
| 1188 | - hr = d3dx_image_get_pixels(&image, i, &src_pixels);
|
|
| 1188 | + hr = d3dx_image_get_pixels(&image, 0, i, &src_pixels);
|
|
| 1189 | 1189 | if (FAILED(hr))
|
| 1190 | 1190 | break;
|
| 1191 | 1191 | |
| ... | ... | @@ -1378,15 +1378,14 @@ HRESULT WINAPI D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device, |
| 1378 | 1378 | DWORD filter, DWORD mip_filter, D3DCOLOR color_key, D3DXIMAGE_INFO *src_info,
|
| 1379 | 1379 | PALETTEENTRY *palette, IDirect3DCubeTexture9 **cube_texture)
|
| 1380 | 1380 | {
|
| 1381 | - HRESULT hr;
|
|
| 1382 | - D3DCAPS9 caps;
|
|
| 1383 | - UINT loaded_miplevels;
|
|
| 1381 | + const struct pixel_format_desc *src_fmt_desc, *dst_fmt_desc;
|
|
| 1382 | + BOOL dynamic_texture, format_specified = FALSE;
|
|
| 1383 | + uint32_t loaded_miplevels, skip_levels, i;
|
|
| 1384 | + IDirect3DCubeTexture9 *tex, *staging_tex;
|
|
| 1385 | + struct d3dx_image image;
|
|
| 1384 | 1386 | D3DXIMAGE_INFO img_info;
|
| 1385 | - BOOL dynamic_texture;
|
|
| 1386 | - BOOL file_size = FALSE;
|
|
| 1387 | - BOOL file_format = FALSE;
|
|
| 1388 | - BOOL file_mip_levels = FALSE;
|
|
| 1389 | - IDirect3DCubeTexture9 *tex, *buftex;
|
|
| 1387 | + D3DCAPS9 caps;
|
|
| 1388 | + HRESULT hr;
|
|
| 1390 | 1389 | |
| 1391 | 1390 | TRACE("device %p, src_data %p, src_data_size %u, size %u, mip_levels %u, usage %#lx, "
|
| 1392 | 1391 | "format %#x, pool %#x, filter %#lx, mip_filter %#lx, color_key 0x%08lx, src_info %p, "
|
| ... | ... | @@ -1397,102 +1396,145 @@ HRESULT WINAPI D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device, |
| 1397 | 1396 | if (!device || !cube_texture || !src_data || !src_data_size)
|
| 1398 | 1397 | return D3DERR_INVALIDCALL;
|
| 1399 | 1398 | |
| 1400 | - hr = D3DXGetImageInfoFromFileInMemory(src_data, src_data_size, &img_info);
|
|
| 1399 | + staging_tex = tex = *cube_texture = NULL;
|
|
| 1400 | + skip_levels = mip_filter != D3DX_DEFAULT ? mip_filter >> D3DX_SKIP_DDS_MIP_LEVELS_SHIFT : 0;
|
|
| 1401 | + skip_levels &= D3DX_SKIP_DDS_MIP_LEVELS_MASK;
|
|
| 1402 | + hr = d3dx_image_init(src_data, src_data_size, &image, skip_levels, 0);
|
|
| 1401 | 1403 | if (FAILED(hr))
|
| 1402 | - return hr;
|
|
| 1403 | - |
|
| 1404 | - if (img_info.ImageFileFormat != D3DXIFF_DDS)
|
|
| 1405 | - return D3DXERR_INVALIDDATA;
|
|
| 1406 | - |
|
| 1407 | - if (img_info.Width != img_info.Height)
|
|
| 1408 | - return D3DXERR_INVALIDDATA;
|
|
| 1409 | - |
|
| 1410 | - if (size == 0 || size == D3DX_DEFAULT_NONPOW2)
|
|
| 1411 | - size = img_info.Width;
|
|
| 1412 | - if (size == D3DX_DEFAULT)
|
|
| 1413 | - size = make_pow2(img_info.Width);
|
|
| 1414 | - |
|
| 1415 | - if (format == D3DFMT_UNKNOWN || format == D3DX_DEFAULT)
|
|
| 1416 | - format = img_info.Format;
|
|
| 1417 | - |
|
| 1418 | - if (size == D3DX_FROM_FILE)
|
|
| 1419 | 1404 | {
|
| 1420 | - file_size = TRUE;
|
|
| 1421 | - size = img_info.Width;
|
|
| 1405 | + FIXME("Unrecognized file format, returning failure.\n");
|
|
| 1406 | + return hr;
|
|
| 1422 | 1407 | }
|
| 1423 | 1408 | |
| 1424 | - if (format == D3DFMT_FROM_FILE)
|
|
| 1409 | + d3dximage_info_from_d3dx_image(&img_info, &image);
|
|
| 1410 | + if (img_info.ResourceType != D3DRTYPE_CUBETEXTURE)
|
|
| 1425 | 1411 | {
|
| 1426 | - file_format = TRUE;
|
|
| 1427 | - format = img_info.Format;
|
|
| 1412 | + hr = E_FAIL;
|
|
| 1413 | + goto err;
|
|
| 1428 | 1414 | }
|
| 1429 | 1415 | |
| 1430 | - if (mip_levels == D3DX_FROM_FILE)
|
|
| 1431 | - {
|
|
| 1432 | - file_mip_levels = TRUE;
|
|
| 1433 | - mip_levels = img_info.MipLevels;
|
|
| 1434 | - }
|
|
| 1416 | + /* Handle default values. */
|
|
| 1417 | + if (!size || size == D3DX_DEFAULT_NONPOW2 || size == D3DX_FROM_FILE)
|
|
| 1418 | + size = max(img_info.Width, img_info.Height);
|
|
| 1419 | + else if (size == D3DX_DEFAULT)
|
|
| 1420 | + size = make_pow2(max(img_info.Width, img_info.Height));
|
|
| 1421 | + |
|
| 1422 | + format_specified = (format != D3DFMT_UNKNOWN && format != D3DX_DEFAULT);
|
|
| 1423 | + if (format == D3DFMT_FROM_FILE || format == D3DFMT_UNKNOWN || format == D3DX_DEFAULT)
|
|
| 1424 | + format = img_info.Format;
|
|
| 1425 | + mip_levels = (mip_levels == D3DX_FROM_FILE) ? img_info.MipLevels : mip_levels;
|
|
| 1435 | 1426 | |
| 1436 | 1427 | hr = D3DXCheckCubeTextureRequirements(device, &size, &mip_levels, usage, &format, pool);
|
| 1437 | 1428 | if (FAILED(hr))
|
| 1438 | - return hr;
|
|
| 1429 | + {
|
|
| 1430 | + FIXME("Couldn't find suitable texture parameters.\n");
|
|
| 1431 | + goto err;
|
|
| 1432 | + }
|
|
| 1439 | 1433 | |
| 1440 | - if ((file_size && size != img_info.Width)
|
|
| 1441 | - || (file_format && format != img_info.Format)
|
|
| 1442 | - || (file_mip_levels && mip_levels != img_info.MipLevels))
|
|
| 1443 | - return D3DERR_NOTAVAILABLE;
|
|
| 1434 | + if (color_key && !format_specified)
|
|
| 1435 | + format = get_alpha_replacement_format(format);
|
|
| 1444 | 1436 | |
| 1445 | 1437 | hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
|
| 1446 | 1438 | if (FAILED(hr))
|
| 1447 | - return D3DERR_INVALIDCALL;
|
|
| 1439 | + {
|
|
| 1440 | + hr = D3DERR_INVALIDCALL;
|
|
| 1441 | + goto err;
|
|
| 1442 | + }
|
|
| 1448 | 1443 | |
| 1449 | 1444 | dynamic_texture = (caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) && (usage & D3DUSAGE_DYNAMIC);
|
| 1450 | 1445 | if (pool == D3DPOOL_DEFAULT && !dynamic_texture)
|
| 1451 | 1446 | {
|
| 1452 | - hr = D3DXCreateCubeTexture(device, size, mip_levels, 0, format, D3DPOOL_SYSTEMMEM, &buftex);
|
|
| 1453 | - tex = buftex;
|
|
| 1447 | + TRACE("Creating staging texture.\n");
|
|
| 1448 | + hr = D3DXCreateCubeTexture(device, size, mip_levels, 0, format, D3DPOOL_SYSTEMMEM, &staging_tex);
|
|
| 1449 | + tex = staging_tex;
|
|
| 1454 | 1450 | }
|
| 1455 | 1451 | else
|
| 1456 | 1452 | {
|
| 1457 | 1453 | hr = D3DXCreateCubeTexture(device, size, mip_levels, usage, format, pool, &tex);
|
| 1458 | - buftex = NULL;
|
|
| 1459 | 1454 | }
|
| 1455 | + |
|
| 1460 | 1456 | if (FAILED(hr))
|
| 1461 | - return hr;
|
|
| 1457 | + {
|
|
| 1458 | + FIXME("Texture creation failed.\n");
|
|
| 1459 | + goto err;
|
|
| 1460 | + }
|
|
| 1461 | + |
|
| 1462 | + TRACE("Texture created correctly. Now loading the texture data into it.\n");
|
|
| 1463 | + dst_fmt_desc = get_format_info(format);
|
|
| 1464 | + src_fmt_desc = get_format_info(img_info.Format);
|
|
| 1465 | + loaded_miplevels = min(img_info.MipLevels, IDirect3DCubeTexture9_GetLevelCount(tex));
|
|
| 1466 | + for (i = 0; i < loaded_miplevels; ++i)
|
|
| 1467 | + {
|
|
| 1468 | + struct d3dx_pixels src_pixels, dst_pixels;
|
|
| 1469 | + D3DSURFACE_DESC dst_surface_desc;
|
|
| 1470 | + D3DLOCKED_RECT dst_locked_rect;
|
|
| 1471 | + RECT dst_rect;
|
|
| 1472 | + uint32_t face;
|
|
| 1473 | + |
|
| 1474 | + IDirect3DCubeTexture9_GetLevelDesc(tex, i, &dst_surface_desc);
|
|
| 1475 | + SetRect(&dst_rect, 0, 0, dst_surface_desc.Width, dst_surface_desc.Height);
|
|
| 1476 | + for (face = D3DCUBEMAP_FACE_POSITIVE_X; face <= D3DCUBEMAP_FACE_NEGATIVE_Z; ++face)
|
|
| 1477 | + {
|
|
| 1478 | + hr = d3dx_image_get_pixels(&image, face, i, &src_pixels);
|
|
| 1479 | + if (FAILED(hr))
|
|
| 1480 | + break;
|
|
| 1481 | + |
|
| 1482 | + hr = IDirect3DCubeTexture9_LockRect(tex, face, i, &dst_locked_rect, NULL, 0);
|
|
| 1483 | + if (FAILED(hr))
|
|
| 1484 | + break;
|
|
| 1485 | + |
|
| 1486 | + set_d3dx_pixels(&dst_pixels, dst_locked_rect.pBits, dst_locked_rect.Pitch, 0, palette,
|
|
| 1487 | + dst_surface_desc.Width, dst_surface_desc.Height, 1, &dst_rect);
|
|
| 1488 | + |
|
| 1489 | + hr = d3dx_load_pixels_from_pixels(&dst_pixels, dst_fmt_desc, &src_pixels, src_fmt_desc, filter, color_key);
|
|
| 1490 | + IDirect3DCubeTexture9_UnlockRect(tex, face, i);
|
|
| 1491 | + if (FAILED(hr))
|
|
| 1492 | + break;
|
|
| 1493 | + }
|
|
| 1494 | + |
|
| 1495 | + if (FAILED(hr))
|
|
| 1496 | + break;
|
|
| 1497 | + }
|
|
| 1462 | 1498 | |
| 1463 | - hr = load_cube_texture_from_dds(tex, src_data, palette, filter, color_key, &img_info);
|
|
| 1464 | 1499 | if (FAILED(hr))
|
| 1465 | 1500 | {
|
| 1466 | - IDirect3DCubeTexture9_Release(tex);
|
|
| 1467 | - return hr;
|
|
| 1501 | + FIXME("Texture loading failed.\n");
|
|
| 1502 | + goto err;
|
|
| 1468 | 1503 | }
|
| 1469 | 1504 | |
| 1470 | - loaded_miplevels = min(IDirect3DCubeTexture9_GetLevelCount(tex), img_info.MipLevels);
|
|
| 1471 | 1505 | hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, palette, loaded_miplevels - 1, mip_filter);
|
| 1472 | 1506 | if (FAILED(hr))
|
| 1473 | 1507 | {
|
| 1474 | - IDirect3DCubeTexture9_Release(tex);
|
|
| 1475 | - return hr;
|
|
| 1508 | + FIXME("Texture filtering failed.\n");
|
|
| 1509 | + goto err;
|
|
| 1476 | 1510 | }
|
| 1477 | 1511 | |
| 1478 | - if (buftex)
|
|
| 1512 | + if (staging_tex)
|
|
| 1479 | 1513 | {
|
| 1480 | - hr = D3DXCreateCubeTexture(device, size, mip_levels, usage, format, pool, &tex);
|
|
| 1514 | + hr = D3DXCreateCubeTexture(device, size, mip_levels, usage, format, pool, cube_texture);
|
|
| 1481 | 1515 | if (FAILED(hr))
|
| 1482 | - {
|
|
| 1483 | - IDirect3DCubeTexture9_Release(buftex);
|
|
| 1484 | - return hr;
|
|
| 1485 | - }
|
|
| 1516 | + goto err;
|
|
| 1486 | 1517 | |
| 1487 | - IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)buftex, (IDirect3DBaseTexture9 *)tex);
|
|
| 1488 | - IDirect3DCubeTexture9_Release(buftex);
|
|
| 1518 | + IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)staging_tex, (IDirect3DBaseTexture9 *)(*cube_texture));
|
|
| 1519 | + IDirect3DCubeTexture9_Release(staging_tex);
|
|
| 1520 | + }
|
|
| 1521 | + else
|
|
| 1522 | + {
|
|
| 1523 | + *cube_texture = tex;
|
|
| 1489 | 1524 | }
|
| 1490 | 1525 | |
| 1526 | + d3dx_image_cleanup(&image);
|
|
| 1491 | 1527 | if (src_info)
|
| 1492 | 1528 | *src_info = img_info;
|
| 1493 | 1529 | |
| 1494 | - *cube_texture = tex;
|
|
| 1495 | - return D3D_OK;
|
|
| 1530 | + return hr;
|
|
| 1531 | + |
|
| 1532 | +err:
|
|
| 1533 | + d3dx_image_cleanup(&image);
|
|
| 1534 | + if (tex)
|
|
| 1535 | + IDirect3DCubeTexture9_Release(tex);
|
|
| 1536 | + |
|
| 1537 | + return hr;
|
|
| 1496 | 1538 | }
|
| 1497 | 1539 | |
| 1498 | 1540 |
| ... | ... | @@ -202,7 +202,7 @@ HRESULT WINAPI D3DXLoadVolumeFromFileInMemory(IDirect3DVolume9 *dst_volume, cons |
| 202 | 202 | set_d3dbox(&box, 0, 0, image_info.Width, image_info.Height, 0, image_info.Depth);
|
| 203 | 203 | }
|
| 204 | 204 | |
| 205 | - hr = d3dx_image_get_pixels(&image, 0, &pixels);
|
|
| 205 | + hr = d3dx_image_get_pixels(&image, 0, 0, &pixels);
|
|
| 206 | 206 | if (FAILED(hr))
|
| 207 | 207 | goto exit;
|
| 208 | 208 |