Patryk Lipski
Patryk Lipski

Reputation: 163

Sharing texture between DirectX 11 and DirectX 10

As everybody knows, DX11 no longer support text writing to the screen. I wanted to do that by creating texture with DX11 and share it for DX10, so it could draw to it with ID3DX10Font interface. Then blend everything with DX11 shaders. I've got an error when trying to open Dx11 created texture with Dx10. Here is the code:

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));

I've got an E_INVALIDARGS from last line of the code. Any thoughts? Both DX11 and DX10 devices are created with DRIVER_TYPE_HARDWARE flags, and both have R8G8B8A8_UNORM as back buffer format.

Upvotes: 2

Views: 1179

Answers (1)

Drop
Drop

Reputation: 13005

You don't need to cope with such unholy hacks because:

  1. ID3DX10Font and ID3DX10Sprite are really slow and crappy
  2. There are many libraries on the web:

Upvotes: 4

Related Questions