views:

29

answers:

1

In Direct2D they recommend drawing similar things together, to avoid unnecessary GPU state changes. They also do some drawing operation reordering behind the scene just for that.

I have to draw a lot of rectangles which can have one of two colors. I'm thinking of doing the drawing in two passes, one for the rectangles with the first color and another for the ones with the other color.

Do you have any idea if this will improve the rendering speed? The speed I have right now is not that great. I draw into a DrawingContext obtained from a DrawingVisual.

+1  A: 

I really don't know what effect grouping by brush will have, but there are some things you should check first:

  • Make sure all brushes, pens and other freezables are frozen.
  • Simplify your visual tree, try to reduce element count.
  • Try to reduce the number of elements that change every time you update your drawing.

Read: http://msdn.microsoft.com/en-us/magazine/dd483292.aspx

Nir
I already do all that. I tried using Direct2D from C++/CLI, the speed was outstanding, but I couldn't get the focus to work correctly (http://stackoverflow.com/questions/2844165/wpf-hwndhost-keyboard-focus), so now I'm trying the lowest level WPF drawing API that I could find, besides going all the way to Direct3D.
Adal
@Adal - DrawingVisual is not the lowest level WPF API, the lowest level is overriding OnRender, using multiple DrawingVisuals is useful when dealing with large data sets where every "cycle" small part of the data changes, that way you can update just the visual containing the changed data and not re-render the entire data set.
Nir