在DirectX 11和DirectX 10之间共享纹理

时间:2013-11-08 21:19:22

标签: directx textures shared directx-11 directx-10

众所周知,DX11不再支持文字写入屏幕。我想通过使用DX11创建纹理并将其共享为DX10来实现这一点,因此可以使用ID3DX10Font接口绘制它。然后将所有内容与DX11着色器混合。尝试使用Dx10打开Dx11创建的纹理时出错。这是代码:

D3D11_TEXTURE2D_DESC desc;
ZeroMemory(&desc,sizeof(D3D11_TEXTURE2D_DESC));
desc.ArraySize = 1;
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.Height = 480;
desc.Width = 640;
desc.MipLevels = 1;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;


Globals::hr = D3D10CreateDevice(0,D3D10_DRIVER_TYPE_HARDWARE,0,0,D3D10_SDK_VERSION,&Globals::pD3D10Device);
Globals::hr = Globals::pD3D11Device->CreateTexture2D(&desc,0,&Globals::backBuffer10);

//keyed mutex for DX11 device
Globals::hr = Globals::backBuffer10->QueryInterface(__uuidof(IDXGIKeyedMutex),(void**)(&Globals::mutex11));

//Get the shared handle so that DX10 can render on texture
IDXGIResource *sharedResource10;
Globals::hr = Globals::backBuffer10->QueryInterface(__uuidof(IDXGIResource),(void**)(&sharedResource10));
Globals::hr = sharedResource10->GetSharedHandle(&Globals::sharedHandle);
sharedResource10->Release();

//open texture for DX10
IDXGISurface *sharedSurface10;
ID3D10Texture2D *sharedTexture10;
Globals::hr = Globals::pD3D10Device->OpenSharedResource(Globals::sharedHandle,__uuidof(IDXGISurface),(void**)(&sharedSurface10));

我从代码的最后一行得到了一个E_INVALIDARGS。有什么想法吗? DX11和DX10设备都使用DRIVER_TYPE_HARDWARE标志创建,并且都使用R8G8B8A8_UNORM作为后缓冲格式。

1 个答案:

答案 0 :(得分:4)

你不需要应对这种邪恶的黑客,因为:

  1. ID3DX10FontID3DX10Sprite真的很慢而且很糟糕
  2. 网上有很多图书馆: