New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add graphics with antialiasing: SmoothRectangle
, SmoothEllipse
, SmoothRoundedRectangle
, SmoothQuad
and SmoothTriangle
#8309
Conversation
Hi @DexerBR ! Did you managed to find out why the tests are failing? |
@misl6 I noticed that the tests fail right after attempting to disable the antialiasing line (by setting I wonder why the test doesn't fail on other platforms. Maybe it's a race condition on that specific platform? |
I found that the problem is on the platform in identifying the file path ( |
e82128c
to
3669d94
Compare
Now all tests pass. |
Hi! So far, I have no changes to add. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @DexerBR !
I've left some minor comments.
Unfortunately, with Cython
we do not have a clean way to reduce the duplicated code, but if you have an idea to reduce (at least partially) the duplicated code between the figures, feel free to share.
Hi @misl6! I totally agree with you about I did a small refactoring, moving all the code that could be defined centrally out of the "snooth instructions". |
Love it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
This PR adds a new graphics section with antialiasing. In addition, some classes have been adjusted to expose the points used in their build (necessary for the antialiasing approach).
Similar to what we have with
SmoothLine
, the new introduced graphics will be:SmoothRectangle
SmoothRoundedRectangle
SmoothEllipse
SmoothQuad
SmoothTriangle
Although there was a desire to integrate antialiasing directly into the current graphics, it seemed better to maintain support for figures without antialiasing and add the new instructions as
Smooth___
.馃煛 All support for antialiasing is maintained regardless of the opacity of the context in which the graphic is drawn.
馃煛 There is still no support for texture antialiasing.
Antialiasing is achieved through a combination of a graphic without antialiasing and
AntiAliasingLine
(a new instruction used internally only for the purpose of antialiasing).AntiAliasingLine
was created and designed to fit around a graphic without antialiasing, providing a smoothing effect to its edges. Although a similar effect could be achieved withSmoothLine
,AntiAliasingLine
has some advantages overSmoothLine
, such as:width
and premultiplied texture, were specifically defined through extensive experimentation for the purpose of antialiasing.AntiAliasingLine
.馃煛
It is worth noting that a customized version of stencil instructions is used here. The reason for this is that the functionglClear(GL_STENCIL_BUFFER_BIT)
is somewhat expensive when it comes to constant updates, which can significantly increase GPU usage. However, by limiting the call to clear stencil functions only when an update is actually needed, performance increases significantly; otherwise, GPU consumption would be close to the maximum limit (when there are tens of thousands of instructions). During the tests, no side effects were observed.stencil_instructions.pyx
, and although it requires more testing, the performance improvement would be significant!Depends on:
clear_stencil
option inStencilPush
, to allow disabling stencil clearing and improve GPU performance when using Stencil Instructions聽#8405Here are some basic comparison data from a test performed with canvas_stress.py, using
64000
RoundedRectangle
/SmoothRoundedRectangle
:Using
RoundedRectangle
:Using
SmoothRoundedRectangle
:The data was obtained by observing the resource monitor while resizing the window or dragging touch across the window using the multitouch simulator (red dot created by the right mouse button).
In almost all cases, the difference between using an instruction with antialiasing and one without would be very small (or insignificant) in terms of resource consumption.
Some comparisons between graphics with and without antialiasing:
Test code:
Maintainer merge checklist
Component: xxx
label.api-deprecation
orapi-break
label.release-highlight
label to be highlighted in release notes.versionadded
,versionchanged
as needed.