WPF as OpenGL texture
I'm working on a simulator which relies on OpenGL to display symbols, maps, moving items... as layers/textures.
We are investigating different options to introduce multitouch support in the simulator.
WPF is one of the options, as it could provide interesting productivity factors for GUI development. A prototype has been built but it does not meet our performance requirements.
I'm looking for a way to improve performance or for any advice which could put us back on the right track.
The current system is based on
A main/hosting application written on C++ and OpenGL which drives (start, schedule, stop...) the WPF part and provides context informations
A WPF app with multitouch support which reacts accordingly to the main context and to user input
A COM component for communication beetween the Main/hosting app and the WPF app
Multitouch inputs managed by a specific abstraction layer (handles TUIO or proprietary events)
The host app scheduler ask the WPF app for a capture/bitmap every xx ms (xx < 50-60ms usually) and adds this bitmap as an OpenGL texture (glTexImage2D) to render the simulation window.
The current way the WPF renders its bitmap relies on RenderTargetBitmap. The rendering time is about 500ms which is at least 10 times slower than we would like it to be and consumes too much CPU (WPF uses the software pipeline in this case)开发者_如何学编程.
So, my questions would be :
Is there a way to render the bitmap of a WPF window much faster while keeping all its features (transparency for instance) ? I'm aware of the gdi32 API but it does not seem to support things like transparency and I don't know if we can gain any performance
The current architecture does not look like an optimal choice as two "rendering" are performed (the rendering of the WPF app itself and the rendering of its bitmap). Would it be possible WPF to render once in some virtual memory space which could be directly read by the Main/hosting app ?
Render API
First of all, you shouldn't mix WPF and OpenGL, because WPF is DirectX based. Make sure you are running WPF on DirectX 9.0+ hardware for best performance.
Rendering
Everytime some presumed layout change takes place, WPF recomputes the entire layout of its display, which can be quite costly. So make sure to always use the least complex container that is sufficient for your task (i.e. don't use a Grid when a Canvas is good enough).
Memory Management
To improve memory handling, you can use weak events (release event handlers from objects when the handler isn't needed any more), use VirtualizingStackPanels instead of StackPanels to minimize memory impact of UI elements, and employ freezable objects.
精彩评论