I'm working on a project where I have a D3DImage hosted in a WPF application. I have other WPF controls being rendered over the D3DImage, each with transparent backgrounds. However, when I render my scene, my UI disappears until I hover over the controls (presumably forcing them to be re-rendered).
I know this shouldn't be an issue, as I have accomplished this relatively recently without this issue, but I no longer have that project so I can't compare my code. If anyone has any ideas as to what this might be, I am all ears. I shall be creating a small test project to try to reproduce this issue tomorrow morning; so I'll update this question then.
Edit I have managed to reproduce the problem I'm having in a simple project, which can be downloaded here. Note: To run the project, you will need the latest SlimDX installed.
Edit Commenting out the call to D3DImage.AddDirtyRect(...) in that test project causes the UI to be drawn correctly. However, when rotating the object (and subsequently re-rendering the 3D content when the rotation is updated) the UI flickers and does not consistently get re-drawn.
I've found the cause of the issue. Basically, in WPF when using the D3DImage as a render surface for the Direct3D content, you cannot use the Device.Present() method call, as this handles the presenting of the front buffer. This should not be done as the D3DImage needs to handle this itself so it can apply the correct transparencies (see here for more information on this).
To put it simply, my fix consisted of two parts:
Surface.CreateRenderTarget(...)
I have to pass the target to the device using mDevice.SetRenderTarget(0, mSurface)
. This allows the rendering to occur on the surface.Device.Present()
so that WPF could handle the correct buffer rendering.I dare say that explanation is not 100% accurate, but reading through that link and around the MSDN documentation for the D3DImage should clear it up.