I am working on a ui lib.
It seems that stencil test function affects performance very much. Did i make some mistake ?
see the example below:
try to hit the no stencil button and see the difference. the FPS is shown as the title.
Performance of the function love.graphics.stencil
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Performance of the function love.graphics.stencil
It's very difficult to tell because that's not a minimal example; getting any info would require digging through your entire GUI library. Please create a single-file example with smallest amount of code possible that still demonstrates the problem.
Re: Performance of the function love.graphics.stencil
Used this way, yes it's slow. It's switching to stencil mode, drawing to the stencil, then switching to drawing mode and drawing to the screen, for every rectangle you're drawing, and that prevents parallelism.
Perhaps you could try to make it in two passes, first drawing everything to the stencil buffer and then drawing everything again to the screen with the stencil active. If you have less than 256 elements, you can even use one stencil value for each element.
And if you have 256 or more, you can maybe draw the first 255 to the stencil, then use the stencil to draw the first 255 to the screen, then clear the stencil and keep drawing the next 255.
Graphically, well, in ASCII art, this is what you're doing and what I propose:
Perhaps you could try to make it in two passes, first drawing everything to the stencil buffer and then drawing everything again to the screen with the stencil active. If you have less than 256 elements, you can even use one stencil value for each element.
And if you have 256 or more, you can maybe draw the first 255 to the stencil, then use the stencil to draw the first 255 to the screen, then clear the stencil and keep drawing the next 255.
Graphically, well, in ASCII art, this is what you're doing and what I propose:
Code: Select all
What you're doing:
Draw to the stencil with value 1
Stencil:
111111111111111
111111111111111
111111111111111
Draw the contents where stencil = 1
Screen:
+-------------+
| Hello |
+-------------+
Clear the stencil and draw to it with value 1
Stencil:
111111111
111111111
111111111
Draw the contents where stencil = 1
Screen:
+-------------+
| Hello | +-------+
+-------------+ | World |
+-------+
etc etc
What I propose:
Draw to the stencil with value 1
Stencil:
111111111111111
111111111111111
111111111111111
Draw to the stencil with value 2
Stencil:
111111111111111
111111111111111 222222222
111111111111111 222222222
222222222
etc etc (up to 255)
Draw the contents where stencil = 1
Screen:
+-------------+
| Hello |
+-------------+
Draw the contents where stencil = 2
Screen:
+-------------+
| Hello | +-------+
+-------------+ | World |
+-------+
etc etc (up to 255)
If more than 255, clear the stencil and start with value 1 again.
Re: Performance of the function love.graphics.stencil
Thank you , i will try with that !pgimeno wrote: ↑Mon Apr 08, 2019 11:00 am Used this way, yes it's slow. It's switching to stencil mode, drawing to the stencil, then switching to drawing mode and drawing to the screen, for every rectangle you're drawing, and that prevents parallelism.
Perhaps you could try to make it in two passes, first drawing everything to the stencil buffer and then drawing everything again to the screen with the stencil active. If you have less than 256 elements, you can even use one stencil value for each element.
And if you have 256 or more, you can maybe draw the first 255 to the stencil, then use the stencil to draw the first 255 to the screen, then clear the stencil and keep drawing the next 255.
Thank you for your reply. that's my fault.
Re: Performance of the function love.graphics.stencil
Forgot to say. Maybe you can just use a scissor instead of a stencil? That should be faster.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 10 guests