with flip() without flip() ?

Blitz3D Forums/Blitz3D Programming/with flip() without flip() ?

RemiD(Posted 2015) [#1]
Hello,

For those who have taken a look at the blitz3d source, can you please explain what is the difference between drawing on the backbuffer then using flip() and drawing on the backbuffer then copying the results (with copyrect) to the frontbuffer ?

In theory it should produce the same result on the screen, but in practice no... Why ?
see the difference :


Thanks,


Rick Nasher(Posted 2015) [#2]
Isn't this because using flip only the physical pointer to the page in memory moves, while for copyrect the buffer needs to be copied bit by bit to another?


RemiD(Posted 2015) [#3]
My question was more why the result displayed on screen is not the same (with copyrect to frontbuffer it seems jerky...) (but the mstime it takes to calculate/render and consequently the fps are the same)


Omnicode(Posted 2015) [#4]
Idk if it helps at all but I swapped some stuff around and got some more noticeable timing differences when it came to loop time when using flip(1) and not using flip(1).

I intentionally put the Waitimer() before calling upon a reference Millisecs(), putting it after seems to only create the 55-60 range without any difference. Whereas Flip(1) counts up through (0-15), to satisfy vwait and without calling Flip(1) stays at (0-1).

At Default Flip(var=1), If never called Flip(var=0) ; Setting the values proves this, it will create the (0-1) range for both if set to Flip(0). Yet, Flip(0 OR 1) still appears smoother than CopyRect().



Tried using banks to help speed up the process, nothing seems to eliminate the jerky attitude to going without calling Flip().
Tried only writing pixels that weren't black ($FF000000), was faster but still didn't eliminate jerky-ness.
Flip() seems pretty hard coded into how Blitz3d flows that it may be impossible to find a suitable sub. Is there really a case that calls for it to not be used?

I'm gonna go with what Rick said above.

I found this article about it, seems to explain it quite well.
https://docs.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html


RemiD(Posted 2015) [#5]

Flip() seems pretty hard coded into how Blitz3d flows that it may be impossible to find a suitable sub. Is there really a case that calls for it to not be used


No this was just by curiosity, to understand why not using flip makes it seems jerky.

I have also tried to add VWait() before Copyrect() but this seems even worse...

Anyway, we will use flip() !


Bobysait(Posted 2015) [#6]
Anything you do on frontbuffer is drawn to the frontbuffer (Sorry if it seems obvious, but as you asked ... there is no answer that can resume it easier ^_^).

It means that : it's rendered on screen at the time you draw it if the scan line is ready. (it does not care about synchronisation/vertical sync, it does not care of frame being complete/safe it does not care about anything ... but the scan line.)

A copyrect will of course copy the pixels at the same time they are drawn on screen when the scan line is ready.
It also means it can draw on arbitrary frames, like at time 2 ms on a frame, and on the next loop at time 16 ms, it may/will result in a dirty and laggy render because it does not wait the synchronisation and render each frame at a different rate.

Adding a VWait can't solve the problem as the problem happens at the very moment you draw something. A VWait will just stop the loop before the next one.

With a Flip (false), the dirty thing happening is mostly due to the fact your drawing is asked to be drawned while the screen is not ready : the scan line is not synchronized with the screen-> if you draw a rect, an image or any kind of buffer, in the middle of the screen while the scan line was around the midle, it will result in a portion of the rect/buffer/whatever you draw, drawn, and the other portionnot rendered at all. It is also noticeable in 3D rendering at a high framerate and fast movements. You will see the scan line in the screen splitting your scene in two parts ; the previous frame on top, and the "current frame" on the bottom.

To resume : Use the ScanLine() function to check if your screen is ready to draw what you want.
But to make things more clear (clearer ?) the frontbuffer is not really intended to be used for rendering anything.
It's mostly a backward compatibility with old stuff, like text-based applications/games (or eventually threaded stuff ...)
it has been almost completely replaced by double/triple-buffering (BackBuffer/RenderBuffer + SwapBuffer)


RemiD(Posted 2015) [#7]
@Bobysait>>Ok, thanks for the clarifications.