1

I'd like to create a XAML application which progressively displays some graphic in a part of the screen. I can have a large number of elements, so I'd like to retain the elements already drawn and only draw the new ones as they come. But unfortunately, I can't get to the swap chain from the SurfaceImageSource (tell me if it is possible) so I can't just copy buffers with each draw call.

How can I draw new elements onto the SurfaceImageSource while preserving the old ones in a performant way?

Sergey Aldoukhov
  • 22,316
  • 18
  • 72
  • 99

1 Answers1

1

I think a swap chain is something you would use with a screen rather than a surface like the one used with SurfaceImageSource, so I don't think it has a swap chain at all - it is just a single texture. I haven't tried but I would assume that if you don't clear it between render calls (with the ClearRenderTargetView method) - the contents should stay as they did. If you want to reuse only a part of the content - you should probably create a separate texture and a render target view that you would use to render to that texture and then copy the contents of that texture to the SurfaceImageSource one some way. I am not sure what the best way to do that would be - maybe memory mapping the textures and doing a memcpy between them or rendering one as a textured quad (two triangles) to the other one.

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • I'm a rookie in DirectX, but in my test I'm calling BeginDraw/DrawLine/EndDraw and that is enough to clear the previous line completely... – Sergey Aldoukhov Jan 09 '13 at 17:49
  • 1
    Well if you are using D2D and the SurfaceImageSource-based render target gets cleared without calling Clear() then you can create a separate bitmap render target and draw to it, then draw the resulting bitmap to the SurfaceImageSource-based target later - check the answer to [this question](http://stackoverflow.com/questions/7690546/replace-gdi-drawimage-with-pinvoked-gdi-and-transparent-pngs) that uses SharpDX and see how a bitmapRenderTarget gets created from another render target and then one bitmap gets rendered to another. – Filip Skakun Jan 09 '13 at 19:00