I'm writing a video player in WPF using Direct3D and the D3DImage object. This object takes a pointer to a Direct3DSurface9 and displays it.
I've been basically following the D3DImage tutorial and the MSDN sample, and that works well, however these assume the rendering happens on the UI thread, in sync. For my application, I want the rendering to be happening on a different thread, and the UI to take frames to display when it wants.
I've managed to do this using a single render target and passing its pointer to D3DImage. However, even when using locks to ensure the GUI isn't updating D3DImage when the rendering thread is rendering and vice-versa, I get a lot of tearing. I've then tried using two different D3DImages on top of each other, each with its own render target, alternate their visibility and always render in the hidden one, but even then if the rendering thread goes too fast, there is tearing.
I've read that when you call IDirect3DDevice::EndScene(), this doesn't mean the buffer is ready to be displayed, just that it's queued for rendering; this could be the reason I'm seeing tearing. I'm not calling "Present" (as the D3DImage tutorial explains), and just passing the pointer to WPF after calling EndScene().
I'm not very knowledgeable with Direct3D and I don't know what would be a good approach to solve this issue. How can I ensure a buffer is ready to be displayed, while locking as little as possible between the GUI and rendering thread and having good performance? My intuition is I should be using a chain of render targets of some sort, but there are many options and I don't know where to start.
Edited by Dr_Asik, 30 January 2013 - 03:48 PM.