Search code examples
c++directxdirectx-9

How does one copy a texture from one device to another?


I have a directx9 device for separate windows. One of the windows has a rendered image on it. What I would like to do is actually take Device 'A' image and place the texture on Device 'B's texture. Is this possible?

I was trying to figure out why the below code did not work and its because StretchRect only works with the specified device you are trying to use.

Below code will not work:

D3DXCreateTexture ( B , 32 , 32 , 1 , D3DUSAGE_RENDERTARGET , D3DFMT_A8R8G8B8 , D3DPOOL_DEFAULT , &Texture );

IDirect3DSurface9 *backBufferSucrface;
Texture ->GetSurfaceLevel ( 0 , &backBufferSucrface );

IDirect3DSurface9* backBufferCurrect;
A->GetBackBuffer ( 0 , 0 , D3DBACKBUFFER_TYPE_LEFT , &backBufferCurrect );

B->StretchRect ( backBufferCurrect , 0 , backBufferSucrface , 0 , D3DTEXF_LINEAR );

backBufferCurrect->Release();

I would love to be able to do this, but if this is not possible, is there any way I could use just use one device and render to multiple windows?


Solution

  • Starting from vista d3d9 supports resources sharing between devices. http://msdn.microsoft.com/en-us/library/windows/desktop/bb219800(v=vs.85).aspx#Sharing_Resources