Search code examples
c++directxrenderingdirect2d

Direct2D Save rendering result


I have several groups (layers) of geometries to be rendered. For instance, first and third groups/layers are static (rendering should be performed only once), but second group/layer should be rendered few times. Is there a way to save the rendering result for first and third layer in order to render only second group and then combine results? I have seen the ID2D1Layer interface, but apparently it cannot hold the rendering result. Could you please advise how to avoid unnecessary rendering for first and third layers?


Solution

  • Is there a way to save the rendering result for first and third layer in order to render only second group and then combine results?

    Yes, there is. You can render (cache) the static geometries in bitmaps (ID2D1Bitmap/1). Then you render the bitmaps to the final render target instead of geometries. In this way you trade memory for speed.

    D2D layers doesn't do what you assume. They are used to set (stackable) settings for the renderer (device context). The settings include: clip rect, opacity, arbitrary brush, arbitrary matrix transform and others.