Page 2 of 2

Re: Drawing outside of love.draw

Posted: Mon Oct 03, 2022 1:48 am
by ReFreezed
No problem. :)

Re: Drawing outside of love.draw

Posted: Mon Oct 03, 2022 2:16 am
by slime
SelfDotX wrote: Sun Oct 02, 2022 9:17 pm Just to be clear, I'm doing this outside of the draw loop.
love.graphics.present creates a frame boundary. But bad things can happen on various operating systems if you don't pump and poll events after that frame boundary, and call love.graphics.clear before drawing to the backbuffer in the current frame (i.e. what the default love.run loop does every frame).

Re: Drawing outside of love.draw

Posted: Mon Oct 03, 2022 2:40 am
by SelfDotX
slime wrote: Mon Oct 03, 2022 2:16 am love.graphics.present creates a frame boundary. But bad things can happen on various operating systems if you don't pump and poll events after that frame boundary, and call love.graphics.clear before drawing to the backbuffer in the current frame (i.e. what the default love.run loop does every frame).
I *technically* understand all the words you used - it may take a while longer before I figure out how to properly use that information :nyu:

Thanks for your help too!

Re: Drawing outside of love.draw

Posted: Mon Oct 03, 2022 3:21 am
by MrFariator
The short and long of it is that for compatibility, it's better to update game stuff during love.update, and draw stuff during love.draw. Things are not guaranteed to work if you mix and match the two, without modifying the default love.run. Even then, it's better to leave game logic out of render logic, and vice versa, unless you have a specific goal in mind.

Re: Drawing outside of love.draw

Posted: Mon Oct 03, 2022 6:27 am
by pgimeno
I created this tool for this kind of purpose: viewtopic.php?f=5&t=87262

In this tool, your code is in a coroutine, which yields when you want to display the screen. That gives every event a chance to run. Of course you can implement your own coroutine-based system without the need to use the tool; it's simple enough.

slime wrote: Mon Oct 03, 2022 2:16 am But bad things can happen on various operating systems if you don't [...] call love.graphics.clear before drawing to the backbuffer in the current frame
Is that also true if you are drawing a fully opaque screen-sized canvas to the screen every frame?

Re: Drawing outside of love.draw

Posted: Mon Oct 03, 2022 11:37 am
by slime
pgimeno wrote: Mon Oct 03, 2022 6:27 am
slime wrote: Mon Oct 03, 2022 2:16 am But bad things can happen on various operating systems if you don't [...] call love.graphics.clear before drawing to the backbuffer in the current frame
Is that also true if you are drawing a fully opaque screen-sized canvas to the screen every frame?
In that situation the main bad thing is that it will be slower on some GPUs (mobile ones especially) than clear + draw, because GPUs of a certain architecture will have to copy the backbuffer's data from vram to on-chip memory unless you tell it that it doesn't need to via the clear() call.

Also you'd probably want to turn blending off.

There's usually little reason to avoid love.graphics.clear, and if the clear color is something common like opaque black then even non-mobile GPUs have super fast paths for it.