我尝试创建新ID3D11Texture2D
的以将其映射到DXGI_MAPPED_RECT
进一步。我收到了一些ID3D11Texture2D
我没有电源的东西(不能改变创建方式)。
这是代码的一部分:
CComPtr<IDXGIResource> cpDXGIResource;
RET_HR_NULL(_pTexIn->QueryInterface(__uuidof(IDXGIResource), (void**)&cpDXGIResource), cpDXGIResource);
HANDLE sharedHandle;
cpDXGIResource->GetSharedHandle(&sharedHandle);
CComPtr<ID3D11Texture2D> cpTexIn;
cpD3D11Device->OpenSharedResource(sharedHandle, __uuidof(ID3D11Resource), (void**)(&cpTexIn));
D3D11_TEXTURE2D_DESC td;
cpTexIn->GetDesc(&td);
td.Usage = D3D11_USAGE_STAGING;
td.BindFlags = D3D11_BIND_SHADER_RESOURCE;
td.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
CComPtr<ID3D11Texture2D> cpNewTexture;
RET_HR_NULL(cpD3D11Device->CreateTexture2D(&td, NULL, &cpNewTexture), cpNewTexture);
cpD3D11DeviceContext->CopyResource(cpNewTexture, cpTexIn);
CComPtr<IDXGISurface> cpDXGISurface;
RET_HR_NULL(cpNewTexture->QueryInterface(&cpDXGISurface), cpDXGISurface);
D3D11_TEXTURE2D_DESC ntd;
cpNewTexture->GetDesc(&ntd);
DXGI_SURFACE_DESC sd;
cpDXGISurface->GetDesc(&sd);
DXGI_MAPPED_RECT bitmap2Dmap;
RET_HR(cpDXGISurface->Map(&bitmap2Dmap, DXGI_MAP_READ));
_pTexIn
是一个输入 ID3D11Texture2D。我收到以下错误,而Map()
:
RET_HR(cpDXGISurface->Map(&bitmap2Dmap, DXGI_MAP_READ));
DXGI 错误:IDXGISurface::Map:此对象不是使用允许 CPU 访问的 CPUAccess 标志创建的。[其他错误 #42:] 在 testhost.x86.exe 中的 0x76734192 处引发异常:Microsoft C++ 异常:_com_error 在内存位置 0x0716E134。线程 0x26bc 以代码 0 (0x0) 退出。
但!,其实我已经D3D11_CPU_ACCESS_READ
设置好了cpNewTexture
。请参阅下面的 ntd 和 sd 的输出:
这是ntd
and的内容sd
:
ntd {Width=0x00000354 Height=0x000001e0 MipLevels=0x00000001 ...} D3D11_TEXTURE2D_DESC
Width 0x00000354 unsigned int
Height 0x000001e0 unsigned int
MipLevels 0x00000001 unsigned int
ArraySize 0x00000001 unsigned int
Format DXGI_FORMAT_B8G8R8A8_UNORM (0x00000057) DXGI_FORMAT
SampleDesc {Count=0x00000001 Quality=0x00000000 } DXGI_SAMPLE_DESC
Usage D3D11_USAGE_DEFAULT (0x00000000) D3D11_USAGE
BindFlags 0x00000008 unsigned int
CPUAccessFlags 0x00020000 unsigned int
MiscFlags 0x00000002 unsigned int
sd {Width=0x00000354 Height=0x000001e0 Format=DXGI_FORMAT_B8G8R8A8_UNORM (0x00000057) ...} DXGI_SURFACE_DESC
Width 0x00000354 unsigned int
Height 0x000001e0 unsigned int
Format DXGI_FORMAT_B8G8R8A8_UNORM (0x00000057) DXGI_FORMAT
SampleDesc {Count=0x00000001 Quality=0x00000000 } DXGI_SAMPLE_DESC