我正在尝试加载一个基本纹理(1024x1024)并用纯色填充它:
unsigned char *texArray = (unsigned char *)malloc(4 * 1024 * 1024 * sizeof(unsigned char));
for (int i = 0; i < 1024 * 1024 * 4; i++) {
texArray[i] = (unsigned char)125;
}
D3D11_TEXTURE2D_DESC desc;
desc.Width = 1024;
desc.Height = 1024;
desc.MipLevels = desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;
ID3D11Texture2D *pTexture = NULL;
D3D11_SUBRESOURCE_DATA TexInitData;
ZeroMemory(&TexInitData, sizeof(D3D11_SUBRESOURCE_DATA));
TexInitData.pSysMem = texArray;
TexInitData.SysMemPitch = static_cast<UINT>( 1024*4 );
TexInitData.SysMemSlicePitch = static_cast<UINT>( 4 * 1024 * 1024 * sizeof(unsigned char) );
GraphicsBase.DXDevice->CreateTexture2D( &desc, &TexInitData, &pTexture );
GraphicsBase.DXDevice->CreateShaderResourceView(pTexture, NULL, &DXTextureContent);
当我使用 时DXTextureContent
,我的纹理看起来都是白色的。我用 125/125/125/125 为 RGBA 填充纹理。我在这里错过了什么吗?