PistonDevelopers / graphics

A library for 2D graphics, written in Rust, that works with multiple back-ends
MIT License
479 stars 55 forks source link

Alternative stencil behavior to allow logical `AND` #1032

Open bvssvni opened 8 years ago

bvssvni commented 8 years ago

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

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:

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 commented 8 years ago

Another idea is to use:

bvssvni commented 8 years ago

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

bvssvni commented 8 years ago

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