I have a specific need, and after looking around, it seems like I have two approaches, but I’m not sure which is better, so I thought I’d ask for comments here.
I am drawing a variety of Windows controls. These are all rectangles, but some will appear as other shapes, such as circles and toroids. Nothing is moving in any of these controls. The whole thing will need to redraw as part of a Paint event, but a circle will always be a circle and a torus will always be a torus. The underlying graphics may or may not have something drawn on them, but if they do or not, what gets drawn will always be in the same place and not moving.
The way I was doing this is using an effect to mask out just the area where the underlying texture is showing through. So, there is an area that is transparent, and an area where the underlying texture is visible. This is then drawn onto another texture (and then something else is drawn over the top, but that’s irrelevant).
My shader isn’t working since moving from XNA4.0 to MG3.8. While looking around for reasons why that might be, I came across some discussion of using the stencil buffer to achieve what appears to be pretty much the same effect. It seems that I’d be slightly better off getting the effect to work, as some controls will need a mask while others will not, and the stencil buffer seems to be set at a higher level than what I’m doing. On the other hand, it looks like I could also just not stencil the rectangular shapes and only stencil the ones that needed cropping.
So, what I’m looking for is a way to decide between using an effect versus using a stencil buffer? What advantages/disadvantages are there for the two approaches?
stenciling if you just need a mask im not to practiced with using the stencil buffer myself.
using a shader this shader maybe overkill here because there is also doing transparency and blending but i obviously favor using shaders. However a full example project is included, its old you might have to rebuild it into a new project.
There are quite a few posts to be found on both if you click on the search icon in the top right of this page.
I certainly favor shaders, as well. It seems more self-contained, which is important for this project, since the control doing the drawing is dynamically loaded, but derives from a base class that is not dynamically loaded. A shader can be totally contained in the dynamically loaded class, whereas the stencil buffer seems like it would need to reach into the base class (to the graphics object). Still, I’m curious as to whether there are any performance advantages.
Thanks for the example, though, that may well be useful.