我在創建和填充DirectX11中的Texture2DArray時遇到了一些問題。創建Texture2DArray並用固定值填充它
我想在屏幕上渲染很多四邊形,繪圖是通過實例完成的,但是每個四邊形都應該有他自己的紋理。所以我嘗試創建一個Texture Array併爲實例數據格式添加一個索引值。
D3D11 ERROR: ID3D11Device::CreateTexture2D: pInitialData[4].SysMemPitch cannot be 0 [ STATE_CREATION ERROR #100: CREATETEXTURE2D_INVALIDINITIALDATA]
D3D11 ERROR: ID3D11Device::CreateTexture2D: pInitialData[6].pSysMem cannot be NULL. [ STATE_CREATION ERROR #100: CREATETEXTURE2D_INVALIDINITIALDATA]
D3D11 ERROR: ID3D11Device::CreateTexture2D: pInitialData[7].pSysMem cannot be NULL. [ STATE_CREATION ERROR #100: CREATETEXTURE2D_INVALIDINITIALDATA]
D3D11 ERROR: ID3D11Device::CreateTexture2D: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #104: CREATETEXTURE2D_INVALIDARG_RETURN]
這裏是我使用的代碼:
的問題是,當我嘗試創建兩個不同的紋理入陣中,當我嘗試調用該函數CreateTexture2D並出現以下錯誤失敗生成紋理:
//Create array for two textures
const int size = 256 * 256 * 4;
unsigned char color[size*2];
//First Texture white
for (int i = 0; i < size; i++) {
color[i] = 255;
}
//Second Texture black
for (int i = size; i < size*2; i++) {
color[i] = 0;
}
//Creating Texture2D description
D3D11_TEXTURE2D_DESC desc;
ZeroMemory(&desc, sizeof(D3D11_TEXTURE2D_DESC));
desc.Width = 256;
desc.Height = 256;
desc.MipLevels = 1;
desc.ArraySize = 2;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
ID3D11Texture2D *pTexture;
D3D11_SUBRESOURCE_DATA texture[2];
//ZeroMemory(&texture, sizeof(D3D11_SUBRESOURCE_DATA));
//Defining the texture start points
texture[0].pSysMem = color;
texture[0].SysMemPitch = sizeof(unsigned char) * 4;
texture[0].SysMemSlicePitch = 0;
texture[1].pSysMem = &color[size];
texture[1].SysMemPitch = sizeof(unsigned char) * 4;
texture[1].SysMemSlicePitch = 0;
result = device->CreateTexture2D(&desc, texture, &pTexture);
我不知道爲什麼在陣列位置的錯誤狀態,我在沒有明確的點,我只有兩個尺寸的紋理數組。 也許我在做初始化或填充數據時出錯。
我希望有人能幫助我。