Respect opacity when drawing annotations #238
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR resolves #237, allowing the engine to respect the opacity value of annotations when drawing them.
The implementation here is meant to work with the way that the engine handles drawing annotations (which I hadn't really understood when I opened the original issue). Basically, the primitives for each annotation don't get passed into the relevant shader(s) separately - what happens is that they get added to global collections of the relevant primitive type ("global" here meaning static member values of the
Annotation
base class). Then the shader calls for each "list of primitives" type are made inside of the drawing methods inDrawBatch
.What this means is that we can't use the opacity argument of each annotation in the
Draw
/DrawLines
calls (e.g. here and similar calls), because these calls are made in a static method without access to a particular annotation's opacity. Thus, I think the only good way to do this is to inject the opacity into the passed color - basically, if an annotation has color (A,R,G,B) and opacity α, we pass the shader (A*α,R,G,B). This is the approach taken here. Note that I had to round the values for this to work correctly -Color.A
is typed as a float, but only seemed to work when I gave it an integer.For testing this, I used the example code I gave in #237, plus some similar code for
Poly
andCircle
annotations.