Why did Microsoft decide to bind Brush resources to individual Direct2D render targets, rather than the overall Direct2D context. What should we do if we have a Direct3D texture, which is mapped to a Direct2D render target (for a HUD) which needs to be resized to the full width and height of the screen when the user changes between fullscreen and windowed mode, or resizes the window? Is the only thing to do recreate all of the brushes when this happens; or is there another way, such as somehow binding brushes to the ID2D1Factory, rather than the Direct2D surface?
2 Answers
Brushes require the allocation of resources on the GPU. Since Direct2D is a "policy-less" API, which means they want to make sure you can have direct control over memory usage, the brush factory methods hang off the render target instead of the root factory. Otherwise they'd need to have some policy in place that decides when to free the hardware resources, and that policy will always be wrong in some scenarios (it would negatively impact performance or memory usage).
Factory methods for geometries and stroke styles hang off the root factory because they are stored in main memory, and any processing they affect is done on the CPU. You can "compile" a geometry object w/ stroke style into a hardware resource via ID2D1Mesh
, which basically just tessellates it straight into a vertex buffer. While it will be much faster (at render time, not at tessellation time!), it can also use a lot more memory depending on the complexity of the geometry.

- 3,374
- 1
- 17
- 21
I am not sure if this can help, since you didn't describe what will happened when user switch between full-screen mode and window mode, so I assume the only change is the size of the render target, if this is the case, you can just resize your render target by calling the ReSize function, and use the brush as usual, nothing need to change with the brush.