microsoft / DirectXTK

The DirectX Tool Kit (aka DirectXTK) is a collection of helper classes for writing DirectX 11.x code in C++

Home Page:https://walbourn.github.io/directxtk/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WIC_LOADER_MAKE_SQUARE, WIC_LOADER_FIT_POW2 cause Failure

Raildex opened this issue · comments

The WIC_LOADER Flags WIC_LOADER_FIT_POW2 and WIC_LOADER_MAKE_SQUARE cause a failure due to a small buffer when supplied in the CreateWICTextureFromFileEx and CreateWICTextureFromMemoryEx functions.

The meaning of these flags is not documented anyway. I'd expect them to resize the buffer automatically (since I as a consumer don't know what the loader does and what size the result will be)

Here is an example usage:

	Texture2D::Texture2D(ID3D11Device* device, const std::wstring& fileName) {
		
		ComPtr<ID3D11Resource> resource;
		ID3D11DeviceContext* context = NULL;
		device->GetImmediateContext(&context);

		throwIfFailed(CreateWICTextureFromFileEx(device, context, fileName.c_str(), (size_t)0,D3D11_USAGE_DEFAULT,D3D11_BIND_SHADER_RESOURCE|D3D11_BIND_RENDER_TARGET,0x0,0x0,LOADER_FLAGS, resource.GetAddressOf(), ShaderResourceView.GetAddressOf()));
		throwIfFailed(resource->QueryInterface(Texture.GetAddressOf()));
	}

with

constexpr static auto LOADER_FLAGS = WIC_LOADER_FORCE_RGBA32 | WIC_LOADER_MAKE_SQUARE | WIC_LOADER_FIT_POW2;

I'm happy to take a look. What is the HRESULT you are getting and can you provide the image that's failing?

The flags are documented here:

The WIC_LOADER_FIT_POW2 and/or WIC_LOADER_MAKE_SQUARE flags can be used to force the image to be resized to a power-of-2 size and/or be made a square texture that has width == height. These flags are most useful for the Direct3D 9 legacy version of WICTextureLoader, but are supported in all versions.

If you can't provide the image, can you tell me the image's original width, height, and pixel format?

I have a repro of this now... working on it.

Thanks for the bug report. It wasn't specific to this flag, but it was defintely a bug.

Fixed in this commit for DX11, and this commit for DX12. Also fixed in this commit for DirectXTex

This issue did not impact the DX9 version of WICTextureLoader

Added test coverage for these cases to DirectX Tool Kit DX11 and DX12 test suites