Example code, why is this is slow using fullscreen? font fnt
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Example code, why is this is slow using fullscreen? font fnt
I think Refreezed only meant when measuring performance. Once measured you can turn vsync back on. But nothing guarantees you will get 60 FPS in every machine; for example in my machine I can choose a refresh rate of either 60 or 75 Hz.
Re: Example code, why is this is slow using fullscreen? font fnt
Yeah, I only meant when measuring performance - nothing else.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
- BrotSagtMist
- Party member
- Posts: 613
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Example code, why is this is slow using fullscreen? font fnt
Just to make this crystal clear, you are NOT drawing the word test.
Your where drawing 2000*1000*20 pixels with alpha channel and the need for 4 multiplications.
And your _fix_ merely makes this horrible pixel count go a little smaller but doesnt change how horrible that method is for real world usage.
The sane fix for this specific script is to use one single canvas for all buttons.
Pixel flipping is what eats the most resources, if you have to draw a lot of stuff on top of each other to create special effects it is sane to do it once and keep the result.
But when in a real world use case does one ever draw text on top of each other?
Furthermore, you are looking for fps, how often you can flip the pixels of your screen. But if this is meant for a button or simple text then you want the opposite. There is no reason to tell thousands of pixels to stay red 100 times a second, this doesnt make any sense.
If you want the maximum performance you remove the screen clear line inside love.run and then print your buttons once, to the screen and not to a canvas. So you get effective 0 fps and zero cpu usage for that part of the screen the button is in. Adding a selective screen refresh for the actual game parts of your screen is trivial in return, just draw a box.
So this test is not really giving anything for real world scenarios. Love is made to have stuff flying around on the screen, not to print test 20 times, if you want that and want to see the slowest cpu usage, you need to throw everything overboard you normally do.
obey
Re: Example code, why is this is slow using fullscreen? font fnt
But I don't update the canvas layout every draw update.
I create a 'static' canvas, and update the layout in it, only when needed using the redraw variable.
Is that still not good enough ?
I thought that I can make the simple gui on top of the game using multiple canvases like this.
And that the thing that that I did draw on it is saved in memory or something.
Or to put it into other words:
- create a canvas
- draw something at the canvas (heavy part)
- save it in memory (like a jpg)
- draw the 'jpg' on screen (and don't do the heavy part, only when needed)
But if I read you text, creating a canvas once, and use it like this is not oke?
The cpu and memory are super low with the 'fix' at the moment.
(it is using alpha mode, because it is a gui inside the game, with a little alpha).
I'm hoping that you say: that saving the result to a canvas, and using it later (like I do below) is possible.
I create a 'static' canvas, and update the layout in it, only when needed using the redraw variable.
Is that still not good enough ?
I thought that I can make the simple gui on top of the game using multiple canvases like this.
And that the thing that that I did draw on it is saved in memory or something.
Or to put it into other words:
- create a canvas
- draw something at the canvas (heavy part)
- save it in memory (like a jpg)
- draw the 'jpg' on screen (and don't do the heavy part, only when needed)
But if I read you text, creating a canvas once, and use it like this is not oke?
The cpu and memory are super low with the 'fix' at the moment.
(it is using alpha mode, because it is a gui inside the game, with a little alpha).
I'm hoping that you say: that saving the result to a canvas, and using it later (like I do below) is possible.
Code: Select all
function drawCanvas(index)
if redraw[index] == false then
return
end
-- create the drawing for this canvas (once)
love.graphics.clear()
love.graphics.setBlendMode("alpha", "alphamultiply")
love.graphics.setColor(1, 0, 0)
love.graphics.rectangle("fill", 20, 20, 100, 100)
love.graphics.draw(texts[index], index * 10, index * 10)
---
redraw[index] = false -- the next loop will call the return
end
function love.draw()
love.graphics.print("FPS: " .. tostring(love.timer.getFPS()), 10, 10)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setBlendMode("alpha", "premultiplied")
for _, canvas in pairs(canvas) do
love.graphics.draw(canvas)
end
love.graphics.setBlendMode("alpha", "alphamultiply")
end
- BrotSagtMist
- Party member
- Posts: 613
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Example code, why is this is slow using fullscreen? font fnt
Anyway you are misunderstanding how canvases work.
Not drawing something to the canvas is the heavy part but drawing the canvas is, simply because it has more pixels.
Unless the total bits flipped in the scene is greater than the amount in the canvas you gain nothing.
Or in other words imagine how much paint is used when drawing a circle normally on white paper vs drawing the same circle on a black paper. You will need to fill the entire page with white paint first and that is basically what you do with your canvas there. Everytime you draw it the entire area is covered in white paint again and again. In our case the paint is invisible, but its still there and is applied.
obey
Re: Example code, why is this is slow using fullscreen? font fnt
Oke.
Did you give the canvas a small width and height ? Like 100x100 ?
I'm sorry but I always though that drawing something on the canvas was the heavy part.
That is not as I read you comment.
And if I create multiple small canvas its not oke either.
I find it hard to understand this all.
But you say (to make it more easy for me), don't use a canvas at all, and just use 1 canvas and draw everything on top of each other.
Or , you can use multiple canvas but don't use the clear and alpha lines in it, just only the drawing things.
Did you give the canvas a small width and height ? Like 100x100 ?
I'm sorry but I always though that drawing something on the canvas was the heavy part.
That is not as I read you comment.
And if I create multiple small canvas its not oke either.
I find it hard to understand this all.
But you say (to make it more easy for me), don't use a canvas at all, and just use 1 canvas and draw everything on top of each other.
Or , you can use multiple canvas but don't use the clear and alpha lines in it, just only the drawing things.
Re: Example code, why is this is slow using fullscreen? font fnt
I updated my code so i'm not using multiple canvas and love.graphics.setBlendMode("alpha", "premultiplied") anymore.
And with vsync off I can now see that the FSP did go up a little. And the main problem is away.
Thanks.
And with vsync off I can now see that the FSP did go up a little. And the main problem is away.
Thanks.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 196 guests