2

众所周知,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 作为后台缓冲区格式。

4

1 回答 1

4

您无需应对此类邪恶的黑客攻击,因为:

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

于 2013-11-09T04:20:58.250 回答