void D3DTexture::Init(const std::string& imagePath, RenderDevice& device) { concurrency::create_async([&]() { CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; { std::lock_guard<std::recursive_mutex> lock(mMutex); ThrowIfFailed(DirectX::CreateWICTextureFromFile(mDevice, mContext, converter.from_bytes(imagePath).c_str(), nullptr, &mColorTexture), "CreateWICTextureFromFile() failed."); } // Create a texture sampler D3D11_SAMPLER_DESC samplerDesc; ZeroMemory(&samplerDesc, sizeof(samplerDesc)); samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; { std::lock_guard<std::recursive_mutex> lock(mMutex); ThrowIfFailed(mDevice->CreateSamplerState(&samplerDesc, &mColorSampler), "ID3D11Device::CreateSamplerState() failed."); } device.ResourceLoaded(); }); }