[Edit]
You'll need to create the texture array separately.
Cheers!
int D3DTexture::LoadTextureInToTextureArray(const char *pAddr,int Index)
{
// pAddr should point to file loaded in memory
// Index is a number between 0 and ArraySize
D3D11_TEXTURE2D_DESC ArrayDesc;
pTextureResource->GetDesc( &ArrayDesc );
D3D11_TEXTURE2D_DESC desc;
D3DX11_IMAGE_LOAD_INFO ImageloadInfo;
ZeroMemory( &ImageloadInfo, sizeof( D3DX11_IMAGE_LOAD_INFO ) );
ImageloadInfo.Width = ArrayDesc.Width;
ImageloadInfo.Height = ArrayDesc.Height;
ImageloadInfo.Depth = D3DX11_DEFAULT;
ImageloadInfo.FirstMipLevel = 0;
ImageloadInfo.MipLevels = ArrayDesc.MipLevels;
ImageloadInfo.Usage = D3D11_USAGE_STAGING;
ImageloadInfo.BindFlags = 0;
ImageloadInfo.CpuAccessFlags = D3D11_CPU_ACCESS_READ;
ImageloadInfo.MiscFlags = 0;
ImageloadInfo.Format = ArrayDesc.Format;
ImageloadInfo.Filter = D3DX11_FILTER_SRGB_IN | D3DX11_FILTER_NONE; //<- SRGB flag should be used for gamma correct rendering
ImageloadInfo.MipFilter = D3DX11_FILTER_NONE;
ImageloadInfo.pSrcInfo = NULL;
ID3D11Resource *pRes = NULL;
HRESULT hr = D3DX11CreateTextureFromMemory(DXUTGetD3D11Device(),pAddr,FileSize,&ImageloadInfo,NULL,&pRes,NULL);
if(FAILED(hr))
{
//Texture creation failed
return 0;
}
if( pRes )
{
ID3D11Texture2D* pTemp;
pRes->QueryInterface( __uuidof( ID3D11Texture2D ), (LPVOID*)&pTemp );
pTemp->GetDesc( &desc );
D3D11_MAPPED_SUBRESOURCE mappedTex2D;
for(UINT i=0; i < desc.MipLevels; i++)
{
HRESULT hr = DXUTGetD3D11DeviceContext()->Map(pRes, i, D3D11_MAP_READ, 0, &mappedTex2D );
if(FAILED(hr))
{
return 0;
}
//pTextureResource should point to a valid and already created 2D Texture Array
if(mappedTex2D.pData)
{
DXUTGetD3D11DeviceContext()->UpdateSubresource( pTextureResource,
D3D11CalcSubresource( i, Index, ArrayDesc.MipLevels ),
NULL,
mappedTex2D.pData,
mappedTex2D.RowPitch,
0 );
DXUTGetD3D11DeviceContext()->Unmap(pRes,i);
}
}
pTemp->Release();
pRes->Release();
}
}