Hello,
I am working on a C++ application using DirectX 11.
I'm trying to create a texture array but I can't get the CreateTexture2D() function to work.
First i'm loading multiple PNG files using :
D3DX11_IMAGE_LOAD_INFO loadInfo;
ZeroMemory(&loadInfo, sizeof(loadInfo));
loadInfo.Width = D3DX11_FROM_FILE;
loadInfo.Height = D3DX11_FROM_FILE;
loadInfo.Depth = D3DX11_FROM_FILE;
loadInfo.FirstMipLevel = 0;
loadInfo.MipLevels = D3DX11_FROM_FILE;
loadInfo.Usage = D3D11_USAGE_STAGING;
loadInfo.BindFlags = 0;
loadInfo.CpuAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
loadInfo.MiscFlags = 0;
loadInfo.Format = DXGI_FORMAT_FROM_FILE;
loadInfo.Filter = D3DX11_FILTER_NONE;
loadInfo.MipFilter = D3DX11_FILTER_LINEAR;
loadInfo.pSrcInfo = 0;
HRESULT hrat = D3DX11CreateTextureFromFileA(_pDevice, _fileName.c_str(), &loadInfo, NULL, reinterpret_cast<ID3D11Resource **>(&_pArrayTex), NULL);
It works just fine.
Then I put all those textures in a vector and pass it to a function to create the texture array using :
D3D11_TEXTURE2D_DESC texDesc;
ID3D11Texture2D * pTex = texList[0];
pTex->GetDesc(&texDesc);
D3D11_TEXTURE2D_DESC texArrayDesc;
ZeroMemory(&texArrayDesc, sizeof(texArrayDesc));
texArrayDesc.Width = texDesc.Width;
texArrayDesc.Height = texDesc.Height;
texArrayDesc.MipLevels = texDesc.MipLevels;
texArrayDesc.ArraySize = texList.size();
texArrayDesc.Format = texDesc.Format;
texArrayDesc.SampleDesc.Count = 1;
texArrayDesc.SampleDesc.Quality = 0;
texArrayDesc.Usage = D3D11_USAGE_DEFAULT;
texArrayDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
texArrayDesc.CPUAccessFlags = 0;
texArrayDesc.MiscFlags = 0;
ID3D11Texture2D * texArray = NULL;
HRESULT hrct = _pDevice->CreateTexture2D(&texArrayDesc, NULL, &texArray);
And this is where it goes wrong, when I try to run my App, I get :
Exception non gérée à 0x000ea133 dans CoreEngine.exe : 0xC0000005: Violation d'accès lors de la lecture de l'emplacement 0x00000000.
It seems like the function is trying to read from pInitialData, but I don't understand why.
I just want to create an empty texture array, the resource will be written later using UpdateSubresource().
Any advice would be nice!
Thanks.