初始化 Texture2DArray
Initializing Texture2DArray
我正在尝试通过以下方式创建和初始化 2D 纹理数组:
D3D11_TEXTURE2D_DESC desc{};
desc.ArraySize = 10; // there should be 10 textures
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
desc.Width = 256;
desc.Height = 1;
desc.MipLevels = 1;
desc.SampleDesc.Count = 1;
desc.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA subresourceData{};
subresourceData.pSysMem = data.data(); // data is a vector of 2560 elements of type XMVECTOR
subresourceData.SysMemPitch = 256 * sizeof(XMVECTOR);
subresourceData.SysMemSlicePitch = 256 * sizeof(XMVECTOR);
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture = nullptr;
m_device->CreateTexture2D(&desc, &subresourceData, &m_texture);
问题是我在 NULL
中调用 CreateTexture2D
和 m_texture
时遇到错误 Access violation reading location 0xFFFFFFFFFFFFFFFF
。当我没有传递初始化数据时,问题没有发生:
m_device->CreateTexture2D(&desc, nullptr, &m_texture);
如何初始化纹理数组?
问题已解决:对于纹理数组,您必须在 CreateTexture2D
函数中传递 D3D11_SUBRESOURCE_DATA
的数组。
我正在尝试通过以下方式创建和初始化 2D 纹理数组:
D3D11_TEXTURE2D_DESC desc{};
desc.ArraySize = 10; // there should be 10 textures
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
desc.Width = 256;
desc.Height = 1;
desc.MipLevels = 1;
desc.SampleDesc.Count = 1;
desc.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA subresourceData{};
subresourceData.pSysMem = data.data(); // data is a vector of 2560 elements of type XMVECTOR
subresourceData.SysMemPitch = 256 * sizeof(XMVECTOR);
subresourceData.SysMemSlicePitch = 256 * sizeof(XMVECTOR);
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture = nullptr;
m_device->CreateTexture2D(&desc, &subresourceData, &m_texture);
问题是我在 NULL
中调用 CreateTexture2D
和 m_texture
时遇到错误 Access violation reading location 0xFFFFFFFFFFFFFFFF
。当我没有传递初始化数据时,问题没有发生:
m_device->CreateTexture2D(&desc, nullptr, &m_texture);
如何初始化纹理数组?
问题已解决:对于纹理数组,您必须在 CreateTexture2D
函数中传递 D3D11_SUBRESOURCE_DATA
的数组。