graphics icon indicating copy to clipboard operation
graphics copied to clipboard

Alternative stencil behavior to allow logical `AND`

Open bvssvni opened this issue 9 years ago • 3 comments

The planned simplied draw state in https://github.com/PistonDevelopers/graphics/issues/996 suggests using:

  • replace operator for Stencil::Clip
  • equality comparison for Stencil::Inside
  • non-equality comparison for Stencil::Outside

This design allows up to 255 different clip shapes at once, but they can not be combined using logical AND.

An idea is to use these settings to allow logical AND:

  • increment_clamp operator for Stencil::Clip
  • greater_equal comparison for Stencil::Inside
  • less comparison for Stencil::Outside

For a single clip shape, the behavior is the same in both alternatives.

The behavior is also the same when you have multiple clip shapes followed by Stencil::Inside(1), because the value will be greater or equal for all cases where the clip shapes overlap.

If you want to render A AND B, you can use Stencil::Clip(1) for both, and then Stencil::Inside(2).

The problem with this idea is that the algorithm for concave polygons will not work.

A downside is you can not have as many clip shapes at once.

bvssvni avatar Feb 08 '16 17:02 bvssvni

Another idea is to use:

  • replace operator for Stencil::Clip
  • increment_clamp operator for a new variant Stencil::Add(u8)
  • greater_equal comparison for Stencil::Inside
  • less comparison for Stencil::Outside

bvssvni avatar Feb 08 '16 17:02 bvssvni

Not sure if there is any benefit of having many clip shapes at once.

bvssvni avatar Feb 08 '16 18:02 bvssvni

I think this needs more time, could wait after upgrading to the new Gfx design.

bvssvni avatar Feb 09 '16 18:02 bvssvni